test for rumpclient reconnect feature
This commit is contained in:
parent
19a57922d0
commit
7605725b2b
|
@ -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 @@ ATFFILE= no
|
|||
|
||||
LDADD+= -lrumpclient
|
||||
LDADD.h_stresscli= -lpthread
|
||||
LDADD.h_reconcli= -lpthread
|
||||
|
||||
WARNS= 4
|
||||
NOMAN=
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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_pipecomm fork pipecomm
|
|||
test_case fork_fakeauth fork fakeauth
|
||||
test_case sigsafe sigsafe sigsafe
|
||||
test_case signal signal
|
||||
test_case reconnect reconnect
|
||||
|
||||
basic()
|
||||
{
|
||||
|
@ -92,6 +93,15 @@ signal()
|
|||
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_init_test_cases()
|
|||
atf_add_test_case fork_fakeauth
|
||||
atf_add_test_case sigsafe
|
||||
atf_add_test_case signal
|
||||
atf_add_test_case reconnect
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue