Module Name: src
Committed By: pooka
Date: Mon Jan 24 17:51:29 UTC 2011
Modified Files:
src/tests/rump/rumpkern: t_sp.sh
src/tests/rump/rumpkern/h_client: Makefile
Added Files:
src/tests/rump/rumpkern/h_client: h_reconcli.c
Log Message:
test for rumpclient reconnect feature
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/rump/rumpkern/t_sp.sh
cvs rdiff -u -r1.4 -r1.5 src/tests/rump/rumpkern/h_client/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/rump/rumpkern/h_client/h_reconcli.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/rump/rumpkern/t_sp.sh
diff -u src/tests/rump/rumpkern/t_sp.sh:1.9 src/tests/rump/rumpkern/t_sp.sh:1.10
--- src/tests/rump/rumpkern/t_sp.sh:1.9 Fri Jan 14 13:23:15 2011
+++ src/tests/rump/rumpkern/t_sp.sh Mon Jan 24 17:51:29 2011
@@ -1,4 +1,4 @@
-# $NetBSD: t_sp.sh,v 1.9 2011/01/14 13:23:15 pooka Exp $
+# $NetBSD: t_sp.sh,v 1.10 2011/01/24 17:51:29 pooka Exp $
#
# Copyright (c) 2010 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -49,6 +49,7 @@
test_case fork_fakeauth fork fakeauth
test_case sigsafe sigsafe sigsafe
test_case signal signal
+test_case reconnect reconnect
basic()
{
@@ -92,6 +93,15 @@
atf_check -s signal:27 $(atf_get_srcdir)/h_client/h_simplecli block
}
+reconnect()
+{
+
+
+ export RUMP_SERVER=unix://commsock
+ atf_check -s exit:0 rump_server ${RUMP_SERVER}
+ atf_check -s exit:0 $(atf_get_srcdir)/h_client/h_reconcli 2
+}
+
atf_init_test_cases()
{
@@ -104,4 +114,5 @@
atf_add_test_case fork_fakeauth
atf_add_test_case sigsafe
atf_add_test_case signal
+ atf_add_test_case reconnect
}
Index: src/tests/rump/rumpkern/h_client/Makefile
diff -u src/tests/rump/rumpkern/h_client/Makefile:1.4 src/tests/rump/rumpkern/h_client/Makefile:1.5
--- src/tests/rump/rumpkern/h_client/Makefile:1.4 Thu Jan 6 07:00:28 2011
+++ src/tests/rump/rumpkern/h_client/Makefile Mon Jan 24 17:51:29 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2011/01/06 07:00:28 pooka Exp $
+# $NetBSD: Makefile,v 1.5 2011/01/24 17:51:29 pooka Exp $
#
.include <bsd.own.mk>
@@ -6,6 +6,7 @@
TESTSDIR= ${TESTSBASE}/rump/rumpkern/h_client
TESTS_C+= h_forkcli
+TESTS_C+= h_reconcli
TESTS_C+= h_sigcli
TESTS_C+= h_simplecli
TESTS_C+= h_stresscli
@@ -14,6 +15,7 @@
LDADD+= -lrumpclient
LDADD.h_stresscli= -lpthread
+LDADD.h_reconcli= -lpthread
WARNS= 4
NOMAN=
Added files:
Index: src/tests/rump/rumpkern/h_client/h_reconcli.c
diff -u /dev/null src/tests/rump/rumpkern/h_client/h_reconcli.c:1.1
--- /dev/null Mon Jan 24 17:51:29 2011
+++ src/tests/rump/rumpkern/h_client/h_reconcli.c Mon Jan 24 17:51:29 2011
@@ -0,0 +1,120 @@
+/* $NetBSD: h_reconcli.c,v 1.1 2011/01/24 17:51:29 pooka Exp $ */
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+#include <rump/rumpclient.h>
+#include <rump/rump_syscalls.h>
+
+#include <err.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static volatile int quit, riseandwhine;
+
+static pthread_mutex_t closermtx;
+static pthread_cond_t closercv;
+
+static void *
+closer(void *arg)
+{
+
+ pthread_mutex_lock(&closermtx);
+ while (!quit) {
+ while (!riseandwhine)
+ pthread_cond_wait(&closercv, &closermtx);
+ riseandwhine = 0;
+ pthread_mutex_unlock(&closermtx);
+
+ /* try to catch a random slot */
+ usleep(random() % 100000);
+
+ /*
+ * wide-angle disintegration beam, but takes care
+ * of the client rumpkernel communication socket.
+ */
+ closefrom(3);
+
+ pthread_mutex_lock(&closermtx);
+ }
+ pthread_mutex_unlock(&closermtx);
+
+ return NULL;
+}
+
+static const int hostnamemib[] = { CTL_KERN, KERN_HOSTNAME };
+static char goodhostname[128];
+
+static void *
+worker(void *arg)
+{
+ char hostnamebuf[128];
+ size_t blen;
+
+ pthread_mutex_lock(&closermtx);
+ while (!quit) {
+ pthread_mutex_unlock(&closermtx);
+ if (rump_sys_getpid() == -1)
+ err(1, "getpid");
+
+ blen = sizeof(hostnamebuf);
+ memset(hostnamebuf, 0, sizeof(hostnamebuf));
+ if (rump_sys___sysctl(hostnamemib, __arraycount(hostnamemib),
+ hostnamebuf, &blen, NULL, 0) == -1)
+ err(1, "sysctl");
+ if (strcmp(hostnamebuf, goodhostname) != 0)
+ exit(1);
+ pthread_mutex_lock(&closermtx);
+ riseandwhine = 1;
+ pthread_cond_signal(&closercv);
+ }
+ riseandwhine = 1;
+ pthread_cond_signal(&closercv);
+ pthread_mutex_unlock(&closermtx);
+
+ return NULL;
+}
+
+int
+main(int argc, char *argv[])
+{
+ pthread_t pt, w1, w2, w3, w4;
+ size_t blen;
+ int timecount;
+
+ if (argc != 2)
+ errx(1, "need timecount");
+ timecount = atoi(argv[1]);
+ if (timecount <= 0)
+ errx(1, "invalid timecount %d\n", timecount);
+
+ srandom(time(NULL));
+
+ if (rumpclient_init() == -1)
+ err(1, "init");
+
+ blen = sizeof(goodhostname);
+ if (rump_sys___sysctl(hostnamemib, __arraycount(hostnamemib),
+ goodhostname, &blen, NULL, 0) == -1)
+ err(1, "sysctl");
+
+ pthread_create(&pt, NULL, closer, NULL);
+ pthread_create(&w1, NULL, worker, NULL);
+ pthread_create(&w2, NULL, worker, NULL);
+ pthread_create(&w3, NULL, worker, NULL);
+ pthread_create(&w4, NULL, worker, NULL);
+
+ sleep(timecount);
+ quit = 1;
+
+ pthread_join(pt, NULL);
+ pthread_join(w1, NULL);
+ pthread_join(w2, NULL);
+ pthread_join(w3, NULL);
+ pthread_join(w4, NULL);
+
+ exit(0);
+}