2 Tests for tools/ctdb.c and libctdb stubs
4 Copyright (C) Martin Schwenke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #define CTDB_TEST_OVERRIDE_MAIN
21 #include "ctdb_test.c"
23 static void test_read_nodemap(void)
25 struct ctdb_context
*ctdb
= talloc_zero(NULL
, struct ctdb_context
);
27 libctdb_test_read_nodemap(ctdb
);
28 libctdb_test_print_nodemap(ctdb
);
33 static void test_read_ifaces(void)
35 struct ctdb_context
*ctdb
= talloc_zero(NULL
, struct ctdb_context
);
37 libctdb_test_read_ifaces(ctdb
);
38 libctdb_test_print_ifaces(ctdb
);
43 static void test_read_vnnmap(void)
45 struct ctdb_context
*ctdb
= talloc_zero(NULL
, struct ctdb_context
);
47 libctdb_test_read_vnnmap(ctdb
);
48 libctdb_test_print_vnnmap(ctdb
);
53 static void test_fake_setup(void)
56 struct ctdb_context
*ctdb
= talloc_zero(NULL
, struct ctdb_context
);
58 libctdb_test_fake_setup(ctdb
);
60 if (ctdb
->nodes
!= NULL
) {
65 libctdb_test_print_nodemap(ctdb
);
69 if (ctdb
->ifaces
!= NULL
) {
74 libctdb_test_print_ifaces(ctdb
);
78 if (ctdb
->vnn_map
!= NULL
) {
83 libctdb_test_print_vnnmap(ctdb
);
90 static const char * decode_pnn_mode(uint32_t pnn_mode
)
97 { CTDB_CURRENT_NODE
, "CURRENT_NODE" },
98 { CTDB_BROADCAST_ALL
, "BROADCAST_ALL" },
99 { CTDB_BROADCAST_VNNMAP
, "BROADCAST_VNNMAP" },
100 { CTDB_BROADCAST_CONNECTED
, "BROADCAST_CONNECTED" },
101 { CTDB_MULTICAST
, "MULTICAST" },
104 for (i
= 0; i
< ARRAY_SIZE(pnn_modes
); i
++) {
105 if (pnn_mode
== pnn_modes
[i
].mode
) {
106 return pnn_modes
[i
].name
;
113 static void print_nodes(uint32_t *nodes
, uint32_t pnn_mode
)
118 for (i
= 0; i
< talloc_array_length(nodes
); i
++) {
119 printf(" %lu", (unsigned long) nodes
[i
]);
123 printf("PNN MODE: %s (%lu)\n",
124 decode_pnn_mode(pnn_mode
), (unsigned long) pnn_mode
);
127 static void test_parse_nodestring(const char *nodestring_s
,
130 const char *nodestring
;
132 struct ctdb_context
*ctdb
;
136 nodestring
= strcmp("", nodestring_s
) == 0 ? NULL
: nodestring_s
;
138 if (strcasecmp(dd_ok_s
, "yes") == 0 ||
139 strcmp(dd_ok_s
, "true") == 0) {
145 ctdb
= talloc_zero(NULL
, struct ctdb_context
);
147 libctdb_test_read_nodemap(ctdb
);
149 if (parse_nodestring(ctdb
, NULL
, nodestring
, CTDB_CURRENT_NODE
, dd_ok
,
150 &nodes
, &pnn_mode
)) {
151 print_nodes(nodes
, pnn_mode
);
157 static void usage(void)
159 fprintf(stderr
, "usage: ctdb_tool_libctdb <op>\n");
163 int main(int argc
, const char *argv
[])
165 LogLevel
= DEBUG_DEBUG
;
166 if (getenv("CTDB_TEST_LOGLEVEL")) {
167 LogLevel
= atoi(getenv("CTDB_TEST_LOGLEVEL"));
174 if (argc
== 2 && strcmp(argv
[1], "read_nodemap") == 0) {
176 } else if (argc
== 2 && strcmp(argv
[1], "read_ifaces") == 0) {
178 } else if (argc
== 2 && strcmp(argv
[1], "read_vnnmap") == 0) {
180 } else if (argc
== 2 && strcmp(argv
[1], "fake_setup") == 0) {
182 } else if (argc
== 4 && strcmp(argv
[1], "parse_nodestring") == 0) {
183 test_parse_nodestring(argv
[2], argv
[3]);