File: test_init.c

package info (click to toggle)
dqlite 1.18.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,372 kB
  • sloc: ansic: 57,583; makefile: 336; sh: 243
file content (85 lines) | stat: -rw-r--r-- 2,629 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "../../../src/raft.h"
#include "../../lib/runner.h"

/******************************************************************************
 *
 * raft_init
 *
 *****************************************************************************/

SUITE(raft_init)

/* Incompatible raft->io and raft->fsm wrt async snapshots. */
TEST(raft_init, incompatIoFsmAsyncSnapshotNotNull, NULL, NULL, 0, NULL)
{
    /* Set incompatible io and fsm versions and non-NULL snapshot_async fn */
    struct raft r = {0};
    struct raft_io io = {0};
    struct raft_fsm fsm = {0};
    io.version = 1; /* Too low */
    io.async_work = (int (*)(struct raft_io *, struct raft_io_async_work *,
                             raft_io_async_work_cb))(uintptr_t)0xDEADBEEF;
    fsm.version = 3;
    fsm.snapshot_async = (int (*)(struct raft_fsm *, struct raft_buffer **,
                                  unsigned int *))(uintptr_t)0xDEADBEEF;

    int rc;
    rc = raft_init(&r, &io, &fsm, 1, "1");
    munit_assert_int(rc, ==, -1);
    munit_assert_string_equal(
        r.errmsg,
        "async snapshot requires io->version > 1 and async_work method.");
    return MUNIT_OK;
}

/* Incompatible raft->io and raft->fsm wrt async snapshots. */
TEST(raft_init, incompatIoFsmAsyncSnapshotNull, NULL, NULL, 0, NULL)
{
    /* Set incompatible io and fsm versions and NULL snapshot_async fn */
    struct raft r = {0};
    struct raft_io io = {0};
    struct raft_fsm fsm = {0};
    io.version = 2;
    io.async_work = NULL;
    fsm.version = 3;
    fsm.snapshot_async = (int (*)(struct raft_fsm *, struct raft_buffer **,
                                  unsigned int *))(uintptr_t)0xDEADBEEF;

    int rc;
    rc = raft_init(&r, &io, &fsm, 1, "1");
    munit_assert_int(rc, ==, -1);
    munit_assert_string_equal(
        r.errmsg,
        "async snapshot requires io->version > 1 and async_work method.");
    return MUNIT_OK;
}

TEST(raft_init, ioVersionNotSet, NULL, NULL, 0, NULL)
{
    struct raft r = {0};
    struct raft_io io = {0};
    struct raft_fsm fsm = {0};
    io.version = 0;
    fsm.version = 3;

    int rc;
    rc = raft_init(&r, &io, &fsm, 1, "1");
    munit_assert_int(rc, ==, -1);
    munit_assert_string_equal(r.errmsg, "io->version must be set");
    return MUNIT_OK;
}

TEST(raft_init, fsmVersionNotSet, NULL, NULL, 0, NULL)
{
    struct raft r = {0};
    struct raft_io io = {0};
    struct raft_fsm fsm = {0};
    io.version = 2;
    fsm.version = 0;

    int rc;
    rc = raft_init(&r, &io, &fsm, 1, "1");
    munit_assert_int(rc, ==, -1);
    munit_assert_string_equal(r.errmsg, "fsm->version must be set");
    return MUNIT_OK;
}