lib/tls: Change default supported TLS versions.
[Samba.git] / ctdb / tests / src / ctdb_functest.c
blob9eaae55765de1a1c2e923d19b81e703b8e6ec249
1 /*
2 Tests for tools/ctdb.c and CTDB client 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 ctdb_test_stubs_read_nodemap(ctdb);
28 ctdb_test_stubs_print_nodemap(ctdb);
30 talloc_free(ctdb);
33 static void test_read_ifaces(void)
35 struct ctdb_context *ctdb = talloc_zero(NULL, struct ctdb_context);
37 ctdb_test_stubs_read_ifaces(ctdb);
38 ctdb_test_stubs_print_ifaces(ctdb);
40 talloc_free(ctdb);
43 static void test_read_vnnmap(void)
45 struct ctdb_context *ctdb = talloc_zero(NULL, struct ctdb_context);
47 ctdb_test_stubs_read_vnnmap(ctdb);
48 ctdb_test_stubs_print_vnnmap(ctdb);
50 talloc_free(ctdb);
53 static void test_fake_setup(void)
55 bool first = true;
56 struct ctdb_context *ctdb = talloc_zero(NULL, struct ctdb_context);
58 ctdb_test_stubs_fake_setup(ctdb);
60 if (ctdb->nodes != NULL) {
61 if (!first) {
62 printf("\n");
64 printf("NODEMAP\n");
65 ctdb_test_stubs_print_nodemap(ctdb);
66 first = false;
69 if (ctdb->ifaces != NULL) {
70 if (!first) {
71 printf("\n");
73 printf("IFACES\n");
74 ctdb_test_stubs_print_ifaces(ctdb);
75 first = false;
78 if (ctdb->vnn_map != NULL) {
79 if (!first) {
80 printf("\n");
82 printf("VNNMAP\n");
83 ctdb_test_stubs_print_vnnmap(ctdb);
84 first = false;
87 talloc_free(ctdb);
90 static const char * decode_pnn_mode(uint32_t pnn_mode)
92 int i;
93 static const struct {
94 uint32_t mode;
95 const char *name;
96 } pnn_modes[] = {
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;
110 return "PNN";
113 static void print_nodes(uint32_t *nodes, uint32_t pnn_mode)
115 int i;
117 printf("NODES:");
118 for (i = 0; i < talloc_array_length(nodes); i++) {
119 printf(" %lu", (unsigned long) nodes[i]);
121 printf("\n");
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,
128 const char *dd_ok_s)
130 const char *nodestring;
131 bool dd_ok;
132 struct ctdb_context *ctdb;
133 uint32_t *nodes;
134 uint32_t pnn_mode;
136 nodestring = strcmp("", nodestring_s) == 0 ? NULL : nodestring_s;
138 if (strcasecmp(dd_ok_s, "yes") == 0 ||
139 strcmp(dd_ok_s, "true") == 0) {
140 dd_ok = true;
141 } else {
142 dd_ok = false;
145 ctdb = talloc_zero(NULL, struct ctdb_context);
147 ctdb_test_stubs_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);
154 talloc_free(ctdb);
157 static void usage(void)
159 fprintf(stderr, "usage: ctdb_tool_functest <op>\n");
160 exit(1);
163 int main(int argc, const char *argv[])
165 DEBUGLEVEL = DEBUG_DEBUG;
166 if (getenv("CTDB_TEST_LOGLEVEL")) {
167 DEBUGLEVEL = atoi(getenv("CTDB_TEST_LOGLEVEL"));
170 if (argc < 2) {
171 usage();
174 if (argc == 2 && strcmp(argv[1], "read_nodemap") == 0) {
175 test_read_nodemap();
176 } else if (argc == 2 && strcmp(argv[1], "read_ifaces") == 0) {
177 test_read_ifaces();
178 } else if (argc == 2 && strcmp(argv[1], "read_vnnmap") == 0) {
179 test_read_vnnmap();
180 } else if (argc == 2 && strcmp(argv[1], "fake_setup") == 0) {
181 test_fake_setup();
182 } else if (argc == 4 && strcmp(argv[1], "parse_nodestring") == 0) {
183 test_parse_nodestring(argv[2], argv[3]);
184 } else {
185 usage();
188 return 0;