summaryrefslogtreecommitdiffstats
path: root/ctdb/tests/src
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2011-12-13 16:48:10 +1100
committerMartin Schwenke <martin@meltin.net>2012-02-06 16:00:23 +1100
commit4bf69a0fffc716d650167d28dfb7fbcd96f5ed37 (patch)
tree51a5ba198d6186e6b0acc970d5c84afceaac9bfc /ctdb/tests/src
parentea22ce5c720043b91c2995c00bd8bbdc6b993c53 (diff)
downloadsamba-4bf69a0fffc716d650167d28dfb7fbcd96f5ed37.tar.gz
samba-4bf69a0fffc716d650167d28dfb7fbcd96f5ed37.tar.xz
samba-4bf69a0fffc716d650167d28dfb7fbcd96f5ed37.zip
Tests - more libctdb stub test infrastructure
Signed-off-by: Martin Schwenke <martin@meltin.net> (This used to be ctdb commit 25a0136bd773e7ed8dfda635471f0498d4a7afe9)
Diffstat (limited to 'ctdb/tests/src')
-rw-r--r--ctdb/tests/src/ctdb_tool_libctdb.c63
-rw-r--r--ctdb/tests/src/libctdb_test.c26
2 files changed, 86 insertions, 3 deletions
diff --git a/ctdb/tests/src/ctdb_tool_libctdb.c b/ctdb/tests/src/ctdb_tool_libctdb.c
index 6d66054566a..0f7088574bb 100644
--- a/ctdb/tests/src/ctdb_tool_libctdb.c
+++ b/ctdb/tests/src/ctdb_tool_libctdb.c
@@ -30,6 +30,63 @@ static void test_read_nodemap(void)
ctdb_disconnect(ctdb);
}
+static void test_read_ifaces(void)
+{
+ struct ctdb_connection *ctdb = ctdb_connect("foo", NULL, NULL);
+
+ libctdb_test_read_ifaces(ctdb);
+ libctdb_test_print_ifaces(ctdb);
+
+ ctdb_disconnect(ctdb);
+}
+
+static void test_read_vnnmap(void)
+{
+ struct ctdb_connection *ctdb = ctdb_connect("foo", NULL, NULL);
+
+ libctdb_test_read_vnnmap(ctdb);
+ libctdb_test_print_vnnmap(ctdb);
+
+ ctdb_disconnect(ctdb);
+}
+
+static void test_fake_setup(void)
+{
+ bool first = true;
+ struct ctdb_connection *ctdb = ctdb_connect("foo", NULL, NULL);
+
+ libctdb_test_fake_setup(ctdb);
+
+ if (ctdb->nodemap != NULL) {
+ if (!first) {
+ printf("\n");
+ }
+ printf("NODEMAP\n");
+ libctdb_test_print_nodemap(ctdb);
+ first = false;
+ }
+
+ if (ctdb->ifaces != NULL) {
+ if (!first) {
+ printf("\n");
+ }
+ printf("IFACES\n");
+ libctdb_test_print_ifaces(ctdb);
+ first = false;
+ }
+
+ if (ctdb->vnnmap != NULL) {
+ if (!first) {
+ printf("\n");
+ }
+ printf("VNNMAP\n");
+ libctdb_test_print_vnnmap(ctdb);
+ first = false;
+ }
+
+ ctdb_disconnect(ctdb);
+}
+
static const char * decode_pnn_mode(uint32_t pnn_mode)
{
int i;
@@ -117,6 +174,12 @@ int main(int argc, const char *argv[])
if (argc == 2 && strcmp(argv[1], "read_nodemap") == 0) {
test_read_nodemap();
+ } else if (argc == 2 && strcmp(argv[1], "read_ifaces") == 0) {
+ test_read_ifaces();
+ } else if (argc == 2 && strcmp(argv[1], "read_vnnmap") == 0) {
+ test_read_vnnmap();
+ } else if (argc == 2 && strcmp(argv[1], "fake_setup") == 0) {
+ test_fake_setup();
} else if (argc == 4 && strcmp(argv[1], "parse_nodestring") == 0) {
test_parse_nodestring(argv[2], argv[3]);
} else {
diff --git a/ctdb/tests/src/libctdb_test.c b/ctdb/tests/src/libctdb_test.c
index 61bb41bbbba..8bedb4bfe99 100644
--- a/ctdb/tests/src/libctdb_test.c
+++ b/ctdb/tests/src/libctdb_test.c
@@ -20,6 +20,8 @@
#include <syslog.h>
#include "ctdb.h"
+#define LIBCTDB_TEST_FAKESTATE "fakestate"
+
/* Can't use the real definition, since including libctdb_private.h
* causes macro conflicts */
struct ctdb_connection {
@@ -50,6 +52,7 @@ void libctdb_test_read_nodemap(struct ctdb_connection *ctdb)
(line[0] != '\n')) {
uint32_t pnn, flags;
char *tok, *t;
+ ctdb_sock_addr saddr;
/* Get rid of pesky newline */
if ((t = strchr(line, '\n')) != NULL) {
@@ -59,15 +62,26 @@ void libctdb_test_read_nodemap(struct ctdb_connection *ctdb)
/* Get PNN */
tok = strtok(line, " \t");
if (tok == NULL) {
- DEBUG(DEBUG_ERR, (__location__ " WARNING, bad line ignoed \"%s\"\n", line));
+ DEBUG(DEBUG_ERR, (__location__ " WARNING, bad line (PNN) ignored \"%s\"\n", line));
continue;
}
pnn = (uint32_t)strtoul(tok, NULL, 0);
+ /* Get IP */
+ tok = strtok(NULL, " \t");
+ if (tok == NULL) {
+ DEBUG(DEBUG_ERR, (__location__ " WARNING, bad line (no IP) ignored \"%s\"\n", line));
+ continue;
+ }
+ if (!parse_ip(tok, NULL, 0, &saddr)) {
+ DEBUG(DEBUG_ERR, (__location__ " WARNING, bad line (IP) ignored \"%s\"\n", line));
+ continue;
+ }
+
/* Get flags */
tok = strtok(NULL, " \t");
if (tok == NULL) {
- DEBUG(DEBUG_ERR, (__location__ " WARNING, bad line ignored \"%s\"\n", line));
+ DEBUG(DEBUG_ERR, (__location__ " WARNING, bad line (flags) ignored \"%s\"\n", line));
continue;
}
flags = (uint32_t)strtoul(tok, NULL, 0);
@@ -90,6 +104,7 @@ void libctdb_test_read_nodemap(struct ctdb_connection *ctdb)
ctdb->nodemap->nodes[ctdb->nodemap->num].pnn = pnn;
ctdb->nodemap->nodes[ctdb->nodemap->num].flags = flags;
+ memcpy(&(ctdb->nodemap->nodes[ctdb->nodemap->num].addr), &saddr, sizeof(ctdb_sock_addr));
ctdb->nodemap->num++;
}
}
@@ -143,7 +158,7 @@ void libctdb_test_read_ifaces(struct ctdb_connection *ctdb)
//tok = strtok(line, ":"); /* Leading colon... */
tok = strtok(line, ":");
if (tok == NULL) {
- DEBUG(DEBUG_ERR, (__location__ " WARNING, bad line ignoed \"%s\"\n", line));
+ DEBUG(DEBUG_ERR, (__location__ " WARNING, bad line ignored \"%s\"\n", line));
continue;
}
name = tok;
@@ -401,6 +416,11 @@ struct ctdb_connection *ctdb_connect(const char *addr,
ctdb->ifaces = NULL;
ctdb->vnnmap = NULL;
+ /* Don't always fake up the state... but do it on request */
+ if (strcmp(addr, LIBCTDB_TEST_FAKESTATE) == 0) {
+ libctdb_test_fake_setup(ctdb);
+ }
+
return ctdb;
}