Module Name: src Committed By: pooka Date: Tue Nov 30 22:09:15 UTC 2010
Modified Files: src/tests/rump/rumpkern: Makefile Added Files: src/tests/rump/rumpkern: t_sp.sh src/tests/rump/rumpkern/h_client: Makefile h_reboot.c h_simplecli.c h_stresscli.c src/tests/rump/rumpkern/h_server: Makefile h_simpleserver.c Log Message: Add a simple and stress test cases for the rump remote syscall code. Fun fact: since the server daemonizes into its own process group, it's not in atf's pgrp. Use rump_sys_reboot() in atf cleanup to kill the server after the test. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/rump/rumpkern/Makefile cvs rdiff -u -r0 -r1.1 src/tests/rump/rumpkern/t_sp.sh cvs rdiff -u -r0 -r1.1 src/tests/rump/rumpkern/h_client/Makefile \ src/tests/rump/rumpkern/h_client/h_reboot.c \ src/tests/rump/rumpkern/h_client/h_simplecli.c \ src/tests/rump/rumpkern/h_client/h_stresscli.c cvs rdiff -u -r0 -r1.1 src/tests/rump/rumpkern/h_server/Makefile \ src/tests/rump/rumpkern/h_server/h_simpleserver.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/Makefile diff -u src/tests/rump/rumpkern/Makefile:1.9 src/tests/rump/rumpkern/Makefile:1.10 --- src/tests/rump/rumpkern/Makefile:1.9 Tue Nov 9 15:25:19 2010 +++ src/tests/rump/rumpkern/Makefile Tue Nov 30 22:09:15 2010 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.9 2010/11/09 15:25:19 pooka Exp $ +# $NetBSD: Makefile,v 1.10 2010/11/30 22:09:15 pooka Exp $ .include <bsd.own.mk> @@ -12,6 +12,10 @@ TESTS_C+= t_tsleep TESTS_C+= t_vm +TESTS_SH= t_sp + +SUBDIR+= h_server h_client + ADD_TO_LD= -lrumpvfs -lrump -lrumpuser -lpthread LDADD.t_modlinkset+= -lukfs -lrumpdev_disk -lrumpdev -lrumpfs_msdos LDADD.t_modlinkset+= -lrumpfs_cd9660 ${ADD_TO_LD} Added files: Index: src/tests/rump/rumpkern/t_sp.sh diff -u /dev/null src/tests/rump/rumpkern/t_sp.sh:1.1 --- /dev/null Tue Nov 30 22:09:15 2010 +++ src/tests/rump/rumpkern/t_sp.sh Tue Nov 30 22:09:15 2010 @@ -0,0 +1,87 @@ +# $NetBSD: t_sp.sh,v 1.1 2010/11/30 22:09:15 pooka Exp $ +# +# Copyright (c) 2010 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case basic cleanup +basic_head() +{ + + atf_set "descr" "Check that basic remote server communication works" +} + +basic_body() +{ + + export RUMP_SERVER=unix://commsock + + atf_check -s exit:0 \ + $(atf_get_srcdir)/h_server/h_simpleserver ${RUMP_SERVER} + + atf_check -s exit:0 $(atf_get_srcdir)/h_client/h_simplecli +} + +basic_cleanup() +{ + + docleanup +} + +stresst=10 +atf_test_case stress cleanup +stress_head() +{ + + atf_set "descr" "Stress/robustness test (~${stresst}s)" +} + +stress_body() +{ + + export RUMP_SERVER=unix://commsock + + atf_check -s exit:0 \ + $(atf_get_srcdir)/h_server/h_simpleserver ${RUMP_SERVER} + + atf_check -s exit:0 $(atf_get_srcdir)/h_client/h_stresscli ${stresst} +} + +stress_cleanup() +{ + + docleanup +} + +docleanup() +{ + RUMP_SERVER=unix://commsock $(atf_get_srcdir)/h_client/h_reboot +} + +atf_init_test_cases() +{ + + atf_add_test_case basic + atf_add_test_case stress +} Index: src/tests/rump/rumpkern/h_client/Makefile diff -u /dev/null src/tests/rump/rumpkern/h_client/Makefile:1.1 --- /dev/null Tue Nov 30 22:09:15 2010 +++ src/tests/rump/rumpkern/h_client/Makefile Tue Nov 30 22:09:15 2010 @@ -0,0 +1,20 @@ +# $NetBSD: Makefile,v 1.1 2010/11/30 22:09:15 pooka Exp $ +# + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/rump/rumpkern/h_client + +TESTS_C+= h_reboot +TESTS_C+= h_simplecli +TESTS_C+= h_stresscli + +ATFFILE= no + +LDADD+= -lrumpclient +LDADD.h_stresscli= -lpthread + +WARNS= 4 +NOMAN= + +.include <bsd.test.mk> Index: src/tests/rump/rumpkern/h_client/h_reboot.c diff -u /dev/null src/tests/rump/rumpkern/h_client/h_reboot.c:1.1 --- /dev/null Tue Nov 30 22:09:15 2010 +++ src/tests/rump/rumpkern/h_client/h_reboot.c Tue Nov 30 22:09:15 2010 @@ -0,0 +1,22 @@ +/* $NetBSD: h_reboot.c,v 1.1 2010/11/30 22:09:15 pooka Exp $ */ + +#include <sys/types.h> + +#include <err.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> + +#include <rump/rump_syscalls.h> +#include <rump/rumpclient.h> + +int +main(void) +{ + + if (rumpclient_init() == -1) + err(1, "rumpclient init"); + + /* returns ENOENT, since server dies */ + rump_sys_reboot(0, NULL); +} Index: src/tests/rump/rumpkern/h_client/h_simplecli.c diff -u /dev/null src/tests/rump/rumpkern/h_client/h_simplecli.c:1.1 --- /dev/null Tue Nov 30 22:09:15 2010 +++ src/tests/rump/rumpkern/h_client/h_simplecli.c Tue Nov 30 22:09:15 2010 @@ -0,0 +1,23 @@ +/* $NetBSD: h_simplecli.c,v 1.1 2010/11/30 22:09:15 pooka Exp $ */ + +#include <sys/types.h> + +#include <err.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> + +#include <rump/rump_syscalls.h> +#include <rump/rumpclient.h> + +int +main(void) +{ + + if (rumpclient_init() == -1) + err(1, "rumpclient init"); + + if (rump_sys_getpid() > 0) + exit(0); + err(1, "getpid"); +} Index: src/tests/rump/rumpkern/h_client/h_stresscli.c diff -u /dev/null src/tests/rump/rumpkern/h_client/h_stresscli.c:1.1 --- /dev/null Tue Nov 30 22:09:15 2010 +++ src/tests/rump/rumpkern/h_client/h_stresscli.c Tue Nov 30 22:09:15 2010 @@ -0,0 +1,126 @@ +/* $NetBSD: h_stresscli.c,v 1.1 2010/11/30 22:09:15 pooka Exp $ */ + +#include <sys/types.h> +#include <sys/atomic.h> +#include <sys/sysctl.h> +#include <sys/wait.h> + +#include <err.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <rump/rump_syscalls.h> +#include <rump/rumpclient.h> + +static unsigned int syscalls; +static pid_t mypid; + +static void +signaali(int sig) +{ + + membar_consumer(); + printf("process did %d syscalls\n", syscalls); + _exit(0); +} + +static const int hostnamemib[] = { CTL_KERN, KERN_HOSTNAME }; +static char hostnamebuf[128]; +#define HOSTNAMEBASE "rumpclient" + +static void * +client(void *arg) +{ + char buf[256]; + size_t blen; + + for (;;) { + pid_t pidi; + blen = sizeof(buf); + if (rump_sys___sysctl(hostnamemib, __arraycount(hostnamemib), + buf, &blen, NULL, 0) == -1) + err(1, "sysctl"); + if (strncmp(buf, hostnamebuf, sizeof(HOSTNAMEBASE)-1) != 0) + errx(1, "hostname (%s/%s) mismatch", buf, hostnamebuf); + atomic_inc_uint(&syscalls); + + pidi = rump_sys_getpid(); + if (pidi == -1) + err(1, "getpid"); + if (pidi != mypid) + errx(1, "mypid mismatch"); + atomic_inc_uint(&syscalls); + } + + return NULL; +} + +/* Stress with max 32 clients, 8 threads each (256 concurrent threads) */ +#define NCLI 32 +#define NTHR 8 + +int +main(int argc, char *argv[]) +{ + pthread_t pt; + pid_t clis[NCLI]; + pid_t apid; + int ncli = 0; + int i = 0, j; + int status; + int rounds; + + if (argc != 2) + errx(1, "need roundcount"); + + memset(clis, 0, sizeof(clis)); + for (rounds = 1; rounds < atoi(argv[1])*10; rounds++) { + while (ncli < NCLI) { + switch ((apid = fork())) { + case -1: + err(1, "fork failed"); + case 0: + if (rumpclient_init() == -1) + err(1, "rumpclient init"); + + mypid = rump_sys_getpid(); + sprintf(hostnamebuf, HOSTNAMEBASE "%d", mypid); + if (rump_sys___sysctl(hostnamemib, + __arraycount(hostnamemib), NULL, NULL, + hostnamebuf, strlen(hostnamebuf)+1) == -1) + err(1, "sethostname"); + + signal(SIGUSR1, signaali); + + for (j = 0; j < NTHR-1; j++) + if (pthread_create(&pt, NULL, + client, NULL) != 0) + err(1, "pthread create"); + client(NULL); + /* NOTREACHED */ + default: + ncli++; + clis[i] = apid; + break; + } + + i = (i + 1) % NCLI; + } + + usleep(100000); + kill(clis[i], SIGUSR1); + + apid = wait(&status); + if (apid != clis[i]) + errx(1, "wanted pid %d, got %d\n", clis[i], apid); + clis[i] = 0; + ncli--; + } + + for (i = 0; i < NCLI; i++) + if (clis[i]) + kill(clis[i], SIGKILL); +} Index: src/tests/rump/rumpkern/h_server/Makefile diff -u /dev/null src/tests/rump/rumpkern/h_server/Makefile:1.1 --- /dev/null Tue Nov 30 22:09:15 2010 +++ src/tests/rump/rumpkern/h_server/Makefile Tue Nov 30 22:09:15 2010 @@ -0,0 +1,17 @@ +# $NetBSD: Makefile,v 1.1 2010/11/30 22:09:15 pooka Exp $ +# + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/rump/rumpkern/h_server + +TESTS_C= h_simpleserver + +ATFFILE= no + +LDADD+= -lrump -lrumpuser -lpthread + +WARNS= 4 +NOMAN= + +.include <bsd.test.mk> Index: src/tests/rump/rumpkern/h_server/h_simpleserver.c diff -u /dev/null src/tests/rump/rumpkern/h_server/h_simpleserver.c:1.1 --- /dev/null Tue Nov 30 22:09:15 2010 +++ src/tests/rump/rumpkern/h_server/h_simpleserver.c Tue Nov 30 22:09:15 2010 @@ -0,0 +1,27 @@ +/* $NetBSD: h_simpleserver.c,v 1.1 2010/11/30 22:09:15 pooka Exp $ */ + +#include <sys/types.h> + +#include <rump/rump.h> + +#include <err.h> +#include <stdlib.h> +#include <unistd.h> + +#define NOFAIL(e) do { int rv = e; if (rv) err(1, #e); } while (/*CONSTCOND*/0) + +int +main(int argc, char *argv[]) +{ + + if (argc != 2) + exit(1); + + NOFAIL(rump_daemonize_begin()); + NOFAIL(rump_init()); + NOFAIL(rump_init_server(argv[1])); + NOFAIL(rump_daemonize_done(RUMP_DAEMONIZE_SUCCESS)); + + for (;;) + pause(); +}