summaryrefslogtreecommitdiff
path: root/source4/cluster/ctdb/tests
diff options
context:
space:
mode:
Diffstat (limited to 'source4/cluster/ctdb/tests')
-rwxr-xr-xsource4/cluster/ctdb/tests/bench.sh6
-rwxr-xr-xsource4/cluster/ctdb/tests/bench1.sh3
-rw-r--r--source4/cluster/ctdb/tests/ctdb_bench.c51
-rw-r--r--source4/cluster/ctdb/tests/ctdb_fetch.c26
-rw-r--r--source4/cluster/ctdb/tests/ctdb_fetch1.c97
-rw-r--r--source4/cluster/ctdb/tests/ctdb_messaging.c7
-rw-r--r--source4/cluster/ctdb/tests/ctdb_test.c13
-rwxr-xr-xsource4/cluster/ctdb/tests/fetch.sh12
-rwxr-xr-xsource4/cluster/ctdb/tests/fetch1.sh5
-rw-r--r--source4/cluster/ctdb/tests/lockwait.c245
-rwxr-xr-xsource4/cluster/ctdb/tests/messaging.sh3
-rwxr-xr-xsource4/cluster/ctdb/tests/test.sh40
-rwxr-xr-xsource4/cluster/ctdb/tests/test1.sh7
13 files changed, 384 insertions, 131 deletions
diff --git a/source4/cluster/ctdb/tests/bench.sh b/source4/cluster/ctdb/tests/bench.sh
index 50e9e08f99..3d0696f171 100755
--- a/source4/cluster/ctdb/tests/bench.sh
+++ b/source4/cluster/ctdb/tests/bench.sh
@@ -3,7 +3,7 @@
killall -q ctdb_bench
echo "Trying 2 nodes"
-bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.2:9001 $* &
-bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.1:9001 $*
+$VALGRIND bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.2:9001 $* &
+$VALGRIND bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.1:9001 $*
+wait
-killall -q ctdb_bench
diff --git a/source4/cluster/ctdb/tests/bench1.sh b/source4/cluster/ctdb/tests/bench1.sh
index 3481d82be2..9adcf3198b 100755
--- a/source4/cluster/ctdb/tests/bench1.sh
+++ b/source4/cluster/ctdb/tests/bench1.sh
@@ -4,5 +4,4 @@ killall -q ctdb_bench
echo "Trying 1 nodes"
bin/ctdb_bench --nlist tests/1node.txt --listen 127.0.0.2:9001 $*
-
-killall -q ctdb_bench
+wait
diff --git a/source4/cluster/ctdb/tests/ctdb_bench.c b/source4/cluster/ctdb/tests/ctdb_bench.c
index 37c095c0c0..02fcc1f2d4 100644
--- a/source4/cluster/ctdb/tests/ctdb_bench.c
+++ b/source4/cluster/ctdb/tests/ctdb_bench.c
@@ -22,7 +22,7 @@
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
#include <sys/time.h>
#include <time.h>
@@ -45,7 +45,6 @@ static double end_timer(void)
static int timelimit = 10;
static int num_records = 10;
static int num_msgs = 1;
-static int num_repeats = 100;
enum my_functions {FUNC_INCR=1, FUNC_FETCH=2};
@@ -78,51 +77,6 @@ static int fetch_func(struct ctdb_call_info *call)
return 0;
}
-/*
- benchmark incrementing an integer
-*/
-static void bench_incr(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db)
-{
- int loops=0;
- int ret, i;
- struct ctdb_call call;
-
- ZERO_STRUCT(call);
-
- start_timer();
-
- while (1) {
- uint32_t v = loops % num_records;
-
- call.call_id = FUNC_INCR;
- call.key.dptr = (uint8_t *)&v;
- call.key.dsize = 4;
-
- for (i=0;i<num_repeats;i++) {
- ret = ctdb_call(ctdb_db, &call);
- if (ret != 0) {
- printf("incr call failed - %s\n", ctdb_errstr(ctdb));
- return;
- }
- }
- if (num_repeats * (++loops) % 10000 == 0) {
- if (end_timer() > timelimit) break;
- printf("Incr: %.2f ops/sec\r", num_repeats*loops/end_timer());
- fflush(stdout);
- }
- }
-
- call.call_id = FUNC_FETCH;
-
- ret = ctdb_call(ctdb_db, &call);
- if (ret == -1) {
- printf("ctdb_call FUNC_FETCH failed - %s\n", ctdb_errstr(ctdb));
- return;
- }
-
- printf("Incr: %.2f ops/sec (loops=%d val=%d)\n",
- num_repeats*loops/end_timer(), loops, *(uint32_t *)call.reply_data.dptr);
-}
static int msg_count;
static int msg_plus, msg_minus;
@@ -259,6 +213,7 @@ int main(int argc, const char *argv[])
bench_ring(ctdb, ev);
/* shut it down */
- talloc_free(ctdb);
+ ctdb_shutdown(ctdb);
+
return 0;
}
diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c
index febaf13fe4..39bd861fc1 100644
--- a/source4/cluster/ctdb/tests/ctdb_fetch.c
+++ b/source4/cluster/ctdb/tests/ctdb_fetch.c
@@ -22,7 +22,7 @@
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
#include <sys/time.h>
#include <time.h>
@@ -58,18 +58,18 @@ static int msg_count;
static void bench_fetch_1node(struct ctdb_context *ctdb)
{
TDB_DATA key, data, nulldata;
- struct ctdb_record_handle *rec;
struct ctdb_db_context *ctdb_db;
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
int dest, ret;
+ struct ctdb_record_handle *h;
- key.dptr = discard_const("testkey");
- key.dsize = strlen((const char *)key.dptr);
+ key.dptr = discard_const(TESTKEY);
+ key.dsize = strlen(TESTKEY);
ctdb_db = ctdb_db_handle(ctdb, "test.tdb");
- rec = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data);
- if (rec == NULL) {
+ h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data);
+ if (h == NULL) {
printf("Failed to fetch record '%s' on node %d\n",
(const char *)key.dptr, ctdb_get_vnn(ctdb));
talloc_free(tmp_ctx);
@@ -88,7 +88,8 @@ static void bench_fetch_1node(struct ctdb_context *ctdb)
msg_count, ctdb_get_vnn(ctdb));
data.dsize = strlen((const char *)data.dptr)+1;
- ret = ctdb_store_unlock(rec, data);
+ ret = ctdb_record_store(h, data);
+ talloc_free(h);
if (ret != 0) {
printf("Failed to store record\n");
}
@@ -141,6 +142,10 @@ static void bench_fetch(struct ctdb_context *ctdb, struct event_context *ev)
printf("Event loop failed!\n");
break;
}
+
+ if (LogLevel > 9) {
+ talloc_report_null_full();
+ }
}
printf("Fetch: %.2f msgs/sec\n", msg_count/end_timer());
@@ -192,6 +197,8 @@ int main(int argc, const char *argv[])
}
}
+ /* talloc_enable_leak_report_full(); */
+
/* setup the remaining options for the main program to use */
extra_argv = poptGetArgs(pc);
if (extra_argv) {
@@ -240,7 +247,8 @@ int main(int argc, const char *argv[])
printf("DATA:\n%s\n", (char *)call.reply_data.dptr);
- /* shut it down */
- talloc_free(ctdb);
+ /* go into a wait loop to allow other nodes to complete */
+ ctdb_shutdown(ctdb);
+
return 0;
}
diff --git a/source4/cluster/ctdb/tests/ctdb_fetch1.c b/source4/cluster/ctdb/tests/ctdb_fetch1.c
index ffe9c7c946..b92e7fcda3 100644
--- a/source4/cluster/ctdb/tests/ctdb_fetch1.c
+++ b/source4/cluster/ctdb/tests/ctdb_fetch1.c
@@ -24,7 +24,8 @@
#include "popt.h"
#include "ctdb.h"
#include "ctdb_private.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
+#include <sys/time.h>
#define PARENT_SRVID 0
#define CHILD1_SRVID 1
@@ -32,6 +33,20 @@
int num_msg=0;
+static struct timeval tp1,tp2;
+
+static void start_timer(void)
+{
+ gettimeofday(&tp1,NULL);
+}
+
+static double end_timer(void)
+{
+ gettimeofday(&tp2,NULL);
+ return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) -
+ (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
+}
+
static void message_handler(struct ctdb_context *ctdb, uint32_t srvid,
TDB_DATA data, void *private_data)
{
@@ -45,9 +60,9 @@ static void child_handler(struct ctdb_context *ctdb, uint32_t srvid,
void test1(struct ctdb_db_context *ctdb_db)
{
- struct ctdb_record_handle *rh;
TDB_DATA key, data, data2, store_data;
int ret;
+ struct ctdb_record_handle *h;
/*
test 1 : write data and read it back. should all be the same
@@ -55,13 +70,27 @@ void test1(struct ctdb_db_context *ctdb_db)
printf("Test1: write and verify we can read it back: ");
key.dptr = discard_const("Record");
key.dsize = strlen((const char *)key.dptr)+1;
- rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data);
+ h = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data);
+ if (h == NULL) {
+ printf("test1: ctdb_fetch_lock() failed\n");
+ exit(1);
+ }
store_data.dptr = discard_const("data to store");
store_data.dsize = strlen((const char *)store_data.dptr)+1;
- ret = ctdb_store_unlock(rh, store_data);
+ ret = ctdb_record_store(h, store_data);
+ talloc_free(h);
+ if (ret!=0) {
+ printf("test1: ctdb_record_store() failed\n");
+ exit(1);
+ }
+
+ h = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2);
+ if (h == NULL) {
+ printf("test1: ctdb_fetch_lock() failed\n");
+ exit(1);
+ }
- rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2);
/* hopefully data2 will now contain the record written above */
if (!strcmp("data to store", (const char *)data2.dptr)) {
printf("SUCCESS\n");
@@ -71,14 +100,19 @@ void test1(struct ctdb_db_context *ctdb_db)
}
/* just write it back to unlock it */
- ret = ctdb_store_unlock(rh, store_data);
+ ret = ctdb_record_store(h, store_data);
+ talloc_free(h);
+ if (ret!=0) {
+ printf("test1: ctdb_record_store() failed\n");
+ exit(1);
+ }
}
void child(int srvid, struct event_context *ev, struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db)
{
TDB_DATA data;
- struct ctdb_record_handle *rh;
TDB_DATA key, data2;
+ struct ctdb_record_handle *h;
data.dptr=discard_const("dummy message");
data.dsize=strlen((const char *)data.dptr)+1;
@@ -94,13 +128,23 @@ void child(int srvid, struct event_context *ev, struct ctdb_context *ctdb, struc
/* fetch and lock the record */
key.dptr = discard_const("Record");
key.dsize = strlen((const char *)key.dptr)+1;
- rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2);
+ printf("client:%d fetching the record\n",srvid);
+ h = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2);
+ printf("client:%d the record is fetched and locked\n",srvid);
+ if (h == NULL) {
+ printf("client: ctdb_fetch_lock() failed\n");
+ exit(1);
+ }
ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), PARENT_SRVID, data);
-
- while (1) {
+ /* wait until parent tells us to release the lock */
+ while (num_msg==1) {
event_loop_once(ev);
}
+
+ printf("child %d terminating\n",srvid);
+ exit(10);
+
}
/*
@@ -204,29 +248,48 @@ int main(int argc, const char *argv[])
*/
data.dptr=discard_const("dummy message");
data.dsize=strlen((const char *)data.dptr)+1;
- printf("Send message to child 1 to fetch_lock the record\n");
ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD1_SRVID, data);
/* wait for child 1 to complete fetching and locking the record */
while (num_msg!=3) {
event_loop_once(ev);
}
- printf("Child 1 has fetched and locked the record\n");
/* now tell child 2 to fetch and lock the same record */
- printf("Send message to child 2 to fetch_lock the record\n");
ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD2_SRVID, data);
- /* wait for child 2 to complete fetching and locking the record */
- while (num_msg!=4) {
+ /* wait a while for child 2 to complete fetching and locking the
+ record, this should fail since the record is already locked
+ by the first child */
+ start_timer();
+ while ( (end_timer() < 1.0) && (num_msg!=4) ) {
event_loop_once(ev);
}
- printf("Child 2 has fetched and locked the record\n");
+ if (num_msg!=4) {
+ printf("Child 2 did not get the lock since it is held by client 1:SUCCESS\n");
+ } else {
+ printf("Child 2 did get the lock:FAILURE\n");
+ exit(10);
+ }
+ /* send message to child 1 to terminate, which should let child 2
+ get the lock.
+ */
+ ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD1_SRVID, data);
- while (1) {
+
+ /* wait for a final message from child 2 it has received the lock
+ which indicates success */
+ while (num_msg!=4) {
event_loop_once(ev);
}
+ printf("child 2 aquired the lock after child 1 terminated:SUCCESS\n");
+
+ /* send a message to child 2 to tell it to terminate too */
+ ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD2_SRVID, data);
+
+
+ printf("Test was SUCCESSFUL\n");
/* shut it down */
talloc_free(ctdb);
diff --git a/source4/cluster/ctdb/tests/ctdb_messaging.c b/source4/cluster/ctdb/tests/ctdb_messaging.c
index d02c2116e8..e7057b64fb 100644
--- a/source4/cluster/ctdb/tests/ctdb_messaging.c
+++ b/source4/cluster/ctdb/tests/ctdb_messaging.c
@@ -22,7 +22,7 @@
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
static int timelimit = 10;
static int num_records = 10;
@@ -130,7 +130,7 @@ int main(int argc, const char *argv[])
for (j=0;j<num_clients;j++) {
printf("sending message to %d:%d\n", i, j);
sprintf(buf,"Message from %d to vnn:%d srvid:%d",ctdb_get_vnn(ctdb),i,j);
- data.dptr=buf;
+ data.dptr = (unsigned char *)buf;
data.dsize=strlen(buf)+1;
ctdb_send_message(ctdb, i, j, data);
}
@@ -141,6 +141,7 @@ int main(int argc, const char *argv[])
}
/* shut it down */
- talloc_free(ctdb);
+ ctdb_shutdown(ctdb);
+
return 0;
}
diff --git a/source4/cluster/ctdb/tests/ctdb_test.c b/source4/cluster/ctdb/tests/ctdb_test.c
index 8125cc4490..dec1ea5100 100644
--- a/source4/cluster/ctdb/tests/ctdb_test.c
+++ b/source4/cluster/ctdb/tests/ctdb_test.c
@@ -22,7 +22,7 @@
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
enum my_functions {FUNC_SORT=1, FUNC_FETCH=2};
@@ -133,6 +133,8 @@ int main(int argc, const char *argv[])
/* start the protocol running */
ret = ctdb_start(ctdb);
+ ctdb_connect_wait(ctdb);
+
ZERO_STRUCT(call);
call.key.dptr = discard_const("test");
call.key.dsize = strlen("test")+1;
@@ -169,14 +171,7 @@ int main(int argc, const char *argv[])
talloc_free(call.reply_data.dptr);
/* go into a wait loop to allow other nodes to complete */
- ctdb_wait_loop(ctdb);
-
- /*talloc_report_full(ctdb, stdout);*/
-
-/* sleep for a while so that our daemon will remaining alive for the other nodes in the cluster */
-sleep(10);
+ ctdb_shutdown(ctdb);
- /* shut it down */
- talloc_free(ctdb);
return 0;
}
diff --git a/source4/cluster/ctdb/tests/fetch.sh b/source4/cluster/ctdb/tests/fetch.sh
index ba043e17c5..73192e70ae 100755
--- a/source4/cluster/ctdb/tests/fetch.sh
+++ b/source4/cluster/ctdb/tests/fetch.sh
@@ -3,7 +3,13 @@
killall -q ctdb_fetch
echo "Trying 2 nodes"
-bin/ctdb_fetch --nlist tests/nodes.txt --listen 127.0.0.2:9001 $* &
-bin/ctdb_fetch --nlist tests/nodes.txt --listen 127.0.0.1:9001 $*
+$VALGRIND bin/ctdb_fetch --nlist tests/nodes.txt --listen 127.0.0.2:9001 $* &
+$VALGRIND bin/ctdb_fetch --nlist tests/nodes.txt --listen 127.0.0.1:9001 $*
+wait
-killall -q ctdb_fetch
+echo "Trying 4 nodes"
+$VALGRIND bin/ctdb_fetch --nlist tests/4nodes.txt --listen 127.0.0.4:9001 $* &
+$VALGRIND bin/ctdb_fetch --nlist tests/4nodes.txt --listen 127.0.0.3:9001 $* &
+$VALGRIND bin/ctdb_fetch --nlist tests/4nodes.txt --listen 127.0.0.2:9001 $* &
+$VALGRIND bin/ctdb_fetch --nlist tests/4nodes.txt --listen 127.0.0.1:9001 $*
+wait
diff --git a/source4/cluster/ctdb/tests/fetch1.sh b/source4/cluster/ctdb/tests/fetch1.sh
index 4331a57d3e..db584ec012 100755
--- a/source4/cluster/ctdb/tests/fetch1.sh
+++ b/source4/cluster/ctdb/tests/fetch1.sh
@@ -3,6 +3,5 @@
killall -q ctdb_fetch1
echo "Trying node"
-bin/ctdb_fetch1 --nlist tests/1node.txt --listen 127.0.0.1:9001 --daemon $*
-
-killall -q ctdb_fetch1
+bin/ctdb_fetch1 --nlist tests/1node.txt --listen 127.0.0.1:9001 $*
+wait
diff --git a/source4/cluster/ctdb/tests/lockwait.c b/source4/cluster/ctdb/tests/lockwait.c
new file mode 100644
index 0000000000..51f88c1168
--- /dev/null
+++ b/source4/cluster/ctdb/tests/lockwait.c
@@ -0,0 +1,245 @@
+/*
+ test a lock wait idea
+
+ Copyright (C) Andrew Tridgell 2006
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "includes.h"
+#include "lib/events/events.h"
+#include "system/filesys.h"
+#include "system/wait.h"
+#include "popt.h"
+#include "cmdline.h"
+
+
+struct lockwait_handle {
+ struct fd_event *fde;
+ int fd[2];
+ pid_t child;
+ void *private_data;
+ void (*callback)(void *);
+};
+
+static void lockwait_handler(struct event_context *ev, struct fd_event *fde,
+ uint16_t flags, void *private_data)
+{
+ struct lockwait_handle *h = talloc_get_type(private_data,
+ struct lockwait_handle);
+ void (*callback)(void *) = h->callback;
+ void *p = h->private_data;
+ talloc_set_destructor(h, NULL);
+ close(h->fd[0]);
+ talloc_free(h);
+ callback(p);
+ waitpid(h->child, NULL, 0);
+}
+
+static int lockwait_destructor(struct lockwait_handle *h)
+{
+ close(h->fd[0]);
+ kill(h->child, SIGKILL);
+ waitpid(h->child, NULL, 0);
+ return 0;
+}
+
+
+static struct lockwait_handle *lockwait(struct event_context *ev,
+ TALLOC_CTX *mem_ctx,
+ int fd, off_t ofs, size_t len,
+ void (*callback)(void *), void *private_data)
+{
+ struct lockwait_handle *h;
+ int ret;
+
+ h = talloc_zero(mem_ctx, struct lockwait_handle);
+ if (h == NULL) {
+ return NULL;
+ }
+
+ ret = pipe(h->fd);
+ if (ret != 0) {
+ talloc_free(h);
+ return NULL;
+ }
+
+ h->child = fork();
+ if (h->child == (pid_t)-1) {
+ close(h->fd[0]);
+ close(h->fd[1]);
+ talloc_free(h);
+ return NULL;
+ }
+
+ h->callback = callback;
+ h->private_data = private_data;
+
+ if (h->child == 0) {
+ /* in child */
+ struct flock lock;
+ close(h->fd[0]);
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = ofs;
+ lock.l_len = len;
+ lock.l_pid = 0;
+ fcntl(fd,F_SETLKW,&lock);
+ _exit(0);
+ }
+
+ close(h->fd[1]);
+ talloc_set_destructor(h, lockwait_destructor);
+
+ h->fde = event_add_fd(ev, h, h->fd[0], EVENT_FD_READ, lockwait_handler, h);
+ if (h->fde == NULL) {
+ talloc_free(h);
+ return NULL;
+ }
+
+ return h;
+}
+
+
+
+
+static void fcntl_lock_callback(void *p)
+{
+ int *got_lock = (int *)p;
+ *got_lock = 1;
+}
+
+/*
+ get an fcntl lock - waiting if necessary
+ */
+static int fcntl_lock(struct event_context *ev,
+ int fd, int op, off_t offset, off_t count, int type)
+{
+ struct flock lock;
+ int ret;
+ int use_lockwait = (op == F_SETLKW);
+ int got_lock = 0;
+
+ lock.l_type = type;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = offset;
+ lock.l_len = count;
+ lock.l_pid = 0;
+
+ do {
+ ret = fcntl(fd,use_lockwait?F_SETLK:op,&lock);
+ if (ret == 0) {
+ return 0;
+ }
+ if (ret == -1 &&
+ (errno == EACCES || errno == EAGAIN || errno == EDEADLK)) {
+ struct lockwait_handle *h;
+ h = lockwait(ev, ev, fd, offset, count,
+ fcntl_lock_callback, &got_lock);
+ if (h == NULL) {
+ errno = ENOLCK;
+ return -1;
+ }
+ /* in real code we would return to the event loop */
+ while (!got_lock) {
+ event_loop_once(ev);
+ }
+ got_lock = 0;
+ }
+ } while (!got_lock);
+
+ return ret;
+}
+
+static void child(struct event_context *ev, int n)
+{
+ int fd;
+ int count=0;
+ struct timeval tv;
+ fd = open("test.dat", O_CREAT|O_RDWR, 0666);
+ if (fd == -1) {
+ perror("test.dat");
+ exit(1);
+ }
+
+ tv = timeval_current();
+
+ while (timeval_elapsed(&tv) < 10) {
+ int ret;
+ ret = fcntl_lock(ev, fd, F_SETLKW, 0, 1, F_WRLCK);
+ if (ret != 0) {
+ printf("Failed to get lock in child %d!\n", n);
+ break;
+ }
+ fcntl_lock(ev, fd, F_SETLK, 0, 1, F_UNLCK);
+ count++;
+ }
+
+ printf("child %2d %.0f ops/sec\n", n, count/timeval_elapsed(&tv));
+ _exit(0);
+}
+
+static int timelimit = 10;
+
+/*
+ main program
+*/
+int main(int argc, const char *argv[])
+{
+ pid_t *pids;
+ int nprogs = 2;
+ int i;
+ struct event_context *ev;
+ struct poptOption popt_options[] = {
+ POPT_AUTOHELP
+ { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
+ { "num-progs", 'n', POPT_ARG_INT, &nprogs, 0, "num_progs", "integer" },
+ POPT_TABLEEND
+ };
+ poptContext pc;
+ int opt;
+
+ pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
+
+ while ((opt = poptGetNextOpt(pc)) != -1) {
+ switch (opt) {
+ default:
+ fprintf(stderr, "Invalid option %s: %s\n",
+ poptBadOption(pc, 0), poptStrerror(opt));
+ exit(1);
+ }
+ }
+
+ ev = event_context_init(NULL);
+
+ pids = talloc_array(ev, pid_t, nprogs);
+
+ /* create N processes fighting over the same lock */
+ for (i=0;i<nprogs;i++) {
+ pids[i] = fork();
+ if (pids[i] == 0) {
+ child(ev, i);
+ }
+ }
+
+ printf("Waiting for %d children ...\n", nprogs);
+
+ /* wait for our kids to finish playing */
+ for (i=0;i<nprogs;i++) {
+ waitpid(pids[i], NULL, 0);
+ }
+
+ return 0;
+}
diff --git a/source4/cluster/ctdb/tests/messaging.sh b/source4/cluster/ctdb/tests/messaging.sh
index 179a2bef88..46f3e4dc77 100755
--- a/source4/cluster/ctdb/tests/messaging.sh
+++ b/source4/cluster/ctdb/tests/messaging.sh
@@ -5,5 +5,4 @@ killall -q ctdb_messaging
echo "Trying 2 nodes"
bin/ctdb_messaging --nlist tests/nodes.txt --listen 127.0.0.2:9001 $* &
bin/ctdb_messaging --nlist tests/nodes.txt --listen 127.0.0.1:9001 $*
-
-killall -q ctdb_messaging
+wait
diff --git a/source4/cluster/ctdb/tests/test.sh b/source4/cluster/ctdb/tests/test.sh
index 6197ce9616..23fdb8d6ce 100755
--- a/source4/cluster/ctdb/tests/test.sh
+++ b/source4/cluster/ctdb/tests/test.sh
@@ -3,33 +3,15 @@
killall -q ctdb_test
-echo "Trying 2 nodes"
-bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.1:9001 &
-bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.2:9001 &
+echo "Trying 2 nodes ..."
+$VALGRIND bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.1:9001 &
+$VALGRIND bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.2:9001
+wait
+
+echo "Trying 4 nodes ..."
+$VALGRIND bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.1:9001 &
+$VALGRIND bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.2:9001 &
+$VALGRIND bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.3:9001 &
+$VALGRIND bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.4:9001
+wait
-sleep 3
-killall ctdb_test
-
-echo "Trying 4 nodes"
-bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.1:9001 &
-bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.2:9001 &
-bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.3:9001 &
-bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.4:9001 &
-sleep 3
-
-killall ctdb_test
-
-echo "Trying 2 nodes in daemon mode"
-bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.1:9001 --daemon &
-bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.2:9001 --daemon &
-
-sleep 3
-killall ctdb_test
-
-echo "Trying 4 nodes in daemon mode"
-bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.1:9001 --daemon &
-bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.2:9001 --daemon &
-bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.3:9001 --daemon &
-bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.4:9001 --daemon &
-sleep 3
-killall ctdb_test
diff --git a/source4/cluster/ctdb/tests/test1.sh b/source4/cluster/ctdb/tests/test1.sh
index 64d5c9fc87..42256f22f9 100755
--- a/source4/cluster/ctdb/tests/test1.sh
+++ b/source4/cluster/ctdb/tests/test1.sh
@@ -1,8 +1,9 @@
#!/bin/sh
-echo "Testing local send"
-bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001
echo "Testing daemon mode"
-bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 --daemon
+bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001
+wait
+
echo "Testing self connect"
bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 --self-connect
+wait