Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/rump/rumpkern Add a simple and stress test cases for t...
details: https://anonhg.NetBSD.org/src/rev/42b123cf1162
branches: trunk
changeset: 759178:42b123cf1162
user: pooka <pooka%NetBSD.org@localhost>
date: Tue Nov 30 22:09:15 2010 +0000
description:
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.
diffstat:
tests/rump/rumpkern/Makefile | 6 +-
tests/rump/rumpkern/h_client/Makefile | 20 ++++
tests/rump/rumpkern/h_client/h_reboot.c | 22 ++++
tests/rump/rumpkern/h_client/h_simplecli.c | 23 ++++
tests/rump/rumpkern/h_client/h_stresscli.c | 126 ++++++++++++++++++++++++++
tests/rump/rumpkern/h_server/Makefile | 17 +++
tests/rump/rumpkern/h_server/h_simpleserver.c | 27 +++++
tests/rump/rumpkern/t_sp.sh | 87 +++++++++++++++++
8 files changed, 327 insertions(+), 1 deletions(-)
diffs (truncated from 370 to 300 lines):
diff -r 6f3355089a8e -r 42b123cf1162 tests/rump/rumpkern/Makefile
--- a/tests/rump/rumpkern/Makefile Tue Nov 30 22:00:01 2010 +0000
+++ b/tests/rump/rumpkern/Makefile Tue Nov 30 22:09:15 2010 +0000
@@ -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}
diff -r 6f3355089a8e -r 42b123cf1162 tests/rump/rumpkern/h_client/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/rumpkern/h_client/Makefile Tue Nov 30 22:09:15 2010 +0000
@@ -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>
diff -r 6f3355089a8e -r 42b123cf1162 tests/rump/rumpkern/h_client/h_reboot.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/rumpkern/h_client/h_reboot.c Tue Nov 30 22:09:15 2010 +0000
@@ -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);
+}
diff -r 6f3355089a8e -r 42b123cf1162 tests/rump/rumpkern/h_client/h_simplecli.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/rumpkern/h_client/h_simplecli.c Tue Nov 30 22:09:15 2010 +0000
@@ -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");
+}
diff -r 6f3355089a8e -r 42b123cf1162 tests/rump/rumpkern/h_client/h_stresscli.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/rumpkern/h_client/h_stresscli.c Tue Nov 30 22:09:15 2010 +0000
@@ -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);
+}
diff -r 6f3355089a8e -r 42b123cf1162 tests/rump/rumpkern/h_server/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/rumpkern/h_server/Makefile Tue Nov 30 22:09:15 2010 +0000
@@ -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>
diff -r 6f3355089a8e -r 42b123cf1162 tests/rump/rumpkern/h_server/h_simpleserver.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/rumpkern/h_server/h_simpleserver.c Tue Nov 30 22:09:15 2010 +0000
@@ -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();
+}
diff -r 6f3355089a8e -r 42b123cf1162 tests/rump/rumpkern/t_sp.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/rumpkern/t_sp.sh Tue Nov 30 22:09:15 2010 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index