From: Sascha Wildner Date: Wed, 4 Aug 2010 23:36:53 +0000 (+0200) Subject: Bring in FreeBSD's stress2 stress testing suite. X-Git-Tag: v2.9.0~612 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/1365b5f1af0c1cc3894d279008de5831984b2990 Bring in FreeBSD's stress2 stress testing suite. Great for crashing the system. See test/stress/stress2/README for instructions. Thanks to Peter Holm for writing it. Thanks to Damian Lubosch for helping with testing on DragonFly. This might need further adjustment in the future. --- diff --git a/test/stress/stress2/Makefile b/test/stress/stress2/Makefile new file mode 100644 index 0000000000..02987a1dd7 --- /dev/null +++ b/test/stress/stress2/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +SUBDIR= lib testcases + +.include diff --git a/test/stress/stress2/Makefile.gnu b/test/stress/stress2/Makefile.gnu new file mode 100644 index 0000000000..06f8c7a127 --- /dev/null +++ b/test/stress/stress2/Makefile.gnu @@ -0,0 +1,28 @@ +#MAKE=gmake + +# Gnu Makefile by "Brad Knotwell" + +LIBOBJS=$(subst .c,.o,$(wildcard lib/*.c)) +TESTDIRS=run swap mkdir creat thr1 syscall rw sysctl tcp udp +EXES=$(foreach dir,$(TESTDIRS),testcases/$(dir)/$(dir).test) +OBJS=$(subst .test,.o,$(EXES)) +SRCS=$(subst .o,.c,$(OBJS)) +LIBS=./lib/libstress.a +CFLAGS=-g -Wall -I./include + +all: $(EXES) + +lib/libstress.a: lib/libstress.a($(LIBOBJS)) + ranlib lib/libstress.a + +lib/libstress.a(*.o): $(LIBOBJS) + +$(OBJS): %.o: %.c + +$(EXES): %.test: %.o lib/libstress.a + +%.test: %.o + $(CC) $(CFLAGS) $(LIBS) $< -o $@ + +clean: + rm -fr $(LIBOBJS) lib/libstress.a $(EXES) $(OBJS) diff --git a/test/stress/stress2/README b/test/stress/stress2/README new file mode 100644 index 0000000000..f430533e80 --- /dev/null +++ b/test/stress/stress2/README @@ -0,0 +1,59 @@ +$FreeBSD$ + +This is the FreeBSD kernel stress test suite. The purpose is to crash the +computer, by stressing selected parts of the kernel, thus exposing inadequate +error handling. + +Do not run the syscall test as root. + +To build and use: + +make +sh ./run.sh + +The "run.sh" script accepts an optional configuration file in order to test specific areas. +For example: + +./run.sh vfs.sh + + +To run all of the different test scenarios type: + +./run.sh -a + +You may have to tune the stress test to make sure that your test box run low +on resources. For example: + +INCARNATIONS=125 ./run.sh + +The following sub-directories exists: + +./doc Documentation +./include Include file for building the test programs in ./testcases +./lib Common support files for the test programs +./misc Various test scenarios. Mostly regression tests +./testcases Test programs +./tools Supplementary tools used in stress testing + +The name stress2 indicates that this is the second generation of the Kernel Stress Test Suite. +The first version (stress) was based mostly on scripts. + + +20090120: des@ pointed out it would be nice to be able to set the + random seed in order to be able to reproduce errors in time. + A test of this show that the occurrence of panics are still + non-deterministic even with a fixed seed. The known broken + unionfs was used to test this: + http://people.freebsd.org/~pho/stress/log/marcus006.txt. + First panic occurred after 29 loops and the second after 8 + with a seed of "123". + + The randomness that is provided by lack of synchronization + with timer interrupt, disk block layout and disk access + latencies caused by platter and heads speed changes, disk + firmware internal operations, and so on are _much_ bigger + then the undeterminism caused by the non-repeatable random + seed. + + Anyway, I have always view the this issue as only a slight + inconvenience. diff --git a/test/stress/stress2/all.cfg b/test/stress/stress2/all.cfg new file mode 100644 index 0000000000..74db0bb7a0 --- /dev/null +++ b/test/stress/stress2/all.cfg @@ -0,0 +1,8 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration: run all test programs + +# Default values +. ./default.cfg + +export TESTPROGS="" diff --git a/test/stress/stress2/beaver1.sentex.ca b/test/stress/stress2/beaver1.sentex.ca new file mode 100644 index 0000000000..f1733eb7ee --- /dev/null +++ b/test/stress/stress2/beaver1.sentex.ca @@ -0,0 +1,15 @@ +# $FreeBSD$ + +# Configuration needed for the beaver1 test box + +export RUNDIR=/usr/tmp/stressX +TZ=Europe/Copenhagen; export TZ + +###export BLASTHOST=192.168.5.105 # orangutan +export BLASTHOST=127.0.0.1 # + +export DISKIMAGE=/usr/tmp/diskimage # Location of 1G disk image +export MNTPOINT=/mnt # Disk image mount point +export TESTUSER=test # Name of non root test user +###export MDSTART=5 # Start of free md units +###INCARNATIONS=125 diff --git a/test/stress/stress2/creat.cfg b/test/stress/stress2/creat.cfg new file mode 100644 index 0000000000..ef62b9d1b2 --- /dev/null +++ b/test/stress/stress2/creat.cfg @@ -0,0 +1,10 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export TESTPROGS="testcases/creat/creat" +export creatNODELAY=1 +export creatLOAD=100 diff --git a/test/stress/stress2/default.cfg b/test/stress/stress2/default.cfg new file mode 100644 index 0000000000..5096b69a9e --- /dev/null +++ b/test/stress/stress2/default.cfg @@ -0,0 +1,76 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +export RUNDIR=${RUNDIR:-/tmp/stressX} +export RUNTIME=${RUNTIME:-2m} +export VERBOSE=${VERBOSE:-1} +export LOAD=20 + +# The INCARNATIONS variable should be set to match the number of CPUs and +# the amount of RAM in the test box. +# 10 for a 1,8 GHz Celeron with 256 Mb of RAM +# 100 for a dual Xeon 1,8 GHz with 1024 Gb of RAM + +export INCARNATIONS=${INCARNATIONS:-20} + +# Change hostname! +#export BLASTHOST=192.168.1.2 # host with udp disacard enabled in inetd.conf +export BLASTHOST=192.168.1.3 # host with udp disacard enabled in inetd.conf + + +# Run all test cases: +export runRUNTIME=${runRUNTIME:-3d} # Run tests for three days +export runINCARNATIONS=1 +export runLOAD=100 + +export swapINCARNATIONS=$((2 * INCARNATIONS)) +export swapLOAD=80 + +export syscallKILL=1 + +export rwLOAD=70 +export mkdirLOAD=80 +export creatLOAD=80 + +export symlinkLOAD=20 + +export tcpKILL=1 +#export shmKILL=1 +export shmINCARNATIONS=5 + +export TESTPROGS=" +testcases/rw/rw +testcases/swap/swap +testcases/creat/creat +testcases/mkdir/mkdir +testcases/thr1/thr1 +testcases/udp/udp +testcases/tcp/tcp +" + +[ -r default.cfg ] && ulimit -t 200 # Do not run this for the misc sub directory + +# +# Defaults for ./misc tests +# + +diskimage=/var/tmp/diskimage # Location of 1G disk image +mntpoint=/mnt # Disk image mount point +testuser=pho # Name of non root test user +mdstart=5 # Start of free md units +part=a # partitition to use on a md FS + +# Wrapper for dd +dede () { # file, blocksize, count + local log=/tmp/$0.$$ + dd if=/dev/zero of=$1 bs=$2 count=$3 > $log 2>&1 + local status=$? + egrep -v "records in|records out|bytes transferred" $log + rm -f $log + return $status +} + +[ -f "./`hostname`" ] && . "./`hostname`" # source in local configuration +[ -f "../`hostname`" ] && . "../`hostname`" # source in local configuration diff --git a/test/stress/stress2/df.cfg b/test/stress/stress2/df.cfg new file mode 100644 index 0000000000..c3731be20f --- /dev/null +++ b/test/stress/stress2/df.cfg @@ -0,0 +1,12 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg +###export creatVERBOSE=3 # Remove comments for test +###export rwVERBOSE=3 # Remove comments for test + +# Only run these two test programs for VFS tests + +export TESTPROGS="testcases/creat/creat testcases/rw/rw" diff --git a/test/stress/stress2/disk.cfg b/test/stress/stress2/disk.cfg new file mode 100644 index 0000000000..3f621a096d --- /dev/null +++ b/test/stress/stress2/disk.cfg @@ -0,0 +1,10 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export TESTPROGS="testcases/rw/rw testcases/creat/creat testcases/mkdir/mkdir" +export rwNODELAY=1 +export rwLOAD=100 diff --git a/test/stress/stress2/doc/README b/test/stress/stress2/doc/README new file mode 100644 index 0000000000..100905e8e9 --- /dev/null +++ b/test/stress/stress2/doc/README @@ -0,0 +1,5 @@ +$FreeBSD$ + +stress.pdf An old (and out of date) document escribing the first + generation of the test suite. +linuxforum06.pdf The slides from a presentation at Linux Forum 2006 diff --git a/test/stress/stress2/doc/linuxforum06.pdf b/test/stress/stress2/doc/linuxforum06.pdf new file mode 100644 index 0000000000..ab9d685b36 Binary files /dev/null and b/test/stress/stress2/doc/linuxforum06.pdf differ diff --git a/test/stress/stress2/doc/stress.pdf b/test/stress/stress2/doc/stress.pdf new file mode 100644 index 0000000000..8c82924129 Binary files /dev/null and b/test/stress/stress2/doc/stress.pdf differ diff --git a/test/stress/stress2/hydra1.netperf.freebsd.org b/test/stress/stress2/hydra1.netperf.freebsd.org new file mode 100644 index 0000000000..a212dc92b2 --- /dev/null +++ b/test/stress/stress2/hydra1.netperf.freebsd.org @@ -0,0 +1,13 @@ +# $FreeBSD$ + +# Configuration needed for the hydra1 test box + +export RUNDIR=/var/tmp/stressX + +export BLASTHOST=192.168.5.105 # orangutan + +export DISKIMAGE=/var/tmp/diskimage # Location of 1G disk image +export MNTPOINT=/mnt # Disk image mount point +export TESTUSER=test # Name of non root test user +export MDSTART=5 # Start of free md units +INCARNATIONS=150 diff --git a/test/stress/stress2/hydra2.netperf.freebsd.org b/test/stress/stress2/hydra2.netperf.freebsd.org new file mode 100644 index 0000000000..ccdf18ae1c --- /dev/null +++ b/test/stress/stress2/hydra2.netperf.freebsd.org @@ -0,0 +1,13 @@ +# $FreeBSD$ + +# Configuration needed for the hydra1 test box + +export RUNDIR=/m2/stressX + +export BLASTHOST=192.168.5.105 # orangutan + +export DISKIMAGE=/m2/tmp/diskimage # Location of 1G disk image +export MNTPOINT=/mnt # Disk image mount point +export TESTUSER=test # Name of non root test user +export MDSTART=5 # Start of free md units +INCARNATIONS=125 diff --git a/test/stress/stress2/include/stress.h b/test/stress/stress2/include/stress.h new file mode 100644 index 0000000000..cf93d0ca47 --- /dev/null +++ b/test/stress/stress2/include/stress.h @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#ifndef _STRESS_H_ +#define _STRESS_H_ +extern int setup(int); +extern int test(void); +extern void cleanup(void); +extern void options(int, char **); +extern int random_int(int, int); +/*extern void limits(void);*/ + +typedef struct { + int argc; + char **argv; + int run_time; + int load; + char *wd; + char *cd; + int verbose; + int incarnations; + int hog; + int nodelay; + int kill; + int kblocks; + int inodes; +} opt_t; + +extern opt_t *op; + +extern volatile int done_testing; +extern char *home; +extern void rmval(void); +extern void putval(unsigned long); +extern unsigned long getval(void); +extern void getdf(int64_t *, int64_t *); +extern void reservedf(int64_t, int64_t); +extern void show_status(void); +extern int64_t swap(void); +extern unsigned long usermem(void); +#endif diff --git a/test/stress/stress2/io.cfg b/test/stress/stress2/io.cfg new file mode 100644 index 0000000000..d14b31f710 --- /dev/null +++ b/test/stress/stress2/io.cfg @@ -0,0 +1,11 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +# Only run these three test programs for VFS tests + +export TESTPROGS="testcases/swap/swap testcases/creat/creat testcases/mkdir/mkdir testcases/rw/rw" +export swapLOAD=10 diff --git a/test/stress/stress2/jeff.cfg b/test/stress/stress2/jeff.cfg new file mode 100644 index 0000000000..2290c7acd7 --- /dev/null +++ b/test/stress/stress2/jeff.cfg @@ -0,0 +1,10 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +# Only run these two test programs for VFS tests + +export TESTPROGS="testcases/creat/creat testcases/mkdir/mkdir" diff --git a/test/stress/stress2/lib/Makefile b/test/stress/stress2/lib/Makefile new file mode 100644 index 0000000000..945dd8384f --- /dev/null +++ b/test/stress/stress2/lib/Makefile @@ -0,0 +1,8 @@ +# $FreeBSD$ + +LIB=stress +SRCS=main.c options.c random_int.c resources.c + +.include "../testcases/Makefile.inc" + +.include diff --git a/test/stress/stress2/lib/main.c b/test/stress/stress2/lib/main.c new file mode 100644 index 0000000000..7f7fda2508 --- /dev/null +++ b/test/stress/stress2/lib/main.c @@ -0,0 +1,204 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Main program for all test programs */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char const rcsid[] = "$Name: $ $FreeBSD$"; + +volatile int done_testing; +static int cleanupcalled = 0; +char *home; + +static pid_t *r; + +void +handler(int i) +{ + int j; + + done_testing = 1; + for (j = 0; j < op->incarnations; j++) { + if (op->verbose > 2) + printf("handler: kill -HUP %d\n", r[j]); + if (r[j] != 0 && kill(r[j], SIGHUP) == -1) + if (errno != ESRCH) + warn("kill(%d, SIGHUP), %s:%d", r[j], __FILE__, __LINE__); + } + if (op->kill == 1) { + sleep(5); + /* test programs may have blocked for the SIGHUP, so try harder */ + for (j = 0; j < op->incarnations; j++) { + if (op->verbose > 2) + printf("handler: kill -KILL %d\n", r[j]); + if (r[j] != 0) + (void) kill(r[j], SIGKILL); + } + } +} + +void +run_test_handler(int i) +{ + + done_testing = 1; +} + +void +exit_handler(int i) +{ + + exit(1); +} + +void +callcleanup(void) +{ + if (cleanupcalled == 0) + cleanup(); + cleanupcalled = 1; +} + +static void +run_tests(int i) +{ + time_t start; + + signal(SIGHUP, run_test_handler); + signal(SIGINT, exit_handler); + atexit(callcleanup); + setup(i); + if ((strcmp(getprogname(), "run") != 0) && (op->nodelay == 0)) + sleep(random_int(1,10)); + start = time(NULL); + while (done_testing == 0 && + (time(NULL) - start) < op->run_time) { + test(); + } + callcleanup(); + exit(EXIT_SUCCESS); +} + +static void +run_incarnations(void) +{ + int i; + int s; + + signal(SIGHUP, handler); + for (i = 0; i < op->incarnations && done_testing == 0; i++) { + if ((r[i] = fork()) == 0) { + run_tests(i); + } + if (r[i] < 0) { + warn("fork(), %s:%d", __FILE__, __LINE__); + r[i] = 0; + break; + } + } + for (i = 0; i < op->incarnations; i++) + if (r[i] != 0 && waitpid(r[i], &s, 0) == -1) + warn("waitpid(%d), %s:%d", r[i], __FILE__, __LINE__); + + exit(EXIT_SUCCESS); +} + +static int +run_test(void) +{ + pid_t p; + time_t start; + int status = 0; + + if (random_int(1,100) > op->load) + return (status); + + show_status(); + + start = time(NULL); + done_testing = 0; + fflush(stdout); + rmval(); + p = fork(); + if (p == 0) + run_incarnations(); + if (p < 0) + err(1, "fork() in %s:%d", __FILE__, __LINE__); + while (done_testing != 1 && + (time(NULL) - start) < op->run_time) + sleep(1); + if (kill(p, SIGHUP) == -1) + warn("kill(%d, SIGHUP), %s:%d", p, __FILE__, __LINE__); + + if (waitpid(p, &status, 0) == -1) + err(1, "waitpid(%d), %s:%d", p, __FILE__, __LINE__); + + return (status); +} + +int +main(int argc, char **argv) +{ + struct stat sb; + int status = 0; + + options(argc, argv); + + umask(0); + if (stat(op->wd, &sb) == -1) { + if (mkdir(op->wd, 0770) == -1) + if (errno != EEXIST) + err(1, "mkdir(%s) %s:%d", op->wd, __FILE__, __LINE__); + } + if (stat(op->cd, &sb) == -1) { + if (mkdir(op->cd, 0770) == -1) + if (errno != EEXIST) + err(1, "mkdir(%s) %s:%d", op->cd, __FILE__, __LINE__); + } + if ((home = getcwd(NULL, 0)) == NULL) + err(1, "getcwd(), %s:%d", __FILE__, __LINE__); + if (chdir(op->wd) == -1) + err(1, "chdir(%s) %s:%d", op->wd, __FILE__, __LINE__); + + r = (pid_t *)calloc(1, op->incarnations * sizeof(pid_t)); + + status = run_test(); + + return (status); +} diff --git a/test/stress/stress2/lib/options.c b/test/stress/stress2/lib/options.c new file mode 100644 index 0000000000..ce37227a81 --- /dev/null +++ b/test/stress/stress2/lib/options.c @@ -0,0 +1,262 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +opt_t opt; +opt_t *op; + +static char path[64]; + +static void +usage(char *where) +{ + char *help; + + if (where != NULL) + printf("Error in \"%s\"\n", where); + fprintf(stderr, "Usage: %s [-t | -l | -i | -d | -h | -k | -v]\n", getprogname()); + help = " t : time to run test\n" + " l : load factor 0 - 100%\n" + " i : max # of parallel incarnations\n" + " d : working directory\n" + " h : hog resources\n" + " k : terminate with SIGHUP + SIGKILL\n" + " n : no startup delay\n" + " v : verbose\n"; + printf(help); + exit(EX_USAGE); +} + +static int +time2sec(const char *string) +{ + int r, s = 0; + char modifier; + r = sscanf(string, "%d%c", &s, &modifier); + if (r == 2) + switch(modifier) { + case 's': break; + case 'm': s = s * 60; break; + case 'h': s = s * 60 * 60; break; + case 'd': s = s * 60 * 60 * 24; break; + default: + usage("-t"); + } + else + usage("-t"); + return (s); +} + +static char *gete(char *name) +{ + char *cp; + char help[128]; + + snprintf(help, sizeof(help), "%s%s", getprogname(), name); + cp = getenv(help); + if (cp == NULL) + cp = getenv(name); + return (cp); +} + +static void +environment(void) +{ + char *cp; + + if ((cp = gete("INCARNATIONS")) != NULL) { + if (sscanf(cp, "%d", &op->incarnations) != 1) + usage("INCARNATIONS"); + } + if ((cp = gete("LOAD")) != NULL) { + if (sscanf(cp, "%d", &op->load) != 1) + usage("LOAD"); + } + if ((cp = gete("RUNTIME")) != NULL) { + op->run_time = time2sec(cp); + } + if ((cp = gete("RUNDIR")) != NULL) { + op->wd = cp; + } + if ((cp = gete("CTRLDIR")) != NULL) { + op->cd = cp; + } + if ((cp = gete("HOG")) != NULL) { + op->hog = 1; + } + if ((cp = gete("KILL")) != NULL) { + op->kill = 1; + } + if ((cp = gete("NODELAY")) != NULL) { + op->nodelay = 1; + } + if ((cp = gete("VERBOSE")) != NULL) { + if (sscanf(cp, "%d", &op->verbose) != 1) + usage("VERBOSE"); + } + if ((cp = gete("KBLOCKS")) != NULL) { + if (sscanf(cp, "%d", &op->kblocks) != 1) + usage("KBLOCKS"); + } + if ((cp = gete("INODES")) != NULL) { + if (sscanf(cp, "%d", &op->inodes) != 1) + usage("INODES"); + } +} + +void +options(int argc, char **argv) +{ + int ch; + + op = &opt; + + op->run_time = 60; + op->load = 100; + op->wd = "/tmp/stressX"; + op->cd = "/tmp/stressX.control"; + op->incarnations = 1; + op->hog = 0; + op->kill = 0; + op->nodelay = 0; + op->verbose = 0; + op->kblocks = 0; + op->inodes = 0; + + environment(); + + while ((ch = getopt(argc, argv, "t:l:i:d:hknv")) != -1) + switch(ch) { + case 't': /* run time */ + op->run_time = time2sec(optarg); + break; + case 'l': /* load factor in pct */ + if (sscanf(optarg, "%d", &op->load) != 1) + usage("-l"); + break; + case 'i': /* max incarnations */ + if (sscanf(optarg, "%d", &op->incarnations) != 1) + usage("-i"); + break; + case 'd': /* working directory */ + op->wd = strdup(optarg); + break; + case 'h': /* hog flag */ + op->hog += 1; + break; + case 'k': /* kill flag */ + op->kill = 1; + break; + case 'n': /* no delay flag */ + op->nodelay = 1; + break; + case 'v': /* verbose flag */ + op->verbose += 1; + break; + default: + usage(NULL); + } + op->argc = argc -= optind; + op->argv = argv += optind; + + if (op->incarnations < 1) + op->incarnations = 1; + if (op->hog == 0) + op->incarnations = random_int(1, op->incarnations); + if (op->run_time < 15) + op->run_time = 15; + if (op->load < 0 || op->load > 100) + op->load = 100; +} + +void +show_status(void) +{ + char buf[80]; + int days; + time_t t; + + if (op->verbose > 0) { + t = op->run_time; + days = t / (60 * 60 * 24); + t = t % (60 * 60 * 24); + strftime(buf, sizeof(buf), "%T", gmtime(&t)); + printf("%8s: run time %2d+%s, incarnations %3d, load %3d, verbose %d\n", + getprogname(), days, buf, op->incarnations, op->load, + op->verbose); + } +} + +void +rmval(void) +{ + if (snprintf(path, sizeof(path), "%s/%s.conf", op->cd, getprogname()) < 0) + err(1, "snprintf path"); + (void) unlink(path); +} + +void +putval(unsigned long v) +{ + char buf[64]; + + rmval(); + snprintf(buf, sizeof(buf), "%lu", v); + if (symlink(buf, path) < 0) + err(1, "symlink(%s, %s)", path, buf); +} + +unsigned long +getval(void) +{ + int i, n; + unsigned long val; + char buf[64]; + + if ((n = readlink(path, buf, sizeof(buf) -1)) < 0) { + for (i = 0; i < 60; i++) { + sleep(1); + if ((n = readlink(path, buf, sizeof(buf) -1)) > 0) + break; + } + if (n < 0) + err(1, "readlink(%s). %s:%d", path, __FILE__, __LINE__); + } + buf[n] = '\0'; + if (sscanf(buf, "%ld", &val) != 1) + err(1, "sscanf(%s)", buf); + return val; +} diff --git a/test/stress/stress2/lib/random_int.c b/test/stress/stress2/lib/random_int.c new file mode 100644 index 0000000000..9d82782850 --- /dev/null +++ b/test/stress/stress2/lib/random_int.c @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include + +int +random_int(int mi, int ma) +{ + return (arc4random() % (ma - mi + 1) + mi); +} + +#ifdef TEST +#include +int +main() +{ + int i, j, min, max, r; + min = 100; + max = 1; + for (i = 0; i < 10000; i++) { + j += (r = random_int(1,100)); + if (max < r) + max = r; + if (min > r) + min = r; + } + printf("Average is %d, min = %d, max = %d\n", j / 10000, min, max); + return (0); +} +#endif diff --git a/test/stress/stress2/lib/resources.c b/test/stress/stress2/lib/resources.c new file mode 100644 index 0000000000..c4c638cdac --- /dev/null +++ b/test/stress/stress2/lib/resources.c @@ -0,0 +1,283 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Get various resource limits for the tests */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static int lockfd; +static int dffd; +static int flags; +static char lockpath[128]; +static char dfpath[128]; + +static int64_t +inodes(void) +{ + char path[MAXPATHLEN+1]; + struct statfs buf; + + if (op->inodes != 0) + return (op->inodes); + if (getcwd(path, sizeof(path)) == NULL) + err(1, "getcwd()"); + + if (statfs(path, &buf) < 0) + err(1, "statfs(%s)", path); + if (!strcmp(buf.f_fstypename, "msdosfs")) + buf.f_ffree = 9999; + flags = buf.f_flags & MNT_VISFLAGMASK; + if (op->verbose > 2) + printf("Free inodes on %s (%s): %jd\n", path, buf.f_mntonname, + (intmax_t)buf.f_ffree); + return (buf.f_ffree); +} + +static int64_t +df(void) +{ + char path[MAXPATHLEN+1]; + struct statfs buf; + + if (op->kblocks != 0) + return (op->kblocks * (uint64_t)1024); + + if (getcwd(path, sizeof(path)) == NULL) + err(1, "getcwd()"); + + if (statfs(path, &buf) < 0) + err(1, "statfs(%s)", path); + if (buf.f_bavail > buf.f_blocks || buf.f_bavail < 0) { + warnx("Corrupt statfs(%s). f_bavail = %jd!", path, + (intmax_t)buf.f_bavail); + buf.f_bavail = 100; + } + if (op->verbose > 2) + printf("Free space on %s: %jd Mb\n", path, + (intmax_t)(buf.f_bavail * buf.f_bsize / 1024 / 1024)); + return (buf.f_bavail * buf.f_bsize); +} + + +int64_t +swap(void) +{ +#error "please put the amount of free swap (in bytes) in sz" /* REMOVE HERE! */ + /* + * Currently, DragonFly has no way of determining free swap as non-root + * + * Please remove the #error line above this comment and modify the + * line below it with the amount of free swap you have (in bytes). + */ + int64_t sz = 1073741824; /* EDIT HERE! */ + + if (op->verbose > 2) + printf("Total free swap space %jd Mb\n", + (intmax_t)(sz / 1024 / 1024)); + + return (sz); +} + +unsigned long +usermem(void) +{ + unsigned long mem; + size_t nlen = sizeof(mem); + + if (sysctlbyname("hw.usermem", &mem, &nlen, NULL, 0) == -1) + err(1, "sysctlbyname() %s:%d", __FILE__, __LINE__); + + if (op->verbose > 2) + printf("Total free user memory %lu Mb\n", + mem / 1024 / 1024); + + return (mem); +} + +void cleanupdf() +{ + unlink(dfpath); +} + +void +getdf(int64_t *block, int64_t *inode) +{ + int i, j; + char buf[128]; + + snprintf(lockpath, sizeof(lockpath), "%s/lock", op->cd); + for (j = 0; j < 10; j++) { + for (i = 0; i < 10000; i++) { + if ((lockfd = open(lockpath, + O_CREAT | O_TRUNC | O_WRONLY | O_EXCL, 0644)) != -1) + break; + usleep(10000); /* sleep 1/100 sec */ + } + if (lockfd != -1) + break; + fprintf(stderr, "%s. Removing stale %s\n", getprogname(), lockpath); + unlink(lockpath); + } + if (lockfd == -1) + errx(1, "%s. Can not create %s\n", getprogname(), lockpath); + snprintf(dfpath, sizeof(dfpath), "%s/df", op->cd); + if ((dffd = open(dfpath, O_RDWR, 0644)) == -1) { + if ((dffd = open(dfpath, + O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) { + unlink(lockpath); + err(1, "creat(%s) %s:%d", dfpath, __FILE__, __LINE__); + } + atexit(cleanupdf); + *block = df(); + *inode = inodes(); + snprintf(buf, sizeof(buf), "%jd %jd", *block, *inode); + + if (write(dffd, buf, strlen(buf) + 1) != strlen(buf) +1) + err(1, "write df. %s:%d", __FILE__, __LINE__); + } else { + if (read(dffd, buf, sizeof(buf)) < 1) { + system("ls -l /tmp/stressX.control"); + unlink(lockpath); + err(1, "read df. %s:%d", __FILE__, __LINE__); + } + sscanf(buf, "%jd %jd", block, inode); + } + close(dffd); +} + + +void +reservedf(int64_t blks, int64_t inos) +{ + char buf[128]; + int64_t blocks, inodes; + + if ((dffd = open(dfpath, O_RDWR, 0644)) == -1) { + warn("open(%s) %s:%d. %s", dfpath, __FILE__, __LINE__, getprogname()); + goto err; + } + if (read(dffd, buf, sizeof(buf)) < 1) { + warn("read df. %s:%d", __FILE__, __LINE__); + goto err; + } + sscanf(buf, "%jd %jd", &blocks, &inodes); + + if (op->verbose > 2) + printf("%-8s: reservefd(%9jdK, %6jd) out of (%9jdK, %6jd)\n", + getprogname(), blks/1024, inos, blocks/1024, inodes); + blocks -= blks; + inodes -= inos; + + snprintf(buf, sizeof(buf), "%jd %jd", blocks, inodes); + if (blocks < 0 || inodes < 0) + printf("******************************** %s: %s\n", getprogname(), buf); + if (lseek(dffd, 0, 0) == -1) + err(1, "lseek. %s:%d", __FILE__, __LINE__); + if (write(dffd, buf, strlen(buf) + 1) != strlen(buf) +1) + warn("write df. %s:%d", __FILE__, __LINE__); +err: + close(dffd); + close(lockfd); + if (unlink(lockpath) == -1) + err(1, "unlink(%s)", lockpath); +} + +/* The UFS2 soft update lag problem causes a lot of confusion, so for now add the err() function here */ + +static void +vpr(int code, const char *fmt, va_list ap) +{ + char path[MAXPATHLEN+1]; + char siz[5], ino[5]; + int64_t s, i; + + s = df(); + i = inodes(); + + if (errno == ENOSPC && (flags & MNT_SOFTDEP) && (flags & MNT_QUOTA) == 0 && + s > 100 && i > 100) { + if (getcwd(path, sizeof(path)) == NULL) + err(1, "getcwd()"); + + humanize_number(siz, sizeof(siz), s, "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); + humanize_number(ino, sizeof(ino), i, "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); + + printf("A syscall has failed with ENOSPC even though free disk " + "space for %s is reported as %s and %s inodes.\n", + path, siz, ino); + } + + + fprintf(stderr, "%s: ", getprogname()); + if (fmt != NULL) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } + fprintf(stderr, "%s\n", strerror(code)); +} + +void +err(int eval, const char *fmt, ...) +{ + va_list ap; + int code = errno; + + va_start(ap, fmt); + vpr(code, fmt, ap); + va_end(ap); + exit(eval); +} + +void +warn(const char *fmt, ...) +{ + va_list ap; + int code = errno; + + va_start(ap, fmt); + vpr(code, fmt, ap); + va_end(ap); +} diff --git a/test/stress/stress2/link.cfg b/test/stress/stress2/link.cfg new file mode 100644 index 0000000000..59c1f30b94 --- /dev/null +++ b/test/stress/stress2/link.cfg @@ -0,0 +1,11 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export TESTPROGS="testcases/link/link testcases/swap/swap" +export linkHOG=1 +export linkLOAD=100 +export linkINCARNATIONS=100 diff --git a/test/stress/stress2/load.cfg b/test/stress/stress2/load.cfg new file mode 100644 index 0000000000..d4d70161a7 --- /dev/null +++ b/test/stress/stress2/load.cfg @@ -0,0 +1,18 @@ +# Just a test of the EXCLUDETESTS feature + +# Default values +. ./default.cfg + +###export TESTPROGS="" # Remove comments for test +###export HOG=1 # Remove comments for test + +###export LOAD=100 # Remove comments for test +###export swapLOAD=100 # Remove comments for test +###export rwLOAD=100 # Remove comments for test +###export mkdirLOAD=100 # Remove comments for test +###export creatLOAD=100 # Remove comments for test +###export symlinkLOAD=100 # Remove comments for test +###export swapLOAD=100 # Remove comments for test +###export linkLOAD=100 # Remove comments for test + +EXCLUDETESTS="sysctl|swap|tcp|udp|syscall|mmap|socket|thr|thr1|thr2|shm|badcode" diff --git a/test/stress/stress2/lockf.cfg b/test/stress/stress2/lockf.cfg new file mode 100644 index 0000000000..ded73eef97 --- /dev/null +++ b/test/stress/stress2/lockf.cfg @@ -0,0 +1,11 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export TESTPROGS="testcases/lockf2/lockf2 testcases/lockf/lockf testcases/swap/swap" +export lockf2HOG=1 +export lockf2LOAD=100 +export lockf2INCARNATIONS=100 diff --git a/test/stress/stress2/marcus.cfg b/test/stress/stress2/marcus.cfg new file mode 100644 index 0000000000..dcd93e4b0e --- /dev/null +++ b/test/stress/stress2/marcus.cfg @@ -0,0 +1,25 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +# Test configuration for the vop_stdvptocnp implementation + +export LOAD=80 +export symlinkLOAD=80 +export TESTPROGS=" +testcases/lockf2/lockf2 +testcases/symlink/symlink +testcases/openat/openat +testcases/rw/rw +testcases/fts/fts +testcases/link/link +testcases/lockf/lockf +testcases/creat/creat +testcases/mkdir/mkdir +testcases/rename/rename +testcases/swap/swap +testcases/mkfifo/mkfifo +" diff --git a/test/stress/stress2/misc/README b/test/stress/stress2/misc/README new file mode 100644 index 0000000000..d87e594a38 --- /dev/null +++ b/test/stress/stress2/misc/README @@ -0,0 +1,6 @@ +$FreeBSD$ + +This directory contains various test scenarios. Most are regression +tests for problems fixed. + +The script "all.sh" will run all the test scenarios for ever. diff --git a/test/stress/stress2/misc/all.sh b/test/stress/stress2/misc/all.sh new file mode 100755 index 0000000000..c8cdd96276 --- /dev/null +++ b/test/stress/stress2/misc/all.sh @@ -0,0 +1,139 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Run all the scripts in stress2/misc + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Start of list Run Known problems Verified + +# altbufferflushes.sh Y +# alternativeFlushPath.sh Y +# backingstore.sh Y +# cdevsw.sh N +# core.sh N No problems seen +# crossmp.sh Y +# crossmp2.sh N panic: sx lock still held 20071101 +# devfs.sh Y +# devfs2.sh Y 20070503 +# fdescfs.sh Y +# fpclone.sh N No problem seen +# fpclone2.sh N No problem seen +# fs.sh Y +# fullpath.sh Y 20081212 +# fuzz.sh N 20080413 +# inversion.sh N Problem not seen lately +# isofs.sh Y +# kevent.sh Y panic: KN_INFLUX set when not suppose to be 20080501 +# kevent2.sh Y +# kevent3.sh Y +# kevent4.sh Y +# kevent5.sh Y +# kinfo.sh Y +# kinfo2.sh Y +# libMicro.sh Y +# lockf.sh Y Page fault in nfs_advlock 20080413 +# lookup_shared.sh N The default, now +# mac.sh Y +# md.sh N Waiting for fix 20071208 +# md2.sh N Waiting for fix 20071208 +# mmap.sh N Waiting for fix 20080222 +# mount.sh N Known problem 20070505 +# mount2.sh Y +# mountro.sh N Waiting for commit 20080725 +# mountro2.sh N Waiting for commit 20080725 +# mountro3.sh N Waiting for commit 20080725 +# msdos.sh Y +# newfs.sh Y Problem not seen lately 20080513 +# newfs2.sh Y +# newfs3.sh N panic: lockmgr: locking against myself 20070505 +# newfs4.sh N Livelock 20080725 +# nfs.sh Y +# nfs2.sh N panic: wrong diroffset 20080801 +# nfs3.sh Y +# nfs4.sh Y +# nfs5.sh N Page fault in ufs/ffs/ffs_vfsops.c:1501 20080913 +# nfs6.sh N Page fault in ffs_fhtovp+0x18 20080913 +# nfsrename.sh Y +# nullfs.sh N panic: xdrmbuf_create with NULL mbuf chain 20081122 +# pthread.sh Y panic: spin lock held too long 20081109 +# quota1.sh Y +# quota10.sh N Deadlock 20081212 +# quota2.sh Y +# quota3.sh Y +# quota4.sh N Known backing store problem 20070703 +# quota5.sh Y +# quota6.sh N Known problem with snapshots and no disk space +# quota7.sh Y 20070505 +# quota8.sh Y 20070505 +# quota9.sh N 20070505 +# recursiveflushes.sh Y +# revoke.sh Y +# snap.sh N Waiting for snap3.sh fix +# snap2-1.sh Y +# snap2.sh Y +# snap3.sh N Reported as kostik033.html +# snap4.sh Y +# snap5-1.sh Y +# snap5.sh Y +# snap6.sh Y +# snap7.sh N Waiting for snap3.sh fix 20070508 +# snapbackup.sh N WIP +# softupdate.sh Y +# statfs.sh Y +# symlink.sh Y +# syscall.sh Y +# ucom.sh N +# umount.sh Y +# umountf.sh Y +# umountf2.sh N Waiting for commit of fix +# umountf3.sh N Deadlock. Waiting for commit of fix 20081212 +# umountf4.sh Y Page fault in ufs/ufs/ufs_dirhash.c:204 20081003 +# unionfs.sh N Page fault 20070503 +# unionfs2.sh N Reported as cons224 20070504 +# unionfs3.sh N Page fault in vfs_statfs 20070504 + +# End of list + +list=`sed -n '/^# Start of list/,/^# End of list/p' < $0 | awk '$3 ~ /Y/ {print $2}'` +[ $# -ne 0 ] && list=$* + + +rm -f /tmp/misc.log +while true; do +# Shuffle the list + list=`perl -e 'print splice(@ARGV,rand(@ARGV),1), " " while @ARGV;' $list` + for i in $list; do + ./cleanup.sh + echo "`date '+%Y%m%d %T'` all: $i" | tee /dev/tty >> /tmp/misc.log + logger "Starting test all: $i" + ./$i + done +done diff --git a/test/stress/stress2/misc/altbufferflushes.sh b/test/stress/stress2/misc/altbufferflushes.sh new file mode 100755 index 0000000000..7d5c41b7a5 --- /dev/null +++ b/test/stress/stress2/misc/altbufferflushes.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test. This script caused this panic: + +# panic: lockmgr: locking against myself +# cpuid = 2 +# KDB: enter: panic +# [thread pid 2526 tid 100070 ] +# Stopped at kdb_enter+0x2b: nop +# db> bt +# Tracing pid 2526 tid 100070 td 0xc46f8360 +# kdb_enter(c094247f) at kdb_enter+0x2b +# panic(c09402b6,c46f8360,0,12,c06af5d9,...) at panic+0x14b +# _lockmgr(d864a748,202122,c479f788,c46f8360,c094b01c,12d) at _lockmgr+0x41a +# getblk(c479f6b8,5d51940,0,4000,0,...) at getblk+0x13c +# breadn(c479f6b8,5d51940,0,4000,0,...) at breadn+0x2f +# bread(c479f6b8,5d51940,0,4000,0,e6d13544,c4743eac,0,c095a185,56d) at bread+0x20 +# ffs_alloccg(c47408c4,104,1754628,0,4000,c4743eac,1,c095a185,4d8) at ffs_alloccg+0x11d +# ffs_hashalloc(c47408c4,104,1754628,0,4000,...) at ffs_hashalloc+0x45 +# ffs_alloc(c47408c4,3f2cd,0,1754628,0,4000,c42fd400,e6d13674) at ffs_alloc+0x1a5 +# ffs_balloc_ufs2(c4735d70,fcb34000,0,4000,c42fd400,...) at ffs_balloc_ufs2+0x1619 +# ffs_copyonwrite(c479f6b8,d84e3d08) at ffs_copyonwrite+0x3d3 +# ffs_geom_strategy(c479f7c0,d84e3d08) at ffs_geom_strategy+0xbd +# bufwrite(d84e3d08,4000,d84e3d08,e6d137e4,c070b7a9,...) at bufwrite+0x17a +# ffs_bufwrite(d84e3d08) at ffs_bufwrite+0x282 +# vfs_bio_awrite(d84e3d08) at vfs_bio_awrite+0x235 +# bdwrite(d864a6e8,c4743eac,0,c095a185,57c,...) at bdwrite+0x237 +# ffs_alloccg(c4b54a50,104,1754628,0,4000,c4743eac,1,c095a185,4d8) at ffs_alloccg+0x1f6 +# ffs_hashalloc(c4b54a50,104,1754628,0,4000,...) at ffs_hashalloc+0x45 +# ffs_alloc(c4b54a50,1b00c,0,1754628,0,4000,c4b22a80,e6d139ac) at ffs_alloc+0x1a5 +# ffs_balloc_ufs2(c4e72158,6c030000,0,4000,c4b22a80,...) at ffs_balloc_ufs2+0x1619 +# ffs_write(e6d13b98) at ffs_write+0x2ac +# VOP_WRITE_APV(c0a00e80,e6d13b98) at VOP_WRITE_APV+0x132 +# vn_write(c46c65a0,e6d13c60,c4b22a80,0,c46f8360) at vn_write+0x1f6 +# dofilewrite(c46f8360,4,c46c65a0,e6d13c60,ffffffff,...) at dofilewrite+0x77 +# kern_writev(c46f8360,4,e6d13c60,8430000,d0000,...) at kern_writev+0x36 +# write(c46f8360,e6d13d00) at write+0x45 +# syscall(e6d13d38) at syscall+0x256 + + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +persist () { + false + while [ $? -ne 0 ]; do + $1 > /dev/null 2>&1 + sleep 1 + done +} + +diskfree=`df -k /var/tmp | tail -1 | awk '{print $4}'` +[ $((diskfree / 1024 / 1024)) -lt 5 ] && echo "Not enough disk space" && exit 1 + +rm -f /var/.snap/pho /var/tmp/big.? +trap "rm -f /var/.snap/pho /var/tmp/big.?" 0 +persist 'mksnap_ffs /var /var/.snap/pho' +sysctl vfs.dirtybufthresh=10 > /dev/null 2>&1 + +cd /var/tmp +for j in `jot 10`; do + old=`sysctl vfs.altbufferflushes | awk '{print $NF}'` + for i in `jot 4`; do + echo "`date '+%T'` Create big.$i" + dd if=/dev/zero of=big.$i bs=1m count=4k 2>&1 | egrep -v "records|transferred" + done + sleep 1 + rm -rf /var/tmp/big.? + new=`sysctl vfs.altbufferflushes | awk '{print $NF}'` + [ $new -ne $old ] && echo "vfs.altbufferflushes changed from $old to $new." +done +rm -f /var/.snap/pho diff --git a/test/stress/stress2/misc/alternativeFlushPath.sh b/test/stress/stress2/misc/alternativeFlushPath.sh new file mode 100755 index 0000000000..444c5d4ed3 --- /dev/null +++ b/test/stress/stress2/misc/alternativeFlushPath.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Alternate buffer flush path test (Not verified) +# Apply this patch to amplyfy the problem: +# +# diff -r1.520 vfs_bio.c +# 894c894 +# < if (bo->bo_dirty.bv_cnt > dirtybufthresh + 10) { +# --- +# > if (bo->bo_dirty.bv_cnt > dirtybufthresh /*+ 10*/) { + +odir=`pwd` +dir=/var/tmp/alternativeFlushPath + +find $dir -type f | xargs rm +[ ! -d $dir ] && mkdir -p $dir +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/alternativeFlushPath.c +cc -o alternativeFlushPath -Wall alternativeFlushPath.c -lthr +rm -f alternativeFlushPath.c + +for j in `jot 10`; do + ./alternativeFlushPath& +done +for j in `jot 20`; do + wait +done +sysctl -a | grep dirtybuf + +rm alternativeFlushPath + +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include + +int +main() +{ + char name[80]; + int i, j, k; + pid_t mypid; + int *fd; + struct rlimit rlp; + + + if (getrlimit(RLIMIT_NOFILE, &rlp) == -1) + err(1, "getrlimit(RLIMIT_NOFILE)"); + rlp.rlim_cur /= 10; + mypid = getpid(); + fd = malloc(rlp.rlim_cur * sizeof(int)); + + for (k = 0; k < 100; k++) { + for (i = 0, j = 0; i < (rlp.rlim_cur - 10); i++, j++) { + sprintf(name, "f%05d.%05d", mypid, i); + if ((fd[i] = open(name, O_CREAT|O_WRONLY, 0666)) == -1) { + warn("open(%s)", name); + break; + } + } + for (i = 0; i < j; i++) { + sprintf(name, "f%05d.%05d", mypid, i); + if (unlink(name) == -1) + warn("unlink(%s)", name); + } + for (i = 0; i < j; i++) { + if (close(fd[i]) == -1) + warn("close(%d)", i); + } + } + + exit(0); +} diff --git a/test/stress/stress2/misc/backingstore.sh b/test/stress/stress2/misc/backingstore.sh new file mode 100755 index 0000000000..493a3f3bec --- /dev/null +++ b/test/stress/stress2/misc/backingstore.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test sparse backing store + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +export here=`pwd` + +m=$mdstart + +mount | grep "${mntpoint}" | grep -q md$m && umount ${mntpoint}$m +mdconfig -l | grep -q md$m && mdconfig -d -u $m + +dede $D$m 100m 1 || exit 1 + +mdconfig -a -t vnode -f $D$m -u $m + +bsdlabel -w md$m auto +newfs md${m}${part} > /dev/null 2>&1 +mount $opt /dev/md${m}${part} ${mntpoint}$m + +n=$m +m=$((m + 1)) + +mount | grep "${mntpoint}" | grep -q md$m && umount ${mntpoint}$m +mdconfig -l | grep -q md$m && mdconfig -d -u $m + +truncate -s 500M ${mntpoint}$n/diskimage +mdconfig -a -t vnode -f ${mntpoint}$n/diskimage -u $m + +bsdlabel -w md$m auto +newfs md${m}${part} > /dev/null 2>&1 +mount $opt /dev/md${m}${part} ${mntpoint}$m + +export RUNDIR=${mntpoint}$m/stressX +../testcases/rw/rw -t 5m -i 200 -h -n + +while mount | grep -q ${mntpoint}$m; do + flag=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f" || echo "") + umount $flag ${mntpoint}$m > /dev/null 2>&1 +done +mdconfig -l | grep -q md$m && mdconfig -d -u $m + +m=$((m - 1)) +while mount | grep -q ${mntpoint}$m; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && \ + echo "-f" || echo "") ${mntpoint}$m > /dev/null 2>&1 +done +mdconfig -l | grep -q md$m && mdconfig -d -u $m +rm -f $D diff --git a/test/stress/stress2/misc/backingstore2.sh b/test/stress/stress2/misc/backingstore2.sh new file mode 100755 index 0000000000..fbc2684597 --- /dev/null +++ b/test/stress/stress2/misc/backingstore2.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test unmount of a device that is already gone + +# Leaves /mnt6 unmountable and leads to a "panic: 1 vncache entries remaining" +# during shut down. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +export here=`pwd` + +m1=$mdstart +m2=$((m1 + 1)) +mount | grep "${mntpoint}" | grep -q md$m2 && umount ${mntpoint}$m2 +mdconfig -l | grep -q md$m2 && mdconfig -d -u $m2 +mount | grep "${mntpoint}" | grep -q md$m1 && umount ${mntpoint}$m1 +mdconfig -l | grep -q md$m1 && mdconfig -d -u $m1 + +dede $D$m1 100m 1 || exit 1 + +mdconfig -a -t vnode -f $D$m1 -u $m1 + +bsdlabel -w md$m1 auto +newfs md${m1}${part} > /dev/null 2>&1 +mount /dev/md${m1}${part} ${mntpoint}$m1 + + +truncate -s 500M ${mntpoint}$m1/diskimage +mdconfig -a -t vnode -f ${mntpoint}$m1/diskimage -u $m2 + +bsdlabel -w md$m2 auto +newfs md${m2}${part} > /dev/null 2>&1 +mount /dev/md${m2}${part} ${mntpoint}$m2 + +# Reversed umount sequence: +umount -f /dev/md${m1}${part} +umount -f /dev/md${m2}${part} + +mount | grep "${mntpoint}" | grep -q md$m2 && umount ${mntpoint}$m2 +mdconfig -l | grep -q md$m2 && mdconfig -d -u $m2 +mount | grep "${mntpoint}" | grep -q md$m1 && umount ${mntpoint}$m1 +mdconfig -l | grep -q md$m1 && mdconfig -d -u $m1 diff --git a/test/stress/stress2/misc/backingstore3.sh b/test/stress/stress2/misc/backingstore3.sh new file mode 100755 index 0000000000..d65c1ead64 --- /dev/null +++ b/test/stress/stress2/misc/backingstore3.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test unmount of a device that is already gone + +# Caused "panic: bundirty: buffer 0xdafaf2c4 still on queue 1" + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +export here=`pwd` + +m1=$mdstart +m2=$((m1 + 1)) +mount | grep "${mntpoint}" | grep -q md$m2 && umount ${mntpoint}$m2 +mdconfig -l | grep -q md$m2 && mdconfig -d -u $m2 +mount | grep "${mntpoint}" | grep -q md$m1 && umount ${mntpoint}$m1 +mdconfig -l | grep -q md$m1 && mdconfig -d -u $m1 + +dede $D$m1 25m 1 || exit 1 + +mdconfig -a -t vnode -f $D$m1 -u $m1 + +bsdlabel -w md$m1 auto +newfs md${m1}${part} > /dev/null 2>&1 +mount /dev/md${m1}${part} ${mntpoint}$m1 + + +truncate -s 500M ${mntpoint}$m1/diskimage +mdconfig -a -t vnode -f ${mntpoint}$m1/diskimage -u $m2 + +bsdlabel -w md$m2 auto +newfs md${m2}${part} > /dev/null 2>&1 +mount /dev/md${m2}${part} ${mntpoint}$m2 + +dd if=/dev/zero of=${mntpoint}$m2/file bs=1m > /dev/null 2>&1 + +# Reversed umount sequence: +umount -f /dev/md${m1}${part} +umount -f /dev/md${m2}${part} + +mount | grep "${mntpoint}" | grep -q md$m2 && umount ${mntpoint}$m2 +mdconfig -l | grep -q md$m2 && mdconfig -d -u $m2 +mount | grep "${mntpoint}" | grep -q md$m1 && umount ${mntpoint}$m1 +mdconfig -l | grep -q md$m1 && mdconfig -d -u $m1 diff --git a/test/stress/stress2/misc/cdevsw.sh b/test/stress/stress2/misc/cdevsw.sh new file mode 100755 index 0000000000..b300daa3ed --- /dev/null +++ b/test/stress/stress2/misc/cdevsw.sh @@ -0,0 +1,220 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by kib@freebsd.org + +# Test of patch for Giant trick in cdevsw + +exit # Test moved to fpclone*.sh + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +dir=$RUNDIR/tclone +[ ! -d $dir ] && mkdir -p $dir + +cd $dir +cat > Makefile < +EOF + +sed '1,/^EOF2/d' < $odir/$0 > tclone.c +make +kldload $dir/tclone.ko + +cd $odir +dd if=/dev/tclone bs=1m count=5k > /dev/null 2>&1 & + +export runRUNTIME=2m +cd /home/pho/stress2; ./run.sh pty.cfg + +kldstat +kldunload $dir/tclone.ko +rm -rf $dir +exit + +EOF2 +/* $FreeBSD$ */ + +#include +#include +#include +#include +#include +#include +#include + +static d_open_t tclone_open; +static d_close_t tclone_close; +static d_read_t tclone_read; + +static struct cdevsw tclone_cdevsw = { + .d_open = tclone_open, + .d_close = tclone_close, + .d_read = tclone_read, + .d_name = "tclone", + .d_version = D_VERSION, + .d_flags = D_TRACKCLOSE|D_NEEDGIANT +}; + +static eventhandler_tag tclone_ehtag; +static struct clonedevs *tclone_clones; + +MALLOC_DEFINE(M_TCLONESC, "tclone memory", "tclone memory"); + +struct tclone_sc +{ + int pos; +}; + +static void +tclone_clone(void *arg, struct ucred *cred, + char *name, int namelen, struct cdev **dev) +{ + int i, clone; + + if (*dev != NULL) + return; + if (strcmp(name, "tclone") != 0) + return; + + clone = 0; + do { + i = clone_create(&tclone_clones, &tclone_cdevsw, + &clone, dev, 0); + if (i == 0) + clone++; + } while ((clone <= CLONE_UNITMASK) && (i == 0)); + + if ((i != 0) && (clone <= CLONE_UNITMASK)) { + *dev = make_dev_credf(MAKEDEV_REF, + &tclone_cdevsw, unit2minor(clone), + cred, UID_ROOT, GID_WHEEL, 0666, + "tclone.%u", clone); + if (*dev != NULL) { + (*dev)->si_flags |= SI_CHEAPCLONE; + (*dev)->si_drv1 = (void *)1; + } + } +} + +static int +tclone_open(struct cdev *dev, int oflags, int devtype, d_thread_t *td) +{ + int status; + + if (!dev->si_drv2) { + /* only allow one open() of this file */ + dev->si_drv2 = malloc(sizeof(struct tclone_sc), M_TCLONESC, + M_WAITOK | M_ZERO); + status = 0; + } else + status = EBUSY; + + if (status == 0) { + /* XXX Fix me? (clear of SI_CHEAPCLONE) */ + dev->si_flags &= ~SI_CHEAPCLONE; + } + + return (status); +} + +static int +tclone_close(struct cdev *dev, int fflag, int devtype, d_thread_t *td) +{ + void *x; + + x = dev->si_drv2; + dev->si_drv2 = &tclone_cdevsw; + if (x != &tclone_cdevsw) + free(x, M_TCLONESC); + destroy_dev_sched(dev); + return (0); +} + +static char rdata[] = "tclone sample data string\n"; + +static int +tclone_read(struct cdev *dev, struct uio *uio, int ioflag) +{ + struct tclone_sc *sc; + int rv, amnt; + + sc = dev->si_drv2; + rv = 0; + while (uio->uio_resid > 0) { + amnt = MIN(uio->uio_resid, sizeof(rdata) - sc->pos); + rv = uiomove(rdata + sc->pos, amnt, uio); + if (rv != 0) + break; + sc->pos += amnt; + sc->pos %= sizeof(rdata); + } + return (rv); +} + +static int +tclone_modevent(module_t mod, int what, void *arg) +{ + switch (what) { + case MOD_LOAD: + clone_setup(&tclone_clones); + tclone_ehtag = EVENTHANDLER_REGISTER(dev_clone, + tclone_clone, 0, 0); + if (tclone_ehtag == NULL) + return ENOMEM; + return(0); + + case MOD_UNLOAD: + EVENTHANDLER_DEREGISTER(dev_clone, tclone_ehtag); + drain_dev_clone_events(); + clone_cleanup(&tclone_clones); + destroy_dev_drain(&tclone_cdevsw); + return (0); + default: + break; + } + + return (0); +} + +moduledata_t tclone_mdata = { + "tclone", + tclone_modevent, + NULL +}; + +DECLARE_MODULE(tclone, tclone_mdata, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); +MODULE_VERSION(tclone, 1); diff --git a/test/stress/stress2/misc/cleanup.sh b/test/stress/stress2/misc/cleanup.sh new file mode 100755 index 0000000000..66858d4594 --- /dev/null +++ b/test/stress/stress2/misc/cleanup.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ ! -z "$mntpoint" ] && rm -rf ${mntpoint}*/* +rm -f /tmp/.snap/pho* /var/.snap/pho* +rm -rf /tmp/stressX.control + +mount | grep -wq $mntpoint && umount $mntpoint +m=$mdstart +for i in `jot 15`; do + while mount | grep -q ${mntpoint}$m; do + rm -rf ${mntpoint}$m + umount -f ${mntpoint}$m > /dev/null 2>&1 + done + mdconfig -l | grep -q md$m && mdconfig -d -u $m + m=$((m + 1)) +done diff --git a/test/stress/stress2/misc/core.sh b/test/stress/stress2/misc/core.sh new file mode 100755 index 0000000000..87af822ce6 --- /dev/null +++ b/test/stress/stress2/misc/core.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test multiple (parallel) core dumps + +. ../default.cfg + +odir=`pwd` + +cd /tmp +rm -f core +sed '1,/^EOF/d' < $odir/$0 > core.c +cc -o core -Wall core.c +rm -f core.c +cd $RUNDIR + +for i in `jot 2`; do + for j in `jot 4`; do + /tmp/core & + done + for j in `jot 4`; do + wait + done +done +rm -f core +exit +EOF +#include +#include +#include +#include +#include +#include +#include + +#define SIZ 10*1024*1024 + +int +main(int argc, char **argv) +{ + char *cp = 0; + + if ((cp = malloc(SIZ)) == NULL) + err(1, "Could not malloc 10Mb!"); + + memset(cp, 1, SIZ); + +// printf("sleep %d\n", (120 - (time(NULL) % 120))); fflush(stdout); + sleep(120 - (time(NULL) % 120)); + raise(SIGSEGV); +// printf(".\n"); + + return (0); +} diff --git a/test/stress/stress2/misc/crossmp.sh b/test/stress/stress2/misc/crossmp.sh new file mode 100755 index 0000000000..d5bc951a20 --- /dev/null +++ b/test/stress/stress2/misc/crossmp.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Copy of crossmp.sh, but with SU enabled. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +mdstart=$mdstart # Use md unit numbers from this point +D=$diskimage + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount | grep "$mntpoint" | grep -q md$m && umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + dede $D$m 1m 1 + mdconfig -a -t vnode -f $D$m -u $m + bsdlabel -w md$m auto + newfs md${m}${part} > /dev/null 2>&1 + done + + # start the parallel tests + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find & + done + + for i in `jot $mounts`; do + wait; wait + done + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + mdconfig -d -u $m + rm -f $D$m + done + +else + if [ $1 = find ]; then + for i in `jot 1024`; do + find ${mntpoint}* -type f > /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + for i in `jot 1024`; do + m=$1 + mount /dev/md${m}${part} ${mntpoint}$m + while mount | grep -qw $mntpoint$m; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + done + fi +fi diff --git a/test/stress/stress2/misc/crossmp2.sh b/test/stress/stress2/misc/crossmp2.sh new file mode 100755 index 0000000000..961c6d6d5d --- /dev/null +++ b/test/stress/stress2/misc/crossmp2.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Panic in getdirentries+0x21a +# Run with stress: disk.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=10 # Number of parallel scripts + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + [ ! -d ${mntpoint}$i ] && mkdir ${mntpoint}$i + mount | grep -qw "${mntpoint}$i" && umount ${mntpoint}$i + done + + # start the parallel tests + for i in `jot $mounts`; do + ./$0 $i & + ./$0 find & + done + + for i in `jot $mounts`; do + wait; wait + done +else + if [ $1 = find ]; then + for i in `jot 64`; do + find ${mntpoint}* -maxdepth 1 -type f > /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + for i in `jot 64`; do + m=$1 + mount -t nfs -o tcp -o nfsv3 -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/tmp ${mntpoint}$m + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + n=0 + while mount | grep -qw ${mntpoint}$m; do + umount $opt ${mntpoint}$m > /dev/null 2>&1 + n=$((n + 1)) + [ $n -gt 99 ] && umount -f ${mntpoint}$m > /dev/null 2>&1 + [ $n -gt 100 ] && exit + done + done + fi +fi diff --git a/test/stress/stress2/misc/datamove.sh b/test/stress/stress2/misc/datamove.sh new file mode 100755 index 0000000000..da2fb2001a --- /dev/null +++ b/test/stress/stress2/misc/datamove.sh @@ -0,0 +1,208 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# There is a well-known problem in FreeBSD, caused by allowing page faults +# while doing filesystem data move to or from userspace during read(2) and +# write(2). The issue is that if the userspace address being read or write +# from/to is backed by the mapping of the same file we are doing i/o to, +# we deadlock. + +# Test scenario by ups + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > dl.c +cc -o dl -Wall dl.c +rm -f dl.c + +n=5 +old=`sysctl vm.old_msync | awk '{print $NF}'` +sysctl vm.old_msync=1 +for i in `jot $n`; do + mkdir -p /tmp/dl.dir.$i + cd /tmp/dl.dir.$i + /tmp/dl & +done +cd /tmp +for i in `jot $n`; do + wait +done +for i in `jot $n`; do + rm -rf /tmp/dl.dir.$i +done +sysctl vm.old_msync=$old + +rm -rf /tmp/dl +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include + + +int prepareFile(char* filename,int* fdp); +int mapBuffer(char** bufferp,int fd1,int fd2); +int startIO(int fd,char *buffer); + +int pagesize; + +#define FILESIZE (32*1024) +char wbuffer[FILESIZE]; + +/* Create a FILESIZE sized file - then remove file data from the cache*/ +int prepareFile(char* filename,int* fdp) +{ + int fd; + int len; + int status; + void *addr; + + fd = open(filename,O_CREAT | O_TRUNC | O_RDWR,S_IRWXU); + if (fd == -1) + { + perror("Creating file"); + return fd; + } + + len = write(fd,wbuffer,FILESIZE); + if (len < 0) + { + perror("Write failed"); + return 1; + } + + status = fsync(fd); + if (status != 0) + { + perror("fsync failed"); + return 1; + } + + addr = mmap(NULL,FILESIZE, PROT_READ | PROT_WRITE , MAP_SHARED, fd, 0); + if (addr == MAP_FAILED) + { + perror("Mmap failed"); + return 1; + } + + status = msync(addr,FILESIZE,MS_INVALIDATE | MS_SYNC); + if (status != 0) + { + perror("Msync failed"); + return 1; + } + + munmap(addr,FILESIZE); + + *fdp = fd; + return 0; +} + + +/* mmap a 2 page buffer - first page is from fd1, second page from fd2 */ +int mapBuffer(char** bufferp,int fd1,int fd2) +{ + void* addr; + char *buffer; + + addr = mmap(NULL,pagesize*2, PROT_READ | PROT_WRITE , MAP_SHARED, fd1, 0); + if (addr == MAP_FAILED) + { + perror("Mmap failed"); + return 1; + } + + buffer = addr; + addr = mmap(buffer + pagesize,pagesize, PROT_READ | PROT_WRITE , MAP_FIXED | +MAP_SHARED, fd2, 0); + + if (addr == MAP_FAILED) + { + perror("Mmap2 failed"); + return 1; + } + *bufferp = buffer; + return 0; +} + + +int startIO(int fd,char *buffer) +{ + ssize_t len; + len = write(fd,buffer,2*pagesize); + if (len == -1) + { + perror("write failed"); + return 1; + } + return 0; +} + + +int main(int argc,char *argv[],char *envp[]) +{ + + int fdA,fdB,fdDelayA,fdDelayB; + int status; + char *bufferA,*bufferB; + pid_t pid; + + pagesize = getpagesize(); + + if ((prepareFile("A",&fdA)) + || (prepareFile("B",&fdB)) + || (prepareFile("DelayA",&fdDelayA)) + || (prepareFile("DelayB",&fdDelayB)) + || (mapBuffer(&bufferA,fdDelayA,fdB)) + || (mapBuffer(&bufferB,fdDelayB,fdA))) + exit(1); + + pid = fork(); + + if (pid == 0) + { + status = startIO(fdA,bufferA); + exit(status); + } + + if (pid == -1) + { + exit(1); + } + status = startIO(fdB,bufferB); + exit(status); + +} diff --git a/test/stress/stress2/misc/datamove2.sh b/test/stress/stress2/misc/datamove2.sh new file mode 100755 index 0000000000..ad321cc8fd --- /dev/null +++ b/test/stress/stress2/misc/datamove2.sh @@ -0,0 +1,210 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Variation of the datamove.sh scenario by not using "sysctl vm.old_msync=1" + +# Deadlock seen + +# Test scenario by ups + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > dl.c +cc -o dl -Wall dl.c +rm -f dl.c + +for i in `jot 3`; do + $here/../testcases/swap/swap -t 10m -i 200 -h & + /tmp/dl + ps | grep swap | grep -v swap | awk '{print $1}' | xargs kill +done +rm -rf /tmp/dl +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +int prepareFile(char *filename, int *fdp); +int mapBuffer (char **bufferp, int fd1, int fd2); +int startIO (int fd, char *buffer); + +int pagesize; + +#define FILESIZE (32*1024) +char wbuffer [FILESIZE]; + +/* Create a FILESIZE sized file - then remove file data from the cache */ +int +prepareFile(char *filename, int *fdp) +{ + int fd; + int len; + int status; + void *addr; + + fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU); + if (fd == -1) { + perror("Creating file"); + return fd; + } + len = write(fd, wbuffer, FILESIZE); + if (len < 0) { + perror("Write failed"); + return 1; + } + status = fsync(fd); + if (status != 0) { + perror("fsync failed"); + return 1; + } + addr = mmap(NULL, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (addr == MAP_FAILED) { + perror("Mmap failed"); + return 1; + } + status = msync(addr, FILESIZE, MS_INVALIDATE | MS_SYNC); + if (status != 0) { + perror("Msync failed"); + return 1; + } + if (munmap(addr, FILESIZE) == -1) { + perror("munmap failed"); + return 1; + } + + *fdp = fd; + return 0; +} + + +/* mmap a 2 page buffer - first page is from fd1, second page from fd2 */ +int +mapBuffer(char **bufferp, int fd1, int fd2) +{ + void *addr; + char *buffer; + + addr = mmap(NULL, pagesize * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd1, 0); + if (addr == MAP_FAILED) { + perror("Mmap failed"); + return 1; + } + buffer = addr; + addr = mmap(buffer + pagesize, pagesize, PROT_READ | PROT_WRITE, MAP_FIXED | + MAP_SHARED, fd2, 0); + + if (addr == MAP_FAILED) { + perror("Mmap2 failed"); + return 1; + } + *bufferp = buffer; + return 0; +} + +void +unmapBuffer(char *bufferp) +{ + if (munmap(bufferp, pagesize * 2) == -1) + err(1, "unmap 1. buffer"); + if (munmap(bufferp + pagesize * 2, pagesize * 2) == -1) + err(1, "unmap 2. buffer"); +} + +int +startIO(int fd, char *buffer) +{ + ssize_t len; + + len = write(fd, buffer, 2 * pagesize); + if (len == -1) { + perror("write failed"); + return 1; + } + return 0; +} + + +int +main(int argc, char *argv[], char *envp[]) +{ + + int fdA, fdB, fdDelayA, fdDelayB; + int status; + int i; + char *bufferA, *bufferB; + pid_t pid; + + pagesize = getpagesize(); + + for (i = 0; i < 1000; i++) { + if ((prepareFile("A", &fdA)) + || (prepareFile("B", &fdB)) + || (prepareFile("DelayA", &fdDelayA)) + || (prepareFile("DelayB", &fdDelayB)) + || (mapBuffer(&bufferA, fdDelayA, fdB)) + || (mapBuffer(&bufferB, fdDelayB, fdA))) + exit(1); + + pid = fork(); + + if (pid == 0) { + status = startIO(fdA, bufferA); + exit(status); + } + if (pid == -1) { + perror("fork"); + exit(1); + } + status = startIO(fdB, bufferB); + if (wait(&status) == -1) + err(1, "wait"); + + close(fdA); + close(fdB); + close(fdDelayA); + close(fdDelayB); + unmapBuffer(bufferA); + unmapBuffer(bufferB); + unlink("A"); + unlink("B"); + unlink("DelayA"); + unlink("DelayB"); + } + exit(status); + +} diff --git a/test/stress/stress2/misc/datamove3.sh b/test/stress/stress2/misc/datamove3.sh new file mode 100755 index 0000000000..0afb42d9e4 --- /dev/null +++ b/test/stress/stress2/misc/datamove3.sh @@ -0,0 +1,219 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Threaded variation of datamove.sh + +# Based on a test scenario by ups and suggestions by kib + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > dl.c +cc -o dl -Wall dl.c -lpthread +rm -f dl.c + +n=5 +old=`sysctl vm.old_msync | awk '{print $NF}'` +sysctl vm.old_msync=1 +for i in `jot $n`; do + mkdir -p /tmp/dl.dir.$i + cd /tmp/dl.dir.$i + /tmp/dl & +done +cd /tmp +for i in `jot $n`; do + wait +done +for i in `jot $n`; do + rm -rf /tmp/dl.dir.$i +done +sysctl vm.old_msync=$old + +rm -rf /tmp/dl +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct args { + char *bp; + int fd1; + int fd2; +} a[2]; + +int prepareFile(char *, int *); +void * mapBuffer(void *); +int startIO(int, char *); + +int pagesize; + +#define FILESIZE (32*1024) +char wbuffer [FILESIZE]; + +/* Create a FILESIZE sized file - then remove file data from the cache */ +int +prepareFile(char *filename, int *fdp) +{ + int fd; + int len; + int status; + void *addr; + + fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU); + if (fd == -1) { + perror("Creating file"); + return fd; + } + len = write(fd, wbuffer, FILESIZE); + if (len < 0) { + perror("Write failed"); + return 1; + } + status = fsync(fd); + if (status != 0) { + perror("fsync failed"); + return 1; + } + addr = mmap(NULL, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (addr == MAP_FAILED) { + perror("Mmap failed"); + return 1; + } + status = msync(addr, FILESIZE, MS_INVALIDATE | MS_SYNC); + if (status != 0) { + perror("Msync failed"); + return 1; + } + munmap(addr, FILESIZE); + + *fdp = fd; + return 0; +} + + +/* mmap a 2 page buffer - first page is from fd1, second page from fd2 */ +void * +mapBuffer(void *ar) +{ + void *addr; + char *buffer; + int i; + + i = (int )ar; + addr = mmap(NULL, pagesize * 2, PROT_READ | PROT_WRITE, MAP_SHARED, a[i].fd1, 0); + if (addr == MAP_FAILED) { + err(1, "Mmap failed"); + } + buffer = addr; + addr = mmap(buffer + pagesize, pagesize, PROT_READ | PROT_WRITE, MAP_FIXED | + MAP_SHARED, a[i].fd2, 0); + + if (addr == MAP_FAILED) { + err(1, "Mmap2 failed"); + } + a[i].bp = buffer; + sleep(1); + return (NULL); +} + + +int +startIO(int fd, char *buffer) +{ + ssize_t len; + + len = write(fd, buffer, 2 * pagesize); + if (len == -1) { + warn("startIO(%d, %p): write failed", fd, buffer); + return 1; + } + return 0; +} + + + +int +main(int argc, char *argv[], char *envp[]) +{ + + int fdA, fdB, fdDelayA, fdDelayB; + int r, status; + char *bufferA, *bufferB; + pid_t pid; + pthread_t threads[2]; + + pagesize = getpagesize(); + + if ((prepareFile("A", &fdA)) + || (prepareFile("B", &fdB)) + || (prepareFile("DelayA", &fdDelayA)) + || (prepareFile("DelayB", &fdDelayB))) + exit(1); + + a[0].fd1 = fdDelayA; + a[0].fd2 = fdB; + + a[1].fd1 = fdDelayB; + a[1].fd2 = fdA; + + if ((r = pthread_create(&threads[0], NULL, mapBuffer, (void *)0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + if ((r = pthread_create(&threads[1], NULL, mapBuffer, (void *)1)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + + while (a[0].bp == NULL || a[1].bp == NULL) + pthread_yield(); + + bufferA = a[0].bp; + bufferB = a[1].bp; + + pid = fork(); + + if (pid == 0) { + status = startIO(fdA, bufferA); + exit(status); + } + if (pid == -1) { + exit(1); + } + status = startIO(fdB, bufferB); + exit(status); + +} diff --git a/test/stress/stress2/misc/devfs.sh b/test/stress/stress2/misc/devfs.sh new file mode 100755 index 0000000000..8f3382803b --- /dev/null +++ b/test/stress/stress2/misc/devfs.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=10 # Number of parallel scripts +D=/usr/tmp/diskimage + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + [ ! -d ${mntpoint}$i ] && mkdir ${mntpoint}$i + mount | grep -q "${mntpoint}$i" && umount ${mntpoint}$i + done + + # start the parallel tests + for i in `jot $mounts`; do + ./$0 $i & + ./$0 find & + done + + for i in `jot $mounts`; do + wait; wait + done +else + if [ $1 = find ]; then + for i in `jot 64`; do + find ${mntpoint}* -maxdepth 1 -type f > /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + for i in `jot 64`; do + m=$1 + mount -t devfs none ${mntpoint}$m + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + while mount | grep -q ${mntpoint}$m; do + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + done + fi +fi diff --git a/test/stress/stress2/misc/devfs2.sh b/test/stress/stress2/misc/devfs2.sh new file mode 100755 index 0000000000..b9b23b9e4d --- /dev/null +++ b/test/stress/stress2/misc/devfs2.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Stopped at devfs_open+0x23f: pushl 0x14(%ebx) +# db> where +# Tracing pid 46017 tid 100350 td 0xc4c08510 +# devfs_open(e6d06a10) at devfs_open+0x23f +# VOP_OPEN_APV(c09edda0,e6d06a10) at VOP_OPEN_APV+0x9b +# vn_open_cred(e6d06b78,e6d06c78,0,c4883900,3,...) at vn_open_cred+0x41e +# vn_open(e6d06b78,e6d06c78,0,3) at vn_open+0x1e +# kern_open(c4c08510,8048887,0,1,0,...) at kern_open+0xb7 +# open(c4c08510,e6d06d00) at open+0x18 +# syscall(e6d06d38) at syscall+0x252 + +# Test scenario by kib@freebsd.org + +odir=`pwd` +dir=/tmp + +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/devfs2.c +cc -o devfs2 -Wall devfs2.c -lthr +rm -f devfs2.c + +./devfs2 + +rm devfs2 + +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include + +void * +thr1(void *arg) +{ + int fd; + int i; + + for (i = 0; i < 1024; i++) { + if ((fd = open("/dev/zero", O_RDONLY)) == -1) + perror("open /dev/zero"); + close(fd); + } + return (0); +} + +void * +thr2(void *arg) +{ + int i; + for (i = 0; i < 1024; i++) + close(3); + return (0); +} + +int +main() +{ + pthread_t threads[2]; + int i; + int r; + + if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + + for (i = 0; i < 2; i++) + if (pthread_join(threads[i], NULL) != 0) + err(1, "pthread_join(%d)", i); + + return (0); +} diff --git a/test/stress/stress2/misc/extattr.sh b/test/stress/stress2/misc/extattr.sh new file mode 100755 index 0000000000..37dcc70755 --- /dev/null +++ b/test/stress/stress2/misc/extattr.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test of extattr on a UFS2 FS using ACLs +# Caused a "Duplicate free" panic. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > extattr.c +cc -o extattr -Wall extattr.c +rm -f extattr.c +cd $odir + +mount | grep "${mntpoint}" | grep -q md${mdstart}${part} && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 20m -u $mdstart +bsdlabel -w md$mdstart auto + +newfs -O 2 md${mdstart}${part} > /dev/null +mount /dev/md${mdstart}${part} $mntpoint + +mkdir -p ${mntpoint}/.attribute/system +cd ${mntpoint}/.attribute/system + +extattrctl initattr -p . 388 posix1e.acl_access +extattrctl initattr -p . 388 posix1e.acl_default +cd / +umount /mnt +tunefs -a enable /dev/md${mdstart}${part} +mount /dev/md${mdstart}${part} $mntpoint +mount | grep md${mdstart}${part} + +touch $mntpoint/acl-test +setfacl -b $mntpoint/acl-test +setfacl -m user:nobody:rw-,group:wheel:rw- $mntpoint/acl-test + +for i in `jot 5`; do + /tmp/extattr $mntpoint/acl-test & +done +for i in `jot 5`; do + wait +done + +umount $mntpoint +mdconfig -d -u $mdstart +rm -f /tmp/extattr +exit +EOF +#include +#include +#include + +int +main(int argc, char **argv) +{ + int i; + struct stat sb; + + for (i = 0; i < 100000; i++) + if (lstat(argv[1], &sb) == -1) + err(1, "lstat(%s)", argv[1]); + return (0); +} diff --git a/test/stress/stress2/misc/extattrctl.sh b/test/stress/stress2/misc/extattrctl.sh new file mode 100755 index 0000000000..98a522b0cc --- /dev/null +++ b/test/stress/stress2/misc/extattrctl.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test of extattrctl and ACLs on UFS1 FS +# Kernel must be compiled with options UFS_EXTATTR and UFS_EXTATTR_AUTOSTART + +# Scenario by rwatson@ from: +# +# Newsgroups: lucky.freebsd.current +# Subject: Re: setfacl requirements? +# Date: Thu, 5 Dec 2002 15:50:02 +0000 (UTC) + + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +sysctl -a | ! grep -q ufs_extattr && echo "Missing options UFS_EXTATTR" && exit 1 + +mount | grep "${mntpoint}" | grep -q md${mdstart}${part} && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 20m -u $mdstart +bsdlabel -w md$mdstart auto + +newfs -O 1 md${mdstart}${part} > /dev/null +mount /dev/md${mdstart}${part} $mntpoint + +mkdir -p ${mntpoint}/.attribute/system +cd ${mntpoint}/.attribute/system + +extattrctl initattr -p . 388 posix1e.acl_access +extattrctl initattr -p . 388 posix1e.acl_default +cd / +umount /mnt +tunefs -a enable /dev/md${mdstart}${part} +mount /dev/md${mdstart}${part} $mntpoint +mount | grep md${mdstart}${part} + +touch $mntpoint/acl-test +setfacl -b $mntpoint/acl-test +setfacl -m user:nobody:rw-,group:wheel:rw- $mntpoint/acl-test +getfacl $mntpoint/acl-test +ls -l $mntpoint/acl-test + +umount $mntpoint +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/fdescfs.sh b/test/stress/stress2/misc/fdescfs.sh new file mode 100755 index 0000000000..a01ab93a10 --- /dev/null +++ b/test/stress/stress2/misc/fdescfs.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +mdstart=$mdstart # Use md unit numbers from this point +D=$diskimage + +if [ $# -eq 0 ]; then + # start the parallel tests + for i in `jot $mounts`; do + ./$0 $i & + ./$0 find & + done + + for i in `jot $mounts`; do + wait; wait + done +else + if [ $1 = find ]; then + exec 6< /dev/zero + exec 7< /dev/zero + exec 8< /dev/zero + exec 9< /dev/zero + for i in `jot 128`; do + ls -l ${mntpoint}* > /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + for i in `jot 128`; do +# mount -t fdescfs null ${mntpoint}$1 # This causes mound to complain + mount_fdescfs null ${mntpoint}$1 + while mount | grep -wq ${mntpoint}$1; do + umount -f ${mntpoint}$1 > /dev/null 2>&1 + done + done + fi +fi diff --git a/test/stress/stress2/misc/fpclone.sh b/test/stress/stress2/misc/fpclone.sh new file mode 100755 index 0000000000..907f5a0e46 --- /dev/null +++ b/test/stress/stress2/misc/fpclone.sh @@ -0,0 +1,197 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by kib@freebsd.org + +# Test of + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +dir=$RUNDIR/fpclone +[ ! -d $dir ] && mkdir -p $dir + +cd $dir +cat > Makefile < +EOF + +sed '1,/^EOF2/d' < $odir/$0 > fpclone.c +make +kldload $dir/fpclone.ko + +cd $odir +for i in `jot 10`; do + dd if=/dev/fpclone bs=1m count=10 > /dev/null 2>&1 & +done + +export runRUNTIME=2m +cd /home/pho/stress2; ./run.sh pty.cfg + +for i in `jot 10`; do + wait +done +kldstat +dd if=/dev/fpclone bs=1m count=1k > /dev/null 2>&1 & +kldunload $dir/fpclone.ko +rm -rf $dir +exit + +EOF2 +/* $FreeBSD$ */ + +#include +#include +#include +#include +#include +#include +#include + +typedef void (*cdevpriv_dtr_t)(void *data); +int devfs_get_cdevpriv(void **datap); +int devfs_set_cdevpriv(void *priv, cdevpriv_dtr_t dtr); +void devfs_clear_cdevpriv(void); +void devfs_fpdrop(struct file *fp); /* XXX This is not public KPI */ + + +static d_open_t fpclone_open; +static d_close_t fpclone_close; +static d_read_t fpclone_read; + +static struct cdevsw fpclone_cdevsw = { + .d_open = fpclone_open, + .d_close = fpclone_close, + .d_read = fpclone_read, + .d_name = "fpclone", + .d_version = D_VERSION, + .d_flags = D_TRACKCLOSE +}; + +MALLOC_DEFINE(M_FPCLONESC, "fpclone memory", "fpclone memory"); + +struct fpclone_sc +{ + int pos; +}; + +static struct cdev *fpclone_dev; +static struct mtx me; + +static void +fpclone_cdevpriv_dtr(void *data) +{ + free(data, M_FPCLONESC); +} + +static int +fpclone_open(struct cdev *dev, int oflags, int devtype, d_thread_t *td) +{ + struct fpclone_sc *sc; + int error; + + sc = malloc(sizeof(struct fpclone_sc), M_FPCLONESC, + M_WAITOK | M_ZERO); + error = devfs_set_cdevpriv(sc, fpclone_cdevpriv_dtr); + if (error) + fpclone_cdevpriv_dtr(sc); + return (error); +} + +static int +fpclone_close(struct cdev *dev, int fflag, int devtype, d_thread_t *td) +{ + + devfs_clear_cdevpriv(); + return (0); +} + +static char rdata[] = "fpclone sample data string\n"; + +static int +fpclone_read(struct cdev *dev, struct uio *uio, int ioflag) +{ + struct fpclone_sc *sc; + int rv, amnt, svpos, error; + + error = devfs_get_cdevpriv((void **)&sc); + if (error) + return (error); + + rv = 0; + while (uio->uio_resid > 0) { + svpos = sc->pos; + amnt = MIN(uio->uio_resid, sizeof(rdata) - svpos); + rv = uiomove(rdata + svpos, amnt, uio); + if (rv != 0) + break; + mtx_lock(&me); + sc->pos += amnt; + sc->pos %= sizeof(rdata); + mtx_unlock(&me); + } + return (rv); +} + +static int +fpclone_modevent(module_t mod, int what, void *arg) +{ + switch (what) { + case MOD_LOAD: + mtx_init(&me, "fp_ref", NULL, MTX_DEF); + fpclone_dev = make_dev(&fpclone_cdevsw, 0, 0, 0, 0666, + "fpclone"); + return(0); + + case MOD_UNLOAD: + destroy_dev(fpclone_dev); + mtx_destroy(&me); + return (0); + + default: + break; + } + + return (0); +} + +moduledata_t fpclone_mdata = { + "fpclone", + fpclone_modevent, + NULL +}; + +DECLARE_MODULE(fpclone, fpclone_mdata, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); +MODULE_VERSION(fpclone, 1); diff --git a/test/stress/stress2/misc/fpclone2.sh b/test/stress/stress2/misc/fpclone2.sh new file mode 100755 index 0000000000..cbbc79c22d --- /dev/null +++ b/test/stress/stress2/misc/fpclone2.sh @@ -0,0 +1,115 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by kib@freebsd.org + +# Test of + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +dir=$RUNDIR/fpclone +[ ! -d $dir ] && mkdir -p $dir + +cd $dir +cat > Makefile < +EOF + +sed '1,/^EOF2/d' < $odir/fpclone.sh > fpclone.c +make +kldload $dir/fpclone.ko + +sed '1,/^EOF2/d' < $odir/$0 > fpclone2.c +cc -o fpclone2 -Wall fpclone2.c +rm -f fpclone2.c + +cd $odir +for i in `jot 10`; do + $dir/fpclone2 & +done + +for i in `jot 10`; do + wait +done +kldstat +kldunload $dir/fpclone.ko +rm -rf $dir fpclone2 +exit + +EOF2 +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + int fd; + int i; + char buf[80]; + + for (i = 0; i < 10000; i++) { + if ((fd = open("/dev/fpclone", O_RDONLY)) == -1) + err(1, "open(/dev/fpclone"); + if (read(fd, buf, sizeof(buf)) <= 0) + err(1, "read"); + if (dup2(fd, 10) == -1) + err(1, "dup"); + if (dup2(fd, 11) == -1) + err(1, "dup"); + if (dup2(fd, 12) == -1) + err(1, "dup"); + if (close(fd) == -1) + err(1, "close(%d)", fd); + if (close(10) == -1) + err(1, "close(%d)", 10); + if (close(11) == -1) + err(1, "close(%d)", 11); + if (close(12) == -1) + err(1, "close(%d)", 12); + } + if ((fd = open("/dev/fpclone", O_WRONLY)) == -1) + err(1, "open(/dev/fpclone"); + if (write(fd, "xxx", 3) == -1 && errno != ENODEV) + err(1, "write"); + if (close(fd) == -1) + err(1, "close(%d)", fd); + + return (0); +} diff --git a/test/stress/stress2/misc/fpu.sh b/test/stress/stress2/misc/fpu.sh new file mode 100755 index 0000000000..e69ac61213 --- /dev/null +++ b/test/stress/stress2/misc/fpu.sh @@ -0,0 +1,105 @@ +#!/bin/sh + +# +# Copyright (c) 2010 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test for FPU changes in r208833 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > fpu.c +cc -o fpu -Wall -O2 fpu.c +rm -f fpu.c +[ -d $RUNDIR ] || mkdir -p $RUNDIR +cd $RUNDIR + +r=`/tmp/fpu` +[ "$r" = "-0.000000017, 0.000000000, 0.000000000" ] || echo $r + +cd $here +rm -f /tmp/fpu + +exit 0 +EOF +#include +#include +#include +#include +#include +#include + +void +handler(int i) +{ +} + +void +test() +{ + float val = 0; + double lval = 0; + long double llval = 0; + int i, j; + + for (i = 0; i < 100000; i++) { + for (j = 0; j < 100000; j++) { + val = val + 0.00001; + lval = lval + 0.00001; + llval = llval + 0.00001; + } + for (j = 0; j < 100000; j++) { + val = val - 0.00001; + lval = lval - 0.00001; + llval = llval - 0.00001; + } + } + printf("%.9f, %.9f, %.9Lf\n", val, lval, llval); + exit(0); + +} + +int +main() +{ + pid_t pid; + int i; + + signal(SIGHUP, handler); + + if ((pid = fork()) == 0) + test(); + + for (i = 0; i < 10000; i++) + kill(pid, SIGHUP); + + wait(NULL); + + return (0); +} diff --git a/test/stress/stress2/misc/fragments.sh b/test/stress/stress2/misc/fragments.sh new file mode 100755 index 0000000000..743633f8bf --- /dev/null +++ b/test/stress/stress2/misc/fragments.sh @@ -0,0 +1,266 @@ +#!/bin/sh + +# +# Copyright (c) 2010 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Scenario that causes "panic: brelse: free buffer onto another queue???" +# Idea for scenario by kib@. Fixed in r203818 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg +here=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $here/$0 > fragments.c +rm -f /tmp/fragments +cc -o fragments -Wall -Wextra -O2 -g fragments.c +rm -f fragments.c +cd $here + +mount | grep "$mntpoint" | grep -q md$mdstart && umount -f ${mntpoint} +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs -U -m 0 md${mdstart}${part} > /dev/null 2>&1 +mount /dev/md${mdstart}${part} /mnt +chmod 777 /mnt + +cd /mnt +su ${testuser} -c "/tmp/fragments" +cd $here + +umount /mnt +mount | grep "$mntpoint" | grep -q md$mdstart && umount -f ${mntpoint} +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +rm -f /tmp/fragments +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 50000 +#define PARALLEL 8 + +static pid_t pid; +static char *buf; + +void +cleanup(int n) +{ + int i, j, start; + int nb = 0; + char file[128]; + struct statfs sbuf; + struct stat sb; + + if (n == -1) { + for (i = 0; i < LOOPS; i++) { + sprintf(file,"t%05d", i); + unlink(file); + } + return; + } + + start = arc4random() % n; + for (i = 0; i < LOOPS; i++) { + j = (start + i) % LOOPS; + sprintf(file,"t%05d", j); + if (stat(file, &sb) != 0) + continue; + + if (sb.st_size == 0) { + unlink(file); + continue; + } + if (truncate(file, 0) == 0) { + nb++; + continue; + } + if (nb > 10) + break; + } + + + for (i = 0; i < 10; i++) { + if (statfs(".", &sbuf) < 0) + err(1, "statfs(%s)", "."); + + if (sbuf.f_bfree > 8) + return; + } + + for (i = 0; i < LOOPS; i++) { + j = (start + i) % LOOPS; + sprintf(file,"t%05d", j); + if (unlink(file) == 0) { + return; + } + } +} + +void +fragments(void) +{ + int i, len; + char file[128]; + int fd; + + for (i = 0;; i++) { + sprintf(file,"d%d/f%05d.%05d", i/1000, pid, i); + + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) { + if (errno != ENOSPC) + warn("open(%s)", file); + break; + } + + len = 2 * 1024; + if (write(fd, buf, len) != len) { + } + + close(fd); + } +} + +void +blocks(void) +{ + int i, len; + char file[128]; + int fd; + + for (i = 0;; i++) { + sprintf(file,"d%d/b%05d.%05d", i/1000, pid, i); + + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) { + if (errno != ENOSPC) + warn("open(%s)", file); + break; + } + + len = 16 * 1024; + if (write(fd, buf, len) != len) { + } + + close(fd); + } +} + +void +setup(void) +{ + int i; + char file[128]; + + for (i = 0; i < 300; i++) { + sprintf(file,"d%d", i); + if (mkdir(file, 0700) == -1) + warn("mkdir(%s)", file); + } + + blocks(); + fragments(); + + for (i = 0;i < 8; i++) { + sprintf(file,"d%d/b%05d.%05d", i/1000, pid, i); + unlink(file); + unlink(file); + } + for (i = 0;i < 1; i++) { + sprintf(file,"d%d/f%05d.%05d", i/1000, pid, i); + unlink(file); + } + +} + +int +test(void) +{ + int i, len, n; + char file[128]; + int fd; + + for (i = 0; i < LOOPS; i++) { + sprintf(file,"t%05d", i); + + if ((fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) { + continue; + } +// n = arc4random() % (12 + 1); + n = 0; + len = (arc4random() % (16 * 1024) + 1) + n * 16; + while (len > 0) { + if (write(fd, buf, len) == len) + break; + len = len / 2; + usleep(1000); + } + close(fd); + if (len == 0) { + cleanup(i); + } + } + + exit(0); + + return (0); +} + +int +main() +{ + int i, j, status; + + pid = getpid(); + if ((buf = malloc(12 * 16 * 1024)) == NULL) + err(1, "malloc()"); + + setup(); + for (j = 0; j < 50; j++) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) + wait(&status); + cleanup(-1); + } + return (0); +} diff --git a/test/stress/stress2/misc/fs.sh b/test/stress/stress2/misc/fs.sh new file mode 100755 index 0000000000..1425e611b9 --- /dev/null +++ b/test/stress/stress2/misc/fs.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Caused panic: ffs_truncate3 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +ftest () { # fstype, soft update, disk full + echo "newfs -O $1 `[ $2 -eq 1 ] && echo \"-U\"` md${mdstart}${part}" + newfs -O $1 `[ $2 -eq 1 ] && echo "-U"` md${mdstart}${part} > /dev/null + mount /dev/md${mdstart}${part} ${mntpoint} + + export RUNDIR=${mntpoint}/stressX + disk=$(($3 + 1)) # 1 or 2 + set `df -ik ${mntpoint} | tail -1 | awk '{print $4,$7}'` + export KBLOCKS=$(($1 * disk)) + export INODES=$(($2 * disk)) + + for i in `jot 10`; do + (cd ../testcases/rw;./rw -t 2m -i 20) + done + + while mount | grep -q ${mntpoint}; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") ${mntpoint} > /dev/null 2>&1 + done +} + + +mount | grep "${mntpoint}" | grep md${mdstart}${part} > /dev/null && umount ${mntpoint} +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t swap -s 20m -u ${mdstart} +bsdlabel -w md${mdstart} auto + +ftest 1 0 0 # ufs1 +ftest 1 0 1 # ufs1, disk full +ftest 2 0 0 # ufs2 +ftest 2 0 1 # ufs2, disk full +ftest 2 1 0 # ufs2 + soft update +ftest 2 1 1 # ufs2 + soft update, disk full + +mdconfig -d -u ${mdstart} diff --git a/test/stress/stress2/misc/fullpath.sh b/test/stress/stress2/misc/fullpath.sh new file mode 100755 index 0000000000..8c07e94865 --- /dev/null +++ b/test/stress/stress2/misc/fullpath.sh @@ -0,0 +1,113 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by marcus@freebsd.org + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fullpath.c +cc -o fullpath -Wall fullpath.c +rm -f fullpath.c +cd /proc + +for i in `jot 5`; do + /tmp/fullpath & +done + +for i in `jot 30`; do + for j in `jot 25`; do + pid=`perl -e 'print splice(@ARGV,rand(@ARGV),1), " ";' $(echo [0-9]*)` +# echo $pid + procstat -f $pid > /dev/null 2>&1 + procstat -f $pid > /dev/null 2>&1 + procstat -f $pid > /dev/null 2>&1 + procstat -f $pid > /dev/null 2>&1 + procstat -f $pid > /dev/null 2>&1 + done +done + +for i in `jot 5`; do + wait +done + +rm -f /tmp/fullpath +exit +EOF + +#include +#include +#include +#include +#include +#include +#include + +char buf[4096]; + +void +handler(int i) { + exit(0); +} + +int +test(void) { + pid_t r; + int status; + + for (;;) { + r = fork(); + if (r == 0) { + bzero(buf, sizeof(buf)); + exit(0); /*child dies */ + } + if (r < 0) { + perror("fork"); + exit(2); + } + wait(&status); + } + return 0; +} + +int main(int argc, char **argv) +{ + int i; + + i = 0; + signal(SIGALRM, handler); + alarm(60); + + + return test(); +} diff --git a/test/stress/stress2/misc/fuzz.sh b/test/stress/stress2/misc/fuzz.sh new file mode 100755 index 0000000000..b86281c9af --- /dev/null +++ b/test/stress/stress2/misc/fuzz.sh @@ -0,0 +1,180 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Stress test UFS2 file systems by introducing single bit errors in the FS +# fsck fould fix the FS no matter how damaged, but f.x. this panic has been seen: +# +# panic(c0912b65,dfe96000,0,c09e4060,ef48c778,...) at panic+0x14b +# vm_fault(c1868000,dfe96000,1,0) at vm_fault+0x1e0 +# trap_pfault(ef48c894,0,dfe96000) at trap_pfault+0x137 +# trap(dfe90008,ef480028,c0690028,d0560000,dfe96000,...) at trap+0x341 +# calltrap() at calltrap+0x5 +# --- trap 0xc, eip = 0xc08785a6, esp = 0xef48c8d4, ebp = 0xef48c958 --- +# generic_bcopy(c81cd570,d0508000,c5ead600,c87b81c0,0,...) at generic_bcopy+0x1a +# ffs_mount(d0508000,c5ead600,0,c09b0860,c5ecfc3c,...) at ffs_mount+0xa14 +# vfs_domount(c5ead600,cd8c7280,ccb75080,0,...) at vfs_domount+0x687 +# vfs_donmount(c5ead600,0,ef48cc04) at vfs_donmount+0x2ef +# kernel_mount(c5660960,0,bfbfec86,0,fffffffe,...) at kernel_mount+0x6d +# ffs_cmount(c5660960,bfbfde50,0,c5ead600,c09b0860,...) at ffs_cmount+0x5d +# mount(c5ead600,ef48cd04) at mount+0x156 +# syscall(3b,3b,3b,804abcf,bfbfe8e4,...) at syscall+0x22f + + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage + +tst() { + rm -f $D + truncate -s 2M $D + mdconfig -a -t vnode -f $D -u $mdstart + bsdlabel -w md$mdstart auto + newfs -b 8192 -f 1024 -U /dev/md${mdstart}${part} > /dev/null 2>&1 + mount /dev/md${mdstart}${part} $mntpoint + cp /etc/passwd /etc/group /etc/hosts $mntpoint + cp -r /usr/include/ufs $mntpoint + umount $mntpoint + + for i in `jot 50`; do + ./fuzz -n 50 $D + if fsck -f -y /dev/md${mdstart}${part} 2>&1 | egrep "^[A-Z]" > /dev/null; then + if fsck -f -y /dev/md${mdstart}${part} 2>&1 | egrep "^[A-Z]" > /dev/null; then + if fsck -f -y /dev/md${mdstart}${part} 2>&1 | egrep "^[A-Z]" > /dev/null; then + echo "fsck is giving up in loop $i!" + break + fi + fi + fi + sync;sync;sync + if mount /dev/md${mdstart}${part} $mntpoint; then + ls -l $mntpoint > /dev/null + find $mntpoint -exec dd if={} of=/dev/null bs=1m count=3 \; > /dev/null 2>&1 + umount $mntpoint + else + echo "Giving up at loop $i" + break + fi + done + mdconfig -d -u ${mdstart} + rm -f $D +} + +odir=`pwd` +dir=/tmp + +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/fuzz.c +cc -o fuzz -Wall fuzz.c +rm -f fuzz.c + +for j in `jot 10`; do + date '+%T' + tst +done +rm -f fuzz + +exit + +EOF +#include +#include +#include +#include +#include +#include + +void +usage(void) +{ + fprintf(stderr, "%s {-n \n", getprogname()); + exit(1); +} + +long +random_long(long mi, long ma) +{ + return (arc4random() % (ma - mi + 1) + mi); +} + +int +main(int argc, char **argv) +{ + int ch, fd, i, times = 1, verbose = 0; + long pos; + unsigned char bit, buf, mask, old; + struct stat sb; + + while ((ch = getopt(argc, argv, "n:v")) != -1) + switch(ch) { + case 'n': /* Bits to alter */ + if (sscanf(optarg, "%d", ×) != 1) + usage(); + break; + case 'v': /* verbose flag */ + verbose += 1; + break; + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc == 0) + usage(); + + + if ((fd = open(argv[0], O_RDWR)) == -1) + err(1, "open(%s)", argv[0]); + if (fstat(fd, &sb) == -1) + err(1, "stat(%s)", argv[0]); + + for (i = 0; i < times; i++) { + pos = random_long(0, sb.st_size - 1); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "fseek(%d, %ld)", fd, pos); + if (read(fd, &buf, 1) != 1) + err(1, "read(%d)", fd); + bit = random_long(0,7); + mask = ~(1 << bit); + old = buf; + buf = (buf & mask) | (~buf & ~mask); + if (verbose > 0) + printf("Change %2x to %2x at %4ld by flipping bit %d\n", + old, buf, pos, bit); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "fseek(%d, %ld)", fd, pos); + if (write(fd, &buf, 1) != 1) + err(1, "write(%d)", fd); + } + close(fd); + return (0); +} diff --git a/test/stress/stress2/misc/inversion.sh b/test/stress/stress2/misc/inversion.sh new file mode 100755 index 0000000000..5bb7a57041 --- /dev/null +++ b/test/stress/stress2/misc/inversion.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Provokes a deadlock by lower priority process holding a lock and +# never beeing run + +dir=/tmp +N=5 # Number of CPUs + 1 +M=25 # Number of lower priority jobs + +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/inversion.c +cc -o inversion -Wall inversion.c +rm -f inversion.c + +for i in `jot $N`; do + ./inversion 3700& +done + +while pgrep inversion > /dev/null; do + date '+%T' + ( + for i in `jot $M`; do + nice -n 20 lockf -s -t 0 .lock pwd > /dev/null & + done + for i in `jot $M`; do + wait + done + ) +done + +for i in `jot $N`; do + wait +done +rm -f inversion +exit + +EOF +#include +#include +#include + +void +handler(int i) +{ + exit(0); +} + +int +main(int argc, char **argv) +{ + + int t; + if (argc == 2) + t = atoi(argv[1]); + else + t = 60; + signal(SIGALRM, handler); + alarm(t); + for (;;) + ; + return (0); +} diff --git a/test/stress/stress2/misc/isofs.sh b/test/stress/stress2/misc/isofs.sh new file mode 100755 index 0000000000..c51b1c43ee --- /dev/null +++ b/test/stress/stress2/misc/isofs.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must not be root!" && exit 1 + +[ -z "`type mkisofs 2>/dev/null`" ] && echo "mkisofs not found" && exit 1 + +. ../default.cfg + +D=`dirname $diskimage`/dir +I=`dirname $diskimage`/dir.iso +export here=`pwd` +cd /tmp + +cc -o fstool $here/../tools/fstool.c + +rm -rf $D $I +mkdir $D + +(cd $D; /tmp/fstool -n 10 -l -f 512) + +mkisofs -o $I -r $D > /dev/null 2>&1 + +mdconfig -a -t vnode -f $I -u ${mdstart} +mount -t cd9660 /dev/md${mdstart} $mntpoint + +for i in `jot 64`; do + find /$mntpoint -type f > /dev/null 2>&1 & +done +for i in `jot 64`; do + wait +done + +umount ${mntpoint} +mdconfig -d -u ${mdstart} + +rm -rf $D $I fstool diff --git a/test/stress/stress2/misc/jail.sh b/test/stress/stress2/misc/jail.sh new file mode 100755 index 0000000000..8798d7480f --- /dev/null +++ b/test/stress/stress2/misc/jail.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test for problem found with the syscall.sh test + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > jail.c +cc -o jail -Wall jail.c +rm -f jail.c +cd $RUNDIR +/tmp/jail +rm -f /tmp/jail +exit +EOF +#include +#include +#include + +int +main() +{ + struct jail j; + + j.version = 2; + j.path = (char *)0xa000000; + j.hostname = (char *)1; + j.jailname = (char *)0; + j.ip4s = 0; + j.ip6s = 0; + j.ip4 = (struct in_addr *)0x58000000; + j.ip6 = (struct in6_addr *)0x33000001; + + if (jail(&j) == -1) + err(1, "jail()"); + + return (0); +} diff --git a/test/stress/stress2/misc/jail2.sh b/test/stress/stress2/misc/jail2.sh new file mode 100755 index 0000000000..94500b42c0 --- /dev/null +++ b/test/stress/stress2/misc/jail2.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test for problem found with the syscall.sh test + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > jail2.c +cc -o jail2 -Wall jail2.c +rm -f jail2.c +cd $odir +/tmp/jail2 +rm -f /tmp/jail2 +exit +EOF +#include +#include +#include + +int +main() +{ + struct jail j; + + /* + version = 0x2, + path = 0x0, + hostname = 0x0, + jailname = 0x50000000
, + ip4s = 0xf7000004, + ip6s = 0x1, + ip4 = 0x0, + ip6 = 0x0 + */ + j.version = 2; + j.path = 0; + j.hostname = 0; + j.jailname = (char *)0x50000000; + j.ip4s = 0xf7000004; + j.ip6s = 1; + j.ip4 = 0; + j.ip6 = 0; + + if (jail(&j) == -1) + err(1, "jail()"); + + return (0); +} diff --git a/test/stress/stress2/misc/jail3.sh b/test/stress/stress2/misc/jail3.sh new file mode 100755 index 0000000000..eb7115d2fe --- /dev/null +++ b/test/stress/stress2/misc/jail3.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test for problem found with the syscall.sh test + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > jail3.c +cc -o jail3 -Wall jail3.c +rm -f jail3.c +cd $odir +/tmp/jail3 +rm -f /tmp/jail3 +exit +EOF +#include +#include +#include + +int +main() +{ + struct jail j; + + /* + version = 0x0, + path = 0x2809cd61
, + hostname = 0x2809b650
, + jailname = 0x0, + ip4s = 0x1, + ip6s = 0x0, + ip4 = 0x0, + ip6 = 0x0 + */ + j.version = 0; + j.path = (char *)0x2809cd61; + j.hostname = (char *)0x2809b650; + j.jailname = 0; + j.ip4s = 1; + j.ip6s = 0; + j.ip4 = 0; + j.ip6 = 0; + + if (jail(&j) == -1) + err(1, "jail()"); + + return (0); +} diff --git a/test/stress/stress2/misc/jail4.sh b/test/stress/stress2/misc/jail4.sh new file mode 100755 index 0000000000..48c56efb39 --- /dev/null +++ b/test/stress/stress2/misc/jail4.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test for problem found with the syscall.sh test + +# "panic: kern_jail: too many iovecs (28)" seen. + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > jail4.c +cc -o jail4 -Wall jail4.c +rm -f jail4.c +cd $odir +/tmp/jail4 +rm -f /tmp/jail4 +exit +EOF +#include +#include +#include + +int +main() +{ + struct jail j; + + /* + version = 0x2, + path = 0x28190cb1
, + hostname = 0x28167b90
, + jailname = 0x28198700
, + ip4s = 0x0, + ip6s = 0x0, + ip4 = 0x0, + ip6 = 0x0} + */ + j.version = 2; + j.path = (char *)0x28190cb1; + j.hostname = (char *)0x28167b90; + j.jailname = (char *)0x28198700; + j.ip4s = 0; + j.ip6s = 0; + j.ip4 = 0; + j.ip6 = 0; + + if (jail(&j) == -1) + err(1, "jail()"); + + return (0); +} diff --git a/test/stress/stress2/misc/kevent.sh b/test/stress/stress2/misc/kevent.sh new file mode 100755 index 0000000000..deeb0787e6 --- /dev/null +++ b/test/stress/stress2/misc/kevent.sh @@ -0,0 +1,173 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# panic: KN_INFLUX set when not suppose to be + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent.c +cc -o kevent -Wall kevent.c -pthread +rm -f kevent.c +cd $RUNDIR + +for i in `jot 10`; do + for j in `jot 12`; do + /tmp/kevent > /dev/null 2>&1 & + done + for j in `jot 12`; do + wait + done +done +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include + +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +static int waiting; + +static int fd1[2]; +static int fd2[2]; +static int fd3[2]; + +void * +thr1(void *arg) +{ + int n; + int kq = -1; + struct kevent ev[3]; + + if ((kq = kqueue()) < 0) + err(1, "kqueue(). %s:%d", __FILE__, __LINE__); + + n = 0; + EV_SET(&ev[n], fd1[1], EVFILT_WRITE, + EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); + n++; + EV_SET(&ev[n], fd2[1], EVFILT_WRITE, + EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); + n++; + EV_SET(&ev[n], fd3[1], EVFILT_WRITE, + EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); + n++; + + if (kevent(kq, ev, n, NULL, 0, NULL) < 0) + err(1, "kevent(). %s:%d", __FILE__, __LINE__); + + if (pthread_mutex_lock(&mutex) == -1) + err(1, "pthread_mutex_lock"); + waiting = 0; + if (pthread_cond_signal(&cond) == -1) + err(1, "pthread_cond_signal"); + if (pthread_mutex_unlock(&mutex) == -1) + err(1, "pthread_mutex_unlock"); + + n = 0; + EV_SET(&ev[n], fd1[1], EVFILT_WRITE, + EV_DELETE, 0, 0, 0); + n++; + if (kevent(kq, ev, n, NULL, 0, NULL) < 0) + err(1, "kevent(). %s:%d", __FILE__, __LINE__); + close(kq); + +// printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); + return (0); +} + +void * +thr2(void *arg) +{ + if (pthread_mutex_lock(&mutex) == -1) + err(1, "pthread_mutex_lock"); + while (waiting == 1) { + if (pthread_cond_wait(&cond, &mutex) == -1) + err(1, "pthread_cond_wait"); + } + if (pthread_mutex_unlock(&mutex) == -1) + err(1, "pthread_mutex_unlock"); +// printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); + close(fd1[0]); + close(fd1[1]); + close(fd2[0]); + close(fd2[1]); + close(fd3[0]); + close(fd3[1]); + return (0); +} + +int +main(int argc, char **argv) +{ + pthread_t threads[2]; + int r; + int i; + + for (i = 0; i < 1000; i++) { + waiting = 1; +// printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); + if (pipe(fd1) == -1) + err(1, "pipe()"); + if (pipe(fd2) == -1) + err(1, "pipe()"); + if (pipe(fd3) == -1) + err(1, "pipe()"); + + if (pthread_mutex_init(&mutex, 0) == -1) + err(1, "pthread_mutex_init"); + if (pthread_cond_init(&cond, NULL) == -1) + err(1, "pthread_cond_init"); + + if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + + if (pthread_join(threads[0], NULL) != 0) + err(1, "pthread_join(%d)", 0); + if (pthread_join(threads[1], NULL) != 0) + err(1, "pthread_join(%d)", 1); + if (pthread_mutex_destroy(&mutex) == -1) + err(1, "pthread_mutex_destroy"); + if (pthread_cond_destroy(&cond) == -1) + err(1, "pthread_condattr_destroy"); + } + + return (0); +} diff --git a/test/stress/stress2/misc/kevent2.sh b/test/stress/stress2/misc/kevent2.sh new file mode 100755 index 0000000000..1d448ca91d --- /dev/null +++ b/test/stress/stress2/misc/kevent2.sh @@ -0,0 +1,175 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent.c +cc -o kevent -Wall kevent.c -pthread +rm -f kevent.c +cd $RUNDIR + +for i in `jot 10`; do + for j in `jot 12`; do + /tmp/kevent > /dev/null 2>&1 & + done + for j in `jot 12`; do + wait + done +done +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include + +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +static int waiting; + +static int fd1[2]; +static int fd2[2]; +static int fd3[2]; + +void * +thr1(void *arg) +{ + int n; + int kq = -1; + struct kevent ev[3]; + struct timespec ts; + + if ((kq = kqueue()) < 0) + err(1, "kqueue(). %s:%d", __FILE__, __LINE__); + + n = 0; + EV_SET(&ev[n], fd1[1], EVFILT_WRITE, + EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); + n++; + EV_SET(&ev[n], fd2[1], EVFILT_WRITE, + EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); + n++; + EV_SET(&ev[n], fd3[1], EVFILT_WRITE, + EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); + n++; + + if (kevent(kq, ev, n, NULL, 0, NULL) < 0) + err(1, "kevent(). %s:%d", __FILE__, __LINE__); + + if (pthread_mutex_lock(&mutex) == -1) + err(1, "pthread_mutex_lock"); + waiting = 0; + if (pthread_cond_signal(&cond) == -1) + err(1, "pthread_cond_signal"); + if (pthread_mutex_unlock(&mutex) == -1) + err(1, "pthread_mutex_unlock"); + + n = 0; + EV_SET(&ev[n], fd1[1], EVFILT_WRITE, + EV_DELETE, 0, 0, 0); + n++; + ts.tv_sec = 0; + ts.tv_nsec = 0; + if (kevent(kq, ev, n, NULL, 0, &ts) < 0) + err(1, "kevent(). %s:%d", __FILE__, __LINE__); + close(kq); + +// printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); + close(fd1[1]); + close(fd2[1]); + close(fd3[1]); + return (0); +} + +void * +thr2(void *arg) +{ + if (pthread_mutex_lock(&mutex) == -1) + err(1, "pthread_mutex_lock"); + while (waiting == 1) { + if (pthread_cond_wait(&cond, &mutex) == -1) + err(1, "pthread_cond_wait"); + } + if (pthread_mutex_unlock(&mutex) == -1) + err(1, "pthread_mutex_unlock"); +// printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); + close(fd1[0]); + close(fd2[0]); + close(fd3[0]); + return (0); +} + +int +main(int argc, char **argv) +{ + pthread_t threads[2]; + int r; + int i; + + for (i = 0; i < 1000; i++) { + waiting = 1; +// printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); + if (pipe(fd1) == -1) + err(1, "pipe()"); + if (pipe(fd2) == -1) + err(1, "pipe()"); + if (pipe(fd3) == -1) + err(1, "pipe()"); + + if (pthread_mutex_init(&mutex, 0) == -1) + err(1, "pthread_mutex_init"); + if (pthread_cond_init(&cond, NULL) == -1) + err(1, "pthread_cond_init"); + + if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + + if (pthread_join(threads[0], NULL) != 0) + err(1, "pthread_join(%d)", 0); + if (pthread_join(threads[1], NULL) != 0) + err(1, "pthread_join(%d)", 1); + if (pthread_mutex_destroy(&mutex) == -1) + err(1, "pthread_mutex_destroy"); + if (pthread_cond_destroy(&cond) == -1) + err(1, "pthread_condattr_destroy"); + } + + return (0); +} diff --git a/test/stress/stress2/misc/kevent3.sh b/test/stress/stress2/misc/kevent3.sh new file mode 100755 index 0000000000..4cc7d378a0 --- /dev/null +++ b/test/stress/stress2/misc/kevent3.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent.c +cc -o kevent -Wall kevent.c -pthread +rm -f kevent.c +cd $RUNDIR + +for i in `jot 64`; do + for j in `jot 12`; do + /tmp/kevent > /dev/null 2>&1 & + done + for j in `jot 12`; do + wait + done +done +exit +EOF +/* + * Obtained from: + * http://projects.info-pull.com/mokb/MOKB-24-11-2006.html + */ +#include +#include +#include +#include +#include + +int main(void) +{ + struct kevent ke; + int kq; + kq = kqueue(); + EV_SET(&ke, getpid(), EVFILT_PROC, EV_ADD, + NOTE_EXIT|NOTE_EXEC|NOTE_TRACK, 0, NULL); + kevent(kq, &ke, 1, NULL, 0, NULL); + if (fork() != 0) + kevent(kq, NULL, 0, &ke, 1, NULL); + return (0); +} diff --git a/test/stress/stress2/misc/kevent4.sh b/test/stress/stress2/misc/kevent4.sh new file mode 100755 index 0000000000..e782783de3 --- /dev/null +++ b/test/stress/stress2/misc/kevent4.sh @@ -0,0 +1,202 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# +# Test scenario by kib@ + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent.c +cc -o kevent -Wall kevent.c -pthread +rm -f kevent.c + +cd $odir/.. +export runRUNTIME=3m +./run.sh & +rpid=$! + +cd $RUNDIR +/tmp/kevent $rpid & + +sleep 120 +kill $rpid +kill $! +rm -f /tmp/kevent + +exit +EOF +// $FreeBSD$ + +#include +#include +#include +#include +#include +#include +#include +#ifndef true +# define true 1 +#endif + +int kq; + +void +err(const char *msg, int err_no) +{ + fprintf(stderr, "%s: %s\n", msg, strerror(err_no)); + exit(1); +} + +void +init_kq() +{ + kq = kqueue(); + if (kq == -1) + err("kqueue", errno); +} + +void +add_watch(pid_t pid) +{ + struct kevent kev; + bzero(&kev, sizeof(kev)); + kev.ident = pid; + kev.flags = EV_ADD | EV_ENABLE; + kev.filter = EVFILT_PROC; + kev.fflags = NOTE_EXIT | NOTE_FORK | NOTE_EXEC | NOTE_TRACK; + + while (true) { + int res = kevent(kq, &kev, 1, NULL, 0, NULL); + if (res == -1) { + if (errno == EINTR) + continue; + if (errno == ESRCH) + break; + + int err_no = errno; + char msg[64]; + snprintf(msg, sizeof(msg), + "kevent - add watch for pid %u", pid); + err(msg, err_no); + } + else + break; + } +} + +void +del_watch(pid_t pid) +{ + struct kevent kev; + bzero(&kev, sizeof(kev)); + kev.ident = pid; + kev.flags = EV_DELETE; + kev.filter = EVFILT_PROC; + + while (true) { + int res = kevent(kq, &kev, 1, NULL, 0, NULL); + if (res == -1) { + if (errno == EINTR) + continue; + if (errno == ESRCH) + break; + + int err_no = errno; + char msg[64]; + snprintf(msg, sizeof(msg), + "kevent - del watch for pid %u", pid); + err(msg, err_no); + } + else + break; + } +} + +void polling() +{ + struct kevent kev[10]; + pid_t pid; + int i; + + while (true) { + bzero(&kev, sizeof(kev)); + int res = kevent(kq, NULL, 0, kev, + sizeof(kev) / sizeof(kev[0]), NULL); + if (res == -1) { + if (errno == EINTR) + continue; + + if (errno == ESRCH) + continue; + + err("kevent", errno); + } + + for (i = 0; i < res; i++) { + pid = kev[i].ident; + if (kev[i].fflags & NOTE_CHILD) { + add_watch(pid); + printf("%u - new process, parent %u\n", pid, kev[i].data); + } + if (kev[i].fflags & NOTE_FORK) { + printf("%u forked\n", pid); + } + if (kev[i].fflags & NOTE_EXEC) { + printf("%u called exec\n", pid); + } + if (kev[i].fflags & NOTE_EXIT) { + printf("%u exited\n", pid); +// del_watch(pid); + } + if (kev[i].fflags & NOTE_TRACK) { + printf("%u forked - track\n", pid); + } + if (kev[i].fflags & NOTE_TRACKERR) { + fprintf(stderr, "%u - track error\n", pid); + } + } + } +} + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + fprintf(stderr, "pid ?\n"); + return (2); + } + pid_t parent = atoi(argv[1]); + + init_kq(); + add_watch(parent); + polling(); + + return (0); +} diff --git a/test/stress/stress2/misc/kevent5.sh b/test/stress/stress2/misc/kevent5.sh new file mode 100755 index 0000000000..d3ff75af13 --- /dev/null +++ b/test/stress/stress2/misc/kevent5.sh @@ -0,0 +1,161 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# +# Test EVFILT_VNODE. Found page fault in knlist_add+0x39 +# +# Test scenario by kib@ + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent.c +cc -o kevent -Wall kevent.c +rm -f kevent.c + +cd $RUNDIR/.. +/tmp/kevent xxx yyy + +rm -f /tmp/kevent + +exit +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static char *file1, *file2; + +#define N 1000 + + +void +test(test) { + int kq = -1; + int n; + struct kevent ev[2]; + int fd; + + if ((fd = open(file1, O_RDONLY, 0)) == -1) + err(1, "open(%s)(2)", file1); + + if ((kq = kqueue()) < 0) + err(1, "kqueue()"); + + n = 0; + EV_SET(&ev[n], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, + NOTE_DELETE, 0, 0); + n++; + + if (kevent(kq, ev, n, NULL, 0, NULL) < 0) + err(1, "kevent()"); + + memset(&ev, 0, sizeof(ev)); + n = kevent(kq, NULL, 0, ev, 1, NULL); +// printf("Event 1\n"); + close(fd); + close(kq); + +/* Once the rendezvous file is gone create a new kevent */ + + if ((fd = open(file2, O_RDONLY, 0)) == -1) + err(1, "open(%s)(2)", file2); + + if ((kq = kqueue()) < 0) + err(1, "kqueue()"); + + n = 0; + EV_SET(&ev[n], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, + NOTE_DELETE, 0, 0); + n++; + + if (kevent(kq, ev, n, NULL, 0, NULL) < 0) + err(1, "kevent()"); + + memset(&ev, 0, sizeof(ev)); + n = kevent(kq, NULL, 0, ev, 1, NULL); +// printf("Event 2\n"); + close(fd); + close(kq); +} + +int +main(int argc, char **argv) { + int i, j; + int fd; + int status; + + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return (1); + } + file1 = argv[1]; + file2 = argv[2]; + + for (j = 0; j < 100; j++) { + if ((fd = open(file1, O_CREAT | O_TRUNC | O_RDWR, 0660)) == -1) + err(1, "open(%s)", file1); + close(fd); + if ((fd = open(file2, O_CREAT | O_TRUNC | O_RDWR, 0660)) == -1) + err(1, "open(%s)", file2); + close(fd); + + for (i = 0; i < N; i++) { + if (fork() == 0) { + test(); + return (0); + } + } + + sleep(1); + if (unlink(file1) == -1) + err(1, "unlink(%s). %s:%d\n", file1, __FILE__, __LINE__); + sleep(1); + if (unlink(file2) == -1) + err(1, "unlink(%s). %s:%d\n", file2, __FILE__, __LINE__); + + for (i = 0; i < N; i++) { + if (wait(&status) == -1) + err(1, "wait(), %s:%d", __FILE__, __LINE__); + } + } + + return (0); +} diff --git a/test/stress/stress2/misc/kinfo.sh b/test/stress/stress2/misc/kinfo.sh new file mode 100755 index 0000000000..2f33255635 --- /dev/null +++ b/test/stress/stress2/misc/kinfo.sh @@ -0,0 +1,164 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by marcus@freebsd.org + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kinfo.c +cc -o kinfo -Wall kinfo.c -lutil +rm -f kinfo.c + +mount | grep -q procfs || mount -t procfs procfs /procfs +for i in `jot 30`; do + for j in `jot 5`; do + /tmp/kinfo & + done + + for j in `jot 5`; do + wait + done +done + +rm -f /tmp/kinfo +exit +EOF + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char buf[8096]; + +void +handler(int i) { + exit(0); +} + +/* Stir /dev/proc */ +int +churning(void) { + pid_t r; + int fd, status; + + for (;;) { + r = fork(); + if (r == 0) { + if ((fd = open("/proc/curproc/mem", O_RDONLY)) == -1) + err(1, "open(/proc/curproc/mem)"); + bzero(buf, sizeof(buf)); + exit(0); + } + if (r < 0) { + perror("fork"); + exit(2); + } + wait(&status); + } +} + +/* Get files for each proc */ +void +list(void) +{ + struct kinfo_file *freep; + struct kinfo_vmentry *freep_vm; + long i; + int cnt, name[4]; + struct kinfo_proc *kipp; + size_t len; + + name[0] = CTL_KERN; + name[1] = KERN_PROC; + name[2] = KERN_PROC_PROC; + + len = 0; + if (sysctl(name, 3, NULL, &len, NULL, 0) < 0) + err(-1, "sysctl: kern.proc.all"); + + kipp = malloc(len); + if (kipp == NULL) + err(1, "malloc"); + + if (sysctl(name, 3, kipp, &len, NULL, 0) < 0) { + free(kipp); +// warn("sysctl: kern.proc.all"); + return; + } + + for (i = 0; i < len / sizeof(*kipp); i++) { + + /* The test starts here */ + freep = kinfo_getfile(kipp[i].ki_pid, &cnt); + free(freep); + + freep_vm = kinfo_getvmmap(kipp[i].ki_pid, &cnt); + free(freep_vm); + /* End test */ + } + free(kipp); +} + +int +main(int argc, char **argv) +{ + pid_t r; + signal(SIGALRM, handler); + alarm(60); + + if ((r = fork()) == 0) { + alarm(60); + for (;;) + churning(); + } + if (r < 0) { + perror("fork"); + exit(2); + } + + for (;;) + list(); + + return (0); +} diff --git a/test/stress/stress2/misc/kinfo2.sh b/test/stress/stress2/misc/kinfo2.sh new file mode 100755 index 0000000000..941b41364b --- /dev/null +++ b/test/stress/stress2/misc/kinfo2.sh @@ -0,0 +1,176 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by marcus@freebsd.org + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kinfo.c +cc -o kinfo -Wall kinfo.c -lutil +rm -f kinfo.c + +mount | grep -q procfs || mount -t procfs procfs /procfs +for i in `jot 30`; do + for j in `jot 5`; do + /tmp/kinfo & + done + + for j in `jot 5`; do + wait + done +done + +rm -f /tmp/kinfo +exit +EOF + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char buf[8096]; + +void +handler(int i) { + exit(0); +} + +/* Stir /dev/proc */ +int +churning(void) { + pid_t r; + int fd, status; + + for (;;) { + r = fork(); + if (r == 0) { + if ((fd = open("/proc/curproc/mem", O_RDONLY)) == -1) + err(1, "open(/proc/curproc/mem)"); + bzero(buf, sizeof(buf)); + exit(0); + } + if (r < 0) { + perror("fork"); + exit(2); + } + wait(&status); + } +} + +/* Get files for each proc */ +void +list(void) +{ + int cnt, fd, n; + int space = sizeof(buf); + long base; + struct dirent *dp; + struct kinfo_file *freep; + struct kinfo_vmentry *freep_vm; + char *bp = buf; + pid_t pid; + long l; + char *dummy; + + if ((fd = open("/proc", O_RDONLY)) == -1) + err(1, "open(%s)", "/proc"); + + do { + if ((n = getdirentries(fd, bp, space, &base)) == -1) + err(1, "getdirentries"); + space = space - n; + bp = bp + n; + } while (n != 0); + close(fd); + + bp = buf; + dp = (struct dirent *)bp; + for (;;) { +#if 0 + printf("name: %-10s, inode %7d, type %2d, namelen %d, d_reclen %d\n", + dp->d_name, dp->d_fileno, dp->d_type, dp->d_namlen, + dp->d_reclen); fflush(stdout); +#endif + + if (dp->d_type == DT_DIR && + (dp->d_name[0] >= '0' && dp->d_name[0] <= '9')) { + l = strtol(dp->d_name, &dummy, 10); + pid = l; + + /* The tests start here */ + freep = kinfo_getfile(pid, &cnt); + free(freep); + + freep_vm = kinfo_getvmmap(pid, &cnt); + free(freep_vm); + /* End test */ + } + + bp = bp + dp->d_reclen; + dp = (struct dirent *)bp; + if (dp->d_reclen <= 0) + break; + } +} + +int +main(int argc, char **argv) +{ + pid_t r; + signal(SIGALRM, handler); + alarm(60); + + if ((r = fork()) == 0) { + alarm(60); + for (;;) + churning(); + } + if (r < 0) { + perror("fork"); + exit(2); + } + + for (;;) + list(); + + return (0); +} diff --git a/test/stress/stress2/misc/kinfo3.sh b/test/stress/stress2/misc/kinfo3.sh new file mode 100755 index 0000000000..a8d4d3c571 --- /dev/null +++ b/test/stress/stress2/misc/kinfo3.sh @@ -0,0 +1,191 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by marcus@freebsd.org and kib@freebsd.org + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kinfo.c +cc -o kinfo -Wall kinfo.c -lutil -pthread +rm -f kinfo.c + +mount | grep -q procfs || mount -t procfs procfs /procfs +for i in `jot 30`; do + for j in `jot 5`; do + /tmp/kinfo & + done + + for j in `jot 5`; do + wait + done +done + +rm -f /tmp/kinfo +exit +EOF + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char buf[8096]; + +void +handler(int i) { + exit(0); +} + +void * +thr(void *arg) +{ + int fd; + if ((fd = open("/proc/curproc/mem", O_RDONLY)) == -1) + err(1, "open(/proc/curproc/mem)"); + close(fd); + return (0); +} + + +/* Stir /dev/proc */ +int +churning(void) { + int i; + pid_t r; + int status; + pthread_t threads[5]; + + + for (;;) { + r = fork(); + if (r == 0) { + for (i = 0; i < 5; i++) { + if ((r = pthread_create(&threads[i], NULL, thr, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + } + for (i = 0; i < 5; i++) { + if (pthread_join(threads[i], NULL) != 0) + err(1, "pthread_join(%d)", 0); + } + + bzero(buf, sizeof(buf)); + exit(0); + } + if (r < 0) { + perror("fork"); + exit(2); + } + wait(&status); + } +} + +/* Get files for each proc */ +void +list(void) +{ + struct kinfo_file *freep, *kif; + struct kinfo_vmentry *freep_vm; + long i, j; + int cnt, name[4]; + struct kinfo_proc *kipp; + size_t len; + + name[0] = CTL_KERN; + name[1] = KERN_PROC; + name[2] = KERN_PROC_PROC; + + len = 0; + if (sysctl(name, 3, NULL, &len, NULL, 0) < 0) + err(-1, "sysctl: kern.proc.all"); + + kipp = malloc(len); + if (kipp == NULL) + err(1, "malloc"); + + if (sysctl(name, 3, kipp, &len, NULL, 0) < 0) { + free(kipp); +// warn("sysctl: kern.proc.all"); + return; + } + + for (i = 0; i < len / sizeof(*kipp); i++) { + + /* The test starts here */ + freep = kinfo_getfile(kipp[i].ki_pid, &cnt); + for (j = 0; j < cnt && freep; j++) { + kif = &freep[j]; +// printf("%d : %s\n", kif->kf_fd, kif->kf_path); + } + free(freep); + + freep_vm = kinfo_getvmmap(kipp[i].ki_pid, &cnt); + free(freep_vm); + /* End test */ + } + free(kipp); +} + +int +main(int argc, char **argv) +{ + pid_t r; + signal(SIGALRM, handler); + alarm(30); + + if ((r = fork()) == 0) { + alarm(30); + for (;;) + churning(); + } + if (r < 0) { + perror("fork"); + exit(2); + } + + for (;;) + list(); + + return (0); +} diff --git a/test/stress/stress2/misc/ldt.sh b/test/stress/stress2/misc/ldt.sh new file mode 100755 index 0000000000..e6910e2be8 --- /dev/null +++ b/test/stress/stress2/misc/ldt.sh @@ -0,0 +1,369 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test the amd64 implementation of: +# 1. Per-process private ldt and corresponding i386 arch syscalls. +# 2. Per-process private io permission bitmap and corresponding +# i386 arch syscalls. +# 3. Sigcontext + +# The tests must be compiled on i386 and run on amd64 + +# All tests by kib@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +cd /tmp +if [ "`uname -p`" = "i386" ]; then + cat > ldt.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char stack[64 * 1024]; + +char a[1]; + +int +s2ds(int sel) +{ + + return (LSEL(sel, SEL_UPL)); +} + +unsigned char +readbyte(int sel, int offset) +{ + unsigned char res; + + __asm__ volatile( + "\tpushl %%es\n" + "\tmovl %1,%%es\n" + "\tmovb %%es:(%2),%0\n" + "\tpopl %%es\n" + : "=r"(res) : "r"(s2ds(sel)), "r"(offset)); + + return (res); +} + +void +writebyte(int sel, int offset, unsigned char val) +{ + + __asm__ volatile( + "\tpushl %%es\n" + "\tmovl %0,%%es\n" + "\tmovb %2,%%es:(%1)\n" + "\tpopl %%es\n" + : : "r"(s2ds(sel)), "r"(offset), "r"(val) : "memory"); +} + +int +alloc_sel(char *base, size_t len, int type, int p) +{ + int sel; + union descriptor descs[1], descsk[1]; + uintptr_t pb; + + memset(descs, 0, sizeof(descs)); + if (len > PAGE_SIZE) { + len = roundup(len, PAGE_SIZE); + len /= PAGE_SIZE; + descs[0].sd.sd_lolimit = len & 0xffff; + descs[0].sd.sd_hilimit = (len >> 16) & 0xf; + descs[0].sd.sd_gran = 1; + } else { + descs[0].sd.sd_lolimit = len; + descs[0].sd.sd_hilimit = 0; + descs[0].sd.sd_gran = 0; + } + pb = (uintptr_t)base; + descs[0].sd.sd_lobase = pb & 0xffffff; + descs[0].sd.sd_hibase = (pb >> 24) & 0xff; + descs[0].sd.sd_type = type; + descs[0].sd.sd_dpl = SEL_UPL; + descs[0].sd.sd_p = p; + descs[0].sd.sd_def32 = 1; + + if ((sel = i386_set_ldt(LDT_AUTO_ALLOC, descs, 1)) == -1) + fprintf(stderr, "i386_set_ldt: %s\n", strerror(errno)); + else if (i386_get_ldt(sel, descsk, 1) == -1) { + fprintf(stderr, "i386_get_ldt: %s\n", strerror(errno)); + sel = -1; + } else if (memcmp(descs, descsk, sizeof(descs)) != 0) { + fprintf(stderr, "descs != descsk\n"); + sel = -1; + } else + fprintf(stderr, "selector %d\n", sel); + + return (sel); +} + +int +test1(int tnum, int sel) +{ + unsigned char ar; + + writebyte(sel, 0, '1'); + ar = readbyte(sel, 0); + if (ar == '1') + fprintf(stderr, "test %d.1 ok\n", tnum); + else + fprintf(stderr, "test%d.1 failed, ar %x\n", tnum, ar); + writebyte(sel, 0, '2'); + ar = readbyte(sel, 0); + if (ar == '2') + fprintf(stderr, "test %d.2 ok\n", tnum); + else + fprintf(stderr, "test%d.2 failed, ar %x\n", tnum, ar); + return (sel); +} + +int +test2_func(void *arg) +{ + int *sel; + + sel = arg; + test1(2, *sel); + rfork(0); + test1(3, *sel); + return (0); +} + +void +test2(int sel) +{ + pid_t r; + int status; + + r = rfork_thread(RFPROC | RFMEM, stack + sizeof(stack), + test2_func, &sel); + if (r == -1) { + fprintf(stderr, "rfork(RFPROC): %s\n", strerror(errno)); + return; + } else { + waitpid(r, &status, 0); + if (WIFSIGNALED(status)) { + fprintf(stderr, "test2: child terminated by %s\n", + strsignal(WTERMSIG(status))); + } + } +} + +int +main(int argc, char *argv[]) +{ + int sel; + + sel = alloc_sel(a, 1, SDT_MEMRWA, 1); + if (sel == -1) + return (1); + + test1(1, sel); + test2(sel); + return (0); +} +EOF + cc -o ldt_static_i386 -Wall -static ldt.c + rm ldt.c + + cat > ioperm.c < +#include +#include +#include +#include +#include + +static const unsigned int port_num = 0x130; + +unsigned char +inb(unsigned int port) +{ + unsigned char data; + + __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port)); + return (data); +} + +void +sigbus_handler(int signo) +{ + + fprintf(stderr, "Got SIGBUS\n"); + exit(0); +} + +int +main(int argc, char *argv[]) +{ + struct sigaction sa; + unsigned int length1; + int enable1; + + if (i386_get_ioperm(port_num, &length1, &enable1) == -1) { + fprintf(stderr, "get 1: %s\n", strerror(errno)); + return (1); + } + if (length1 != 0 && enable1 != 0) { + fprintf(stderr, "enable1: enabled\n"); + return (1); + } + if (i386_set_ioperm(port_num, 1, 1) == -1) { + fprintf(stderr, "set 1: %s\n", strerror(errno)); + return (1); + } + inb(port_num); + if (i386_set_ioperm(port_num, 1, 0) == -1) { + fprintf(stderr, "set 2: %s\n", strerror(errno)); + return (1); + } + if (i386_get_ioperm(port_num, &length1, &enable1) == -1) { + fprintf(stderr, "get 1: %s\n", strerror(errno)); + return (1); + } + if (enable1 != 0) { + fprintf(stderr, "enable2: enabled\n"); + return (1); + } + fprintf(stderr, "And now we should get SIGBUS\n"); + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = sigbus_handler; + if (sigaction(SIGBUS, &sa, NULL) == -1) { + fprintf(stderr, "sigaction(SIGBUS): %s\n", strerror(errno)); + return (1); + } + inb(port_num); + + return (0); +} +EOF + cc -o ioperm_static_i386 -Wall -static ioperm.c + rm ioperm.c + + cat > fault.c < +#include +#include +#include +#include +#include +#include +#include + +extern char *fault_instr; +int run; + +void +sigsegv_sigaction(int signo, siginfo_t *si, void *c) +{ + ucontext_t *uc; + mcontext_t *mc; + + uc = c; + mc = &uc->uc_mcontext; + printf("SIGSEGV run %d err %x ds %x ss %x es %x fs %x gs %x\n", + run, mc->mc_err, mc->mc_ds, mc->mc_ss, mc->mc_es, mc->mc_fs, + mc->mc_gs); + switch (run) { + case 0: + mc->mc_ds = 0x1111; + break; + case 1: + mc->mc_es = 0x1111; + break; + case 2: + mc->mc_fs = 0x1111; + break; + case 3: + mc->mc_gs = 0x1111; + break; + case 4: + mc->mc_ss = 0x1111; + break; + case 5: + _exit(11); + } + run++; +} + +void +fault(void) +{ + + __asm__ volatile(".globl\tfault_instr;fault_instr:\ttestl\t\$0,0\n"); +} + +int +main(int argc, char *argv[]) +{ + struct sigaction sa; + + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = sigsegv_sigaction; + sa.sa_flags = SA_SIGINFO; + if (sigaction(SIGSEGV, &sa, NULL) == -1) { + fprintf(stderr, "sigaction: %s\n", strerror(errno)); + return (1); + } + if (sigaction(SIGBUS, &sa, NULL) == -1) { + fprintf(stderr, "sigaction: %s\n", strerror(errno)); + return (1); + } + + fault(); + + return (0); +} +EOF + cc -o fault_static_i386 -Wall -static fault.c + rm fault.c +fi + +if [ "`uname -p`" = "amd64" ]; then + [ -x ldt_static_i386 ] && ./ldt_static_i386 + [ -x ioperm_static_i386 ] && ./ioperm_static_i386 + [ -x fault_static_i386 ] && ./fault_static_i386 +fi diff --git a/test/stress/stress2/misc/ldt2.sh b/test/stress/stress2/misc/ldt2.sh new file mode 100755 index 0000000000..dfe3506821 --- /dev/null +++ b/test/stress/stress2/misc/ldt2.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# + +# Test the implementation of i386_get_ldt() and i386_set_ldt() for 32 bit +# processes on amd64 by running wine and mplayer with a 32 bit codec. + +# This is not a test script, but more of a howto document. + +[ `uname -p` != "amd64" ] && echo "Must run on amd64" && exit + +exit 0 + +This are notes of how to perform the test. + + +First of all you will need a i386 jail on amd64. This could be build like +this: + +cat > jailbuild.sh < mplayer.sh <:0 +while true;do + pos=100 + for i in `jot 5`; do + mplayer -vc rv40win -geometry $pos:$pos /root/samples/Real_Media.rm < \ + /dev/null > /dev/null 2>&1 & + pos=$((pos + 50)) + done + for i in `jot 5`; do + wait + done +done +EOF diff --git a/test/stress/stress2/misc/libMicro.sh b/test/stress/stress2/misc/libMicro.sh new file mode 100755 index 0000000000..17961a86e0 --- /dev/null +++ b/test/stress/stress2/misc/libMicro.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test using OpenSolaris libmicro-0.4.0.tar.gz benchmark +# Has shown page fault with the cascade_lockf test + +. ../default.cfg + +odir=`pwd` + +cd $RUNDIR +ftp http://www.opensolaris.org/os/project/libmicro/files/libmicro-0.4.0.tar.gz +[ ! -r libmicro-0.4.0.tar.gz ] && exit 1 +tar zxfv libmicro-0.4.0.tar.gz +cat > $RUNDIR/libMicro-0.4.0/Makefile.FreeBSD <<2EOF +CC= gcc + +CFLAGS= -pthread +CPPFLAGS= -DUSE_SEMOP -D_REENTRANT +MATHLIB= -lm + +ELIDED_BENCHMARKS= \ + cachetocache \ + atomic + + +include ../Makefile.com +2EOF + +cd libMicro-0.4.0 +gmake +ed bench <<3EOF +/ARCH +s/arch -k/uname -m/ +w +q +3EOF +./bench > output & +for i in `jot $((30 * 60))`; do + ps | grep -q bench || break + sleep 1 +done +ps | grep bin/connection | grep -v grep | awk '{print $1}' | xargs kill # hack +cd ..;rm -rf libMicro-0.4.0 diff --git a/test/stress/stress2/misc/lockf.sh b/test/stress/stress2/misc/lockf.sh new file mode 100755 index 0000000000..2acc762c93 --- /dev/null +++ b/test/stress/stress2/misc/lockf.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Page fault in nfs_advlock + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +trap "rm -f /tmp/$0.$$.*" 0 +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint + +for i in `jot 100`; do + mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/tmp $mntpoint + + for j in `jot 50`; do +# sh -c "lockf -t 10 $mntpoint/$0.$$.$j sleep 3" & + lockf -t 10 $mntpoint/$0.$$.$j sleep 3 & + done + + while mount | grep -q ${mntpoint}; do + umount -f $mntpoint > /dev/null 2>&1 + done + for j in `jot 50`; do + wait + done +done diff --git a/test/stress/stress2/misc/lookup_shared.sh b/test/stress/stress2/misc/lookup_shared.sh new file mode 100755 index 0000000000..f18aea05f0 --- /dev/null +++ b/test/stress/stress2/misc/lookup_shared.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +saved=`sysctl vfs.lookup_shared | awk '{print $NF}'` + +export runRUNTIME=10m # Run tests for 10 minutes +for i in 1 0; do + sysctl vfs.lookup_shared=$i + (cd /home/pho/stress2; ./run.sh disk.cfg) +done + +sysctl vfs.lookup_shared=$saved diff --git a/test/stress/stress2/misc/mac.sh b/test/stress/stress2/misc/mac.sh new file mode 100755 index 0000000000..b85d476f63 --- /dev/null +++ b/test/stress/stress2/misc/mac.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +if sysctl security.mac.test 2>&1 | grep -q unknown; then + echo "Kernel must be configured with MAC and MAC_TEST!" + exit 1 +fi + +./crossmp.sh + +sysctl security.mac.test diff --git a/test/stress/stress2/misc/mac_chkexec.sh b/test/stress/stress2/misc/mac_chkexec.sh new file mode 100755 index 0000000000..b29315e4ad --- /dev/null +++ b/test/stress/stress2/misc/mac_chkexec.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test for panic in second ls + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +sysctl -a | ! grep -q security.mac.chkexec && echo "chkexec.ko must be loaded" && exit 1 + +mount | grep "${mntpoint}" | grep -q md${mdstart}${part} && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 12m -u $mdstart +bsdlabel -w md$mdstart auto + +newfs md${mdstart}${part} > /dev/null +tunefs -l enable /dev/md${mdstart}${part} +mount /dev/md${mdstart}${part} $mntpoint + +cp /bin/ls $mntpoint +setfmac chkexec/md5:`md5 -q $mntpoint/ls` $mntpoint/ls +sysctl security.mac.chkexec.enforce=1 +$mntpoint/ls $mntpoint/ls +setfmac chkexec/none $mntpoint/ls +$mntpoint/ls $mntpoint/ls +sysctl security.mac.chkexec.enforce=0 + +umount $mntpoint +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/md.sh b/test/stress/stress2/misc/md.sh new file mode 100755 index 0000000000..26420fa3b8 --- /dev/null +++ b/test/stress/stress2/misc/md.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Caused panic: ffs_truncate3 +# The problem is caused by a full FS with Soft-updates disabled. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep "${mntpoint}" | grep md${mdstart}${part} > /dev/null && umount ${mntpoint} +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t swap -s 2m -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs md${mdstart}${part} > /dev/null +mount /dev/md${mdstart}${part} ${mntpoint} + +export RUNDIR=${mntpoint}/stressX +export KBLOCKS=30000 # Exaggerate disk capacity +export INODES=8000 + +for i in `jot 500`; do + (cd ../testcases/rw;./rw -t 2m -i 20) +done + +while mount | grep -q ${mntpoint}; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f" || echo "") ${mntpoint} > /dev/null 2>&1 +done + +mdconfig -d -u ${mdstart} diff --git a/test/stress/stress2/misc/md2.sh b/test/stress/stress2/misc/md2.sh new file mode 100755 index 0000000000..dff6246c5c --- /dev/null +++ b/test/stress/stress2/misc/md2.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# panic: ufs_dirbad: /mnt: bad dir ino 32899 at offset 16896: mangled entry + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t malloc -s 256m -u ${mdstart} + +for i in 1 2; do + newfs -O$i -i1024 /dev/md${mdstart} > /dev/null 2>&1 + mount /dev/md${mdstart} ${mntpoint} + df -i $mntpoint + + export RUNDIR=$mntpoint/stressX + export runRUNTIME=10m + cd /home/pho/stress2; ./run.sh + + umount ${mntpoint} +done +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/md3.sh b/test/stress/stress2/misc/md3.sh new file mode 100755 index 0000000000..7deaab59d0 --- /dev/null +++ b/test/stress/stress2/misc/md3.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $Id: nfs.sh,v 1.2 2008/02/25 16:31:43 pho Exp $ +# + +# Test scenario for deadlock fixed in r200447 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep -q "$mntpoint" && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1400m -u $mdstart +bsdlabel -w md${mdstart} auto + +newfs -U md5${part} > /dev/null +mount /dev/md5${part} /mnt + +# Stop FS "out of inodes" problem by only using 70% +set `df -ik /mnt | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 / 10 * 7)) +export INODES=$(($2 / 10 * 7)) + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m + +(cd /home/pho/stress2; ./run.sh marcus.cfg) + +umount $mntpoint +mount | grep -q "$mntpoint" && umount -f $mntpoint +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/mlockall.sh b/test/stress/stress2/misc/mlockall.sh new file mode 100755 index 0000000000..fed9ec1919 --- /dev/null +++ b/test/stress/stress2/misc/mlockall.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# "panic: swap_reserved < decr" seen. Fixed in r195329 + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mlockall.c +cc -o mlockall -Wall mlockall.c +rm -f mlockall.c + +for i in `jot 10`; do + /tmp/mlockall & + sleep 1 + ps | grep /tmp/mlockall | grep -v grep | awk '{print $1}' | while read pid; do + kill -2 $pid + kill -9 $pid + done +done + +rm -f /tmp/mlockall +exit +EOF +#include +#include +#include +#include +#include +#include + +void +child(void) +{ + if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) + err(1, "mlockall(MCL_CURRENT | MCL_FUTURE)"); + fork(); + sleep(60); +} + +int +main(int argc, char **argv) +{ + int status; + + if (fork() == 0) + child(); + wait(&status); + + return (0); +} diff --git a/test/stress/stress2/misc/mmap.sh b/test/stress/stress2/misc/mmap.sh new file mode 100755 index 0000000000..bccdf117ba --- /dev/null +++ b/test/stress/stress2/misc/mmap.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# +# $FreeBSD$ +# + +# Test scenario by Michiel Boland + +# panic: pmap_remove_all: page 0xc491f000 is fictitious + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mmap.c +cc -o mmap -Wall mmap.c +rm -f mmap.c + +./mmap +rm -f ./mmap +exit + +EOF +#include +#include +#include +#include +#include + +static const off_t map_address = 0xa0000; +static const size_t map_size = 0x1000; + +static int testit(int fd) +{ + void *p; + int rv; + + p = mmap(NULL, 2 * map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, + map_address); + if (p == MAP_FAILED) { + perror("mmap"); + return -1; + } + rv = *(char *) p; + if (munmap(p, map_size) == -1) { + perror("munmap"); + return -1; + } + return rv; +} + +int main(void) +{ + int fd, rv; + + fd = open("/dev/mem", O_RDWR); + if (fd == -1) { + perror("open"); + return 1; + } + rv = testit(fd); + close(fd); + return rv; +} diff --git a/test/stress/stress2/misc/mmap2.sh b/test/stress/stress2/misc/mmap2.sh new file mode 100755 index 0000000000..7ece8ab053 --- /dev/null +++ b/test/stress/stress2/misc/mmap2.sh @@ -0,0 +1,176 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Stress mmap by having at most 100 threads mapping random areas within +# a 100 Mb range. + +# Test scenario by kib@ + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mmap2.c +cc -o mmap2 -Wall mmap2.c -lpthread +rm -f mmap2.c + +for i in `jot 10`; do + ./mmap2 +done +rm -f ./mmap2 +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define THREADS 100 +#define STARTADDR 0x50000000U +#define ADRSPACE 0x06400000U /* 100 Mb */ + +static void +work(int nr) +{ + int fd, m; + void *p; + size_t left, len; + char path[128]; + + p = (void *)STARTADDR + trunc_page(arc4random() % ADRSPACE); + left = ADRSPACE - (size_t)p + STARTADDR; + len = trunc_page(arc4random() % left) + PAGE_SIZE; + fd = -1; + + if (arc4random() % 100 < 90) + sprintf(path, "/tmp/mmap.%06d.%04d", getpid(), nr); + else + sprintf(path, "/dev/zero"); + if (arc4random() % 2 == 0) { + if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) + err(1,"open()"); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate"); + if (arc4random() % 2 == 0) { + if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) { + if (errno == ENOMEM) + return; + err(1, "mmap()"); + } + } else { + if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) == + MAP_FAILED) { + if (errno == ENOMEM) + return; + err(1, "mmap()"); + } + } + if (fd > 0 && strcmp(path, "/dev/zero")) + if (unlink(path) == -1) + err(1, "unlink(%s)", path); + } else { + if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) == MAP_FAILED) { + if (errno == ENOMEM) + return; + err(1, "mmap()"); + } + strcpy(path, "anon"); + } +#if 0 + printf("nr = %d, %-14s, start = %p, end = %p, len = 0x%08x, (%5d pages)\n", + nr, path, p, p + len, len, len>>PAGE_SHIFT); +#endif + + *(int *)p = 1; + + if (arc4random() % 2 == 0) { + m = arc4random() % 10; + if (madvise(p, len, m) == -1) + warn("madvise(%p, %d, %d)", p, len, m); + } + if (arc4random() %2 == 0) + if (mprotect(p, trunc_page(arc4random() % len), PROT_READ) == -1 ) + err(1, "mprotect failed with error:"); + if (arc4random() % 2 == 0) { + if (arc4random() %2 == 0) { + if (msync(p, 0, MS_SYNC) == -1) + err(1, "msync(%p)", p); + } else { + if (msync(p, 0, MS_INVALIDATE) == -1) + err(1, "msync(%p)", p); + } + } + if (munmap(p, len) == -1) + err(1, "munmap(%p)", p); + close(fd); +} + +void * +thr(void *arg) +{ + int i; + + for (i = 0; i < 512; i++) { + work(*(int *)arg); + } + return (0); +} + +int +main(int argc, char **argv) +{ + pthread_t threads[THREADS]; + int nr[THREADS]; + int i, n, r; + +// printf("Address start 0x%x, address end 0x%x, pages %d\n", +// STARTADDR, STARTADDR + ADRSPACE, ADRSPACE>>PAGE_SHIFT); + n = arc4random() % THREADS + 1; + for (i = 0; i < n; i++) { + nr[i] = i; + if ((r = pthread_create(&threads[i], NULL, thr, (void *)&nr[i])) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + } + + for (i = 0; i < n; i++) { + if (pthread_join(threads[i], NULL) != 0) + err(1, "pthread_join(%d)", i); + } + + return (0); +} diff --git a/test/stress/stress2/misc/mmap3.sh b/test/stress/stress2/misc/mmap3.sh new file mode 100755 index 0000000000..cb7c7c35fc --- /dev/null +++ b/test/stress/stress2/misc/mmap3.sh @@ -0,0 +1,159 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Variation of mmap2.sh with focus on random arguments for mprotect() + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mmap3.c +cc -o mmap3 -Wall mmap3.c -lpthread +rm -f mmap3.c + +for i in `jot 20`; do + ./mmap3 +done +for i in `jot 100`; do + ./mmap3 random +done +rm -f mmap3 mmap3.core /tmp/mmap.0* +exit + +EOF +/* + Stress mmap by having max 18 threads mapping random areas within + a 100 Mb range. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define THREADS 100 +#define STARTADDR 0x50000000U +#define ADRSPACE 0x06400000U /* 100 Mb */ + +static int +ra; + +void +trash(void *p) +{ + mprotect(p, 0x570e3d38, 0x2c8fd54f); + + if (ra) { + madvise((void *)arc4random(), arc4random(), arc4random()); + mprotect((void *)arc4random(), arc4random(), arc4random()); + msync((void *)arc4random(), arc4random(), arc4random()); + } + +} + +void +work(int nr) +{ + int fd, m; + void *p; + size_t len; + char path[128]; + + p = (void *)STARTADDR; + len = ADRSPACE; + + sprintf(path, "/tmp/mmap.%06d.%04d", getpid(), nr); + if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) + err(1,"open()"); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate"); + if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) { + if (errno == ENOMEM) + return; + err(1, "mmap()"); + } + if (unlink(path) == -1) + err(1, "unlink(%s)", path); + + trash(p); + + m = arc4random() % 10; + if (madvise(p, len, m) == -1) + warn("madvise(%p, %d, %d)", p, len, m); + if (mprotect(p, trunc_page(arc4random() % len), PROT_READ) == -1 ) + err(1, "mprotect failed with error:"); + if (msync(p, 0, MS_SYNC) == -1) + err(1, "msync(%p)", p); + if (munmap(p, len) == -1) + err(1, "munmap(%p)", p); + close(fd); +} + +void * +thr(void *arg) +{ + int i; + + for (i = 0; i < 512; i++) { + work(*(int *)arg); + } + return (0); +} + +int +main(int argc, char **argv) +{ + pthread_t threads[THREADS]; + int nr[THREADS]; + int i, n, r; + + n = arc4random() % 14 + 5; + ra = argc != 1; +// printf("Address start 0x%x, address end 0x%x, pages %d, n %d\n", +// STARTADDR, STARTADDR + ADRSPACE, ADRSPACE>>PAGE_SHIFT, n); + for (i = 0; i < n; i++) { + nr[i] = i; + if ((r = pthread_create(&threads[i], NULL, thr, (void *)&nr[i])) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + } + + for (i = 0; i < n; i++) { + if (pthread_join(threads[i], NULL) != 0) + err(1, "pthread_join(%d)", i); + } + + return (0); +} diff --git a/test/stress/stress2/misc/mmap4.sh b/test/stress/stress2/misc/mmap4.sh new file mode 100755 index 0000000000..fc35d23b8d --- /dev/null +++ b/test/stress/stress2/misc/mmap4.sh @@ -0,0 +1,118 @@ +#!/bin/sh + +# +# Copyright (c) 2010 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test overcommit of the file system capacity +# Causes panic: 1 vncache entries remaining + +# Scanario by kib@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap4.c +cc -o mmap4 -Wall -O2 mmap4.c +rm -f mmap4.c + +mount | grep -q "$mntpoint" && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 40m -u $mdstart +bsdlabel -w md${mdstart} auto + +newfs -U md${mdstart}${part} > /dev/null +mount /dev/md${mdstart}${part} $mntpoint + +/tmp/mmap4 /$mntpoint/file +ls -lh $mntpoint +df -h + +cd $here +rm -f /tmp/mmap4 + +while mount | grep -q $mntpoint; do + sync;sync;sync + sleep 1 + umount $mntpoint +done + +mdconfig -d -u $mdstart +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define STARTADDR 0x0U +#define ADRSPACE 0x06400000U /* 100 Mb */ + +int +main(int argc, char **argv) +{ + int fd, ps; + void *p; + size_t len; + char *c, *path; + + p = (void *)STARTADDR; + len = ADRSPACE; + + path = argv[1]; + if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) + err(1,"open()"); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate"); + if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) { + if (errno == ENOMEM) + return (1); + err(1, "mmap(1)"); + } + + c = p; + ps = getpagesize(); + for (c = p; (void *)c < p + len; c += ps) { + *c = 1; + } + + close(fd); + + return (0); +} diff --git a/test/stress/stress2/misc/mount.sh b/test/stress/stress2/misc/mount.sh new file mode 100755 index 0000000000..1057623caf --- /dev/null +++ b/test/stress/stress2/misc/mount.sh @@ -0,0 +1,76 @@ +#!/bin/sh +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Mount regression test + +# panic: vm_fault: fault on nofault entry, addr: deadc000 +# cpuid = 1 +# KDB: enter: panic +# [thread pid 69453 tid 100388 ] +# Stopped at kdb_enter+0x2b: nop +# db> where +# Tracing pid 69453 tid 100388 td 0xc4b5c1b0 +# kdb_enter(c091d9db) at kdb_enter+0x2b +# panic(c0938fa0,deadc000,e6b44834,c06c650e,c0a57d20,...) at panic+0x14b +# vm_fault(c1869000,deadc000,1,0) at vm_fault+0x1e0 +# trap_pfault(e6b4499c,0,deadc112) at trap_pfault+0x137 +# trap(8,c0910028,28,deadc0de,deadc0de,...) at trap+0x3f5 +# calltrap() at calltrap+0x5 +# --- trap 0xc, eip = 0xc0667def, esp = 0xe6b449dc, ebp = 0xe6b44a00 --- +# g_io_request(c66d6bdc,c4a1d840,d7c99940,d7c99940,e6b44a34,...) at g_io_request+0x5f +# g_vfs_strategy(c40624c4,d7c99940,d7c99940,0,c4e16dec,...) at g_vfs_strategy+0x49 +# ffs_geom_strategy(c40624c4,d7c99940,4ba0,0,c09dad00,...) at ffs_geom_strategy+0x141 +# ufs_strategy(e6b44a7c) at ufs_strategy+0xb5 +# VOP_STRATEGY_APV(c09da7c0,e6b44a7c) at VOP_STRATEGY_APV+0x95 +# bufstrategy(c50d2be0,d7c99940) at bufstrategy+0x55 +# breadn(c50d2b2c,0,0,1000,0,...) at breadn+0xf7 +# bread(c50d2b2c,0,0,1000,0,...) at bread+0x20 +# ffs_read(e6b44bb0) at ffs_read+0x23f +# VOP_READ_APV(c09da7c0,e6b44bb0) at VOP_READ_APV+0x7e +# ufs_readdir(e6b44c38) at ufs_readdir+0xd1 +# VOP_READDIR_APV(c09da7c0,e6b44c38) at VOP_READDIR_APV+0x7e +# getdirentries(c4b5c1b0,e6b44d04) at getdirentries+0x13f +# syscall(3b,3b,3b,8240160,1,...) at syscall+0x256 + + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +mount | grep /tmp && umount -f /tmp + +# The test: + +mount -r /tmp +mount -r /tmp +umount /tmp + +ls -lR /tmp > /dev/null # panic + +# End of test + +mount /tmp diff --git a/test/stress/stress2/misc/mount2.sh b/test/stress/stress2/misc/mount2.sh new file mode 100755 index 0000000000..2e76c9f806 --- /dev/null +++ b/test/stress/stress2/misc/mount2.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Stress test by performing parallel calls to mount and umount. Alternate +# between forced and non-forced unmounts + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +D=$diskimage + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount | grep "${mntpoint}" | grep -q md$m && umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + dd if=/dev/zero of=$D$m bs=1m count=1 > /dev/null 2>&1 + mdconfig -a -t vnode -f $D$m -u $m + bsdlabel -w md$m auto + newfs md${m}${part} > /dev/null 2>&1 + done + + # start the parallel tests + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + done + + + for i in `jot $mounts`; do + wait + done + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + mdconfig -d -u $m + rm -f $D$m + done + +else + # The test: Parallel mount and unmounts + for i in `jot 1024`; do + m=$1 + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + mount /dev/md${m}${part} ${mntpoint}$m + while mount | grep -q ${mntpoint}$m; do + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + done +fi diff --git a/test/stress/stress2/misc/mountro.sh b/test/stress/stress2/misc/mountro.sh new file mode 100755 index 0000000000..6184bbe685 --- /dev/null +++ b/test/stress/stress2/misc/mountro.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +D=$diskimage +dede $D 1m 128 || exit + +mount | grep "$mntpoint" | grep -q /md && umount -f ${mntpoint} +mdconfig -l | grep -q ${mdstart} && mdconfig -d -u $mdstart + +mdconfig -a -t vnode -f $D -u $mdstart + +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} > /dev/null 2>&1 +mount /dev/md${mdstart}${part} $mntpoint + +mkdir ${mntpoint}/stressX +chmod 777 ${mntpoint}/stressX + +export RUNDIR=${mntpoint}/stressX +export runRUNTIME=4m +(cd /home/pho/stress2; ./run.sh disk.cfg) & +sleep 30 + +for i in `jot 10`; do + mount $mntpoint -u -o ro > /dev/null 2>&1 + sleep 3 + mount $mntpoint -u -o rw > /dev/null 2>&1 + sleep 3 +done +df -i $mntpoint + +umount -f $mntpoint > /dev/null 2>&1 +mdconfig -d -u $mdstart +rm -f $D +kill `ps | grep run.sh | grep -v grep | awk '{print $1}'` diff --git a/test/stress/stress2/misc/mountro2.sh b/test/stress/stress2/misc/mountro2.sh new file mode 100755 index 0000000000..54b33f4760 --- /dev/null +++ b/test/stress/stress2/misc/mountro2.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by Matthew D. Fuller + + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +D=$diskimage +dede $D 1m 20 || exit + +mount | grep "$mntpoint" | grep -q /md && umount -f ${mntpoint} +mdconfig -l | grep -q ${mdstart} && mdconfig -d -u $mdstart + +mdconfig -a -t vnode -f $D -u $mdstart + +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} > /dev/null 2>&1 +mount /dev/md${mdstart}${part} $mntpoint + +mtree -deU -f /etc/mtree/BSD.usr.dist -p $mntpoint/ >> /dev/null +sync ; sync ; sync + +rm -rf $mntpoint/* +mount -u -o ro $mntpoint + +umount -f $mntpoint > /dev/null 2>&1 +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/mountro3.sh b/test/stress/stress2/misc/mountro3.sh new file mode 100755 index 0000000000..dd41d15600 --- /dev/null +++ b/test/stress/stress2/misc/mountro3.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by barbara +# kern/121809: unable to umount + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +dede $D 1m 64 || exit 1 + +mount | grep "$mntpoint" | grep md${mdstart}${part} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} > /dev/null 2>&1 + +mount /dev/md${mdstart}${part} $mntpoint +touch $mntpoint/file +umount $mntpoint + +mount /dev/md${mdstart}${part} $mntpoint +rm $mntpoint/file +mount -u -o ro $mntpoint # Should fail with "Device busy" + +umount $mntpoint +mdconfig -d -u ${mdstart} +rm -f $D diff --git a/test/stress/stress2/misc/msdos.sh b/test/stress/stress2/misc/msdos.sh new file mode 100755 index 0000000000..d03c612b65 --- /dev/null +++ b/test/stress/stress2/misc/msdos.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2010 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# LOR seen. Fixed by r204467. + +. ../default.cfg + +mount | grep "$mntpoint" | grep -q md$mdstart && umount -f ${mntpoint} +mdconfig -l | grep -q ${mdstart} && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md${mdstart} auto +newfs_msdos /dev/md${mdstart}a > /dev/null +mount -t msdosfs /dev/md${mdstart}a $mntpoint + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd ..; ./run.sh disk.cfg) + +while mount | grep "$mntpoint" | grep -q md$mdstart; do + umount $mntpoint || sleep 1 +done +fsck -t msdosfs -y /dev/md${mdstart}a +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/msdos2.sh b/test/stress/stress2/misc/msdos2.sh new file mode 100755 index 0000000000..aea34534b2 --- /dev/null +++ b/test/stress/stress2/misc/msdos2.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# Copyright (c) 2010 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# panic: __lockmgr_args: recursing on non recursive lockmgr devfs @ ../../../kern/vfs_subr.c:2204 +# Scenario by kib@ + +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + + +. ../default.cfg + +mount | grep "$mntpoint" | grep -q md$mdstart && umount -f $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md${mdstart} auto +newfs_msdos /dev/md${mdstart}a > /dev/null +mount -t msdosfs /dev/md${mdstart}a $mntpoint + +u=$((mdstart + 1)) +mdconfig -l | grep -q $u && mdconfig -d -u $u +mdconfig -a -t swap -s 1g -u $u +bsdlabel -w md${u} auto +newfs_msdos /dev/md${u}a > /dev/null +mount -u /dev/md${u}a $mntpoint > /dev/null 2>&1 # panic + +ls $mntpoint > /dev/null + +while mount | grep "$mntpoint" | grep -q md$mdstart; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +mdconfig -d -u $u diff --git a/test/stress/stress2/misc/msdos3.sh b/test/stress/stress2/misc/msdos3.sh new file mode 100755 index 0000000000..bc3cd52af9 --- /dev/null +++ b/test/stress/stress2/misc/msdos3.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# +# Copyright (c) 2010 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Page fault seen +# Scenario by kib@ + +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + + +. ../default.cfg + +mount | grep "$mntpoint" | grep -q md$mdstart && umount -f $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md${mdstart} auto +newfs_msdos /dev/md${mdstart}a > /dev/null + +mount -t msdosfs /dev/md${mdstart}a $mntpoint +mount -t msdosfs /dev/md${mdstart}a $mntpoint + +ls $mntpoint > /dev/null + +while mount | grep "$mntpoint" | grep -q md$mdstart; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/msdos4.sh b/test/stress/stress2/misc/msdos4.sh new file mode 100755 index 0000000000..9b1b19f29a --- /dev/null +++ b/test/stress/stress2/misc/msdos4.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# +# Copyright (c) 2010 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +# "panic: leaf should be empty" seen + +. ../default.cfg + +mount | grep "$mntpoint" | grep -q md$mdstart && umount -f ${mntpoint} +mdconfig -l | grep -q ${mdstart} && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md${mdstart} auto +newfs_msdos /dev/md${mdstart}a > /dev/null +mount -t msdosfs /dev/md${mdstart}a $mntpoint + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=20m +export TESTPROGS=' +testcases/lockf2/lockf2 +testcases/openat/openat +testcases/rw/rw +testcases/fts/fts +testcases/lockf/lockf +testcases/creat/creat +testcases/mkdir/mkdir +testcases/rename/rename +testcases/swap/swap +' + +(cd ..; ./run.sh) + +while mount | grep "$mntpoint" | grep -q md$mdstart; do + umount $mntpoint || sleep 1 +done +fsck -t msdosfs -y /dev/md${mdstart}a +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/namecache.sh b/test/stress/stress2/misc/namecache.sh new file mode 100755 index 0000000000..644d39598e --- /dev/null +++ b/test/stress/stress2/misc/namecache.sh @@ -0,0 +1,212 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test case for vfs.lookup_shared=1 that shows possible name cache +# inconsistency: + +# $ ls -l /tmp/file.05015? +# ls: /tmp/file.050150: No such file or directory +# $ fsdb -r /dev/ad4s1e +# ** /dev/ad4s1e (NO WRITE) +# Examining file system `/dev/ad4s1e' +# Last Mounted on /tmp +# current inode: directory +# I=2 MODE=41777 SIZE=5120 +# BTIME=May 7 05:54:47 2006 [0 nsec] +# MTIME=Apr 2 11:27:36 2009 [0 nsec] +# CTIME=Apr 2 11:27:36 2009 [0 nsec] +# ATIME=Apr 2 12:00:30 2009 [0 nsec] +# OWNER=root GRP=wheel LINKCNT=35 FLAGS=0 BLKCNT=c GEN=65f71df4 +# fsdb (inum: 2)> lookup file.050150 +# component `file.050150': current inode: regular file +# I=198 MODE=100600 SIZE=0 +# BTIME=Apr 2 11:24:33 2009 [0 nsec] +# MTIME=Apr 2 11:24:33 2009 [0 nsec] +# CTIME=Apr 2 11:24:33 2009 [0 nsec] +# ATIME=Apr 2 11:24:33 2009 [0 nsec] +# OWNER=pho GRP=wheel LINKCNT=1 FLAGS=0 BLKCNT=0 GEN=1deaab3a +# fsdb (inum: 198)> quit +# $ + +# Consistency is restored by a umount + mount of the FS + +# Observations: +# No problems seen with vfs.lookup_shared=0. +# Does not fail in a "private" subdirectory + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > namecache.c +cc -o namecache -Wall namecache.c +rm -f namecache.c + +#dir=/tmp/namecache.dir # No problems seen +dir=/tmp +[ -d $dir ] || mkdir -p $dir +cd $dir + +for i in `jot 30`; do + for j in `jot 10`; do + /tmp/namecache & + done + + for j in `jot 10`; do + wait + done +done + +if ls -l ${dir}/file.0* 2>&1 | egrep "file.0[0-9]" | grep -q "No such file"; then + echo "ls -l ${dir}/file.0*" + ls -l ${dir}/file.0* +fi + +rm -f /tmp/namecache # /${dir}/file.0* +exit +EOF +/* Test scenario for possible name cache problem */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char path[MAXPATHLEN+1]; +static char buf[64 * 1024]; + +void +pm(void) +{ + int fd, n; + int space = sizeof(buf); + struct stat statb; + long base; + struct dirent *dp; + char *bp = buf; + + if ((fd = open(".", O_RDONLY)) == -1) + err(1, "open(%s)", "."); + + do { + if ((n = getdirentries(fd, bp, space, &base)) == -1) + err(1, "getdirentries"); + space = space - n; + bp = bp + n; + } while (n != 0); + close(fd); + + bp = buf; + dp = (struct dirent *)bp; + for (;;) { + if (strcmp(path, dp->d_name) == 0) { + + if (stat(dp->d_name, &statb) == -1) { + warn("stat(%s)", dp->d_name); + printf("name: %-10s, inode %7d, type %2d, namelen %d, d_reclen %d\n", + dp->d_name, dp->d_fileno, dp->d_type, dp->d_namlen, + dp->d_reclen); + fflush(stdout); + } else { + printf("stat(%s) succeeded!\n", path); + fflush(stdout); + } + + } + bp = bp + dp->d_reclen; + dp = (struct dirent *)bp; + if (dp->d_reclen <= 0) + break; + } +} + +static void +reader(void) { + int fd; + + if ((fd = open(path, O_RDWR, 0600)) < 0) { + warn("open(%s). %s:%d", path, __FILE__, __LINE__); + pm(); + exit(1); + } + close(fd); + return; +} + +static void +writer(void) { + int fd; + + if ((fd = open(path, O_RDWR, 0600)) < 0) { + warn("open(%s). %s:%d", path, __FILE__, __LINE__); + pm(); + exit(1); + } + close(fd); + return; +} + +int +main(int argc, char **argv) +{ + pid_t pid; + int fd, i, status; + + for (i = 0; i < 10000; i++) { + if (sprintf(path, "file.0%d", getpid()) < 0) + err(1, "sprintf()"); + if ((fd = open(path, O_CREAT | O_RDWR, 0600)) == -1) + err(1, "open(%s)", path); + close(fd); + + if ((pid = fork()) == 0) { + writer(); + exit(EXIT_SUCCESS); + + } else if (pid > 0) { + reader(); + if (waitpid(pid, &status, 0) == -1) + warn("waitpid(%d)", pid); + } else + err(1, "fork(), %s:%d", __FILE__, __LINE__); + + if (unlink(path) == -1) + err(1, "unlink(%s). %s:%d", path, __FILE__, __LINE__); + } + return (0); +} diff --git a/test/stress/stress2/misc/nbufkv.sh b/test/stress/stress2/misc/nbufkv.sh new file mode 100755 index 0000000000..6a65c3792f --- /dev/null +++ b/test/stress/stress2/misc/nbufkv.sh @@ -0,0 +1,136 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario with a 20G files on two UFS2 FSs with 64k/64k +# Test program will hang (deadlock) in "nbufkv" + +# Test scenario by John-Mark Gurney + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > nbufkv.c +cc -o nbufkv -Wall nbufkv.c +rm -f nbufkv.c +cd $odir + +u1=$mdstart +u2=$((u1 + 1)) +d1=/tmp/diskimage1 +d2=/tmp/diskimage2 +[ -d mp1 ] || mkdir mp1 +[ -d mp2 ] || mkdir mp2 +truncate -s 20g $d1 +truncate -s 20g $d2 + +mount | grep -q /dev/md${u2}$part && umount -f /dev/md${u2}$part +mount | grep -q /dev/md${u1}$part && umount -f /dev/md${u1}$part +mdconfig -l | grep -q md${u2} && mdconfig -d -u $u2 +mdconfig -l | grep -q md${u1} && mdconfig -d -u $u1 + +mdconfig -a -t vnode -f $d1 -u $u1 +bsdlabel -w md$u1 auto +newfs -b 65536 -f 65536 -O2 md${u1}${part} > /dev/null + +mdconfig -a -t vnode -f $d2 -u $u2 +bsdlabel -w md$u2 auto +newfs -b 65536 -f 65536 -O2 md${u2}${part} > /dev/null + +mount /dev/md${u1}$part mp1 +mount /dev/md${u2}$part mp2 + +/tmp/nbufkv `pwd`/mp1 & +/tmp/nbufkv `pwd`/mp2 & +wait;wait + +umount /dev/md${u2}$part +umount /dev/md${u1}$part + +mount | grep -q /dev/md${u2}$part && umount -f /dev/md${u2}$part +mount | grep -q /dev/md${u1}$part && umount -f /dev/md${u1}$part + +mdconfig -d -u $u2 +mdconfig -d -u $u1 + +rm -rf mp1 mp2 $d1 $d2 /tmp/nbufkv +exit +EOF +#include +#include +#include +#include +#include +#include +#include + +void +work(int fd, size_t n) +{ + int i; + + for (i = 0; i < 128 * 1024; i++) { + n = n - PAGE_SIZE; + if (lseek(fd, n , SEEK_SET) == -1) + err(1, "lseek()"); + if (write(fd, "1", 1) != 1) + err(1, "write()"); + } + +} + +int +main(int argc, char **argv) +{ + + int fd; + off_t len; + char path[128]; + + len = 20; + len = len * 1024 * 1024 * 1024; + + sprintf(path, "%s/nbufkv.%06d", argv[1], getpid()); + if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0640)) == -1) + err(1,"open()"); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate"); + + work(fd, len); + + close(fd); + if (unlink(path) == -1) + err(1, "unlink(%s)", path); + + return (0); +} diff --git a/test/stress/stress2/misc/newfs.sh b/test/stress/stress2/misc/newfs.sh new file mode 100755 index 0000000000..64276392ca --- /dev/null +++ b/test/stress/stress2/misc/newfs.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +size=1 # Gb +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print $4'}` -lt $((size * 1024 * 1024)) ] && \ + echo "Not enough disk space." && exit 1 +truncate -s ${size}G $diskimage + +mount | grep "$mntpoint" | grep md${mdstart}${part} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $diskimage -u ${mdstart} +bsdlabel -w md${mdstart} auto + + +for opt in "-O1" "-O2" "-O2 -U"; do + blocksize=4096 + while [ $blocksize -le 65536 ]; do + for i in 8 4 2 1; do + fragsize=$((blocksize / i)) + echo "newfs $opt -b $blocksize -f $fragsize md${mdstart}${part}" + newfs $opt -b $blocksize -f $fragsize md${mdstart}${part} > /dev/null + mount /dev/md${mdstart}${part} $mntpoint + export RUNDIR=$mntpoint/stressX + export runRUNTIME=4m + (cd /home/pho/stress2; ./run.sh disk.cfg) + while mount | grep "$mntpoint" | grep -q md${mdstart}${part}; do + umount $mntpoint > /dev/null 2>&1 + done + done + blocksize=$((blocksize * 2)) + done +done +mdconfig -d -u ${mdstart} +rm -f $diskimage diff --git a/test/stress/stress2/misc/newfs2.sh b/test/stress/stress2/misc/newfs2.sh new file mode 100755 index 0000000000..58b5f2d863 --- /dev/null +++ b/test/stress/stress2/misc/newfs2.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# phk has seen freezes with this newfs option: "-b 32768 -f 4096 -O2" + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +size=$((32 * 1024 * 1024)) + +mount | grep "$mntpoint" | grep md${mdstart}${part} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +while [ $size -le $((900 * 1024 * 1024)) ]; do + echo "Testing with $((size / 1024 / 1024)) Mb" + truncate -s $size $diskimage + mdconfig -a -t vnode -f $diskimage -u ${mdstart} + disklabel -r -w md${mdstart} auto + newfs -b 32768 -f 4096 -O2 md${mdstart}${part} > /dev/null 2>&1 + mount /dev/md${mdstart}${part} $mntpoint + df -i $mntpoint + export RUNDIR=$mntpoint/stressX + export runRUNTIME=10m # Run tests for 10 minutes + (cd /home/pho/stress2; ./run.sh disk.cfg) + while mount | grep "$mntpoint" | grep -q md${mdstart}${part}; do + umount $mntpoint > /dev/null 2>&1 + done + mdconfig -d -u ${mdstart} + size=$((size + 32 * 1024 * 1024)) +done +rm -f $diskimage diff --git a/test/stress/stress2/misc/newfs3.sh b/test/stress/stress2/misc/newfs3.sh new file mode 100755 index 0000000000..78d785df75 --- /dev/null +++ b/test/stress/stress2/misc/newfs3.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# phk has seen freezes with this newfs option: "-b 32768 -f 4096 -O2" +# +# Deadlocks seen with this test and: +# newfs -b 4096 -f 4096 -O2 md0c on a 128 Mb FS +# newfs -b 4096 -f 1024 -O2 md0c on a 64 Mb FS +# 20070505 newfs -b 4096 -f 4096 -O2 md0c on a 32 Mb FS: panic: lockmgr: locking against myself + + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +size=$((32 * 1024 * 1024)) +opt="-O2" # newfs option. Eg. -U + +mount | grep "$mntpoint" | grep md${mdstart}${part} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +while [ $size -le $((128 * 1024 * 1024)) ]; do + truncate -s $size $diskimage + mdconfig -a -t vnode -f $diskimage -u ${mdstart} + disklabel -r -w md${mdstart} auto + blocksize=4096 + while [ $blocksize -le 65536 ]; do + for i in 1 2 4 8; do + fragsize=$((blocksize / i)) + echo "newfs -b $blocksize -f $fragsize $opt md${mdstart}${part} on a $((size / 1024 / 1024)) Mb FS" + newfs -b $blocksize -f $fragsize $opt md${mdstart}${part} > /dev/null 2>&1 + mount /dev/md${mdstart}${part} $mntpoint + export RUNDIR=$mntpoint/stressX + export runRUNTIME=5m + (cd /home/pho/stress2; ./run.sh disk.cfg) + while mount | grep "$mntpoint" | grep -q md${mdstart}${part}; do + umount $mntpoint > /dev/null 2>&1 + done + done + blocksize=$((blocksize * 2)) + done + mdconfig -d -u ${mdstart} + size=$((size + 32 * 1024 * 1024)) +done +rm -f $diskimage diff --git a/test/stress/stress2/misc/newfs4.sh b/test/stress/stress2/misc/newfs4.sh new file mode 100755 index 0000000000..e2a22b8795 --- /dev/null +++ b/test/stress/stress2/misc/newfs4.sh @@ -0,0 +1,126 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + + +. ../default.cfg + +# Deadlock problems. Test scenario by Lev Serebryakov +# newfs -O2 -U -b 65536 +# The io programs will get stuck in nbufkv wait state. + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > io.c +cc -o io -Wall io.c +rm -f io.c +cd $odir + +mount | grep "$mntpoint" | grep md${mdstart}${part} > /dev/null && umount $mntpoint +mdconfig -l | grep md$mdstart > /dev/null && mdconfig -d -u $mdstart + +size=9 # Gb +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print $4'}` -lt $((size * 1024 * 1024)) ] && \ + echo "Not enough disk space." && exit 1 +truncate -s ${size}G $diskimage + +blocksize="-b 65536" +opt="-O2 -U" +mdconfig -a -t vnode -f $diskimage -u $mdstart +bsdlabel -w md$mdstart auto +newfs $blocksize $opt md${mdstart}${part} > /dev/null +mount /dev/md${mdstart}${part} $mntpoint + +cd $mntpoint +truncate -s 2g f1 +truncate -s 2g f2 +truncate -s 2g f3 +truncate -s 2g f4 +/tmp/io f1 & +/tmp/io f2 & +/tmp/io f3 & +/tmp/io f4 & +wait;wait;wait;wait + +while mount | grep "$mntpoint" | grep -q md${mdstart}${part}; do + umount -f $mntpoint > /dev/null 2>&1 +done + +mdconfig -d -u $mdstart +rm -f $diskimage +rm -f $RUNDIR/fsx.$$.* +rm -f /tmp/io +exit + +EOF +#include +#include +#include +#include +#include +#include +#include + +/* Perform random IO operations on a file */ + +int +main(int argc, char **argv) +{ + struct stat sb; + char buf[256]; + off_t bp, maxb; + int fd; + long i; + + if (argc != 2) { + fprintf(stderr, "Usage %s: file\n", argv[0]); + return (1); + } + if ((fd = open(argv[1], O_RDWR)) == -1) + err(1, "open(%s)", argv[1]); + if (fstat(fd, &sb) == -1) + err(1, "fstatf(stdin)"); + maxb = sb.st_size - sizeof(buf); + + for (i = 0; i < 10000; i++) { + bp = arc4random(); + bp = (bp << 31 | arc4random()) % maxb; +// printf("%jd\n", bp); + + if (lseek(fd, bp, 0) == -1) + err(1, "lseek()"); + if (write(fd, buf, sizeof(buf)) != sizeof(buf)) + err(1, "write()"); + } + close(fd); + + return (0); +} diff --git a/test/stress/stress2/misc/nfs.sh b/test/stress/stress2/misc/nfs.sh new file mode 100755 index 0000000000..37d26b65dd --- /dev/null +++ b/test/stress/stress2/misc/nfs.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# No problems seen with this test + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/tmp $mntpoint + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m # Run tests for 10 minutes + +(cd /home/pho/stress2; ./run.sh disk.cfg) + +while mount | grep "$mntpoint" | grep -q nfs; do + umount $mntpoint +done diff --git a/test/stress/stress2/misc/nfs2.sh b/test/stress/stress2/misc/nfs2.sh new file mode 100755 index 0000000000..512e88ab30 --- /dev/null +++ b/test/stress/stress2/misc/nfs2.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test msdos over nfs. "panic: wrong diroffset" seen. +# This needs to be in /etc/exports: /mnt -maproot=root 127.0.0.1 + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +D=$diskimage +dede $D 1m 128 || exit + +mount | grep "${mntpoint}2" | grep nfs > /dev/null && umount -f ${mntpoint}2 +mount | grep "$mntpoint" | grep /md > /dev/null && umount -f ${mntpoint} +mdconfig -l | grep -q ${mdstart} && mdconfig -d -u $mdstart + +mdconfig -a -t vnode -f $D -u $mdstart + +bsdlabel -w md${mdstart} auto +newfs_msdos -F 16 -b 8192 /dev/md${mdstart}a > /dev/null +mount -t msdosfs -o rw /dev/md${mdstart}a $mntpoint + +mkdir ${mntpoint}/stressX +chmod 777 ${mntpoint}/stressX + +[ ! -d ${mntpoint}2 ] && mkdir ${mntpoint}2 +chmod 777 ${mntpoint}2 + +mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:$mntpoint $mntpoint2 + +export INODES=9999 # No inodes on a msdos fs +export RUNDIR=${mntpoint}2/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd /home/pho/stress2; ./run.sh disk.cfg) + +umount -f ${mntpoint}2 > /dev/null 2>&1 +umount -f $mntpoint > /dev/null 2>&1 +mdconfig -d -u $mdstart +rm -f $D diff --git a/test/stress/stress2/misc/nfs3.sh b/test/stress/stress2/misc/nfs3.sh new file mode 100755 index 0000000000..a696d7eed0 --- /dev/null +++ b/test/stress/stress2/misc/nfs3.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# panic: neg mount point vnode list size + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ ! -d $mntpoint ] && mkdir $mntpoint +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/tmp $mntpoint +rm -rf $mntpoint/stressX/* +rm -rf /tmp/stressX.control + +export RUNDIR=$mntpoint/nfs/stressX +[ ! -d $RUNDIR ] && mkdir -p $RUNDIR +export runRUNTIME=1m +rm -rf /tmp/stressX.control/* + +cd .. +./run.sh -a & +cd - +sleep 50 + +while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 +done +kill -9 $! +../tools/killall.sh diff --git a/test/stress/stress2/misc/nfs4.sh b/test/stress/stress2/misc/nfs4.sh new file mode 100755 index 0000000000..c890bf43f4 --- /dev/null +++ b/test/stress/stress2/misc/nfs4.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# panic: vm_fault: fault on nofault entry, from vfs_stdcheckexp+0x74 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ ! -d $mntpoint ] && mkdir $mntpoint +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/tmp $mntpoint +rm -rf $mntpoint/stressX/* +rm -rf /tmp/stressX.control + +export RUNDIR=$mntpoint/nfs/stressX +[ ! -d $RUNDIR ] && mkdir -p $RUNDIR +export runRUNTIME=3m +rm -rf /tmp/stressX.control/* + +(cd ..; ./run.sh all.cfg) & +sleep 60 + +while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 +done +kill -9 $! +../tools/killall.sh diff --git a/test/stress/stress2/misc/nfs5.sh b/test/stress/stress2/misc/nfs5.sh new file mode 100755 index 0000000000..6baaf5f634 --- /dev/null +++ b/test/stress/stress2/misc/nfs5.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +D=$diskimage +dede $D 1m 128 || exit + +mount | grep "${mntpoint}2" | grep nfs > /dev/null && umount -f ${mntpoint}2 +mount | grep "$mntpoint" | grep /md > /dev/null && umount -f ${mntpoint} +mdconfig -l | grep -q ${mdstart} && mdconfig -d -u $mdstart + +mdconfig -a -t vnode -f $D -u $mdstart + +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} +mount /dev/md${mdstart}${part} $mntpoint + +mkdir ${mntpoint}/stressX +chmod 777 ${mntpoint}/stressX + +[ ! -d ${mntpoint}2 ] && mkdir ${mntpoint}2 +chmod 777 ${mntpoint}2 + +mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/$mntpoint $mntpoint2 + +export RUNDIR=${mntpoint}2/stressX +export runRUNTIME=4m +(cd /home/pho/stress2; ./run.sh disk.cfg) & +sleep 60 + +umount -f $mntpoint > /dev/null 2>&1 +umount -f ${mntpoint}2 > /dev/null 2>&1 + +mdconfig -d -u $mdstart +rm -f $D +kill `ps | grep run.sh | grep -v grep | awk '{print $1}'` diff --git a/test/stress/stress2/misc/nfs6.sh b/test/stress/stress2/misc/nfs6.sh new file mode 100755 index 0000000000..867960c753 --- /dev/null +++ b/test/stress/stress2/misc/nfs6.sh @@ -0,0 +1,75 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# panic: vn_finished_write: neg cnt + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +D=$diskimage +dede $D 1m 128 || exit + +mount | grep "${mntpoint}2" | grep nfs > /dev/null && umount -f ${mntpoint}2 +mount | grep "$mntpoint" | grep /md > /dev/null && umount -f ${mntpoint} +mdconfig -l | grep -q ${mdstart} && mdconfig -d -u $mdstart + +mdconfig -a -t vnode -f $D -u $mdstart + +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} +mount /dev/md${mdstart}${part} $mntpoint + +mkdir ${mntpoint}/stressX +chmod 777 ${mntpoint}/stressX + +[ ! -d ${mntpoint}2 ] && mkdir ${mntpoint}2 +chmod 777 ${mntpoint}2 + +mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:$mntpoint ${mntpoint}2 + +export RUNDIR=${mntpoint}2/stressX +export runRUNTIME=4m +(cd /home/pho/stress2; ./run.sh disk.cfg) & +sleep 60 + +for i in `jot 10`; do + umount -f $mntpoint > /dev/null 2>&1 + sleep 1 + mount /dev/md${mdstart}${part} $mntpoint + sleep 1 +done + +umount -f $mntpoint > /dev/null 2>&1 +umount -f ${mntpoint}2 > /dev/null 2>&1 + +mdconfig -d -u $mdstart +rm -f $D +kill `ps | grep run.sh | grep -v grep | awk '{print $1}'` diff --git a/test/stress/stress2/misc/nfs7.sh b/test/stress/stress2/misc/nfs7.sh new file mode 100755 index 0000000000..d9ac7eee84 --- /dev/null +++ b/test/stress/stress2/misc/nfs7.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# NFS test excluding lockd + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ ! -d $mntpoint ] && mkdir $mntpoint +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint +mount -t nfs -o nfsv3,tcp,nolockd -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/tmp $mntpoint +rm -rf $mntpoint/stressX/* +rm -rf /tmp/stressX.control + +export RUNDIR=$mntpoint/nfs/stressX +[ ! -d $RUNDIR ] && mkdir -p $RUNDIR +export runRUNTIME=10m +rm -rf /tmp/stressX.control/* + +cd .. +./run.sh marcus.cfg +cd - + +umount $mntpoint +while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 +done diff --git a/test/stress/stress2/misc/nfs8.sh b/test/stress/stress2/misc/nfs8.sh new file mode 100755 index 0000000000..cda7692a55 --- /dev/null +++ b/test/stress/stress2/misc/nfs8.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario for a lock cascade problem with sending SIGSTOP to processes +# accessing a NFS intr mount. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ ! -d $mntpoint ] && mkdir $mntpoint +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint +mount -t nfs -o nfsv3,tcp,nolockd -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/tmp $mntpoint + +pids="" +for i in `jot 10`; do + find $mntpoint > /dev/null 2>&1 & + sleep 0.1 + kill -s STOP $! + pids="$pids $!" +done + +umount $mntpoint 2>&1 | grep -v "Device busy" +while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 +done + +kill -s CONT $pids +for i in `jot 10`; do + wait +done diff --git a/test/stress/stress2/misc/nfs9.sh b/test/stress/stress2/misc/nfs9.sh new file mode 100755 index 0000000000..7b0e973c75 --- /dev/null +++ b/test/stress/stress2/misc/nfs9.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Copy of nfs4.sh, where it was discovered that a missing killall.sh script +# turned up quite a few new panics. For example: + +# vfs_mount_destroy: nonzero writeopcount +# Lock nfs not locked @ kern/vfs_default.c:462 +# Assertion x == LK_SHARERS_LOCK(1) failed at kern/kern_lock.c:236 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ ! -d $mntpoint ] && mkdir $mntpoint +for i in `jot 10`; do + mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint + mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/tmp $mntpoint + rm -rf $mntpoint/stressX/* + rm -rf /tmp/stressX.control + + export RUNDIR=$mntpoint/nfs/stressX + [ ! -d $RUNDIR ] && mkdir -p $RUNDIR + export runRUNTIME=3m + rm -rf /tmp/stressX.control/* + + (cd ..; ./run.sh all.cfg) & + sleep 60 + + while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 + done + kill -9 $! +done +../tools/killall.sh diff --git a/test/stress/stress2/misc/nfsrename.sh b/test/stress/stress2/misc/nfsrename.sh new file mode 100755 index 0000000000..ccadf95eac --- /dev/null +++ b/test/stress/stress2/misc/nfsrename.sh @@ -0,0 +1,215 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + + +. ../default.cfg + +# Test scenario by jhb@ + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > nfsrename.c +cc -o nfsrename -Wall nfsrename.c +rm -f nfsrename.c +cd $odir + +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw 127.0.0.1:/tmp $mntpoint + + +#export RUNDIR=$mntpoint/stressX +#export runRUNTIME=2m +#(cd /home/pho/stress2; ./run.sh disk.cfg) & + +for i in `jot 10`; do + /tmp/nfsrename $mntpoint/nfsrename.$i & +done +for i in `jot 10`; do + wait +done +killall nfsrename +rm -f $mntpoint/nfsrename.* + +umount $mntpoint > /dev/null 2>&1 +while mount | grep "$mntpoint" | grep -q nfs; do + umount -f $mntpoint > /dev/null 2>&1 +done + +rm -f /tmp/nfsrename +exit + +EOF +/* + * Try to expose races with doing renames over NFS that require silly + * renames. This results in 2 different RENAME RPCs leaving a race + * window where the file may not exist. It also appears that FreeBSD + * with shared lookups in NFS can get confused and possibly reference + * the sillyrenamed file in lookup but the file is deleted by the time + * open gets to it. + */ + +#include +#include +#include +#include +#include +#include + +const char *filename; +const char *dir; + +static void +usage(void) +{ + + fprintf(stderr, "nfsrename: [-n children] file\n"); + exit(1); +} + +static void +read_file(void) +{ + FILE *fp; + char buffer[4096]; + + fp = fopen(filename, "r"); + if (fp == NULL) { + warn("fopen"); + return; + } + while (!feof(fp)) { + if (fread(buffer, sizeof(buffer), 1, fp) < sizeof(buffer)) + break; + } + if (ferror(fp)) + warnx("fread encountered an error"); + fclose(fp); +} + +static void +write_file(void) +{ + FILE *fp; + char path[1024]; + int fd; + + snprintf(path, sizeof(path), "%s/nfsrename.XXXXXX", dir); + fd = mkstemp(path); + if (fd < 0) { + warn("mkstemp"); + return; + } + + fp = fdopen(fd, "w"); + if (fp == NULL) { + warn("fopen:writer"); + close(fd); + unlink(path); + } + + fprintf(fp, "blah blah blah garbage %ld\n", random()); + fclose(fp); + if (rename(path, filename) < 0) { + warn("rename"); + unlink(path); + } +} + +static void +random_sleep(int base, int slop) +{ + long val; + + val = random() % slop; + usleep(base + val); +} + +static void +child(void) +{ + + for (;;) { + random_sleep(500, 50); + read_file(); + } + exit(0); +} + +int +main(int ac, char **av) +{ + long i, nchild; + char *cp; + int ch; + + nchild = 1; + while ((ch = getopt(ac, av, "n:")) != -1) { + switch (ch) { + case 'n': + nchild = strtol(optarg, &cp, 0); + if (*cp != '\0') + errx(1, "Invalid count %s", optarg); + break; + case '?': + default: + usage(); + } + } + ac -= optind; + av += optind; + + if (ac == 0) + errx(1, "Missing filename"); + else if (ac > 1) + errx(1, "Extra arguments"); + + filename = av[0]; + dir = dirname(filename); + srandomdev(); + write_file(); + + for (i = 0; i < nchild; i++) { + switch (fork()) { + case 0: + child(); + case -1: + err(1, "fork"); + } + } + + for (i = 0; i < 10000; i++) { + random_sleep(1500, 1000); + write_file(); + } + + return (0); +} diff --git a/test/stress/stress2/misc/nullfs.sh b/test/stress/stress2/misc/nullfs.sh new file mode 100755 index 0000000000..2fe3a1b81a --- /dev/null +++ b/test/stress/stress2/misc/nullfs.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Stress test by performing parallel calls to mount and umount. Alternate +# between forced and non-forced unmounts + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + [ ! -d ${mntpoint}$i ] && mkdir ${mntpoint}$i + mount | grep "$mntpoint" | grep -q ${mntpoint}$i && umount ${mntpoint}$i + done + + # start the parallel tests + for i in `jot $mounts`; do + ./$0 $i & + done + + + for i in `jot $mounts`; do + wait + done + + for i in `jot $mounts`; do + umount ${mntpoint}$i > /dev/null 2>&1 + done + +else + # The test: Parallel mount and unmounts + for i in `jot 1024`; do + m=$1 + mount_nullfs /tmp ${mntpoint}$m > /dev/null 2>&1 + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + while mount | grep "$mntpoint" | grep -q ${mntpoint}$m; do + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + done +fi diff --git a/test/stress/stress2/misc/nullfs2.sh b/test/stress/stress2/misc/nullfs2.sh new file mode 100755 index 0000000000..374eb05e9b --- /dev/null +++ b/test/stress/stress2/misc/nullfs2.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Simple nullfs test scenario + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -d mp1 ] || mkdir mp1 + +mp=`pwd`/mp1 +mount | grep -q $mp && umount -f $mp + +mount -t nullfs `dirname $RUNDIR` $mp + +export RUNDIR=`pwd`/mp1/stressX +export runRUNTIME=10m +(cd ..; ./run.sh marcus.cfg) + +umount $mp 2>&1 | grep -v busy + +mount | grep -q $mp && umount -f $mp + +rm -rf mp1 diff --git a/test/stress/stress2/misc/nullfs3.sh b/test/stress/stress2/misc/nullfs3.sh new file mode 100755 index 0000000000..86c2060339 --- /dev/null +++ b/test/stress/stress2/misc/nullfs3.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by "Paul B. Mahol" + +# Caused: lock violation + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -d mp1 ] || mkdir mp1 +[ -d $RUNDIR ] || mkdir $RUNDIR + +mp=`pwd`/mp1 +mount | grep -q $mp && umount -f $mp + +mount -t nullfs `dirname $RUNDIR` $mp + +cd $mp/stressX +whereis something +cd / + +umount $mp + +mount | grep -q $mp && umount -f $mp + +rm -rf $mp diff --git a/test/stress/stress2/misc/nullfs4.sh b/test/stress/stress2/misc/nullfs4.sh new file mode 100755 index 0000000000..7fa91b699c --- /dev/null +++ b/test/stress/stress2/misc/nullfs4.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by Anatoli Klassen + +# kern/94269: [nullfs] procfs shows wrong data if executable is running from +# nullfs + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep -q /proc || mount -t procfs procfs /proc +mount -t nullfs /bin $mntpoint + +r1=`/bin/ls -l /proc/curproc/file` +r2=`$mntpoint/ls -l /proc/curproc/file | sed "s#$mntpoint#/bin#"` +if [ "$r1" != "$r2" ]; then + echo "/bin/ls -l /proc/curproc/file" + echo $r1 + echo "$mntpoint/ls -l /proc/curproc/file" + echo $r2 +fi + +umount $mntpoint diff --git a/test/stress/stress2/misc/nullfs5.sh b/test/stress/stress2/misc/nullfs5.sh new file mode 100755 index 0000000000..fa68c6d3ba --- /dev/null +++ b/test/stress/stress2/misc/nullfs5.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Composit test: nullfs2.sh + kinfo.sh + +# Kernel page fault with the following non-sleepable locks held from +# nullfs/null_vnops.c:531 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d;s/60/600/' < $odir/kinfo.sh > kinfo.c +cc -o kinfo -Wall -g kinfo.c -lutil +rm -f kinfo.c +cd $odir + +mount | grep -q procfs || mount -t procfs procfs /procfs + +for j in `jot 5`; do + /tmp/kinfo & +done + +[ -d mp1 ] || mkdir mp1 + +mp=`pwd`/mp1 +mount | grep -q $mp && umount -f $mp + +mount -t nullfs `dirname $RUNDIR` $mp + +export RUNDIR=`pwd`/mp1/stressX +export runRUNTIME=10m +(cd ..; ./run.sh marcus.cfg) + +umount $mp 2>&1 | grep -v busy + +mount | grep -q $mp && umount -f $mp + +rm -rf mp1 + +for j in `jot 5`; do + wait +done +rm -f /tmp/kinfo diff --git a/test/stress/stress2/misc/nullfs6.sh b/test/stress/stress2/misc/nullfs6.sh new file mode 100755 index 0000000000..b5e1d4c764 --- /dev/null +++ b/test/stress/stress2/misc/nullfs6.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# +# Copyright (c) 2010 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Lock violation panic regression test +# Test scenario by Mikolaj Golub +# Fixed in r208773 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep nullfs | grep -q /tmp/1 && umount /tmp/1 + +rm -rf /tmp/1 /tmp/2 +mkdir /tmp/1 /tmp/2 +touch /tmp/1/test.file + +mount -t nullfs /tmp/1 /tmp/2 + +cp /tmp/1/test.file /tmp/2/test.file # scenario by kib +mv /tmp/1/test.file /tmp/2/ # panics with lock violation + +umount /tmp/1 +rm -rf /tmp/1 /tmp/2 diff --git a/test/stress/stress2/misc/pmc.sh b/test/stress/stress2/misc/pmc.sh new file mode 100755 index 0000000000..dbd83e3c28 --- /dev/null +++ b/test/stress/stress2/misc/pmc.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Simple pmc test + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q hwpmc || kldload hwpmc + +for i in `jot 2`; do + pmcstat -P instructions -O /tmp/sample.out.$i find /var -name not.there & +done + +export runRUNTIME=5m +(cd /home/pho/stress2; ./run.sh vfs.cfg) + +for i in `jot 2`; do + wait +done diff --git a/test/stress/stress2/misc/procfs.sh b/test/stress/stress2/misc/procfs.sh new file mode 100755 index 0000000000..95491847c2 --- /dev/null +++ b/test/stress/stress2/misc/procfs.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +mdstart=$mdstart # Use md unit numbers from this point + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount | grep "$mntpoint" | grep -q md$m && umount ${mntpoint}$m + done + + # start the parallel tests + touch /tmp/$0 + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find $m & + done + + for i in `jot $mounts`; do + wait; wait + done +else + if [ $1 = find ]; then + while [ -r /tmp/$0 ]; do + ls -lR ${mntpoint}* + done + echo "Done 1 @ `date '+%T'`" + else + + # The test: Parallel mount and unmounts + for i in `jot 1024`; do + m=$1 + mount -t procfs proc ${mntpoint}$m + while mount | grep -qw $mntpoint$m; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + done + rm -f /tmp/$0 + echo "Done 2 @ `date '+%T'`" + fi +fi diff --git a/test/stress/stress2/misc/pthread.sh b/test/stress/stress2/misc/pthread.sh new file mode 100755 index 0000000000..7d35aa0101 --- /dev/null +++ b/test/stress/stress2/misc/pthread.sh @@ -0,0 +1,140 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# panic: spin lock held too long + +# Test program and scenario by Peter Wemm + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > pth.c +cc -o pth -Wall pth.c -pthread +rm -f pth.c +cd $odir + +for i in `jot 2000`; do + date + /tmp/pth +done + +rm -f /tmp/pth +exit +EOF +#include + +#include +#include +#include +#include +#include + +static pthread_t worker1_thr; +static pthread_t worker2_thr; + +static pthread_mutex_t worker_mtx; +static pthread_cond_t worker_go; +static pthread_cond_t worker_done; + +struct workitem { + struct workitem *next; + int a, b; +}; + +struct workitem *head; + +static void * +worker(void *arg) +{ + struct workitem *w; + + pthread_detach(pthread_self()); + fprintf(stderr, "WORKER: started %p\n", arg); fflush(stderr); + + for (;;) { + pthread_mutex_lock(&worker_mtx); + while (head == NULL) { + pthread_cond_wait(&worker_go, &worker_mtx); + } + w = head; + head = w->next; + pthread_mutex_unlock(&worker_mtx); + + fprintf(stderr, "WORKER(%p): got work a=%d b=%d\n", arg, w->a, w->b); fflush(stderr); + free(w); + pthread_cond_signal(&worker_done); + } +} + +void +work_add(int a, int b) +{ + struct workitem *w; + int dowake = 0; + + w = calloc(sizeof(*w), 1); + w->a = a; + w->b = b; + pthread_mutex_lock(&worker_mtx); + if (head == 0) + dowake = 1; + w->next = head; + head = w; + pthread_mutex_unlock(&worker_mtx); + if (dowake) + pthread_cond_signal(&worker_go); +} + +int +main() +{ + pthread_mutex_init(&worker_mtx, NULL); + pthread_cond_init(&worker_go, NULL); + pthread_cond_init(&worker_done, NULL); + + fprintf(stderr, "pthread create\n"); fflush(stderr); + pthread_create(&worker1_thr, NULL, worker, (void *)1); + pthread_create(&worker2_thr, NULL, worker, (void *)2); + + work_add(10, 15); + work_add(11, 22); + work_add(314, 159); + + pthread_mutex_lock(&worker_mtx); + while (head != NULL) { + pthread_cond_wait(&worker_done, &worker_mtx); + } + pthread_mutex_unlock(&worker_mtx); + + fprintf(stderr, "job complete\n"); fflush(stderr); + exit(0); +} diff --git a/test/stress/stress2/misc/quota1.sh b/test/stress/stress2/misc/quota1.sh new file mode 100755 index 0000000000..15368f22c8 --- /dev/null +++ b/test/stress/stress2/misc/quota1.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Causes this: panic: mutex Giant not owned at ../../../kern/vfs_subr.c:1968 +# with a kernel compiled with "options QUOTA" + +. ../default.cfg + +D=$diskimage +trap "rm -f $D" 0 +dede $D 1m 128 || exit 1 + +mount | grep "${mntpoint}" | grep md${mdstart}${part} > /dev/null && umount ${mntpoint} +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} > /dev/null +mount /dev/md${mdstart}${part} ${mntpoint} +export RUNDIR=${mntpoint}/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd /home/pho/stress2; ./run.sh disk.cfg) +false +while mount | grep -q ${mntpoint}; do + umount ${mntpoint} > /dev/null 2>&1 +done +mdconfig -d -u ${mdstart} +rm -f $D diff --git a/test/stress/stress2/misc/quota10.sh b/test/stress/stress2/misc/quota10.sh new file mode 100755 index 0000000000..2c67e85a8d --- /dev/null +++ b/test/stress/stress2/misc/quota10.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Hunt for deadlock that could occur running umount and quota at the same time + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +mdstart=$mdstart # Use md unit numbers from this point +D=$diskimage + +if [ $# -eq 0 ]; then + cp -p /etc/fstab /etc/fstab.save + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount | grep "$mntpoint" | grep -q md$m && umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + dede $D$m 1m 1 + mdconfig -a -t vnode -f $D$m -u $m + bsdlabel -w md$m auto + newfs md${m}${part} > /dev/null 2>&1 + echo "/dev/md${m}${part} ${mntpoint}$m ufs rw,userquota 2 2" >> /etc/fstab + mount ${mntpoint}$m + edquota -u -f ${mntpoint}$m -e ${mntpoint}$m:100000:110000:15000:16000 root + umount ${mntpoint}$m + done + sync;sync;sync + + # start the parallel tests + touch /tmp/$0 + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find $m & + done + + for i in `jot $mounts`; do + wait; wait + done + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + mdconfig -d -u $m + rm -f $D$m + done + + mv /etc/fstab.save /etc/fstab + +else + if [ $1 = find ]; then + while [ -r /tmp/$0 ]; do + quotaon ${mntpoint}$2 + quotaoff ${mntpoint}$2 + done + echo "Done 1 @ `date '+%T'`" + else + + # The test: Parallel mount and unmounts + for i in `jot 1024`; do + m=$1 + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + mount $opt /dev/md${m}${part} ${mntpoint}$m + while mount | grep -qw $mntpoint$m; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + done + rm -f /tmp/$0 + echo "Done 2 @ `date '+%T'`" + fi +fi diff --git a/test/stress/stress2/misc/quota2.sh b/test/stress/stress2/misc/quota2.sh new file mode 100755 index 0000000000..8ecb185980 --- /dev/null +++ b/test/stress/stress2/misc/quota2.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +trap "rm -f $D" 0 +dede $D 1m 128 || exit 1 + +mount | grep "${mntpoint}" | grep md${mdstart}${part} > /dev/null && umount ${mntpoint} +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} > /dev/null +echo "/dev/md${mdstart}${part} ${mntpoint} ufs rw,userquota 2 2" >> /etc/fstab +mount ${mntpoint} +edquota -u -f ${mntpoint} -e ${mntpoint}:100000:110000:15000:16000 root +quotacheck ${mntpoint} +quotaon ${mntpoint} +quota root +df -i ${mntpoint} +sed -i -e "/md${mdstart}${part}/d" /etc/fstab # clean up before any panics +export RUNDIR=${mntpoint}/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd /home/pho/stress2; ./run.sh disk.cfg) +false +while [ $? -ne 0 ]; do + umount ${mntpoint} > /dev/null 2>&1 +done +mdconfig -d -u ${mdstart} +rm -f $D diff --git a/test/stress/stress2/misc/quota3.sh b/test/stress/stress2/misc/quota3.sh new file mode 100755 index 0000000000..e821227fad --- /dev/null +++ b/test/stress/stress2/misc/quota3.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +trap "rm -f $D" 0 +dede $D 1m 1k || exit 1 + +mount | grep "${mntpoint}" | grep md${mdstart}${part} > /dev/null && umount ${mntpoint} +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} > /dev/null +echo "/dev/md${mdstart}${part} ${mntpoint} ufs rw,userquota 2 2" >> /etc/fstab +mount ${mntpoint} +edquota -u -f ${mntpoint} -e ${mntpoint}:850000:900000:130000:140000 root +quotacheck ${mntpoint} +quotaon ${mntpoint} +quota root +df -i ${mntpoint} +sed -i -e "/md${mdstart}${part}/d" /etc/fstab # clean up before any panics +mksnap_ffs ${mntpoint} ${mntpoint}/.snap/pho +export RUNDIR=${mntpoint}/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd /home/pho/stress2; ./run.sh disk.cfg) +false +while mount | grep -q ${mntpoint}; do + umount ${mntpoint} > /dev/null 2>&1 +done +mdconfig -d -u ${mdstart} +rm -f $D diff --git a/test/stress/stress2/misc/quota4.sh b/test/stress/stress2/misc/quota4.sh new file mode 100755 index 0000000000..c962c5b691 --- /dev/null +++ b/test/stress/stress2/misc/quota4.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Has shown a deadlock after 7 hours of testing + +. ../default.cfg + +D=$diskimage +trap "rm -f $D" 0 +dede $D 1m 1k || exit 1 + +mount | grep "${mntpoint}" | grep md${mdstart}${part} > /dev/null && umount ${mntpoint} +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} > /dev/null +echo "/dev/md${mdstart}${part} ${mntpoint} ufs rw,userquota 2 2" >> /etc/fstab +mount ${mntpoint} +edquota -u -f ${mntpoint} -e ${mntpoint}:850000:900000:130000:140000 root > /dev/null 2>&1 +quotaon ${mntpoint} +sed -i -e "/md${mdstart}${part}/d" /etc/fstab # clean up before any panics +export RUNDIR=${mntpoint}/stressX +../testcases/rw/rw -t 2m -i 200 -h -n -v -v& +sleep 60 +false +while mount | grep -q ${mntpoint}; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f" || echo "") ${mntpoint} > /dev/null 2>&1 +done +mdconfig -d -u ${mdstart} +rm -f $D diff --git a/test/stress/stress2/misc/quota5.sh b/test/stress/stress2/misc/quota5.sh new file mode 100755 index 0000000000..907875f219 --- /dev/null +++ b/test/stress/stress2/misc/quota5.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +if ! grep /tmp /etc/fstab | grep -q quota ; then + echo "/tmp must have quota enabled!" + exit 2 +fi +edquota -u -f /tmp -e /tmp:1500000:1400000:200000:180000 pho +edquota -g -f /tmp -e /tmp:1500000:1400000:200000:180000 pho +quotaon /tmp + +#su pho -c "export runRUNTIME=60m; cd /home/pho/stress2; ./run.sh disk.cfg" +su pho -c "export runRUNTIME=60m; cd /home/pho/stress2/testcases/mkdir; ./mkdir -t 1h -i 200 -v -v" + +quotaoff /tmp diff --git a/test/stress/stress2/misc/quota6.sh b/test/stress/stress2/misc/quota6.sh new file mode 100755 index 0000000000..a3c173bc22 --- /dev/null +++ b/test/stress/stress2/misc/quota6.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Deadlock in umount(1) while out of disk space + +D=/usr/tmp/diskimage +#truncate -s 1G $D +truncate -s 250M $D + +mount | grep "/mnt" | grep md0c > /dev/null && umount /mnt +mdconfig -l | grep md0 > /dev/null && mdconfig -d -u 0 + +mdconfig -a -t vnode -f $D -u 0 +bsdlabel -w md0 auto +newfs -U md0c > /dev/null +echo "/dev/md0c /mnt ufs rw,userquota 2 2" >> /etc/fstab +mount /mnt +edquota -u -f /mnt -e /mnt:850000:900000:130000:140000 root > /dev/null 2>&1 +quotaon /mnt +sed -i -e '/md0c/d' /etc/fstab # clean up before any panics +export RUNDIR=/mnt/stressX +../testcases/rw/rw -t 10m -i 200 -h -n -v -v& +pid=$! +for i in `jot 5`; do + echo "`date '+%T'` mksnap_ffs /mnt /mnt/.snap/snap$i" + mksnap_ffs /mnt /mnt/.snap/snap$i +done +for i in `jot 5`; do + rm -f /mnt/.snap/snap1 +done +kill $pid +false +while mount | grep -q /mnt; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f" || echo "") /mnt > /dev/null 2>&1 +done +mdconfig -d -u 0 +rm -f $D diff --git a/test/stress/stress2/misc/quota7.sh b/test/stress/stress2/misc/quota7.sh new file mode 100755 index 0000000000..5d91fbee54 --- /dev/null +++ b/test/stress/stress2/misc/quota7.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Quota / snapshot test scenario by Kris@ +# Causes spin in ffs_sync or panic in panic: vfs_allocate_syncvnode: insmntque failed + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +D=/var/tmp/diskimage +trap "rm -f $D" 0 +dd if=/dev/zero of=$D bs=1m count=1k + +mount | grep "/mnt" | grep -q md0 && umount -f /mnt +mdconfig -l | grep -q md0 && mdconfig -d -u 0 + +mdconfig -a -t vnode -f $D -u 0 +bsdlabel -w md0 auto +newfs -U md0c > /dev/null +echo "/dev/md0c /mnt ufs rw,userquota 2 2" >> /etc/fstab +mount /mnt +set `df -ik /mnt | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 / 21)) +export INODES=$(($2 / 21)) +export HOG=1 +export INCARNATIONS=40 + +export QK=$((KBLOCKS / 2)) +export QI=$((INODES / 2)) +edquota -u -f /mnt -e /mnt:$((QK - 50)):$QK:$((QI - 50 )):$QI pho +quotaon /mnt +sed -i -e '/md0c/d' /etc/fstab +export RUNDIR=/mnt/stressX +mkdir /mnt/stressX +chmod 777 /mnt/stressX +su pho -c "(cd ..;runRUNTIME=1h ./run.sh disk.cfg)"& # panic: vfs_allocate_syncvnode: insmntque failed +for i in `jot 20`; do + echo "`date '+%T'` mksnap_ffs /mnt /mnt/.snap/snap$i" + mksnap_ffs /mnt /mnt/.snap/snap$i + sleep 1 +done +i=$(($(date '+%S') % 20 + 1)) +echo "rm -f /mnt/.snap/snap$i" +rm -f /mnt/.snap/snap$i +wait + +while mount | grep -q /mnt; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f" || echo "") /mnt > /dev/null 2>&1 +done +mdconfig -d -u 0 +rm -f $D diff --git a/test/stress/stress2/misc/quota8.sh b/test/stress/stress2/misc/quota8.sh new file mode 100755 index 0000000000..cb03717e58 --- /dev/null +++ b/test/stress/stress2/misc/quota8.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Quota / snapshot test scenario by Kris@ +# Causes spin in ffs_sync or panic in panic: vfs_allocate_syncvnode: insmntque failed + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +trap "rm -f $D" 0 +dede $D 1m 1k || exit 1 + +mount | grep "${mntpoint}" | grep -q md${mdstart} && umount -f ${mntpoint} +mdconfig -l | grep -q md${mdstart} && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs -U md${mdstart}${part} > /dev/null +echo "/dev/md${mdstart}${part} ${mntpoint} ufs rw,userquota 2 2" >> /etc/fstab +mount ${mntpoint} +set `df -ik ${mntpoint} | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 / 21)) +export INODES=$(($2 / 21)) +export HOG=1 +export INCARNATIONS=40 + +export QK=$((KBLOCKS / 2)) +export QI=$((INODES / 2)) +edquota -u -f ${mntpoint} -e ${mntpoint}:$((QK - 50)):$QK:$((QI - 50 )):$QI ${testuser} +quotaon ${mntpoint} +sed -i -e "/md${mdstart}${part}/d" /etc/fstab +export RUNDIR=${mntpoint}/stressX +mkdir ${mntpoint}/stressX +chmod 777 ${mntpoint}/stressX +su ${testuser} -c 'sh -c "(cd ..;runRUNTIME=20m ./run.sh disk.cfg)"&' # Deadlock +for i in `jot 20`; do + echo "`date '+%T'` mksnap_ffs ${mntpoint} ${mntpoint}/.snap/snap$i" + mksnap_ffs ${mntpoint} ${mntpoint}/.snap/snap$i + sleep 1 +done +i=$(($(date '+%S') % 20 + 1)) +echo "rm -f ${mntpoint}/.snap/snap$i" +rm -f ${mntpoint}/.snap/snap$i +wait + +while mount | grep -q ${mntpoint}; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f" || echo "") ${mntpoint} > /dev/null 2>&1 +done +mdconfig -d -u ${mdstart} +rm -f $D diff --git a/test/stress/stress2/misc/quota9.sh b/test/stress/stress2/misc/quota9.sh new file mode 100755 index 0000000000..3df67969fd --- /dev/null +++ b/test/stress/stress2/misc/quota9.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test if quotacheck reports actual usage + +. ../default.cfg + +export tmp=/tmp/$(basename $0).$$ +export D=$diskimage + +qc() { + quotacheck -v $1 > $tmp 2>&1 + grep -q fixed $tmp && cat $tmp +} + +if [ $# -eq 0 ]; then + trap "rm -f $D $tmp" 0 + [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + + dede $D 1m 50 || exit 1 + + mount | grep "${mntpoint}" | grep -q md${mdstart} && umount -f ${mntpoint} + mdconfig -l | grep -q md${mdstart} && mdconfig -d -u ${mdstart} + + mdconfig -a -t vnode -f $D -u ${mdstart} + bsdlabel -w md${mdstart} auto + newfs -U md${mdstart}${part} > /dev/null + echo "/dev/md${mdstart}${part} ${mntpoint} ufs rw,userquota 2 2" >> /etc/fstab + mount ${mntpoint} + mkdir ${mntpoint}/stressX + chown $testuser ${mntpoint}/stressX + set `df -ik ${mntpoint} | tail -1 | awk '{print $4,$7}'` + export KBLOCKS=$1 + export INODES=$2 + + export QK=$((KBLOCKS / 2)) + export QI=$((INODES / 2)) + edquota -u -f ${mntpoint} -e ${mntpoint}:$((QK - 50)):$QK:$((QI - 50 )):$QI ${testuser} > /dev/null 2>&1 + quotaon ${mntpoint} + +# quotaoff ${mntpoint};umount ${mntpoint}; mount ${mntpoint};quotaon ${mntpoint} +# df -i ${mntpoint} +# repquota -v ${mntpoint} + qc ${mntpoint} +# repquota -v ${mntpoint} +# echo "- Start test -" + + su ${testuser} $0 xxx + du -k /mnt/stressX + +# quotaoff ${mntpoint};umount ${mntpoint}; mount ${mntpoint};quotaon ${mntpoint} +# df -i ${mntpoint} +# repquota -v ${mntpoint} + qc ${mntpoint} +# repquota -v ${mntpoint} + + sed -i -e "/md${mdstart}${part}/d" /etc/fstab + while mount | grep -q ${mntpoint}; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f" || echo "") ${mntpoint} > /dev/null 2>&1 + done + mdconfig -d -u ${mdstart} + rm -f $D +else + for i in `jot 20`; do + dede ${mntpoint}/stressX/d$i 1m 1 + done +fi diff --git a/test/stress/stress2/misc/recursiveflushes.sh b/test/stress/stress2/misc/recursiveflushes.sh new file mode 100755 index 0000000000..5e89a23f20 --- /dev/null +++ b/test/stress/stress2/misc/recursiveflushes.sh @@ -0,0 +1,65 @@ +# $FreeBSD$ + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# test recursive flushes in bdwrite(). + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +snap() { + for i in `jot 5`; do + mksnap_ffs $1 $2 + [ $? -eq 0 ] && break + done +} + +old=`sysctl vfs.recursiveflushes | awk '{print $NF}'` +cd /var/tmp +rm -f /var/.snap/pho.* +trap "rm -f /var/.snap/pho.*" 0 +snap /var /var/.snap/pho.1 +snap /var /var/.snap/pho.2 +snap /var /var/.snap/pho.3 +snap /var /var/.snap/pho.4 +snap /var /var/.snap/pho.5 + +for i in `jot 32`; do + # Create 32 Mb files + dd if=/dev/zero of=big.$i bs=16k count=2048 2>&1 | egrep -v "records|transferred"& +done +for i in `jot 32`; do + wait +done +for i in `jot 32`; do + rm -f big.$i +done + +rm -f /var/.snap/pho.* +new=`sysctl vfs.recursiveflushes | awk '{print $NF}'` +[ $old != $new ] && echo "vfs.recursiveflushes changed from $old to $new" diff --git a/test/stress/stress2/misc/rename.sh b/test/stress/stress2/misc/rename.sh new file mode 100755 index 0000000000..edf3769531 --- /dev/null +++ b/test/stress/stress2/misc/rename.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test race between ISDOTDOT lookups and directory removal/rename + +# With lookup_shared=1 rename() will fail from time to time with ENOENT and +# the following stat() will succed. + +# Test scenario by tegge + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename.c +cc -o rename -Wall rename.c +rm -f rename.c +cd $here + +rm -rf /tmp/rename.dir.* +for i in `jot 10`; do + for j in `jot 10`; do + /tmp/rename & + done + for j in `jot 10`; do + wait + done +done +rm -rf /tmp/rename.dir.* +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char dir1[128]; +static char dir2[128]; + +int +main(int argc, char **argv) +{ + int i, status; + struct stat sb; + pid_t p; + + sprintf(dir1, "/tmp/rename.dir.%d", getpid()); + sprintf(dir2, "/tmp/rename.dir.2.%d", getpid()); + if (mkdir(dir1, 0700) == -1) + err(1, "mkdir(%s)", dir1); + + if (chdir(dir1) == -1) + err(1, "chdir(%s)", dir1); + if ((p = fork()) == -1) + err(1, "fork()"); + if (p == 0) { + if (chdir("..") == -1) + err(1, "chdir(%s)", ".."); + for (i = 0; i < 100000; i++) { + if (rename(dir1, dir2) == -1) { + warn("rename(%s, %s)", dir1, dir2); + stat(dir1, &sb); + if (stat(dir1, &sb) == -1) + err(1, "stat(%s)", dir1); + else + errx(1, "stat(%s) succeeded!", dir1); + } + if (rename(dir2, dir1) == -1) { + warn("rename(%s, %s)", dir2, dir1); + stat(dir2, &sb); + if (stat(dir2, &sb) == -1) + err(1, "stat(%s)", dir2); + else + errx(1, "stat(%s) succeeded!", dir2); + } + } + exit(0); + } else { + for (i = 0; i < 100000; i++) { + if (stat("..", &sb) == -1) + err(1, "stat(..)"); + } + } + if (waitpid(p, &status, 0) == -1) + err(1, "waitpid()"); + if (rmdir(dir1) == -1) + err(1, "rmdir(%s)", dir1); + + return (0); +} diff --git a/test/stress/stress2/misc/rename2.sh b/test/stress/stress2/misc/rename2.sh new file mode 100755 index 0000000000..4f28714f90 --- /dev/null +++ b/test/stress/stress2/misc/rename2.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# With lookup_shared=1 rename() will fail from time to time with ENOENT and +# the following stat() will succeed. (Variation of rename.sh) + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename.c +cc -o rename -Wall rename.c +rm -f rename.c +cd $here + +rm -rf /tmp/rename.dir.* +for i in `jot 10`; do + for j in `jot 10`; do + /tmp/rename & + done + for j in `jot 10`; do + wait + done +done +rm -rf /tmp/rename.dir.* +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include + +static char dir1[128]; +static char dir2[128]; + +int +main(int argc, char **argv) +{ + int i; + struct stat sb; + + sprintf(dir1, "/tmp/rename.dir.%d", getpid()); + sprintf(dir2, "/tmp/rename.dir.2.%d", getpid()); + if (mkdir(dir1, 0700) == -1) + err(1, "mkdir(%s)", dir1); + + if (chdir(dir1) == -1) + err(1, "chdir(%s)", dir1); + if (chdir("..") == -1) + err(1, "chdir(%s)", ".."); + + for (i = 0; i < 100000; i++) { + if (rename(dir1, dir2) == -1) { + warn("rename(%s, %s)", dir1, dir2); + if (stat(dir1, &sb) == -1) + err(1, "stat(%s)", dir1); + else + errx(1, "stat(%s) succeeded!", dir1); + } + if (rename(dir2, dir1) == -1) { + warn("rename(%s, %s)", dir2, dir1); + if (stat(dir2, &sb) == -1) + err(1, "stat(%s)", dir2); + else + errx(1, "stat(%s) succeeded!", dir2); + } + } + + if (rmdir(dir1) == -1) + err(1, "rmdir(%s)", dir1); + + return (0); +} diff --git a/test/stress/stress2/misc/rename3.sh b/test/stress/stress2/misc/rename3.sh new file mode 100755 index 0000000000..8a654e4eca --- /dev/null +++ b/test/stress/stress2/misc/rename3.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test vulnerability to transient failures when a directory closer +# to the root directory is renamed + +# Test scenario by Tor Egge + +root=/tmp +for i in `jot 10000`; do + rm -rf ${root}/a + mkdir -p ${root}/a/b/c/d/e/f/g + mkdir -p ${root}/a/b/c/d/e/f/z + cd ${root}/a/b/c/d/e/f + ( mv ${root}/a/b/c ${root}/a/c ) & + if ! mv z g/z; then + echo "FAILURE at loop $i" + break + fi + wait +done +rm -rf ${root}/a diff --git a/test/stress/stress2/misc/rename4.sh b/test/stress/stress2/misc/rename4.sh new file mode 100755 index 0000000000..8a8cb55086 --- /dev/null +++ b/test/stress/stress2/misc/rename4.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# lookup() does not return error when lookup of path ending on "/." is done +# for RENAME operation. + +# Tets scenario by Jim Meyering + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > rename4.c +cc -o rename4 -Wall rename4.c +rm -f rename4.c +cd $RUNDIR + +rm -rf 1 2 +mkdir 1 2 + +/tmp/rename4 1 2/. + +rm -rf 1 2 /tmp/rename4 +exit +EOF +#include +#include + +int +main(int argc, char **argv) +{ + if (rename(argv[1], argv[2]) == -1) + err(1, "rename(%s, %s)", argv[1], argv[2]); + + return (0); +} diff --git a/test/stress/stress2/misc/revoke.sh b/test/stress/stress2/misc/revoke.sh new file mode 100755 index 0000000000..626994d484 --- /dev/null +++ b/test/stress/stress2/misc/revoke.sh @@ -0,0 +1,118 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test. Causes panic on 6.1 + +odir=`pwd` +dir=/tmp + +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/revoke.c +cc -o revoke -Wall revoke.c +rm -f revoke.c + +n=100 # Number of times to test +for i in `jot $n`; do + ./revoke /dev/ttyv9& + ./revoke /dev/ttyva& + ./revoke /dev/ttyvb& + ./revoke /dev/ttyvc& + for j in `jot 4`; do + wait + done +done + +#rm -f revoke + +exit +EOF +/* By Martin Blapp, */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/*#define TTY "/dev/ttyv9"*/ /* should be totally unused */ +#define CTTY "/dev/tty" + +int +main(int argc, char **argv) +{ + int ttyfd; + pid_t pid; + + if (argc != 2) { + fprintf(stderr, "Usage: %s /dev/ttyv?\n", argv[0]); + return 1; + } + + /* Get rid of my ctty. */ + printf("Parent starting: pid %d\n", getpid()); + pid = fork(); + if (pid < 0) { + err(1, "fork"); + exit(1); + } else if (pid > 0) { + int status; + /* parent */ + waitpid(pid, &status, 0); + exit(0); + } + /* child */ + printf("Child: pid %d\n", getpid()); + + if (setsid() < 0) { + err(1, "setsid"); + exit(1); + } + ttyfd = open(argv[1], O_RDWR); + if (ttyfd < 0) { + err(1, "open(%s)", argv[1]); + exit(1); + } + if (ioctl(ttyfd, TIOCSCTTY) < 0) { + err(1, "ioctl(TIOCSCTTY)"); + exit(1); + } + if (revoke(argv[1]) < 0) { + err(1, "revoke(%s)", argv[1]); + exit(1); + } + if (open(CTTY, O_RDWR) < 0) { + err(1, "open(%s)", CTTY); + exit(1); + } + return 0; +} diff --git a/test/stress/stress2/misc/sem.sh b/test/stress/stress2/misc/sem.sh new file mode 100755 index 0000000000..d6bc6c865d --- /dev/null +++ b/test/stress/stress2/misc/sem.sh @@ -0,0 +1,145 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test for panic in semexit_myhook +# Test scenario by kib@ + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > sem.c +cc -o sem -Wall sem.c +rm -f sem.c + +cd $RUNDIR/.. +for i in `jot 5`; do + /tmp/sem& +done +for i in `jot 5`; do + wait +done + +rm -f /tmp/sem + +exit +EOF + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int semid = -1; +key_t semkey; +struct sembuf sop[2]; + +size_t pgsize; +pid_t pid; + +void +random_work(void) +{ + int i, n; + + n = (arc4random() % 5000) + 200; + for (i = 0; i < n; i++) + (void) getpid(); +} + +int +main() +{ + int i, j, seed, status; + + seed = getpid(); + semkey = ftok("/", seed); + + for (i = 0; i < 5000; i++) { + + pid = fork(); + if (pid == -1) { + perror("fork"); + exit(2); + } + + if (pid == 0) { /* child */ + j = 0; + /* get sem */ + do { + sched_yield(); + semid = semget(semkey, 0, 0); + } while (semid == -1 && j++ < 10000); + if (semid == -1) + exit(1); + + /* + * Attempt to acquire the semaphore. + */ + sop[0].sem_num = 0; + sop[0].sem_op = -1; + sop[0].sem_flg = SEM_UNDO; + + semop(semid, sop, 1); + random_work(); + _exit(0); + + } else { /* parent */ + /* create sem */ + if ((semid = semget(semkey, 1, IPC_CREAT | 010640)) == -1) + err(1, "semget (%s:%d)", __FILE__, __LINE__); + usleep(2000); + + sop[0].sem_num = 0; + sop[0].sem_op = 1; + sop[0].sem_flg = 0; + if (semop(semid, sop, 1) == -1) + warn("init: semop (%s:%d)", __FILE__, __LINE__); + + random_work(); + if (semctl(semid, 0, IPC_RMID, 0) == -1 && errno != EINVAL) + warn("shmctl IPC_RMID (%s:%d)", __FILE__, __LINE__); + + } + waitpid(pid, &status, 0); + } + return (0); +} diff --git a/test/stress/stress2/misc/sendfile.sh b/test/stress/stress2/misc/sendfile.sh new file mode 100755 index 0000000000..399edf7567 --- /dev/null +++ b/test/stress/stress2/misc/sendfile.sh @@ -0,0 +1,215 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario for sendfile livelock seen on 7.2-STABLE for non SMP + +# Scenario by kib@ + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > sendfile.c +cc -o sendfile -Wall sendfile.c -pthread +rm -f sendfile.c +[ -d "$RUNDIR" ] || mkdir -p $RUNDIR +cd $RUNDIR + +in=/tmp/inputFile +out=/tmp/outputFile + +for i in 1 2 3 4 8 16 1k 2k 3k 4k 5k 1m 2m 3m 4m 5m ; do + rm -f $in $out + dd if=/dev/random of=$in bs=$i count=1 2>&1 | \ + egrep -v "records|transferred" + /tmp/sendfile $in $out 12345 + cmp $in $out || ls -l $in $out + rm -f $in $out +done +rm -f /tmp/sendfile +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int port; +char *inputFile; +char *outputFile; +int bufsize = 4096; + +static void +reader(void) { + int tcpsock, msgsock; + int on; + socklen_t len; + struct sockaddr_in inetaddr, inetpeer; + int n, t, *buf, fd; + + on = 1; + if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) + err(1, "socket(), %s:%d", __FILE__, __LINE__); + + if (setsockopt(tcpsock, + SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) + err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); + + inetaddr.sin_family = AF_INET; + inetaddr.sin_addr.s_addr = INADDR_ANY; + inetaddr.sin_port = htons(port); + inetaddr.sin_len = sizeof(inetaddr); + + if (bind(tcpsock, + (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) + err(1, "bind(), %s:%d", __FILE__, __LINE__); + + if (listen(tcpsock, 5) < 0) + err(1, "listen(), %s:%d", __FILE__, __LINE__); + + len = sizeof(inetpeer); + if ((msgsock = accept(tcpsock, + (struct sockaddr *)&inetpeer, &len)) < 0) + err(1, "accept(), %s:%d", __FILE__, __LINE__); + + t = 0; + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + + if ((fd = open(outputFile, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) + err(1, "open(%s)", outputFile); + + for (;;) { + if ((n = read(msgsock, buf, bufsize)) < 0) + err(1, "read(), %s:%d", __FILE__, __LINE__); + t += n; + if (n == 0) break; + + if ((write(fd, buf, n)) != n) + err(1, "write"); + } + close(msgsock); + close(fd); + return; +} + +static void +writer(void) { + int tcpsock, on; + struct sockaddr_in inetaddr; + struct hostent *hostent; + struct stat statb; + int i, r, fd; + off_t off = 0; +#if 1 + size_t size; +#endif + + on = 1; + for (i = 1; i < 5; i++) { + if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) + err(1, "socket(), %s:%d", __FILE__, __LINE__); + + if (setsockopt(tcpsock, + SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) + err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); + +#if 1 /* livelock trigger */ + size = getpagesize() -4; + if (setsockopt(tcpsock, + SOL_SOCKET, SO_SNDBUF, (void *)&size, sizeof(size)) < 0) + err(1, "setsockopt(SO_SNDBUF), %s:%d", __FILE__, __LINE__); +#endif + + hostent = gethostbyname ("localhost"); + memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, + sizeof (struct in_addr)); + + inetaddr.sin_family = AF_INET; + inetaddr.sin_addr.s_addr = INADDR_ANY; + inetaddr.sin_port = htons(port); + inetaddr.sin_len = sizeof(inetaddr); + + r = connect(tcpsock, (struct sockaddr *) &inetaddr, + sizeof(inetaddr)); + if (r == 0) + break; + sleep(1); + close(tcpsock); + } + if (r < 0) + err(1, "connect(), %s:%d", __FILE__, __LINE__); + + if (stat(inputFile, &statb) != 0) + err(1, "stat(%s)", inputFile); + + if ((fd = open(inputFile, O_RDONLY)) == -1) + err(1, "open(%s)", inputFile); + + if (sendfile(fd, tcpsock, 0, statb.st_size, NULL, &off, 0) == -1) + err(1, "sendfile"); + + return; +} + +int +main(int argc, char **argv) +{ + pid_t pid; + + if (argc != 4) { + fprintf(stderr, "Usage: %s 0) { + reader(); + kill(pid, SIGINT); + } else + err(1, "fork(), %s:%d", __FILE__, __LINE__); + + return (0); +} diff --git a/test/stress/stress2/misc/snap.sh b/test/stress/stress2/misc/snap.sh new file mode 100755 index 0000000000..863d914a8f --- /dev/null +++ b/test/stress/stress2/misc/snap.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +mount | grep "/dev/md0 on /mnt" > /dev/null && umount /mnt +rm -f /tmp/.snap/pho +trap "rm -f /tmp/.snap/pho" 0 + +for i in `jot 128`; do + mksnap_ffs /tmp /tmp/.snap/pho + mdconfig -a -t vnode -f /tmp/.snap/pho -u 0 -o readonly + mount -r /dev/md0 /mnt + + ls -l /mnt > /dev/null + + umount /mnt + mdconfig -d -u 0 + rm -f /tmp/.snap/pho +done + + +for i in `jot 128`; do + mksnap_ffs /tmp /tmp/.snap/pho + rm -f /tmp/.snap/pho +done diff --git a/test/stress/stress2/misc/snap2-1.sh b/test/stress/stress2/misc/snap2-1.sh new file mode 100755 index 0000000000..cf78136bcb --- /dev/null +++ b/test/stress/stress2/misc/snap2-1.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Regression test: Delete an active md device +# +# panic(c088cd33,deadc000,c0943aa0,0,c08753e1) at panic+0x14b +# vm_fault(c1060000,deadc000,1,0,c54de480) at vm_fault+0x1e0 +# trap_pfault(e76728b8,0,deadc112) at trap_pfault+0x137 +# trap(8,c0870028,28,deadc0de,deadc0de) at trap+0x355 +# calltrap() at calltrap+0x5 +# --- trap 0xc, eip = 0xc060bcfb, esp = 0xe76728f8, ebp = 0xe767291c --- +# g_io_request(c53ff7bc,c5051d40,d8c72408,c54ca110,e7672950) at g_io_request+0x5f + +rm -f /tmp/.snap/pho +[ -d /tmp/.snap ] || mkdir /tmp/.snap +trap "rm -f /tmp/.snap/pho" 0 +mount | grep "/mnt" | grep md0 > /dev/null && umount /mnt +mdconfig -l | grep -q md0 && mdconfig -d -u 0 + +mksnap_ffs /tmp /tmp/.snap/pho +mdconfig -a -t vnode -o readonly -f /tmp/.snap/pho -u 0 +mount -o ro /dev/md0 /mnt + +ls -lR /mnt > /dev/null 2>&1 & +mdconfig -d -u 0 > /dev/null 2>&1 + +umount -f /mnt +mdconfig -d -u 0 +rm -f /tmp/.snap/pho diff --git a/test/stress/stress2/misc/snap2.sh b/test/stress/stress2/misc/snap2.sh new file mode 100755 index 0000000000..302b8b1eb0 --- /dev/null +++ b/test/stress/stress2/misc/snap2.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Regression test: Delete an active md device +# +# panic(c088cd33,deadc000,c0943aa0,0,c08753e1) at panic+0x14b +# vm_fault(c1060000,deadc000,1,0,c54de480) at vm_fault+0x1e0 +# trap_pfault(e76728b8,0,deadc112) at trap_pfault+0x137 +# trap(8,c0870028,28,deadc0de,deadc0de) at trap+0x355 +# calltrap() at calltrap+0x5 +# --- trap 0xc, eip = 0xc060bcfb, esp = 0xe76728f8, ebp = 0xe767291c --- +# g_io_request(c53ff7bc,c5051d40,d8c72408,c54ca110,e7672950) at g_io_request+0x5f + +. ../default.cfg + +rm -f /tmp/.snap/pho +trap "rm -f /tmp/.snap/pho" 0 +mount | grep "${mntpoint}" | grep -q md${mdstart} && umount -f ${mntpoint} +mdconfig -l | grep -q md${mdstart} && mdconfig -d -u ${mdstart} + +mksnap_ffs /tmp /tmp/.snap/pho +mdconfig -a -t vnode -f /tmp/.snap/pho -u $mdstart -o readonly +mount -r /dev/md${mdstart} ${mntpoint} + +ls -lR > /dev/null 2>&1 & +mdconfig -d -u $mdstart > /dev/null 2>&1 + +umount ${mntpoint} > /dev/null 2>&1 +umount -f ${mntpoint} > /dev/null 2>&1 +mdconfig -d -u $mdstart +rm -f /tmp/.snap/pho diff --git a/test/stress/stress2/misc/snap3.sh b/test/stress/stress2/misc/snap3.sh new file mode 100755 index 0000000000..23d2991a60 --- /dev/null +++ b/test/stress/stress2/misc/snap3.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test with two snapshots +# 20070506 Page fault in g_io_request+0x7f + +mount | grep "/dev/md0 on /mnt" > /dev/null && umount /mnt +rm -f /tmp/.snap/pho.1 +rm -f /tmp/.snap/pho.2 +trap "rm -f /tmp/.snap/pho.?" 0 +mount | grep "/mnt" | grep md5 > /dev/null && umount /mnt +mdconfig -l | grep -q md5 && mdconfig -d -u 5 +mdconfig -l | grep -q md6 && mdconfig -d -u 6 + +for i in `jot 64`; do + mksnap_ffs /tmp /tmp/.snap/pho.1 + mksnap_ffs /tmp /tmp/.snap/pho.2 + mdconfig -a -t vnode -f /tmp/.snap/pho.1 -u 5 -o readonly + mdconfig -a -t vnode -f /tmp/.snap/pho.2 -u 6 -o readonly + mount -o ro /dev/md5 /mnt + + sleep 3 + + umount /mnt + mdconfig -d -u 5 + mdconfig -d -u 6 + rm -f /tmp/.snap/pho.1 + rm -f /tmp/.snap/pho.2 +done diff --git a/test/stress/stress2/misc/snap4.sh b/test/stress/stress2/misc/snap4.sh new file mode 100755 index 0000000000..1c22d4117c --- /dev/null +++ b/test/stress/stress2/misc/snap4.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test with snapshot file unlinked before unmount + +mount | grep "/dev/md0 on /mnt" > /dev/null && umount /mnt +mdconfig -l | grep -q md0 && mdconfig -d -u 0 +rm -f /tmp/.snap/pho +trap "rm -f /tmp/.snap/pho" 0 + +for i in `jot 64`; do + mksnap_ffs /tmp /tmp/.snap/pho + mdconfig -a -t vnode -f /tmp/.snap/pho -u 0 -o readonly + mount -o ro /dev/md0 /mnt + + ls -l /mnt > /dev/null + rm -f /tmp/.snap/pho + sleep 1 + + umount /mnt + mdconfig -d -u 0 + rm -f /tmp/.snap/pho +done diff --git a/test/stress/stress2/misc/snap5-1.sh b/test/stress/stress2/misc/snap5-1.sh new file mode 100755 index 0000000000..b74cbc9818 --- /dev/null +++ b/test/stress/stress2/misc/snap5-1.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ ! -d /mnt2 ] && mkdir /mnt2 + +trap "rm -f /tmp/.snap/pho" 0 +for i in `jot 64`; do + if mount | grep -q "/dev/md0 on /mnt2"; then + umount /mnt2 || exit 2 + fi + if mdconfig -l | grep -q md0; then + mdconfig -d -u 0 || exit 3 + fi + rm -f /tmp/.snap/pho + + date '+%T' + mksnap_ffs /tmp /tmp/.snap/pho || continue + mdconfig -a -t vnode -f /tmp/.snap/pho -u 0 -o readonly || exit 4 + mount -o ro /dev/md0 /mnt2 || exit 5 + + ls -l /mnt2 > /dev/null + r=`head -c4 /dev/urandom | od -N2 -tu4 | sed -ne '1s/ *$//;1s/.* //p'` + sleep $(( r % 120 )) +done +mount | grep -q "/dev/md0 on /mnt2" && umount /mnt2 +mdconfig -l | grep -q md0 && mdconfig -d -u 0 diff --git a/test/stress/stress2/misc/snap5.sh b/test/stress/stress2/misc/snap5.sh new file mode 100755 index 0000000000..1713ed000b --- /dev/null +++ b/test/stress/stress2/misc/snap5.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ ! -d /mnt2 ] && mkdir /mnt2 +mount | grep "/dev/md0 on /mnt2" > /dev/null && umount /mnt2 +mdconfig -l | grep md0 > /dev/null && mdconfig -d -u 0 +rm -f /tmp/.snap/pho +trap "rm -f /tmp/.snap/pho" 0 + +for i in `jot 64`; do + date '+%T' + mksnap_ffs /tmp /tmp/.snap/pho + mdconfig -a -t vnode -f /tmp/.snap/pho -u 0 -o readonly + mount -o ro /dev/md0 /mnt2 + + ls -l /mnt2 > /dev/null + r=`head -c4 /dev/urandom | od -N2 -tu4 | sed -ne '1s/ *$//;1s/.* //p'` + sleep $(( r % 120 )) + + umount /mnt2 + mdconfig -d -u 0 + rm -f /tmp/.snap/pho +done diff --git a/test/stress/stress2/misc/snap6.sh b/test/stress/stress2/misc/snap6.sh new file mode 100755 index 0000000000..c1bfdc304b --- /dev/null +++ b/test/stress/stress2/misc/snap6.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# Problem Report kern/92272 : [ffs] [hang] Filling a filesystem while creating +# a snapshot on it locks the system + +# John Kozubik + +# If a filesystem is completely full (approaching 110% in `df` output on +# most systems), mksnap_ffs will refuse to begin a snapshot for that reason. +# There seem to be no negative consequences. + +# However, if the filesystem is not quite completely full, mksnap_ffs will +# (correctly) begin creating the snapshot as expected. If, during the course +# of snapshot creation, the filesystem being snapshotted becomes full, +# mksnap_ffs will exit with an error exactly as it does if it is started on +# an already full filesystem. + +# However, several hours later, the system will lock up completely. It still +# responds to pings, and open connections to and from it remain in that +# state, but they cannot be used and new connections cannot be established. + +# *** This script does not provoke the problem. *** + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +root=/var + +rm -f $root/.snap/pho $root/big $root/big2 +trap "rm -f $root/.snap/pho $root/big $root/big2" 0 +free=`df $root | tail -1 | awk '{print $4}'` +dd if=/dev/zero of=$root/big bs=1m count=$(( free / 1024 - 90)) > /dev/null 2>&1 +df $root + +for i in `jot 1024`; do + date + nice -20 mksnap_ffs $root $root/.snap/pho & + dd if=/dev/zero of=$root/big2 bs=1m > /dev/null 2>&1 + wait + [ -f $root/.snap/pho ] && exit 0 + rm -f $root/.snap/pho $root/big2 +done +df $root + +rm -f $root/.snap/pho $root/big $root/big2 diff --git a/test/stress/stress2/misc/snap7.sh b/test/stress/stress2/misc/snap7.sh new file mode 100755 index 0000000000..8baa29bd3a --- /dev/null +++ b/test/stress/stress2/misc/snap7.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test with unmount and paralless access to mountpoint +# 20070508 page fault in g_io_request+0xa6 + +mount | grep "/dev/md0 on /mnt" > /dev/null && umount /mnt +rm -f /tmp/.snap/pho.1 +trap "rm -f /tmp/.snap/pho.1" 0 +mount | grep "/mnt" | grep md0 > /dev/null && umount /mnt +mdconfig -l | grep -q md0 && mdconfig -d -u 0 + +for i in `jot 64`; do + mksnap_ffs /tmp /tmp/.snap/pho.1 + mdconfig -a -t vnode -f /tmp/.snap/pho.1 -u 0 -o readonly + sh -c "while true; do ls /mnt > /dev/null;done" & + for i in `jot 64`; do + mount -o ro /dev/md0 /mnt + umount /mnt + done + kill $! + mdconfig -d -u 0 + rm -f /tmp/.snap/pho.1 +done diff --git a/test/stress/stress2/misc/snap8.sh b/test/stress/stress2/misc/snap8.sh new file mode 100755 index 0000000000..aecb2f3026 --- /dev/null +++ b/test/stress/stress2/misc/snap8.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Deadlock seen when deleting the snapshots during an "ls" of the FS + +# Based on test scenario by John Kozubik +# kern/94769: [ufs] Multiple file deletions on multi-snapshotted filesystems +# causes hang + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep -q /dev/md${mdstart}$part && umount -f /dev/md${mdstart}$part +mdconfig -l | grep -q md${mdstart} && mdconfig -d -u $mdstart + + +parallel=20 +size=25 # Gb +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print $4'}` -lt $((size * 1024 * 1024)) ] && \ + echo "Not enough disk space." && exit 1 +truncate -s ${size}G $diskimage + +mdconfig -a -t vnode -f $diskimage -u $mdstart +bsdlabel -w md$mdstart auto +newfs -O2 -U md${mdstart}${part} > /dev/null +mount /dev/md${mdstart}${part} $mntpoint + + +cc -o /tmp/fstool -Wall ../tools/fstool.c +for i in `jot $parallel`; do + (mkdir $mntpoint/test$i; cd $mntpoint/test$i; /tmp/fstool -l -f 50 -n 500 -s 8k) & +done +for i in `jot $parallel`; do + wait +done +rm -f /tmp/fstool + +mksnap_ffs $mntpoint $mntpoint/.snap/snap1 +mksnap_ffs $mntpoint $mntpoint/.snap/snap2 +mksnap_ffs $mntpoint $mntpoint/.snap/snap3 +mksnap_ffs $mntpoint $mntpoint/.snap/snap4 +mksnap_ffs $mntpoint $mntpoint/.snap/snap5 +mksnap_ffs $mntpoint $mntpoint/.snap/snap6 +mksnap_ffs $mntpoint $mntpoint/.snap/snap7 +mksnap_ffs $mntpoint $mntpoint/.snap/snap8 +mksnap_ffs $mntpoint $mntpoint/.snap/snap9 + +for i in `jot $parallel`; do + rm -rf $mntpoint/test$i & +done +for i in `jot $parallel`; do + wait +done + +rm -rf $mntpoint/.snap/snap? & + +for i in `jot 10`; do + ls -lsrt $mntpoint > /dev/null 2>&1 + sleep 2 +done +wait + +umount /dev/md${mdstart}$part + +mount | grep -q /dev/md${mdstart}$part && umount -f /dev/md${mdstart}$part +mdconfig -l | grep -q md${mdstart} && mdconfig -d -u $mdstart +rm -f $diskimage diff --git a/test/stress/stress2/misc/snapbackup.sh b/test/stress/stress2/misc/snapbackup.sh new file mode 100755 index 0000000000..8664084b03 --- /dev/null +++ b/test/stress/stress2/misc/snapbackup.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Maintain four snapshot backups of /tmp in /backup/snap? + +[ ! -d /backup ] && mkdir /backup + +for i in `mount | grep "/backup" | awk '{print $1}'`; do + num=`echo $i | sed 's/.*md//'` + false + while [ $? -ne 0 ]; do + umount $i + done + mdconfig -d -u $num +done +for i in `mdconfig -l | sed 's/md//g'`; do + [ $i -lt 1 -o $i -gt 4 ] && continue + mdconfig -d -u $i +done + +cd /tmp/.snap +[ -r snap4 ] && rm -f snap4 +[ -r snap3 ] && mv snap3 snap4 +[ -r snap2 ] && mv snap2 snap3 +[ -r snap1 ] && mv snap1 snap2 + +mksnap_ffs /tmp /tmp/.snap/snap1 + +for i in `ls /tmp/.snap/snap*`; do + name=`basename $i` + num=`echo $name | sed 's/snap//'` + mdconfig -a -t vnode -o readonly -f /tmp/.snap/snap${num} -u ${num} + [ ! -d /backup/snap${num} ] && mkdir /backup/snap${num} + mount -o ro /dev/md${num} /backup/snap${num} +done diff --git a/test/stress/stress2/misc/softupdate.sh b/test/stress/stress2/misc/softupdate.sh new file mode 100755 index 0000000000..ba821954e6 --- /dev/null +++ b/test/stress/stress2/misc/softupdate.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Like the symlink.sh test, this test shows the problem with Soft Update and +# incorrect statfs(2). + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg +runRUNTIME=10m +runRUNTIME=1m +RUNDIR=${mntpoint}/stressX + +D=$diskimage +dede $D 1m 512 || exit 1 + +mount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} + +for mode in "" "-U"; do + printf "newfs -O2 $mode /dev/md${mdstart}\n\n" + newfs -O2 $mode /dev/md${mdstart} > /dev/null 2>&1 + mount /dev/md${mdstart} ${mntpoint} + + for i in `jot 10`; do + (cd ..;./run.sh disk.cfg) + done + + umount -f ${mntpoint} +done +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/statfs.sh b/test/stress/stress2/misc/statfs.sh new file mode 100755 index 0000000000..825f65a10a --- /dev/null +++ b/test/stress/stress2/misc/statfs.sh @@ -0,0 +1,129 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Regression test for statfs problems with deleting a large number of files + +# $ ./statfs.sh +# Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on +# /dev/ad0s1e 1982798 1782134 42042 98% 4965 254105 2% /tmp +# Free inodes on /tmp: 254105 +# Creating 100000 files... +# Deleting 100000 files... +# Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on +# /dev/ad0s1e 1982798 -284096 2108272 -16% 4965 254105 2% /tmp +# $ umount -f /tmp; mount /tmp +# $ df -i /tmp +# Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on +# /dev/ad0s1e 1982798 1784528 39648 98% 4965 254105 2% /tmp + + +odir=`pwd` +dir=/tmp + +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/statfs.c +cc -o statfs -Wall statfs.c +rm -f statfs.c + +df -i /tmp +./statfs +df -i /tmp + +exit +EOF +/* $FreeBSD$ */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int64_t +inodes(void) +{ + char path[MAXPATHLEN+1]; + struct statfs buf; + + sync(); + if (getcwd(path, sizeof(path)) == NULL) + err(1, "getcwd()"); + + if (statfs(path, &buf) < 0) + err(1, "statfs(%s)", path); + printf("Free inodes on %s: %jd\n", path, buf.f_ffree); + return (buf.f_ffree); +} + +int +main() +{ + int fd, i, j; + int64_t size; + pid_t pid; + char file[128]; + + size = inodes() - 1000; + + if (size > 100000) + size = 100000; + + printf("Creating %jd files...", size); fflush(stdout); + pid = getpid(); + for (j = 0; j < size; j++) { + sprintf(file,"p%06d.%05d", pid, j); + if ((fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0666)) == -1) { + if (errno != EINTR) { + warn("creat(%s)", file); + printf("break out at %d, errno %d\n", j, errno); + break; + } + } + if (fd != -1 && close(fd) == -1) + err(2, "close(%d)", j); + + } + + printf("\nDeleting %jd files...", size); fflush(stdout); + for (i = --j; i >= 0; i--) { + sprintf(file,"p%06d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + } + printf("\n"); + return (0); +} diff --git a/test/stress/stress2/misc/suj.sh b/test/stress/stress2/misc/suj.sh new file mode 100755 index 0000000000..be0903d054 --- /dev/null +++ b/test/stress/stress2/misc/suj.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# +# Copyright (c) 2010 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# SUJ suspfs deadlock seen + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount $mntpoint +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs -U md${mdstart}$part > /dev/null +tunefs -j enable /dev/md${mdstart}$part +mount /dev/md${mdstart}$part $mntpoint + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=20m +(cd ..; ./run.sh rw.cfg) + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/test/stress/stress2/misc/symlink.sh b/test/stress/stress2/misc/symlink.sh new file mode 100755 index 0000000000..3976ad7e24 --- /dev/null +++ b/test/stress/stress2/misc/symlink.sh @@ -0,0 +1,129 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Testing problem with premature disk full problem with symlinks + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +dede $D 1m 1024 || exit 1 + +odir=`pwd` +dir=$mntpoint + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > symlink.c +cc -o symlink -Wall symlink.c +rm -f symlink.c +cd $odir + +mount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} + + +tst() { + cd $dir + df -ik $mntpoint + i=`df -ik $mntpoint | tail -1 | awk '{printf "%d\n", ($7 - 500)/2}'` + [ $i -gt 20000 ] && i=20000 + + for k in `jot 5`; do + for j in `jot 2`; do + /tmp/symlink $i & + done + for j in `jot 2`; do + wait + done + df -ik $mntpoint | tail -1 +# sleep 30 # With this enabled, soft update also works + done + cd $odir +} + +for i in "" "-U"; do + echo "newfs $i /dev/md${mdstart}" + newfs $i /dev/md${mdstart} > /dev/null 2>&1 + mount /dev/md${mdstart} ${mntpoint} + + tst + + umount -f ${mntpoint} +done +mdconfig -d -u $mdstart +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + int i, j; + int64_t size; + pid_t pid; + char file[128]; + + size = atol(argv[1]); + +// printf("Creating %jd symlinks...\n", size); fflush(stdout); + pid = getpid(); + for (j = 0; j < size; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if (symlink("/mnt/not/there", file) == -1) { + if (errno != EINTR) { + warn("symlink(%s)", file); + printf("break out at %d, errno %d\n", j, errno); + break; + } + } + } + +// printf("Deleting %jd files...\n", size); fflush(stdout); + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + } + return (0); +} diff --git a/test/stress/stress2/misc/symlink2.sh b/test/stress/stress2/misc/symlink2.sh new file mode 100755 index 0000000000..698aa1d88f --- /dev/null +++ b/test/stress/stress2/misc/symlink2.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Testing problem with buffer cache inconsistancy + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +dede $D 1m 10 || exit 1 + +odir=`pwd` +dir=$mntpoint + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > symlink2.c +cc -o symlink2 -Wall symlink2.c +rm -f symlink2.c +cd $odir + +mount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} + +for i in "" "-U"; do + echo "newfs $i /dev/md${mdstart}" + newfs $i /dev/md${mdstart} > /dev/null 2>&1 + mount /dev/md${mdstart} $mntpoint + mkdir ${mntpoint}/dir + + /tmp/symlink2 ${mntpoint}/dir/link + + ls -l ${mntpoint}/dir > /dev/null 2>&1 + if [ $? -ne 0 ]; then + set -x + ls -l ${mntpoint}/dir + umount $mntpoint + mount /dev/md${mdstart} $mntpoint + ls -l ${mntpoint}/dir + set +x + fi + + umount -f ${mntpoint} +done +mdconfig -d -u $mdstart +exit +EOF +#include +#include +#include +#include +#include +#include +#include + +static char *path; + +int +main(int argc, char **argv) +{ + int i, n; + pid_t p; + char buf[128]; + + path = argv[1]; + for (i = 0; i < 100; i++) { + if ((p = fork()) == 0) { + if ((n = readlink(path, buf, sizeof(buf) -1)) < 0) { + for (i = 0; i < 60; i++) { + sleep(1); + if ((n = readlink(path, buf, sizeof(buf) -1)) > 0) { + break; + } + } + } + if (n < 0) + err(1, "readlink(%s). %s:%d", path, __FILE__, __LINE__); + exit(0); + } + } + (void) unlink(path); + sleep(2); + if (symlink("1234", path) < 0) + err(1, "symlink(%s, %s)", path, "1234"); + + for (i = 0; i < 100; i++) { + if (wait(&n) == -1) + err(1, "wait(), %s:%d", __FILE__, __LINE__); + } + + return (0); +} diff --git a/test/stress/stress2/misc/syscall.sh b/test/stress/stress2/misc/syscall.sh new file mode 100755 index 0000000000..a5fd553b96 --- /dev/null +++ b/test/stress/stress2/misc/syscall.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test calls with random arguments, in reverse order + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q sysvmsg || kldload sysvmsg +kldstat -v | grep -q sysvsem || kldload sysvsem +kldstat -v | grep -q sysvshm || kldload sysvshm + +kldstat -v | grep -q aio || kldload aio +kldstat -v | grep -q mqueuefs || kldload mqueuefs + +syscall=`grep SYS_MAXSYSCALL /usr/include/sys/syscall.h | awk '{print $NF}'` + +n=$syscall +[ $# -eq 1 ] && n=$1 + +rm -f /tmp/syscall.log +while [ $n -gt 0 ]; do + echo "`date '+%T'` syscall $n" | tee /dev/tty >> /tmp/syscall.log + for i in `jot 5`; do + su ${testuser} -c "sh -c \"../testcases/syscall/syscall -t 30s -i 100 -h -l 100 -k $n\"" + done + n=$((n - 1)) + chflags -R 0 $RUNDIR + rm -rf $RUNDIR +done diff --git a/test/stress/stress2/misc/syscall2.sh b/test/stress/stress2/misc/syscall2.sh new file mode 100755 index 0000000000..054f64ed37 --- /dev/null +++ b/test/stress/stress2/misc/syscall2.sh @@ -0,0 +1,224 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test calls with random arguments, in reverse order +# Variation of the syscall test program. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > syscall2.c +cc -o syscall2 -Wall -I $odir/../include -L $odir/../lib syscall2.c -lstress -lutil +rm -f syscall2.c + +kldstat -v | grep -q sysvmsg || kldload sysvmsg +kldstat -v | grep -q sysvsem || kldload sysvsem +kldstat -v | grep -q sysvshm || kldload sysvshm + +kldstat -v | grep -q aio || kldload aio +kldstat -v | grep -q mqueuefs || kldload mqueuefs + +syscall=`grep SYS_MAXSYSCALL /usr/include/sys/syscall.h | awk '{print $NF}'` + +n=$syscall +[ $# -eq 1 ] && n=$1 + +rm -f /tmp/syscall2.log +while [ $n -gt 0 ]; do + echo "`date '+%T'` syscall $n" | tee /dev/tty >> /tmp/syscall2.log + for i in `jot 5`; do + su ${testuser} -c "sh -c \"/tmp/syscall2 -t 30s -i 100 -h -l 100 -k $n\"" + done + chflags -R 0 $RUNDIR + rm -rf $RUNDIR + n=$((n - 1)) +done +rm -f /tmp/syscall2 +exit +EOF + +/* Call random system calls with random arguments */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path[128]; +static int num; +static int starting_dir = 0; +uint32_t rb[7][10]; + +static int ignore[] = { + SYS_syscall, + SYS_exit, + SYS_fork, + 11, /* 11 is obsolete execv */ + SYS_unmount, + SYS_reboot, + SYS_vfork, + 109, /* 109 is old sigblock */ + 111, /* 111 is old sigsuspend */ + SYS_shutdown, + SYS___syscall, + SYS_rfork, + SYS_sigsuspend, + SYS_mac_syscall, + SYS_sigtimedwait, + SYS_sigwaitinfo, +}; + +int +setup(int nb) +{ + int i; + struct rlimit rl; + + umask(0); + sprintf(path,"%s.%05d", getprogname(), getpid()); + (void)mkdir(path, 0770); + if (chdir(path) == -1) + err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__); + if ((starting_dir = open(".", 0)) < 0) + err(1, "."); + + if (op->argc == 1) { + num = atoi(op->argv[0]); + for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++) + if (num == ignore[i]) { + printf("syscall %d is marked a no test!\n", num); + exit(1); + } + } else { + num = 0; + while (num == 0) { + num = random_int(0, SYS_MAXSYSCALL); + for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++) + if (num == ignore[i]) { + num = 0; + break; + } + } + } + if (op->verbose > 1) + printf("Testing syscall #%d, pid %d\n", num, getpid()); + + /* Multiple parallel core dump may panic the kernel with: + panic: kmem_malloc(184320): kmem_map too small: 84426752 total allocated + */ + rl.rlim_max = rl.rlim_cur = 0; + if (setrlimit(RLIMIT_CORE, &rl) == -1) + warn("setrlimit"); + + setproctitle("#%d", num); + + return (0); +} + +void +cleanup(void) +{ + if (starting_dir != 0) { + if (fchdir(starting_dir) == -1) + err(1, "fchdir()"); + (void)system("find . -type d -exec chmod 777 {} \\;"); + (void)system("find . -type f -exec chmod 666 {} \\;"); + (void)system("find . -delete"); + + if (chdir("..") == -1) + err(1, "chdir(..)"); + if (rmdir(path) == -1) + err(1, "rmdir(%s), %s:%d", path, __FILE__, __LINE__); + } + starting_dir = 0; +} + +void +rainit(void) +{ + int i, j; + + for (i = 0; i < 7; i++) { + for (j = 0; j < 10; j++) { + if (arc4random() % 100 > 20) + rb[i][j] = arc4random(); + else + rb[i][j] = (uint32_t) &rb[i][j]; + } + } +} + +uint32_t +ra(int i) +{ + uint32_t r; + + r = arc4random(); + if ((r & 1) == 0) + r = arc4random(); + else + r = (uint32_t) &rb[i][0]; + + return (r); +} + +int +test(void) +{ + int i; + unsigned int arg1, arg2, arg3, arg4, arg5, arg6, arg7; + + for (i = 0; i < 128; i++) { + rainit(); + arg1 = ra(0); + arg2 = ra(1); + arg3 = ra(2); + arg4 = ra(3); + arg5 = ra(4); + arg6 = ra(5); + arg7 = ra(6); + + if (op->verbose > 3) + printf("%2d : syscall(%3d, %x, %x, %x, %x, %x, %x, %x)\n", + i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + } + + return (0); +} diff --git a/test/stress/stress2/misc/tmpfs.sh b/test/stress/stress2/misc/tmpfs.sh new file mode 100755 index 0000000000..25c3deadb9 --- /dev/null +++ b/test/stress/stress2/misc/tmpfs.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $Id: nfs.sh,v 1.2 2008/02/25 16:31:43 pho Exp $ +# + +# panic: tmpfs_alloc_vp: type 0xc866ce58 0, seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep "$mntpoint" | grep -q tmpfs && umount $mntpoint +mount -t tmpfs tmpfs $mntpoint + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m # Run tests for 10 minutes + +(cd /home/pho/stress2; ./run.sh marcus.cfg) + +umount $mntpoint +mount | grep "$mntpoint" | grep -q tmpfs && umount -f $mntpoint diff --git a/test/stress/stress2/misc/tmpfs2.sh b/test/stress/stress2/misc/tmpfs2.sh new file mode 100755 index 0000000000..af696c9c2f --- /dev/null +++ b/test/stress/stress2/misc/tmpfs2.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $Id: crossmp.sh,v 1.2 2008/02/25 16:31:43 pho Exp $ +# + +# panic: vfs_mount_destroy: nonzero writeopcount, seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +mdstart=$MDSTART # Use md unit numbers from this point +D=$DISKIMAGE + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount | grep "$mntpoint" | grep -q md$m && umount ${mntpoint}$m + done + + # start the parallel tests + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find & + done + + for i in `jot $mounts`; do + wait; wait + done + +else + if [ $1 = find ]; then + for i in `jot 1024`; do + find ${mntpoint}* -type f > /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + for i in `jot 1024`; do + m=$1 + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + mount -t tmpfs tmpfs ${mntpoint}$m + cp -r /usr/include/machine/a* ${mntpoint}$m + while mount | grep -qw $mntpoint$m; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + done + fi +fi diff --git a/test/stress/stress2/misc/tmpfs3.sh b/test/stress/stress2/misc/tmpfs3.sh new file mode 100755 index 0000000000..268a5e669c --- /dev/null +++ b/test/stress/stress2/misc/tmpfs3.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $Id: nfs.sh,v 1.2 2008/02/25 16:31:43 pho Exp $ +# + +# panic: tmpfs_alloc_vp: type 0xc866ce58 0, seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep "$mntpoint" | grep -q tmpfs && umount $mntpoint +mount -t tmpfs tmpfs $mntpoint + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m # Run tests for 10 minutes + +(cd /home/pho/stress2; ./run.sh vfs.cfg) + +umount $mntpoint +mount | grep "$mntpoint" | grep -q tmpfs && umount -f $mntpoint diff --git a/test/stress/stress2/misc/tmpfs4.sh b/test/stress/stress2/misc/tmpfs4.sh new file mode 100755 index 0000000000..2bff3dcba6 --- /dev/null +++ b/test/stress/stress2/misc/tmpfs4.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $Id: nfs.sh,v 1.2 2008/02/25 16:31:43 pho Exp $ +# + +# Regression test from kern/122038 by gprspb mail ru + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep "$mntpoint" | grep -q tmpfs && umount $mntpoint +mount -t tmpfs tmpfs $mntpoint + +for i in `jot 100`; do + mkdir -p /${mntpoint}/1/2 + cd /${mntpoint}/1/2 + rm -rf /${mntpoint}/1 + cd .. 2>&1 | grep -v "cd to" +done + + +umount $mntpoint 2>&1 | grep -v busy +mount | grep "$mntpoint" | grep -q tmpfs && umount -f $mntpoint diff --git a/test/stress/stress2/misc/truncate.sh b/test/stress/stress2/misc/truncate.sh new file mode 100755 index 0000000000..b60fc9ac27 --- /dev/null +++ b/test/stress/stress2/misc/truncate.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test high water mark for freeblks + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > truncate.c +cc -o truncate -Wall -O2 truncate.c +rm -f truncate.c +[ -d $RUNDIR ] || mkdir -p $RUNDIR +cd $RUNDIR + +/tmp/truncate + +rm -f /tmp/truncate +exit 0 +EOF +#include +#include +#include +#include +#include +#include + +#define SIZ 512 +char buf[SIZ]; + +void +test(void) +{ + int fd[10], i, j; + char name[128]; + + for (j = 0; j < 10; j++) { + sprintf(name, "%05d.%05d", getpid(), j); + if ((fd[j] = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) + err(1, name); + unlink(name); + } + + for (i = 0; i < 100000; i++) { + for (j = 0; j < 10; j++) { + if (write(fd[j], buf, 2) != 2) + err(1, "write"); + if (ftruncate(fd[j], 0) == -1) + err(1, "ftruncate"); + } + } + + exit(0); +} +int +main(int argc, char **argv) +{ + int i, status; + + for (i = 0; i < 20; i++) { + if (fork() == 0) + test(); + } + for (i = 0; i < 20; i++) + wait(&status); + + return (0); +} diff --git a/test/stress/stress2/misc/truncate2.sh b/test/stress/stress2/misc/truncate2.sh new file mode 100755 index 0000000000..51a8f61ec0 --- /dev/null +++ b/test/stress/stress2/misc/truncate2.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > truncate2.c +cc -o truncate2 -Wall -O2 truncate2.c +rm -f truncate2.c +[ -d $RUNDIR ] || mkdir -p $RUNDIR +cd $RUNDIR + +/tmp/truncate2 & + +sleep 1 +while ps | grep -v grep | egrep -q "truncate2$"; do + $here/../testcases/swap/swap -t 2m -i 20 +done + +rm -f /tmp/truncate2 +exit 0 +EOF +#include +#include +#include +#include +#include +#include + +#define SIZ 512 +char buf[SIZ]; + +void +test(void) +{ + int fd[10], i, j; + char name[128]; + off_t len; + + for (j = 0; j < 10; j++) { + sprintf(name, "%05d.%05d", getpid(), j); + fd[j] = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666); + if (fd[j] == -1) + err(1, name); + unlink(name); + } + + for (i = 0; i < 100; i++) { + for (j = 0; j < 10; j++) { + if (write(fd[j], buf, 2) != 2) + err(1, "write"); + len = arc4random() % 1024 * 1024; + if (ftruncate(fd[j], len) == -1) + err(1, "ftruncate"); + } + } + + exit(0); +} +int +main(int argc, char **argv) +{ + int i, status; + + for (i = 0; i < 20; i++) { + if (fork() == 0) + test(); + } + for (i = 0; i < 20; i++) + wait(&status); + + return (0); +} diff --git a/test/stress/stress2/misc/ucom.sh b/test/stress/stress2/misc/ucom.sh new file mode 100755 index 0000000000..4ea67748a1 --- /dev/null +++ b/test/stress/stress2/misc/ucom.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test disconnecting busy UCOM USB serial dongle + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +tst () { + for i in `jot 10`; do + [ -r /dev/cuaU0 ] && break + sleep 1 + done + echo $1 + (eval "$@")& + sleep 10 + ps | grep -qw $! && kill $! +} + +if [ $# -eq 0 ]; then + ( + while true; do + pstat -t > /dev/null + sleep 1 + done + ) & + pid=$! +fi + + +tst "cat < /dev/ttyU0" +tst "cat < /dev/cuaU0" + +tst "cu -l /dev/cuaU0" +tst "cu -l /dev/ttyU0" + +tst "stty -a -f /dev/ttyU0" +tst "stty -a < /dev/ttyU0" +tst "stty -f /dev/ttyU0 -a" +tst "tail -F /dev/ttyU0" +tst "tail /dev/ttyU0" + +[ ! -z "$pid" ] && kill $pid diff --git a/test/stress/stress2/misc/umount.sh b/test/stress/stress2/misc/umount.sh new file mode 100755 index 0000000000..b6e6ae8c97 --- /dev/null +++ b/test/stress/stress2/misc/umount.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test "umount" + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +dede $D 1m 110 || exit 1 + +mount | grep "$mntpoint" | grep md${mdstart}${part} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs md${mdstart}${part} +mount /dev/md${mdstart}${part} $mntpoint +export RUNDIR=$mntpoint/stressX +export runRUNTIME=3m # Run tests for three minutes +(cd /home/pho/stress2; ./run.sh vfs.cfg) +umount $mntpoint +mdconfig -d -u ${mdstart} +rm -f $D diff --git a/test/stress/stress2/misc/umountf.sh b/test/stress/stress2/misc/umountf.sh new file mode 100755 index 0000000000..49f75cbb83 --- /dev/null +++ b/test/stress/stress2/misc/umountf.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test problems with "umount -f" + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +dede $D 1m 110 || exit 1 + +mount | grep "$mntpoint" | grep md${mdstart}${part} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs md${mdstart}${part} +mount /dev/md${mdstart}${part} $mntpoint + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=2m +cd /home/pho/stress2; ./run.sh vfs.cfg & +pid=$! + +sleep 30 + +umount -f $mntpoint +mdconfig -d -u $mdstart +rm -f $D + +while ps | egrep "testcases|swap|mkdir|creat" | grep -vq grep; do + ps | egrep "testcases|swap|mkdir|creat" | grep -v grep | awk '{print $1}' | xargs kill + sleep 1 +done diff --git a/test/stress/stress2/misc/umountf2.sh b/test/stress/stress2/misc/umountf2.sh new file mode 100755 index 0000000000..7740068412 --- /dev/null +++ b/test/stress/stress2/misc/umountf2.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Test scenario by kris@freebsd.org + +# Test problems with "umount -f and fsx. Results in a "KDB: enter: watchdog timeout" + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +fsxc=`find / -name fsx.c | tail -1` +[ -z "fsxc" ] && exit + +cc -o /tmp/fsx $fsxc + +. ../default.cfg + +D=$diskimage +dede $D 1m 1k || exit 1 + +mount | grep "$mntpoint" | grep md${mdstart}${part} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs md${mdstart}${part} > /dev/null 2>&1 +mount /dev/md${mdstart}${part} $mntpoint +df -ih $mntpoint +sleep 5 +for i in `jot 100`; do + /tmp/fsx -S $i -q ${mntpoint}/xxx$i & +done +sleep 30 +umount -f $mntpoint& +sleep 300 +killall fsx +sleep 5 +ls -l ${mntpoint} +mdconfig -d -u $mdstart +rm -f $D +ls -l $mntpoint diff --git a/test/stress/stress2/misc/umountf3.sh b/test/stress/stress2/misc/umountf3.sh new file mode 100755 index 0000000000..596ded0317 --- /dev/null +++ b/test/stress/stress2/misc/umountf3.sh @@ -0,0 +1,122 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Demonstrate livelock with "umount -f" seen both with UFS and MSDOS + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +dede $D 1m 1k || exit 1 + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > umountf3.c +cc -o umountf3 -Wall umountf3.c +rm -f umountf3.c +cd $odir + + +mount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint +mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} + +mdconfig -a -t vnode -f $D -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs md${mdstart}${part} > /dev/null 2>&1 +mount /dev/md${mdstart}${part} $mntpoint +#newfs_msdos -F 32 -b 8192 /dev/md${mdstart}a +#mount -t msdosfs /dev/md${mdstart}a $mntpoint +export RUNDIR=$mntpoint/stressX +for i in `jot 25`; do + (cd /$mntpoint; /tmp/umountf3) & +done +sleep $((4 * 60)) +echo "umount -f $mntpoint" +umount -f $mntpoint +mdconfig -d -u $mdstart +rm -f $D /tmp/umountf3 +exit +EOF + +#include +#include +#include +#include +#include +#include +#include + +static unsigned long size = 1024 * 1024 * 2; + +int +main(int argc, char **argv) +{ + int buf[1024], index, to, n; + int fd; + char file[128]; + + + sprintf(file,"p%06d", getpid()); + if ((fd = open(file, O_CREAT | O_RDWR, 0666)) == -1) + err(1, "creat(%s)", file); + + to = sizeof(buf); + for (;;) { + index = 0; + while (index < size) { + if (index + to > size) + to = size - index; + index += to; + if (write(fd, buf, to) != to) + err(1, "write(%s), %s:%d", file, __FILE__, __LINE__); + } + + if (lseek(fd, 0, 0) == -1) + err(1, "lseek"); + index = 0; + while (index < size) { + if (index + to > size) + to = size - index; + if ((n = read(fd, buf, to)) != to) + err(1, "rw read(%d, %d, %d). %s.%d", n, to, index, __FILE__, __LINE__); + index += to; + } + if (lseek(fd, 0, 0) == -1) + err(1, "lseek"); + } + + if (close(fd) == -1) + err(1, "close(%s), %s:%d", file, __FILE__, __LINE__); + if (unlink(file) == -1) + err(1, "unlink(%s), %s:%d", file, __FILE__, __LINE__); + return (0); +} diff --git a/test/stress/stress2/misc/umountf4.sh b/test/stress/stress2/misc/umountf4.sh new file mode 100755 index 0000000000..d7c57ea77d --- /dev/null +++ b/test/stress/stress2/misc/umountf4.sh @@ -0,0 +1,89 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Found: Fatal trap 12: page fault while in kernel mode + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +mdstart=$mdstart # Use md unit numbers from this point +D=$diskimage + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount | grep "$mntpoint" | grep -q md$m && umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + dede $D$m 1m 10 + mdconfig -a -t vnode -f $D$m -u $m + bsdlabel -w md$m auto + newfs md${m}${part} > /dev/null 2>&1 + done + + # start the parallel tests + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find & + done + + for i in `jot $mounts`; do + wait; wait + done + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + mdconfig -d -u $m + rm -f $D$m + done + +else + if [ $1 = find ]; then + for i in `jot 100`; do + find ${mntpoint}* -type f > /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + for i in `jot 100`; do + m=$1 + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + mount $opt /dev/md${m}${part} ${mntpoint}$m + cp -r /usr/include/machine/a* ${mntpoint}$m + while mount | grep -qw $mntpoint$m; do + umount -f ${mntpoint}$m > /dev/null 2>&1 + done + done + fi +fi diff --git a/test/stress/stress2/misc/union.sh b/test/stress/stress2/misc/union.sh new file mode 100755 index 0000000000..c02dac6e6a --- /dev/null +++ b/test/stress/stress2/misc/union.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Simple union test scenario + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +u1=$mdstart +u2=$((u1 + 1)) +[ -d mp1 ] || mkdir mp1 + +mount | grep -q /dev/md${u2}$part && umount -f /dev/md${u2}$part +mount | grep -q /dev/md${u1}$part && umount -f /dev/md${u1}$part +mdconfig -l | grep -q md${u2} && mdconfig -d -u $u2 +mdconfig -l | grep -q md${u1} && mdconfig -d -u $u1 + +mdconfig -s 256m -u $u1 +bsdlabel -w md$u1 auto +newfs md${u1}${part} > /dev/null + +mdconfig -s 256m -u $u2 +bsdlabel -w md$u2 auto +newfs md${u2}${part} > /dev/null + +mount -o ro /dev/md${u1}$part mp1 +mount -o union /dev/md${u2}$part mp1 + +export RUNDIR=`pwd`/mp1/stressX +export runRUNTIME=10m +(cd ..; ./run.sh marcus.cfg) + +umount /dev/md${u2}$part +umount /dev/md${u1}$part + +mount | grep -q /dev/md${u2}$part && umount -f /dev/md${u2}$part +mount | grep -q /dev/md${u1}$part && umount -f /dev/md${u1}$part + +mdconfig -d -u $u2 +mdconfig -d -u $u1 + +rm -rf mp1 diff --git a/test/stress/stress2/misc/unionfs.sh b/test/stress/stress2/misc/unionfs.sh new file mode 100755 index 0000000000..68f7c5ebde --- /dev/null +++ b/test/stress/stress2/misc/unionfs.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Causes this: panic: mutex Giant not owned at ../../../kern/vfs_subr.c:1968 +# with a kernel compiled with "options QUOTA" + +D=/usr/tmp/diskimage +truncate -s 256M $D + +mount | grep "/mnt" | grep md0c > /dev/null && umount /mnt +mdconfig -l | grep md0 > /dev/null && mdconfig -d -u 0 + +mdconfig -a -t vnode -f $D -u 0 +bsdlabel -w md0 auto +newfs -U md0c > /dev/null +mount /dev/md0c /mnt +mount -t unionfs -o noatime /mnt /tmp +export RUNDIR=/tmp/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd /home/pho/stress2; ./run.sh disk.cfg) +mount | grep "/mnt" | grep md0c > /dev/null && umount /mnt +mount | grep "/mnt" | grep md0c > /dev/null && umount -f /mnt +mdconfig -d -u 0 +rm -f $D diff --git a/test/stress/stress2/misc/unionfs2.sh b/test/stress/stress2/misc/unionfs2.sh new file mode 100755 index 0000000000..5960082d95 --- /dev/null +++ b/test/stress/stress2/misc/unionfs2.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +saved=`sysctl vfs.lookup_shared | awk '{print $NF}'` +for i in 1 0; do + sysctl vfs.lookup_shared=$i + [ -d /var/tmp/unionfs ] || mkdir -p /var/tmp/unionfs + mount_unionfs /var/tmp/unionfs /tmp/stressX + + export RUNDIR=/var/tmp/unionfs/stressX + export runRUNTIME=10m # Run tests for 10 minutes + (cd /home/pho/stress2; ./run.sh disk.cfg) + false + while mount | grep -q /unionfs; do + umount /tmp/stressX > /dev/null 2>&1 + done + rm -rf /var/tmp/unionfs +done +sysctl vfs.lookup_shared=$saved diff --git a/test/stress/stress2/misc/unionfs3.sh b/test/stress/stress2/misc/unionfs3.sh new file mode 100755 index 0000000000..f3cd77b492 --- /dev/null +++ b/test/stress/stress2/misc/unionfs3.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test with interchanged arguments to mount_unionfs +# Causes page fault in vfs_mount.c:1975 + +D=/usr/tmp/diskimage +truncate -s 256M $D + +mount | grep "/mnt" | grep md0c > /dev/null && umount /mnt +mdconfig -l | grep md0 > /dev/null && mdconfig -d -u 0 + +mdconfig -a -t vnode -f $D -u 0 +bsdlabel -w md0 auto +newfs -U md0c > /dev/null +mount /dev/md0c /mnt +mount -t unionfs -o noatime /tmp /mnt +umount -f /tmp # panic +mount /tmp +mount | grep "/mnt" | grep md0c > /dev/null && umount /mnt +mount | grep "/mnt" | grep md0c > /dev/null && umount -f /mnt +mdconfig -d -u 0 +rm -f $D diff --git a/test/stress/stress2/misc/zfs.sh b/test/stress/stress2/misc/zfs.sh new file mode 100755 index 0000000000..6c91fc2967 --- /dev/null +++ b/test/stress/stress2/misc/zfs.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Simple zfs raidz test scenario + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q zfs.ko || kldload zfs.ko + +u1=$mdstart +u2=$((u1 + 1)) +u3=$((u2 + 1)) + +mdconfig -l | grep -q md${u1} && mdconfig -d -u $u1 +mdconfig -l | grep -q md${u2} && mdconfig -d -u $u2 +mdconfig -l | grep -q md${u3} && mdconfig -d -u $u3 + +mdconfig -s 512m -u $u1 +mdconfig -s 512m -u $u2 +mdconfig -s 512m -u $u3 + +zpool create tank raidz md$u1 md$u2 md$u3 +zfs create tank/test + +export RUNDIR=/tank/test/stressX +export runRUNTIME=10m +(cd ..; ./run.sh marcus.cfg) + +zfs destroy -r tank +zpool destroy tank + +mdconfig -d -u $u1 +mdconfig -d -u $u2 +mdconfig -d -u $u3 diff --git a/test/stress/stress2/misc/zfs2.sh b/test/stress/stress2/misc/zfs2.sh new file mode 100755 index 0000000000..82414e5d5c --- /dev/null +++ b/test/stress/stress2/misc/zfs2.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Simple zfs mirror test scenario + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q zfs.ko || kldload zfs.ko + +d1=${diskimage}.1 +d2=${diskimage}.2 + +dd if=/dev/zero of=$d1 bs=1m count=1k 2>&1 | egrep -v "records|transferred" +dd if=/dev/zero of=$d2 bs=1m count=1k 2>&1 | egrep -v "records|transferred" + +u1=$mdstart +u2=$((u1 + 1)) + +mdconfig -l | grep -q md${u1} && mdconfig -d -u $u1 +mdconfig -l | grep -q md${u2} && mdconfig -d -u $u2 + +mdconfig -a -t vnode -f $d1 -u $u1 +mdconfig -a -t vnode -f $d2 -u $u2 + +zpool create tank mirror md$u1 md$u2 + +export RUNDIR=/tank/stressX +export runRUNTIME=10m +(cd ..; ./run.sh marcus.cfg) + +zfs destroy -r tank +zpool destroy tank + +mdconfig -d -u $u1 +mdconfig -d -u $u2 + +rm -rf $d1 $d2 diff --git a/test/stress/stress2/misc/zfs3.sh b/test/stress/stress2/misc/zfs3.sh new file mode 100755 index 0000000000..aac53df949 --- /dev/null +++ b/test/stress/stress2/misc/zfs3.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Simple zfs snapshot test scenario + +# page fault from fs/zfs/dbuf.c:1807 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q zfs.ko || kldload zfs.ko + +d1=${diskimage}.1 +d2=${diskimage}.2 + +dd if=/dev/zero of=$d1 bs=1m count=1k 2>&1 | egrep -v "records|transferred" +dd if=/dev/zero of=$d2 bs=1m count=1k 2>&1 | egrep -v "records|transferred" + +u1=$mdstart +u2=$((u1 + 1)) + +mdconfig -l | grep -q md${u1} && mdconfig -d -u $u1 +mdconfig -l | grep -q md${u2} && mdconfig -d -u $u2 + +mdconfig -a -t vnode -f $d1 -u $u1 +mdconfig -a -t vnode -f $d2 -u $u2 + +zpool create tank md$u1 md$u2 +zfs create tank/test +zfs set quota=800m tank/test +zfs snapshot tank/test@snap1 + +export RUNDIR=/tank/test/stressX +export runRUNTIME=10m +(cd ..; ./run.sh marcus.cfg) + +zfs rollback tank/test@snap1 +zfs destroy tank/test@snap1 + +zfs destroy -r tank +zpool destroy tank + +mdconfig -d -u $u1 +mdconfig -d -u $u2 + +rm -rf $d1 $d2 diff --git a/test/stress/stress2/misc/zfs4.sh b/test/stress/stress2/misc/zfs4.sh new file mode 100755 index 0000000000..8d9848ba27 --- /dev/null +++ b/test/stress/stress2/misc/zfs4.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Simple zfs snapshot test scenario + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q zfs.ko || kldload zfs.ko + +d1=${diskimage}.1 +d2=${diskimage}.2 + +dd if=/dev/zero of=$d1 bs=1m count=1k 2>&1 | egrep -v "records|transferred" +dd if=/dev/zero of=$d2 bs=1m count=1k 2>&1 | egrep -v "records|transferred" + +u1=$mdstart +u2=$((u1 + 1)) + +mdconfig -l | grep -q md${u1} && mdconfig -d -u $u1 +mdconfig -l | grep -q md${u2} && mdconfig -d -u $u2 + +mdconfig -a -t vnode -f $d1 -u $u1 +mdconfig -a -t vnode -f $d2 -u $u2 + +zpool create tank md$u1 md$u2 +zfs create tank/test +zfs set quota=100m tank/test +zfs set snapdir=visible tank/test + +export RUNDIR=/tank/test/stressX +export runRUNTIME=10m +(cd ..; ./run.sh marcus.cfg) & + +for i in `jot 20`; do + zfs snapshot tank/test@snap$i +done +for i in `jot 20`; do + zfs destroy tank/test@snap$i +done +wait + +zfs destroy -r tank +zpool destroy tank + +mdconfig -d -u $u1 +mdconfig -d -u $u2 + +rm -rf $d1 $d2 diff --git a/test/stress/stress2/misc/zfs5.sh b/test/stress/stress2/misc/zfs5.sh new file mode 100755 index 0000000000..b3f5a15e17 --- /dev/null +++ b/test/stress/stress2/misc/zfs5.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# +# Copyright (c) 2009 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Simple zfs test of vdev as a file and snapshot clones + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q zfs.ko || kldload zfs.ko + +d1=${diskimage}.1 +d2=${diskimage}.2 + +dd if=/dev/zero of=$d1 bs=1m count=1k 2>&1 | egrep -v "records|transferred" +dd if=/dev/zero of=$d2 bs=1m count=1k 2>&1 | egrep -v "records|transferred" + +zpool create tank $d1 $d2 +zfs create tank/test +zfs set quota=100m tank/test + +export RUNDIR=/tank/test/stressX +export runRUNTIME=10m +(cd ..; ./run.sh vfs.cfg) & + +for i in `jot 20`; do + zfs snapshot tank/test@snap$i + zfs clone tank/test@snap$i tank/snap$i +done +for i in `jot 20`; do + zfs destroy tank/snap$i + zfs destroy tank/test@snap$i +done +wait + +zfs destroy -r tank +zpool destroy tank + +rm -rf $d1 $d2 diff --git a/test/stress/stress2/mkdir.cfg b/test/stress/stress2/mkdir.cfg new file mode 100644 index 0000000000..45d5153d85 --- /dev/null +++ b/test/stress/stress2/mkdir.cfg @@ -0,0 +1,11 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export TESTPROGS="testcases/mkdir/mkdir" +export mkdirNODELAY=1 +export mkdirLOAD=100 +export mkdirRUNTIME=2m diff --git a/test/stress/stress2/mkfifo.cfg b/test/stress/stress2/mkfifo.cfg new file mode 100644 index 0000000000..978bd1df2a --- /dev/null +++ b/test/stress/stress2/mkfifo.cfg @@ -0,0 +1,10 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export TESTPROGS="testcases/mkfifo/mkfifo testcases/swap/swap" +export mkfifoNODELAY=1 +export mkfifoLOAD=100 diff --git a/test/stress/stress2/norw.cfg b/test/stress/stress2/norw.cfg new file mode 100644 index 0000000000..969da9ef9c --- /dev/null +++ b/test/stress/stress2/norw.cfg @@ -0,0 +1,8 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export rwLOAD=0 diff --git a/test/stress/stress2/noswap.cfg b/test/stress/stress2/noswap.cfg new file mode 100644 index 0000000000..cb93966674 --- /dev/null +++ b/test/stress/stress2/noswap.cfg @@ -0,0 +1,8 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export swapLOAD=0 diff --git a/test/stress/stress2/orangutan.netperf.freebsd.org b/test/stress/stress2/orangutan.netperf.freebsd.org new file mode 100644 index 0000000000..ccbdbd65cb --- /dev/null +++ b/test/stress/stress2/orangutan.netperf.freebsd.org @@ -0,0 +1,17 @@ +# $FreeBSD$ + +# Configuration needed for the orangutan test box + +RUNDIR=/m2/stressX +KBLOCKS=`df -ik $RUNDIR | tail -1 | awk '{print $4}` +INODES=`df -ik $RUNDIR | tail -1 | awk '{print $7}` + +BLASTHOST=127.0.0.1 + +DISKIMAGE=/m2/diskimage # Location of 1G disk image +MNTPOINT=/m2 # Disk image mount point +TESTUSER=test # Name of non root test user +MDSTART=5 # Start of free md units + +TZ=Europe/Copenhagen; export TZ +SHELL=/bin/sh diff --git a/test/stress/stress2/pty.cfg b/test/stress/stress2/pty.cfg new file mode 100644 index 0000000000..a776e7ad39 --- /dev/null +++ b/test/stress/stress2/pty.cfg @@ -0,0 +1,10 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export TESTPROGS="testcases/pty/pty" +export ptyNODELAY=1 +export ptyLOAD=100 diff --git a/test/stress/stress2/run.sh b/test/stress/stress2/run.sh new file mode 100755 index 0000000000..3c53fb5f85 --- /dev/null +++ b/test/stress/stress2/run.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Run 1) with no argument: the default test cases +# 2) with the "-a" arguments all the *.cfg test variations +# 3) with one argument: that specific test case + +while getopts a name; do + case $name in + a) aflag=1;; + ?) printf "Usage: %s: [-a] [arg]\n" $0 + exit 2;; + esac +done +shift $(($OPTIND - 1)) + +. ./default.cfg +if [ ! -z "$aflag" ]; then + export runRUNTIME=5m + t1=`date '+%s'` + while true;do + for i in `ls *.cfg | grep -v default`; do + t2=`date '+%s'` +# e=` date -u -j -f '%s' '+%T' $((t2 - t1))` +# echo "`date '+%Y%m%d %T'` $i, elapsed $e" | tee /dev/tty >> /tmp/all.log + echo "`date '+%Y%m%d %T'` $i, elapsed $((t2 - t1))s" | tee /dev/tty >> /tmp/all.log + logger "Starting test $i" + $0 $i + done + [ "`id -un`" = pho ] && ipcs | \ + awk '$5 ~/pho/ && $6 ~/pho/ {print "-" $1,$2}' | xargs ipcrm + done +else + CONFIG=./default.cfg + if [ $# -eq 1 ]; then + [ ! -r $1 ] && echo "$0: $1 not found!" && exit 1 + CONFIG=$1 + fi + . $CONFIG + + [ -z "$RUNDIR" ] && echo "$0: RUNDIR is unset!" && exit 1 + [ `basename $RUNDIR` != stressX ] && \ + echo "$0: Basename of RUNDIR must be stressX!" && exit 2 + [ -d "$RUNDIR" ] && (cd $RUNDIR && find . -delete) + + [ -z "$EXCLUDETESTS" ] && EXCLUDETESTS=DuMmY + + [ -z "$TESTPROGS" ] && \ + TESTPROGS=`find testcases/ -perm -1 -type f | egrep -v "/run/|$EXCLUDETESTS"` + #LD_PRELOAD=/usr/local/lib/libefence.so.0 ./testcases/run/run $TESTPROGS + ./testcases/run/run $TESTPROGS +fi diff --git a/test/stress/stress2/rw.cfg b/test/stress/stress2/rw.cfg new file mode 100644 index 0000000000..8e5720c6fe --- /dev/null +++ b/test/stress/stress2/rw.cfg @@ -0,0 +1,10 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export TESTPROGS="testcases/rw/rw" +export rwNODELAY=1 +export rwLOAD=100 diff --git a/test/stress/stress2/syscall.cfg b/test/stress/stress2/syscall.cfg new file mode 100644 index 0000000000..5f45a80f8a --- /dev/null +++ b/test/stress/stress2/syscall.cfg @@ -0,0 +1,13 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export RUNTIME=15s +export TESTPROGS="testcases/swap/swap testcases/syscall/syscall" + +export syscallKILL=1 +export syscallNODELAY=1 +export syscallLOAD=100 diff --git a/test/stress/stress2/sysctl.cfg b/test/stress/stress2/sysctl.cfg new file mode 100644 index 0000000000..4030ff090d --- /dev/null +++ b/test/stress/stress2/sysctl.cfg @@ -0,0 +1,14 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export RUNTIME=15s +export TESTPROGS="testcases/swap/swap testcases/sysctl/sysctl testcases/mmap/mmap" + +export sysctlKILL=1 +export sysctlNODELAY=1 +export sysctlLOAD=100 +export mmapLOAD=100 diff --git a/test/stress/stress2/testcases/Makefile b/test/stress/stress2/testcases/Makefile new file mode 100644 index 0000000000..8c537c36ac --- /dev/null +++ b/test/stress/stress2/testcases/Makefile @@ -0,0 +1,29 @@ +# $FreeBSD$ + +SUBDIR= \ +badcode \ +creat \ +fts \ +link \ +lockf \ +lockf2 \ +mkdir \ +mkfifo \ +mmap \ +openat \ +pty \ +rename \ +run \ +rw \ +shm \ +socket \ +swap \ +symlink \ +syscall \ +sysctl \ +tcp \ +thr1 \ +thr2 \ +udp + +.include diff --git a/test/stress/stress2/testcases/Makefile.inc b/test/stress/stress2/testcases/Makefile.inc new file mode 100644 index 0000000000..200a353c5d --- /dev/null +++ b/test/stress/stress2/testcases/Makefile.inc @@ -0,0 +1,8 @@ +# $FreeBSD$ + +NO_MAN= +NO_OBJ= noobj +LDADD+= -L../../lib -lstress -lutil +DPADD+= ../../lib/libstress.a +CFLAGS =-g -Wall -I../../include -I../include +NOMAN= sorry diff --git a/test/stress/stress2/testcases/README b/test/stress/stress2/testcases/README new file mode 100644 index 0000000000..2a025c17e7 --- /dev/null +++ b/test/stress/stress2/testcases/README @@ -0,0 +1,11 @@ +$FreeBSD$ + +All test programs must implement these three procedures: + +int setup(int nb) +void cleanup(void) +int test(void) + +The setup() procedure is called once before test() is called multiple times +until timeout. After timeout cleanup() is called. +test() should periodically test the global variable done_testing and return. diff --git a/test/stress/stress2/testcases/badcode/Makefile b/test/stress/stress2/testcases/badcode/Makefile new file mode 100644 index 0000000000..8abcbb90a7 --- /dev/null +++ b/test/stress/stress2/testcases/badcode/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG= badcode + +.include diff --git a/test/stress/stress2/testcases/badcode/badcode.c b/test/stress/stress2/testcases/badcode/badcode.c new file mode 100644 index 0000000000..2974ffa783 --- /dev/null +++ b/test/stress/stress2/testcases/badcode/badcode.c @@ -0,0 +1,121 @@ +/* + * COPYRIGHT (c) 1990 BY * + * GEORGE J. CARRETTE, CONCORD, MASSACHUSETTS. * + * ALL RIGHTS RESERVED * + +Permission to use, copy, modify, distribute and sell this software +and its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all copies +and that both that copyright notice and this permission notice appear +in supporting documentation, and that the name of the author +not be used in advertising or publicity pertaining to distribution +of the software without specific, written prior permission. + +THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +HE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +This code is based on crashme.c + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +#define BUFS 64 + +char buf [BUFS]; +pid_t pid; + +void (*sub)(); + +void +proto(void) { + int i = 2; + printf("Hello, world (%d)\n", i); + return; +} + +void +alter(void) { /* Change one byte in the code */ + int i; + i = random() % BUFS; + buf[i] = random() & 0xff; +} + +void +hand(int i) { /* alarm handler */ + if (pid != 0) { + kill(pid, SIGHUP); + kill(pid, SIGKILL); + } + exit(1); +} + +int +setup(int nb) +{ + return (0); +} + +void +cleanup(void) +{ +} + +int +test(void) +{ + pid_t pid; + int i, status; + + for (i = 0; i < 512; i++) { + if (i % 10 == 0) + bcopy(proto, buf, BUFS); + alter(); + + if ((pid = fork()) == 0) { + signal(SIGALRM, hand); +#if 0 + signal(SIGILL, hand); + signal(SIGFPE, hand); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + signal(SIGURG, hand); + signal(SIGSYS, hand); + signal(SIGTRAP, hand); +#endif + alarm(2); + + (*sub)(); + + exit(EXIT_SUCCESS); + + } else if (pid > 0) { + signal(SIGALRM, hand); + alarm(3); + if (waitpid(pid, &status, 0) == -1) + warn("waitpid(%d)", pid); + alarm(0); + kill(pid, SIGINT); + } else + err(1, "fork(), %s:%d", __FILE__, __LINE__); + } + + return (0); +} diff --git a/test/stress/stress2/testcases/creat/Makefile b/test/stress/stress2/testcases/creat/Makefile new file mode 100644 index 0000000000..0cac1bdd78 --- /dev/null +++ b/test/stress/stress2/testcases/creat/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=creat + +.include diff --git a/test/stress/stress2/testcases/creat/creat.c b/test/stress/stress2/testcases/creat/creat.c new file mode 100644 index 0000000000..236eb87a7e --- /dev/null +++ b/test/stress/stress2/testcases/creat/creat.c @@ -0,0 +1,140 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path[128]; +static unsigned long size; + +int +setup(int nb) +{ + int pct; + int64_t in; + int64_t bl; + int64_t reserve_in; + int64_t reserve_bl; + + + umask(0); + path[0] = 0; + if (nb == 0) { + getdf(&bl, &in); + size = in / op->incarnations; + + pct = 90; + if (op->hog == 0) + pct = random_int(1, 90); + size = size / 100 * pct + 1; + + if (size > 20000) + size = 20000; /* arbitrary limit number of files pr. dir */ + if (size > 1000) + size = 1000; /* XXX Soft Update */ + + /* Resource requirements: */ + while (size > 0) { + reserve_in = 1 * size * op->incarnations + size; + reserve_bl = 29 * size * op->incarnations; +// printf("size = %lu, reserve(%jd, %jd)\n", size, reserve_bl/1024, reserve_in); + if (reserve_bl <= bl && reserve_in <= in) + break; + size--; + } + if (size == 0) + reserve_bl = reserve_in = 0; + + if (op->verbose > 1) + printf("creat(size=%lu, incarnations=%d). Free(%jdk, %jd), reserve(%jdk, %jd)\n", + size, op->incarnations, bl/1024, in, reserve_bl/1024, reserve_in); + reservedf(reserve_bl, reserve_in); + putval(size); + } else { + size = getval(); + } + + if (size == 0) + exit(1); + sprintf(path,"%s.%05d", getprogname(), getpid()); + if (mkdir(path, 0770) < 0) + err(1, "mkdir(%s), %s:%d", path, __FILE__, __LINE__); + + if (chdir(path) == -1) + err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__); + + return (0); +} + +void +cleanup(void) +{ + (void)chdir(".."); + if (path[0] != 0 && rmdir(path) == -1) { + warn("rmdir(%s), %s:%d", path, __FILE__, __LINE__); + } +} + +int +test(void) +{ + int fd, i, j; + pid_t pid; + char file[128]; + + pid = getpid(); + for (j = 0; j < size && done_testing == 0; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if ((fd = creat(file, 0660)) == -1) { + if (errno != EINTR) { + warn("creat(%s). %s:%d", file, __FILE__, __LINE__); + break; + } + } + if (fd != -1 && close(fd) == -1) + err(2, "close(%d)", j); + + } + + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + } + + return (0); +} diff --git a/test/stress/stress2/testcases/fts/Makefile b/test/stress/stress2/testcases/fts/Makefile new file mode 100644 index 0000000000..9b29d27cd6 --- /dev/null +++ b/test/stress/stress2/testcases/fts/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG= fts + +.include diff --git a/test/stress/stress2/testcases/fts/fts.c b/test/stress/stress2/testcases/fts/fts.c new file mode 100644 index 0000000000..80750cce2d --- /dev/null +++ b/test/stress/stress2/testcases/fts/fts.c @@ -0,0 +1,103 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Directory scan */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +int +setup(int nb) +{ + return (0); +} + +void +cleanup(void) +{ +} + +int +test(void) +{ + + FTS *fts; + FTSENT *p; + int ftsoptions; + char *args[2]; + + ftsoptions = 0; + args[0] = "."; + args[1] = 0; + + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + if (op->verbose > 1) + (void) printf("%s\n", p->fts_path); + switch (p->fts_info) { + case FTS_F: /* Ignore. */ + break; + case FTS_D: /* Ignore. */ + break; + case FTS_DP: + break; + case FTS_DC: /* Ignore. */ + break; + case FTS_SL: /* Ignore. */ + break; + case FTS_DNR: /* Warn, continue. */ + case FTS_ERR: + case FTS_NS: + case FTS_DEFAULT: + if (op->verbose > 1) + warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); + break; + default: + printf("%s: default, %d\n", getprogname(), p->fts_info); + break; + } + } + + if (errno != 0 && errno != ENOENT) + err(1, "fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + + return (0); +} diff --git a/test/stress/stress2/testcases/link/Makefile b/test/stress/stress2/testcases/link/Makefile new file mode 100644 index 0000000000..a466747f91 --- /dev/null +++ b/test/stress/stress2/testcases/link/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=link + +.include diff --git a/test/stress/stress2/testcases/link/link.c b/test/stress/stress2/testcases/link/link.c new file mode 100644 index 0000000000..fba4083045 --- /dev/null +++ b/test/stress/stress2/testcases/link/link.c @@ -0,0 +1,147 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path[128]; +static unsigned long size; + +int +setup(int nb) +{ + int pct; + int64_t in; + int64_t bl; + int64_t reserve_in; + int64_t reserve_bl; + + umask(0); + path[0] = 0; + if (nb == 0) { + getdf(&bl, &in); + size = in / op->incarnations; + + pct = 90; + if (op->hog == 0) + pct = random_int(1, 90); + size = size / 100 * pct + 1; + + if (size > 20000 && op->hog == 0) + size = 20000; /* arbitrary limit number of files pr. dir */ + if (size > LINK_MAX) + size = LINK_MAX; + + + /* Resource requirements: */ + reserve_in = 2 * op->incarnations + 1; + reserve_bl = 26 * size * op->incarnations; + if (reserve_bl > bl) + size = bl / 26 * op->incarnations; + if (reserve_in > in) + size = reserve_in = reserve_bl = 0; + + if (op->verbose > 1) + printf("link(size=%lu, incarnations=%d). Free(%jdk, %jd), reserve(%jdk, %jd)\n", + size, op->incarnations, bl/1024, in, reserve_bl/1024, reserve_in); + reservedf(reserve_bl, reserve_in); + putval(size); + } else { + size = getval(); + } + if (size == 0) + exit (1); + + sprintf(path,"%s.%05d", getprogname(), getpid()); + if (mkdir(path, 0770) < 0) + err(1, "mkdir(%s), %s:%d", path, __FILE__, __LINE__); + + if (chdir(path) == -1) + err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__); + + return (0); +} + +void +cleanup(void) +{ + (void)chdir(".."); + if (path[0] != 0 && rmdir(path) == -1) + warn("rmdir(%s), %s:%d", path, __FILE__, __LINE__); +} + +int +test(void) +{ + int fd, i, j; + pid_t pid; + char file[128]; + char lfile[128]; + + pid = getpid(); + for (j = 0; j < size && done_testing == 0; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if (j == 0) { + if ((fd = creat(file, 0660)) == -1) { + if (errno != EINTR) { + warn("creat(%s)", file); + break; + } + } + if (fd != -1 && close(fd) == -1) + err(2, "close(%d)", j); + strcpy(lfile, file); + } else { + if (link(lfile, file) == -1) { + if (errno != EINTR) { + warn("link(%s, %s)", lfile, file); + break; + } + } + } + + } + + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + } + + return (0); +} diff --git a/test/stress/stress2/testcases/lockf/Makefile b/test/stress/stress2/testcases/lockf/Makefile new file mode 100644 index 0000000000..7baff7cd77 --- /dev/null +++ b/test/stress/stress2/testcases/lockf/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG= lockf + +.include diff --git a/test/stress/stress2/testcases/lockf/lockf.c b/test/stress/stress2/testcases/lockf/lockf.c new file mode 100644 index 0000000000..b261d66056 --- /dev/null +++ b/test/stress/stress2/testcases/lockf/lockf.c @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Test lockf(3) */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +char file[128]; +int fd; +pid_t pid; + +int +get(void) { + int sem; + if (lockf(fd, F_LOCK, 0) == -1) + err(1, "lockf(%s, F_LOCK)", file); + if (read(fd, &sem, sizeof(sem)) != sizeof(sem)) + err(1, "get: read(%d)", fd); + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + if (lockf(fd, F_ULOCK, 0) == -1) + err(1, "lockf(%s, F_ULOCK)", file); + return (sem); +} + +void +incr(void) { + int sem; + if (lockf(fd, F_LOCK, 0) == -1) + err(1, "lockf(%s, F_LOCK)", file); + if (read(fd, &sem, sizeof(sem)) != sizeof(sem)) + err(1, "incr: read(%d)", fd); + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + sem++; + if (write(fd, &sem, sizeof(sem)) != sizeof(sem)) + err(1, "incr: read"); + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + if (lockf(fd, F_ULOCK, 0) == -1) + err(1, "lockf(%s, F_ULOCK)", file); +} +int +setup(int nb) +{ + return (0); +} + +void +cleanup(void) +{ +} + +int +test(void) +{ + int i; + int sem = 0; + + sprintf(file, "lockf.0.%d", getpid()); + if ((fd = open(file,O_CREAT | O_TRUNC | O_RDWR, 0600)) == -1) + err(1, "creat(%s)", file); + if (write(fd, &sem, sizeof(sem)) != sizeof(sem)) + err(1, "write"); + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + + pid = fork(); + if (pid == -1) { + perror("fork"); + exit(2); + } + + if (pid == 0) { /* child */ + for (i = 0; i < 100; i++) { + while ((get() & 1) == 0) + ; + if (op->verbose > 2) + printf("Child %d, sem = %d\n", i, get()), + fflush(stdout); + incr(); + } + exit(0); + } else { /* parent */ + for (i = 0; i < 100; i++) { + while ((get() & 1) == 1) + ; + if (op->verbose > 2) + printf("Parent %d, sem = %d\n", i, get()), + fflush(stdout); + incr(); + } + } + close(fd); + waitpid(pid, &i, 0); + unlink(file); + + return (0); +} diff --git a/test/stress/stress2/testcases/lockf2/Makefile b/test/stress/stress2/testcases/lockf2/Makefile new file mode 100644 index 0000000000..dc43bcbc3f --- /dev/null +++ b/test/stress/stress2/testcases/lockf2/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG= lockf2 + +.include diff --git a/test/stress/stress2/testcases/lockf2/lockf2.c b/test/stress/stress2/testcases/lockf2/lockf2.c new file mode 100644 index 0000000000..f3bf434d76 --- /dev/null +++ b/test/stress/stress2/testcases/lockf2/lockf2.c @@ -0,0 +1,101 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Test lockf(3) with overlapping ranges */ + +/* Provoked: + lock order reversal: + 1st 0xc50057a0 vnode interlock (vnode interlock) @ kern/kern_lockf.c:190 + 2nd 0xc14710e8 system map (system map) @ vm/vm_kern.c:296 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +char file[128]; +int fd; + +int +setup(int nb) +{ + int i; + char buf[1024]; + + sprintf(file, "lockf.%d", getpid()); + if ((fd = open(file,O_CREAT | O_TRUNC | O_RDWR, 0600)) == -1) + err(1, "creat(%s)", file); + bzero(buf, sizeof(buf)); + for (i = 0; i < 1024; i++) + if (write(fd, &buf, sizeof(buf)) != sizeof(buf)) + err(1, "write"); + close(fd); + return (0); +} + +void +cleanup(void) +{ + unlink(file); +} + +int +test(void) +{ + int i; + off_t pos; + off_t size; + + if ((fd = open(file, O_RDWR, 0600)) == -1) + err(1, "open(%s)", file); + + for (i = 0; i < 1024; i++) { + pos = random_int(0, 1024 * 1024 - 1); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + size = random_int(1, 1024 * 1024 - pos); + if (size > 64) + size = 64; + if (lockf(fd, F_LOCK, size) == -1) + err(1, "lockf(%s, F_LOCK)", file); + size = random_int(1, size); + if (lockf(fd, F_ULOCK, size) == -1) + err(1, "lockf(%s, F_ULOCK)", file); + + } + close(fd); + + return (0); +} diff --git a/test/stress/stress2/testcases/mkdir/Makefile b/test/stress/stress2/testcases/mkdir/Makefile new file mode 100644 index 0000000000..4220ecf5c3 --- /dev/null +++ b/test/stress/stress2/testcases/mkdir/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=mkdir + +.include diff --git a/test/stress/stress2/testcases/mkdir/mkdir.c b/test/stress/stress2/testcases/mkdir/mkdir.c new file mode 100644 index 0000000000..d192f61891 --- /dev/null +++ b/test/stress/stress2/testcases/mkdir/mkdir.c @@ -0,0 +1,135 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static unsigned long size; + + +int +setup(int nb) +{ + int pct; + int64_t in; + int64_t bl; + int64_t reserve_in; + int64_t reserve_bl; + + if (nb == 0) { + getdf(&bl, &in); + size = in / op->incarnations; + + pct = 90; + if (op->hog == 0) + pct = random_int(1, 90); + size = size / 100 * pct + 1; + + size = size % 10000; /* arbitrary limit depth */ + size = size % 200; /* arbitrary limit depth */ /* XXX Soft Update */ + + /* Resource requirements: */ + while (size > 0) { + reserve_in = 1 * size * op->incarnations + 1; + reserve_bl = 2048 * size * op->incarnations; +// printf("---size = %lu, reserve(%jd, %jd)\n", size, reserve_bl/1024, reserve_in); + if (reserve_bl <= bl && reserve_in <= in) + break; + size--; + } + if (size == 0) + reserve_bl = reserve_in = 0; + + if (op->verbose > 1) + printf("mkdir(size=%lu, incarnations=%d). Free(%jdk, %jd), reserve(%jdk, %jd)\n", + size, op->incarnations, bl/1024, in, reserve_bl/1024, reserve_in); + reservedf(reserve_bl, reserve_in); + putval(size); + } else + size = getval(); + + return (0); +} + +void +cleanup(void) +{ +} + +void +mkDir(char *path, int level) { + char newPath[MAXPATHLEN + 1]; + + if (mkdir(path, 0770) == -1) { + warn("mkdir(%s), %s:%d", path, __FILE__, __LINE__); + size = level; + } else + chdir(path); + + if (done_testing == 1) + size = level; + + if (level < size) { + sprintf(newPath,"d%d", level+1); + mkDir(newPath, level+1); + } +} + +void +rmDir(char *path, int level) { + char newPath[MAXPATHLEN + 1]; + + if (level < size) { + sprintf(newPath,"d%d", level+1); + rmDir(newPath, level+1); + } + chdir (".."); + if (rmdir(path) == -1) { + err(1, "rmdir(%s), %s:%d", path, __FILE__, __LINE__); + } +} + +int +test(void) +{ + char path[MAXPATHLEN + 1]; + + umask(0); + sprintf(path,"p%05d.d%d", getpid(), 1); + mkDir(path, 1); + rmDir(path, 1); + + return (0); +} diff --git a/test/stress/stress2/testcases/mkfifo/Makefile b/test/stress/stress2/testcases/mkfifo/Makefile new file mode 100644 index 0000000000..33ac79d413 --- /dev/null +++ b/test/stress/stress2/testcases/mkfifo/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +PROG= mkfifo +LDADD= -lutil + +.include diff --git a/test/stress/stress2/testcases/mkfifo/mkfifo.c b/test/stress/stress2/testcases/mkfifo/mkfifo.c new file mode 100644 index 0000000000..e7ead07ece --- /dev/null +++ b/test/stress/stress2/testcases/mkfifo/mkfifo.c @@ -0,0 +1,144 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path[MAXPATHLEN+1]; +#define NB (1 * 1024 * 1024) + +int bufsize; + +static void +reader(void) { + int fd; + int i, n, *buf; + + if ((fd = open(path, O_RDWR, 0600)) < 0) { + unlink(path); + err(1, "open(%s)", path); + } + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + for (i = 0; i < NB; i+= bufsize) { + if ((n = read(fd, buf, bufsize)) < 0) + err(1, "read(), %s:%d", __FILE__, __LINE__); + if (n == 0) break; + } + close(fd); + free(buf); + return; +} + +static void +writer(void) { + int i, *buf; + int fd; + + if ((fd = open(path, O_RDWR, 0600)) < 0) { + unlink(path); + err(1, "open(%s)", path); + } + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + for (i = 0; i < bufsize / sizeof(int); i++) + buf[i] = i; + + for (i = 0; i < NB; i+= bufsize) { + if (write(fd, buf, bufsize) < 0) { + err(1, "write(%d), %s:%d", fd, + __FILE__, __LINE__); + } + } + close(fd); + free(buf); + return; +} + +int +setup(int nb) +{ + bufsize = 2 << random_int(2, 12); + return (0); +} + +void +cleanup(void) +{ +} + +int +test(void) +{ + pid_t pid; + int i, status; + + for (i = 0; i < 100; i++) { + if (sprintf(path, "fifo.%d.%d", getpid(), i) < 0) + err(1, "sprintf()"); + if (mkfifo(path, 0600) < 0) + err(1, "mkfifo(%s)", path); + } + for (i = 0; i < 100; i++) { + if (sprintf(path, "fifo.%d.%d", getpid(), i) < 0) + err(1, "sprintf()"); + if (unlink(path) < 0) + err(1, "unlink(%s)", path); + } + + + if (sprintf(path, "fifo.%d", getpid()) < 0) + err(1, "sprintf()"); + if (mkfifo(path, 0600) < 0) + err(1, "mkfifo(%s)", path); + + if ((pid = fork()) == 0) { + writer(); + exit(EXIT_SUCCESS); + + } else if (pid > 0) { + reader(); + kill(pid, SIGINT); + if (waitpid(pid, &status, 0) == -1) + warn("waitpid(%d)", pid); + } else + err(1, "fork(), %s:%d", __FILE__, __LINE__); + + unlink(path); + return (0); +} diff --git a/test/stress/stress2/testcases/mmap/Makefile b/test/stress/stress2/testcases/mmap/Makefile new file mode 100644 index 0000000000..8f132b60ea --- /dev/null +++ b/test/stress/stress2/testcases/mmap/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=mmap + +.include diff --git a/test/stress/stress2/testcases/mmap/mmap.c b/test/stress/stress2/testcases/mmap/mmap.c new file mode 100644 index 0000000000..2dfd437b8c --- /dev/null +++ b/test/stress/stress2/testcases/mmap/mmap.c @@ -0,0 +1,125 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path[128]; + +#define INPUTFILE "/bin/date" + +int +setup(int nb) +{ + umask(0); + + sprintf(path,"%s.%05d", getprogname(), getpid()); + if (mkdir(path, 0770) < 0) + err(1, "mkdir(%s), %s:%d", path, __FILE__, __LINE__); + + if (chdir(path) == -1) + err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__); + + return (0); +} + +void +cleanup(void) +{ + (void)chdir(".."); + if (rmdir(path) == -1) { + warn("rmdir(%s), %s:%d", path, __FILE__, __LINE__); + } + +} + +int +test(void) +{ + int i; + pid_t pid; + char file[128]; + int fdin, fdout; + char *src, *dst; + struct stat statbuf; + + pid = getpid(); + for (i = 0; i < 100 && done_testing == 0; i++) { + sprintf(file,"p%05d.%05d", pid, i); + + if ((fdin = open(INPUTFILE, O_RDONLY)) < 0) + err(1, INPUTFILE); + + if ((fdout = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) + err(1, "%s", file); + + if (fstat(fdin, &statbuf) < 0) + err(1, "fstat error"); + + if (lseek(fdout, statbuf.st_size - 1, SEEK_SET) == -1) + err(1, "lseek error"); + + /* write a dummy byte at the last location */ + if (write(fdout, "", 1) != 1) + err(1, "write error"); + + if ((src = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0)) == + (caddr_t) - 1) + err(1, "mmap error for input"); + + if ((dst = mmap(0, statbuf.st_size, PROT_READ | PROT_WRITE, + MAP_SHARED, fdout, 0)) == (caddr_t) - 1) + err(1, "mmap error for output"); + + memcpy(dst, src, statbuf.st_size); + + + if (munmap(src, statbuf.st_size) == -1) + err(1, "munmap"); + close(fdin); + + if (munmap(dst, statbuf.st_size) == -1) + err(1, "munmap"); + close(fdout); + + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + } + + + return (0); +} diff --git a/test/stress/stress2/testcases/openat/Makefile b/test/stress/stress2/testcases/openat/Makefile new file mode 100644 index 0000000000..8ed401edd5 --- /dev/null +++ b/test/stress/stress2/testcases/openat/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=openat + +.include diff --git a/test/stress/stress2/testcases/openat/doat.c b/test/stress/stress2/testcases/openat/doat.c new file mode 100644 index 0000000000..8337e0f9d4 --- /dev/null +++ b/test/stress/stress2/testcases/openat/doat.c @@ -0,0 +1,693 @@ +/*- + * Copyright (c) 2007 Roman Divacky + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +union param { + int i; + char *cp; + mode_t m; + dev_t d; + void *vp; + uid_t u; + gid_t g; + char **cpp; +}; + +struct testcase { + int result; + union param params[5]; // no *at syscall with more than 5 params +}; + +struct test { + int syscall; + int num_of_cases; + char *name; + struct testcase tests[10]; // no more than 10 tests + +}; + +struct test *tests; +#define NUM_OF_TESTS 15 + +char *absolute_path = NULL; +char *relative_path = "tmp/"; +char *not_dir_path = "/bin/date"; + +char *file = "foo"; +char *absolute_file = NULL; +char *relative_file = NULL; +char *symlinkf = "link"; +char *newlink = "nlink1"; +char *newlink2 = "nlink2"; +char *newlink3 = "nlink3"; +char *newdir = "newdir"; +char *fifo = "fifo"; +char *nod = "nod"; +char *newfile = "newfile"; +char *newslink = "nslink1"; + +bool dir_exist = false; +bool file_exist = false; +bool link_exist = false; + +int rel_fd, abs_fd, notd_fd, exec_fd; + +struct timeval times[2]; +struct stat buf; +char *pargv[2] = { "/bin/date", NULL }; +char cbuf[PATH_MAX]; + +void +setup() +{ + int i, error; + struct stat sb; + + tests = calloc(NUM_OF_TESTS, sizeof(struct test)); + if (tests == NULL) { + perror(""); + exit(0); + } + + absolute_path = getcwd(NULL, 0); + if (absolute_path == NULL) { + perror("getcwd"); + exit(0); + } + + absolute_path = realloc(absolute_path, strlen(absolute_path) + 5); + if (absolute_path == NULL) { + perror("realloc"); + exit(0); + } + + strcat(absolute_path, "/"); + strcat(absolute_path, relative_path); + + absolute_file = malloc(strlen(absolute_path) + 1 + strlen(file)); + bzero(absolute_file, strlen(absolute_path) + 1 + strlen(file)); + if (absolute_file == NULL) { + perror("malloc"); + exit(0); + } + strcpy(absolute_file, absolute_path); + absolute_file[strlen(absolute_file)] = '/'; + strcpy(absolute_file + strlen(absolute_path), file); + + printf("XX: %s\n", absolute_file); + + relative_file = malloc(strlen(relative_path) + 1 + strlen(file)); + bzero(relative_file, strlen(relative_path) + 1 + strlen(file)); + if (relative_file == NULL) { + perror("malloc"); + exit(0); + } + strcpy(relative_file, relative_path); + relative_file[strlen(relative_file)] = '/'; + strcpy(relative_file + strlen(relative_path), file); + + printf("YY: %s\n", relative_file); + + error = mkdir(relative_path, 0744); + dir_exist = (errno == EEXIST); + if (error && errno != EEXIST) { + perror("tmp"); + exit(0); + } + + error = stat("tmp/foo", &sb); + file_exist = (errno != ENOENT); + i = open("tmp/foo", O_RDONLY | O_CREAT, 0644); + if (i == -1) { + perror("foo"); + exit(0); + } + + rel_fd = open(relative_path, O_RDONLY); + if (rel_fd == -1) { + perror("relative path"); + exit(0); + } + + abs_fd = open(absolute_path, O_RDONLY); + if (abs_fd == -1) { + perror("absolute path"); + exit(0); + } + + notd_fd = open(not_dir_path, O_RDONLY); + if (notd_fd == -1) { + perror("not a directory"); + exit(0); + } + + exec_fd = open(not_dir_path, O_RDONLY); + if (exec_fd == -1) { + perror("not a directory"); + exit(0); + } + + error = symlink(absolute_file, symlinkf); + link_exist = (errno == EEXIST); + if (error && errno != EEXIST) { + perror("symlink"); + exit(0); + } + + // faccessat + tests[0].syscall = SYS_faccessat; + tests[0].num_of_cases = 6; + tests[0].name = "faccessat"; + tests[0].tests[0].result = EBADF; + tests[0].tests[0].params[0].i = 106; // invalid fd + tests[0].tests[0].params[1].cp = relative_path; + tests[0].tests[0].params[2].m = 0; + tests[0].tests[0].params[3].i = 0; + tests[0].tests[1].result = EBADF; + tests[0].tests[1].params[0].i = 106; // invalid fd + tests[0].tests[1].params[1].cp = relative_path; + tests[0].tests[1].params[2].m = 0; + tests[0].tests[1].params[3].i = AT_EACCESS; + tests[0].tests[2].result = EINVAL; + tests[0].tests[2].params[0].i = rel_fd; + tests[0].tests[2].params[1].cp = absolute_path; + tests[0].tests[2].params[2].m = 0; + tests[0].tests[2].params[3].i = 123; // invalid flag + tests[0].tests[3].result = ENOTDIR; + tests[0].tests[3].params[0].i = notd_fd; + tests[0].tests[3].params[1].cp = relative_file; + tests[0].tests[3].params[2].m = 0; + tests[0].tests[3].params[3].i = 0; + tests[0].tests[4].result = 0; + tests[0].tests[4].params[0].i = rel_fd; + tests[0].tests[4].params[1].cp = file; + tests[0].tests[4].params[2].m = 0; + tests[0].tests[4].params[3].i = 0; + tests[0].tests[5].result = 0; + tests[0].tests[5].params[0].i = rel_fd; + tests[0].tests[5].params[1].cp = file; + tests[0].tests[5].params[2].m = 0; + tests[0].tests[5].params[3].i = AT_EACCESS; + tests[0].tests[6].result = 0; + tests[0].tests[6].params[0].i = 106; // invalid fd + tests[0].tests[6].params[1].cp = absolute_path; + tests[0].tests[6].params[2].m = 0; + tests[0].tests[6].params[3].i = 0; + + // fchmodat + tests[1].syscall = SYS_fchmodat; + tests[1].num_of_cases = 6; + tests[1].name = "fchmodat"; + tests[1].tests[0].result = EBADF; + tests[1].tests[0].params[0].i = 106; // invalid fd + tests[1].tests[0].params[1].cp = relative_path; + tests[1].tests[0].params[2].m = 33190; + tests[1].tests[0].params[3].i = 0; + tests[1].tests[1].result = EINVAL; + tests[1].tests[1].params[0].i = rel_fd; + tests[1].tests[1].params[1].cp = absolute_path; + tests[1].tests[1].params[2].m = 33190; // mode 646 translated + tests[1].tests[1].params[3].i = 123; // invalid flag + tests[1].tests[2].result = ENOTDIR; + tests[1].tests[2].params[0].i = notd_fd; + tests[1].tests[2].params[1].cp = relative_file; + tests[1].tests[2].params[2].m = 33190; + tests[1].tests[2].params[3].i = 0; + tests[1].tests[3].result = 0; + tests[1].tests[3].params[0].i = notd_fd; + tests[1].tests[3].params[1].cp = absolute_file; + tests[1].tests[3].params[2].m = 33190; + tests[1].tests[3].params[3].i = 0; + tests[1].tests[4].result = 0; + tests[1].tests[4].params[0].i = AT_FDCWD; + tests[1].tests[4].params[1].cp = symlinkf; + tests[1].tests[4].params[2].m = 33190; + tests[1].tests[4].params[3].i = AT_SYMLINK_NOFOLLOW; + tests[1].tests[5].result = 0; + tests[1].tests[5].params[0].i = rel_fd; + tests[1].tests[5].params[1].cp = file; + tests[1].tests[5].params[2].m = 33190; + tests[1].tests[5].params[3].i = 0; + + // fchownat + tests[2].syscall = SYS_fchownat; + tests[2].num_of_cases = 6; + tests[2].name = "fchownat"; + tests[2].tests[0].result = EBADF; + tests[2].tests[0].params[0].i = 106; // invalid fd + tests[2].tests[0].params[1].cp = relative_file; + tests[2].tests[0].params[2].u = 65534; + tests[2].tests[0].params[3].g = 65534; + tests[2].tests[0].params[4].i = 0; + tests[2].tests[1].result = EINVAL; + tests[2].tests[1].params[0].i = rel_fd; + tests[2].tests[1].params[1].cp = file; + tests[2].tests[1].params[2].u = 65534; + tests[2].tests[1].params[3].g = 65534; + tests[2].tests[1].params[4].i = 123; // invalid flag + tests[2].tests[2].result = ENOTDIR; + tests[2].tests[2].params[0].i = notd_fd; + tests[2].tests[2].params[1].cp = relative_file; + tests[2].tests[2].params[2].u = 65534; + tests[2].tests[2].params[3].g = 65534; + tests[2].tests[2].params[4].i = 0; + tests[2].tests[3].result = 0; + tests[2].tests[3].params[0].i = notd_fd; + tests[2].tests[3].params[1].cp = absolute_file; + tests[2].tests[3].params[2].u = 65534; + tests[2].tests[3].params[3].g = 65534; + tests[2].tests[3].params[4].i = 0; + tests[2].tests[4].result = 0; + tests[2].tests[4].params[0].i = AT_FDCWD; + tests[2].tests[4].params[1].cp = symlinkf; + tests[2].tests[4].params[2].u = 65534; + tests[2].tests[4].params[3].g = 65534; + tests[2].tests[4].params[4].i = AT_SYMLINK_NOFOLLOW; + tests[2].tests[5].result = 0; + tests[2].tests[5].params[0].i = rel_fd; + tests[2].tests[5].params[1].cp = file; + tests[2].tests[5].params[2].u = 0; + tests[2].tests[5].params[3].g = 0; + tests[2].tests[5].params[4].i = 0; + + // fstatat + tests[3].syscall = SYS_fstatat; + tests[3].num_of_cases = 5; + tests[3].name = "fstatat"; + tests[3].tests[0].result = EBADF; + tests[3].tests[0].params[0].i = 106; // invalid fd + tests[3].tests[0].params[1].cp = relative_file; + tests[3].tests[0].params[2].vp = &buf; + tests[3].tests[0].params[3].i = 0; + tests[3].tests[1].result = EINVAL; + tests[3].tests[1].params[0].i = rel_fd; + tests[3].tests[1].params[1].cp = relative_file; + tests[3].tests[1].params[2].vp = &buf; + tests[3].tests[1].params[3].i = 123; // invalid flags + tests[3].tests[2].result = ENOTDIR; + tests[3].tests[2].params[0].i = notd_fd; + tests[3].tests[2].params[1].cp = relative_file; + tests[3].tests[2].params[2].vp = &buf; + tests[3].tests[2].params[3].i = 0; + tests[3].tests[2].result = 0; + tests[3].tests[2].params[0].i = rel_fd; + tests[3].tests[2].params[1].cp = file; + tests[3].tests[2].params[2].vp = &buf; + tests[3].tests[2].params[3].i = 0; + tests[3].tests[3].result = 0; + tests[3].tests[3].params[0].i = AT_FDCWD; + tests[3].tests[3].params[1].cp = symlinkf; + tests[3].tests[3].params[2].vp = &buf; + tests[3].tests[3].params[3].i = AT_SYMLINK_NOFOLLOW; + tests[3].tests[4].result = 0; + tests[3].tests[4].params[0].i = notd_fd; + tests[3].tests[4].params[1].cp = absolute_file; + tests[3].tests[4].params[2].vp = &buf; + tests[3].tests[4].params[3].i = 0; + + // futimesat + tests[4].syscall = SYS_futimesat; + tests[4].num_of_cases = 4; + tests[4].name = "futimesat"; + tests[4].tests[0].result = EBADF; + tests[4].tests[0].params[0].i = 106; // invalid fd + tests[4].tests[0].params[1].cp = relative_file; + tests[4].tests[0].params[2].vp = times; + tests[4].tests[1].result = ENOTDIR; + tests[4].tests[1].params[0].i = notd_fd; + tests[4].tests[1].params[1].cp = relative_file; + tests[4].tests[1].params[2].vp = times; + tests[4].tests[2].result = 0; + tests[4].tests[2].params[0].i = rel_fd; + tests[4].tests[2].params[1].cp = file; + tests[4].tests[2].params[2].vp = times; + tests[4].tests[3].result = 0; + tests[4].tests[3].params[0].i = notd_fd; + tests[4].tests[3].params[1].cp = absolute_file; + tests[4].tests[3].params[2].vp = times; + + // linkat + tests[5].syscall = SYS_linkat; + tests[5].num_of_cases = 7; + tests[5].name = "linkat"; + tests[5].tests[0].result = EBADF; + tests[5].tests[0].params[0].i = 106; // invalid fd + tests[5].tests[0].params[1].cp = relative_file; + tests[5].tests[0].params[2].i = AT_FDCWD; + tests[5].tests[0].params[3].cp = newlink; + tests[5].tests[0].params[4].i = 0; + tests[5].tests[1].result = EBADF; + tests[5].tests[1].params[0].i = AT_FDCWD; + tests[5].tests[1].params[1].cp = relative_file; + tests[5].tests[1].params[2].i = 106; // invalid fd + tests[5].tests[1].params[3].cp = newlink; + tests[5].tests[1].params[4].i = 0; + tests[5].tests[2].result = EINVAL; + tests[5].tests[2].params[0].i = rel_fd; + tests[5].tests[2].params[1].cp = relative_file; + tests[5].tests[2].params[2].i = AT_FDCWD; + tests[5].tests[2].params[3].cp = newlink; + tests[5].tests[2].params[4].i = 123; // invalid flag + tests[5].tests[3].result = ENOTDIR; + tests[5].tests[3].params[0].i = notd_fd; + tests[5].tests[3].params[1].cp = relative_file; + tests[5].tests[3].params[2].i = AT_FDCWD; + tests[5].tests[3].params[3].cp = newlink; + tests[5].tests[3].params[4].i = 0; + tests[5].tests[4].result = 0; + tests[5].tests[4].params[0].i = rel_fd; + tests[5].tests[4].params[1].cp = file; + tests[5].tests[4].params[2].i = rel_fd; + tests[5].tests[4].params[3].cp = newlink; + tests[5].tests[4].params[4].i = 0; + tests[5].tests[5].result = 0; + tests[5].tests[5].params[0].i = AT_FDCWD; + tests[5].tests[5].params[1].cp = symlinkf; + tests[5].tests[5].params[2].i = rel_fd; + tests[5].tests[5].params[3].cp = newlink2; + tests[5].tests[5].params[4].i = 0; + tests[5].tests[6].result = 0; + tests[5].tests[6].params[0].i = AT_FDCWD; + tests[5].tests[6].params[1].cp = symlinkf; + tests[5].tests[6].params[2].i = rel_fd; + tests[5].tests[6].params[3].cp = newlink3; + tests[5].tests[6].params[4].i = AT_SYMLINK_FOLLOW; + + // mkdirat + tests[6].syscall = SYS_mkdirat; + tests[6].num_of_cases = 3; + tests[6].name = "mkdirat"; + tests[6].tests[0].result = EBADF; + tests[6].tests[0].params[0].i = 106; // invalid fd + tests[6].tests[0].params[1].cp = relative_file; + tests[6].tests[0].params[2].m = 33190; + tests[6].tests[1].result = ENOTDIR; + tests[6].tests[1].params[0].i = notd_fd; + tests[6].tests[1].params[1].cp = relative_file; + tests[6].tests[1].params[2].m = 33190; + tests[6].tests[2].result = 0; + tests[6].tests[2].params[0].i = rel_fd; + tests[6].tests[2].params[1].cp = newdir; + tests[6].tests[2].params[2].m = 33190; + + // mkfifoat + tests[7].syscall = SYS_mkfifoat; + tests[7].num_of_cases = 3; + tests[7].name = "mkfifoat"; + tests[7].tests[0].result = EBADF; + tests[7].tests[0].params[0].i = 107; // invalid fd + tests[7].tests[0].params[1].cp = relative_file; + tests[7].tests[0].params[2].m = 33190; + tests[7].tests[1].result = ENOTDIR; + tests[7].tests[1].params[0].i = notd_fd; + tests[7].tests[1].params[1].cp = relative_file; + tests[7].tests[1].params[2].m = 33190; + tests[7].tests[2].result = 0; + tests[7].tests[2].params[0].i = rel_fd; + tests[7].tests[2].params[1].cp = fifo; + tests[7].tests[2].params[2].m = 33190; + + // mknodat + tests[8].syscall = SYS_mknodat; + tests[8].num_of_cases = 3; + tests[8].name = "mknodat"; + tests[8].tests[0].result = EBADF; + tests[8].tests[0].params[0].i = 108; // invalid fd + tests[8].tests[0].params[1].cp = relative_file; + tests[8].tests[0].params[2].m = 0666 | S_IFCHR; + tests[8].tests[0].params[3].d = 15; + tests[8].tests[1].result = ENOTDIR; + tests[8].tests[1].params[0].i = notd_fd; + tests[8].tests[1].params[1].cp = relative_file; + tests[8].tests[1].params[2].m = 0666 | S_IFCHR; + tests[8].tests[1].params[3].d = 15; + tests[8].tests[2].result = 0; + tests[8].tests[2].params[0].i = rel_fd; + tests[8].tests[2].params[1].cp = nod; + tests[8].tests[2].params[2].m = 0666 | S_IFCHR; + tests[8].tests[2].params[3].d = 2570; + + // openat + tests[9].syscall = SYS_openat; + tests[9].num_of_cases = 5; + tests[9].name = "openat"; + tests[9].tests[0].result = EBADF; + tests[9].tests[0].params[0].i = 106; // invalid fd + tests[9].tests[0].params[1].cp = relative_file; + tests[9].tests[0].params[2].i = O_RDONLY; + tests[9].tests[0].params[3].i = 0666; + tests[9].tests[1].result = ENOTDIR; + tests[9].tests[1].params[0].i = notd_fd; + tests[9].tests[1].params[1].cp = relative_file; + tests[9].tests[1].params[2].i = O_RDONLY; + tests[9].tests[1].params[3].i = 0666; + tests[9].tests[2].result = 7; // hardcoded fd + tests[9].tests[2].params[0].i = rel_fd; + tests[9].tests[2].params[1].cp = file; + tests[9].tests[2].params[2].i = O_RDONLY; + tests[9].tests[2].params[3].i = 0400; + tests[9].tests[3].result = 8; // hardcoded fd + tests[9].tests[3].params[0].i = notd_fd; + tests[9].tests[3].params[1].cp = absolute_file; + tests[9].tests[3].params[2].i = O_RDONLY; + tests[9].tests[3].params[3].i = 0400; + tests[9].tests[4].result = 9; // hardcoded fd + tests[9].tests[4].params[0].i = rel_fd; + tests[9].tests[4].params[1].cp = newfile; + tests[9].tests[4].params[2].i = O_RDONLY | O_CREAT; + tests[9].tests[4].params[3].i = 0666; + + // readlinkat + tests[10].syscall = SYS_readlinkat; + tests[10].num_of_cases = 3; + tests[10].name = "readlinkat"; + tests[10].tests[0].result = EBADF; + tests[10].tests[0].params[0].i = 106; // invalid fd + tests[10].tests[0].params[1].cp = relative_file; + tests[10].tests[0].params[2].vp = cbuf; + tests[10].tests[0].params[3].i = PATH_MAX; + tests[10].tests[1].result = ENOTDIR; + tests[10].tests[1].params[0].i = notd_fd; + tests[10].tests[1].params[1].cp = relative_file; + tests[10].tests[1].params[2].vp = cbuf; + tests[10].tests[1].params[3].i = PATH_MAX; + tests[10].tests[2].result = strlen(absolute_file); + tests[10].tests[2].params[0].i = AT_FDCWD; + tests[10].tests[2].params[1].cp = symlinkf; + tests[10].tests[2].params[2].vp = cbuf; + tests[10].tests[2].params[3].i = PATH_MAX; + + // renameat + tests[11].syscall = SYS_renameat; + tests[11].num_of_cases = 5; + tests[11].name = "renameat"; + tests[11].tests[0].result = EBADF; + tests[11].tests[0].params[0].i = 106; // invalid fd + tests[11].tests[0].params[1].cp = file; + tests[11].tests[0].params[2].i = rel_fd; + tests[11].tests[0].params[3].cp = file; + tests[11].tests[1].result = EBADF; + tests[11].tests[1].params[0].i = rel_fd; + tests[11].tests[1].params[1].cp = file; + tests[11].tests[1].params[2].i = 106; // invalid fd + tests[11].tests[1].params[3].cp = file; + tests[11].tests[2].result = ENOTDIR; + tests[11].tests[2].params[0].i = notd_fd; + tests[11].tests[2].params[1].cp = relative_file; + tests[11].tests[2].params[2].i = rel_fd; + tests[11].tests[2].params[3].cp = file; + tests[11].tests[3].result = ENOTDIR; + tests[11].tests[3].params[0].i = rel_fd; + tests[11].tests[3].params[1].cp = file; + tests[11].tests[3].params[2].i = notd_fd; + tests[11].tests[3].params[3].cp = relative_file; + tests[11].tests[4].result = 0; + tests[11].tests[4].params[0].i = rel_fd; + tests[11].tests[4].params[1].cp = newfile; + tests[11].tests[4].params[2].i = AT_FDCWD; + tests[11].tests[4].params[3].cp = newfile; + + // symlinkat + tests[12].syscall = SYS_symlinkat; + tests[12].num_of_cases = 3; + tests[12].name = "symlinkat"; + tests[12].tests[0].result = EBADF; + tests[12].tests[0].params[0].cp = file; + tests[12].tests[0].params[1].i = 106; // invalid fd + tests[12].tests[0].params[2].cp = file; + tests[12].tests[1].result = ENOTDIR; + tests[12].tests[1].params[0].cp = file; + tests[12].tests[1].params[1].i = notd_fd; + tests[12].tests[1].params[2].cp = relative_file; + tests[12].tests[2].result = 0; + tests[12].tests[2].params[0].cp = absolute_file; + tests[12].tests[2].params[1].i = rel_fd; + tests[12].tests[2].params[2].cp = newslink; + + + // unlinkat + tests[13].syscall = SYS_unlinkat; + tests[13].num_of_cases = 7; + tests[13].name = "unlinkat"; + tests[13].tests[0].result = EBADF; + tests[13].tests[0].params[0].i = 106; // invalid fd + tests[13].tests[0].params[1].cp = relative_file; + tests[13].tests[0].params[2].i = 0; + tests[13].tests[1].result = ENOTDIR; + tests[13].tests[1].params[0].i = notd_fd; + tests[13].tests[1].params[1].cp = relative_file; + tests[13].tests[1].params[2].i = 0; + tests[13].tests[2].result = EINVAL; + tests[13].tests[2].params[0].i = rel_fd; + tests[13].tests[2].params[1].cp = file; + tests[13].tests[2].params[2].i = 123; // invalid flag + tests[13].tests[3].result = ENOTDIR; + tests[13].tests[3].params[0].i = rel_fd; + tests[13].tests[3].params[1].cp = not_dir_path; + tests[13].tests[3].params[2].i = AT_REMOVEDIR; + tests[13].tests[4].result = ENOTEMPTY; + tests[13].tests[4].params[0].i = AT_FDCWD; + tests[13].tests[4].params[1].cp = relative_path; + tests[13].tests[4].params[2].i = AT_REMOVEDIR; + tests[13].tests[5].result = 0; + tests[13].tests[5].params[0].i = rel_fd; + tests[13].tests[5].params[1].cp = newdir; + tests[13].tests[5].params[2].i = AT_REMOVEDIR; + tests[13].tests[6].result = 0; + tests[13].tests[6].params[0].i = AT_FDCWD; + tests[13].tests[6].params[1].cp = newfile; + tests[13].tests[6].params[2].i = 0; + + + // fexecve + tests[14].syscall = SYS_fexecve; + tests[14].num_of_cases = 2; + tests[14].name = "fexecve"; + tests[14].tests[0].result = EBADF; + tests[14].tests[0].params[0].i = 106; // invalid fd + tests[14].tests[0].params[1].cpp = pargv; + tests[14].tests[0].params[2].cpp = NULL; + // This is EXPECTED to execve /bin/date, so dont expect OK output + tests[14].tests[1].result = 0; + tests[14].tests[1].params[0].i = exec_fd; + tests[14].tests[1].params[1].cpp = pargv; + tests[14].tests[1].params[2].cpp = NULL; +} + +void +cleanup() +{ + int error; + + close(notd_fd); + close(rel_fd); + close(abs_fd); + + if (!file_exist) { + error = unlink("tmp/foo"); + if (error) { + perror("unlink"); + exit(0); + } + } + if (!dir_exist) { + error = rmdir(absolute_path); + if (error) { + perror("rmdir"); + exit(0); + } + } + if (link_exist) { + error = unlink(symlinkf); + if (error) { + perror("unlink"); + exit(0); + } + } +} + +void +setup_once() +{ +} + +int +main(int argc, char *argv[]) +{ + int i,j; + int error; + + setup(); + + for (i = 0; i < NUM_OF_TESTS; i++) { + printf("\nTest: %s\n", tests[i].name); + for (j = 0; j < tests[i].num_of_cases; j++) { + error = syscall(tests[i].syscall, + tests[i].tests[j].params[0], + tests[i].tests[j].params[1], + tests[i].tests[j].params[2], + tests[i].tests[j].params[3], + tests[i].tests[j].params[4]); + if (error == 0) { + if (tests[i].tests[j].result == 0) + printf("#%i ... OK\n", j); + else { + printf("#%i ... BAD: ", j); + printf("expected %i, but got %i\n", tests[i].tests[j].result, error); + } + } else { + if (tests[i].tests[j].result == errno) + printf("#%i ... OK\n", j); + else { + if (error != tests[i].tests[j].result) { + printf("#%i ... BAD: ", j); + printf("expected %i, but got %i\n", tests[i].tests[j].result, error); + } else + printf("#%i ... OK\n", j); + } + } + + + } + } + +// cleanup(); + + + return (0); +} diff --git a/test/stress/stress2/testcases/openat/openat.c b/test/stress/stress2/testcases/openat/openat.c new file mode 100644 index 0000000000..482c42da2c --- /dev/null +++ b/test/stress/stress2/testcases/openat/openat.c @@ -0,0 +1,162 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path1[128]; +static char path2[] = "tmp"; + +static char rpath[128]; +static char apath[128]; + +static int fd; + +int +setup(int nb) +{ + umask(0); + + sprintf(path1,"%s.%05d", getprogname(), getpid()); + if (mkdir(path1, 0770) < 0) + err(1, "mkdir(%s), %s:%d", path1, __FILE__, __LINE__); + if (chdir(path1) == -1) + err(1, "chdir(%s), %s:%d", path2, __FILE__, __LINE__); + + if (mkdir(path2, 0770) < 0) + err(1, "mkdir(%s), %s:%d", path2, __FILE__, __LINE__); + if (chdir(path2) == -1) + err(1, "chdir(%s), %s:%d", path2, __FILE__, __LINE__); + if (getcwd(apath, sizeof(apath)) == NULL) + err(1, "getcwd(%s), %s:%d", path2, __FILE__, __LINE__); + + if (chdir("..") == -1) + err(1, "chdir(%s), %s:%d", path1, __FILE__, __LINE__); + + if ((fd = open(path2, O_RDONLY)) == -1) + err(1, "open(%s), %s:%d", path2, __FILE__, __LINE__); + + strcpy(rpath, "tmp"); + return (0); +} + +void +cleanup(void) +{ +#if 1 + if (rmdir(path2) == -1) + warn("rmdir(%s), %s:%d", path2, __FILE__, __LINE__); + (void)chdir(".."); + if (rmdir(path1) == -1) + warn("rmdir(%s), %s:%d", path1, __FILE__, __LINE__); +#endif +} + +static void +test_openat(void) +{ + int i; + pid_t pid; + char file[128]; + char p[128]; + int tfd; + + pid = getpid(); + for (i = 0; i < 100; i++) { + sprintf(file,"p%05d.%05d", pid, i); + if ((tfd = openat(fd, file, O_RDONLY|O_CREAT, 0660)) == -1) + err(1, "openat(%s), %s:%d", file, __FILE__, __LINE__); + close(tfd); + strcpy(p, "tmp/"); + strcat(p, file); + if (unlink(p) == -1) + err(1, "unlink(%s), %s:%d", p, __FILE__, __LINE__); + } +} + +static void +test_renameat(void) +{ + int i; + pid_t pid; + char file[128]; + char file2[128]; + int tfd; + + pid = getpid(); + for (i = 0; i < 100; i++) { + sprintf(file,"p%05d.%05d", pid, i); + if ((tfd = openat(fd, file, O_RDONLY|O_CREAT, 0660)) == -1) + err(1, "openat(%s), %s:%d", file, __FILE__, __LINE__); + close(tfd); + + sprintf(file2,"p%05d.%05d.togo", pid, i); + if (renameat(fd, file, fd, file2) == -1) + err(1, "renameat(%s)", file2); + + sprintf(file2,"tmp/p%05d.%05d.togo", pid, i); + if (unlink(file2) == -1) + err(1, "unlink(%s), %s:%d", file2, __FILE__, __LINE__); + } +} + +static void +test_unlinkat(void) +{ + int i; + pid_t pid; + char file[128]; + int tfd; + + pid = getpid(); + for (i = 0; i < 100; i++) { + sprintf(file,"p%05d.%05d", pid, i); + if ((tfd = openat(fd, file, O_RDONLY|O_CREAT, 0660)) == -1) + err(1, "openat(%s), %s:%d", file, __FILE__, __LINE__); + close(tfd); + if (unlinkat(fd, file, 0) == -1) + err(1, "unlinkat(%s), %s:%d", file, __FILE__, __LINE__); + } +} + +int +test(void) +{ + test_openat(); + test_renameat(); + test_unlinkat(); + + return (0); +} diff --git a/test/stress/stress2/testcases/pty/Makefile b/test/stress/stress2/testcases/pty/Makefile new file mode 100644 index 0000000000..cdae6dea2f --- /dev/null +++ b/test/stress/stress2/testcases/pty/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +PROG= pty +LDADD= -lutil + +.include diff --git a/test/stress/stress2/testcases/pty/pty.c b/test/stress/stress2/testcases/pty/pty.c new file mode 100644 index 0000000000..855d9fd7a7 --- /dev/null +++ b/test/stress/stress2/testcases/pty/pty.c @@ -0,0 +1,111 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Test PTYs */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +#define TXT "Hello, world!" + +int +setup(int nb) +{ + return (0); +} + +void +cleanup(void) +{ +} + +int +test(void) +{ + int i, master, slave; + int s[32], m[32]; + char buf[512], slname[1025]; + struct termios tios; + + for (i = 0; i < 32; i++) { + if (openpty(&m[i], &s[i], slname, NULL, NULL) == -1) + err(1, "openpty"); + } + for (i = 0; i < 32; i++) { + close(m[i]); + close(s[i]); + } + + for (i = 0; i < 1024; i++) { + if (openpty(&m[0], &s[0], slname, NULL, NULL) == -1) + err(1, "openpty"); + close(m[0]); + close(s[0]); + } + + for (i = 0; i < 10 && done_testing == 0; i++) { + if (openpty(&master, &slave, slname, NULL, NULL) == -1) + err(1, "openpty"); + if ((i & 1) == 0) { + if (close(master) == -1) + err(1, "close(master)"); + if (close(slave) == -1) + err(1, "close(%s)", slname); + } else { + if (close(slave) == -1) + err(1, "close(%s)", slname); + if (close(master) == -1) + err(1, "close(master)"); + } + } + + if (openpty(&master, &slave, slname, NULL, NULL) == -1) + err(1, "openpty"); + if (tcgetattr(slave, &tios) < 0) + err(1, "tcgetattr(%s)", slname); + cfmakeraw(&tios); + if (tcsetattr(slave, TCSAFLUSH, &tios) < 0) + err(1, "tcsetattr(%s)", slname); + + for (i = 0; i < 64 && done_testing == 0; i++) { + if (write(master, TXT, sizeof(TXT)) == -1) + err(1, "write"); + if (read(slave, buf, sizeof(TXT)) == -1) + err(1, "read(%s)", slname); + } + close(master); + close(slave); + return (0); +} diff --git a/test/stress/stress2/testcases/rename/Makefile b/test/stress/stress2/testcases/rename/Makefile new file mode 100644 index 0000000000..57e23f700e --- /dev/null +++ b/test/stress/stress2/testcases/rename/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=rename + +.include diff --git a/test/stress/stress2/testcases/rename/rename.c b/test/stress/stress2/testcases/rename/rename.c new file mode 100644 index 0000000000..fcd26b1618 --- /dev/null +++ b/test/stress/stress2/testcases/rename/rename.c @@ -0,0 +1,144 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path[128]; +static unsigned long size; + +int +setup(int nb) +{ + int64_t in; + int64_t bl; + int64_t reserve_in; + int64_t reserve_bl; + + umask(0); + + if (nb == 0) { + getdf(&bl, &in); + size = in / op->incarnations; + + if (size > 100) + size = 100; /* arbitrary limit number of files pr. dir */ + + /* Resource requirements: */ + while (size > 0) { + reserve_in = 1 * size * op->incarnations + 2 * op->incarnations; + reserve_bl = 100 * size * op->incarnations; +// printf("size = %lu, reserve(%jd, %jd)\n", size, reserve_bl/1024, reserve_in); + if (reserve_bl <= bl && reserve_in <= in) + break; + size--; + } + if (size == 0) + reserve_bl = reserve_in = 0; + + if (op->verbose > 1) + printf("rename(size=%lu, incarnations=%d). Free(%jdk, %jd), reserve(%jdk, %jd)\n", + size, op->incarnations, bl/1024, in, reserve_bl/1024, reserve_in); + reservedf(reserve_bl, reserve_in); + putval(size); + } else { + size = getval(); + } + + sprintf(path,"%s.%05d", getprogname(), getpid()); + if (mkdir(path, 0770) < 0) + err(1, "mkdir(%s), %s:%d", path, __FILE__, __LINE__); + if (chdir(path) == -1) + err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__); + + return (0); +} + +void +cleanup(void) +{ + (void)system("rm -f p*"); + (void)chdir(".."); + if (rmdir(path) == -1) + warn("rmdir(%s), %s:%d", path, __FILE__, __LINE__); +} + +static void +test_rename(void) +{ + int i, j; + pid_t pid; + char file1[128]; + char file2[128]; + int tfd; + + pid = getpid(); + for (i = 0; i < size; i++) { + sprintf(file1,"p%05d.%05d", pid, i); + if ((tfd = open(file1, O_RDONLY|O_CREAT, 0660)) == -1) + err(1, "openat(%s), %s:%d", file1, __FILE__, __LINE__); + close(tfd); + } + for (j = 0; j < 100; j++) { + for (i = 0; i < size; i++) { + sprintf(file1,"p%05d.%05d", pid, i); + sprintf(file2,"p%05d.%05d.togo", pid, i); + if (rename(file1, file2) == -1) + err(1, "rename(%s, %s). %s:%d", file1, file2, + __FILE__, __LINE__); + } + for (i = 0; i < size; i++) { + sprintf(file1,"p%05d.%05d", pid, i); + sprintf(file2,"p%05d.%05d.togo", pid, i); + if (rename(file2, file1) == -1) + err(1, "rename(%s, %s). %s:%d", file2, file1, + __FILE__, __LINE__); + } + } + + for (i = 0; i < size; i++) { + sprintf(file1,"p%05d.%05d", pid, i); + if (unlink(file1) == -1) + err(1, "unlink(%s), %s:%d", file1, __FILE__, __LINE__); + } +} + +int +test(void) +{ + test_rename(); + + return (0); +} diff --git a/test/stress/stress2/testcases/run/Makefile b/test/stress/stress2/testcases/run/Makefile new file mode 100644 index 0000000000..49cd4ea3c7 --- /dev/null +++ b/test/stress/stress2/testcases/run/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=run + +.include diff --git a/test/stress/stress2/testcases/run/run.c b/test/stress/stress2/testcases/run/run.c new file mode 100644 index 0000000000..16543717bf --- /dev/null +++ b/test/stress/stress2/testcases/run/run.c @@ -0,0 +1,122 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Control program to run all the other test cases */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +#define MAXAV 10 +static char *av[MAXAV]; +static int loop = 1; + +int +setup(int nb) +{ + return (0); +} + +void +cleanup(void) +{ +} + +static char ** +mkargv(char *name) +{ + av[0] = name; + av[1] = 0; + return (av); +} + +static void +clean(void) +{ + char buf[132]; + + /* cleanup after the syscall test */ + snprintf(buf, sizeof(buf), + "cd %s; find . -type d -mtime -1 -exec chmod 777 {} \\;", op->wd); + (void)system(buf); + snprintf(buf, sizeof(buf), + "cd %s; find . -type f -mtime -1 -exec chmod 666 {} \\;", op->wd); + (void)system(buf); + snprintf(buf, sizeof(buf), + "cd %s; chflags \"nouappnd nouchg nouunlnk\" .", op->wd); + (void)system(buf); + snprintf(buf, sizeof(buf), + "cd %s; rm -rf syscall.[0-9]* fifo.[0-9]* creat.[0-9]* " + "p[0-9]*.d1 df lock", op->cd); + (void)system(buf); +} + +int +test(void) +{ + int i; + int s; + pid_t *r; + char fullpath[MAXPATHLEN+1]; + time_t t; + char ct[80]; + struct tm *tm; + + r = (pid_t *)malloc(op->argc * sizeof(pid_t)); + + (void)time(&t); + tm = localtime(&t); + (void) strftime(ct, sizeof(ct), "%T", tm); + printf("%s Loop #%d\n", ct, loop++); + + for (i = 0; i < op->argc; i++) { + if ((r[i] = fork()) == 0) { + snprintf(fullpath, sizeof(fullpath), "%s/%s", home, + op->argv[i]); + if (execv(fullpath, mkargv(basename(op->argv[i]))) == -1) + err(1, "execl(%s), %s:%d", fullpath, __FILE__, + __LINE__); + } + if (r[i] < 0) + err(1, "fork(), %s:%d", __FILE__, __LINE__); + } + for (i = 0; i < op->argc; i++) + if (r[i] != 0 && waitpid(r[i], &s, 0) == -1) + err(1, "waitpid(%d), %s:%d", r[i], __FILE__, __LINE__); + free(r); + + clean(); + + return (0); +} diff --git a/test/stress/stress2/testcases/rw/Makefile b/test/stress/stress2/testcases/rw/Makefile new file mode 100644 index 0000000000..597cda0ec4 --- /dev/null +++ b/test/stress/stress2/testcases/rw/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG= rw + +.include diff --git a/test/stress/stress2/testcases/rw/rw.c b/test/stress/stress2/testcases/rw/rw.c new file mode 100644 index 0000000000..ed17a20166 --- /dev/null +++ b/test/stress/stress2/testcases/rw/rw.c @@ -0,0 +1,181 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Write and check read a file */ + +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path[128]; +static int starting_dir; +static unsigned long size; + +#define MAXSIZE 256 * 1024 + +int +setup(int nb) +{ + int64_t bl; + int64_t in; + int64_t reserve_in; + int64_t reserve_bl; + int pct; + + if (nb == 0) { + getdf(&bl, &in); + size = bl / op->incarnations / 1024; + + pct = 90; + if (op->hog == 0) + pct = random_int(1, 90); + size = size / 100 * pct + 1; + + if (size > MAXSIZE) + size = MAXSIZE; /* arbitrary limit size pr. incarnation */ + + /* Resource requirements: */ + while (size > 0) { + reserve_in = 2 * op->incarnations + 1; + reserve_bl = size * 1024 * op->incarnations + + (512 * 1024 * op->incarnations) + + 64 * 1024; +// printf("-- size = %lu, reserve(%jd, %jd)\n", size, reserve_bl/1024, reserve_in); + if (reserve_bl <= bl && reserve_in <= in) + break; + size = size - 1024; + } + if (size == 0) + reserve_bl = reserve_in = 0; + + if (op->verbose > 1) + printf("rw(size=%lu, incarnations=%d). Free(%jdk, %jd), reserve(%jdk, %jd)\n", + size, op->incarnations, bl/1024, in, reserve_bl/1024, reserve_in); + reservedf(reserve_bl, reserve_in); + putval(size); + size = size * 1024; + } else { + size = getval(); + size = size * 1024; + } + + umask(0); + sprintf(path,"%s.%05d", getprogname(), getpid()); + (void)mkdir(path, 0770); + if (chdir(path) == -1) + err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__); + if ((starting_dir = open(".", 0)) < 0) + err(1, "."); + + + return (0); +} + +void +cleanup(void) +{ + if (size == 0) + return; + if (fchdir(starting_dir) == -1) + err(1, "fchdir()"); + if (close(starting_dir) < 0) + err(1, "close(starting_dir:%d)", starting_dir); + + (void)system("find . -delete"); + + if (chdir("..") == -1) + err(1, "chdir(..)"); + if (rmdir(path) == -1) + err(1, "rmdir(%s), %s:%d", path, __FILE__, __LINE__); + size = 0; +} + +int +test(void) +{ + int buf[1024], index, to; +#ifdef TEST + int i; +#endif + int fd; + char file[128]; + + + sprintf(file,"p%05d", getpid()); + if ((fd = creat(file, 0660)) == -1) + err(1, "creat(%s)", file); + + to = sizeof(buf); + index = 0; + while (index < size) { + if (index + to > size) + to = size - index; +#ifdef TEST + for (i = 0; i < to; i++) + buf[i] = index + i; +#endif + index += to; + if (write(fd, buf, to) != to) + err(1, "write(%s), %s:%d", file, __FILE__, __LINE__); + } + if (close(fd) == -1) + err(1, "close(%s), %s:%d", file, __FILE__, __LINE__); + + if ((fd = open(file, O_RDONLY)) == -1) + err(1, "open(%s), %s:%d", file, __FILE__, __LINE__); + + index = 0; + while (index < size && done_testing == 0) { + if (index + to > size) + to = size - index; + if (read(fd, buf, to) != to) + err(1, "rw read. %s.%d", __FILE__, __LINE__); +#ifdef TEST + for (i = 0; i < to; i++) { + if (buf[i] != index + i) { + fprintf(stderr, + "%s, pid %d: expected %d @ %d, got %d\n", + getprogname(), getpid(), index+i, index+i, + buf[i]); + exit(EXIT_FAILURE); + } + } +#endif + index += to; + } + if (close(fd) == -1) + err(1, "close(%s), %s:%d", file, __FILE__, __LINE__); + if (unlink(file) == -1) + err(1, "unlink(%s), %s:%d", file, __FILE__, __LINE__); + return (0); +} diff --git a/test/stress/stress2/testcases/shm/Makefile b/test/stress/stress2/testcases/shm/Makefile new file mode 100644 index 0000000000..e30b93faba --- /dev/null +++ b/test/stress/stress2/testcases/shm/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +PROG= shm +LDADD= -lutil + +.include diff --git a/test/stress/stress2/testcases/shm/shm.c b/test/stress/stress2/testcases/shm/shm.c new file mode 100644 index 0000000000..3c6e1c9b45 --- /dev/null +++ b/test/stress/stress2/testcases/shm/shm.c @@ -0,0 +1,185 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Test shared memory */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +int shmid = -1; +key_t shmkey; +char *shm_buf; + +int semid = -1; +key_t semkey; +struct sembuf sop[2]; + +size_t pgsize; +pid_t pid; + +int +setup(int nb) +{ + int seed; + + pgsize = sysconf(_SC_PAGESIZE); + + seed = getpid(); +// printf("seed(%d) = %d\n", getpid(), seed); + shmkey = ftok("/tmp", seed); + if ((shmid = shmget(shmkey, 10 * pgsize, IPC_CREAT | IPC_EXCL | 0640)) == -1) { + if (errno == ENOSPC) { + fprintf(stderr, "Max number of semaphores reached.\n"); + exit(1); + } + err(1, "shmget (%s:%d)", __FILE__, __LINE__); + } + + shm_buf = 0; + if ((shm_buf = shmat(shmid, NULL, 0)) == (void *) -1) + err(1, "sender: shmat (%s:%d)", __FILE__, __LINE__); + +// printf("seed(%d) = %d\n", getpid(), seed); + semkey = ftok("/var", seed); + if ((semid = semget(semkey, 2, IPC_CREAT | IPC_EXCL | 0640)) == -1) { + if (errno == ENOSPC) { + fprintf(stderr, "Max number of semaphores reached.\n"); + exit(1); + } + err(1, "semget (%s:%d)", __FILE__, __LINE__); + } + /* Initialize the semaphore. */ + sop[0].sem_num = 0; + sop[0].sem_op = 0; /* This is the number of runs without queuing. */ + sop[0].sem_flg = 0; + sop[1].sem_num = 1; + sop[1].sem_op = 0; /* This is the number of runs without queuing. */ + sop[1].sem_flg = 0; + if (semop(semid, sop, 2) == -1) + err(1, "init: semop (%s:%d)", __FILE__, __LINE__); + return (0); +} + +void +cleanup(void) +{ + if (shmid != -1) + if (shmctl(shmid, IPC_RMID, NULL) == -1 && errno != EINVAL) + warn("shmctl IPC_RMID (%s:%d)", __FILE__, __LINE__); + if (semid != -1) + if (semctl(semid, 0, IPC_RMID, 0) == -1 && errno != EINVAL) + warn("shmctl IPC_RMID (%s:%d)", __FILE__, __LINE__); +} + +static void +Wait(int i) { + sop[0].sem_num = i; + sop[0].sem_op = -1; + if (semop(semid, sop, 1) == -1) { + if (errno != EINTR && errno != EIDRM && errno != EINVAL) + warn("Wait: semop (%s:%d)", __FILE__, __LINE__); + done_testing = 1; + } +} + +static void +Sig(int i) { + sop[0].sem_num = i; + sop[0].sem_op = 1; + if (semop(semid, sop, 1) == -1) { + if (errno != EINTR && errno != EIDRM && errno != EINVAL) + warn("Sig: semop (%s:%d)", __FILE__, __LINE__); + done_testing = 1; + } +} + +int +test(void) +{ + int i = 0; + + pid = fork(); + if (pid == -1) { + perror("fork"); + exit(2); + } + + if (pid == 0) { /* child */ + i = 0; + for (;;) { + Wait(1); + if (done_testing == 1) + break; + if (shm_buf[i] != (i % 128)) { + fprintf(stderr, + "child %d: expected %d, got %d\n", + getpid(), i % 128, shm_buf[i]); + break; + } + shm_buf[i] = 0; + i = (i + 1) % (10 * pgsize); + shm_buf[i] = (i % 128); + i = (i + 1) % (10 * pgsize); + Sig(0); + } + exit(0); + + } else { /* parent */ + i = 0; + for (;;) { + shm_buf[i] = (i % 128); + Sig(1); + i = (i + 1) % (10 * pgsize); + Wait(0); + if (done_testing == 1) + break; + if (shm_buf[i] != (i % 128)) { + fprintf(stderr, + "parent(%d): expected %d, got %d\n", + getpid(), i % 128, shm_buf[i]); + break; + } + shm_buf[i] = 0; + i = (i + 1) % (10 * pgsize); + } + kill(pid, SIGHUP); + kill(pid, SIGKILL); + } + return (0); +} diff --git a/test/stress/stress2/testcases/socket/Makefile b/test/stress/stress2/testcases/socket/Makefile new file mode 100644 index 0000000000..c31d950fdd --- /dev/null +++ b/test/stress/stress2/testcases/socket/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=socket + +.include diff --git a/test/stress/stress2/testcases/socket/socket.c b/test/stress/stress2/testcases/socket/socket.c new file mode 100644 index 0000000000..6a7dd9bdf9 --- /dev/null +++ b/test/stress/stress2/testcases/socket/socket.c @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +#define NB (400 * 1024 * 1024) + +int port; +int bufsize; +int sv[2]; + +static void +reader(void) { + int n, t, *buf; + + t = 0; + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + while (done_testing == 0) { + if ((n = read(sv[0], buf, bufsize)) < 0) + err(1, "read(), %s:%d", __FILE__, __LINE__); + t += n; + if (n == 0) break; + } + close(sv[0]); + return; +} + +static void +writer(void) { + int i, *buf, r; + + if (r < 0) + err(1, "connect(), %s:%d", __FILE__, __LINE__); + + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + for (i = 0; i < bufsize / sizeof(int); i++) + buf[i] = i; + + for (;;) { + for (i = 0; i < NB; i+= bufsize) { + if (write(sv[1], buf, bufsize) < 0) { + if (errno == EPIPE) + return; + err(1, "write(%d), %s:%d", sv[1], + __FILE__, __LINE__); + } + } + } + return; +} + +int +setup(int nb) +{ + port = 12340 + nb; + bufsize = 2 << random_int(2, 12); + return (0); +} + +void +cleanup(void) +{ +} + +int +test(void) +{ + pid_t pid; + + if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) != 0) + err(1, "socketpair()"); + if ((pid = fork()) == 0) { + writer(); + exit(EXIT_SUCCESS); + + } else if (pid > 0) { + reader(); + kill(pid, SIGINT); + } else + err(1, "fork(), %s:%d", __FILE__, __LINE__); + + return (0); +} diff --git a/test/stress/stress2/testcases/swap/Makefile b/test/stress/stress2/testcases/swap/Makefile new file mode 100644 index 0000000000..509db0ded5 --- /dev/null +++ b/test/stress/stress2/testcases/swap/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=swap + +.include diff --git a/test/stress/stress2/testcases/swap/swap.c b/test/stress/stress2/testcases/swap/swap.c new file mode 100644 index 0000000000..77d2bef1e1 --- /dev/null +++ b/test/stress/stress2/testcases/swap/swap.c @@ -0,0 +1,130 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "stress.h" + +static unsigned long size; + +int +setup(int nb) +{ + int pct; + unsigned long mem; + int64_t swapinfo = 0; + struct rlimit rlp; + + if (nb == 0) { + mem = usermem(); + swapinfo = swap(); + if (swapinfo > mem) + swapinfo = mem; + + if (op->hog == 0) + pct = random_int(1, 10); + + if (op->hog == 1) + pct = random_int(10, 20); + + if (op->hog == 2) + pct = random_int(80, 90); + + if (op->hog >= 3) + pct = random_int(100, 110); + + if (swapinfo == 0) + size = mem / 100 * pct; + else + size = swapinfo / 100 * pct + mem; + + size = size / op->incarnations; + + if (getrlimit(RLIMIT_DATA, &rlp) < 0) + err(1,"getrlimit"); + rlp.rlim_cur -= 1024 * 1024; + + if (size > rlp.rlim_cur) + size = rlp.rlim_cur; + putval(size); + + + if (op->verbose > 1 && nb == 0) + printf("setup: pid %d, %d%%. Total %luMb\n", + getpid(), pct, size / 1024 / 1024 * op->incarnations); + } else + size = getval(); + return (0); +} + +void +cleanup(void) +{ +} + +int +test(void) +{ + char *c; + int i, page; + unsigned long oldsize = size; + time_t start; + + c = malloc(size); + while (c == NULL && done_testing == 0) { + size -= 1024 * 1024; + c = malloc(size); + } + if (op->verbose > 1 && size != oldsize) + printf("Malloc size changed from %ld Mb to %ld Mb\n", + oldsize / 1024 / 1024, size / 1024 / 1024); + page = getpagesize(); + start = time(NULL); /* Livelock workaround */ + while (done_testing == 0 && + (time(NULL) - start) < op->run_time) { + i = 0; + while (i < size && done_testing == 0) { + c[i] = 0; + i += page; + } +#if 0 + if (op->hog != 1) + usleep(1000); +#endif + } + free(c); + + return (0); +} diff --git a/test/stress/stress2/testcases/symlink/Makefile b/test/stress/stress2/testcases/symlink/Makefile new file mode 100644 index 0000000000..77fe9e8d2a --- /dev/null +++ b/test/stress/stress2/testcases/symlink/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=symlink + +.include diff --git a/test/stress/stress2/testcases/symlink/symlink.c b/test/stress/stress2/testcases/symlink/symlink.c new file mode 100644 index 0000000000..9d955ae265 --- /dev/null +++ b/test/stress/stress2/testcases/symlink/symlink.c @@ -0,0 +1,137 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path[128]; +static unsigned long size; + +int +setup(int nb) +{ + int pct; + int64_t in; + int64_t bl; + int64_t reserve_in; + int64_t reserve_bl; + + umask(0); + if (nb == 0) { + getdf(&bl, &in); + size = in / op->incarnations; + + pct = 90; + if (op->hog == 0) + pct = random_int(1, 90); + size = size / 100 * pct + 1; + + if (size > 20000) + size = 20000; /* arbitrary limit number of files pr. dir */ + + /* Resource requirements: */ + while (size > 0) { + reserve_in = 1 * size * op->incarnations; + reserve_bl = 36 * size * op->incarnations; +// printf("size = %lu, reserve(%jd, %jd)\n", size, reserve_bl/1024, reserve_in); + if (reserve_bl <= bl && reserve_in <= in) + break; + size--; + } + if (size == 0) + reserve_bl = reserve_in = 0; + + if (op->verbose > 1) + printf("symlink(size=%lu, incarnations=%d). Free(%jdk, %jd), reserve(%jdk, %jd)\n", + size, op->incarnations, bl/1024, in, reserve_bl/1024, reserve_in); + reservedf(reserve_bl, reserve_in); + putval(size); + } else { + size = getval(); + } + + sprintf(path,"%s.%05d", getprogname(), getpid()); + if (mkdir(path, 0770) < 0) + err(1, "mkdir(%s), %s:%d", path, __FILE__, __LINE__); + + if (chdir(path) == -1) + err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__); + + return (0); +} + +void +cleanup(void) +{ + (void)chdir(".."); + if (rmdir(path) == -1) { + warn("rmdir(%s), %s:%d", path, __FILE__, __LINE__); + } +} + +int +test(void) +{ + int i, j, error = 0; + pid_t pid; + char file[128]; + + pid = getpid(); + for (j = 0; j < size && done_testing == 0; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if (symlink("/tmp/not/there", file) == -1) { + if (errno != EINTR) { + warn("symlink(%s). %s.%d", file, __FILE__, __LINE__); + error = 1; +/* printf("break out at %d, errno %d\n", j, errno);*/ + exit(1); + break; + } + } + if (j % 4000) sleep(1); + } + + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + } + + if (error != 0) + exit(1); + + return (0); +} diff --git a/test/stress/stress2/testcases/syscall/Makefile b/test/stress/stress2/testcases/syscall/Makefile new file mode 100644 index 0000000000..91bb2e5af6 --- /dev/null +++ b/test/stress/stress2/testcases/syscall/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=syscall + +.include diff --git a/test/stress/stress2/testcases/syscall/syscall.c b/test/stress/stress2/testcases/syscall/syscall.c new file mode 100644 index 0000000000..0392654348 --- /dev/null +++ b/test/stress/stress2/testcases/syscall/syscall.c @@ -0,0 +1,155 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Call random system calls with random arguments */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static char path[128]; +static int num; +static int starting_dir = 0; + +static int ignore[] = { + SYS_syscall, + SYS_exit, + SYS_fork, + 11, /* 11 is obsolete execv */ + SYS_unmount, + SYS_reboot, + SYS_vfork, + 109, /* 109 is old sigblock */ + 111, /* 111 is old sigsuspend */ + SYS_shutdown, + SYS___syscall, + SYS_rfork, + SYS_sigsuspend, +// SYS_mac_syscall, + SYS_sigtimedwait, + SYS_sigwaitinfo, +}; + +int +setup(int nb) +{ + int i; + struct rlimit rl; + + umask(0); + sprintf(path,"%s.%05d", getprogname(), getpid()); + (void)mkdir(path, 0770); + if (chdir(path) == -1) + err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__); + if ((starting_dir = open(".", 0)) < 0) + err(1, "."); + + if (op->argc == 1) { + num = atoi(op->argv[0]); + for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++) + if (num == ignore[i]) { + printf("syscall %d is marked a no test!\n", num); + exit(1); + } + } else { + num = 0; + while (num == 0) { + num = random_int(0, SYS_MAXSYSCALL); + for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++) + if (num == ignore[i]) { + num = 0; + break; + } + } + } + if (op->verbose > 1) + printf("Testing syscall #%d, pid %d\n", num, getpid()); + + /* Multiple parallel core dump may panic the kernel with: + panic: kmem_malloc(184320): kmem_map too small: 84426752 total allocated + */ + rl.rlim_max = rl.rlim_cur = 0; + if (setrlimit(RLIMIT_CORE, &rl) == -1) + warn("setrlimit"); + + setproctitle("#%d", num); + + return (0); +} + +void +cleanup(void) +{ + if (starting_dir != 0) { + if (fchdir(starting_dir) == -1) + err(1, "fchdir()"); + (void)system("find . -type d -exec chmod 777 {} \\;"); + (void)system("find . -type f -exec chmod 666 {} \\;"); + (void)system("find . -delete"); + + if (chdir("..") == -1) + err(1, "chdir(..)"); + if (rmdir(path) == -1) + err(1, "rmdir(%s), %s:%d", path, __FILE__, __LINE__); + } + starting_dir = 0; +} + +int +test(void) +{ + int i; + unsigned int arg1, arg2, arg3, arg4, arg5, arg6, arg7; + + for (i = 0; i < 128; i++) { + arg1 = arc4random(); + arg2 = arc4random(); + arg3 = arc4random(); + arg4 = arc4random(); + arg5 = arc4random(); + arg6 = arc4random(); + arg7 = arc4random(); + + if (op->verbose > 3) + printf("%2d : syscall(%3d, %x, %x, %x, %x, %x, %x, %x)\n", + i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + } +#if 0 + while (done_testing == 0) + sleep(1); +#endif + + return (0); +} diff --git a/test/stress/stress2/testcases/sysctl/Makefile b/test/stress/stress2/testcases/sysctl/Makefile new file mode 100644 index 0000000000..3785ed3d46 --- /dev/null +++ b/test/stress/stress2/testcases/sysctl/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG= sysctl + +.include diff --git a/test/stress/stress2/testcases/sysctl/sysctl.c b/test/stress/stress2/testcases/sysctl/sysctl.c new file mode 100644 index 0000000000..231de58e4c --- /dev/null +++ b/test/stress/stress2/testcases/sysctl/sysctl.c @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +/* Call sysctl(8) and fstat(1) a few times */ + +#include +#include +#include +#include + +#include "stress.h" + +int +setup(int nb) +{ + return (0); +} + +void +cleanup(void) +{ +} + + +int +test(void) +{ + int i; + + for (i = 0; i < 64 && done_testing == 0; i++) { + if (system("sysctl -a > /dev/null 2>&1") == -1) + err(1, "system(\"sysctl -a\"), %s:%d", __FILE__, __LINE__); + + if (system("fstat > /dev/null 2>&1") == -1) + err(1, "system(\"fstat\"), %s:%d", __FILE__, __LINE__); + sleep(1); + } + return (0); +} diff --git a/test/stress/stress2/testcases/tcp/Makefile b/test/stress/stress2/testcases/tcp/Makefile new file mode 100644 index 0000000000..941c2863c4 --- /dev/null +++ b/test/stress/stress2/testcases/tcp/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=tcp + +.include diff --git a/test/stress/stress2/testcases/tcp/tcp.c b/test/stress/stress2/testcases/tcp/tcp.c new file mode 100644 index 0000000000..92e006c665 --- /dev/null +++ b/test/stress/stress2/testcases/tcp/tcp.c @@ -0,0 +1,179 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +#define NB (400 * 1024 * 1024) + +int port; +int bufsize; + +static void +reader(void) { + int tcpsock, msgsock; + int on; + socklen_t len; + struct sockaddr_in inetaddr, inetpeer; + int n, t, *buf; + + on = 1; + if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) + err(1, "socket(), %s:%d", __FILE__, __LINE__); + + if (setsockopt(tcpsock, + SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) + err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); + + inetaddr.sin_family = AF_INET; + inetaddr.sin_addr.s_addr = INADDR_ANY; + inetaddr.sin_port = htons(port); + inetaddr.sin_len = sizeof(inetaddr); + + if (bind(tcpsock, + (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) + err(1, "bind(), %s:%d", __FILE__, __LINE__); + + if (listen(tcpsock, 5) < 0) + err(1, "listen(), %s:%d", __FILE__, __LINE__); + + if ((random_int(1,100) > 60) || (op->hog == 1)) { + usleep(random_int(1000000,1000000) * 60); + } + + len = sizeof(inetpeer); + if ((msgsock = accept(tcpsock, + (struct sockaddr *)&inetpeer, &len)) < 0) + err(1, "accept(), %s:%d", __FILE__, __LINE__); + + t = 0; + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + while (done_testing == 0) { + if ((n = read(msgsock, buf, bufsize)) < 0) + err(1, "read(), %s:%d", __FILE__, __LINE__); + t += n; + if (n == 0) break; + } + close(msgsock); + return; +} + +static void +writer(void) { + int tcpsock, on; + struct sockaddr_in inetaddr; + struct hostent *hostent; + int i, *buf, r; + + on = 1; + for (i = 1; i < 5; i++) { + if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) + err(1, "socket(), %s:%d", __FILE__, __LINE__); + + if (setsockopt(tcpsock, + SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) + err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); + + hostent = gethostbyname ("localhost"); + memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, + sizeof (struct in_addr)); + + inetaddr.sin_family = AF_INET; + inetaddr.sin_addr.s_addr = INADDR_ANY; + inetaddr.sin_port = htons(port); + inetaddr.sin_len = sizeof(inetaddr); + + r = connect(tcpsock, (struct sockaddr *) &inetaddr, + sizeof(inetaddr)); + if (r == 0) + break; + sleep(1); + close(tcpsock); + } + if (r < 0) + err(1, "connect(), %s:%d", __FILE__, __LINE__); + + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + for (i = 0; i < bufsize / sizeof(int); i++) + buf[i] = i; + + for (;;) { + for (i = 0; i < NB; i+= bufsize) { + if (write(tcpsock, buf, bufsize) < 0) { + if (errno == EPIPE) + return; + err(1, "write(%d), %s:%d", tcpsock, + __FILE__, __LINE__); + } + } + } + return; +} + +int +setup(int nb) +{ + port = 12340 + nb; + bufsize = 2 << random_int(1, 12); + return (0); +} + +void +cleanup(void) +{ +} + +int +test(void) +{ + pid_t pid; + + if ((pid = fork()) == 0) { + writer(); + exit(EXIT_SUCCESS); + + } else if (pid > 0) { + reader(); + kill(pid, SIGINT); + } else + err(1, "fork(), %s:%d", __FILE__, __LINE__); + + return (0); +} diff --git a/test/stress/stress2/testcases/thr1/Makefile b/test/stress/stress2/testcases/thr1/Makefile new file mode 100644 index 0000000000..f9e5f5d39a --- /dev/null +++ b/test/stress/stress2/testcases/thr1/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +PROG= thr1 + +.include + +CFLAGS+= -pthread diff --git a/test/stress/stress2/testcases/thr1/thr1.c b/test/stress/stress2/testcases/thr1/thr1.c new file mode 100644 index 0000000000..d86b9f49bd --- /dev/null +++ b/test/stress/stress2/testcases/thr1/thr1.c @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +#define NTHREADS 256 + +int +setup(int nb) +{ + return (0); +} + +void +cleanup(void) +{ +} + +void * +thr_routine(void *arg) +{ + (void) getpid(); + return (0); +} + +int +test(void) +{ + pthread_t threads[NTHREADS]; + int i; + int r; + + for (i = 0; i < NTHREADS; i++) + if ((r = pthread_create(&threads[i], NULL, thr_routine, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + + for (i = 0; i < NTHREADS; i++) + if (pthread_join(threads[i], NULL) != 0) + err(1, "pthread_join(%d)", i); + + return (0); +} diff --git a/test/stress/stress2/testcases/thr2/Makefile b/test/stress/stress2/testcases/thr2/Makefile new file mode 100644 index 0000000000..efa1aec14d --- /dev/null +++ b/test/stress/stress2/testcases/thr2/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +PROG= thr2 + +.include + +CFLAGS+= -pthread diff --git a/test/stress/stress2/testcases/thr2/thr2.c b/test/stress/stress2/testcases/thr2/thr2.c new file mode 100644 index 0000000000..052cbd5317 --- /dev/null +++ b/test/stress/stress2/testcases/thr2/thr2.c @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +#define NTHREADS 256 + +volatile int done = 0; + +int +setup(int nb) +{ + return (0); +} + +void +cleanup(void) +{ +} + +void * +thr1(void *arg) +{ + return (0); +} + +void * +thr2(void *arg) +{ + while (done == 0) + pthread_yield(); + return (0); +} + +int +test(void) +{ + pthread_t threads[NTHREADS]; + int i; + int r; + + for (i = 0; i < NTHREADS; i++) + if ((r = pthread_create(&threads[i], NULL, thr1, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + + for (i = 0; i < NTHREADS; i++) + if (pthread_join(threads[i], NULL) != 0) + err(1, "pthread_join(%d)", i); + + for (i = 0; i < NTHREADS; i++) + if ((r = pthread_create(&threads[i], NULL, thr2, 0)) != 0) + err(1, "pthread_create(): %s\n", strerror(r)); + done = 1; + + for (i = 0; i < NTHREADS; i++) + if (pthread_join(threads[i], NULL) != 0) + err(1, "pthread_join(%d)", i); + + return (0); +} diff --git a/test/stress/stress2/testcases/udp/Makefile b/test/stress/stress2/testcases/udp/Makefile new file mode 100644 index 0000000000..442ed66cca --- /dev/null +++ b/test/stress/stress2/testcases/udp/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +PROG=udp + +.include diff --git a/test/stress/stress2/testcases/udp/udp.c b/test/stress/stress2/testcases/udp/udp.c new file mode 100644 index 0000000000..9a75b0ea1f --- /dev/null +++ b/test/stress/stress2/testcases/udp/udp.c @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +/*#include */ +#include +#include +#include +#include +#include +#include +#include + +#include "stress.h" + +static int bufsize; + +int +setup(int nb) +{ + bufsize = 2 << random_int(1, 12); + return (0); +} + +void +cleanup(void) +{ +} + +int +test(void) +{ + struct sockaddr_in sock_in; + struct hostent *host; + char *hostname; + int f, i, n; + int *buf; + + bzero((char *)&sock_in, sizeof(sock_in)); + sock_in.sin_family = AF_INET; + f = socket(AF_INET, SOCK_DGRAM, 0); + if (f < 0) + err(1, "socket"); + if (bind(f, (struct sockaddr *)&sock_in, sizeof(sock_in)) < 0) { + warn("bind"); + return (1); + } + if (getenv("BLASTHOST") == NULL) + hostname = "localhost"; + else + hostname = getenv("BLASTHOST"); + host = gethostbyname(hostname); + if (host) { + sock_in.sin_family = host->h_addrtype; + bcopy(host->h_addr, &sock_in.sin_addr, host->h_length); + } else { + sock_in.sin_family = AF_INET; + sock_in.sin_addr.s_addr = inet_addr(hostname); + if (sock_in.sin_addr.s_addr == -1) { + err(1, "host: %s", hostname); + } + } + sock_in.sin_port = htons(9); + + if (connect(f, (struct sockaddr *)&sock_in, sizeof(sock_in)) < 0) + err(1, "connect"); + + if ((buf = calloc(1, bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + + if (op->verbose > 1) + printf("udp %s:9 with %d bytes\n", hostname, bufsize); + for (i = 0; i < 128 && done_testing == 0; i++) { + n = write(f, buf, bufsize); + if (n == -1 && errno == ENOBUFS) + continue; + if (n == -1 && errno == ECONNREFUSED) + break; + if (n == -1) + err(1, "write(%d) #%d", bufsize, i); + if (n == 0) break; + } + free(buf); + close(f); + return (0); +} diff --git a/test/stress/stress2/tools/df.sh b/test/stress/stress2/tools/df.sh new file mode 100755 index 0000000000..7389ec0580 --- /dev/null +++ b/test/stress/stress2/tools/df.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Trace the df of RUNDIR + +. ../default.cfg + +old=x +while true;do + d=`df -i $RUNDIR | tail -1` + p1=`echo $d | awk '{print $5}' | sed 's/\%//'` + p2=`echo $d | awk '{print $8}' | sed 's/\%//'` + [ $p1 -lt 80 -a $p2 -lt 80 -a $old != x ] && continue + [ "$old" != "$d" ] && echo `date '+%T'` $d + old=$d + sleep 30 +done diff --git a/test/stress/stress2/tools/freeze.sh b/test/stress/stress2/tools/freeze.sh new file mode 100755 index 0000000000..de37b67419 --- /dev/null +++ b/test/stress/stress2/tools/freeze.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Freeze detection script + +while true; do + t1=`date '+%s'` + sleep 60 + t2=`date '+%s'` + delta=$((t2 - $t1)) + if [ $delta -gt 120 ]; then + d1=`date -j -f '%s' '+%T' $t1` + d2=`date -j -f '%s' '+%T' $t2` + e=` date -u -j -f '%s' '+%T' $delta` + echo "Freeze from $d1 to $d2, $e elapsed." + fi +done diff --git a/test/stress/stress2/tools/freeze2.sh b/test/stress/stress2/tools/freeze2.sh new file mode 100755 index 0000000000..7225665b77 --- /dev/null +++ b/test/stress/stress2/tools/freeze2.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Freeze detection script + +while true; do + t1=`date '+%s'` + ls -l /var > /dev/null + sleep 30 + t2=`date '+%s'` + delta=$((t2 - $t1)) + if [ $delta -gt 120 ]; then + d1=`date -j -f '%s' '+%T' $t1` + d2=`date -j -f '%s' '+%T' $t2` + e=` date -u -j -f '%s' '+%T' $delta` + echo "Freeze from $d1 to $d2, $e elapsed." + fi +done diff --git a/test/stress/stress2/tools/fstool.c b/test/stress/stress2/tools/fstool.c new file mode 100644 index 0000000000..90eecebff7 --- /dev/null +++ b/test/stress/stress2/tools/fstool.c @@ -0,0 +1,193 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static int files = 5; +static int fs = 1024; +static char *buffer; +static int max; + +void +error(char *op, char* arg, char* file, int line) { + fprintf(stderr,"%s. %s. %s (%s:%d)\n", + op, arg, sys_errlist[errno], file, line); +} + +void +mkDir(char *path, int level) { + int fd, j; + char newPath[MAXPATHLEN + 1]; + char file[128]; + + if (mkdir(path, 0770) == -1) { + error("mkdir", path, __FILE__, __LINE__); + fprintf(stderr, "length(path) = %d\n", strlen(path)); + fprintf(stderr, ") level = %d\n", level); + exit(2); + } + chdir(path); + + for (j = 0; j < files; j++) { + sprintf(file,"f%05d", j); + if ((fd = creat(file, 0660)) == -1) { + if (errno != EINTR) { + err(1, "%d: creat(%s)", level, file); + break; + } + } + if (write(fd, buffer, fs) != fs) + err(1, "%d: write(%s), %s:%d", level, file, __FILE__, __LINE__); + + if (fd != -1 && close(fd) == -1) + err(2, "%d: close(%d)", level, j); + + } + + if (level < max) { + sprintf(newPath,"d%d", level+1); + mkDir(newPath, level+1); + } +} + +static void +rmFile(void) +{ + int j; + char file[128]; + + for (j = 0; j < files; j++) { + sprintf(file,"f%05d", j); + (void) unlink(file); + } +} + +void +rmDir(char *path, int level) { + char newPath[10]; + + + if (level < max) { + sprintf(newPath,"d%d", level+1); + rmDir(newPath, level+1); + } + rmFile(); + chdir (".."); + if (rmdir(path) == -1) { + error("rmdir", path, __FILE__, __LINE__); + exit(2); + } +} + +void +rmDir2(char *path, int level) { + char newPath[10]; + char help[80]; + + rmFile(); + chdir(path); + sprintf(newPath,"d%d", level+1); + if (access(newPath, R_OK) == 0) + rmDir2(newPath, level+1); + chdir (".."); + if (rmdir(path) == -1) { + error("rmdir", path, __FILE__, __LINE__); + sprintf(help, "rm -rf ./%s", path); + system(help); + } +} + +int +main(int argc, char **argv) +{ + int c, levels = 1, leave = 0; + char path[128], rpath[128] = ""; + char ch = 0; + extern char *optarg; + pid_t pid; + + while ((c = getopt(argc, argv, "ln:r:f:s:")) != -1) + switch (c) { + case 'l': + leave = 1; + break; + case 'r': + strcpy(rpath, optarg); + break; + case 'n': + levels = atoi(optarg); + break; + case 'f': + files = atoi(optarg); + break; + case 's': + sscanf(optarg, "%d%c", &fs, &ch); + if (ch == 'k' || ch == 'K') + fs = fs * 1024; + if (ch == 'm' || ch == 'M') + fs = fs * 1024 * 1024; + break; + default: + fprintf(stderr, + "Usage: %s {-l} | {-n } | -r | -s " + "-f \n", + argv[0]); + printf(" -l: Leave the files.\n"); + printf(" -r: Remove an old tree.\n"); + printf(" -n: Tree depth.\n"); + printf(" -f: Number of files.\n"); + printf(" -s: Size of each file.\n"); + exit(1); + } + + + max = levels; + pid = getpid(); + if ((buffer = calloc(1, fs)) == NULL) + err(1, "calloc(%d)", fs); + + if (strlen(rpath) > 0) { + rmDir2(rpath,1); + } else { + umask(0); + sprintf(path,"p%05d.d%d", pid, 1); + mkDir(path, 1); + if (leave == 0) rmDir(path, 1); + } + return 0; +} diff --git a/test/stress/stress2/tools/iwatch.sh b/test/stress/stress2/tools/iwatch.sh new file mode 100755 index 0000000000..18c8a29805 --- /dev/null +++ b/test/stress/stress2/tools/iwatch.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Watch max inode usage in RUNDIR + +. ../default.cfg + +[ ! -d $RUNDIR ] && mkdir $RUNDIR +imax=0 +kmax=0 +istart=`df -ik $RUNDIR | tail -1 | awk '{print $6}'` +kstart=`df -ik $RUNDIR | tail -1 | awk '{print $3}'` +while true;do + i=`df -ik $RUNDIR | tail -1 | awk '{print $6}'` + k=`df -ik $RUNDIR | tail -1 | awk '{print $3}'` + if [ $i -gt $imax -o $k -gt $kmax ]; then + imax=$i + kmax=$k + printf "%s %d %dk (%d %dk)\n" `date '+%T'` $i $k $((imax - istart)) $((kmax - kstart)) + fi + sleep 1 +done diff --git a/test/stress/stress2/tools/l3.sh b/test/stress/stress2/tools/l3.sh new file mode 100755 index 0000000000..7967b59a9a --- /dev/null +++ b/test/stress/stress2/tools/l3.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Script to catch possible leaks in vm, malloc and mbufs + +i=0 +while true; do + sysctl vm.kvm_free | tail -1 | sed 's/:/,/' + vmstat -z | grep VNODE: | awk '{print $1 "," $4}' | sed 's/,$//' + sleep 1 +done | awk -F, ' +{ +# Pairs of "name, value" are passed to this awk script + name=$1 + size=$2 + if (NF != 2) + print "Number of fields for ", name, "is ", NF + if (size == s[name]) + next; +# print "name, size, old minimum :", name, size, s[name] + + if ((size < s[name]) || (f[name] == 0)) { +# print "Initial value / new minimum", n[name], s[name], size + n[name] = 0 + s[name] = size + f[name] = 1 + } + + if (++n[name] > 120) { + cmd="date '+%T'" + cmd | getline t + close(cmd) + if (++w[name] > 10) + printf "%s \"%s\" may be leaking, size %d\n", t, name, size + n[name] = 0 + s[name] = size + } +}' diff --git a/test/stress/stress2/tools/leaks.sh b/test/stress/stress2/tools/leaks.sh new file mode 100755 index 0000000000..217ad0c14b --- /dev/null +++ b/test/stress/stress2/tools/leaks.sh @@ -0,0 +1,118 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Script to catch possible leaks in vm, malloc and mbufs +# Report values growing in 10 consecuitive samples + +i=0 +while true; do + # Check for leaks in vm.zone + +# ITEM SIZE LIMIT USED FREE REQUESTS +# +# UMA Kegs: 140, 0, 66, 6, 66 +# UMA Zones: 120, 0, 66, 24, 66 + + + vmstat -z | sed '1,3d;s/://g' | \ + sed 's/ */ /g;s/\([0-9]\) *\([0-9]\)/\1,\2/g;s/ \([0-9]\)/,\1/;s/^ *//' | \ + awk -F, ' +/^..*$/{ + gsub("^ *", "", $1); + size=$4; + printf "vmstat -z %s,%s\n", $1, size; +} +' + # vmstat -m + + # Type InUse MemUse HighUse Requests Size(s) + # DEVFS3 168 21K - 169 128 + # DEVFS1 157 40K - 157 256 + # DEVFS 12 1K - 13 16,128 + vmstat -m | \ + sed '1,1d;s/K .*//;s/ [0-9][0-9]* //;s/ */ /g;s/^ *//;s/ /_/g;s/_\([0-9][0-9]*$\)/ \1/' | \ + awk '{printf "vmstat -m %s, %d\n", $1, $2}' + + # Check for leaks in mbufs + +# $ netstat -m +# 1233/597/1830 mbufs in use (current/cache/total) +# 1232/196/1428/8896 mbuf clusters in use (current/cache/total/max) +# 1232/74 mbuf+clusters out of packet secondary zone in use (current/cache) +# 0/0/0/0 4k (page size) jumbo clusters in use (current/cache/total/max) +# 0/0/0/0 9k jumbo clusters in use (current/cache/total/max) +# 0/0/0/0 16k jumbo clusters in use (current/cache/total/max) +# 2772K/541K/3313K bytes allocated to network (current/cache/total) +# 508/7778/5734 requests for mbufs denied (mbufs/clusters/mbuf+clusters) +# 0/0/0 requests for jumbo clusters denied (4k/9k/16k) +# 0/6/2480 sfbufs in use (current/peak/max) +# 0 requests for sfbufs denied +# 0 requests for sfbufs delayed +# 0 requests for I/O initiated by sendfile +# 251 calls to protocol drain routines + + + netstat -m | head -10 | sed 's#/# #g;s/k / /;s/K / /' | awk ' +/mbufs / {mbufs=$1}; +/ clusters/ {clusters=$2}; +/sfbufs in use/ {sfbufs=$3}; +/allocated/ {allocated=$1} +END { + print "mbufs,", mbufs; + print "clusters,", clusters; + print "sfbufs,", sfbufs; + print "allocatedToNetwork,", allocated; +} +' + sysctl vm.kvm_free | tail -1 | sed 's/:/,/' + sleep 10 +done | awk -F, ' +{ +# Pairs of "name, value" are passed to this awk script + name=$1; + size=$2; +# print "name, size :", name, size; + if (NF != 2) + print "Number of fields for ", name, "is ", NF; + if (size > s[name]) { + n[name]++; + if (n[name] > 10) { + cmd="date '+%T'"; + cmd | getline t; + close(cmd); + printf "%s \"%s\" may be leaking, size %d\n", t, name, size; + n[name] = 0; + } + s[name] = size; + } else { + if (n[name] > 0) + n[name]--; + } +}' diff --git a/test/stress/stress2/tools/leaks2.sh b/test/stress/stress2/tools/leaks2.sh new file mode 100755 index 0000000000..7adcd4b4a4 --- /dev/null +++ b/test/stress/stress2/tools/leaks2.sh @@ -0,0 +1,117 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Script to catch possible leaks in vm, malloc and mbufs +# This version looks for increse in minimum values + +i=0 +while true; do + # Check for leaks in vm.zone + +# ITEM SIZE LIMIT USED FREE REQUESTS +# +# UMA Kegs: 140, 0, 66, 6, 66 +# UMA Zones: 120, 0, 66, 24, 66 + + + vmstat -z | sed '1,3d;s/://g' | \ + sed 's/ */ /g;s/\([0-9]\) *\([0-9]\)/\1,\2/g;s/ \([0-9]\)/,\1/;s/^ *//' | \ + awk -F, ' +/^..*$/{ + gsub("^ *", "", $1); + size=$4; + printf "vmstat -z %s,%s\n", $1, size; +} +' + # Check for leaks in mbufs + +# $ netstat -m +# 1233/597/1830 mbufs in use (current/cache/total) +# 1232/196/1428/8896 mbuf clusters in use (current/cache/total/max) +# 1232/74 mbuf+clusters out of packet secondary zone in use (current/cache) +# 0/0/0/0 4k (page size) jumbo clusters in use (current/cache/total/max) +# 0/0/0/0 9k jumbo clusters in use (current/cache/total/max) +# 0/0/0/0 16k jumbo clusters in use (current/cache/total/max) +# 2772K/541K/3313K bytes allocated to network (current/cache/total) +# 508/7778/5734 requests for mbufs denied (mbufs/clusters/mbuf+clusters) +# 0/0/0 requests for jumbo clusters denied (4k/9k/16k) +# 0/6/2480 sfbufs in use (current/peak/max) +# 0 requests for sfbufs denied +# 0 requests for sfbufs delayed +# 0 requests for I/O initiated by sendfile +# 251 calls to protocol drain routines + + + netstat -m | head -10 | sed 's#/# #g;s/k / /;s/K / /' | awk ' +/mbufs / {mbufs=$1}; +/ clusters/ {clusters=$2}; +/sfbufs in use/ {sfbufs=$3}; +/allocated/ {allocated=$1} +END { + print "mbufs,", mbufs; + print "clusters,", clusters; + print "sfbufs,", sfbufs; + print "allocatedToNetwork,", allocated; +} +' +# sysctl vm.kvm_free | tail -1 | sed 's/:/,/' # Need used here! + sleep 1 +done | awk -F, ' +{ +# Pairs of "name, value" are passed to this awk script + name=$1 + size=$2 + if (NF != 2) + print "Number of fields for ", name, "is ", NF + if (size == s[name]) + next; +# print "name, size, old minimum :", name, size, s[name] + + if ((size - 10 < s[name]) || (f[name] == 0)) { +# print "Initial value / new minimum", n[name], s[name], size + n[name] = 0 + if (f[name] == 0) + f[name] = 1 + if (f[name] != 2) + s[name] = size + } + + if (++n[name] > 120) { + cmd="date '+%T'" + cmd | getline t + close(cmd) +# if (++w[name] > 4) { + printf "%s \"%s\" may be leaking, size %d\n", t, name, size + f[name] = 2 +# } + n[name] = 0 + s[name] = size + } +}' diff --git a/test/stress/stress2/tools/module/Makefile b/test/stress/stress2/tools/module/Makefile new file mode 100644 index 0000000000..e78be1c481 --- /dev/null +++ b/test/stress/stress2/tools/module/Makefile @@ -0,0 +1,8 @@ +# $FreeBSD$ + +KMOD= ptest +SRCS= ptest.c + +CFLAGS+=-g + +.include diff --git a/test/stress/stress2/tools/module/ptest.c b/test/stress/stress2/tools/module/ptest.c new file mode 100644 index 0000000000..68df24a842 --- /dev/null +++ b/test/stress/stress2/tools/module/ptest.c @@ -0,0 +1,96 @@ +/*- + * Copyright (c) 2008 Peter Holm + * 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 AUTHOR 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 AUTHOR 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +static int panic_type = 0; + +static int +sysctl_panic_type(SYSCTL_HANDLER_ARGS) +{ + int error, value; + volatile int i; + + /* Write out the old value. */ + error = SYSCTL_OUT(req, &panic_type, sizeof(int)); + if (error || req->newptr == NULL) + return (error); + + /* Read in and verify the new value. */ + error = SYSCTL_IN(req, &value, sizeof(int)); + if (error) + return (error); + if (value < 0) + return (EINVAL); + panic_type = value; + + if (panic_type == 1) + panic("Test panic type 1"); + + if (panic_type == 2) + i = *(int *)0; /* Fatal trap */ + + return (0); +} + + +SYSCTL_PROC(_debug, OID_AUTO, panic_type, CTLTYPE_INT|CTLFLAG_RW, + &panic_type, 0, sysctl_panic_type, "I", + "Test panic type"); + + +static int +ptest_modevent(module_t mod, int what, void *arg) +{ + switch (what) { + case MOD_LOAD: + return(0); + case MOD_UNLOAD: + return (0); + default: + break; + } + + return (0); +} + +moduledata_t ptest_mdata = { + "ptest", + ptest_modevent, + NULL +}; + +DECLARE_MODULE(ptest, ptest_mdata, SI_SUB_DRIVERS, SI_ORDER_ANY); +MODULE_VERSION(ptest, 1); diff --git a/test/stress/stress2/tools/monitor.sh b/test/stress/stress2/tools/monitor.sh new file mode 100755 index 0000000000..b0217b1bb6 --- /dev/null +++ b/test/stress/stress2/tools/monitor.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Script to monitor test box + +font="fixed" +xterm -geo 164x21+1+1 -fn "$font" \ + -T top \ + -e "sh -c \"ssh -t crashbox 'top -s 1';sleep 36000\""& +xterm -geo 164x5+1+307 -fn "$font" \ + -T leaks.sh \ + -e "sh -c \"ssh -n crashbox '~pho/stress2/tools/leaks.sh';sleep 36000\""& +xterm -geo 164x14+1+405 -fn "$font" \ + -T 'tail -F /var/log/messages' \ + -e "sh -c \"ssh crashbox 'tail -F /var/log/messages';sleep 36000\""& diff --git a/test/stress/stress2/tools/ptsleak.sh b/test/stress/stress2/tools/ptsleak.sh new file mode 100755 index 0000000000..147e5f3388 --- /dev/null +++ b/test/stress/stress2/tools/ptsleak.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Keep count of pts that hasn't been in use for the last 15 minutes + +max=0 +while true; do + n=`find /dev/pts -mtime +15m 2>/dev/null | wc -l` + if [ $n -gt $max ]; then + max=$n + echo "`date '+%T'` $n" + fi + sleep 30 +done diff --git a/test/stress/stress2/tools/ptyleak.sh b/test/stress/stress2/tools/ptyleak.sh new file mode 100755 index 0000000000..e4fa3f824c --- /dev/null +++ b/test/stress/stress2/tools/ptyleak.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Keep count of ptys that hasn't been in use for the last 15 minutes + +max=0 +while true; do + n=`find /dev -mtime +15m 2>/dev/null | \ + egrep "/dev/pty[p-sP-S][0-9a-v]|/dev/tty[p-sP-S][0-9a-v]" | wc -l` + if [ $n -gt $max ]; then + max=$n + echo "`date '+%T'` $n" + fi + sleep 30 +done diff --git a/test/stress/stress2/tools/rwatch.sh b/test/stress/stress2/tools/rwatch.sh new file mode 100755 index 0000000000..4f699b3f75 --- /dev/null +++ b/test/stress/stress2/tools/rwatch.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# +# Copyright (c) 2008 Peter Holm +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ +# + +# Watch disk resources for a test program + +. ../../default.cfg + +unset LOAD +unset runLOAD +unset swapLOAD +unset rwLOAD +unset mkdirLOAD +unset creatLOAD +unset symlinkLOAD + +[ ! -d $RUNDIR ] && mkdir $RUNDIR +imax=0 +kmax=0 +istart=`df -ik $RUNDIR | tail -1 | awk '{print $6}'` +kstart=`df -ik $RUNDIR | tail -1 | awk '{print $3}'` + +"$@" & + +while ps -p $! > /dev/null; do + i=`df -ik $RUNDIR | tail -1 | awk '{print $6}'` + k=`df -ik $RUNDIR | tail -1 | awk '{print $3}'` + if [ $i -gt $imax -o $k -gt $kmax ]; then + imax=$i + kmax=$k + fi + sleep 1 +done +printf "Disk usage: %d inodes and %dk\n" $((imax - istart)) $((kmax - kstart)) +wait diff --git a/test/stress/stress2/udp.cfg b/test/stress/stress2/udp.cfg new file mode 100644 index 0000000000..eb9460fc4d --- /dev/null +++ b/test/stress/stress2/udp.cfg @@ -0,0 +1,11 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +# Only run these three test programs for VFS tests + +export udpLOAD=100 +export TESTPROGS="testcases/swap/swap testcases/udp/udp" diff --git a/test/stress/stress2/vfs.cfg b/test/stress/stress2/vfs.cfg new file mode 100644 index 0000000000..ab17b5c407 --- /dev/null +++ b/test/stress/stress2/vfs.cfg @@ -0,0 +1,10 @@ +# $FreeBSD$ + +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +# Only run these three test programs for VFS tests + +export TESTPROGS="testcases/swap/swap testcases/creat/creat testcases/mkdir/mkdir"