tests: Add a test program to hold a lock on a database
authorAmitay Isaacs <amitay@gmail.com>
Tue, 4 Dec 2012 07:27:10 +0000 (18:27 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Thu, 1 Aug 2013 01:08:26 +0000 (11:08 +1000)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Makefile.in
tests/src/ctdb_lock_tdb.c [new file with mode: 0644]

index 620ed845cd1db9ad1b51e9da76bbab9dbfe9c70a..7bda4d5bb0323db1b7a493005a011fe0e306fa44 100755 (executable)
@@ -120,7 +120,7 @@ TEST_BINS=tests/bin/ctdb_bench tests/bin/ctdb_fetch tests/bin/ctdb_fetch_one \
        tests/bin/ctdb_takeover_tests tests/bin/ctdb_update_record \
        tests/bin/ctdb_update_record_persistent \
        tests/bin/ctdb_tool_libctdb tests/bin/ctdb_tool_stubby \
-       tests/bin/ctdb_porting_tests \
+       tests/bin/ctdb_porting_tests tests/bin/ctdb_lock_tdb \
        @INFINIBAND_BINS@
 
 BINS = bin/ctdb @CTDB_SCSI_IO@ bin/smnotify bin/ping_pong bin/ltdbtool \
@@ -313,6 +313,10 @@ tests/bin/ctdb_tool_stubby: $(CTDB_TEST_OBJ) tests/src/ctdb_tool_stubby.o
        @echo Linking $@
        $(WRAPPER) $(CC) $(CFLAGS) -o $@ tests/src/ctdb_tool_stubby.o $(CTDB_TEST_OBJ) $(POPT_OBJ) $(LIB_FLAGS)
 
+tests/bin/ctdb_lock_tdb: tests/src/ctdb_lock_tdb.o @TDB_OBJ@
+       @echo Linking $@
+       $(WRAPPER) $(CC) $(CFLAGS) -o $@ $^ $(LIB_FLAGS)
+
 tests/bin/ibwrapper_test: $(CTDB_CLIENT_OBJ) ib/ibwrapper_test.o
        @echo Linking $@
        $(WRAPPER) $(CC) $(CFLAGS) -o $@ ib/ibwrapper_test.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
diff --git a/tests/src/ctdb_lock_tdb.c b/tests/src/ctdb_lock_tdb.c
new file mode 100644 (file)
index 0000000..ad2a329
--- /dev/null
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "includes.h"
+
+const char *tdb_file;
+TDB_CONTEXT *tdb;
+
+void signal_handler(int signum)
+{
+       tdb_close(tdb);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+       if (argc != 2) {
+               printf("Usage: %s <tdb file>\n", argv[0]);
+               exit(1);
+       }
+
+       tdb_file = argv[1];
+
+       tdb = tdb_open(tdb_file, 0, 0, O_RDWR, 0);
+       if (tdb == NULL) {
+               fprintf(stderr, "Failed to open TDB file %s\n", tdb_file);
+               exit(1);
+       }
+
+       signal(SIGINT, signal_handler);
+
+       if (tdb_lockall(tdb) != 0) {
+               fprintf(stderr, "Failed to lock database %s\n", tdb_file);
+               tdb_close(tdb);
+               exit(1);
+       }
+
+       sleep(999999);
+
+       return 0;
+}