diff --git a/tools/test/README b/tools/test/README index 2bafa48a9764..5512fd5203ba 100644 --- a/tools/test/README +++ b/tools/test/README @@ -21,5 +21,6 @@ ppsapi Test 1 Pulse Per Second (1PPS) input for time control. pthread_vfork Check that vfork and pthreads work together. ptrace Verify that ptrace works with syscalls, vfork etc. sort Tests for the sort command, including a full regression. +stress2 Kernel stress tool. testfloat Programs to test floating-point implementations upsdl Test of mmap functionality. diff --git a/tools/test/stress2/Makefile b/tools/test/stress2/Makefile new file mode 100644 index 000000000000..ce98559377b9 --- /dev/null +++ b/tools/test/stress2/Makefile @@ -0,0 +1,11 @@ +SUBDIR= lib testcases +MK_AUTO_OBJ= no + +.include + +all: setup + +setup: + @cd ${.CURDIR}; ./tools/setup.sh +test: + cd ${.CURDIR}/misc; pwd; ./all.sh -onc diff --git a/tools/test/stress2/README b/tools/test/stress2/README new file mode 100644 index 000000000000..ddc8db817ce2 --- /dev/null +++ b/tools/test/stress2/README @@ -0,0 +1,20 @@ +stress2 is a tool for finding problems in the kernel. + +It is composed of a large number of regression tests, tests that +stress various components of the kernel and a few validation tests. +There are currently some 700 different tests. + +The key idea behind stress2 is to randomize as much as possible in +a test, as a way of achieving better coverage. For example, varying +VM pressure, varying numbers of threads, varying delays, etc. +stress2 has found a large number of problems: +https://people.freebsd.org/~pho/stress/log/ + +To run the full test suite type "make test" in the stress2 directory. + +To run a subset of tests, go to the stress2/misc directory. + To run for example all tmpfs tests, type ./all.sh -o $(grep -l tmpfs *.sh) + To run fdatasync.sh for one hour, type ./all.sh -m 60 fdatasync.sh" + To run dup2.sh three times, type ./all.sh -l 3 dup2.sh + +Peter Holm diff --git a/tools/test/stress2/all.cfg b/tools/test/stress2/all.cfg new file mode 100644 index 000000000000..562ed767a110 --- /dev/null +++ b/tools/test/stress2/all.cfg @@ -0,0 +1,8 @@ +# Stress Test Suite Configuration: run all test programs + +# Default values +. ./default.cfg + +export TESTPROGS="" +export swapHOG=1 +export swapLOAD=100 diff --git a/tools/test/stress2/creat.cfg b/tools/test/stress2/creat.cfg new file mode 100644 index 000000000000..dc5931564ffd --- /dev/null +++ b/tools/test/stress2/creat.cfg @@ -0,0 +1,8 @@ +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +export TESTPROGS="testcases/creat/creat" +export creatNODELAY=1 +export creatLOAD=100 diff --git a/tools/test/stress2/ddb.conf b/tools/test/stress2/ddb.conf new file mode 100644 index 000000000000..d0805f5640b8 --- /dev/null +++ b/tools/test/stress2/ddb.conf @@ -0,0 +1,6 @@ +# ddb commands used for stress2 crash reports +# + +script pho1=bt; show allpcpu; show alllocks; show lockedvnods; show allchains; show mount; show bufqueues; show page; show pageq +script pho=set $lines 20000; run pho1; show freepages; acttrace; ps; allt; dump + diff --git a/tools/test/stress2/default.cfg b/tools/test/stress2/default.cfg new file mode 100644 index 000000000000..43b89dc7e160 --- /dev/null +++ b/tools/test/stress2/default.cfg @@ -0,0 +1,122 @@ +# Stress Test Suite Configuration. + +# Changes should be added to a `hostname` file in this directory. +# As a minimum you must updated "testuser". + +export SHELL=/bin/sh +: ${allconfig:=/tmp/stress2.d/`hostname`} +[ -f "$allconfig" ] && . $allconfig # Source in local configuration + +# Default values +export RUNDIR=${RUNDIR:-/tmp/stressX} +export RUNTIME=${RUNTIME:-2m} +export VERBOSE=${VERBOSE:-1} +export LOAD=${LOAD:-20} + +# The INCARNATIONS variable may be set to match the number of CPUs and +# the amount of RAM in the test box. +export INCARNATIONS=${INCARNATIONS:-20} + +export BLASTHOST=${BLASTHOST:-192.168.1.1} # host with udp discard enabled in inetd.conf +#export nfs_export=somehost:mount # Used by the NFS tests + +# Run all test cases: +export runRUNTIME=${runRUNTIME:-3d} # Run tests for three days +export runINCARNATIONS=1 +export runLOAD=100 + +export swapINCARNATIONS=${swapINCARNATIONS:-$((2 * INCARNATIONS))} +export swapLOAD=${swapLOAD:-80} + +export syscallKILL=1 +export swapKILL=1 # May takes a long time to stop + +export rwLOAD=${rwLOAD:-70} +export mkdirLOAD=${mkdirLOAD:-80} +export creatLOAD=${creatLOAD:-80} + +export symlinkLOAD=${symlinkLOAD:-20} + +export tcpKILL=1 +export shmINCARNATIONS=${shmINCARNATIONS:-5} + +[ -z "$TESTPROGS" ] && export TESTPROGS=" +testcases/rw/rw +testcases/swap/swap +testcases/creat/creat +testcases/mkdir/mkdir +testcases/thr1/thr1 +testcases/udp/udp +testcases/tcp/tcp +" + +# +# Defaults for ./misc tests +# + +export diskimage=${diskimage:-/tmp/diskimage} # Location of 1G disk image +export mntpoint=${mntpoint:-/mnt} # Disk image mount point +export testuser=${testuser:-TBD} # Name of non root test user +export mdstart=${mdstart:-10} # Start of free md units +export part=${part:-a} # Partition to use on a md FS +export newfs_flags=${newfs_flags:-"-U"} # Default file system flags +export stress2origin=${stress2origin:-`pwd`} +export stress2tools=`dirname $stress2origin`/tools + +# fsck wrapper +checkfs () { + local s + + fsck -t ufs -fy $1 > /tmp/fsck.log 2>&1 + if grep -v "IS CLEAN" /tmp/fsck.log | \ + LANG=C egrep -q "[A-Z][A-Z]"; then + echo "fsck -t ufs -fy $1" + cat /tmp/fsck.log + s=1 + else + rm -f /tmp/fsck.log + s=0 + fi + return $s +} + +# Support for pre-build binaries for stress2/misc tests +# Build modes: +# 1 Build and copy binary to $STRESS2BIN +# 2 Do not compile; use binary from $STRESS2BIN + +# Examples: +# BMODE=1 ./all.sh -on `grep -lw mycc *.sh` +# BMODE=2 STRESS2BIN=/home/pho/stress2/bin.i386.r276368 ./all.sh + +CC=${CC:-cc} +top=`dirname $(pwd)` # cwd for the all.sh script +STRESS2BIN=${STRESS2BIN:-$top/bin} +mycc () { # "-o" must be first argument + local file + + [ "$1" = "-o" ] && file=`basename $2` + if [ "$BMODE" = "1" ]; then + $CC $@ || return + [ -z "$file" ] && return # "-c" + [ -d $STRESS2BIN ] || mkdir $STRESS2BIN + [ -x $STRESS2BIN/$file ] && + echo "Overwriting $STRESS2BIN/$file" + echo "cp $2 $STRESS2BIN" + cp $2 $STRESS2BIN + exit 0 # Build but do not run the test + elif [ "$BMODE" = "2" ]; then + [ -z "$file" ] && return + if [ ! -x $STRESS2BIN/$file ]; then + echo "$STRESS2BIN/$file not found" + exit 1 + fi + echo "Using binary $STRESS2BIN/$file" + cp $STRESS2BIN/$file /tmp + else + $CC $@ # default "build and run" mode + fi +} + +id $testuser > /dev/null 2>&1 || + { echo "Non-root \$testuser \"$testuser\" not found."; exit 1; } diff --git a/tools/test/stress2/df.cfg b/tools/test/stress2/df.cfg new file mode 100644 index 000000000000..933f52aa5896 --- /dev/null +++ b/tools/test/stress2/df.cfg @@ -0,0 +1,8 @@ +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +# Only run these two test programs for VFS tests + +export TESTPROGS="testcases/creat/creat testcases/rw/rw" diff --git a/tools/test/stress2/disk.cfg b/tools/test/stress2/disk.cfg new file mode 100644 index 000000000000..557dcc913202 --- /dev/null +++ b/tools/test/stress2/disk.cfg @@ -0,0 +1,8 @@ +# 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/tools/test/stress2/doc/README b/tools/test/stress2/doc/README new file mode 100644 index 000000000000..cd932e4da01f --- /dev/null +++ b/tools/test/stress2/doc/README @@ -0,0 +1,3 @@ +stress.pdf An old (and out of date) document describing the first + generation of the test suite. +linuxforum06.pdf The slides from a presentation at Linux Forum 2006 diff --git a/tools/test/stress2/doc/linuxforum06.pdf b/tools/test/stress2/doc/linuxforum06.pdf new file mode 100644 index 000000000000..ab9d685b36c3 Binary files /dev/null and b/tools/test/stress2/doc/linuxforum06.pdf differ diff --git a/tools/test/stress2/doc/stress.pdf b/tools/test/stress2/doc/stress.pdf new file mode 100644 index 000000000000..8c82924129a7 Binary files /dev/null and b/tools/test/stress2/doc/stress.pdf differ diff --git a/tools/test/stress2/include/stress.h b/tools/test/stress2/include/stress.h new file mode 100644 index 000000000000..3ffb49410a20 --- /dev/null +++ b/tools/test/stress2/include/stress.h @@ -0,0 +1,64 @@ +/*- + * 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. + */ + +#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; + int64_t kblocks; + int64_t 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/tools/test/stress2/io.cfg b/tools/test/stress2/io.cfg new file mode 100644 index 000000000000..38830d6bbd63 --- /dev/null +++ b/tools/test/stress2/io.cfg @@ -0,0 +1,9 @@ +# 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/tools/test/stress2/jeff.cfg b/tools/test/stress2/jeff.cfg new file mode 100644 index 000000000000..66345968d635 --- /dev/null +++ b/tools/test/stress2/jeff.cfg @@ -0,0 +1,8 @@ +# 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/tools/test/stress2/lib/Makefile b/tools/test/stress2/lib/Makefile new file mode 100644 index 000000000000..b2f3cfb0efee --- /dev/null +++ b/tools/test/stress2/lib/Makefile @@ -0,0 +1,9 @@ +LIB= stress +SRCS= main.c options.c random_int.c resources.c +INTERNALLIB= true +MK_AUTO_OBJ= no + +.include "../testcases/Makefile.inc" +CFLAGS+=-fPIE + +.include diff --git a/tools/test/stress2/lib/main.c b/tools/test/stress2/lib/main.c new file mode 100644 index 000000000000..e7267fff2ed9 --- /dev/null +++ b/tools/test/stress2/lib/main.c @@ -0,0 +1,212 @@ +/*- + * 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" + +volatile int done_testing; +static int cleanupcalled = 0; +char *home; + +static pid_t *r; + +static void +handler(int i __unused) +{ + 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); + } + } +} + +static void +run_test_handler(int i __unused) +{ + + done_testing = 1; +} + +static void +exit_handler(int i __unused) +{ + + _exit(1); +} + +static void +callcleanup(void) +{ + if (cleanupcalled == 0) + cleanup(); + cleanupcalled = 1; +} + +static void +run_tests(int i) +{ + time_t start; + int e; + + 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)); + e = 0; + start = time(NULL); + while (done_testing == 0 && e == 0 && + (time(NULL) - start) < op->run_time) { + e = test(); + } + callcleanup(); + exit(e); +} + +static void +run_incarnations(void) +{ + int e, i, s; + + e = 0; + 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__); + if (s != 0) + e = 1; + } + + exit(e); +} + +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 (waitpid(p, &status, WNOHANG) == p) + return (status != 0); + } + 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 != 0); +} + +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__); + } else if ((sb.st_mode & S_IRWXU) == 0) + errx(1, "No RWX access to %s", op->wd); + 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/tools/test/stress2/lib/options.c b/tools/test/stress2/lib/options.c new file mode 100644 index 000000000000..a081ca4c6c84 --- /dev/null +++ b/tools/test/stress2/lib/options.c @@ -0,0 +1,268 @@ +/*- + * 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" + +static opt_t opt; +opt_t *op; + +static char path[64]; + +static void +usage(const char *where) +{ + const 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("%s", 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(const 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, "%jd", &op->kblocks) != 1) + usage("KBLOCKS"); + } + if ((cp = gete("INODES")) != NULL) { + if (sscanf(cp, "%jd", &op->inodes) != 1) + usage("INODES"); + } +} + +void +options(int argc, char **argv) +{ + int ch; + + op = &opt; + + op->run_time = 60; + op->load = 100; + op->wd = strdup("/tmp/stressX"); + op->cd = strdup("/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], pgname[9]; + int days; + time_t t; + + if (op->verbose > 0) { + strncpy(pgname, getprogname(), sizeof(pgname)); + pgname[8] = 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", + pgname, days, buf, op->incarnations, op->load, + op->verbose); + fflush(stdout); + } +} + +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/tools/test/stress2/lib/random_int.c b/tools/test/stress2/lib/random_int.c new file mode 100644 index 000000000000..2f74523ba83c --- /dev/null +++ b/tools/test/stress2/lib/random_int.c @@ -0,0 +1,56 @@ +/*- + * 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 "stress.h" + +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/tools/test/stress2/lib/resources.c b/tools/test/stress2/lib/resources.c new file mode 100644 index 000000000000..935a085a58de --- /dev/null +++ b/tools/test/stress2/lib/resources.c @@ -0,0 +1,248 @@ +/*- + * 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, 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 > (int64_t)buf.f_blocks || buf.f_bavail < 0) { + warnx("Corrupt statfs(%s). f_bavail = %jd!", path, + buf.f_bavail); + buf.f_bavail = 100; + } + if (op->verbose > 2) + printf("Free space on %s: %jd Mb\n", path, buf.f_bavail * + buf.f_bsize / 1024 / 1024); + return (buf.f_bavail * buf.f_bsize); +} + +int64_t +swap(void) +{ + struct xswdev xsw; + size_t mibsize, size; + int mib[16], n; + int64_t sz; + + mibsize = sizeof mib / sizeof mib[0]; + sz = 0; + + if (sysctlnametomib("vm.swap_info", mib, &mibsize) == -1) + err(1, "sysctlnametomib()"); + + for (n = 0; ; ++n) { + mib[mibsize] = n; + size = sizeof xsw; + if (sysctl(mib, mibsize + 1, &xsw, &size, NULL, 0) == -1) + break; + if (xsw.xsw_version != XSWDEV_VERSION) + errx(1, "xswdev version mismatch"); + sz = sz + xsw.xsw_nblks - xsw.xsw_used; + } + if (errno != ENOENT) + err(1, "sysctl()"); + + if (op->verbose > 2) + printf("Total free swap space %jd Mb\n", + sz * getpagesize() / 1024 / 1024); + + return (sz * getpagesize()); +} + +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); +} + +static 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 < 2; 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 (i > 0 && i % 1000 == 0) + fprintf(stderr, "%s is waiting for lock file" + " %s\n", + getprogname(), lockpath); + } + 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) != + (ssize_t)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) != (ssize_t)strlen(buf) +1) + warn("write df. %s:%d", __FILE__, __LINE__); +err: + close(dffd); + close(lockfd); + if (unlink(lockpath) == -1) + err(1, "unlink(%s)", lockpath); +} diff --git a/tools/test/stress2/link.cfg b/tools/test/stress2/link.cfg new file mode 100644 index 000000000000..e66c5a24031e --- /dev/null +++ b/tools/test/stress2/link.cfg @@ -0,0 +1,9 @@ +# 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/tools/test/stress2/load.cfg b/tools/test/stress2/load.cfg new file mode 100644 index 000000000000..d4d70161a790 --- /dev/null +++ b/tools/test/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/tools/test/stress2/lockf.cfg b/tools/test/stress2/lockf.cfg new file mode 100644 index 000000000000..279814a73a65 --- /dev/null +++ b/tools/test/stress2/lockf.cfg @@ -0,0 +1,9 @@ +# 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/tools/test/stress2/marcus.cfg b/tools/test/stress2/marcus.cfg new file mode 100644 index 000000000000..855f1dd4e80b --- /dev/null +++ b/tools/test/stress2/marcus.cfg @@ -0,0 +1,24 @@ +# Stress Test Suite Configuration + +# Default values +. ./default.cfg + +# Test configuration for the vop_stdvptocnp implementation + +export LOAD=80 +export symlinkLOAD=80 +export rwLOAD=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/tools/test/stress2/misc/1st.sh b/tools/test/stress2/misc/1st.sh new file mode 100755 index 000000000000..00602d67e803 --- /dev/null +++ b/tools/test/stress2/misc/1st.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# stress2 config test: +# Check that diskimage and RUNDIR has not been clobbered in `hostname`. +# Variables must be set like this: var=${var:-value} + +export diskimage=dummy +export RUNDIR=dummy +. ../default.cfg + +[ "`sysctl -in debug.vmem_check`" = "1" ] && + echo "debug.vmem_check must be set to 0" +[ "`sysctl -in debug.vmmap_check`" = "0" ] && + echo "debug.vmmap_check must be set to 1" + +if [ "$diskimage" != "dummy" ]; then + echo "FATAL: diskimage was overwritten with \"$diskimage\"" + exit 1 +fi +if [ "$RUNDIR" != "dummy" ]; then + echo "FATAL: RUNDIR was overwritten with \"$RUNDIR\"" + exit 1 +fi +if [ "`dirname $mntpoint`" != "/" ]; then + echo "FATAL: mntpoint \"$mntpoint\" must be a root directory" + exit 1 +fi +[ -z "`which ruby 2>/dev/null`" ] && echo "Consider installing ruby" +[ -z "`type mke2fs 2>/dev/null`" ] && echo "Consider installing e2fsprogs" +[ -z "`type mkisofs 2>/dev/null`" ] && echo "Consider installing cdrtools" +[ -z "`type mDNSNetMonitor 2>/dev/null`" ] && echo "Consider installing mDNSResponder" +[ ! -x /usr/local/lib/libmill.so ] && echo "Consider installing libmill" + +# Random sanity checks + +df -k $(dirname $diskimage) | tail -1 | awk '{print $4}' | + grep -Eq '^[0-9]+$' || { echo FATAL; df -k $(dirname $diskimage); } + +grep -Eq "^discard" /etc/inetd.conf || + echo "Discard is not enabled in /etc/inetd.conf" +pgrep -Sq inetd || echo "inetd is not running" + +[ `sysctl -n kern.maxvnodes` -le 2000 ] && + echo "FATAL kern.maxvnodes is too small" + +exit 0 diff --git a/tools/test/stress2/misc/256m.sh b/tools/test/stress2/misc/256m.sh new file mode 100755 index 000000000000..79b96010af05 --- /dev/null +++ b/tools/test/stress2/misc/256m.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 scenario with 256MB RAM on a single CPU i386. + +# "panic: ffs_checkblk: bad block -1" seen: +# https://people.freebsd.org/~pho/stress/log/256m.txt +# Fixed by r291743. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ `uname -m` = "i386" ] || exit 0 +[ `sysctl -n hw.ncpu` -eq 1 ] || { echo "Single CPU test."; exit 0; } +[ `sysctl -n hw.physmem` -gt $((256 * 1024 * 1024)) ] && + { echo "RAM must be clamped to 256MB for this test."; exit 0; } +[ -f /usr/src/sys/i386/conf/GENERIC ] || exit 0 + +cd /usr/src +make -j 2 buildkernel KERNCONF=GENERIC +rm -rf /usr/obj/usr/src/sys/GENERIC diff --git a/tools/test/stress2/misc/README b/tools/test/stress2/misc/README new file mode 100644 index 000000000000..7b19252cf219 --- /dev/null +++ b/tools/test/stress2/misc/README @@ -0,0 +1,4 @@ +This directory contains various test scenarios. Most are regression +tests for problems fixed. + +The script "all.sh" will run all the test scenarios forever. diff --git a/tools/test/stress2/misc/advlock.sh b/tools/test/stress2/misc/advlock.sh new file mode 100755 index 000000000000..16b67c3f3340 --- /dev/null +++ b/tools/test/stress2/misc/advlock.sh @@ -0,0 +1,245 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# From r238952's commit log: +# The first change closes a race where an open() that will block with O_SHLOCK +# or O_EXLOCK can increase the write count while it waits. If the process +# holding the current lock on the file then tries to call exec() on the file +# it has locked, it can fail with ETXTBUSY even though the advisory lock is +# preventing other threads from successfully completing a writable open(). +# +# The second change closes a race where a read-only open() with O_SHLOCK or +# O_EXLOCK may return successfully while the write count is non-zero due to +# another descriptor that had the advisory lock and was blocking the open() +# still being in the process of closing. If the process that completed the +# open() then attempts to call exec() on the file it locked, it can fail with +# ETXTBUSY even though the other process that held a write lock has closed +# the file and released the lock. + +# https://people.freebsd.org/~pho/stress/log/kostik859.txt +# https://people.freebsd.org/~pho/stress/log/kostik860.txt + +# Fixed by r294204. + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/advlock.c +mycc -o advlock -Wall -Wextra -O0 -g advlock.c || exit 1 +rm -f advlock.c + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 512m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +cp /usr/bin/true $mntpoint +cd $mntpoint +/tmp/advlock +r=$? +cd $odir + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/advlock +exit $r + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +volatile u_int *share; +char *cmdline[] = { "./true", NULL }; +const char *tp; + +#define SYNC 0 +#define PARALLEL 2 + +#define RUNTIME (1 * 60) + +void +handler(int i __unused) { + + fprintf(stderr, "ALARM from %s.\n", tp); + _exit(1); +} + +void +slock(void) +{ + int fd; + + setproctitle("%s", __func__); + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + tp = __func__; + alarm(2); + if ((fd = open(cmdline[0], O_RDONLY | O_SHLOCK)) == -1) + err(1, "open(%s). %d", cmdline[0], __LINE__); + usleep(500); + close(fd); + + _exit(0); +} + +void +elock(void) +{ + int fd; + + setproctitle("%s", __func__); + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + tp = __func__; + alarm(2); + if ((fd = open(cmdline[0], O_WRONLY | O_EXLOCK)) == -1) { + if (errno != ETXTBSY) + err(1, "open(%s). %d", cmdline[0], __LINE__); + } else { + usleep(500); + close(fd); + } + + _exit(0); +} + +void +stest(void) +{ + int fd; + + setproctitle("%s", __func__); + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + tp = __func__; + alarm(2); + if ((fd = open(cmdline[0], O_RDONLY | O_SHLOCK)) == -1) + err(1, "open(%s). %d", cmdline[0], __LINE__); + + if (execve(cmdline[0], cmdline, NULL) == -1) + err(1, "execve(%s) @ %d", cmdline[0], __LINE__); + + _exit(0); +} + +void +etest(void) +{ + int fd; + + setproctitle("%s", __func__); + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + tp = __func__; + alarm(2); + if ((fd = open(cmdline[0], O_RDONLY | O_EXLOCK)) == -1) + err(1, "open(%s). %d", cmdline[0], __LINE__); + + if (execve(cmdline[0], cmdline, NULL) == -1) + err(1, "execve(%s) @ %d", cmdline[0], __LINE__); + + _exit(0); +} + +int +main(void) +{ + size_t len; + time_t start; + int i, n, r, s; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, + -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + signal(SIGALRM, handler); + n = r = 0; + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + n++; + share[SYNC] = 0; + if (fork() == 0) + slock(); + if (fork() == 0) + stest(); + + for (i = 0; i < PARALLEL; i++) { + wait(&s); + r += s == 0 ? 0 : 1; + } + if (r != 0) + break; + + share[SYNC] = 0; + if (fork() == 0) + elock(); + if (fork() == 0) + etest(); + + for (i = 0; i < PARALLEL; i++) { + wait(&s); + r += s == 0 ? 0 : 1; + } + if (r != 0) + break; + } + if (r != 0) + fprintf(stderr, "FAIL @ %d\n", n); + + return (r); +} diff --git a/tools/test/stress2/misc/aesni.sh b/tools/test/stress2/misc/aesni.sh new file mode 100755 index 000000000000..c25694fa002a --- /dev/null +++ b/tools/test/stress2/misc/aesni.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Simple AESNI(4) test. + +kldstat -v | grep -qw aesni || { kldload aesni.ko; loaded=1; } + +../misc/geli.sh + +[ $loaded ] && kldunload aesni.ko + +exit 0 diff --git a/tools/test/stress2/misc/all.debug.inc b/tools/test/stress2/misc/all.debug.inc new file mode 100644 index 000000000000..ea0f2d6a5c58 --- /dev/null +++ b/tools/test/stress2/misc/all.debug.inc @@ -0,0 +1,95 @@ +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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$ +# + +# Example debug include file for misc/all.sh + +pre_debug() { + debug_statfs=`vmstat -m | grep -w statfs | awk '{print $2}'` + debug_freework=`vmstat -m | grep -w freework | awk '{print $2}'` + debug_newblk=`vmstat -m | grep -w newblk | awk '{print $2}'` + debug_pts=`vmstat -m | grep -w pts | awk '{print $2}'` + debug_routetbl=`vmstat -m | grep -w routetbl | awk '{print $2}'` + debug_mount=`vmstat -m | awk '/ mount/{print $2}'` + debug_geom=`vmstat -m | grep -w GEOM | awk '{print $2}'` +# debug_indirdep=`vmstat -m | grep -w indirdep | awk '{print $2}'` +} + +post_debug() { + local debug_new + + debug_new=`vmstat -m | grep -w statfs | awk '{print $2}'` + [ $((debug_new - debug_statfs)) -gt 0 ] && + { printf "stress2: statfs leak: %d/%d.\r\n" \ + $((debug_new - debug_statfs)) $debug_new > $console + debug_statfs=$debug_new; } + + debug_new=`vmstat -m | grep -w freework | awk '{print $2}'` + [ $((debug_new - debug_freework)) -gt 0 -a $debug_new -gt 100 ] && + { printf "stress2: freework leak: %d/%d.\r\n" \ + $((debug_new - debug_freework)) $debug_new > $console + debug_freework=$debug_new; } + + debug_new=`vmstat -m | grep -w newblk | awk '{print $2}'` + [ $((debug_new - debug_newblk)) -gt 0 -a $debug_new -gt 100 ] && + { printf "stress2: newblk leak: %d/%d.\r\n" \ + $((debug_new - debug_newblk)) $debug_new > $console + debug_newblk=$debug_new; } + + debug_new=`vmstat -m | grep -w pts | awk '{print $2}'` + [ $((debug_new - debug_pts)) -gt 0 ] && + { printf "stress2: pts leak: %d/%d\r\n" \ + $((debug_new - debug_pts)) $debug_new > $console + debug_pts=$debug_new; } + + debug_new=`vmstat -m | grep -w routetbl | awk '{print $2}'` + [ $((debug_new - debug_routetbl)) -gt 0 ] && + { printf "stress2: routetbl leak: %d/%d\r\n" \ + $((debug_new - debug_routetbl)) $debug_new > $console + debug_routetbl=$debug_new; } + + debug_new=`vmstat -m | awk '/ mount/{print $2}'` + [ $((debug_new - debug_mount)) -gt 0 ] && + { printf "stress2: mount leak: %d/%d\r\n" \ + $((debug_new - debug_mount)) $debug_new > $console + debug_mount=$debug_new; } + + debug_new=`vmstat -m | awk '/GEOM/{print $2}'` + [ $((debug_new - debug_geom)) -gt 0 ] && + { printf "stress2: GEOM leak: %d/%d\r\n" \ + $((debug_new - debug_geom)) $debug_new > $console + debug_geom=$debug_new; } + +# debug_new=`vmstat -m | awk '/indirdep/{print $2}'` +# [ $((debug_new - debug_indirdep)) -gt 100 -a $debug_new -gt 100 ] && +# { printf "stress2: indirdep leak: %d/%d\r\n" \ +# $((debug_new - debug_indirdep)) $debug_new > $console +# debug_indirdep=$debug_new; } +} + +all_debug=1 diff --git a/tools/test/stress2/misc/all.exclude b/tools/test/stress2/misc/all.exclude new file mode 100644 index 000000000000..f04766c3c2ec --- /dev/null +++ b/tools/test/stress2/misc/all.exclude @@ -0,0 +1,111 @@ +# List of tests not to run, unless the '-a' option is used with run.sh +# Exclude names must start in column 1 + +backingstore.sh g_vfs_done():md6a[WRITE(offset=...)]error = 28 20111220 +backingstore2.sh panic: 43 vncache entries remaining 20111220 +backingstore3.sh g_vfs_done():md6a[WRITE(offset=...)]error = 28 20111230 +collapse.sh panic: freeing mapped page 0xfffffe0028ed1d50 20200106 +dd.sh CAM stuck in vmwait 20200116 +devfs4.sh Hang seen 20210210 +fsync.sh panic: Journal overflow 20190208 +fuse.sh Memory corruption seen in log file kostik734.txt 20141114 +fuse2.sh Deadlock seen 20121129 +fuse3.sh Deadlock seen 20141120 +getrandom.sh Known DoS issue 20201107 +getrandom2.sh Known DoS issue 20200302 +gjournal.sh panic: Journal overflow 20190626 +gjournal2.sh panic: Journal overflow 20180125 +gjournal3.sh panic: Bio not on queue 20171225 +gjournal4.sh CAM stuck in vmwait 20180517 +gnop7.sh Waiting for patch commit 20190820 +gnop8.sh Waiting for patch commit 20201214 +gnop9.sh Waiting for patch commit 20201214 +gnop10.sh Waiting for patch commit 20210105 +graid1_8.sh Known issue 20170909 +graid1_9.sh panic: Bad effnlink 20180212 +lockf5.sh Spinning threads seen 20160718 +ifconfig2.sh https://people.freebsd.org/~pho/stress/log/log0051.txt 20210210 +maxvnodes.sh Only supposed to work in single user mode 20190412 +maxvnodes2.sh Only supposed to work in single user mode 20190412 +memguard.sh Waiting for fix commit +memguard2.sh Waiting for fix commit +memguard3.sh Waiting for fix commit +memsetdomain.sh May change policy for random threads to to domainset_fixed 20210104 +mlockall2.sh Unrecoverable OOM killing seen 20190203 +mlockall7.sh Needs further investigation 20210123 +nfs15lockd.sh panic: Assertion td->td_realucred == td->td_ucred failed ... 20210211 +Xnfs15lockd2.sh WiP 20200805 +Xnfs15lockd3.sh WiP 20200805 +newfs4.sh watchdog fired. newbuf 20190225 +nfs10.sh Double fault 20151013 +nfs13.sh mount_nfs hangs in mntref 20191007 +nfs16.sh panic: Failed to register NFS lock locally - error=11 20160608 +oom2.sh Hang in pfault 20180324 +overcommit2.sh CAM stuck in vmwait seen 20200112 +pageout.sh panic: handle_written_filepage: not started 20190218 +pmc4.sh ld: error: /usr/lib/libpmc.so: undefined reference 20210124 +pmc5.sh ld: error: /usr/lib/libpmc.so: undefined reference 20210124 +pmc6.sh ld: error: /usr/lib/libpmc.so: undefined reference 20210124 +quota10.sh people.freebsd.org/~pho/stress/log/quota10-2.txt 20200525 +quota2.sh panic: dqflush: stray dquot 20120221 +quota3.sh panic: softdep_deallocate_dependencies: unrecovered ... 20111222 +quota7.sh panic: dqflush: stray dquot 20120221 +Xrename14.sh mark136.txt 20200525 +sctp.sh panic: Queues are not empty when handling ... i386 20201104 +sctp2.sh panic: soclose: SS_NOFDREF on enter 20200307 +sctp3.sh panic: Queues are not empty when handling SHUTDOWN-COMPLETE 20210211 +sendfile25.sh WiP 20200611 +signal.sh Timing issues. Needs fixing 20171116 +snap8.sh https://people.freebsd.org/~pho/stress/log/log0049.txt 20210216 +snap9.sh panic: handle_written_filepage: not started 20170722 +snap11.sh panic: handle_written_filepage: not started 20200928 +suj13.sh Stuck with suspfs 20210105 +suj31.sh Stuck with suspfs 20210105 +suj34.sh Various hangs and panics (SUJ + NULLFS issue) 20131210 +Xswap4.sh WiP 20171208 +swapoff2.sh swap_pager_force_pagein: read from swap failed 20171223 +swapoff5.sh log0005.txt, known issue 20210111 +systrace.sh WiP 20200227 +systrace2.sh WiP 20200227 +syzkaller11.sh WiP 20200721 +syzkaller15.sh WiP 20200712 +syzkaller16.sh WiP 20200620 +syzkaller17.sh WiP 20200630 +syzkaller19.sh WiP 20200712 +syzkaller25.sh WiP 20201116 +syzkaller28.sh WiP 20201120 +syzkaller29.sh May change policy for random threads to to domainset_fixed 20210104 +syzkaller30.sh May change policy for random threads to to domainset_fixed 20210104 +truss3.sh WiP 20200915 +unionfs.sh insmntque: non-locked vp: xx is not exclusive locked... 20130909 +unionfs2.sh insmntque: mp-safe fs and non-locked vp is not ... 20111219 +unionfs3.sh insmntque: mp-safe fs and non-locked vp is not ... 20111216 + +# Test not to run for other reasons: + +fuzz.sh A know issue +marcus3.sh OK, but runs for a long time +statfs.sh Not very interesting +vunref.sh No problems ever seen +vunref2.sh No problems ever seen + +# Snapshots has been disabled on SU+J +suj15.sh +suj16.sh +suj19.sh +suj20.sh +suj21.sh +suj22.sh +suj24.sh +suj25.sh +suj26.sh +suj27.sh +suj28.sh + +# Exclude NFS loopback tests +nfs2.sh panic: wrong diroffset 20140219 +nfs5.sh +nfs6.sh +nfs11.sh vmwait deadlock 20151004 +nullfs8.sh +tmpfs18.sh mntref hang seen 20191019 diff --git a/tools/test/stress2/misc/all.exclude.pae b/tools/test/stress2/misc/all.exclude.pae new file mode 100644 index 000000000000..281eff644e77 --- /dev/null +++ b/tools/test/stress2/misc/all.exclude.pae @@ -0,0 +1,11 @@ +PAE tests + +# crossmp7.sh +# zfs.sh +# zfs2.sh +# zfs3.sh +# zfs4.sh +# zfs5.sh +# zfs6.sh +# zfs7.sh +# zfs8.sh diff --git a/tools/test/stress2/misc/all.sh b/tools/test/stress2/misc/all.sh new file mode 100755 index 000000000000..58bf3a630294 --- /dev/null +++ b/tools/test/stress2/misc/all.sh @@ -0,0 +1,255 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2009, 2012-13 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. +# + +# Run all the scripts in stress2/misc. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Log and config files: +sdir=/tmp/stress2.d +mkdir -p $sdir +allconfig=$sdir/`hostname` # config file +allfaillog=$sdir/fail # Tests that failed +alllast=$sdir/last # Last test run +alllist=$sdir/list # -o list +alllog=$sdir/log # Tests run +alloutput=$sdir/output # Output from current test +allexcess=$sdir/excessive # Tests with excessive runtime +allelapsed=$sdir/elapsed # Test runtime +alllocal=$sdir/all.exclude # Local exclude list +loops=0 # Times to run the tests +# Get kernel config + revision +rev=`uname -a | awk '{print $7}' | sed 's/://'` +rev="`uname -a | sed 's#.*/compile/##; s/ .*//'` $rev" + +args=`getopt acl:m:no "$@"` +[ $? -ne 0 ] && + echo "Usage $0 [-a] [-c] [-l ] [-m ] [-n] [-o] []" && + exit 1 +set -- $args +for i; do + case "$i" in + -a) all=1 # Run all tests + echo "Note: including known problem tests." + shift + ;; + -c) rm -f $alllast # Clear last know test + rm -f $alllist + shift + ;; + -l) loops=$2 # Number of time to run + shift; shift + ;; + -m) minutes=$(($2 * 60)) # Run for minutes + shift; shift + ;; + -n) noshuffle=1 # Do not shuffle the list of tests + shift # Resume test after last test + ;; + -o) loops=1 # Only run once + shift + ;; + --) + shift + break + ;; + esac +done + +export allconfig +if [ ! -f $allconfig ]; then + echo "Creating local configuration file: $allconfig." + ../tools/setup.sh || exit 1 +fi + +. ../default.cfg + +# Sanity checks +minspace=$((1024 * 1024)) # in k +[ -d `dirname "$diskimage"` ] || + { echo "diskimage dir: $diskimage not found"; exit 1; } +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print $4}'` -lt \ + $minspace ] && + echo "Warn: Not enough disk space on `dirname $diskimage` " \ + "for \$diskimage" +[ ! -d $(dirname $RUNDIR) ] && + echo "No such \$RUNDIR \"`dirname $RUNDIR`\"" && + exit 1 +[ `sysctl -n hw.physmem` -le $((3 * 1024 * 1024 * 1024)) ] && + echo "Warn: Small RAM size for stress tests `sysctl -n hw.physmem`" +[ `df -k $(dirname $RUNDIR) | tail -1 | awk '{print $4}'` -lt \ + $minspace ] && + echo "Warn: Not enough disk space on `dirname $RUNDIR` for \$RUNDIR" +id $testuser > /dev/null 2>&1 || + { echo "\$testuser \"$testuser\" not found."; exit 1; } +probe=`dirname $RUNDIR`/probe +su $testuser -c "touch $probe" > /dev/null 2>&1 +[ -f $probe ] && rm $probe || + { echo "No write access to `dirname $RUNDIR`."; exit 1; } +[ `swapinfo | wc -l` -eq 1 ] && + echo "Consider adding a swap disk. Many tests rely on this." +mount | grep -wq $mntpoint && + echo "\$mntpoint ($mntpoint) is already in use" && exit 1 +[ -x ../testcases/run/run ] || + (cd ..; make) +ping -c 2 -t 2 $BLASTHOST > /dev/null 2>&1 || + { echo "Note: Can not ping \$BLASTHOST: $BLASTHOST"; } +echo "$loops" | grep -Eq "^[0-9]+$" || + { echo "The -l argument must be a positive number"; exit 1; } +[ `grep "^[a-zA-Z].*\.sh" $alllocal 2>/dev/null | wc -l` -ne 0 ] && + echo "Using $alllocal" + +find `dirname $alllast` -maxdepth 1 -name $alllast -mtime +12h -delete +touch $alllast $alllog +chmod 640 $alllast $alllog +find ../testcases -perm -1 \( -name "*.debug" -o -name "*.full" \) -delete +tail -2000 $alllog > ${alllog}.new; mv ${alllog}.new $alllog +touch $allelapsed +tail -20000 $allelapsed > ${allelapsed}.new; mv ${allelapsed}.new $allelapsed + +console=/dev/console +printf "\r\n" > $console & +pid=$! +sleep 1 +kill -0 $pid > /dev/null 2>&1 && +{ console=/dev/null; kill -9 $pid; } +while pgrep -q fsck; do sleep 10; done + +status() { + local s2 r + + s2=`date +%s` + r=$(echo "elapsed $(((s2 - s1) / 86400)) day(s)," \ + "`date -u -j -f '%s' '+%H:%M.%S' $((s2 - s1))`") + printf "`date '+%Y%m%d %T'` all.sh done, $r\n" + printf "`date '+%Y%m%d %T'` all.sh done, $r\r\n" > $console +} + +intr() { + printf "\nExit all.sh\n" + ./cleanup.sh + exit 1 +} +trap status EXIT +trap intr INT + +[ -f all.debug.inc ] && . all.debug.inc +s1=`date +%s` +while true; do + exclude=`cat all.exclude $alllocal 2>/dev/null | sed '/^#/d' | + grep "^[a-zA-Z].*\.sh" | awk '{print $1}'` + list=`echo *.sh` + [ $# -ne 0 ] && list=$* + list=`echo $list | + sed "s/[[:<:]]all\.sh[[:>:]]//g;\ + s/[[:<:]]cleanup\.sh[[:>:]]//g"` + + if [ -n "$noshuffle" -a $# -eq 0 ]; then + last=`cat $alllast` + if [ -n "$last" ]; then + last=`basename $last` + l=`cat "$alllist" | sed "s/.*$last//"` + [ -z "$l" ] && l=$list # start over + list=$l + echo "Last test was $last,"\ + "resuming test at" \ + "`echo "$list" | awk '{print $1}'`" + fi + fi + [ -n "$noshuffle" ] || + list=`echo $list | tr ' ' '\n' | sort -R | + tr '\n' ' '` + + lst="" + for i in $list; do + [ -z "$all" ] && echo $exclude | grep -qw `basename $i` && + continue + lst="$lst $i" + done + [ -z "$lst" ] && exit + echo "$lst" > $alllist + + pgrep -fq vmstat.sh || + daemon ../tools/vmstat.sh > /tmp/stress2.d/vmstat 2>&1 + + n1=0 + n2=`echo $lst | wc -w | sed 's/ //g'` + for i in $lst; do + i=`basename $i` + [ ! -f ./$i ] && { echo "No such file ./$i"; continue; } + n1=$((n1 + 1)) + echo $i > $alllast + ./cleanup.sh || exit 1 + ts=`date '+%Y%m%d %T'` + echo "$ts all: $i" + printf "$ts all ($n1/$n2): $i\n" >> $alllog + printf "$ts all ($n1/$n2): $i\r\n" > $console + logger "Starting stress2 test all.sh: $i" + [ $all_debug ] && pre_debug + [ -f $i ] || loops=1 # break + sync; sleep .5; sync; sleep .5 + grep -E "^USE_TIMEOUT=1" $i && TIMEOUT_ONE=1 || + unset TIMEOUT_ONE + start=`date '+%s'` + ( + if [ $USE_TIMEOUT ] || [ $TIMEOUT_ONE ]; then + timeout -k 1m 1h ./$i + else + ./$i + fi + e=$? + [ $e -ne 0 ] && + echo "FAIL $i exit code $e" + ) 2>&1 | tee $alloutput + ts=`date '+%Y%m%d %T'` + grep -qw FAIL $alloutput && + echo "$ts $rev $i" >> $allfaillog && + logger "stress2 test $i failed" + grep -qw FATAL $alloutput && exit $e + rm -f $alloutput + printf "$ts $rev $i $((`date '+%s'` - start))\n" >> \ + $allelapsed + [ -f ../tools/ministat.sh ] && + ../tools/ministat.sh $allelapsed $i + [ $((`date '+%s'` - start)) -gt 1980 ] && + printf "$ts *** Excessive run time: %s %d min\r\n" $i, \ + $(((`date '+%s'` - start) / 60)) | + tee $console >> $allexcess + while pgrep -q "^swap$"; do + echo "swap still running" + sleep 2 + done + [ $USE_SWAPOFF ] && { swapoff -a; swapon -a; } + [ $all_debug ] && post_debug + [ $minutes ] && [ $((`date +%s` - s1)) -ge $minutes ] && + break 2 + done + [ $((loops -= 1)) -eq 0 ] && break +done +[ -x ../tools/fail.sh ] && ../tools/fail.sh +find /tmp . -name "*.core" -mtime -2 -maxdepth 2 -ls 2>/dev/null diff --git a/tools/test/stress2/misc/altbufferflushes.sh b/tools/test/stress2/misc/altbufferflushes.sh new file mode 100755 index 000000000000..20b1928d5236 --- /dev/null +++ b/tools/test/stress2/misc/altbufferflushes.sh @@ -0,0 +1,98 @@ +#!/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. +# + +# 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/stress2 /var/tmp/big.? +trap "rm -f /var/.snap/stress2 /var/tmp/big.?" EXIT INT +persist 'mksnap_ffs /var /var/.snap/stress2' +tresh=`sysctl vfs.dirtybufthresh | awk '{print $NF}'` +sysctl vfs.dirtybufthresh=10 + +cd /var/tmp +for j in `jot 5`; 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 status=none + 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 +sysctl vfs.dirtybufthresh=$tresh +rm -f /var/.snap/stress2 diff --git a/tools/test/stress2/misc/alternativeFlushPath.sh b/tools/test/stress2/misc/alternativeFlushPath.sh new file mode 100755 index 000000000000..d122b095902a --- /dev/null +++ b/tools/test/stress2/misc/alternativeFlushPath.sh @@ -0,0 +1,131 @@ +#!/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. +# + +# Alternate buffer flush path test (Not verified). +# Regression test for r169006. +# Apply this patch to amplify 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*/) { + +. ../default.cfg + +odir=`pwd` +dir=$RUNDIR/alternativeFlushPath + +[ -d $dir ] && find $dir -type f | xargs rm +rm -rf $dir +mkdir -p $dir +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/alternativeFlushPath.c +mycc -o /tmp/alternativeFlushPath -Wall -Wextra alternativeFlushPath.c || + exit 1 +rm -f alternativeFlushPath.c + +for j in `jot 10`; do + /tmp/alternativeFlushPath & +done +wait +sysctl vfs.altbufferflushes + +cd $odir +rm -rf /tmp/alternativeFlushPath $dir + +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXNOFILE 500000 /* To limit runtime */ + +static volatile sig_atomic_t more; + +static void +handler(int i __unused) { + more = 0; +} + +void +test(void) +{ + int i, j; + char name[80]; + pid_t mypid; + int *fd; + struct rlimit rlp; + + if (getrlimit(RLIMIT_NOFILE, &rlp) == -1) + err(1, "getrlimit(RLIMIT_NOFILE)"); + if (rlp.rlim_cur > MAXNOFILE) + rlp.rlim_cur = MAXNOFILE; + rlp.rlim_cur /= 10; + mypid = getpid(); + fd = malloc(rlp.rlim_cur * sizeof(int)); + + for (i = 0, j = 0; i < rlp.rlim_cur && more == 1; i++, j++) { + sprintf(name, "f%05d.%05d", mypid, i); + if ((fd[i] = open(name, O_CREAT|O_WRONLY, 0666)) == -1) { + warn("open(%s)", name); + more = 0; + 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); + } + free(fd); +} + +int +main() +{ + more = 1; + signal(SIGALRM, handler); + alarm(20 * 60); + while (more == 1) + test(); + + return(0); +} diff --git a/tools/test/stress2/misc/arp.sh b/tools/test/stress2/misc/arp.sh new file mode 100755 index 000000000000..ef66ce351e24 --- /dev/null +++ b/tools/test/stress2/misc/arp.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# arp(8) seen waiting in "sbwait" (on non HEAD): +# UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND +# 0 70090 68079 0 20 0 9872 2384 sbwait S+ u0 0:00.32 arp -da + +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +start=`date +%s` +for i in `jot 3`; do + while [ $((`date +%s` - start)) -lt 120 ]; do arp -da > /dev/null 2>&1; done & + pids="$pids $!" +done +(cd ../testcases/swap; ./swap -t 2m -i 20 -h -l 100) > /dev/null +while [ $((`date +%s` - start)) -lt 120 ]; do sleep 1; done + +for i in `jot 10`; do + n=`pgrep -f arp.sh | wc -l` + [ $n -eq 0 ] && break + sleep 10 +done +s=0 +if [ $n -ne 0 ]; then + ps -l | grep -v grep | grep arp + pgrep arp | xargs procstat -k + while pkill arp; do :; done + s=1 +fi +wait +exit $s diff --git a/tools/test/stress2/misc/aslr.sh b/tools/test/stress2/misc/aslr.sh new file mode 100755 index 000000000000..6261fae4546b --- /dev/null +++ b/tools/test/stress2/misc/aslr.sh @@ -0,0 +1,46 @@ +#/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# ELF32/64 address map randomization test. + +# "panic: page 0xfffff8103971b840 has queue state" seen in WiP kernel code. +# https://people.freebsd.org/~pho/stress/log/mark087.txt + +old32=`sysctl -ni kern.elf32.aslr.enable` +old64=`sysctl -ni kern.elf64.aslr.enable` + +if [ -n "$old32" ]; then + sysctl kern.elf32.aslr.enable=$((1 - old32)) + ./su.sh + sysctl kern.elf32.aslr.enable=$old32 +elif [ -n "$old64" ]; then + sysctl kern.elf64.aslr.enable=$((1 - old64)) + ./su.sh + sysctl kern.elf64.aslr.enable=$old64 +fi diff --git a/tools/test/stress2/misc/audit.sh b/tools/test/stress2/misc/audit.sh new file mode 100755 index 000000000000..70e1ef8b6977 --- /dev/null +++ b/tools/test/stress2/misc/audit.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# "Fatal trap 12: page fault while in kernel mode" seen. +# https://people.freebsd.org/~pho/stress/log/audit.txt +# Fixed by: r294137 + +# Test scenario by: kib + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -z "$footshoot" ] && exit 0 + +[ -f /usr/sbin/auditd -a -f /etc/rc.d/auditd ] || exit 0 +pgrep -q auditd && exit 0 +mount | grep -q /var || exit 0 + +service auditd onestart + +sleep 1 +su $testuser -c date > /dev/null + +sleep 1 +umount -f /var +sleep 1 +mount /var + +service auditd onestop + +# Some services react badly to /var being unmounted. +service -R +exit 0 diff --git a/tools/test/stress2/misc/audit2.sh b/tools/test/stress2/misc/audit2.sh new file mode 100755 index 000000000000..1435b13d9768 --- /dev/null +++ b/tools/test/stress2/misc/audit2.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# +# No problems seen. + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -f /usr/sbin/auditd -a -f /etc/rc.d/auditd ] || exit 0 +pgrep -q auditd && exit 0 || service auditd onestart + +mount | grep $mntpoint | grep -q /dev/md && 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' + +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +checkfs /dev/md${mdstart}$part; s=$? +mdconfig -d -u $mdstart +service auditd onestop + +exit 0 diff --git a/tools/test/stress2/misc/backingstore.sh b/tools/test/stress2/misc/backingstore.sh new file mode 100755 index 000000000000..b16ff852acd9 --- /dev/null +++ b/tools/test/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. +# + +# 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 + +dd if=/dev/zero of=$D$m bs=100m count=1 status=none || exit 1 + +mdconfig -a -t vnode -f $D$m -u $m + +bsdlabel -w md$m auto +newfs md${m}$part > /dev/null 2>&1 +[ -d ${mntpoint}$m ] || mkdir -p ${mntpoint}$m +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 +[ -d ${mntpoint}$m ] || mkdir -p ${mntpoint}$m +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/tools/test/stress2/misc/backingstore2.sh b/tools/test/stress2/misc/backingstore2.sh new file mode 100755 index 000000000000..48dc6109f719 --- /dev/null +++ b/tools/test/stress2/misc/backingstore2.sh @@ -0,0 +1,72 @@ +#!/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 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 +[ -d ${mntpoint}$m1 ] || mkdir -p ${mntpoint}$m1 +[ -d ${mntpoint}$m2 ] || mkdir -p ${mntpoint}$m2 + +dd if=/dev/zero of=$D$m bs=100m count=1 status=none || 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/tools/test/stress2/misc/backingstore3.sh b/tools/test/stress2/misc/backingstore3.sh new file mode 100755 index 000000000000..2610983da92e --- /dev/null +++ b/tools/test/stress2/misc/backingstore3.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. +# + +# 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 +[ -d ${mntpoint}$m1 ] || mkdir -p ${mntpoint}$m1 +[ -d ${mntpoint}$m2 ] || mkdir -p ${mntpoint}$m2 + +dd if=/dev=zero of=$D$m bs=25m count=1 status=none || 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/tools/test/stress2/misc/badcode.sh b/tools/test/stress2/misc/badcode.sh new file mode 100755 index 000000000000..c869c3a8c13e --- /dev/null +++ b/tools/test/stress2/misc/badcode.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Run tests on a 2g swap backed MD with UFS SU fs. + +# "panic: SACK scoreboard must not be empty" seen: +# https://people.freebsd.org/~pho/stress/log/full.txt +# Fixed by r310547. + +. ../default.cfg +kldstat -v | grep -q pty || kldload pty # ignore any load failure + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export LOAD=80 +export rwLOAD=80 +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +export TESTPROGS=" +testcases/badcode/badcode +testcases/swap/swap +testcases/sysctl/sysctl +" +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +../tools/killall.sh +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +checkfs /dev/md${mdstart}$part +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/badcode2.sh b/tools/test/stress2/misc/badcode2.sh new file mode 100755 index 000000000000..8e47a74a87d1 --- /dev/null +++ b/tools/test/stress2/misc/badcode2.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Peter Holm +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Freeze seen: https://people.freebsd.org/~pho/stress/log/kostik1241.txt +# Fixed by: r355474 + +. ../default.cfg + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +export badcodeLOAD=100 +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +export TESTPROGS="testcases/badcode/badcode testcases/swap/swap" +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +../tools/killall.sh +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +exit + diff --git a/tools/test/stress2/misc/badcode3.sh b/tools/test/stress2/misc/badcode3.sh new file mode 100755 index 000000000000..e0a10d0074a4 --- /dev/null +++ b/tools/test/stress2/misc/badcode3.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Peter Holm +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# No problems seen. + +. ../default.cfg + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +here=`pwd` +cd $mntpoint +(cd $here/../testcases/swap; ./swap -t 5m -i 20) & +sleep 2 +while pgrep -q swap; do + timeout 1m limits -c 0 $here/../testcases/badcode/badcode -t 1m -i 20 +done +wait +cd $here +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +exit + diff --git a/tools/test/stress2/misc/bench.sh b/tools/test/stress2/misc/bench.sh new file mode 100755 index 000000000000..965c9a3d9b99 --- /dev/null +++ b/tools/test/stress2/misc/bench.sh @@ -0,0 +1,300 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# "benchmark" for file system use, using no physical disk. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +export LANG=C +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/bench.c +mycc -o bench -Wall -Wextra -O0 -g bench.c || exit 1 +rm -f bench.c +cd $odir + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +log=/tmp/stress2.d/bench.sh.log +[ -f $log ] && old=`tail -1 $log | awk '{print $2}'` +tmp=/tmp/bench.sh.tmp +s=0 +for j in `jot 5`; do + newfs -n -b 4096 -f 512 -i 1024 md${mdstart}$part > \ + /dev/null + mount -o async /dev/md${mdstart}$part $mntpoint + /usr/bin/time sh -c "(cd $mntpoint; /tmp/bench)" 2>&1 | \ + awk '{print $1}' + [ $? -ne 0 ] && s=1 + umount $mntpoint +done | ministat -n | tail -1 | awk '{printf "%.3f %.3f\n",$6,$7}' > $tmp +r=`cat $tmp` +echo "`date +%Y%m%d%H%M` $r `uname -a`" >> $log +tail -5 $log | cut -c 1-92 +rm $tmp + +if [ $old ]; then + awk -v old=$old -v new=$(echo $r | awk '{print $1}') \ + 'BEGIN {if ((new - old) * 100 / old > 5) exit 1; else exit 0}' + s=$? +fi + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && exit 1 +mdconfig -d -u $mdstart +rm -rf /tmp/bench +exit 0 + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 50000 +#define TESTS 6 +#define TIMEOUT 600 + +static void (*functions[TESTS])(); + +static void +t1(void) +{ + int fd, i; + char file[128]; + + alarm(TIMEOUT); + for (i = 0; i < LOOPS; i++) { + if (i % 1000 == 0) + setproctitle("%s @ %d", __func__, i); + snprintf(file, sizeof(file), "t1.%06d.%03d", getpid(), i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, + DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + close(fd); + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + usleep(100); + } + _exit(0); +} + +static void +t2(void) +{ + int fd, i; + char file[128]; + + alarm(TIMEOUT); + for (i = 0; i < LOOPS; i++) { + if (i % 1000 == 0) + setproctitle("%s @ %d", __func__, i); + snprintf(file, sizeof(file), "t2.%06d.%03d", getpid(), i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, + DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + close(fd); + usleep(100); + } + for (i = 0; i < LOOPS; i++) { + snprintf(file, sizeof(file), "t2.%06d.%03d", getpid(), i); + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + } + _exit(0); +} + +static void +t3(void) +{ + int fd, i; + char dir[128], file[128]; + + alarm(TIMEOUT); + snprintf(dir, sizeof(dir), "t3.%06d.dir", getpid()); + if (mkdir(dir, 700) == -1) + err(1, "mkdir(%s)", dir); + for (i = 0; i < LOOPS; i++) { + if (i % 1000 == 0) + setproctitle("%s @ %d", __func__, i); + snprintf(file, sizeof(file), "%s/t3.%06d.%03d", dir, + getpid(), i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, + DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + close(fd); + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + usleep(100); + } + if (rmdir(dir) == -1) + err(1, "rmdir(%s)", dir); + + _exit(0); +} + +static void +t4(void) +{ + int fd, i; + char file[128], new[128]; + + alarm(TIMEOUT); + for (i = 0; i < LOOPS / 2; i++) { + if (i % 1000 == 0) + setproctitle("%s @ %d", __func__, i); + snprintf(file, sizeof(file), "t4.%06d.%03d", getpid(), i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, + DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + close(fd); + snprintf(new, sizeof(new), "t4.%06d.%03d.new", getpid(), i); + if (rename(file, new) == -1) + err(1, "rename(%s, %s)", file, new); + if (unlink(new) == -1) + err(1, "unlink(%s)", new); + usleep(100); + } + _exit(0); +} + +static void +t5(void) +{ + int fd, i; + char buf[512], file[128]; + + alarm(TIMEOUT); + memset(buf, 0, sizeof(buf)); + for (i = 0; i < LOOPS; i++) { + if (i % 1000 == 0) + setproctitle("%s @ %d", __func__, i); + snprintf(file, sizeof(file), "t5.%06d.%03d", getpid(), i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, + DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + if (write(fd, buf, sizeof(buf)) != sizeof(buf)) + err(1, "write(%s)", file); + close(fd); + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + usleep(100); + } + _exit(0); +} + +static void +t6(void) +{ + int fd, i; + char buf[512], file[128]; + + alarm(TIMEOUT); + memset(buf, 0, sizeof(buf)); + for (i = 0; i < LOOPS / 2; i++) { + if (i % 1000 == 0) + setproctitle("%s/write @ %d", __func__, i); + snprintf(file, sizeof(file), "t6.%06d.%03d", getpid(), i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, + DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + if (write(fd, buf, sizeof(buf)) != sizeof(buf)) + err(1, "write(%s)", file); + close(fd); + } + for (i = 0; i < LOOPS / 2; i++) { + if (i % 1000 == 0) + setproctitle("%s/read @ %d", __func__, i); + snprintf(file, sizeof(file), "t6.%06d.%03d", getpid(), i); + if ((fd = open(file, O_RDONLY)) == -1) + err(1, "open(%s)", file); + if (read(fd, buf, sizeof(buf)) != sizeof(buf)) + err(1, "write(%s)", file); + close(fd); + usleep(100); + } + for (i = 0; i < LOOPS / 2; i++) { + snprintf(file, sizeof(file), "t6.%06d.%03d", getpid(), i); + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + } + _exit(0); +} + +static int +test(void) +{ + pid_t pids[TESTS]; + int e, i, status; + + e = 0; + for (i = 0; i < TESTS; i++) + if ((pids[i] = fork()) == 0) + functions[i](); + for (i = 0; i < TESTS; i++) { + if (waitpid(pids[i], &status, 0) != pids[i]) + err(1, "waitpid(%d)", pids[i]); + e += status != 0; + } + + return (e); +} + +int +main(void) +{ + int e; + + functions[0] = &t1; + functions[1] = &t2; + functions[2] = &t3; + functions[3] = &t4; + functions[4] = &t5; + functions[5] = &t6; + + e = test(); + + return (e); +} diff --git a/tools/test/stress2/misc/beneath.sh b/tools/test/stress2/misc/beneath.sh new file mode 100755 index 000000000000..6c2f71a7e992 --- /dev/null +++ b/tools/test/stress2/misc/beneath.sh @@ -0,0 +1,110 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Konstantin Belousov +# +# 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 of open(2) with the O_BENEATH flag. + +# userret: returning with the following locks held: +# shared lockmgr ufs (ufs) r = 0 (0xfffff804ec0d2a48) locked @ +# kern/vfs_subr.c:2590 seen in WiP code: +# https://people.freebsd.org/~pho/stress/log/kostik1126.txt + +top=/tmp/beneath.d +mkdir -p $top +cat > $top/beneath.c < +#include +#include +#include +#include +#include + +#ifndef O_BENEATH +#define O_BENEATH 0x00400000 /* Fail if not under cwd */ +#define AT_BENEATH 0x1000 /* Fail if not under dirfd */ +#endif + +int +main(int argc, char *argv[]) +{ + struct stat st; + char *name; + int error, fd, i; + + for (i = 1; i < argc; i++) { + name = argv[i]; + alarm(120); + fd = open(name, O_RDONLY | O_BENEATH); + if (fd == -1) { + fprintf(stderr, "open(\"%s\") failed, error %d %s\n", + name, errno, strerror(errno)); + } else { + fprintf(stderr, "open(\"%s\") succeeded\n", name); + close(fd); + } + error = fstatat(AT_FDCWD, name, &st, AT_BENEATH); + if (error == -1){ + fprintf(stderr, "stat(\"%s\") failed, error %d %s\n", + name, errno, strerror(errno)); + } else { + fprintf(stderr, "stat(\"%s\") succeeded\n", name); + } + } +} +EOF +cc -o $top/beneath -Wall -Wextra $top/beneath.c || exit 1 +rm $top/beneath.c + +# Test with two directories as arguments: +cd $top +mkdir -p a/b +./beneath a/b +./beneath $top/a/b +touch $top/a/c +./beneath a/c +./beneath $top/a/c +./beneath a/d +./beneath $top/a/d + +# CWD is still $top for this test +top2=/var/tmp/beneath.d +mkdir -p $top2 +mkdir -p $top2/a/b +./beneath $top2/a/b > /dev/null 2>&1 + +touch $top2/a/c +./beneath $top2/a/c > /dev/null 2>&1 + +# Other CWDs +(cd /etc; find . | head -1000 | xargs $top/beneath) > /dev/null 2>&1 +(cd /var; find . | head -1000 | xargs $top/beneath) > /dev/null 2>&1 + +rm -rf $top $top2 +exit 0 diff --git a/tools/test/stress2/misc/beneath2.sh b/tools/test/stress2/misc/beneath2.sh new file mode 100755 index 000000000000..93a937c054ff --- /dev/null +++ b/tools/test/stress2/misc/beneath2.sh @@ -0,0 +1,101 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# O_BENEATH test with a relative path, which is a symbolic link pointing +# to an absolute path. + +# "panic: Assertion (ndp->ni_lcf & NI_LCF_LATCH) != 0 failed at +# ../../../kern/vfs_lookup.c:182" seen. Fixed by r340343. + +# Based on scenario by Vladimir Kondratyev + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/beneath2.c +mycc -o beneath2 -Wall -Wextra -O0 -g beneath2.c || exit 1 +rm -f beneath2.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +set +e + +cd $mntpoint +ln -s /tmp/justalongname symlink +$dir/beneath2 symlink +s=$? +[ -f beneath2.core -a $s -eq 0 ] && + { ls -l beneath2.core; mv beneath2.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/beneath2 +exit $s + +EOF +#include + +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + int fd; + char *file; + + if (argc != 2) { + fprintf(stderr, "Usage: %s ", argv[0]); + exit(1); + } + file = argv[1]; + if ((fd = open(file, O_RDONLY | O_BENEATH)) != 0 && + errno != ENOTCAPABLE) + err(1, "open(%s)", file); + + return (0); +} diff --git a/tools/test/stress2/misc/beneath3.sh b/tools/test/stress2/misc/beneath3.sh new file mode 100755 index 000000000000..52dc37a7f873 --- /dev/null +++ b/tools/test/stress2/misc/beneath3.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# vput: 0xfffff808d79c0278 is not locked but should be +# KDB: enter: lock violation +# Test scenario suggestions by kib@ and markj@ + +# Fixed by r348052. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/beneath3.c +mycc -o beneath3 -Wall -Wextra -O0 -g beneath3.c || exit 1 +rm -f beneath3.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +set +e + +cd $mntpoint +(cd /usr; $dir/beneath3) +s=$? +[ -f beneath3.core -a $s -eq 0 ] && + { ls -l beneath3.core; mv beneath3.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/beneath3 +exit $s + +EOF +#include + +#include +#include +#include + +int +main(void) +{ + int fd; + char file[] = "/.."; + + errno = 0; + fd = open(file, O_CREAT | O_RDONLY | O_BENEATH); + if (fd != -1 || errno != ENOTCAPABLE) + err(1, "open(%s) returns %d", file, fd); + + return (0); +} diff --git a/tools/test/stress2/misc/beneath4.sh b/tools/test/stress2/misc/beneath4.sh new file mode 100755 index 000000000000..d9ee71a8f222 --- /dev/null +++ b/tools/test/stress2/misc/beneath4.sh @@ -0,0 +1,133 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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 of: +# AT_BENEATH 0x1000 /* Fail if not under dirfd */ +# AT_RESOLVE_BENEATH 0x2000 /* As AT_BENEATH, but do not allow +# resolve to walk out of dirfd even + +dir=/tmp/beneath4.dir +rm -rf $dir +mkdir -p $dir +here=`pwd` +cd $dir + +cat > beneath4.c < + +#include +#include +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + struct stat st; + int exp, fd, flag, r; + char *cwd, *dir, *obj, *s; + + if (argc != 5) { + fprintf(stderr, + "Usage: %s \n", + argv[0]); + return (1); + } + + cwd = getwd(NULL); + dir = argv[1]; + obj = argv[2]; + sscanf(argv[3], "%x", &flag); + exp = atoi(argv[4]); +#if 0 + if ((flag & (AT_BENEATH | AT_RESOLVE_BENEATH)) == 0) { + fprintf(stderr, "Flag must be %#x or %#x\n", + AT_BENEATH, AT_RESOLVE_BENEATH); + return (1); + } +#endif + if ((fd = open(dir, O_DIRECTORY | O_RDONLY)) == -1) + err(1, "open(%s)", dir); + + if (fstatat(fd, obj, &st, flag) == -1) + r = errno; + else + r = 0; + s = "FAIL"; + if (r == exp) + s = "OK"; + warn("cwd=%s, top=%s. flag=%0.6x. fstatf(%s) = %2d (expect %2d). %4s", + cwd, dir, flag, obj, r, exp, s); + + return (r == exp ? 0 : errno); +} +EOF +cc -o beneath4 -Wall -Wextra -O2 -g beneath4.c || exit 1 +rm beneath4.c + +mkdir -p /tmp/beneath4.dir/a/a +touch /tmp/beneath4.dir/a/f +ln /tmp/beneath4.dir/a/f /tmp/beneath4.dir/a/c +ln -s /tmp/beneath4.dir/a/a /tmp/beneath4.dir/a/d +ln -s /tmp/beneath4.dir/a/b /tmp/beneath4.dir/a/e +mkfifo /tmp/beneath4.dir/a/fifo + +top=$dir/a + +cd $here +s=0 +ls -lR $dir +echo AT_BENEATH +$dir/beneath4 $top a 0x1000 0 || s=1 +$dir/beneath4 $top b 0x1000 2 || s=1 +$dir/beneath4 $top c 0x1000 0 || s=1 +$dir/beneath4 $top d 0x1000 0 || s=1 +$dir/beneath4 $top e 0x1000 2 || s=1 +$dir/beneath4 $top fifo 0x1000 0 || s=1 +$dir/beneath4 $top $top/../../beneath4.d/a/a 0x1000 93 || s=1 +$dir/beneath4 $top $top/.. 0x1000 93 || s=1 +$dir/beneath4 $top ../a 0x1000 0 || s=1 + +printf "\nAT_RESOLVE_BENEATH\n" +$dir/beneath4 $top a 0x2000 0 || s=1 +$dir/beneath4 $top b 0x2000 2 || s=1 +$dir/beneath4 $top c 0x2000 0 || s=1 +$dir/beneath4 $top d 0x2000 93 || s=1 +$dir/beneath4 $top e 0x2000 93 || s=1 +$dir/beneath4 $top fifo 0x2000 0 || s=1 +$dir/beneath4 $top $top/../../beneath4.d/a/a 0x2000 22 || s=1 +$dir/beneath4 $top $top/.. 0x2000 22 || s=1 +$dir/beneath4 $top ../a 0x2000 93 || s=1 +printf "\nNo flag\n" +$dir/beneath4 $top ../a 0x0000 0 || s=1 +rm -rf $top +exit $s diff --git a/tools/test/stress2/misc/bio.sh b/tools/test/stress2/misc/bio.sh new file mode 100755 index 000000000000..d344fdb281c3 --- /dev/null +++ b/tools/test/stress2/misc/bio.sh @@ -0,0 +1,225 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# mmap() & read()/write() on same file. +# Test scenario suggestion by: jeff@ + +# Out of VM deadlock seen: +# https://people.freebsd.org/~pho/stress/log/jeff114.txt + +# panic: deadlkres: possible deadlock detected: +# https://people.freebsd.org/~pho/stress/log/jeff115.txt + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +ps=`sysctl -n hw.pagesize` +sed "1,/^EOF/d;s/\$ps/$ps/" < $odir/$0 > $dir/bio.c +mycc -o bio -Wall -Wextra -O0 -g bio.c || exit 1 +rm -f bio.c +cd $odir + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs -n md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +(cd $mntpoint; /tmp/bio) & +pid1=$! +sleep 5 +(cd ../testcases/swap; ./swap -t 5m -i 20 -k -l 100 -h) & +pid2=$! + +while pgrep -q bio; do + sleep 2 +done + +while pgrep -q swap; do + pkill -9 swap +done +wait $pid2 +wait $pid1 +s=$? + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -rf /tmp/bio +exit $s + +EOF +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define PS $ps /* From hw.pagesize */ +#define SYN1 0 +#define SYN2 1 +#define INDX 2 + +#define PAGES (512 * 1024 * 1024 / PS) /* 512MB file size */ +#define PARALLEL 3 +#define RUNTIME (5 * 60) +#define TIMEOUT (30 * 60) + +char buf[PS]; + +void +test(int inx) +{ + pid_t pid; + size_t i, len, slen; + time_t start; + volatile u_int *share; + int fd, r; + u_int *ip, val; + char file[80]; + + slen = PS; + if ((share = mmap(NULL, slen, PROT_READ | PROT_WRITE, MAP_ANON | + MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + snprintf(file, sizeof(file), "file.%06d", inx); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0640)) < 0) + err(1, "%s", file); + + for (i = 0; i < PAGES; i++) { + if (write(fd, buf, sizeof(buf)) != sizeof(buf)) + err(1, "write error"); + } + + len = PS * PAGES * sizeof(u_int); + if ((ip = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + if ((pid = fork()) == 0) { + alarm(2 * RUNTIME); + /* mmap read / write access */ + for (i = 0; i < (size_t)(PAGES * PS); i += PS) { + while (share[SYN1] == 0) + sched_yield(); + atomic_add_int(&share[SYN1], -1); + if (ip[share[INDX] / sizeof(u_int)] != share[INDX]) + warn("child expected %d, but got %d\n", + ip[share[INDX] / sizeof(u_int)], + share[INDX]); + share[INDX] += PS; + ip[share[INDX] / sizeof(u_int)] = share[INDX]; + atomic_add_int(&share[SYN2], 1); /* signal parent */ + if (i % 1000 == 0 && time(NULL) - start > TIMEOUT) + errx(1, "Timed out");; + } + _exit(0); + } + if (pid == -1) + err(1, "fork()"); + share[INDX] = 0; + atomic_add_int(&share[SYN2], 1); + alarm(2 * RUNTIME); + for (i = 0; i < (size_t)(PAGES * PS); i += PS) { + while (share[SYN2] == 0) + sched_yield(); + atomic_add_int(&share[SYN2], -1); + if (lseek(fd, share[INDX], SEEK_SET) == -1) + err(1, "lseek error"); + if ((r = read(fd, &val, sizeof(val))) != sizeof(val)) + err(1, "parent read read %d bytes", r); + if (val != share[INDX]) + warn("parent expected %d, but got %d\n", + share[INDX], val); + val += PS; + if (lseek(fd, val, SEEK_SET) == -1) + err(1, "lseek error"); + if (write(fd, &val, sizeof(val)) != sizeof(val)) + err(1, "write"); + + atomic_add_int(&share[SYN1], 1); /* signal child */ + if (i % 1000 == 0 && time(NULL) - start > TIMEOUT) + errx(1, "Timed out");; + } + atomic_add_int(&share[SYN2], -1); + if (waitpid(pid, NULL, 0) != pid) + err(1, "wait"); + + if (munmap(ip, len) == -1) + err(1, "unmap()"); + if (munmap((void *)share, slen) == -1) + err(1, "unmap()"); + close(fd); + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + time_t start; + int i, s, status; + + start = time(NULL); + s = 0; + while ((time(NULL) - start) < RUNTIME && s == 0) { + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(i); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) + fprintf(stderr, "Child exit status = %d\n", + status); + s += status == 0 ? 0 : 1; + } + } + + return (s); +} diff --git a/tools/test/stress2/misc/buildkernel.sh b/tools/test/stress2/misc/buildkernel.sh new file mode 100755 index 000000000000..fe8d530dfab7 --- /dev/null +++ b/tools/test/stress2/misc/buildkernel.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# Buildkernel test with SU + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -d /usr/src/sys ] || exit 0 +set -e +mount | grep -q "on $mntpoint " && umount $mntpoint +mdconfig -a -t swap -s 5g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +cd /usr/src +export MAKEOBJDIRPREFIX=$mntpoint/obj +export TMPDIR=$mntpoint/tmp +mkdir $TMPDIR +chmod 0777 $TMPDIR +log=$mntpoint/log + +p=$((`sysctl -n hw.ncpu`+ 1)) +p=`jot -r 1 1 $p` +echo "make -j $p buildkernel KERNCONF=GENERIC DESTDIR=$mntpoint" \ + "TARGET=amd64 TARGET_ARCH=amd64" +make -j $p buildkernel KERNCONF=GENERIC DESTDIR=$mntpoint TARGET=amd64 \ + TARGET_ARCH=amd64 > $log 2>&1; s=$? +[ $s -ne 0 ] && tail -50 $log + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/buildworld.sh b/tools/test/stress2/misc/buildworld.sh new file mode 100755 index 000000000000..ef4927d8dd1b --- /dev/null +++ b/tools/test/stress2/misc/buildworld.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# "panic: Invalid page 0xfffff8007f227cf0 on inact queue" seen. +# https://people.freebsd.org/~pho/stress/log/buildworld.txt +# Fixed by r289377 + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -d /usr/src/sys ] || exit 0 +[ `sysctl -n hw.physmem` -gt $(( 2 * 1024 * 1024 * 1024)) ] && + { echo "RAM must be clamped to 2GB or less for this test."; exit 0; } +rm -f $diskimage +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print $4}'` -lt \ + $((3 * 1024 * 1024)) ] && { echo "Need 3GB on `dirname $diskimage`"; \ + exit 0; } +mount | grep -q "on $mntpoint " && umount $mntpoint +dd if=/dev/zero of=$diskimage bs=1m count=3k status=none +trap "rm -f $diskimage" EXIT INT +mdconfig -a -t vnode -f $diskimage -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount -o async /dev/md${mdstart}$part $mntpoint + +cd /usr/src +export MAKEOBJDIRPREFIX=$mntpoint/obj +export TMPDIR=$mntpoint/tmp +mkdir $TMPDIR +chmod 0777 $TMPDIR + +p=$((`sysctl -n hw.ncpu`+ 1)) +timeout 20m make -i -j $p buildworld DESTDIR=$mntpoint TARGET=amd64 \ + TARGET_ARCH=amd64 > /dev/null + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +checkfs /dev/md$mdstart || s=$? +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/buildworld2.sh b/tools/test/stress2/misc/buildworld2.sh new file mode 100755 index 000000000000..9c1eed97b7ea --- /dev/null +++ b/tools/test/stress2/misc/buildworld2.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# tmpfs version of buildworld.sh + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -d /usr/src/sys ] || exit 0 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +[ `sysctl -n hw.physmem` -gt $(( 2 * 1024 * 1024 * 1024)) ] && + { echo "RAM must be clamped to 2GB or less."; exit 0; } +mount | grep -q "on $mntpoint " && umount $mntpoint +mount -t tmpfs tmpfs $mntpoint || exit 1 + +cd /usr/src +export MAKEOBJDIRPREFIX=$mntpoint/obj +export TMPDIR=$mntpoint/tmp +mkdir $TMPDIR +chmod 0777 $TMPDIR + +p=$((`sysctl -n hw.ncpu`+ 1)) +make -j $p buildworld DESTDIR=$mntpoint TARGET=amd64 TARGET_ARCH=amd64 \ + > /dev/null & +sleep $((20 * 60)) +kill $! +wait + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done diff --git a/tools/test/stress2/misc/buildworld3.sh b/tools/test/stress2/misc/buildworld3.sh new file mode 100755 index 000000000000..518c16151bcd --- /dev/null +++ b/tools/test/stress2/misc/buildworld3.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Buildworld / quota test scenario. + +# "panic: chkdquot: missing dquot" seen +# https://people.freebsd.org/~pho/stress/log/kostik1113.txt +# Fixed in r338798 + r338799 + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 +[ -d /usr/src/sys ] || exit 0 +mount | grep -q "on $mntpoint " && umount $mntpoint +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null + +export PATH_FSTAB=/tmp/fstab +trap "rm -f $PATH_FSTAB" EXIT INT +echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" > $PATH_FSTAB +mount $mntpoint +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export QK=$(($1 / 2)) +export QI=$(($2 / 2)) +edquota -u -f $mntpoint -e \ + ${mntpoint}:$((QK - 50)):$QK:$((QI - 50 )):$QI $testuser +quotaon $mntpoint +mount | grep $mntpoint + +cd /usr/src +export MAKEOBJDIRPREFIX=$mntpoint/obj +export TMPDIR=$mntpoint/tmp +mkdir $TMPDIR $MAKEOBJDIRPREFIX +chmod 0777 $TMPDIR $MAKEOBJDIRPREFIX + +p=$((`sysctl -n hw.ncpu`+ 1)) +su $testuser -c \ + "make -i -j $p buildworld DESTDIR=$mntpoint TARGET=amd64 \ + TARGET_ARCH=amd64 > /dev/null" & +sleep 2 +start=`date +%s` +while [ $((`date +%s` - start)) -lt 1200 ]; do + kill -0 $! > /dev/null 2>&1 || break + sleep 2 +done +kill $! > /dev/null 2>&1 +# Let make run 50% of the time so quotaoff runs on an active FS +[ `jot -r 1 0 1` -eq 1 ] && + pkill -U$testuser make +wait + +while ! quotaoff $mntpoint; do + sync + sleep 5 +done +pgrep -q -U$testuser make && pkill -U$testuser make +export tmp=/tmp/$(basename $0).$$ +quotacheck -v $mntpoint > $tmp 2>&1 +grep -q failed $tmp && { cat $tmp; s=1; } +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +checkfs /dev/md$mdstart || s=$? +mdconfig -d -u $mdstart +rm -f $PATH_FSTAB +exit $s diff --git a/tools/test/stress2/misc/buildworld4.sh b/tools/test/stress2/misc/buildworld4.sh new file mode 100755 index 000000000000..fae22b9a17b9 --- /dev/null +++ b/tools/test/stress2/misc/buildworld4.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Buildworld test with SUJ +# "fsync: giving up on dirty (error = 35): tag devfs, type VCHR" seen. + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -d /usr/src/sys ] || exit 0 +rm -f $diskimage +mount | grep -q "on $mntpoint " && umount $mntpoint +mdconfig -a -t swap -s 5g -u $mdstart +bsdlabel -w md$mdstart auto +[ "$newfs_flags" = "-U" ] && newfs_flags="-j" +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +mount | grep $mntpoint + +cd /usr/src +export MAKEOBJDIRPREFIX=$mntpoint/obj +export TMPDIR=$mntpoint/tmp +mkdir $TMPDIR +chmod 0777 $TMPDIR + +p=$((`sysctl -n hw.ncpu`+ 1)) +[ `sysctl -n vm.swap_total` -gt 0 ] && p=$((p * 4)) +p=`jot -r 1 1 $p` +echo "make -i -j $p buildworld DESTDIR=$mntpoint TARGET=amd64 "\ + "TARGET_ARCH=amd64" +make -i -j $p buildworld DESTDIR=$mntpoint TARGET=amd64 TARGET_ARCH=amd64 \ + > /dev/null & +sleep 1 +start=`date +%s` +while [ $((`date +%s` - start)) -lt 600 ]; do + kill -0 $! > /dev/null 2>&1 || break + sleep 30 +done +kill $! > /dev/null 2>&1 +wait + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +checkfs /dev/md$mdstart; s=$? +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/burnin.sh b/tools/test/stress2/misc/burnin.sh new file mode 100755 index 000000000000..0b6c206cd69b --- /dev/null +++ b/tools/test/stress2/misc/burnin.sh @@ -0,0 +1,210 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Time creating and deleting a number of files once a minute. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +export LANG=C +dir=/tmp +runtime=1200 # default +[ $# -eq 1 ] && runtime=$1 +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/burnin.c +mycc -o burnin -Wall -Wextra -O0 -g burnin.c || exit 1 +rm -f burnin.c +cd $odir + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs -n md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +d=`date '+%Y%m%dT%H%M%S'` +log=/tmp/burnin.$d.log +mode=`pgrep -q cron && echo "Multi-user" || echo "Single-user"` +echo "# `uname -a` $mode mode `hostname`" > $log + +/tmp/burnin -r 10 -d $mntpoint > /dev/null 2>&1 +/tmp/burnin -r $runtime -d $mntpoint >> $log + +ministat -A -C 2 -w 72 $log | tail -1 | awk '{if ($NF > .1) exit(1)}' +s=$? +[ $s -ne 0 ] && ministat -C 2 -w 72 $log + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -rf /tmp/burnin $log +exit 0 +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define DELAY 60 +#define SYNC 0 + +volatile u_int *share; +int bufsize, files, parallel, runtime; +char *buf, *dir; + +void +usage(void) +{ + fprintf(stderr, "Usage: %s [-b buf size] [-d directory] [-p parallel] " + "[-r runtime]\n", + getprogname()); + _exit(1); +} + +void +test(void) +{ + pid_t pid; + int fd, i; + char path[MAXPATHLEN + 1]; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != (volatile u_int)parallel) + ; + + pid =getpid(); + for (i = 0; i < files; i++) { + snprintf(path, sizeof(path), "%s/f%06d.%06d", dir, pid, i); + if ((fd = open(path, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE)) == + -1) + err(1, "open(%s)", path); + if (write(fd, buf, bufsize) != bufsize) + err(1, "write()"); + if (close(fd) == -1) + err(1, "close(%d)", fd); + if (unlink(path) == -1) + err(1, "unlink(%s)", path); + } + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + struct timeval t1, t2, diff; + struct tm *tp; + size_t len; + time_t start, now; + int ch, e, i, *pids, status; + char help[80]; + + bufsize = 8 * 1024; + dir = "/tmp"; + files = 5000; + parallel = 4; + runtime = 1 * 60 * 60 * 24; + + while ((ch = getopt(argc, argv, "b:d:f:r:")) != -1) + switch(ch) { + case 'b': /* bufsize */ + if (sscanf(optarg, "%d", &bufsize) != 1) + usage(); + break; + case 'd': /* dir */ + dir = optarg; + break; + case 'f': /* files */ + if (sscanf(optarg, "%d", &files) != 1) + usage(); + break; + case 'p': /* parallel */ + if (sscanf(optarg, "%d", ¶llel) != 1) + usage(); + break; + case 'r': /* runtime */ + if (sscanf(optarg, "%d", &runtime) != 1) + usage(); + break; + default: + usage(); + } + argc -= optind; + argv += optind; + + printf("# Options used: dir=%s, bufsize=%d, files=%d, parallel=%d, " + "runtime=%d\n", + dir, bufsize, files, parallel, runtime); + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d)", bufsize); + if ((pids = malloc(sizeof(pid_t) * parallel)) == NULL) + err(1, "malloc(%d)", (int)(sizeof(pid_t) * parallel)); + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < runtime && e == 0) { + share[SYNC] = 0; + gettimeofday(&t1, NULL); + for (i = 0; i < parallel; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < parallel; i++) { + waitpid(pids[i], &status, 0); + e += status == 0 ? 0 : 1; + } + gettimeofday(&t2, NULL); + timersub(&t2, &t1, &diff); + now = time(NULL); + tp = localtime(&now); + strftime(help, sizeof(help), "%Y%m%d%H%M%S", tp); + printf("%s %ld.%06ld\n", help, (long)diff.tv_sec, + diff.tv_usec); + fflush(stdout); + if (runtime > DELAY) + sleep(DELAY); + } + + return (e); +} diff --git a/tools/test/stress2/misc/callout_reset_on.sh b/tools/test/stress2/misc/callout_reset_on.sh new file mode 100755 index 000000000000..cdffc0dd67f7 --- /dev/null +++ b/tools/test/stress2/misc/callout_reset_on.sh @@ -0,0 +1,331 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Scenario based on pr. kern/166340 +# Process under FreeBSD 9.0 hangs in uninterruptable sleep with apparently +# no syscall (empty wchan). + +# http://people.freebsd.org/~pho/stress/log/callout_reset_on.txt +# Fixed in r243901. + +# panic: Bad link elm 0xfffff80012ba8ec8 prev->next != elm +# https://people.freebsd.org/~pho/stress/log/rrs005.txt +# Fixed in r278623. + +# "ritwait DE 0- 0:00.01 crlogger: writer" seen. +# https://people.freebsd.org/~pho/stress/log/kostik917.txt +# Fixed in r302981 + +. ../default.cfg + +rm -f /tmp/crwriter /tmp/crlogger || exit 1 + +cat > /tmp/crwriter.c < +#include +#include +#include + +char *txt[] = { + "0 This is a line of text: abcdefghijklmnopqrstuvwxyz", + "1 Another line of text: ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "2 A different line of text", + "3 A very, very different text", + "4 A much longer line with a lot of characters in the line", + "5 Now this is a quite long line of text, with both upper and lower case letters, and one digit!" +}; + +int +main(void) +{ + int i, j, n; + char help[256]; + + for (i = 0; i < 100000; i++) { + j = arc4random() % 6; + n = arc4random() % strlen(txt[j]); + strncpy(help, txt[j], n); + help[n] = 0; + printf("%s\n", txt[j]); + if ((arc4random() % 1000) == 1) + usleep(100000); + } + + return (0); +} +EOF +mycc -o /tmp/crwriter -Wall -Wextra -O2 -g /tmp/crwriter.c +rm -f /tmp/crwriter.c + +cat > /tmp/crlogger.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BARRIER_CREATE 1 +#define BARRIER_WAIT 2 +#define BARRIER_DELETE 3 + +void +barrier(int mode) +{ + int fd; + char path[128]; + + if (mode == BARRIER_CREATE) { + snprintf(path, sizeof(path), "barrier.%d", getpid()); + if ((fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) + err(1, "%s", path); + } else if (mode == BARRIER_WAIT) { + snprintf(path, sizeof(path), "barrier.%d", getppid()); + for(;;) { + if (access(path, R_OK) == -1) + break; + usleep(10000); + } + } else if (mode == BARRIER_DELETE) { + snprintf(path, sizeof(path), "barrier.%d", getpid()); + if (unlink(path) == -1) + err(1, "unlink(%s)", path); + } else + errx(1, "Bad barrier mode: %d", mode); +} + +pid_t pid; +int bufsize; +int port; +int alarm_exit; + +void +killer(void) +{ + setproctitle("killer"); + alarm(120); + barrier(BARRIER_WAIT); + for (;;) { + if (pid == 0) + break; + if (kill(pid, SIGUSR1) == -1) + break; + usleep(1000); + } + _exit(0); +} + +void +handler(int s __unused) +{ +} + +void +ahandler(int s __unused) +{ + if (alarm_exit) + _exit(0); +} + +/* Read form socket, discard */ +static void +reader(void) { + int tcpsock, msgsock; + int on; + socklen_t len; + struct sockaddr_in inetaddr, inetpeer; + int n, *buf; + + setproctitle("reader - init"); + 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); + + signal(SIGUSR1, handler); + alarm(60); + 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__); + + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + setproctitle("reader"); + alarm(0); + signal(SIGALRM, ahandler); + for (;;) { + ualarm(5000, 0); + if ((n = recvfrom(msgsock, buf, 4, 0, NULL, NULL)) < 0) { + if (errno == EAGAIN) + continue; + err(1, "read(), %s:%d", __FILE__, __LINE__); + } + if (n == 0) + break; + if (write(msgsock, "OK", 3) != 3) + err(1, "write ack. %s:%d", __FILE__, __LINE__); + + } + close(msgsock); + _exit(0); +} + +/* read from stdin, write to socket */ +static void +writer(void) { + int tcpsock, on; + struct sockaddr_in inetaddr; + struct hostent *hostent; + int i, r; + char line[1024], ack[80];; + pid_t ppid; + + setproctitle("writer - init"); + ppid = getppid(); + signal(SIGUSR1, handler); + alarm(60); + 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"); + bzero(&inetaddr, sizeof(inetaddr)); + memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, + sizeof (struct in_addr)); + + inetaddr.sin_family = AF_INET; + 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__); + + setproctitle("writer"); + barrier(BARRIER_DELETE); + alarm(0); + while (fgets(line, sizeof(line), stdin) != NULL) { + alarm(10); + alarm_exit = 1; + if (write(tcpsock, line, strlen(line)) < 0) + err(1, "socket write(). %s:%d", __FILE__, __LINE__); + alarm_exit = 0; + ualarm(5000, 0); + if (recvfrom(tcpsock, ack, 4, 0, NULL, NULL) < 0) { + if (errno == EAGAIN) + continue; + err(1, "read(), %s:%d", __FILE__, __LINE__); + } + } + sleep(30); + return; +} + +int +main(int argc, char **argv) +{ + + pid_t kpid; + + if (argc != 2) + errx(1, "Usage: %s \n", argv[0]); + port = atoi(argv[1]); + bufsize = 128; + + barrier(BARRIER_CREATE); + signal(SIGCHLD, SIG_IGN); + if ((pid = fork()) == 0) + reader(); + + if ((kpid = fork()) == 0) + killer(); + + writer(); + sleep(1); + kill(pid, SIGINT); + kill(kpid, SIGINT); + + return (0); +} +EOF +mycc -o /tmp/crlogger -Wall -Wextra -O2 -g /tmp/crlogger.c +rm -f /tmp/crlogger.c + +N=200 +cd /tmp +start=`date '+%s'` +for i in `jot 40`; do + for j in `jot $N`; do + /tmp/crwriter | /tmp/crlogger 1236$j 2>/dev/null & + done + + for j in `jot $N`; do + wait + done + [ $((`date '+%s'` - start)) -gt 1200 ] && break +done +rm -f /tmp/crwriter /tmp/crlogger ./barrier.* +exit 0 diff --git a/tools/test/stress2/misc/callout_reset_on2.sh b/tools/test/stress2/misc/callout_reset_on2.sh new file mode 100755 index 000000000000..270aeb95aa97 --- /dev/null +++ b/tools/test/stress2/misc/callout_reset_on2.sh @@ -0,0 +1,303 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Copy of callout_reset_on.sh. Waiting to see if this catches anything. + +. ../default.cfg + +rm -f /tmp/crwriter2 /tmp/crlogger2 || exit 1 + +cat > /tmp/crwriter2.c < +#include +#include +#include +#include + +char *txt[] = { + "0 This is a line of text: abcdefghijklmnopqrstuvwxyz", + "1 Another line of text: ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "2 A different line of text", + "3 A very, very different text", + "4 A much longer line with a lot of characters in the line", + "5 Now this is a quite long line of text, with both upper and lower case letters, and one digit!" +}; + +#define RUNTIME (10 * 60) + +int +main(void) +{ + time_t start; + int j, n; + char help[256]; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + j = arc4random() % 6; + n = arc4random() % strlen(txt[j]); + strncpy(help, txt[j], n); + help[n] = 0; + printf("%s\n", txt[j]); + if ((arc4random() % 1000) == 1) + usleep(100000); + } + + return (0); +} +EOF +mycc -o /tmp/crwriter2 -Wall -Wextra -O2 -g /tmp/crwriter2.c +rm -f /tmp/crwriter2.c + +cat > /tmp/crlogger2.c < +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +volatile u_int *share; + +#define SYNC 0 + +pid_t pid; +int bufsize; +int port; +int alarm_exit; + +void +killer(void) +{ + setproctitle("killer"); + while (share[SYNC] == 0) + ; + alarm(120); + for (;;) { + if (pid == 0) + break; + if (kill(pid, SIGUSR1) == -1) + break; + usleep(arc4random() % 2000 + 10); + } + _exit(0); +} + +void +handler(int s __unused) +{ +} + +void +ahandler(int s __unused) +{ + if (alarm_exit) + _exit(0); +} + +/* Read form socket, discard */ +static void +reader(void) { + int tcpsock, msgsock; + int on; + socklen_t len; + struct sockaddr_in inetaddr, inetpeer; + int n, *buf; + + setproctitle("reader - init"); + 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); + + signal(SIGUSR1, handler); + alarm(60); + 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__); + + if ((buf = malloc(bufsize)) == NULL) + err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); + setproctitle("reader"); + alarm(0); + signal(SIGALRM, ahandler); + for (;;) { + ualarm(arc4random() % 5000 + 100, 0); + if ((n = recvfrom(msgsock, buf, bufsize, 0, NULL, NULL)) < 0) { + if (errno == EAGAIN) + continue; + err(1, "read(), %s:%d", __FILE__, __LINE__); + } + if (n == 0) + break; + if (write(msgsock, "OK", 3) != 3) + err(1, "write ack. %s:%d", __FILE__, __LINE__); + + } + close(msgsock); + _exit(0); +} + +/* read from stdin, write to socket */ +static void +writer(void) { + int tcpsock, on; + struct sockaddr_in inetaddr; + struct hostent *hostent; + int i, r; + char line[1024], ack[80];; + pid_t ppid; + + setproctitle("writer - init"); + share[SYNC] = 1; + ppid = getppid(); + signal(SIGUSR1, handler); + signal(SIGALRM, ahandler); + alarm(60); + 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"); + bzero(&inetaddr, sizeof(inetaddr)); + memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, + sizeof (struct in_addr)); + + inetaddr.sin_family = AF_INET; + 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__); + + setproctitle("writer"); + alarm(0); + while (fgets(line, sizeof(line), stdin) != NULL) { + alarm(10); + alarm_exit = 1; + if (write(tcpsock, line, strlen(line)) < 0) + err(1, "socket write(). %s:%d", __FILE__, __LINE__); + alarm_exit = 0; + ualarm(arc4random() % 5000 + 1000, 0); + if (recvfrom(tcpsock, ack, 4, 0, NULL, NULL) < 0) { + if (errno == EAGAIN) + continue; + err(1, "read(), %s:%d", __FILE__, __LINE__); + } + } + sleep(30); + return; +} + +int +main(int argc, char **argv) +{ + + pid_t kpid; + size_t len; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + _exit(1); + } + port = atoi(argv[1]); + bufsize = 128; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + signal(SIGCHLD, SIG_IGN); + if ((pid = fork()) == 0) + reader(); + + if ((kpid = fork()) == 0) + killer(); + + writer(); + sleep(1); + kill(pid, SIGINT); + kill(kpid, SIGINT); + + return (0); +} +EOF +mycc -o /tmp/crlogger2 -Wall -Wextra -O2 -g /tmp/crlogger2.c +rm -f /tmp/crlogger2.c + +N=50 +cd /tmp +for j in `jot $N`; do + /tmp/crwriter2 | /tmp/crlogger2 1236$j & +done +wait +rm -f /tmp/crwriter2 /tmp/crlogger2 +exit 0 diff --git a/tools/test/stress2/misc/chain.sh b/tools/test/stress2/misc/chain.sh new file mode 100755 index 000000000000..46d2f32cd7c4 --- /dev/null +++ b/tools/test/stress2/misc/chain.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Jeremy +# +# 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. +# +# Unkillable process in "vm map (user)" seen. +# https://people.freebsd.org/~pho/stress/log/kostik1070.txt +# Fixed by: r327468 + +# OOM killing: https://people.freebsd.org/~pho/stress/log/chain.txt + +if [ ! -f /usr/local/include/libmill.h -o \ + ! -x /usr/local/lib/libmill.so ]; then + echo "ports/devel/libmill needed." + exit 0 +fi + +. ../default.cfg + +cat > /tmp/chain.c < +#include +#include + +coroutine void f(chan left, chan right) { + chs(left, int, 1 + chr(right, int)); +} + +int +main(int argc __unused, char **argv) +{ + int i, n = argv[1] ? atoi(argv[1]) : 10000; + chan leftmost = chmake(int, 0); + chan left = NULL; + chan right = leftmost; + + alarm(600); + for (i = 0; i < n; i++) { + left = right; + right = chmake(int, 0); + go(f(left, right)); + } + chs(right, int, 0); + i = chr(leftmost, int); + printf("result = %d\n", i); + return(0); +} +EOF + +mycc -o /tmp/chain -I /usr/local/include -L /usr/local/lib -Wall -Wextra \ + -O2 -g /tmp/chain.c -lmill || exit 1 +limits -c 0 /tmp/chain 1000000 +rm -f /tmp/chain /tmp/chain.c +exit 0 diff --git a/tools/test/stress2/misc/churn.sh b/tools/test/stress2/misc/churn.sh new file mode 100755 index 000000000000..6d40381e32bd --- /dev/null +++ b/tools/test/stress2/misc/churn.sh @@ -0,0 +1,211 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# VM test. No problems seen. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/churn.c +mycc -o churn -Wall -Wextra -O0 -g churn.c -lpthread || exit 1 +rm -f churn.c + +/tmp/churn `sysctl -n hw.ncpu` `sysctl -n hw.usermem` +s=$? + +rm -rf /tmp/churn +exit $? + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#ifdef __FreeBSD__ +#include +#define __NP__ +#endif +#include +#include +#include +#include + +#define ARRAYSIZE (4 * 1024) +#define RUNTIME (10 * 60) +#define SYNC 0 + +volatile u_int *share; +long mem, parallel; +int done; + +struct { + void *addr; + long pages; + volatile u_int busy; +} v[ARRAYSIZE]; + +void * +test2(void *arg __unused) +{ + long i, j, n; + volatile char *cp; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + while (done == 0) { + n = 0; + for (i = 0; i < ARRAYSIZE; i++) { + if (v[i].pages == 0) + continue; + atomic_add_int(&v[i].busy, 1); + if (v[i].busy != 1) { + atomic_add_int(&v[i].busy, -1); + continue; + } + cp = v[i].addr; + for (j = 0; j < v[i].pages; j++) + cp[j * PAGE_SIZE] = 1; + atomic_add_int(&v[i].busy, -1); + n++; + } + if (n == 0) { + usleep(10000); + } + } + + return (0); +} + +void +test(void) +{ + pthread_t tp[2]; + size_t len; + time_t start; + long i, j, k, size; + int r; + volatile char *cp; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != (volatile u_int)parallel) + ; + + if ((r = pthread_create(&tp[0], NULL, test2, NULL)) != 0) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&tp[1], NULL, test2, NULL)) != 0) + errc(1, r, "pthread_create"); + size = 0; + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (k = 0; k < ARRAYSIZE; k++) { + i = arc4random() % ARRAYSIZE; + if (v[i].pages != 0) + break; + } + if (v[i].addr != NULL) { + atomic_add_int(&v[i].busy, 1); + if (v[i].busy != 1) { + atomic_add_int(&v[i].busy, -1); + continue; + } + if (munmap(v[i].addr, v[i].pages * PAGE_SIZE) == -1) + err(1, "munmap(%p, %ld)", v[i].addr, v[i].pages); + v[i].addr = NULL; + size -= v[i].pages; + v[i].pages = 0; + atomic_add_int(&v[i].busy, -1); + } + if (size < mem) { + j = round_page((arc4random() % (mem / 10)) + 1); + len = j * PAGE_SIZE; + if ((v[i].addr = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) { + v[i].addr = NULL; + continue; + } + atomic_add_int(&v[i].busy, 1); + v[i].pages = j; + size += j; + assert(size > 0); + cp = v[i].addr; + for (k = 0; k < j * PAGE_SIZE; k += PAGE_SIZE) + cp[k] = 1; + atomic_add_int(&v[i].busy, -1); + } + } + done = 1; + pthread_join(tp[0], NULL); + pthread_join(tp[1], NULL); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + size_t len; + int e, i, *pids, status; + + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + _exit(1); + } + + parallel = atol(argv[1]); + mem = atol(argv[2]) / PAGE_SIZE; + mem = mem / parallel; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + pids = malloc(sizeof(void *) * parallel); + for (i = 0; i < parallel; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < parallel; i++) { + waitpid(pids[i], &status, 0); + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/cleanup.sh b/tools/test/stress2/misc/cleanup.sh new file mode 100755 index 000000000000..ac8762d225b5 --- /dev/null +++ b/tools/test/stress2/misc/cleanup.sh @@ -0,0 +1,105 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +bname=`basename $mntpoint` +mounts=`mount | awk "/$bname/{print \\$3}"` +nmounts=`sysctl -n hw.ncpu` # Max number of mounts in use +[ $nmounts -lt 31 ] && nmounts=31 # Arbitrary value +s=0 +# Unmount the test mount points: /mnt, /mnt10 .. mnt31 +for i in $mounts; do + u=`echo $i | sed "s/\/$bname//"` + [ -z "$u" ] && u=$mdstart + echo "$u" | grep -Eq '^[0-9]+$' || continue +# [ $u -lt $mdstart -o $u -gt $((mdstart + nmounts)) ] && continue + while mount | grep -q "on $i "; do + r=`fstat -mf $i 2>/dev/null | awk '$3 ~ /^[0-9]+$/ {print $3}'` + if [ -n "$r" ]; then + echo "cleanup.sh: kill $r" + echo $r | xargs kill; sleep 1 + fi + echo "cleanup.sh: umount -f $i" + umount -f $i > /dev/null 2>&1 || s=1 + [ -z "$r" ] && break + done +done + +# Delete the test mount points /mnt10 .. /mnt31 +for i in `ls -d $mntpoint* 2>/dev/null | grep -Ev '^$mntpoint$'`; do + u=`echo $i | sed "s/\/$bname//"` + echo "$u" | grep -Eq '^[0-9]+$' || continue +# [ $u -lt $mdstart -o $u -gt $((mdstart + nmounts)) ] && continue + if ! mount | grep -q "on $i "; then + [ -d $i ] && find $i -delete \ + 2>/dev/null + rm -rf $i > /dev/null 2>&1 + fi +done + +# Delete the memory disks +units=`mdconfig -l | sed 's/md//g'` +for u in $units; do + if [ $u -ge $mdstart -a $u -lt $((mdstart + nmounts)) ]; then + echo "cleanup.sh: mdconfig -d -u $u" + mdconfig -d -u $u || s=1 + [ -c /dev/md$u ] && sleep .1 + fi +done + +[ -d "$mntpoint" ] && (cd $mntpoint && find . -delete) +rm -f /tmp/.snap/stress2* /var/.snap/stress2* +rm -rf /tmp/stressX.control $RUNDIR +[ -d `dirname "$diskimage"` ] || mkdir -p `dirname "$diskimage"` +mkdir -p $RUNDIR +chmod 0777 $RUNDIR + +# Delete $testuser's ipcs +ipcs | awk "\$5 ~/$testuser/ && \$6 ~/$testuser/ {print \"-\" \$1,\$2}" | \ + xargs -t ipcrm + +# Modules +#mlist=/tmp/stress2.d/mlist +#find $mlist -mtime +1 -delete 2>/dev/null +#[ -f $mlist ] && touch $mlist || +# { kldstat | kldstat | awk '/\.ko$/ {print $NF}' > $mlist; \ +# echo "Updating $mlist"; } +#for m in `kldstat | awk '/\.ko$/ {print $NF}'`; do +# grep -q $m $mlist && continue +# echo "pty.ko mqueuefs.ko ioat.ko ums.ko" | grep -q $m && continue +# echo "cleanup.sh: kldunload $m" +# kldunload $m +#done +# unloading an active dtrace causes a panic +#kldstat | grep -q dtraceall.ko && kldunload dtraceall.ko +kldstat | grep -q ext2fs.ko && kldunload ext2fs.ko +[ $s -ne 0 ] && echo "cleanup.sh: FAIL $s" +exit $s diff --git a/tools/test/stress2/misc/cluster.sh b/tools/test/stress2/misc/cluster.sh new file mode 100755 index 000000000000..bcda95da4755 --- /dev/null +++ b/tools/test/stress2/misc/cluster.sh @@ -0,0 +1,269 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Open four (sparse) files for random read and write. + +# "panic: softdep_deallocate_dependencies: dangling deps" seen: +# https://people.freebsd.org/~pho/stress/log/kirk075.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=`dirname $diskimage` +free=`df -k $dir | tail -1 | awk '{print $4}'` +[ $((free / 1024 / 1024)) -lt 9 ] && echo "Not enough disk space." && exit + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > cluster.c +rm -f /tmp/cluster +mycc -o cluster -Wall -Wextra -g -O2 cluster.c || exit 1 +rm -f cluster.c +cd $odir + +su $testuser -c "/tmp/cluster $dir abc" + +rm -f /tmp/cluster +exit 0 +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define BSIZE (8 * 1024 * 1024) +#define MX (8LL * 1024 * 1024 * 1024) +#define PARALLEL 4 +#define RUNTIME 600 +#define WRLOOPS 1024 + +int rfd; +char *buf; +char *path; +char *uid; +char file[MAXPATHLEN + 1]; + +unsigned long long +rnd(void) { + unsigned long long v; + + read(rfd, &v, sizeof(v)); + v = v % MX; + return (v); +} + +void +wr(int idx) +{ + off_t offset; + size_t ln; + int fd, i, n; + + snprintf(file, sizeof(file), "%s/f.%s.%06d", path, uid, idx); + setproctitle(__func__); + if ((fd = open(file, O_RDWR | O_CREAT, 0644)) == -1) + err(1, "open(%s)", file); + n = arc4random() % WRLOOPS + 1; + for (i = 0; i < n; i++) { + ln = rnd() % BSIZE + 1; + offset = rnd() % (MX - ln); + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek in rw 1"); + while (lockf(fd, F_LOCK, ln) == -1) { + if (errno != EDEADLK) + err(1, "lockf(%s, F_LOCK)", file); + } + if (write(fd, buf, ln) < 0) + err(1, "write"); + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek in rw 2"); + if (lockf(fd, F_ULOCK, ln) == -1) + err(1, "lockf(%s, F_ULOCK)", file); + } + close(fd); + _exit(0); +} + +void +rd(int idx) +{ + off_t offset; + size_t ln; + int fd, i, n; + + snprintf(file, sizeof(file), "%s/f.%s.%06d", path, uid, idx); + setproctitle(__func__); + for (i = 0; i < 100; i++) { + if (access(file, R_OK) == 0) + break; + usleep(1000); + } + if ((fd = open(file, O_RDONLY)) == -1) + if (errno != ENOENT) + err(1, "open(%s)for read", file); + n = arc4random() % WRLOOPS + 1; + for (i = 0; i < n; i++) { + ln = rnd() % BSIZE + 1; + offset = rnd() % (MX - ln); + if (lseek(fd, offset, SEEK_SET) == -1) { + if (errno == EBADF) + continue; + err(1, "lseek in rd"); + } + if (read(fd, buf, ln) < 0) + err(1, "write"); + } + close(fd); + _exit(0); +} + +void +mv(int idx) +{ + int i; + char file2[MAXPATHLEN + 1]; + + snprintf(file, sizeof(file), "%s/f.%s.%06d", path, uid, idx); + snprintf(file2, sizeof(file2), "%s/f.%s.%06d.old", path, uid, idx); + for (i = 0; i < 100; i++) { + if (access(file, R_OK) == 0) + break; + usleep(1000); + } + if (rename(file, file2) == -1) + if (errno != ENOENT) + warn("rename(%s, %s)", file, file2); + _exit(0); +} + +void +tr(int idx) +{ + off_t offset; + int fd; + + if (arc4random() % 100 < 10) { + snprintf(file, sizeof(file), "%s/f.%s.%06d", path, uid, idx); + setproctitle(__func__); + if ((fd = open(file, O_RDWR | O_CREAT, 0644)) == -1) + err(1, "open(%s)for read", file); + offset = rnd() % MX; + offset = rnd(); + if (ftruncate(fd, offset) == -1) + err(1, "truncate"); + close(fd); + } + _exit(0); +} + +void +rm(int idx) +{ + int i; + char file2[MAXPATHLEN + 1]; + + snprintf(file2, sizeof(file2), "%s/f.%s.%06d.old", path, uid, idx); + for (i = 0; i < 100; i++) { + if (access(file2, R_OK) == 0) + break; + usleep(1000); + } + if (unlink(file2) == -1) + if (errno != ENOENT) + warn("unlink(%s)", file2); + _exit(0); +} + +void +test2(void (*func)(int nr)) +{ + time_t start; + int i; + + setproctitle(__func__); + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + func(i); + } + for (i = 0; i < PARALLEL; i++) + wait(NULL); + } + _exit(0); + +} + +void +test(void (*func)(int nr)) +{ + + if (fork() == 0) + test2(func); +} + +int +main(int argc, char *argv[]) +{ + int i; + + if (argc != 3) + errx(1, "Usage: %s ", argv[0]); + + path = argv[1]; + uid = argv[2]; + + if ((rfd = open("/dev/random", O_RDONLY)) == -1) + err(1, "open(/dev/random)"); + setproctitle(__func__); + buf = malloc(BSIZE); + test(wr); + test(rd); + test(tr); + test(mv); + for (i = 0; i < 4; i++) + if (wait(NULL) == -1) + err(1, "wait"); + + for (i = 0; i < PARALLEL; i++) { + snprintf(file, sizeof(file), "%s/f.%s.%06d", path, uid, i); + unlink(file); + snprintf(file, sizeof(file), "%s/f.%s.%06d.old", path, uid, i); + unlink(file); + } + + return (0); +} diff --git a/tools/test/stress2/misc/cmp.sh b/tools/test/stress2/misc/cmp.sh new file mode 100755 index 000000000000..bd492c8493ca --- /dev/null +++ b/tools/test/stress2/misc/cmp.sh @@ -0,0 +1,187 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Cross mount test of mkdir(2). +# Page fault seen: +# http://people.freebsd.org/~pho/stress/log/cmp.txt +# Fixed by r275347 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > cmp.c +mycc -o cmp -Wall -Wextra -O2 -g cmp.c || exit 1 +rm -f cmp.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +# Don't use SU due to bogus "out of inodes" messages. +newfs md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 5m -i 20 -h -l 100)" \ + > /dev/null 2>&1 +sleep 1 +su $testuser -c "/tmp/cmp $mntpoint" & + +while kill -0 $! 2>/dev/null; do + umount -f $mntpoint && + mount /dev/md${mdstart}$part $mntpoint + chmod 777 $mntpoint + sleep .1 +done +wait + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +[ -d "$mntpoint" ] && (cd $mntpoint && find . -delete) + +# tmpfs +mount -t tmpfs tmpfs $mntpoint +chmod 777 $mntpoint + +su $testuser -c "/tmp/cmp $mntpoint" & + +while kill -0 $! 2>/dev/null; do + umount -f $mntpoint && + mount -t tmpfs tmpfs $mntpoint + chmod 777 $mntpoint + sleep .1 +done +pkill -9 swap +wait + +while pkill -9 swap; do + : +done > /dev/null 2>&1 +while mount | grep $mntpoint | grep -q tmpfs; do + umount $mntpoint || sleep 1 +done +[ -d "$mntpoint" ] && (cd $mntpoint && find . -delete) +rm -f /tmp/cmp +exit 0 +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 160 +#define PARALLEL 16 + +int nbc, nbd; +char *dir; + +void +tmkdir(void) +{ + int i, j; + char d[MAXPATHLEN + 1], name[MAXPATHLEN + 1]; + + setproctitle(__func__); + + i = 0; + snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid()); + if (mkdir(name, 0755) == -1) { + if (errno != ENAMETOOLONG && errno != ENOENT && + errno != EBUSY && errno != EACCES && errno != EPERM) + warn("mkdir(%s)", name); + _exit(0); + } + for (;;) { + snprintf(d, sizeof(d), "/%d", i++); + strncat(name, d, sizeof(name) - 1); + if (mkdir(name, 0755) == -1) { + if (errno != ENAMETOOLONG && errno != ENOENT && + errno != EBUSY && errno != EACCES && errno != EPERM) + warn("mkdir(%s)", name); + i--; + break; + } + nbc++; + } + + while (i >= 0) { + snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid()); + for (j = 0; j < i; j++) { + snprintf(d, sizeof(d), "/%d", j); + strncat(name, d, sizeof(name) - 1); + } + if (rmdir(name) == -1) { + if (errno != ENOTEMPTY && errno != ENOENT && errno != + EBUSY) + warn("rmdir(%s)", name); + } else + nbd++; + i--; + } +#if defined(TEST) + if (nbc == 0) + fprintf(stderr, "FAIL nbc = %d, nbd = %d\n", nbc, nbd); +#endif + _exit(0); +} + +int +main(int argc, char **argv) +{ + int i, j; + + if (argc != 2) { + fprintf(stderr, "Usage: %s ", argv[0]); + exit(1); + } + dir = argv[1]; + + for (j = 0; j < LOOPS; j++) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + tmkdir(); + } + for (i = 0; i < PARALLEL; i++) + wait(NULL); + } + + return(0); +} diff --git a/tools/test/stress2/misc/collapse.sh b/tools/test/stress2/misc/collapse.sh new file mode 100755 index 000000000000..fc903d49c6a2 --- /dev/null +++ b/tools/test/stress2/misc/collapse.sh @@ -0,0 +1,153 @@ +#!/bin/sh + +# +# Copyright (c) 2020 Jeffrey Roberson +# 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. +# + +. ../default.cfg + +# "panic: freeing mapped page 0xfffffe000aa73910" seen: +# https://people.freebsd.org/~pho/stress/log/collapse.txt + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > collapse.c +mycc -o collapse -Wall -Wextra -g -O0 collapse.c || exit 1 +rm -f collapse.c +cd $odir + +daemon sh -c '(cd ../testcases/swap; ./swap -t 20m -i 16 -l 85)' > \ + /dev/null 2>&1 +sleep 2 +/tmp/collapse +while pgrep -q swap; do + pkill -9 swap +done +rm -f /tmp/collapse +exit 0 + +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define ADRSPACE (256 * 1024) +#define DEPTH 6 +#define WIDTH 3 +#define PARALLEL 4 +#define RUNTIME 1200 +#define CHILDTIME 5 +#define STARTTIME 5 +#define TOUCH 16 + +char *p; + +static void +child(int depth, time_t start) +{ + time_t run, delay; + int i, shared, off; + int len; + + /* Pick a random bit of address space to change inherit on. */ + for (i = 0; i < ADRSPACE; i += len) { + shared = arc4random() & 0x1; + len = roundup2(arc4random() % ((ADRSPACE - i) / 4), + PAGE_SIZE); + if (minherit(p + i, len, shared ? INHERIT_SHARE : + INHERIT_COPY) != 0) + err(1, "minherit"); + } + + for (i = 0; depth != 0 && i < WIDTH; i++) + if (fork() == 0) + child(depth - 1, start); + + /* + * Touch all of the memory and exit at a random time to collapse + * some portion of the chain. + */ + delay = arc4random() % (CHILDTIME - 1); + run = arc4random() % (CHILDTIME - delay); + for (;;) { + if (time(NULL) >= start + delay) + break; + usleep(100); + } + while (time(NULL) - start < run) { + off = rounddown2(arc4random() % ADRSPACE, PAGE_SIZE); + bzero(p + off, PAGE_SIZE); + usleep((run * 1000) / TOUCH); + } + + _exit(0); +} + +static void +work(int depth) +{ + + if ((p = mmap(NULL, ADRSPACE, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0)) == MAP_FAILED) { + if (errno == ENOMEM) + return; + err(1, "mmap()"); + } + child(depth, time(NULL) + STARTTIME); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + time_t start; + int i, n; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + n = arc4random() % PARALLEL + 1; + for (i = 0; i < n; i++) { + if ((pids[i] = fork()) == 0) + work(DEPTH); + } + + sleep(CHILDTIME + STARTTIME + 1); + + for (i = 0; i < n; i++) + if (waitpid(pids[i], NULL, 0) != pids[i]) + err(1, "waitpid(%d)", pids[i]); + } + + return (0); +} diff --git a/tools/test/stress2/misc/compare.sh b/tools/test/stress2/misc/compare.sh new file mode 100755 index 000000000000..c983046384b5 --- /dev/null +++ b/tools/test/stress2/misc/compare.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Compare two disk files. + +diskimage=/var/tmp/diskimage + +d1=$diskimage +d2=${diskimage}2 +have=`df -k $(dirname $d1) | tail -1 | awk '{print int($4 / 1024)}'` +[ $have -lt 1024 ] && + { echo "Not enough disk space on `dirname $d1`"; exit 1; } + +dd if=/dev/random of=$d1 bs=1m count=512 status=none || exit 1 +cp $d1 $d2 +cmp $d1 $d2 && s=0 || { echo FAIL; s=1; } +rm -f $d1 $d2 +exit $s diff --git a/tools/test/stress2/misc/context.sh b/tools/test/stress2/misc/context.sh new file mode 100755 index 000000000000..02fc9b8df4c1 --- /dev/null +++ b/tools/test/stress2/misc/context.sh @@ -0,0 +1,130 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > context.c +mycc -o context -Wall -Wextra -O2 -g context.c || exit 1 +rm -f context.c +[ -d $RUNDIR ] || mkdir -p $RUNDIR +cd $RUNDIR + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 10m -i 20)" > \ + /dev/null 2>&1 +for i in `jot 4`; do + /tmp/context & + pids="$pids $!" +done +s=0 +for i in $pids; do + wait $i + [ $? -ne 0 ] && s=$((s + 1)) +done +while pgrep -q swap; do + pkill -9 swap +done +rm -f /tmp/context +exit $s +EOF +/* + * Inspired by lmbench-3.0-a9/src/lat_ctx.c + * Pass a token thru pipes to CHILDREN+1 processes in a circular list + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define CHILDREN 64 +#define RUNTIME 300 + +int fds[CHILDREN +1 ][2]; +pid_t pid[CHILDREN]; + +void +handler(int s __unused) +{ + _exit(0); +} + +int +main(void) +{ + time_t start; + int i, j; + int token; + + for (i = 0; i < CHILDREN + 1; i++) { + if (pipe(fds[i]) == -1) + err(1, "pipe"); + } + + signal(SIGHUP, handler); + start = time(NULL); + for (i = 0; i < CHILDREN; i++) { + pid[i] = fork(); + if (pid[i] == -1) { + perror("fork"); + exit(2); + } + + if (pid[i] == 0) { /* child */ + for (;;) { + if (read(fds[i][0], &token, sizeof(token)) + != sizeof(token)) + err(1, "read pipe 2"); + if (write(fds[i+1][1], &token, sizeof(token)) + != sizeof(token)) + err(1, "write pipe 1"); + } + } + + } /* parent */ + + for (j = 0; time(NULL) - start < RUNTIME; j++) { + token = j; + if (write(fds[0][1], &token, sizeof(token)) != sizeof(token)) + err(1, "write pipe 2"); + if (read(fds[CHILDREN][0], &token, sizeof(token)) + != sizeof(token)) + err(1, "read pipe 1"); + } + + for (i = 0; i < CHILDREN; i++) + kill(pid[i], SIGHUP); + + return (0); +} diff --git a/tools/test/stress2/misc/context2.sh b/tools/test/stress2/misc/context2.sh new file mode 100755 index 000000000000..093e72e9084d --- /dev/null +++ b/tools/test/stress2/misc/context2.sh @@ -0,0 +1,131 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# This problem was seen with WiP kernel code: +# https://people.freebsd.org/~pho/stress/log/kostik1210.txt + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > context2.c +mycc -o context2 -Wall -Wextra -O2 context2.c -lpthread || exit 1 +rm -f context2.c +[ -d $RUNDIR ] || mkdir -p $RUNDIR +cd $RUNDIR + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 10m -i 20)" > \ + /dev/null 2>&1 +for i in `jot 4`; do + /tmp/context2 & +done +wait +while pgrep -q swap; do + pkill -9 swap +done +rm -f /tmp/context2 +exit 0 +EOF +/* + * Inspired by lmbench-3.0-a9/src/lat_ctx.c + * Pass a token thru pipes to NTHREADS+1 threads in a circular list. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define NTHREADS 64 +#define RUNTIME 300 + +pid_t pid[NTHREADS]; +int fds[NTHREADS+1][2]; + +void * +thr_routine(void *arg) +{ + int i; + int token; + + i = (long)arg; + for (;;) { + if (read(fds[i][0], &token, sizeof(token)) != sizeof(token)) + err(1, "read pipe 2"); + token++; + if (write(fds[i+1][1], &token, sizeof(token)) != sizeof(token)) + err(1, "write pipe 1"); + } + return (0); +} + +int +main(void) +{ + pthread_t threads[NTHREADS]; + time_t start; + long arg; + int i, r, token; + + for (i = 0; i < NTHREADS + 1; i++) { + if (pipe(fds[i]) == -1) + err(1, "pipe"); + } + + for (i = 0; i < NTHREADS; i++) { + arg = i; + if ((r = pthread_create(&threads[i], NULL, thr_routine, + (void *)arg)) != 0) + errc(1, r, "pthread_create(): %s\n", strerror(r)); + } + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + token = 0; + if (write(fds[0][1], &token, sizeof(token)) != sizeof(token)) + err(1, "write pipe 2"); + if (read(fds[NTHREADS][0], &token, sizeof(token)) != + sizeof(token)) + err(1, "read pipe 1"); + } + + for (i = 0; i < NTHREADS; i++) + if ((r = pthread_cancel(threads[i])) != 0) + errc(1, r, "pthread_cancel(%d)", i); + for (i = 0; i < NTHREADS; i++) + if ((r = pthread_join(threads[i], NULL)) != 0) + errc(1, r, "pthread_join(%d)", i); + + return (0); +} diff --git a/tools/test/stress2/misc/contigmalloc.sh b/tools/test/stress2/misc/contigmalloc.sh new file mode 100755 index 000000000000..92bf6ff40905 --- /dev/null +++ b/tools/test/stress2/misc/contigmalloc.sh @@ -0,0 +1,255 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# contigmalloc(9) / contigfree(9) test scenario. +# malloc() a random number of buffers with random size and then free them. + +# A malloc pattern might look like this: +# contigmalloc(186 pages) +# contigmalloc(56 pages) +# contigmalloc(9 pages) +# contigmalloc(202 pages) +# contigmalloc(49 pages) +# contigmalloc(5 pages) + +# "panic: vm_reserv_alloc_contig: reserv 0xff... isn't free" seen. +# http://people.freebsd.org/~pho/stress/log/contigmalloc.txt +# Fixed by r271351. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -d /usr/src/sys ] || exit 0 +builddir=`sysctl kern.version | grep @ | sed 's/.*://'` +[ -d "$builddir" ] && export KERNBUILDDIR=$builddir || exit 0 +export SYSDIR=`echo $builddir | sed 's#/sys.*#/sys#'` + +. ../default.cfg + +odir=`pwd` +dir=/tmp/contigmalloc +rm -rf $dir; mkdir -p $dir +cat > $dir/ctest.c < +#include + +#include +#include +#include +#include +#include + +#define min(a,b) (((a)<(b))?(a):(b)) +#define CAP (64 * 1024 * 1024) /* Total allocation */ +#define MAXBUF (32 * 1024 * 1024) /* Max buffer size */ +#define N 512 /* Max allocations */ +#define RUNTIME 120 +#define TALLOC 1 +#define TFREE 2 + +void *p[N]; +long size[N]; +int n; + +void +test(int argc, char *argv[]) +{ + long mw, s; + int i, no, ps, res; + + if (argc == 3) { + no = atoi(argv[1]); + mw = atol(argv[2]); + } + if (argc != 3 || no == 0 || mw == 0) + errx(1, "Usage: %s ", argv[0]); + + ps = getpagesize(); + s = 0; + n = arc4random() % N + 1; + mw = mw / 100 * 10 * ps; /* Use 10% of vm.max_user_wired */ + mw = min(mw, CAP); + for (i = 0; i < n; i++) { + size[i] = round_page((arc4random() % MAXBUF) + 1); + if (s + size[i] > mw) + continue; + res = syscall(no, TALLOC, &p[i], &size[i]); + if (res == -1) { + warn("contigmalloc(%lu pages) failed at loop %d", + size[i] / ps, i); + usleep(200000); + } else { +#if defined(TEST) + fprintf(stderr, "contigmalloc(%lu pages)\n", + size[i] / ps); +#endif + s += size[i]; + } + } + + setproctitle("%ld Mb", s / 1024 / 1024); + + for (i = 0; i < n; i++) { + if (p[i] != NULL) { + res = syscall(no, TFREE, &p[i], &size[i]); +#if defined(TEST) + fprintf(stderr, "contigfree(%lu pages)\n", + size[i] / ps); +#endif + p[i] = NULL; + } + } +} + +int +main(int argc, char *argv[]) +{ + time_t start; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) + test(argc, argv); + + return (0); +} + +EOF +mycc -o /tmp/ctest -Wall -Wextra -O0 -g $dir/ctest.c || exit 1 +rm $dir/ctest.c + +cd $dir +cat > Makefile < +EOF + +sed '1,/^EOF2/d' < $odir/$0 > cmalloc.c +make || exit 1 +kldload $dir/cmalloc.ko || exit 1 + +cd $odir +mw=`sysctl -n vm.max_user_wired` || exit 1 +/tmp/ctest `sysctl -n debug.cmalloc_offset` $mw 2>&1 | tail -5 +kldunload $dir/cmalloc.ko +rm -rf $dir /tmp/ctest +exit 0 + +EOF2 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TALLOC 1 +#define TFREE 2 + +/* + * Hook up a syscall for contigmalloc testing. + */ + +struct cmalloc_args { + int a_op; + void *a_ptr; + void *a_size; +}; + +static int +cmalloc(struct thread *td, struct cmalloc_args *uap) +{ + void *p; + unsigned long size; + int error; + + error = copyin(uap->a_size, &size, sizeof(size)); + if (error != 0) { + return (error); + } + switch (uap->a_op) { + case TFREE: + error = copyin(uap->a_ptr, &p, sizeof(p)); + if (error == 0) { + if (p != NULL) + contigfree(p, size, M_TEMP); + } + return (error); + + case TALLOC: + p = contigmalloc(size, M_TEMP, M_NOWAIT, 0ul, ~0ul, 4096, 0); + if (p != NULL) { + error = copyout(&p, uap->a_ptr, sizeof(p)); + return (error); + } + return (ENOMEM); + } + return (EINVAL); +} + +/* + * The sysent for the new syscall + */ +static struct sysent cmalloc_sysent = { + .sy_narg = 3, /* sy_narg */ + .sy_call = (sy_call_t *) cmalloc /* sy_call */ +}; + +/* + * The offset in sysent where the syscall is allocated. + */ +static int cmalloc_offset = NO_SYSCALL; + +SYSCTL_INT(_debug, OID_AUTO, cmalloc_offset, CTLFLAG_RD, &cmalloc_offset, 0, + "cmalloc syscall number"); + +/* + * The function called at load/unload. + */ + +static int +cmalloc_load(struct module *module, int cmd, void *arg) +{ + int error = 0; + + switch (cmd) { + case MOD_LOAD : + break; + case MOD_UNLOAD : + break; + default : + error = EOPNOTSUPP; + break; + } + return (error); +} + +SYSCALL_MODULE(cmalloc_syscall, &cmalloc_offset, &cmalloc_sysent, + cmalloc_load, NULL); diff --git a/tools/test/stress2/misc/contigmalloc2.sh b/tools/test/stress2/misc/contigmalloc2.sh new file mode 100755 index 000000000000..e3ec5bf3a358 --- /dev/null +++ b/tools/test/stress2/misc/contigmalloc2.sh @@ -0,0 +1,223 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# contigmalloc(9) / contigfree(9) test scenario. +# Regression test for allocations >= 2 GiB. +# "panic: vm_page_insert_after: mpred doesn't precede pindex" seen. +# Fixed by r284207. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -d /usr/src/sys ] || exit 0 +builddir=`sysctl kern.version | grep @ | sed 's/.*://'` +[ -d "$builddir" ] && export KERNBUILDDIR=$builddir || exit 0 +export SYSDIR=`echo $builddir | sed 's#/sys.*#/sys#'` + +. ../default.cfg + +odir=`pwd` +dir=/tmp/contigmalloc +rm -rf $dir; mkdir -p $dir +cat > $dir/ctest2.c < +#include + +#include +#include +#include +#include +#include + +#define TALLOC 1 +#define TFREE 2 + +void *p; +long size; +int n; + +void +test(int argc, char *argv[]) +{ + long mw; + int no, ps, res; + + if (argc == 3) { + no = atoi(argv[1]); + mw = atol(argv[2]); + } + if (argc != 3 || no == 0 || mw == 0) + errx(1, "Usage: %s ", argv[0]); + + ps = getpagesize(); + size = mw / 100 * 80 * ps; /* Use 80% of vm.max_user_wired */ + while (size > 0) { + res = syscall(no, TALLOC, &p, &size); + if (res == -1) { + if (errno != ENOMEM) + warn("contigmalloc(%lu pages) failed", + size); + } else { +#if defined(TEST) + fprintf(stderr, "pre contigmalloc(%lu pages): %lu MiB\n", + size, size * ps / 1024 / 1024); +#endif + res = syscall(no, TFREE, &p, &size); +#if defined(TEST) + fprintf(stderr, "contigfree(%lu pages)\n", + size); +#endif + } + size /= 2; + } +} + +int +main(int argc, char *argv[]) +{ + test(argc, argv); + + return (0); +} + +EOF +mycc -o /tmp/ctest2 -Wall -Wextra -O0 -g $dir/ctest2.c || exit 1 +rm $dir/ctest2.c + +cd $dir +cat > Makefile < +EOF + +sed '1,/^EOF2/d' < $odir/$0 > cmalloc2.c +make depend all || exit 1 +kldload $dir/cmalloc2.ko || exit 1 + +cd $odir +mw=$((`sysctl -n vm.max_user_wired` - \ + `sysctl -n vm.stats.vm.v_user_wire_count`)) || exit 1 +/tmp/ctest2 `sysctl -n debug.cmalloc_offset` $mw #2>&1 | tail -5 +kldunload $dir/cmalloc2.ko +rm -rf $dir /tmp/ctest2 +exit 0 + +EOF2 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TALLOC 1 +#define TFREE 2 + +/* + * Hook up a syscall for contigmalloc testing. + */ + +struct cmalloc_args { + int a_op; + void *a_ptr; + void *a_size; +}; + +static int +cmalloc(struct thread *td, struct cmalloc_args *uap) +{ + void *p; + unsigned long size; + int error; + + error = copyin(uap->a_size, &size, sizeof(size)); + if (error != 0) { + return (error); + } + switch (uap->a_op) { + case TFREE: + error = copyin(uap->a_ptr, &p, sizeof(p)); + if (error == 0) { + if (p != NULL) + contigfree(p, size, M_TEMP); + } + return (error); + + case TALLOC: + p = contigmalloc(size, M_TEMP, M_NOWAIT, 0ul, ~0ul, 4096, 0); + if (p != NULL) { + error = copyout(&p, uap->a_ptr, sizeof(p)); + return (error); + } + return (ENOMEM); + } + return (EINVAL); +} + +/* + * The sysent for the new syscall + */ +static struct sysent cmalloc_sysent = { + .sy_narg = 3, /* sy_narg */ + .sy_call = (sy_call_t *) cmalloc /* sy_call */ +}; + +/* + * The offset in sysent where the syscall is allocated. + */ +static int cmalloc_offset = NO_SYSCALL; + +SYSCTL_INT(_debug, OID_AUTO, cmalloc_offset, CTLFLAG_RD, &cmalloc_offset, 0, + "cmalloc syscall number"); + +/* + * The function called at load/unload. + */ + +static int +cmalloc_load(struct module *module, int cmd, void *arg) +{ + int error = 0; + + switch (cmd) { + case MOD_LOAD : + break; + case MOD_UNLOAD : + break; + default : + error = EOPNOTSUPP; + break; + } + return (error); +} + +SYSCALL_MODULE(cmalloc_syscall, &cmalloc_offset, &cmalloc_sysent, + cmalloc_load, NULL); diff --git a/tools/test/stress2/misc/contigmalloc3.sh b/tools/test/stress2/misc/contigmalloc3.sh new file mode 100755 index 000000000000..9497a67f21cf --- /dev/null +++ b/tools/test/stress2/misc/contigmalloc3.sh @@ -0,0 +1,225 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# contigmalloc(9) / contigfree(9) test scenario. +# Test allocation with 1GB + +# "panic: Bad link elm 0x6766fbc next->prev != elm" seen: +# https://people.freebsd.org/~pho/stress/log/kostik1094.txt +# Fixed by r331247 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -d /usr/src/sys ] || exit 0 +builddir=`sysctl kern.version | grep @ | sed 's/.*://'` +[ -d "$builddir" ] && export KERNBUILDDIR=$builddir || exit 0 +export SYSDIR=`echo $builddir | sed 's#/sys.*#/sys#'` + +. ../default.cfg + +odir=`pwd` +dir=/tmp/contigmalloc +rm -rf $dir; mkdir -p $dir +cat > $dir/ctest.c < +#include + +#include +#include +#include +#include +#include + +#define MAXBUF (1LL * 1024 * 1024 * 1024) /* Max buffer size */ +#define TALLOC 1 +#define TFREE 2 + +void +test(int argc, char *argv[]) +{ + long mw, size; + int i, no, ps, res; + char *cp; + + if (argc == 3) { + no = atoi(argv[1]); + mw = atol(argv[2]); + } + if (argc != 3 || no == 0 || mw == 0) + errx(1, "Usage: %s ", argv[0]); + + ps = getpagesize(); + if (mw < MAXBUF / ps) { + fprintf(stderr, "max_user_wired too small for this test\n"); + exit (0); + } + i = 0; + size = round_page(MAXBUF); + res = syscall(no, TALLOC, &cp, &size); + if (res == -1) { + err(1, "contigmalloc(%lu MB) failed", + size / 1024 / 1024); + } else { +#if defined(TEST) + fprintf(stderr, "contigmalloc(%lu pages) %luMB\n", + size / ps, size / 1024 / 1024); +#endif + } + + res = syscall(no, TFREE, &cp, &size); +#if defined(TEST) + fprintf(stderr, "contigfree(%lu pages) %luMB\n", + size / ps, size / 1024 / 1024); +#endif +} + +int +main(int argc, char *argv[]) +{ + + test(argc, argv); + + return (0); +} + +EOF +mycc -o /tmp/ctest -Wall -Wextra -O0 -g $dir/ctest.c || exit 1 +rm $dir/ctest.c + +cd $dir +cat > Makefile < +EOF + +sed '1,/^EOF2/d' < $odir/$0 > cmalloc.c +make || exit 1 +kldload $dir/cmalloc.ko || exit 1 + +cd $odir +mw=`sysctl -n vm.max_user_wired` || exit 1 +/tmp/ctest `sysctl -n debug.cmalloc_offset` $mw 2>&1 | tail -5 +kldunload $dir/cmalloc.ko +rm -rf $dir /tmp/ctest +exit 0 + +EOF2 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TALLOC 1 +#define TFREE 2 + +/* + * Hook up a syscall for contigmalloc testing. + */ + +struct cmalloc_args { + int a_op; + void *a_ptr; + void *a_size; +}; + +static int +cmalloc(struct thread *td, struct cmalloc_args *uap) +{ + void *p; + unsigned long size; + int error; + + error = copyin(uap->a_size, &size, sizeof(size)); + if (error != 0) { + return (error); + } + switch (uap->a_op) { + case TFREE: + error = copyin(uap->a_ptr, &p, sizeof(p)); + if (error == 0) { + if (p != NULL) + contigfree(p, size, M_TEMP); + } + return (error); + + case TALLOC: + p = contigmalloc(size, M_TEMP, M_NOWAIT, 0ul, ~0ul, 4096, 0); + if (p != NULL) { + error = copyout(&p, uap->a_ptr, sizeof(p)); + return (error); + } + return (ENOMEM); + } + return (EINVAL); +} + +/* + * The sysent for the new syscall + */ +static struct sysent cmalloc_sysent = { + .sy_narg = 3, /* sy_narg */ + .sy_call = (sy_call_t *) cmalloc /* sy_call */ +}; + +/* + * The offset in sysent where the syscall is allocated. + */ +static int cmalloc_offset = NO_SYSCALL; + +SYSCTL_INT(_debug, OID_AUTO, cmalloc_offset, CTLFLAG_RD, &cmalloc_offset, 0, + "cmalloc syscall number"); + +/* + * The function called at load/unload. + */ + +static int +cmalloc_load(struct module *module, int cmd, void *arg) +{ + int error = 0; + + switch (cmd) { + case MOD_LOAD : + break; + case MOD_UNLOAD : + break; + default : + error = EOPNOTSUPP; + break; + } + return (error); +} + +SYSCALL_MODULE(cmalloc_syscall, &cmalloc_offset, &cmalloc_sysent, + cmalloc_load, NULL); diff --git a/tools/test/stress2/misc/core.sh b/tools/test/stress2/misc/core.sh new file mode 100755 index 000000000000..10d957f1f888 --- /dev/null +++ b/tools/test/stress2/misc/core.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. +# + +# Test multiple (parallel) core dumps + +. ../default.cfg + +odir=`pwd` + +cd /tmp +rm -f core +sed '1,/^EOF/d' < $odir/$0 > core.c +mycc -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 /tmp/core +exit +EOF +#include +#include +#include +#include +#include +#include +#include + +#define SIZ 10*1024*1024 + +int +main(int argc, char **argv) +{ + char *cp; + + if ((cp = malloc(SIZ)) == NULL) + err(1, "Could not malloc 10Mb!"); + + memset(cp, 1, SIZ); + + sleep(120 - (time(NULL) % 120)); + raise(SIGSEGV); + + return (0); +} diff --git a/tools/test/stress2/misc/core2.sh b/tools/test/stress2/misc/core2.sh new file mode 100755 index 000000000000..4f0e0472af95 --- /dev/null +++ b/tools/test/stress2/misc/core2.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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 multiple (parallel) core dumps and umount + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > core2.c +mycc -o core2 -Wall -Wextra -O0 core2.c || exit 1 +rm -f core2.c +cd $RUNDIR + +mount | grep "on $mntpoint " | grep -q md$mdstart && umount $mntpoint +[ -c /dev/mn$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +touch /tmp/continue +for i in `jot 64`; do + mkdir -p $mntpoint/d$i + (cd $mntpoint; /tmp/core2) & +done +rm -f /tmp/continue + +for i in `jot 60`; do + umount $mntpoint 2>/dev/null || sleep 1 + mount | grep -q "on $mntpoint " || break +done +wait +mount | grep -q "on $mntpoint " && + umount -f $mntpoint +mdconfig -d -u $mdstart +rm -f /tmp/core2 +exit +EOF +#include + +#include +#include +#include +#include +#include +#include +#include + +#define SIZ 1L * 128 * 1024 * 1024 + +void *p; + +int +main(void) +{ + size_t len; + + len = SIZ; + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + + while (access("/tmp/continue", R_OK) == 0) + usleep(1); + + raise(SIGSEGV); + + return (0); +} diff --git a/tools/test/stress2/misc/core3.sh b/tools/test/stress2/misc/core3.sh new file mode 100755 index 000000000000..68d55468c087 --- /dev/null +++ b/tools/test/stress2/misc/core3.sh @@ -0,0 +1,171 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 multiple (parallel) core dumps and mount / umount. +# mount(8) stuck in "ufs" or "tmpfs". +# http://people.freebsd.org/~pho/stress/log/kostik724.txt +# Fixed by r272535. +# On i386 pgrep(1) loops. Fixed by r272566. + +# "Sleeping on "pmapdi" with the following non-sleepable locks held:" +# https://people.freebsd.org/~pho/stress/log/kostik883.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > core3.c +mycc -o core3 -Wall -Wextra -O2 core3.c || exit 1 +rm -f core3.c +cd $odir + +mount | grep -q "on $mntpoint " && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +mkdir $mntpoint/d +chmod 777 $mntpoint/d + +su $testuser -c "/tmp/core3 $mntpoint/d" & +pid=$! +sleep 1 + +while pgrep -q core3; do + [ -d $mntpoint/d ] && + umount -f $mntpoint +done > /dev/null 2>&1 & +while pgrep -q core3; do + [ -d $mntpoint/d ] || + mount /dev/md${mdstart}$part $mntpoint +done > /dev/null 2>&1 +wait $pid +status=$? +mount | grep -q "on $mntpoint " && + umount -f $mntpoint +mdconfig -d -u $mdstart +[ $status -ne 0 ] && exit $status + +# tmpfs +mount -o size=1g -t tmpfs tmpfs $mntpoint +su $testuser -c "/tmp/core3 $mntpoint/d" & +pid=$! +sleep 1 + +while pgrep -q core3; do + [ -d $mntpoint/d ] && + umount -f $mntpoint +done > /dev/null & +while pgrep -q core3; do + if [ ! -d $mntpoint/d ]; then + mount -t tmpfs tmpfs $mntpoint + mkdir $mntpoint/d + fi +done +wait $pid +status=$? +for i in `jot 5` ; do + mount | grep -q "on $mntpoint " || break + umount -f $mntpoint + sleep 1 +done +rm -f /tmp/core3 +exit $status +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 64 +#define SIZ (4 * 1024 * 1024) +#define TIMEDOUT 22 + +void *p; + +static void +hand(int i __unused) { /* handler */ + _exit(TIMEDOUT); +} + +void +test(char *argv[]) +{ + size_t len; + + len = SIZ; + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + + /* + * This loop caused mount to wait in "ufs". + * Adding a usleep(200) would remove the hang. + */ + signal(SIGALRM, hand); + alarm(600); + while (chdir(argv[1]) == -1) + ; + + raise(SIGSEGV); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + time_t start; + int i, s, status; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + + status = 0; + start = time(NULL); + while (time(NULL) - start < 600 && status == 0) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + test(argv); + } + for (i = 0; i < PARALLEL; i++) { + wait(&s); + if (WEXITSTATUS(s) == TIMEDOUT) + status = 1; + } + } + + return (status); +} diff --git a/tools/test/stress2/misc/core4.sh b/tools/test/stress2/misc/core4.sh new file mode 100755 index 000000000000..562160a1a314 --- /dev/null +++ b/tools/test/stress2/misc/core4.sh @@ -0,0 +1,89 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 multiple (parallel) core dumps and umount -f + +# "panic: vn_finished_write: neg cnt" seen. +# http://people.freebsd.org/~pho/core4.sh +# Fixed in r274501 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > core4.c +mycc -o core4 -Wall -Wextra -O0 -g core4.c || exit 1 +rm -f core4.c + +mount | grep -q "$mntpoint" && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null +for i in `jot 20`; do + mount /dev/md${mdstart}$part $mntpoint + chmod 777 $mntpoint + su $testuser -c "(cd $mntpoint; /tmp/core4)" & + su $testuser -c "(cd $mntpoint; /tmp/core4)" & + su $testuser -c "(cd $mntpoint; /tmp/core4)" & + sleep .5 + sleep .`jot -r 1 1 9` + umount -f $mntpoint + wait +done 2>/dev/null + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/core4 +exit 0 +EOF +#include +#include + +#include +#include +#include + +#define SIZ (1024L * 1024 * 1024) + +int +main(void) +{ + void *p; + + p = mmap(NULL, SIZ, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + usleep(1000); + raise(SIGSEGV); + + return (0); +} diff --git a/tools/test/stress2/misc/core5.sh b/tools/test/stress2/misc/core5.sh new file mode 100755 index 000000000000..6dc6ba96b742 --- /dev/null +++ b/tools/test/stress2/misc/core5.sh @@ -0,0 +1,199 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# The core file vnode is unreferenced before notification is sent. + +# Problem reported by sbruno@ +# http://people.freebsd.org/~pho/stress/log/core5.txt +# Fixed by r279237. + +# 20150714 Slowdown seen with core5 waiting in vlruwk. +# sysctl vfs.vlru_allow_cache_src=1 used to resolve this. +# For now change MAXVNODES from 1.000 to 4.000. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > core5.c +mycc -o core5 -Wall -Wextra -O0 -g core5.c || exit 1 +rm -f core5.c + +cat > core5-dumper.c << EOT +#include + +#include +#include +#include +#include +#include +#include + +int +main(int argc __unused, char *argv[]) +{ + time_t start; + char core[80]; + + snprintf(core, sizeof(core), "%s.core", argv[0]); + + if (unlink(core) == -1) + if (errno != ENOENT) + warn("unlink(%s)", core); + + start = time(NULL); + while (time(NULL) - start < 600) { + if (fork() == 0) + raise(SIGSEGV); + wait(NULL); + } + if (unlink(core) == -1) + if (errno != ENOENT) + warn("unlink(%s)", core); + + return (0); +} +EOT +mycc -o core5-dumper -Wall -Wextra -O0 -g core5-dumper.c || exit 1 +rm -f core5-dumper.c +for i in `jot 10`; do + cp core5-dumper core5-dumper$i +done +rm -f core5-dumper + +mount | grep -q "on $mntpoint " && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t malloc -s 1g -u $mdstart +bsdlabel -w md$mdstart auto + +newfs -b 4096 -f 512 -i 2048 md${mdstart}$part > /dev/null +mount -o async /dev/md${mdstart}$part $mntpoint || exit 1 + +cp /tmp/core5 $mntpoint +mkdir $mntpoint/dir +cd $mntpoint + +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir $mp2 +mount | grep -q "on $mp2 " && umount $mp2 +mount -o size=2g -t tmpfs tmpfs $mp2 || exit 1 +for i in `jot 10`; do + (cd $mp2; /tmp/core5-dumper$i ) & +done +maxvnodes=`sysctl -n kern.maxvnodes` +trap "sysctl kern.maxvnodes=$maxvnodes > /dev/null" EXIT INT +$mntpoint/core5 $mntpoint/dir +wait +umount $mp2 + +cd $here +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/core5 /tmp/core5-dumper* /tmp/core5-dumper*.core +exit 0 +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define MAXVNODES 4000 +#define NBFILES 10000 +#define PARALLEL 4 +#define RTIME (10 * 60) + +char *path; + +void +test(int n) +{ + int fd, i; + char file[80]; + + usleep(arc4random() % 1000); + for (i = 0; i < NBFILES; i++) { + snprintf(file, sizeof(file), "%s/f%d.%06d", path, n, i); + if ((fd = open(file, O_CREAT, 0644)) == -1) { + warn("open(%s)", file); + break; + } + close(fd); + } + for (i = 0; i < NBFILES; i++) { + snprintf(file, sizeof(file), "%s/f%d.%06d", path, n, i); + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + } + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + size_t len; + time_t start; + unsigned long nv, maxvnodes; + int j; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + path = argv[1]; + + nv = MAXVNODES; + len = sizeof(maxvnodes); + if (sysctlbyname("kern.maxvnodes", &maxvnodes, &len, &nv, + sizeof(nv)) != 0) + err(1, "sysctl kern.maxvnodes 1"); + + start = time(NULL); + while (time(NULL) - start < RTIME) { + for (j = 0; j < PARALLEL; j++) + if (fork() == 0) + test(j); + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + if (sysctlbyname("kern.maxvnodes", NULL, NULL, &maxvnodes, + sizeof(maxvnodes)) != 0) + err(1, "sysctl kern.maxvnodes 2"); + + return (0); +} diff --git a/tools/test/stress2/misc/cpuset.sh b/tools/test/stress2/misc/cpuset.sh new file mode 100755 index 000000000000..ad9f8569f386 --- /dev/null +++ b/tools/test/stress2/misc/cpuset.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Deadlock with one really small domain: +# https://people.freebsd.org/~pho/stress/log/mark074.txt + +[ `sysctl -n vm.ndomains` -eq 1 ] && exit 0 + +#set -e +# * round-robin:0-4 explicit +# * round-robin:all explicit root domains +# * 0-4 implicit root policy +# * round-robin implicit root domains +# * all explicit root domains and implicit policy + +for p in "round-robin:0" "round-robin:1" "round-robin:0-1" \ + "round-robin:all" "0-1" round-robin all first-touch prefer:1 \ + interleave; do + echo "`date +%T` cpuset -n $p" + cpuset -n $p ../misc/ufsbench.sh +done + +exit 0 diff --git a/tools/test/stress2/misc/credleak.sh b/tools/test/stress2/misc/credleak.sh new file mode 100755 index 000000000000..da6c0b73f460 --- /dev/null +++ b/tools/test/stress2/misc/credleak.sh @@ -0,0 +1,162 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC +# 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. +# + +# Demonstrate that vfs_export() leaks M_CRED when mountd(8) is started: +# "M_CRED leaked 160". + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +pgrep -q mountd || echo "Note: mountd(8) must run for this test to fail" +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > credleak.c +mycc -o credleak -Wall -Wextra -O2 -g credleak.c || exit 1 +rm -f credleak.c + +mount | grep -q "on $mntpoint " && umount -f $mntpoint +mount -t tmpfs tmpfs $mntpoint +chmod 777 $mntpoint + +old=`vmstat -m | grep -w cred | awk '{print $2}'` +su $testuser -c "/tmp/credleak $mntpoint" & + +while kill -0 $! 2>/dev/null; do + umount -f $mntpoint && + mount -t tmpfs tmpfs $mntpoint + chmod 777 $mntpoint + sleep .1 +done +pkill -9 swap +wait + +while pkill -9 swap; do + : +done > /dev/null 2>&1 +while mount | grep $mntpoint | grep -q tmpfs; do + umount $mntpoint || sleep 1 +done +[ -d "$mntpoint" ] && (cd $mntpoint && find . -delete) +rm -f /tmp/credleak + +s=0 +leak=$((`vmstat -m | grep -w cred | awk '{print $2}'` - old)) +[ $leak -gt 10 ] && { echo "M_CRED leaked $leak"; s=1; } +exit $s +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 160 +#define PARALLEL 16 + +int nbc, nbd; +char *dir; + +void +tmkdir(void) +{ + int i, j; + char d[MAXPATHLEN + 1], name[MAXPATHLEN + 1]; + + setproctitle(__func__); + + i = 0; + snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid()); + if (mkdir(name, 0755) == -1) { + if (errno != ENAMETOOLONG && errno != ENOENT && + errno != EBUSY && errno != EACCES && errno != EPERM) + warn("mkdir(%s)", name); + _exit(0); + } + for (;;) { + snprintf(d, sizeof(d), "/%d", i++); + strncat(name, d, sizeof(name) - 1); + if (mkdir(name, 0755) == -1) { + if (errno != ENAMETOOLONG && errno != ENOENT && + errno != EBUSY && errno != EACCES && errno != EPERM) + warn("mkdir(%s)", name); + i--; + break; + } + nbc++; + } + + while (i >= 0) { + snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid()); + for (j = 0; j < i; j++) { + snprintf(d, sizeof(d), "/%d", j); + strncat(name, d, sizeof(name) - 1); + } + if (rmdir(name) == -1) { + if (errno != ENOTEMPTY && errno != ENOENT && errno != + EBUSY) + warn("rmdir(%s)", name); + } else + nbd++; + i--; + } +#if defined(TEST) + if (nbc == 0) + fprintf(stderr, "FAIL nbc = %d, nbd = %d\n", nbc, nbd); +#endif + _exit(0); +} + +int +main(int argc, char **argv) +{ + int i, j; + + if (argc != 2) { + fprintf(stderr, "Usage: %s ", argv[0]); + exit(1); + } + dir = argv[1]; + + for (j = 0; j < LOOPS; j++) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + tmkdir(); + } + for (i = 0; i < PARALLEL; i++) + wait(NULL); + } + + return(0); +} diff --git a/tools/test/stress2/misc/crossmp.sh b/tools/test/stress2/misc/crossmp.sh new file mode 100755 index 000000000000..7d1ccbe3a469 --- /dev/null +++ b/tools/test/stress2/misc/crossmp.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. +# + +# Parallel mount and umount of file systems + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +cont=/tmp/crossmp.continue +mdstart=$mdstart # Use md unit numbers from this point +D=$diskimage + +if [ $# -eq 0 ]; then + touch $cont + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount | grep "on ${mntpoint}$m " | 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 status=none + mdconfig -a -t vnode -f $D$m -u $m + bsdlabel -w md$m auto + newfs $newfs_flags 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 + + wait + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + mdconfig -d -u $m + rm -f $D$m + done + exit 0 +else + if [ $1 = find ]; then + while [ -r $cont ]; 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 -q "on ${mntpoint}$m "; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && + echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + done + rm -f $cont + fi +fi diff --git a/tools/test/stress2/misc/crossmp10.sh b/tools/test/stress2/misc/crossmp10.sh new file mode 100755 index 000000000000..30e64a064dac --- /dev/null +++ b/tools/test/stress2/misc/crossmp10.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC Isilon +# 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. +# + +# ext2fs parallel mount & umount test scenario +# "panic: vm_fault_hold: fault on nofault entry" seen. +# https://people.freebsd.org/~pho/stress/log/crossmp10.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -z "`which mke2fs`" ] && echo "mke2fs not found" && exit 0 + +. ../default.cfg + +CONT=/tmp/crossmp10.continue +mounts=4 # Number of parallel scripts +size=512 # Disk size in MB + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && + { mkdir ${mntpoint}$m; chmod 755 ${mntpoint}$m; } + mount | grep "${mntpoint}$m " | grep -q md$m && umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + mdconfig -a -t swap -s ${size}m -u $m + bsdlabel -w md$m auto + mke2fs -m 0 /dev/md${m}$part > /dev/null 2>&1 + done + + # start the parallel tests + touch $CONT + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find & + done + + wait + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + while mount | grep -q "on ${mntpoint}$m "; do + umount ${mntpoint}$m && break + sleep 1 + done + mdconfig -d -u $m + done + exit 0 +else + if [ $1 = find ]; then + while [ -f $CONT ]; do + find ${mntpoint}* -ls > /dev/null 2>&1 + sleep .1 + done + else + export runRUNTIME=30s + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt 300 ]; do + m=$1 + mount -t ext2fs /dev/md${m}$part ${mntpoint}$m && + chmod 777 ${mntpoint}$m + export RUNDIR=${mntpoint}$m/stressX + export CTRLDIR=${mntpoint}$m/stressX.control + (cd ${mntpoint}$m && find . -delete) + su $testuser -c 'cd ..; ./run.sh disk.cfg' > /dev/null 2>&1 & + + sleep 2 + while mount | grep -q "on ${mntpoint}$m "; do + opt=$([ `jot -r 1 0 1` -eq 0 ] && echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + [ -f $CONT ] || break 2 + done + wait $! + done + rm -f $CONT + ../tools/killall.sh + fi +fi diff --git a/tools/test/stress2/misc/crossmp11.sh b/tools/test/stress2/misc/crossmp11.sh new file mode 100755 index 000000000000..8bc008f6f504 --- /dev/null +++ b/tools/test/stress2/misc/crossmp11.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Copy of crossmp3.sh + elements from dfull.sh + +# Live lock seen: +# https://people.freebsd.org/~pho/stress/log/crossmp11.txt + +# umount stuck in mnt_ref seen: +# https://people.freebsd.org/~pho/stress/log/kostik1002.txt + +# Fixed by r319518, r319519 and r319539. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +g3=$((3 * 1024 * 1024 * 1024)) +CONT=/tmp/crossmp11.continue +N=`sysctl -n hw.ncpu` +[ $N -gt 4 ] && N=4 +usermem=`sysctl -n hw.usermem` +[ $usermem -gt $g3 ] && usermem=$g3 +[ `sysctl -n vm.swap_total` -eq 0 ] && usermem=$((usermem/100*80)) +size=$((usermem / 1024 / 1024 / N)) + +mounts=$N # Number of parallel scripts + +if [ $# -eq 0 ]; then + echo "Expect: + /mnt6: write failed, filesystem is full + /mnt6: create/symlink failed, no inodes free" + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && + { mkdir ${mntpoint}$m; chmod 755 ${mntpoint}$m; } + mount | grep "${mntpoint}$m " | grep -q md$m && umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + mdconfig -a -t swap -s ${size}m -u $m + bsdlabel -w md$m auto + newfs $newfs_flags md${m}$part > /dev/null 2>&1 + done + + # start the parallel tests + touch $CONT + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find & + done + + wait + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + while mount | grep -q "on ${mntpoint}$m "; do + umount ${mntpoint}$m && break + sleep 1 + done + mdconfig -d -u $m + done + exit 0 +else + if [ $1 = find ]; then + while [ -f $CONT ]; do + find ${mntpoint}* -type f > /dev/null 2>&1 + done + else + m=$1 + export runRUNTIME=20s + # The test: Parallel mount and unmounts + for i in `jot 3`; do + mount /dev/md${m}$part ${mntpoint}$m && + chmod 777 ${mntpoint}$m + export RUNDIR=${mntpoint}$m/stressX + export CTRLDIR=${mntpoint}$m/stressX.control + (cd ${mntpoint}$m && find . -delete) + if [ -z "$KBLOCKS" ]; then + r=`df -ik ${mntpoint}$m | tail -1 | awk '{print $4,$7}'` + export KBLOCKS=`echo $r | awk '{print $1 * 10}'` + export INODES=`echo $r | awk '{print $2 * 10}'` + fi + su $testuser -c 'cd ..; ./run.sh disk.cfg' > \ + /dev/null 2>&1 + + while mount | grep -q "on ${mntpoint}$m "; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + [ -f $CONT ] || break 2 + done + done + rm -f $CONT + fi +fi diff --git a/tools/test/stress2/misc/crossmp2.sh b/tools/test/stress2/misc/crossmp2.sh new file mode 100755 index 000000000000..03cd04e077c1 --- /dev/null +++ b/tools/test/stress2/misc/crossmp2.sh @@ -0,0 +1,86 @@ +#!/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. +# + +# NFS test + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +cont=/tmp/crossmp2.continue +mounts=10 # Number of parallel scripts + +if [ $# -eq 0 ]; then + [ -z "$nfs_export" ] && exit 0 + ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + touch $cont + mount -t nfs -o tcp -o nfsv3 -o retrycnt=1 -o intr,soft,timeout=1 \ + -o rw $nfs_export $mntpoint || exit 0 + sleep .2 + umount $mntpoint + + for i in `jot $mounts`; do + mp=${mntpoint}$i + [ ! -d $mp ] && mkdir $mp + mount | grep -q "$mp " && umount $mp + done + + # start the parallel tests + for i in `jot $mounts`; do + ./$0 $i & + ./$0 find & + done + wait + exit 0 +else + if [ $1 = find ]; then + while [ -r $cont ]; do + find ${mntpoint}* -maxdepth 1 -type f > \ + /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + for i in `jot 128`; do + m=$1 + mount -t nfs -o tcp -o nfsv3 -o retrycnt=3 \ + -o intr,soft -o rw $nfs_export ${mntpoint}$m + sleep .5 + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + n=0 + while mount | grep -q "${mntpoint}$m "; do + umount $opt ${mntpoint}$m > /dev/null 2>&1 + [ $((n += 1)) -gt 99 ] && umount -f \ + ${mntpoint}$m > /dev/null 2>&1 + [ $n -gt 100 ] && exit + done + done + rm -f $cont + fi +fi diff --git a/tools/test/stress2/misc/crossmp3.sh b/tools/test/stress2/misc/crossmp3.sh new file mode 100755 index 000000000000..30c9f86840f1 --- /dev/null +++ b/tools/test/stress2/misc/crossmp3.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Parallel mount and umount of file systems +# "panic: Bad link elm 0xfffff8052a20cc00 prev->next != elm" seen: +# http://people.freebsd.org/~pho/stress/log/crossmp3.txt +# Fixed in r269853 + +# panic: softdep_waitidle: work added after flush: +# http://people.freebsd.org/~pho/stress/log/crossmp3-2.txt, fixed by r273967. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +CONT=/tmp/crossmp3.continue +if [ $# -eq 0 ]; then + N=`sysctl -n hw.ncpu` + usermem=`sysctl -n hw.usermem` + [ `sysctl -n vm.swap_total` -eq 0 ] && usermem=$((usermem / 2)) + size=$((usermem / 1024 / 1024 / N)) + echo "Using $N memory disks of size $size MB." + + mounts=$N # Number of parallel scripts + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && + { mkdir ${mntpoint}$m; chmod 755 ${mntpoint}$m; } + mount | grep "${mntpoint}$m " | grep -q md$m && + umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + mdconfig -a -t swap -s ${size}m -u $m + bsdlabel -w md$m auto + newfs $newfs_flags md${m}$part > /dev/null 2>&1 + done + + # start the parallel tests + touch $CONT + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find & + done + wait + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + while mount | grep -q "on ${mntpoint}$m "; do + umount ${mntpoint}$m && break + sleep 1 + done + mdconfig -d -u $m + done + exit 0 +else + if [ $1 = find ]; then + while [ -f $CONT ]; do + find ${mntpoint}* -type f > /dev/null 2>&1 + done + else + export runRUNTIME=20s + # The test: Parallel mount and unmounts + for i in `jot 3`; do + m=$1 + mount /dev/md${m}$part ${mntpoint}$m && + chmod 777 ${mntpoint}$m + export RUNDIR=${mntpoint}$m/stressX + export CTRLDIR=${mntpoint}$m/stressX.control + (cd ${mntpoint}$m && find . -delete) + su $testuser -c 'cd ..; ./run.sh disk.cfg' > \ + /dev/null 2>&1 + + while mount | grep -q "on ${mntpoint}$m "; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + [ -f $CONT ] || break 2 + done + done + rm -f $CONT + fi +fi diff --git a/tools/test/stress2/misc/crossmp4.sh b/tools/test/stress2/misc/crossmp4.sh new file mode 100755 index 000000000000..7f24097475f3 --- /dev/null +++ b/tools/test/stress2/misc/crossmp4.sh @@ -0,0 +1,107 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Parallel mount and umount of file systems. Nullfs version. + +# "panic: Lock (lockmgr) null not locked @ kern/vfs_default.c:523." seen. +# http://people.freebsd.org/~pho/stress/log/kostik698.txt +# Fixed by r269708. + +# Not fixed: https://people.freebsd.org/~pho/stress/log/kostik798.txt +# https://people.freebsd.org/~pho/stress/log/kostik856.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +N=`sysctl -n hw.ncpu` +usermem=`sysctl -n hw.usermem` +[ `swapinfo | wc -l` -eq 1 ] && usermem=$((usermem/100*80)) +size=$((usermem / 1024 / 1024 - 2)) + +CONT=/tmp/crossmp4.continue +mounts=$N # Number of parallel scripts + +if [ $# -eq 0 ]; then + mount | grep "$mntpoint" | grep -q md && umount $mntpoint + mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + + mdconfig -a -t swap -s ${size}m -u $mdstart + bsdlabel -w md$mdstart auto + newfs $newfs_flags md${mdstart}$part > /dev/null 2>&1 + mount /dev/md${mdstart}$part $mntpoint + + # start the parallel tests + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find & + done + + wait + + while mount | grep -q "on $mntpoint "; do + umount $mntpoint > /dev/null 2>&1 || sleep 1 + done + mdconfig -d -u $mdstart + exit 0 +else + touch $CONT + if [ $1 = find ]; then + while [ -f $CONT ]; do + find ${mntpoint}* -type f > /dev/null 2>&1 + done + else + m=$1 + set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` + export KBLOCKS=$(($1 / N)) + export INODES=$(($2 / N)) + export runRUNTIME=1m + export INCARNATIONS=4 + # The test: Parallel mount and unmounts + for i in `jot 4`; do + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount -t nullfs $mntpoint ${mntpoint}$m + mkdir -p ${mntpoint}$m/$m + chmod 777 ${mntpoint}$m/$m + export RUNDIR=${mntpoint}$m/$m/stressX + export CTRLDIR=${mntpoint}$m/$m/stressX.control + (cd ${mntpoint}$m/$m && find . -delete) + su $testuser -c 'cd ..; ./run.sh disk.cfg' > \ + /dev/null 2>&1 & + sleep 30 + + while mount | grep -q "on ${mntpoint}$m "; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + wait + done + rm -f $CONT + fi +fi diff --git a/tools/test/stress2/misc/crossmp5.sh b/tools/test/stress2/misc/crossmp5.sh new file mode 100755 index 000000000000..9a636c9aae45 --- /dev/null +++ b/tools/test/stress2/misc/crossmp5.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Variation of crossmp3.sh + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +N=`sysctl -n hw.ncpu` +usermem=`sysctl -n hw.usermem` +[ `swapinfo | wc -l` -eq 1 ] && usermem=$((usermem/100*80)) +size=$((usermem / 1024 / 1024 / N)) + +mounts=$N # Number of parallel scripts + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount | grep "${mntpoint}$m " | grep -q md$m && + umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + mdconfig -a -t swap -s ${size}m -u $m + bsdlabel -w md$m auto + newfs $newfs_flags 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 + + wait + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + mdconfig -d -u $m + rm -f $D$m + done + exit 0 +else + touch /tmp/crossmp.continue + if [ $1 = find ]; then + while [ -f /tmp/crossmp.continue ]; do + find ${mntpoint}* -type f > /dev/null 2>&1 + done + else + # The test: Parallel mount and unmount + m=$1 + for i in `jot 200`; do + mount /dev/md${m}$part ${mntpoint}$m + chmod 777 ${mntpoint}$m + l=`jot -r 1 65535` + dd if=/dev/zero of=$mntpoint/$i bs=$l count=100 \ + status=none + rm -f $mntpoint/$i + + while mount | grep -q "on ${mntpoint}$m "; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && + echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + done + done + rm -f /tmp/crossmp.continue + fi +fi diff --git a/tools/test/stress2/misc/crossmp6.sh b/tools/test/stress2/misc/crossmp6.sh new file mode 100755 index 000000000000..92ca0abcba27 --- /dev/null +++ b/tools/test/stress2/misc/crossmp6.sh @@ -0,0 +1,103 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Copy of crossmp2.sh: NFS test, with lockf(1) added. +# "panic: vinvalbuf: dirty bufs" seen. +# https://people.freebsd.org/~pho/stress/log/crossmp6.txt +# Fixed by r283968. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 +pgrep -q lockd || { echo "lockd not running."; exit 0; } + +CONT=/tmp/crossmp6.continue +mounts=10 # Number of parallel scripts + +if [ $# -eq 0 ]; then + [ -z "$nfs_export" ] && exit 0 + ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + mount -t nfs -o tcp -o nfsv3 -o retrycnt=1 -o soft,timeout=1 \ + -o rw $nfs_export $mntpoint || exit 0 + umount $mntpoint + + for i in `jot $mounts`; do + mp=${mntpoint}$i + [ ! -d $mp ] && mkdir $mp + mount | grep -qw "$mp" && umount $mp + done + + # start the parallel tests + for i in `jot $mounts`; do + ./$0 $i & + ./$0 find $i & + done + wait + mount -t nfs -o tcp -o nfsv3 -o retrycnt=1 -o soft,timeout=1 \ + -o rw $nfs_export $mntpoint || exit 0 + sleep .5 + rm -f $mntpoint/$0.* + umount $mntpoint + rm -f $mntpoint*/$0.* + exit 0 +else + if [ $1 = find ]; then + for i in `jot 128`; do + find ${mntpoint}* -maxdepth 1 -type f > \ + /dev/null 2>&1 + (lockf -t 10 ${mntpoint}$2/$0.$$.$i sleep 1 &) > \ + /dev/null 2>&1 + [ -f $CONT ] || break + done + wait + else + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt 300 ]; do + m=$1 + mount -t nfs -o tcp -o nfsv3 -o retrycnt=3 \ + -o soft -o rw $nfs_export ${mntpoint}$m + sleep .5 + 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 + rm -f $CONT + fi +fi diff --git a/tools/test/stress2/misc/crossmp7.sh b/tools/test/stress2/misc/crossmp7.sh new file mode 100755 index 000000000000..c2c2752f38e7 --- /dev/null +++ b/tools/test/stress2/misc/crossmp7.sh @@ -0,0 +1,100 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Parallel mount and umount of zfs file systems. + +# Page fault seen: +# https://people.freebsd.org/~pho/stress/log/avg002.txt +# Fixed by r309090. + +# Page fault seen: +# https://people.freebsd.org/~pho/stress/log/crossmp7.txt +# Fixed by r352437. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `uname -m` = "i386" ] && exit 0 +[ `sysctl -n kern.kstack_pages` -lt 4 ] && exit 0 + +. ../default.cfg + +mounts=15 # Number of parallel scripts + +if [ $# -eq 0 ]; then + kldstat -v | grep -q zfs.ko || { kldload zfs.ko || + exit 0; loaded=1; } + zpool list | egrep -q "^stress2_tank" && zpool destroy stress2_tank + + u1=$mdstart + u2=$((u1 + 1)) + u3=$((u2 + 1)) + + [ -c /dev/md$u1 ] && mdconfig -d -u $u1 + [ -c /dev/md$u2 ] && mdconfig -d -u $u2 + [ -c /dev/md$u3 ] && mdconfig -d -u $u3 + + mdconfig -s 512m -u $u1 + mdconfig -s 512m -u $u2 + mdconfig -s 512m -u $u3 + + zpool create stress2_tank raidz md$u1 md$u2 md$u3 + + for i in `jot $mounts`; do + zfs create stress2_tank/test$i + zfs umount stress2_tank/test$i + done + + # start the parallel tests + touch /tmp/crossmp7.continue + for i in `jot $mounts`; do + ./$0 $i & + ./$0 find & + done + + wait + + zpool destroy stress2_tank + [ -n "$loaded" ] && kldunload zfs.ko + mdconfig -d -u $u1 + mdconfig -d -u $u2 + mdconfig -d -u $u3 + exit 0 +else + if [ $1 = find ]; then + while [ -f /tmp/crossmp7.continue ]; do + find /stress2_tank -type f > /dev/null 2>&1 + done + else + # The test: Parallel mount and unmounts + m=$1 + for i in `jot 1024`; do + zfs mount stress2_tank/test$m + zfs umount -f stress2_tank/test$m + done 2>/dev/null + rm -f /tmp/crossmp7.continue + fi +fi diff --git a/tools/test/stress2/misc/crossmp8.sh b/tools/test/stress2/misc/crossmp8.sh new file mode 100755 index 000000000000..f8d06d6a4a30 --- /dev/null +++ b/tools/test/stress2/misc/crossmp8.sh @@ -0,0 +1,125 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Variation of crossmp3.sh. fifos and sockets added to load. +# Not really a cross mount point test, but a test of the old +# non-directory use of the vnode v_un union. +# mckusick@ suggested using fifos for this test. + +# "panic: mtx_lock() of spin mutex @ ../kern/vfs_subr.c:512" seen. +# https://people.freebsd.org/~pho/stress/log/crossmp8.txt +# Fixed by r291671. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +CONT=/tmp/crossmp8.continue +N=`sysctl -n hw.ncpu` +usermem=`sysctl -n hw.usermem` +[ `swapinfo | wc -l` -eq 1 ] && usermem=$((usermem/100*80)) +size=$((usermem / 1024 / 1024 / N)) + +mounts=$N # Number of parallel scripts + +if [ $# -eq 0 ]; then + oldmx=`sysctl -n kern.maxvnodes` + trap "sysctl kern.maxvnodes=$oldmx > /dev/null" EXIT SIGINT + sysctl kern.maxvnodes=3072 > /dev/null + + for i in `jot $mounts`; do + m=$((i + mdstart - 1)) + [ ! -d ${mntpoint}$m ] && + { mkdir ${mntpoint}$m; chmod 755 ${mntpoint}$m; } + mount | grep "${mntpoint}$m " | grep -q md$m && + umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + mdconfig -a -t swap -s ${size}m -u $m + bsdlabel -w md$m auto + newfs md${m}$part > /dev/null 2>&1 + done + + # start the parallel tests + touch $CONT + for i in `jot $mounts`; do + m=$((i + mdstart - 1)) + ./$0 $m & + ./$0 find & + done + sleep 60 + rm -f $CONT + ../tools/killall.sh + wait + + for i in `jot $mounts`; do + m=$((i + mdstart - 1)) + while mount | grep -q "on ${mntpoint}$m "; do + umount ${mntpoint}$m && break + sleep 1 + done + mdconfig -d -u $m + done + ./cleanup.sh + exit 0 +else + if [ $1 = find ]; then + while [ -f $CONT ]; do + find ${mntpoint}* -maxdepth 1 -ls > /dev/null 2>&1 + sleep .1 + done + else + export RUNTIME=15s + export runRUNTIME=15s + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt 300 ]; do + m=$1 + mount /dev/md${m}$part ${mntpoint}$m && + chmod 777 ${mntpoint}$m + export RUNDIR=${mntpoint}$m/stressX + export CTRLDIR=${mntpoint}$m/stressX.control + export mkfifoLOAD=80 + export socketLOAD=80 + export TP=" + testcases/mkfifo/mkfifo + testcases/mkdir/mkdir + " + (cd ${mntpoint}$m && find . -delete) + su $testuser -c 'cd ..; ./testcases/run/run $TP' > \ + /dev/null 2>&1 + + while mount | grep -q "on ${mntpoint}$m "; do + opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") + umount $opt ${mntpoint}$m > /dev/null 2>&1 + [ -f $CONT ] || break 2 + done + done + rm -f $CONT + fi +fi diff --git a/tools/test/stress2/misc/crossmp9.sh b/tools/test/stress2/misc/crossmp9.sh new file mode 100755 index 000000000000..e55f16b5ede4 --- /dev/null +++ b/tools/test/stress2/misc/crossmp9.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC Isilon +# 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. +# + +# Parallel mount and umount of file systems, while using getfsstat(2) via +# mount(8). + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +cont=/tmp/crossmp.continue +mdstart=$mdstart # Use md unit numbers from this point + +if [ $# -eq 0 ]; then + touch $cont + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m + mount | grep "${mntpoint}$m " | grep -q md$m && + umount ${mntpoint}$m + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + mdconfig -a -t swap -s 512m -u $m + bsdlabel -w md$m auto + newfs $newfs_flags 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 $m & + done + wait + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + mdconfig -d -u $m + rm -f $D$m + done + exit 0 +else + if [ $1 = find ]; then + m=$2 + while [ -r $cont ]; do + df ${mntpoint}$m + mount + done > /dev/null 2>&1 + else + + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt 300 ] ; 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 + rm -f $cont + fi +fi diff --git a/tools/test/stress2/misc/dangling.sh b/tools/test/stress2/misc/dangling.sh new file mode 100755 index 000000000000..5f3db6db00ec --- /dev/null +++ b/tools/test/stress2/misc/dangling.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "panic: softdep_deallocate_dependencies: dangling deps" seen. +# "panic: softdep_write_inodeblock: indirect pointer #0 mismatch" seen. +# http://people.freebsd.org/~pho/stress/log/dangling.txt +# http://people.freebsd.org/~pho/stress/log/dangling2.txt +# https://people.freebsd.org/~pho/stress/log/kostik1101.txt + +# Test scenario seems optimized for 4 CPUs. + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 4g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint || exit 1 +chmod 777 $mntpoint + +export runRUNTIME=4m +export RUNDIR=$mntpoint/stressX +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 / 4)) +export INODES=$(($2 / 4)) + +export symlinkHOG=1 +export rwHOG=1 +export mkdirHOG=1 + +export LOAD=100 +export symlinkLOAD=100 +export rwLOAD=100 +export mkdirLOAD=100 +export TESTPROGS=" +testcases/symlink/symlink +testcases/fts/fts +testcases/mkdir/mkdir +testcases/rw/rw +" + +for i in `jot 10`; do + su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > \ + /dev/null 2>&1 & + sleep 60 + kill $! + ../tools/killall.sh > /dev/null 2>&1 + ../tools/killall.sh > /dev/null 2>&1 + wait +done + +s=0 +for i in `jot 6`; do + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && s=1 +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/datagram.sh b/tools/test/stress2/misc/datagram.sh new file mode 100755 index 000000000000..895145a22c84 --- /dev/null +++ b/tools/test/stress2/misc/datagram.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# UNIX datagram socket test. + +# "panic: mutex unp not owned at ../../../kern/uipc_usrreq.c:879" seen: +# https://people.freebsd.org/~pho/stress/log/datagram.txt +# Fixed by r334756. + +. ../default.cfg + +cd /tmp +cat > datagram.c < +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +char *filename = "/tmp/datagram.socket"; + +int +main(void) { + + struct sockaddr_un addr; + int bytes, sockfd; + char buf[1024]; + + unlink(filename); + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, filename, 104); + + if ((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) + err(1, "socket"); + + if (bind(sockfd, (struct sockaddr *) &addr, + sizeof(addr)) == -1) + err(1, "bind"); + + if (connect(sockfd, (struct sockaddr *) &addr, + sizeof(addr)) == -1) + err(1, "connect"); + + bytes = read(sockfd, buf, sizeof(buf)); + + return (0); +} +EOF + +mycc -o datagram -Wall -Wextra -O2 -g datagram.c || exit 1 +rm datagram.c + +./datagram & +sleep 1 +kill $! +wait + +rm -f datagram /tmp/datagram.socket +exit 0 diff --git a/tools/test/stress2/misc/datagram2.sh b/tools/test/stress2/misc/datagram2.sh new file mode 100755 index 000000000000..66cfd44711c2 --- /dev/null +++ b/tools/test/stress2/misc/datagram2.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# UNIX datagram socket test. + +# "panic: mutex unp not owned at ../../../kern/uipc_usrreq.c:879" seen. +# Fixed by r334756. + +. ../default.cfg + +cd /tmp +cat > datagram2.c < +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +char *filename = "/tmp/datagram2.socket"; + +int +main(void) { + + struct message { struct cmsghdr msg_hdr; int fd; } m; + struct msghdr mh; + struct sockaddr_un addr; + ssize_t len; + int sockfd; + + unlink(filename); + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, filename, 104); + + if ((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) + err(1, "socket"); + + if (bind(sockfd, (struct sockaddr *) &addr, + sizeof(addr)) == -1) + err(1, "bind"); + + if (connect(sockfd, (struct sockaddr *) &addr, + sizeof(addr)) == -1) + err(1, "connect"); + + bzero(&mh, sizeof(mh)); + bzero(&m, sizeof(m)); + mh.msg_control = &m; + mh.msg_controllen = sizeof(m); + m.msg_hdr.cmsg_len = sizeof(m); + m.msg_hdr.cmsg_level = SOL_SOCKET; + m.msg_hdr.cmsg_type = SCM_RIGHTS; + m.fd = sockfd; + len = sendmsg(sockfd, &mh, 0); + if (len < 0) + err(1, "sendmsg"); + + return (0); +} +EOF + +cc -o datagram2 -Wall -Wextra -O2 -g datagram2.c || exit 1 +rm -f datagram2.c datagram2.socket + +./datagram2 + +rm datagram2 datagram2.socket +exit 0 diff --git a/tools/test/stress2/misc/datagram3.sh b/tools/test/stress2/misc/datagram3.sh new file mode 100755 index 000000000000..ca54377befcc --- /dev/null +++ b/tools/test/stress2/misc/datagram3.sh @@ -0,0 +1,106 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# UNIX datagram socket test. + +# "panic: mutex unp not owned at ../../../kern/uipc_usrreq.c:879" seen. +# Fixed by r334756. + +. ../default.cfg + +cd /tmp +cat > datagram3.c < +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +char *filename = "/tmp/datagram3.socket"; + +int +main(void) { + + struct message { struct cmsghdr msg_hdr; int fd; } m; + struct msghdr mh; + struct sockaddr_un addr; + ssize_t len; + int i, sockfd; + + unlink(filename); + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, filename, 104); + + if ((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) + err(1, "socket"); + + if (bind(sockfd, (struct sockaddr *) &addr, + sizeof(addr)) == -1) + err(1, "bind"); + + if (connect(sockfd, (struct sockaddr *) &addr, + sizeof(addr)) == -1) + err(1, "connect"); + + for (i = 0; i < 32; i++) { + bzero(&mh, sizeof(mh)); + bzero(&m, sizeof(m)); + mh.msg_control = &m; + mh.msg_controllen = sizeof(m); + m.msg_hdr.cmsg_len = sizeof(m); + m.msg_hdr.cmsg_level = SOL_SOCKET; + m.msg_hdr.cmsg_type = SCM_RIGHTS; + m.fd = sockfd; + len = sendmsg(sockfd, &mh, 0); + if (len < 0) + err(1, "sendmsg"); + } + + return (0); +} +EOF + +mycc -o datagram3 -Wall -Wextra -O2 -g datagram3.c || exit 1 +rm -f datagram3.c datagram3.socket + +./datagram3 + +rm datagram3 datagram3.socket +exit 0 diff --git a/tools/test/stress2/misc/datamove.sh b/tools/test/stress2/misc/datamove.sh new file mode 100755 index 000000000000..a27a53e5e31b --- /dev/null +++ b/tools/test/stress2/misc/datamove.sh @@ -0,0 +1,230 @@ +#!/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. +# + +# 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 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > datamove.c +mycc -o datamove -Wall datamove.c +rm -f datamove.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/datamove.dir.$i + cd /tmp/datamove.dir.$i + /tmp/datamove & +done +cd /tmp +for i in `jot $n`; do + wait +done +for i in `jot $n`; do + rm -rf /tmp/datamove.dir.$i +done +sysctl vm.old_msync=$old + +rm -rf /tmp/datamove +exit 0 +EOF +/*- + * Copyright (c) 2006, Stephan Uphoff + * 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 unmodified, 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 ``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 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 + +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/tools/test/stress2/misc/datamove2.sh b/tools/test/stress2/misc/datamove2.sh new file mode 100755 index 000000000000..1b4c964a1f12 --- /dev/null +++ b/tools/test/stress2/misc/datamove2.sh @@ -0,0 +1,244 @@ +#!/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. +# + +# Variation of the datamove.sh scenario by not using "sysctl vm.old_msync=1" + +# Deadlock seen: +# https://people.freebsd.org/~pho/stress/log/numa042.txt + +# Test scenario by ups + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > datamove2.c +mycc -o datamove2 -Wall datamove2.c +rm -f datamove2.c + +for i in `jot 2`; do + $here/../testcases/swap/swap -t 5m -i 100 -h & + sleep 1 + /tmp/datamove2 || { echo FAIL; r=1; } + while pkill -9 swap; do :; done + [ -n "$r" ] && break +done +rm -rf /tmp/datamove2 +exit $r +EOF +/*- + * Copyright (c) 2006, Stephan Uphoff + * 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 unmodified, 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 ``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 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 + +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"); + /* + The following unmaps something random, which could trigger: + Program received signal SIGSEGV, Segmentation fault. + free (cp=0x28070000) at /usr/src/libexec/rtld-elf/malloc.c:311 + */ + +#if 0 + if (munmap(bufferp + pagesize * 2, pagesize * 2) == -1) + err(1, "unmap 2. buffer"); +#endif +} + +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/tools/test/stress2/misc/datamove3.sh b/tools/test/stress2/misc/datamove3.sh new file mode 100755 index 000000000000..47a1cbce4c95 --- /dev/null +++ b/tools/test/stress2/misc/datamove3.sh @@ -0,0 +1,241 @@ +#!/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. +# + +# 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 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > datamove3.c +mycc -o datamove3 -Wall datamove3.c -lpthread +rm -f datamove3.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/datamove3.dir.$i + cd /tmp/datamove3.dir.$i + /tmp/datamove3 & +done +cd /tmp +for i in `jot $n`; do + wait +done +for i in `jot $n`; do + rm -rf /tmp/datamove3.dir.$i +done +sysctl vm.old_msync=$old + +rm -rf /tmp/datamove3 +exit 0 +EOF +/*- + * Copyright (c) 2006, Stephan Uphoff + * 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 unmodified, 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 ``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 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 + +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) + errc(1, r, "pthread_create()"); + if ((r = pthread_create(&threads[1], NULL, mapBuffer, (void *)1)) != 0) + errc(1, r, "pthread_create()"); + + 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/tools/test/stress2/misc/datamove4.sh b/tools/test/stress2/misc/datamove4.sh new file mode 100755 index 000000000000..4b4726b8dace --- /dev/null +++ b/tools/test/stress2/misc/datamove4.sh @@ -0,0 +1,251 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Variation of the datamove2.sh, using TMPFS +# Deadlock seen +# https://people.freebsd.org/~pho/stress/log/datamove4.txt + +# panic: elf32_putnote: Note type 10 changed as we read it (2236 > 2220)... +# https://people.freebsd.org/~pho/stress/log/datamove4-2.txt +# Fixed by r288944. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > datamove4.c +mycc -o datamove4 -Wall -Wextra -O2 -g datamove4.c +rm -f datamove4.c + +mount | grep -q "$mntpoint " && umount $mntpoint +mount -t tmpfs tmpfs $mntpoint +chmod 777 $mntpoint + +for i in `jot 5`; do + su $testuser -c "cd $mntpoint; /tmp/datamove4" +done +while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 +done + +rm -rf /tmp/datamove4 +exit 0 +EOF +/*- + * Copyright (c) 2006, Stephan Uphoff + * 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 unmodified, 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 ``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 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 + +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(filename); + 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"); + /* + The following unmaps something random, which could trigger: + Program received signal SIGSEGV, Segmentation fault. + free (cp=0x28070000) at /usr/src/libexec/rtld-elf/malloc.c:311 + */ + +#if 0 + if (munmap(bufferp + pagesize * 2, pagesize * 2) == -1) + err(1, "unmap 2. buffer"); +#endif +} + +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 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/tools/test/stress2/misc/datamove5.sh b/tools/test/stress2/misc/datamove5.sh new file mode 100755 index 000000000000..5f4a868f03b1 --- /dev/null +++ b/tools/test/stress2/misc/datamove5.sh @@ -0,0 +1,262 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Variation of the datamove2.sh, using NULLFS +# No problems seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > datamove5.c +mycc -o datamove5 -Wall -Wextra -O2 -g datamove5.c +rm -f datamove5.c + +mp1=$mntpoint +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir $mp2 + +mount | grep -wq $mp2 && umount $mp2 +mount | grep -wq $mp1 && umount $mp1 +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mp1 + +mount -t nullfs $opt $mp1 $mp2 +chmod 777 $mp2 + +for i in `jot 5`; do + su $testuser -c "cd $mp2; /tmp/datamove5" +done + +while mount | grep -wq $mp2; do + umount $mp2 || sleep 1 +done +while mount | grep $mp1 | grep -q /dev/md; do + umount $mp1 || sleep 1 +done +mdconfig -d -u $mdstart + +rm -rf /tmp/datamove5 +exit 0 +EOF +/*- + * Copyright (c) 2006, Stephan Uphoff + * 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 unmodified, 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 ``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 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 + +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(filename); + 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"); + /* + The following unmaps something random, which could trigger: + Program received signal SIGSEGV, Segmentation fault. + free (cp=0x28070000) at /usr/src/libexec/rtld-elf/malloc.c:311 + */ + +#if 0 + if (munmap(bufferp + pagesize * 2, pagesize * 2) == -1) + err(1, "unmap 2. buffer"); +#endif +} + +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 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/tools/test/stress2/misc/db.sh b/tools/test/stress2/misc/db.sh new file mode 100755 index 000000000000..580ee71c4c94 --- /dev/null +++ b/tools/test/stress2/misc/db.sh @@ -0,0 +1,178 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Demonstrate resource starvation using msync(2). + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/db.c +mycc -o db -Wall -Wextra -O0 -g db.c -lpthread || exit 1 +rm -f db.c +cd $odir + +dd if=/dev/zero of=$diskimage bs=1m count=10 status=none + +/tmp/db $diskimage & + +start=`date '+%s'` +ls -l $diskimage > /dev/null # Will wait for more than 90 seconds +[ `date '+%s'` -gt $((start + 90)) ] && fail="yes" +wait +e=$((`date +%s` - start)) +[ $fail ] && + echo "Time for a ls is $((e / 60)) minutes $((e % 60)) seconds" +rm -f /tmp/db $diskimage +#[ $fail ] && exit 1 || exit 0 # Known issue +exit 0 + +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#ifdef __FreeBSD__ +#include +#define __NP__ +#endif +#include +#include +#include +#include +#include + +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +size_t len; +void *p; +int wthreads; + +#define BZ 128 /* buffer size */ +#define RUNTIME 180 /* runtime for test */ +#define RTHREADS 64 /* reader threads */ +#define WTHREADS 64 /* writer threads */ + +void * +wt(void *arg __unused) +{ + time_t start; + int64_t pos; + void *c; + int r; + char buf[BZ]; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + if ((r = pthread_mutex_lock(&mutex)) != 0) + errc(1, r, "pthread_mutex_lock"); + wthreads++; + if ((r = pthread_mutex_unlock(&mutex)) != 0) + errc(1, r, "pthread_mutex_unlock"); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + pos = arc4random() % (len / BZ); + pos = pos * BZ; + c = p + pos; + bcopy(buf, c, BZ); + c = (void *)trunc_page((unsigned long)c); + if (msync((void *)c, round_page(BZ), MS_SYNC) == -1) + err(1, "msync(%p)", c); + usleep(10000 + arc4random() % 1000); + } + + if ((r = pthread_mutex_lock(&mutex)) != 0) + errc(1, r, "pthread_mutex_lock"); + wthreads--; + if ((r = pthread_mutex_unlock(&mutex)) != 0) + errc(1, r, "pthread_mutex_unlock"); + + return (NULL); +} + +void * +rt(void *arg __unused) +{ + int64_t pos; + char buf[BZ], *c; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + c = p; + do { + pos = arc4random() % (len / BZ); + pos = pos * BZ; + bcopy(&c[pos], buf, BZ); + usleep(10000 + arc4random() % 1000); + } while (wthreads != 0); + + return (NULL); +} + +int +main(int argc, char *argv[]) +{ + pthread_t cp[RTHREADS + WTHREADS]; + struct stat st; + int fd, i, j, rc; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + if ((fd = open(argv[1], O_RDWR)) == -1) + err(1, "open %s", argv[1]); + if (fstat(fd, &st) == -1) + err(1, "stat"); + len = round_page(st.st_size); + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if ((void *)p == MAP_FAILED) + err(1, "mmap"); + + i = 0; + for (j = 0; j < WTHREADS; j++) { + if ((rc = pthread_create(&cp[i++], NULL, wt, NULL)) != 0) + errc(1, rc, "pthread_create()"); + } + usleep(100); + for (j = 0; j < RTHREADS; j++) { + if ((rc = pthread_create(&cp[i++], NULL, rt, NULL)) != 0) + errc(1, rc, "pthread_create()"); + } + + for (j = 0; j < RTHREADS + WTHREADS; j++) + pthread_join(cp[--i], NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/dd.sh b/tools/test/stress2/misc/dd.sh new file mode 100755 index 000000000000..ba57e7f1d0a2 --- /dev/null +++ b/tools/test/stress2/misc/dd.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Watchdog fired: +# https://people.freebsd.org/~pho/stress/log/mark013.txt +# Fixed by: r327213 + +# watchdogd: https://people.freebsd.org/~pho/stress/log/kostik1245.txt + +. ../default.cfg + +outputfile=$RUNDIR/dd.outputfile +(cd ../testcases/swap; ./swap -t 30m -i 20) > /dev/null 2>&1 & +trap "rm -f ${outputfile}*" EXIT INT +N=2 +NCPU=`sysctl -n hw.ncpu` +s=0 +size=512 +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 720 ]; do + pids="" + for i in `jot $N`; do + dd if=/dev/zero of=${outputfile}$i bs=1m count=$size & + pids="$pids $!" + done > /dev/null 2>&1 + for pid in $pids; do + wait $pid + s=$? + [ $s -ne 0 ] && break 2 + done + N=$((N * 2)) + rm -f ${outputfile}* + [ $N -gt $((NCPU * 2)) ] && break +done + +while pgrep -q swap; do + pkill -9 swap +done +exit $s diff --git a/tools/test/stress2/misc/dev.sh b/tools/test/stress2/misc/dev.sh new file mode 100755 index 000000000000..1dc094a09e5b --- /dev/null +++ b/tools/test/stress2/misc/dev.sh @@ -0,0 +1,137 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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 parallel read access to /dev. + +# "panic: Most recently used by DEVFS1" seen. +# https://people.freebsd.org/~pho/stress/log/dev.txt +# Fixed by r293826. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > dev.c +mycc -o dev -Wall -Wextra -O2 dev.c || exit 1 +rm -f dev.c + +echo "Expect: g_access(958): provider ufsid/5c581221fcac7d80 has error 6 set" +daemon sh -c \ + "(cd $here/../testcases/swap; ./swap -t 6m -i 20 -k -l 100)" > \ + /dev/null + +/tmp/dev # Note: this runs as root. +s=$? + +while pkill -9 swap; do + : +done + +rm -f /tmp/dev +exit $s +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define RUNTIME 300 + +char path[80]; + +void +churn(char *path) +{ + FTS *fts; + FTSENT *p; + time_t start; + int fd, ftsoptions; + char *args[2]; + + ftsoptions = FTS_PHYSICAL; + args[0] = path; + args[1] = 0; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + if (p->fts_info == FTS_D || + p->fts_info == FTS_DP) + continue; + if (strstr(p->fts_path, "ttyu") != NULL) + continue; + if (strstr(p->fts_path, "fcdm") != NULL) + continue; + if ((fd = open(p->fts_path, O_RDONLY|O_NONBLOCK)) == -1) + continue; + usleep(arc4random() % 1000); + close(fd); + + } + + if (errno != 0 && errno != ENOENT) + warn("fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } + + _exit(0); +} + +int +main(void) +{ + int e, i, status;; + + e = 0; + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + churn("/dev"); + + for (i = 0; i < PARALLEL; i++) { + wait(&status); + if (status != 0) + e++; + } + + return (e); +} diff --git a/tools/test/stress2/misc/dev2.sh b/tools/test/stress2/misc/dev2.sh new file mode 100755 index 000000000000..5a194974e135 --- /dev/null +++ b/tools/test/stress2/misc/dev2.sh @@ -0,0 +1,144 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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 parallel access to /dev. A non-root version. + +# "panic: Bad link elm 0xfffff8000b07ed00 prev->next != elm" seen. +# https://people.freebsd.org/~pho/stress/log/dev2.txt + +# Fixed by r294204. + +# "panic: Assertion !tty_gone(tp) failed at ../sys/ttydevsw.h:165" seen: +# https://people.freebsd.org/~pho/stress/log/dev2-2.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q pty || { kldload pty || exit 0; } +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > dev2.c +mycc -o dev2 -Wall -Wextra -O2 dev2.c || exit 1 +rm -f dev2.c + +daemon sh -c \ + "(cd $here/../testcases/swap; ./swap -t 6m -i 20 -k -l 100)" > \ + /dev/null + +su $testuser -c /tmp/dev2 + +while pkill -9 swap; do + : +done + +rm -f /tmp/dev2 +exit +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define RUNTIME 300 + +jmp_buf jbuf; +char path[80]; + +void +handler(int i __unused) { + longjmp(jbuf, 1); +} + +void +churn(char *path) +{ + FTS *fts; + FTSENT *p; + time_t start; + int fd, ftsoptions; + char *args[2]; + + ftsoptions = FTS_PHYSICAL; + args[0] = path; + args[1] = 0; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + (void)setjmp(jbuf); + ualarm(0, 0); + while ((p = fts_read(fts)) != NULL) { + if (p->fts_info == FTS_D || + p->fts_info == FTS_DP) + continue; + ualarm(500000, 0); + if ((fd = open(p->fts_path, arc4random() % (O_CLOEXEC << 2))) == -1) + continue; + ualarm(0, 0); + usleep(arc4random() % 1000); + close(fd); + + } + + if (errno != 0 && errno != ENOENT) + warn("fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } + + _exit(0); +} + +int +main(void) +{ + int i; + + signal(SIGALRM, handler); + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + churn("/dev"); + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/dev3.sh b/tools/test/stress2/misc/dev3.sh new file mode 100755 index 000000000000..b120266faf83 --- /dev/null +++ b/tools/test/stress2/misc/dev3.sh @@ -0,0 +1,160 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# pts memory leak regression test. + +# Leaks seen when flags is either O_SHLOCK or O_EXLOCK and /dev/ptmx and +# /dev/pts/ is being opened. +# Fixed in r313496. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q pty || { kldload pty || exit 0; } +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > dev3.c +mycc -o dev3 -Wall -Wextra -O2 dev3.c || exit 1 +rm -f dev3.c + +#(cd $here/../testcases/swap; ./swap -t 10h -i 20 -l 100) > \ +# /dev/null & + +pts=`vmstat -m | grep pts | awk '{print $2}'` +[ -z "$pts" ] && pts=0 + +e=0 +n=0 +while true; do + su $testuser -c "/tmp/dev3 $n" + new=`vmstat -m | grep pts | awk '{print $2}'` + if [ $new -gt $pts ]; then + leak=$((new - pts)) + printf "flag %d (0x%x) leaks %d pts, %d allocated.\n" $n $n \ + $leak $new + pts=$new + e=1 + fi + [ $n -eq 0 ] && n=1 || n=$((n * 2)) + [ $n -gt $((0x00200000)) ] && break # O_VERIFY +done +while pkill -9 swap; do + sleep 1 +done +wait +rm -f /tmp/dev3 +exit $e +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define RUNTIME 60 + +jmp_buf jbuf; +char path[80]; + +void +handler(int i __unused) { + longjmp(jbuf, 1); +} + +void +churn(int flag, char *path) +{ + FTS *fts; + FTSENT *p; + time_t start; + int fd, ftsoptions; + char *args[2]; + + ftsoptions = FTS_PHYSICAL; + args[0] = path; + args[1] = 0; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + (void)setjmp(jbuf); + ualarm(0, 0); + while ((p = fts_read(fts)) != NULL) { + if (p->fts_info == FTS_D || + p->fts_info == FTS_DP) + continue; + ualarm(500000, 0); + if ((fd = open(p->fts_path, flag)) == -1) + continue; + ualarm(0, 0); + usleep(arc4random() % 1000); + close(fd); + + } + + if (errno != 0 && errno != ENOENT) + warn("fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + int flag, i; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + flag = atoi(argv[1]); + signal(SIGALRM, handler); + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + churn(flag, "/dev"); + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/devfd.sh b/tools/test/stress2/misc/devfd.sh new file mode 100755 index 000000000000..1f5eecece0ca --- /dev/null +++ b/tools/test/stress2/misc/devfd.sh @@ -0,0 +1,130 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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. +# + +# "panic: vn_lock 0xc65b5828: zero hold count" seen. + +# Originally found by the iknowthis test suite +# by Tavis Ormandy +# Fixed by r227952 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > devfd.c +rm -f /tmp/devfd +mycc -o devfd -Wall -Wextra -O2 -g devfd.c -lpthread || exit 1 +rm -f devfd.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +su $testuser -c "(cd $mntpoint; /tmp/devfd)" + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/devfd +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int fd[3], fd2[3]; + +void * +thr1(void *arg __unused) +{ + int i, j; + char path[80]; + + for (i = 0; i < 100000; i++) { + for (j = 0; j < 3; j++) { + if (fd[j] != -1) + close(fd[j]); + sprintf(path, "fx%d", j); + fd[j] = open(path, O_RDWR | O_CREAT, 0640); + } + } + return (0); +} + +void * +thr2(void *arg __unused) +{ + int i, j; + char path[80]; + + for (i = 0; i < 100000; i++) { + for (j = 0; j < 3; j++) { + if (fd2[j] != -1) + close(fd2[j]); + sprintf(path, "/dev/fd/%d", j); + if ((fd2[j] = open(path, O_RDONLY)) != -1) + fchflags(fd2[j], UF_NODUMP); + } + + } + return (0); +} + +int +main(void) +{ + pthread_t p1, p2; + int r; + + close(0); + close(1); + close(2); + if ((r = pthread_create(&p1, NULL, thr1, NULL)) != 0) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&p2, NULL, thr2, NULL)) != 0) + errc(1, r, "pthread_create"); + pthread_join(p1, NULL); + pthread_join(p2, NULL); + + return (0); +} + diff --git a/tools/test/stress2/misc/devfs.sh b/tools/test/stress2/misc/devfs.sh new file mode 100755 index 000000000000..acb351f26e56 --- /dev/null +++ b/tools/test/stress2/misc/devfs.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. +# + +# Page fault seen: +# https://people.freebsd.org/~pho/stress/log/devfs.txt +# Fixed by r326851. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +cont=/tmp/devfs.continue + +if [ $# -eq 0 ]; then + touch $cont + for i in `jot $mounts`; do + [ ! -d ${mntpoint}$i ] && mkdir ${mntpoint}$i + mount | grep -q "on ${mntpoint}$i " && umount ${mntpoint}$i + done + + # start the parallel tests + for i in `jot $mounts`; do + ./$0 $i & + ./$0 find & + done + wait +else + if [ $1 = find ]; then + while [ -r $cont ]; do + find ${mntpoint}* > /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ `date '+%s'` -lt $((start + 300)) ]; 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 + rm -f $cont + fi +fi diff --git a/tools/test/stress2/misc/devfs2.sh b/tools/test/stress2/misc/devfs2.sh new file mode 100755 index 000000000000..47f80a09f7f8 --- /dev/null +++ b/tools/test/stress2/misc/devfs2.sh @@ -0,0 +1,107 @@ +#!/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. +# + +# 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 + +. ../default.cfg + +odir=`pwd` +dir=/tmp + +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/devfs2.c +mycc -o devfs2 -Wall devfs2.c -lthr || exit 1 +rm -f devfs2.c + +./devfs2 + +rm devfs2 +exit 0 + +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 ((r = pthread_join(threads[i], NULL)) != 0) + errc(1, r, "pthread_join(%d)", i); + + return (0); +} diff --git a/tools/test/stress2/misc/devfs3.sh b/tools/test/stress2/misc/devfs3.sh new file mode 100755 index 000000000000..4bfce110eade --- /dev/null +++ b/tools/test/stress2/misc/devfs3.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Panic seen with two instances of devfs.sh running simultaneously. + +# "panic: dev_rel() gave negative count" seen: +# https://people.freebsd.org/~pho/stress/log/devfs3.txt + +# "panic: No vop_unlock(0xfffff80089eb0750, 0xfffffe104944f4c8)" seen: +# https://people.freebsd.org/~pho/stress/log/kostik898.txt + +# Fixed by r301928 + r301929. + +./devfs.sh > /dev/null 2>&1 & +p1=$! +./devfs.sh > /dev/null 2>&1 & +p2=$! + +wait $p1 +wait $p2 diff --git a/tools/test/stress2/misc/devfs4.sh b/tools/test/stress2/misc/devfs4.sh new file mode 100755 index 000000000000..eac87374db11 --- /dev/null +++ b/tools/test/stress2/misc/devfs4.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Bug 235513 - panic: dead bo 0xfffff8000a838b48 +# https://people.freebsd.org/~pho/stress/log/devfs4.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +umount -f /dev && mount /dev diff --git a/tools/test/stress2/misc/devfs5.sh b/tools/test/stress2/misc/devfs5.sh new file mode 100755 index 000000000000..b0b1d98fc83e --- /dev/null +++ b/tools/test/stress2/misc/devfs5.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test scenario for https://reviews.freebsd.org/D20411 +# Add devfs(5) support for VOP_MKDIR(9) and VOP_RMDIR(9) + +. ../default.cfg + +mkdir /dev/devfs5 2>/dev/null || exit 0 +rmdir /dev/devfs5 +mount | grep -q "on $mntpoint " && umount -f $mntpoint +mount -t devfs null $mntpoint || exit 1 + +(cd ../testcases/swap; ./swap -t 30m -i 20 -h -l 100) & +spid=$! +cd $mntpoint +N=3000 +for i in `jot 25`; do + ( + mkdir s$i; cd s$i + for k in `jot 5`; do + for j in `jot $N`; do mkdir d$i.$j; done + for j in `jot $N`; do rmdir d$i.$j; done + done + cd ..; rmdir s$i + ) & + pids="$pids $!" +done +for i in $pids; do + wait $i +done +while pkill swap; do :; done +wait spid + +cd / +while mount | grep -q "on $mntpoint "; do + umount $mntpoint && break + sleep 1 +done +exit 0 diff --git a/tools/test/stress2/misc/dfull.sh b/tools/test/stress2/misc/dfull.sh new file mode 100755 index 000000000000..100784047dbc --- /dev/null +++ b/tools/test/stress2/misc/dfull.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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. +# + +# Processes stuck in "ufs" seen. +# Looping softdep_request_cleanup() seen + +[ `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 512m -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +export RUNDIR=$mntpoint/stressX +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 * 10)) +export INODES=$(($2 * 10)) +export runRUNTIME=20m +export RUNTIME=1m + +(cd ..; ./run.sh disk.cfg > /dev/null 2>&1) + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/dtrace.sh b/tools/test/stress2/misc/dtrace.sh new file mode 100755 index 000000000000..3521ef3099e5 --- /dev/null +++ b/tools/test/stress2/misc/dtrace.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Simple dtrace(1) test scenario. +# https://people.freebsd.org/~pho/stress/log/dtrace.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg +dtrace -n 'dtrace:::BEGIN { exit(0); }' > /dev/null 2>&1 || exit 0 + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX + +log=/tmp/dtrace.$$ +trap "rm -f $log" EXIT INT +dtrace -w -n 'syscall::*read:entry,syscall::*write:entry {\ + @rw[execname,probefunc] = count(); }' > $log 2>&1 & +pid=$! +sleep 1 +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 +kill -INT $pid > /dev/null 2>&1 +while pgrep -q dtrace; do + pkill dtrace + sleep 2 +done +wait +tail -5 $log + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +kldstat | grep -q dtraceall && + kldunload dtraceall.ko +exit 0 diff --git a/tools/test/stress2/misc/dtrace_fault.sh b/tools/test/stress2/misc/dtrace_fault.sh new file mode 100755 index 000000000000..508cfc48cd59 --- /dev/null +++ b/tools/test/stress2/misc/dtrace_fault.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Konstantin Belousov +# +# 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. +# + +# Regression test for: + +# panic: invalid signal +# KDB: stack backtrace: +# db_trace_self_wrapper(c161045c,c18b9e7c,0,c15df420,f3de7ad8,...) at db_trace_self_wrapper+0x2a/frame 0xf3de7aa8 +# kdb_backtrace(c160aaf6,5984403e,0,f3de7b74,d,...) at kdb_backtrace+0x2d/frame 0xf3de7b10 +# vpanic(c160b255,f3de7b74,c160b255,f3de7b74,f3de7b74,...) at vpanic+0x133/frame 0xf3de7b44 +# kassert_panic(c160b255,c1612dc1,7d,cc97240c,0,...) at kassert_panic+0xd9/frame 0xf3de7b68 +# trapsignal(cc29ea80,f3de7c30,c0cb259e,2,0,...) at trapsignal+0x246/frame 0xf3de7ba0 +# trap(f3de7ce8) at trap+0x7fe/frame 0xf3de7cdc +# calltrap() at calltrap+0x6/frame 0xf3de7cdc +# --- trap 0x20, eip = 0x8048565, esp = 0xbfbfe7d4, ebp = 0xbfbfe7d4 --- + +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221151 +# Fixed by r321919 + +. ../default.cfg + +uname -a | egrep -q "i386|amd64" || exit 0 + +cat > /tmp/dtrace_fault.c < /dev/null || exit 1 + +mount /dev/md$mdstart $mntpoint || exit 1 + +here=`pwd` +cd $mntpoint +for i in `jot 10`; do + echo $i +done > file1 +cp file1 file2 +cp file2 file3 +mv file1 filea +rm file2 + +cd $here +umount $mntpoint +dumpfs /dev/md$mdstart | expand > $dump +r=`sed 's/time *[A-Z].*//;s/id .*//' < $dump | md5` +if [ $md != $r ]; then + echo "$r != $md" + s=1 + [ -f $good ] && diff $good $dump +else + [ ! -f $good ] && mv $dump $good # save good dump +fi +mdconfig -d -u $mdstart +[ $s -eq 0 ] && rm -f $disk $dump +rm -f $disk $dump # for now +exit $s diff --git a/tools/test/stress2/misc/dup.sh b/tools/test/stress2/misc/dup.sh new file mode 100755 index 000000000000..7223709d09c4 --- /dev/null +++ b/tools/test/stress2/misc/dup.sh @@ -0,0 +1,122 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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 scenario for "D20947: Check and avoid overflow when incrementing +# fp->f_count in fget_unlocked() and fhold()". + +# OOM killing seen. Cap files and procs for now. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +rm -f /tmp/dup /tmp/dup.c || exit 1 +sed '1,/^EOF/d' < $odir/$0 > $dir/dup.c +mycc -o dup -Wall -Wextra dup.c || exit 1 +rm -f dup.c +cd $odir + +/tmp/dup; s=$? + +rm -f /tmp/dup +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; +#define N 10240 +#define CAP_FILES 50000 +#define CAP_PROCS 1000 +#define SYNC 0 + +int +main(void) +{ + struct stat st; + pid_t pid[N]; + size_t len; + int fd, fd2, i, j, last; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + if ((fd = open("/dev/zero", O_RDONLY)) == -1) + err(1, "open(/dev/zero)"); + i = 0; + for (;;) { + if ((fd2 = dup(fd)) == -1) { + if (errno == EMFILE) + break; + err(1, "dup()"); + } + last = fd2; + if (++i == CAP_FILES) + break; + } +#if defined(DEBUG) + fprintf(stderr, "i = %d\n", i); +#endif + + for (i = 0; i < N; i++) { + if ((pid[i] = fork()) == 0) { + if (fstat(last, &st) == -1) + err(1, "stat(%s)", "/dev/zero"); + while(share[SYNC] == 0) + usleep(100000); + _exit(0); + } + if (pid[i] == -1) { + warn("fork()"); + i--; + break; + } + if (i + 1 == CAP_PROCS) + break; + } + share[SYNC] = 1; + for (j = 0; j < i; j++) { + if (waitpid(pid[j], NULL, 0) != pid[j]) + err(1, "waitpid(%d), index %d", pid[j], j); + } + + return (0); +} diff --git a/tools/test/stress2/misc/dup2.sh b/tools/test/stress2/misc/dup2.sh new file mode 100755 index 000000000000..2e575d6625f9 --- /dev/null +++ b/tools/test/stress2/misc/dup2.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Regression test for r234131. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/dup2.c +mycc -o dup2 -Wall -Wextra dup2.c || exit 1 +rm -f dup2.c +cd $odir + +/tmp/dup2 || { echo FAIL; exit 1; } + +rm -f /tmp/dup2 +exit 0 + +EOF +#include +#include +#include +#include + +int +main(void) +{ + int error, fd2, i; + + error = 0; + for (i = 0; i < 10000; i++) { + fd2 = arc4random() % 1000000; + if (dup2(1, fd2) == -1) { + if (errno != EBADF) { + warn("dup2(1, %d)", fd2); + error = 1; + break; + } + } else + close(fd2); + } + + return (error); +} diff --git a/tools/test/stress2/misc/execi386.sh b/tools/test/stress2/misc/execi386.sh new file mode 100755 index 000000000000..c59a96765746 --- /dev/null +++ b/tools/test/stress2/misc/execi386.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Calling exec*(2) in a thread of a i386 binary on amd64 caused a reboot. +# Test scenario by: Steven Chamberlain +# Fixed by r266464 + +[ `uname -p` = "amd64" ] || exit 0 + +. ../default.cfg + +wd=/tmp/execi386.dir +mkdir -p $wd +here=`pwd` +cd $wd + +cat > execi386.c < +#include + +void * +thread_main() { + char *cmdline[] = { "./i386", NULL }; + + execve(cmdline[0], cmdline, NULL); + + return (NULL); +} + +int +main() { + pthread_t thread; + + pthread_create(&thread, NULL, thread_main, NULL); + pthread_join(thread, NULL); + + return (0); +} +EOF + +mycc -o execi386 -Wall -Wextra -O2 -g execi386.c -lpthread || exit 1 + +cat > i386.c < + +int +main(void) +{ + fprintf(stdout, "Hello, world\n"); + return (0); +} +EOF + +mycc -m32 -o i386 -Wall -Wextra -O2 -g i386.c || exit 1 + +./execi386 > /dev/null || echo FAIL + +cd $here +rm -rf $wd +exit 0 diff --git a/tools/test/stress2/misc/execve.sh b/tools/test/stress2/misc/execve.sh new file mode 100755 index 000000000000..7a36ec4ca3e7 --- /dev/null +++ b/tools/test/stress2/misc/execve.sh @@ -0,0 +1,130 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 of execve(2) from a threaded program. +# "load: 5.40 cmd: bash 24517 [vmmaps] 2.45r 0.00u 0.00s 0% 3448k" seen. +# Fixed by r282708. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > execve.c +mycc -o execve -Wall -Wextra -O2 execve.c -lpthread || exit 1 +rm -f execve.c + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 20m -i 20 -l 100)" > \ + /dev/null 2>&1 +sleep `jot -r 1 1 9` +for i in `jot 2`; do + /tmp/execve +done +while pgrep -q swap; do + pkill -9 swap +done + +rm -f /tmp/execve /tmp/execve.core +exit 0 +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 50 +#define PARALLEL 50 + +volatile int go; + +void * +texecve(void *arg __unused) +{ + char *cmdline[] = { "/usr/bin/true", NULL }; + + while (go == 0) + usleep(100); + if (execve(cmdline[0], cmdline, NULL) == -1) + err(1, "execve"); + + return (NULL); +} + +void +test(void) +{ + pthread_t tid[5]; + int i, rc; + + go = 0; + + for (i = 0; i < 5; i++) { + if ((rc = pthread_create(&tid[i], NULL, texecve, NULL)) != 0) + errc(1, rc, "texecve()"); + } + + usleep(arc4random() % 2000); + go = 1; + + for (i = 0; i < 5; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(void) +{ + struct rlimit rl; + int i, j; + + rl.rlim_max = rl.rlim_cur = 0; + if (setrlimit(RLIMIT_CORE, &rl) == -1) + warn("setrlimit"); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/exlock.sh b/tools/test/stress2/misc/exlock.sh new file mode 100755 index 000000000000..6e88f9437177 --- /dev/null +++ b/tools/test/stress2/misc/exlock.sh @@ -0,0 +1,122 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Simple O_EXLOCK test scenario. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > exlock.c +mycc -o exlock -Wall -Wextra exlock.c || exit 1 +rm -f exlock.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +su $testuser -c "cd $mntpoint; /tmp/exlock" + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/exlock +exit +EOF +#include +#include + +#include +#include +#include +#include + +char buf[128]; + +#define PARALLEL 3 + +static void +tst(char *file, int n) +{ + int fd, i; + + for (i = 0; i < (int)sizeof(buf); i++) + buf[i] = '0' + n; + + for (i = 0; i < 1024 * 1024; i++) { + if ((fd = open(file, O_RDWR | O_CREAT | O_APPEND | O_EXLOCK, + 0644)) == -1) + err(1, "open(%s)", file); + if (write(fd, buf, sizeof(buf)) != sizeof(buf)) + err(1, "write"); + close(fd); + } + + _exit(0); +} +static void +test(void) +{ + int i; + char file[80]; + + snprintf(file, sizeof(file), "f06%d", getpid()); + + for (i = 0; i < 3; i++) + if (fork() == 0) + tst(file, i); + for (i = 0; i < 3; i++) + wait(NULL); + + unlink(file); + + _exit(0); +} + +int +main(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + test(); + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/exlock2.sh b/tools/test/stress2/misc/exlock2.sh new file mode 100755 index 000000000000..94e3f88f48e3 --- /dev/null +++ b/tools/test/stress2/misc/exlock2.sh @@ -0,0 +1,210 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# O_CREAT|O_EXCL|O_EXLOCK atomic implementation test. +# Lots of input from kib@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/exlock2.c +mycc -o exlock2 -Wall -Wextra -O0 -g exlock2.c || exit 1 +rm -f exlock2.c +cd $odir + +$dir/exlock2 +s=$? +[ -f exlock2.core -a $s -eq 0 ] && + { ls -l exlock2.core; mv exlock2.core $dir; s=1; } +cd $odir + +rm -f $dir/exlock2 /tmp/exlock2.*.file +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static _Atomic(int) *share; +static int quit; +static char file[80]; + +#define RUNTIME (2 * 60) +#define SYNC 0 + +static void +handler(int s __unused) +{ + quit = 1; +} + +static void +test1(void) +{ + time_t start; + int fd, n; + + signal(SIGHUP, handler); + n = 0; + start = time(NULL); + while (time(NULL) - start < RUNTIME && quit == 0) { + n++; + if ((fd = open(file, O_RDWR|O_CREAT|O_EXCL|O_EXLOCK, + DEFFILEMODE)) == -1) + err(1, "open(%s) creat", file); + unlink(file); + if (write(fd, "test", 5) != 5) + err(1, "write()"); + while (share[SYNC] == 1) + ; /* wait for test2 to signal "done" */ + close(fd); + } +#if defined(DEBUG) + fprintf(stderr, "%s: n = %d\n", __func__, n); +#endif + + _exit(0); +} + +static void +test2(void) +{ + struct flock fl; + struct stat st; + time_t start; + int e, fd, n; + + e = 0; + fd = 0; + n = 0; + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + share[SYNC] = 1; + if ((fd = open(file, O_RDWR)) == -1) + goto out; + n++; + memset(&fl, 0, sizeof(fl)); + fl.l_start = 0; + fl.l_len = 0; + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + if (fcntl(fd, F_SETLK, &fl) < 0) { + if (errno != EAGAIN) + err(1, "fcntl(F_SETFL)"); + goto out; + } + /* test1 must have dropped the lock */ + fprintf(stderr, "%s got the lock.\n", __func__); + if (fstat(fd, &st) == -1) + err(1, "stat(%s)", file); + /* As test1 has opened the file exclusivly, this + should not happen */ + if (st.st_size == 0) + fprintf(stderr, "%s has size 0\n", file); + e = 1; + break; +out: + if (fd != -1) + close(fd); + share[SYNC] = 0; + usleep(100); + } +#if defined(DEBUG) + if (e != 0) { + system("ps -Uroot | grep -v grep | grep /tmp/exlock2 | "\ + "awk '{print $1}' | xargs procstat -f"); + } +#endif + share[SYNC] = 0; + + _exit(e); +} + +int +main(void) +{ + pid_t pid1, pid2; + size_t len; + int e, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + snprintf(file, sizeof(file), "/tmp/exlock2.%d.file", getpid()); + if ((pid1 = fork()) == 0) + test1(); + if (pid1 == -1) + err(1, "fork()"); + + if ((pid2 = fork()) == 0) + test2(); + if (pid2 == -1) + err(1, "fork()"); + + if (waitpid(pid2, &status, 0) != pid2) + err(1, "waitpid(%d)", pid2); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pid2, WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + kill(pid1, SIGHUP); + if (waitpid(pid1, &status, 0) != pid1) + err(1, "waitpid(%d)", pid1); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pid1, WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + + return (e); +} diff --git a/tools/test/stress2/misc/ext2fs.sh b/tools/test/stress2/misc/ext2fs.sh new file mode 100755 index 000000000000..f4d33116faed --- /dev/null +++ b/tools/test/stress2/misc/ext2fs.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Deadlock seen: http://people.freebsd.org/~pho/stress/log/ext2fs.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# Uses mke2fs from sysutils/e2fsprogs +[ -z "`type mke2fs 2>/dev/null`" ] && + echo "Skipping test as mke2fs not installed" && exit 0 + +mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +mke2fs -m 0 /dev/md$mdstart > /dev/null + +mount -t ext2fs /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done + +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/ext2fs2.sh b/tools/test/stress2/misc/ext2fs2.sh new file mode 100755 index 000000000000..a576c582cc7e --- /dev/null +++ b/tools/test/stress2/misc/ext2fs2.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "panic: ext2_dirbad: /mnt: bad dir ino ...: mangled entry" seen. +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191895 + +. ../default.cfg + +# Uses mke2fs from sysutils/e2fsprogs +[ -x /usr/local/sbin/mke2fs ] || exit 0 +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 +mke2fs /dev/md${mdstart}a +# No panic seen when disabling hashed b-tree lookup for large directories +# tune2fs -O ^dir_index /dev/md${mdstart}$part +mount -t ext2fs /dev/md${mdstart}$part $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 +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/ext2fs3.sh b/tools/test/stress2/misc/ext2fs3.sh new file mode 100755 index 000000000000..f33b4cc73547 --- /dev/null +++ b/tools/test/stress2/misc/ext2fs3.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# ext2fs(5) test scenario with a 1k block size +# "panic: ext2_reallocblks: alloc mismatch" seen. +# "Fatal trap 12: page fault while in kernel mode" seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -r /usr/src/tools/regression/fsx/fsx.c ] || exit 0 + +. ../default.cfg + +# Uses mke2fs from sysutils/e2fsprogs +[ -z "`type mke2fs 2>/dev/null`" ] && + echo "Skipping test as mke2fs not installed" && exit 0 + +dir=/tmp +odir=`pwd` +cd $dir +cc -o fsx -Wall -Wextra -O2 -g /usr/src/tools/regression/fsx/fsx.c || exit 1 +rm -f fsx.c +cd $odir + +mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +mke2fs -m 0 -b 1024 /dev/md$mdstart > /dev/null + +mount -t ext2fs /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +cp /tmp/fsx $mntpoint +cd $mntpoint +./fsx -S 2016 -N 2000 ./TEST_FILE +cd $here + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done + +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/ext3fs.sh b/tools/test/stress2/misc/ext3fs.sh new file mode 100755 index 000000000000..826317857f85 --- /dev/null +++ b/tools/test/stress2/misc/ext3fs.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Simple ext3 test. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# Uses mke2fs from sysutils/e2fsprogs +[ -z "`type mke2fs 2>/dev/null`" ] && + echo "Skipping test as mke2fs not installed" && exit 0 + +mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +mke2fs -t ext3 -m 0 -b 2048 /dev/md$mdstart > /dev/null + +mount -t ext2fs /dev/md$mdstart $mntpoint || exit 1 +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' & +sleep 300 +../tools/killall.sh +wait + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done + +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/ext4fs.sh b/tools/test/stress2/misc/ext4fs.sh new file mode 100755 index 000000000000..610351352501 --- /dev/null +++ b/tools/test/stress2/misc/ext4fs.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Simple ext4 test. + +# "panic: buf_vlist_add: Preallocated nodes insufficient" seen: +# https://people.freebsd.org/~pho/stress/log/mjguzik036.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# Uses mke2fs from sysutils/e2fsprogs +[ -z "`type mke2fs 2>/dev/null`" ] && + echo "Skipping test as mke2fs not installed" && exit 0 + +mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +mke2fs -t ext4 -m 0 -b 2048 /dev/md$mdstart > /dev/null + +mount -t ext2fs /dev/md$mdstart $mntpoint || exit 1 +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' & +sleep 300 +../tools/killall.sh +wait + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done + +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/extattr.sh b/tools/test/stress2/misc/extattr.sh new file mode 100755 index 000000000000..31027eec696b --- /dev/null +++ b/tools/test/stress2/misc/extattr.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. +# + +# 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 +[ -z "`which setfacl`" ] && exit 0 + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > extattr.c +mycc -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 $mntpoint +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/tools/test/stress2/misc/extattr2.sh b/tools/test/stress2/misc/extattr2.sh new file mode 100755 index 000000000000..313d4ea26447 --- /dev/null +++ b/tools/test/stress2/misc/extattr2.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# [Bug 230962] Kernel panic when writing extended attributes with soft updates +# enabled. +# "panic: softdep_deallocate_dependencies: dangling deps" seen: +# https://people.freebsd.org/~pho/stress/log/kostik1121.txt +# Fixed in r343536. +# "panic: ffs_truncate3" seen: +# https://people.freebsd.org/~pho/stress/log/extattr2.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg +[ -z "`which setfacl`" ] && exit 0 + +here=`pwd` +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 2g -u $mdstart +bsdlabel -w md$mdstart auto + +newfs $newfs_flags 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 $mntpoint +tunefs -a enable /dev/md${mdstart}$part +mount /dev/md${mdstart}$part $mntpoint +mount | grep md${mdstart}$part + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX +if [ `jot -r 1 0 1` -eq 1 ]; then + set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` + export KBLOCKS=$(($1 / 2)) + export INODES=$(($2 / 2)) +fi + +mkdir -p $RUNDIR +chmod 0777 $RUNDIR +setfacl -b $RUNDIR +setfacl -m user:$testuser:rwx,group:$testuser:rwx $RUNDIR +su $testuser -c "cd $here/..; ./run.sh marcus.cfg" & + +sleep 5 +while pgrep -U$testuser -q -f run.sh; do + find $RUNDIR | \ + xargs -P0 -J% setfacl -m user:$testuser:rwx,group:$testuser:rwx % +done > /dev/null 2>&1 +wait + +s=0 +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FAIL; fstat -mf $mntpoint; exit 1; } +done +checkfs /dev/md${mdstart}$part || s=1 +mdconfig -d -u $mdstart || s=2 +exit $s diff --git a/tools/test/stress2/misc/extattr3.sh b/tools/test/stress2/misc/extattr3.sh new file mode 100755 index 000000000000..84b5e1821473 --- /dev/null +++ b/tools/test/stress2/misc/extattr3.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Bug 230962 Kernel panic when writing extended attributes with soft updates +# "panic: softdep_disk_write_complete: softdep_bp_to_mp returned NULL with +# outstanding dependencies" seen. + +# Original test scenario by Koro + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg +[ -z "`which setfacl`" ] && exit 0 + +here=`pwd` +mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 512m -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +tunefs -a enable /dev/md$mdstart +mount /dev/md$mdstart $mntpoint +setfacl -d -m u::rwx,g::rx,o::,u:nobody:r $mntpoint + +timeout 2s nc -lU $mntpoint/socket + +s=0 +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FAIL; fstat -mf $mntpoint; exit 1; } +done +checkfs /dev/md$mdstart || s=1 +mdconfig -d -u $mdstart || s=2 +exit $s diff --git a/tools/test/stress2/misc/extattr_set_fd.sh b/tools/test/stress2/misc/extattr_set_fd.sh new file mode 100755 index 000000000000..22bfa52f4813 --- /dev/null +++ b/tools/test/stress2/misc/extattr_set_fd.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# "panic: kmem_malloc(2069012480): kmem_map too small" seen. +# Fixed in r237366. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg +[ -z "`which setfacl`" ] && exit 0 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > extattr_set_fd.c +mycc -o extattr_set_fd -Wall -Wextra -O2 extattr_set_fd.c +rm -f extattr_set_fd.c + +mount | grep -q "$mntpoint" && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +(cd $mntpoint; /tmp/extattr_set_fd) + +while mount | grep -q $mntpoint; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/extattr_set_fd +exit 0 +EOF +#include +#include +#include +#include +#include + +char buf[4096]; + +int +main(void) +{ + int fd; + + if ((fd = open("theFile", O_RDWR | O_CREAT, 0622)) == -1) + err(1, "open(%s)", "theFile"); + + (void) extattr_set_fd(fd, 1, "test", buf, 0x7b5294a6); + + return (0); +} diff --git a/tools/test/stress2/misc/extattrctl.sh b/tools/test/stress2/misc/extattrctl.sh new file mode 100755 index 000000000000..dad79023a2fc --- /dev/null +++ b/tools/test/stress2/misc/extattrctl.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. +# + +# 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 -in kern.features.ufs_extattr`" != "1" ] && + { echo "Kernel not build with UFS_EXTATTR"; exit 0; } +[ -z "`which setfacl`" ] && exit 0 + +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 $mntpoint +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/tools/test/stress2/misc/f_offset.sh b/tools/test/stress2/misc/f_offset.sh new file mode 100755 index 000000000000..746f14bea265 --- /dev/null +++ b/tools/test/stress2/misc/f_offset.sh @@ -0,0 +1,160 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Problem seen with atomic assignment of f_offset. Fixed in r238029. + +# Test scenario by kib@ + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > f_offset.c +mycc -o f_offset -Wall -Wextra -O2 f_offset.c -lpthread +rm -f f_offset.c + +/tmp/f_offset + +rm -f /tmp/f_offset +exit 0 +EOF +/* + Description by kib: +To really exercise the race conditions, all the following items must +be fulfilled simultaneously: +1. you use 32bit host, i.e. i386 +2. you operate on the file offsets larger than 4GB (but see below) +3. there are several threads or processes that operate on the same + file descriptor simultaneously. + +Please note that the normal fork(2) causes file descriptor table +copy, so only rfork(2) call with RFFDG flag unset causes sharing. Or, +multi-threading can be used. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +int errors, fd; +char file[128]; + +#define START 0x100000000ULL +#define N 1000000 + +void * +t1(void *arg __unused) +{ + int i; + off_t offset; + + offset = START + 2; + + for (i = 0; i < N; i++) { + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek error"); + } + + return (0); +} + +void * +t2(void *arg __unused) +{ + int i; + off_t offset; + + offset = 1; + + for (i = 0; i < N; i++) { + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek error"); + } + return (0); +} +void * +t3(void *arg __unused) +{ + int i; + off_t offset; + + offset = 1; + + for (i = 0; i < N; i++) { + if ((offset = lseek(fd, 0, SEEK_CUR)) == -1) + err(1, "lseek error"); + if (offset != 1 && offset != START + 2) + fprintf(stderr, "FAIL #%d offset = %10jd (0x%09jx)\n", + errors++, offset, offset); + } + + return (0); +} + +int +main(void) +{ + pthread_t threads[3]; + int r; + int i; + off_t offset; + + snprintf(file, sizeof(file), "file.%06d", getpid()); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) + err(1, "%s", file); + + offset = 1; + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek error"); + + for (i = 0; i < 20 && errors < 10; i++) { + if ((r = pthread_create(&threads[0], NULL, t1, 0)) != 0) + errc(1, r, "pthread_create()"); + if ((r = pthread_create(&threads[1], NULL, t2, 0)) != 0) + errc(1, r, "pthread_create()"); + if ((r = pthread_create(&threads[2], NULL, t3, 0)) != 0) + errc(1, r, "pthread_create()"); + + if ((r = pthread_join(threads[0], NULL)) != 0) + errc(1, r, "pthread_join(%d)", 0); + if ((r = pthread_join(threads[1], NULL)) != 0) + errc(1, r, "pthread_join(%d)", 1); + if ((r = pthread_join(threads[2], NULL)) != 0) + errc(1, r, "pthread_join(%d)", 2); + } + close(fd); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + return (0); +} diff --git a/tools/test/stress2/misc/fcntl.sh b/tools/test/stress2/misc/fcntl.sh new file mode 100755 index 000000000000..ccbcc45a325f --- /dev/null +++ b/tools/test/stress2/misc/fcntl.sh @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# fcntl(2) locking scenario. No problems seen. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > fcntl.c +mycc -o fcntl -Wall -Wextra -O0 -g fcntl.c || exit 1 +rm -f fcntl.c + +mkdir -p $RUNDIR +cd $RUNDIR +/tmp/fcntl +status=$? + +rm -f /tmp/fcntl +exit $status +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 16 +#define N 4096 + +static volatile sig_atomic_t completed; +const char name[] = "work"; +int fd; + +static void +ahandler(int s __unused) +{ + unlink(name); + _exit(1); +} + +static void +handler(int s __unused) +{ + completed++; +} + +void +add(int n, int increment) +{ + struct flock fl; + off_t pos; + long val, oval; + int r; + + pos = n * sizeof(val); + memset(&fl, 0, sizeof(fl)); + fl.l_start = pos; + fl.l_len = sizeof(val); + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + + while (fcntl(fd, F_SETLK, &fl) < 0) { + if (errno != EAGAIN) + err(1, "F_SETLK (child)"); + usleep(100); + } + + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + oval = 999999; + while ((r = read(fd, &val, sizeof(val)) != sizeof(val))) { + if (r == -1 && errno != EAGAIN) + err(1, "read"); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + } + oval = val; + val = val + increment; +#if defined(DEBUG) + fprintf(stderr, "add(%d, %d) @ pos %ld: %ld = %ld + %d\n", + n, increment, (long)pos, val, oval, increment); +#endif + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + while ((r = write(fd, &val, sizeof(val)) != sizeof(val))) { + if (r == -1 && errno != EAGAIN) + err(1, "write"); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + } + + fl.l_type = F_UNLCK; + if (fcntl(fd, F_SETLK, &fl) < 0) + err(1, "F_UNLCK"); + +} + +void +up(void) +{ + int flags, i; + + /* Need to re-open after a fork() */ + close(fd); + if ((fd = open(name, O_RDWR)) == -1) + err(1, "open(%s)", name); + if ((flags = fcntl(fd, F_GETFL)) == -1) + err(1, "fcntl(%d, T_GETFL)", fd); + flags |= O_NONBLOCK; + if ((flags = fcntl(fd, F_SETFL, flags)) == -1) + err(1, "fcntl(%d, T_SETFL, %d)", fd, flags); + + for (i = 0; i < N; i++) + add(i, 1); + + kill(getppid(), SIGHUP); + while (access("work", R_OK) == 0) + usleep(100); + + _exit(0); +} + +void +down(void) +{ + int flags, i; + + close(fd); + if ((fd = open(name, O_RDWR)) == -1) + err(1, "open(%s)", name); + if ((flags = fcntl(fd, F_GETFL)) == -1) + err(1, "fcntl(%d, T_GETFL)", fd); + flags |= O_NONBLOCK; + if ((flags = fcntl(fd, F_SETFL, flags)) == -1) + err(1, "fcntl(%d, T_SETFL, %d)", fd, flags); + + for (i = 0; i < N; i++) + add(i, -1); + + kill(getppid(), SIGHUP); + while (access("work", R_OK) == 0) + usleep(100); + + _exit(0); +} + +int +main(void) +{ + int flags, i; + long val, sum; + off_t len; + + signal(SIGHUP, handler); + signal(SIGALRM, ahandler); + alarm(300); + if ((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) + err(1, "open(%s)", name); + len = N * sizeof(val); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate"); + + if ((flags = fcntl(fd, F_GETFL)) == -1) + err(1, "fcntl(%d, T_GETFL)", fd); + flags |= O_NONBLOCK; + if ((flags = fcntl(fd, F_SETFL, flags)) == -1) + err(1, "fcntl(%d, T_SETFL, %d)", fd, flags); + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + up(); + } + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + down(); + } + + while (completed != PARALLEL * 2) + usleep(200); + + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + sum = 0; + for (i = 0; i < N; i++) { + if (read(fd, &val, sizeof(val)) != sizeof(val)) + err(1, "Final read"); + if (val != 0) + fprintf(stderr, "index %d: %ld\n", i, val); + sum += val; + } + if (sum != 0) + fprintf(stderr, "FAIL\n"); + unlink(name); + + for (i = 0; i < PARALLEL; i++) { + wait(NULL); + wait(NULL); + } + + close(fd); + + return (sum != 0); +} diff --git a/tools/test/stress2/misc/fcntl2.sh b/tools/test/stress2/misc/fcntl2.sh new file mode 100755 index 000000000000..5f276ae81ccc --- /dev/null +++ b/tools/test/stress2/misc/fcntl2.sh @@ -0,0 +1,188 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# fcntl(2) fuzz +# "umount: unmount of /mnt failed: Device busy" seen: +# https://people.freebsd.org/~pho/stress/log/fcntl2.txt + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/fcntl2.c +mycc -o fcntl2 -Wall -Wextra -O0 -g fcntl2.c || exit 1 +rm -f fcntl2.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +(cd $odir/../testcases/swap; ./swap -t 3m -i 20) & +cd $mntpoint +limits -n 10000 $dir/fcntl2 +s=$? +[ -f fcntl2.core -a $s -eq 0 ] && + { ls -l fcntl2.core; mv fcntl2.core $dir; s=1; } +cd $odir +while pkill swap; do :; done + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/fcntl2 +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#define PARALLEL 64 +#define RUNTIME (3 * 60) +#define SYNC 0 + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +static u_int32_t r[N]; + +static unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return (val); +} +static void +test(void) +{ + time_t start; + unsigned long arg3; + int cmd, fd, i, n, success; + char file[80]; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + success = 0; + snprintf(file, sizeof(file), "file.%d", getpid()); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE)) + == -1) + err(1, "open(%s)", file); + n = arc4random() % 100 + 1; + for (i = 0; i < n; i++) + if (write(fd, file, sizeof(file)) != sizeof(file)) + err(1, "write()"); + start = time(NULL); + while (time(NULL) - start < 60) { + cmd = arc4random() % 20; + arg3 = makearg(); + alarm(20); + if (fcntl(fd, cmd, arg3) != -1) + success++; + alarm(0); + } + close(fd); + unlink(file); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int i, status; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + for (i = 0; i < N; i++) + r[i] = arc4random(); + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + } + } + + return (0); +} diff --git a/tools/test/stress2/misc/fcntl3.sh b/tools/test/stress2/misc/fcntl3.sh new file mode 100755 index 000000000000..8892a9d5670b --- /dev/null +++ b/tools/test/stress2/misc/fcntl3.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Mark Johnston +# +# 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 scenario submitted by Mark Johnston + +# "Fatal trap 18: integer divide fault while in kernel mode" seen. +# Reported by syzkaller +# Fixed by r353010 + +cat > /tmp/fcntl3.c < +#include +#include + +int +main(void) +{ + + if (fcntl(STDIN_FILENO, F_RDAHEAD) != 0) + err(1, "fcntl"); + return (0); +} +EOF +cc -o /tmp/fcntl3 -Wall -Wextra -O2 /tmp/fcntl3.c || exit 1 + +echo "Expect: fcntl3: fcntl: Inappropriate ioctl for device" +/tmp/fcntl3 + +rm -f /tmp/fcntl3 /tmp/fcntl3.c +exit 0 diff --git a/tools/test/stress2/misc/fdatasync.sh b/tools/test/stress2/misc/fdatasync.sh new file mode 100755 index 000000000000..f17e2826ad94 --- /dev/null +++ b/tools/test/stress2/misc/fdatasync.sh @@ -0,0 +1,197 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# fdatasync(2) fuzz. + +# Deadlock seen: +# https://people.freebsd.org/~pho/stress/log/fdatasync.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=$RUNDIR +nfiles=500 +[ `df -i $dir | tail -1 | awk '{print $7}'` -lt $nfiles ] && exit 0 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fdatasync.c +rm -f /tmp/fdatasync +mycc -o fdatasync -Wall -Wextra -O2 -g fdatasync.c -lpthread || exit 1 +rm -f fdatasync.c + +mkdir -p $dir && chmod 777 $dir + +cd $dir +jot $nfiles | xargs touch +jot $nfiles | xargs chmod 666 +cd $odir + +(cd /tmp; /tmp/fdatasync $dir) +e=$? + +rm -rf $dir/* /tmp/fdatasync +exit $e +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define RUNTIME 180 +#define THREADS 2 + +static int fd[900]; +static u_int32_t r[N]; +static char *args[2]; + +static unsigned long +makearg(void) +{ + unsigned long val; + + val = arc4random(); +#if defined(__LP64__) + val = (val << 32) | arc4random(); + val = val & 0x00007fffffffffffUL; +#endif + + return(val); +} + +static void * +test(void *arg __unused) +{ + FTS *fts; + FTSENT *p; + int ftsoptions, i, n; + + ftsoptions = FTS_PHYSICAL; + + for (;;) { + for (i = 0; i < N; i++) + r[i] = arc4random(); + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + i = n = 0; + while ((p = fts_read(fts)) != NULL) { + if (fd[i] > 0) + close(fd[i]); + if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) + if ((fd[i] = open(p->fts_path, O_WRONLY)) == + -1) + continue; + if (ftruncate(fd[i], 0) != 0) + err(1, "ftruncate"); + i++; + i = i % nitems(fd); + } + + if (fts_close(fts) == -1) + err(1, "fts_close()"); + sleep(1); + } + return(0); +} + +static void * +calls(void *arg __unused) +{ + off_t offset; + time_t start; + int fd2; + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + fd2 = makearg() % nitems(fd) + 3; + offset = makearg(); + if (lseek(fd2, offset - 1, SEEK_SET) != -1) { + if (write(fd2, "x", 1) != 1) + if (errno != EBADF && errno != ENOSPC && + errno != E2BIG && errno != ESTALE && + errno != EFBIG) + warn("write"); + } else + if (errno != EBADF) + warn("lseek"); + if (fdatasync(fd2) == -1) + if (errno != EBADF) + warn("x"); + + } + + return (0); +} + +int +main(int argc, char **argv) +{ + struct passwd *pw; + pthread_t rp, cp[THREADS]; + int e, i; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + args[0] = argv[1]; + args[1] = 0; + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "failed to resolve nobody"); + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) + errc(1, e, "pthread_create"); + usleep(1000); + for (i = 0; i < THREADS; i++) + if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) + errc(1, e, "pthread_create"); + for (i = 0; i < THREADS; i++) + pthread_join(cp[i], NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/fdatasync2.sh b/tools/test/stress2/misc/fdatasync2.sh new file mode 100755 index 000000000000..6011eba53698 --- /dev/null +++ b/tools/test/stress2/misc/fdatasync2.sh @@ -0,0 +1,196 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# fdatasync(2) fuzz. Variation of fdatasync.sh. +# https://people.freebsd.org/~pho/stress/log/fdatasync2.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=$RUNDIR +nfiles=10000 +[ `df -i $dir | tail -1 | awk '{print $7}'` -lt $nfiles ] && exit 0 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fdatasync2.c +rm -f /tmp/fdatasync2 +mycc -o fdatasync2 -Wall -Wextra -O2 -g fdatasync2.c -lpthread || exit 1 +rm -f fdatasync2.c + +mkdir -p $dir && chmod 777 $dir + +cd $dir +jot $nfiles | xargs touch +jot $nfiles | xargs chmod 666 +cd $odir + +(cd /tmp; /tmp/fdatasync2 $dir) +e=$? + +rm -rf $dir/* /tmp/fdatasync2 +exit $e +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define RUNTIME 180 +#define THREADS 6 + +static int fd[900]; +static u_int32_t r[N]; +static char *args[2]; + +static unsigned long +makearg(void) +{ + unsigned long val; + + val = arc4random(); +#if defined(__LP64__) + val = (val << 32) | arc4random(); + val = val & 0x00007fffffffffffUL; +#endif + + return(val); +} + +static void * +test(void *arg __unused) +{ + FTS *fts; + FTSENT *p; + int ftsoptions, i, n; + + ftsoptions = FTS_PHYSICAL; + + for (;;) { + for (i = 0; i < N; i++) + r[i] = arc4random(); + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + i = n = 0; + while ((p = fts_read(fts)) != NULL) { + if (fd[i] > 0) + close(fd[i]); + if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) + if ((fd[i] = open(p->fts_path, O_WRONLY)) == + -1) + continue; + if (ftruncate(fd[i], 0) != 0) + err(1, "ftruncate"); + i++; + i = i % nitems(fd); + } + + if (fts_close(fts) == -1) + err(1, "fts_close()"); + sleep(1); + } + return(0); +} + +static void * +calls(void *arg __unused) +{ + off_t offset; + time_t start; + int fd2; + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + fd2 = makearg() % nitems(fd) + 3; + offset = makearg(); + if (lseek(fd2, offset - 1, SEEK_SET) != -1) { + if (write(fd2, "x", 1) != 1) + if (errno != EBADF && errno != ENOSPC && + errno != E2BIG && errno != ESTALE && + errno != EFBIG) + warn("write"); + } else + if (errno != EBADF) + warn("lseek"); + if (fdatasync(fd2) == -1) + if (errno != EBADF) + warn("x"); + + } + + return (0); +} + +int +main(int argc, char **argv) +{ + struct passwd *pw; + pthread_t rp, cp[THREADS]; + int e, i, threads; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + args[0] = argv[1]; + args[1] = 0; + threads = arc4random() % (THREADS -1 ) + 2; /* 2 - THREADS */ + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "failed to resolve nobody"); + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) + errc(1, e, "pthread_create"); + usleep(1000); + for (i = 0; i < threads; i++) + if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) + errc(1, e, "pthread_create"); + for (i = 0; i < threads; i++) + pthread_join(cp[i], NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/fdescfs.sh b/tools/test/stress2/misc/fdescfs.sh new file mode 100755 index 000000000000..b0f07e34b285 --- /dev/null +++ b/tools/test/stress2/misc/fdescfs.sh @@ -0,0 +1,74 @@ +#!/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. +# + +# Page fault seen in fdesc_allocvp+0x8f: +# http://people.freebsd.org/~pho/stress/log/fdescfs-2.txt +# Fixed by r279401 +# https://people.freebsd.org/~pho/stress/log/fdescfs-3.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +cont=/tmp/fdescfs.continue + +if [ $# -eq 0 ]; then + kldstat -v | grep -q fdescfs || { kldload fdescfs.ko; unload=1; } + touch $cont + # start the parallel tests + for i in `jot $mounts`; do + [ -d ${mntpoint}$i ] || mkdir -p ${mntpoint}$i + ./$0 $i & + ./$0 find & + done + wait + [ $unload ] && kldunload fdescfs.ko + exit 0 +else + if [ $1 = find ]; then + exec 6< /dev/zero + exec 7< /dev/zero + exec 8< /dev/zero + exec 9< /dev/zero + while [ -r $cont ]; do + ls -l ${mntpoint}* > /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ `date '+%s'` -lt $((start + 300)) ]; do + mount -t fdescfs null ${mntpoint}$1 + while mount | grep -wq ${mntpoint}$1; do + umount -f ${mntpoint}$1 > /dev/null 2>&1 + done + done + rm -f $cont + fi +fi diff --git a/tools/test/stress2/misc/fdgrowtable.sh b/tools/test/stress2/misc/fdgrowtable.sh new file mode 100755 index 000000000000..b75094489412 --- /dev/null +++ b/tools/test/stress2/misc/fdgrowtable.sh @@ -0,0 +1,105 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Regression test for r236822. +# http://people.freebsd.org/~pho/stress/log/fdgrowtable.txt +# Fixed in r256210. + +. ../default.cfg + +max=`ulimit -n` + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > fdgrowtable.c +mycc -o fdgrowtable -Wall -Wextra -O2 fdgrowtable.c || exit 1 +rm -f fdgrowtable.c +cd $here + +su $testuser -c "/tmp/fdgrowtable $max" & +while kill -0 $! 2>/dev/null; do + ../testcases/swap/swap -t 2m -i 40 -h +done +wait +rm -f /tmp/fdgrowtable +exit + +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 3 + +int max; + +void test(void) +{ + int i; + + for (i = 0; i < max; i++) { + if (dup2(1, i + 3) == -1) + err(1, "dup2(%d)", i + 3); + } + _exit(0); +} + +int +main(int argc, char **argv) +{ + time_t start; + int i; + + if (argc == 2) + max = atoi(argv[1]); + else + err(1, "Usage: %s ", argv[0]); + + max = (max - 3) / PARALLEL; + + start = time(NULL); + while (time(NULL) - start < 600) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + test(); + } + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/fexecve.sh b/tools/test/stress2/misc/fexecve.sh new file mode 100755 index 000000000000..01ff0b723134 --- /dev/null +++ b/tools/test/stress2/misc/fexecve.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Reported by syzkaller. +# "panic: vm_page_free_prep: page 0x61e5968 has unexpected ref_count ." seen +# Fixed by r352748 + +# Test scenario by: Mark Johnston + +cat > /tmp/fexecve.c < +#include +#include + +#include +#include +#include +#include +#include + +int +main(int argc __unused, char **argv) +{ + char template[PATH_MAX]; + void *addr; + size_t sz; + int fd; + + sz = 16 * 4096; + + (void)snprintf(template, sizeof(template), "fexecve.XXXXXX"); + fd = mkstemp(template); + if (fd < 0) + err(1, "mkstemp"); + if (fchmod(fd, 0700) < 0) + err(1, "fchmod"); + if (ftruncate(fd, sz) < 0) + err(1, "ftruncate"); + + addr = mmap(NULL, sz, PROT_MAX(PROT_READ) | PROT_READ, MAP_SHARED, + fd, 0); + if (addr == MAP_FAILED) + err(1, "mmap"); + + if (mlock(addr, sz) != 0) + err(1, "mlock"); + + if (ftruncate(fd, 0) != 0) + err(1, "ftruncate"); + if (ftruncate(fd, sz) != 0) + err(1, "ftruncate"); + + (void)close(fd); + + fd = open(template, O_EXEC); + if (fd < 0) + err(1, "open"); + fexecve(fd, argv, NULL); + err(1, "fexecve"); + + return (0); +} +EOF +cc -o /tmp/fexecve -Wall -Wextra -O2 /tmp/fexecve.c || exit 1 +echo "Expect: fexecve: fexecve: Input/output error" +(cd /tmp; /tmp/fexecve) + +rm -f /tmp/fexecve /tmp/fexecve.c /tmp/fexecve.?????? diff --git a/tools/test/stress2/misc/ffs_blkfree.sh b/tools/test/stress2/misc/ffs_blkfree.sh new file mode 100755 index 000000000000..5ea4828429c3 --- /dev/null +++ b/tools/test/stress2/misc/ffs_blkfree.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +DUMP=$RUNDIR/dump +trap "rm -f $D" EXIT INT +dd if=/dev/zero of=$D bs=1m count=1024 status=none || 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +mount + +for i in `jot 10`; do + mkdir $mntpoint/d$i + for j in `jot 100`; do + touch $mntpoint/d$i/f$j + done +done + +dump -L0a -f $DUMP /dev/md${mdstart}$part + +ls -lf $DUMP + +while mount | grep -q $mntpoint; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && + echo "-f" || echo "") $mntpoint > /dev/null 2>&1 +done + +for i in `jot 10`; do + newfs $newfs_flags -n md${mdstart}$part > /dev/null + mount /dev/md${mdstart}$part $mntpoint + (cd $mntpoint; restore -rf $DUMP) + rm -rf $mntpoint/* + while mount | grep -q $mntpoint; do + umount $([ $((`date '+%s'` % 2)) -eq 0 ] && + echo "-f" || echo "") $mntpoint > /dev/null 2>&1 + done +done + +mdconfig -d -u $mdstart +rm -f $D $DUMP diff --git a/tools/test/stress2/misc/ffs_sync.sh b/tools/test/stress2/misc/ffs_sync.sh new file mode 100755 index 000000000000..aa970839c7b3 --- /dev/null +++ b/tools/test/stress2/misc/ffs_sync.sh @@ -0,0 +1,254 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "ffs_fsync: dirty" seen: +# http://people.freebsd.org/~pho/stress/log/ffs_sync.txt + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > ffs_sync.c +mycc -o ffs_sync -Wall -Wextra ffs_sync.c || exit 1 +rm -f ffs_sync.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 4g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +for i in `jot 3`; do + su $testuser -c "cd $mntpoint; /tmp/ffs_sync" & + sleep 60 + killall -q ffs_sync + killall -q ffs_sync +done + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +rm -f /tmp/ffs_sync +mdconfig -d -u $mdstart +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 12 +#define NRW 1000 +#define NFTS 10000 +#define NMKDIR 6000 +#define NSYMLINK 20000 + +void +slinktest(void) +{ + int i, j; + pid_t pid; + char file[128]; + + setproctitle("slink"); + pid = getpid(); + for (j = 0; j < NSYMLINK; 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__); + } + } + + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + } + + _exit(0); +} + +void +mktest(void) +{ + int i; + char path[80]; + + setproctitle("mkdir"); + sprintf(path, "d%06d", getpid()); + if (mkdir(path, 0770) == -1) + err(1, "mkdir(%s)", path); + chdir(path); + + sprintf(path, "d"); + for (i = 0; i < NMKDIR; i++) { + if (mkdir(path, 0770) == -1) { + warn("mkdir(%s), %s:%d", path, __FILE__, __LINE__); + } else + chdir(path); + + } + for (i = 0; i < NMKDIR; i++) { + chdir(".."); + rmdir(path); + } + chdir(".."); + + _exit(0); +} + +void +rwtest(void) +{ + int fd, i, j; + char buf[80], file[80]; + + setproctitle("rw"); + for (i = 0; i < NRW; i++) { + sprintf(file, "f%06d.%06d", getpid(), i); + if ((fd = open(file, O_CREAT | O_EXCL, 0644)) == -1) + err(1, "open(%s)", file); + for (j = 0; j < 1024; j++) + write(fd, buf, sizeof(buf)); + lseek(fd, 0, SEEK_SET); + for (j = 0; j < 1024; j++) + read(fd, buf, sizeof(buf)); + close(fd); + } + for (i = 0; i < NRW; i++) { + sprintf(file, "f%06d.%06d", getpid(), i); + if (unlink(file) == -1) + warn("unlink(%s)", file); + } + _exit(0); +} + +void +slink(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + slinktest(); +} + +void +mk(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + mktest(); +} + +void +rw(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + rwtest(); +} + +void +ftstest(void) +{ + FTS *fts; + FTSENT *p; + int ftsoptions, i; + char *args[2]; + + setproctitle("fts"); + ftsoptions = FTS_PHYSICAL; + args[0] = "."; + args[1] = 0; + + for (i = 0; i < NFTS; i++) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) + ; + + if (errno != 0 && errno != ENOENT) + err(1, "fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } + + _exit(0); +} + +void +fts(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + ftstest(); +} + +int +main(void) +{ + int i; + + slink(); + mk(); + rw(); + fts(); + + for (i = 0; i < PARALLEL; i++) { + wait(NULL); + wait(NULL); + wait(NULL); + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/ffs_syncvnode.sh b/tools/test/stress2/misc/ffs_syncvnode.sh new file mode 100755 index 000000000000..faa9856a8bca --- /dev/null +++ b/tools/test/stress2/misc/ffs_syncvnode.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# "panic: flush_newblk_deps: Bad newblk 0xc8d2ac00" seen. + +# "panic: softdep_deallocate_dependencies: dangling deps" seen with +# /mnt: out of inodes. 20130627. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +find -x / -type f > /dev/null 2>&1 & +su $testuser -c 'cd ..; ./run.sh disk.cfg' +wait + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/ffs_syncvnode2.sh b/tools/test/stress2/misc/ffs_syncvnode2.sh new file mode 100755 index 000000000000..5fd9e4cfe843 --- /dev/null +++ b/tools/test/stress2/misc/ffs_syncvnode2.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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. +# + +# Lock seen with: +# 1001 61985 61981 0 52 0 9624 1028 ufs D+ 0 0:22,89 mkdir +# 1001 61986 61981 0 52 0 9624 1028 ufs D+ 0 0:21,63 mkdir +# 1001 61987 61981 0 52 0 9624 1028 ufs D+ 0 0:23,39 mkdir + +# Fixed in rxxxxxx. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 * 4)) +export INODES=$(($2 * 4)) + +su $testuser -c 'cd ..; ./run.sh disk.cfg' 2>/dev/null + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/fifo.sh b/tools/test/stress2/misc/fifo.sh new file mode 100755 index 000000000000..17881bd9eb00 --- /dev/null +++ b/tools/test/stress2/misc/fifo.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Page fault seen. +# http://people.freebsd.org/~pho/stress/log/kostik652.txt +# Fixed by r259522. + +# https://people.freebsd.org/~pho/stress/log/kostik863.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fifo.c +rm -f /tmp/fifo +mycc -o fifo -Wall -Wextra -O2 -g fifo.c || exit 1 +rm -f fifo.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +(cd $mntpoint; /tmp/fifo) + +for i in `jot 10`; do + mount | grep -q md${mdstart}$part && \ + umount $mntpoint && mdconfig -d -u $mdstart && break + sleep 10 +done +rm -f /tmp/fifo +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(void) +{ + int fd; + + if (mkfifo("fifo", 0644) == -1) + err(1, "mkfifo"); + + fd = open("fifo", O_RDWR | O_SHLOCK | O_EXLOCK); + fd = open("fifo", 0x60e9f2, 0xc74c65b1db4be370, 0xb64a34df72368759); + + return (0); +} diff --git a/tools/test/stress2/misc/fifo2.sh b/tools/test/stress2/misc/fifo2.sh new file mode 100755 index 000000000000..7f269f2368d4 --- /dev/null +++ b/tools/test/stress2/misc/fifo2.sh @@ -0,0 +1,206 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Page fault seen +# http://people.freebsd.org/~pho/stress/log/kostik654.txt +# Fixed by r259521. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fifo2.c +rm -f /tmp/fifo2 +mycc -o fifo2 -Wall -Wextra -O2 -g fifo2.c -lpthread || exit 1 +rm -f fifo2.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint +mkfifo $mntpoint/f +chmod 777 $mntpoint/f + +sleeptime=12 +st=`date '+%s'` +while [ $((`date '+%s'` - st)) -lt $((10 * sleeptime)) ]; do + (cd $mntpoint; /tmp/fifo2) & + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt $sleeptime ]; do + pgrep -q fifo2 || break + sleep .5 + done + while pkill -9 fifo2; do :; done + wait +done + +for i in `jot 10`; do + mount | grep -q md${mdstart}$part && \ + umount $mntpoint > /dev/null 2>&1 && + mdconfig -d -u $mdstart && break + sleep 10 +done +s=0 +mount | grep -q md${mdstart}$part && + { echo "umount $mntpoint failed"; s=1; } +rm -f /tmp/fifo2 +exit $s +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +u_int32_t r[N]; + +static void +hand(int i __unused) { /* handler */ + _exit(1); +} + +static unsigned long +makearg(void) +{ + unsigned int i; + unsigned long val; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +static void * +calls(void *arg __unused) +{ + unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; + int i, num; + + for (i = 0;; i++) { + arg1 = (unsigned long)(void *)"f"; + arg2 = makearg(); + arg3 = makearg(); + arg4 = makearg(); + arg5 = makearg(); + arg6 = makearg(); + arg7 = makearg(); + +#if 0 + fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx, %lx, %lx)\n", + i, SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + usleep(100000); +#endif + alarm(1); + syscall(SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + num = 0; + } + + return (0); +} + +int +main(void) +{ + struct passwd *pw; + struct rlimit limit; + pthread_t cp[50]; + time_t start; + int e, j; + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + limit.rlim_cur = limit.rlim_max = 1000; + if (setrlimit(RLIMIT_NPTS, &limit) < 0) + err(1, "setrlimit"); + + signal(SIGALRM, hand); + signal(SIGILL, hand); + signal(SIGFPE, hand); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + signal(SIGURG, hand); + signal(SIGSYS, hand); + signal(SIGTRAP, hand); + + start = time(NULL); + while ((time(NULL) - start) < 120) { + if (fork() == 0) { + for (j = 0; j < 1; j++) + if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) + errc(1, e,"pthread_create"); + + for (j = 0; j < 1; j++) + pthread_join(cp[j], NULL); + _exit(0); + } + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/fifo3.sh b/tools/test/stress2/misc/fifo3.sh new file mode 100755 index 000000000000..04fca483eabf --- /dev/null +++ b/tools/test/stress2/misc/fifo3.sh @@ -0,0 +1,209 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Demonstrate that fts_read(3) will open a fifo for read. +# Not seen on a pristine FreeBSD. + +# $ while ./fifo.sh; do date; done +# Wed Oct 1 14:07:41 CEST 2014 +# Wed Oct 1 14:09:58 CEST 2014 +# FAIL +# $ ps -l19547 +# UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND +# 0 19547 19544 0 25 0 12176 3996 fifoor I 0 0:08.19 /tmp/fifo +# $ gdb /tmp/fifo 19547 +# GNU gdb 6.1.1 [FreeBSD] +# Copyright 2004 Free Software Foundation, Inc. +# GDB is free software, covered by the GNU General Public License, and you are +# welcome to change it and/or distribute copies of it under certain conditions. +# Type "show copying" to see the conditions. +# There is absolutely no warranty for GDB. Type "show warranty" for details. +# This GDB was configured as "amd64-marcel-freebsd"... +# Attaching to program: /tmp/fifo, process 19547 +# Reading symbols from /lib/libc.so.7...done. +# Loaded symbols for /lib/libc.so.7 +# Reading symbols from /libexec/ld-elf.so.1...done. +# Loaded symbols for /libexec/ld-elf.so.1 +# 0x00000008008a9ab8 in enc_openat () from /lib/libc.so.7 +# (gdb) bt +# #0 0x00000008008a9ab8 in enc_openat () from /lib/libc.so.7 +# #1 0x00000008008a581b in fts_read () from /lib/libc.so.7 +# #2 0x00000008008a4f24 in fts_read () from /lib/libc.so.7 +# #3 0x0000000000400ee9 in test () at /tmp/fifo.c:86 +# #4 0x0000000000400fd8 in main () at /tmp/fifo.c:108 +# (gdb) f 3 +# #3 0x0000000000400ee9 in test () at /tmp/fifo.c:86 +# 86 while ((p = fts_read(fts)) != NULL) { +# Current language: auto; currently minimal +# (gdb) +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +cat > /tmp/fifo3.c < +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 50 +#define PARALLEL 4 + +void +tmkfifo(void) +{ + pid_t pid; + int i, j; + char name[80]; + + setproctitle(__func__); + pid = getpid(); + for (j = 0; j < LOOPS; j++) { + for (i = 0; i < 1000; i++) { + snprintf(name, sizeof(name), "fifo.%d.%06d", pid, i); + if (mkfifo(name, 0644) == -1) + err(1, "mkfifo(%s)", name); + } + for (i = 0; i < 1000; i++) { + snprintf(name, sizeof(name), "fifo.%d.%06d", pid, i); + if (unlink(name) == -1) + err(1, "unlink(%s)", name); + } + } + _exit(0); +} + +void +tmkdir(void) +{ + pid_t pid; + int i, j; + char name[80]; + + setproctitle(__func__); + pid = getpid(); + for (j = 0; j < LOOPS; j++) { + for (i = 0; i < 1000; i++) { + snprintf(name, sizeof(name), "dir.%d.%06d", pid, i); + if (mkdir(name, 0644) == -1) + err(1, "mkdir(%s)", name); + } + for (i = 0; i < 1000; i++) { + snprintf(name, sizeof(name), "dir.%d.%06d", pid, i); + if (rmdir(name) == -1) + err(1, "unlink(%s)", name); + } + } + _exit(0); +} + +void +test(void) +{ + FTS *fts; + FTSENT *p; + int ftsoptions, i; + char *args[2]; + + if (fork() == 0) + tmkfifo(); + if (fork() == 0) + tmkdir(); + + ftsoptions = FTS_PHYSICAL; + args[0] = "."; + args[1] = 0; + + for (i = 0; i < LOOPS; i++) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { +#if defined(TEST) + fprintf(stdout, "%s\n", p->fts_path); +#endif + } + + if (errno != 0 && errno != ENOENT) + err(1, "fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } + wait(NULL); + wait(NULL); + + _exit(0); +} + +int +main(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + test(); + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} +EOF +mycc -o /tmp/fifo3 -Wall -Wextra -O0 -g /tmp/fifo3.c || exit 1 + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +(cd $mntpoint; /tmp/fifo3 ) & + +while pgrep -q fifo3; do + ps -lx | grep -v grep | grep -q fifoor && + { echo FAIL; exit 1; } + sleep 2 +done + +wait + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm /tmp/fifo3 /tmp/fifo3.c diff --git a/tools/test/stress2/misc/fifo4.sh b/tools/test/stress2/misc/fifo4.sh new file mode 100755 index 000000000000..7f46f8537dc6 --- /dev/null +++ b/tools/test/stress2/misc/fifo4.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# tmpfs(5) version of fifo2.sh +# No problems seen on HEAD. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/fifo2.sh > fifo2.c +rm -f /tmp/fifo2 +mycc -o fifo2 -Wall -Wextra -O2 -g fifo2.c -lpthread || exit 1 +rm -f fifo2.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint + +mount -o size=1g -t tmpfs tmpfs $mntpoint +chmod 777 $mntpoint +for i in `jot 5`; do + mkfifo $mntpoint/f$i + chmod 777 $mntpoint/f$i +done + +daemon sh -c "(cd $odir/../testcases/swap; ./swap -t 10m -i 20 -l 100)" > \ + /dev/null +sleeptime=12 +st=`date '+%s'` +while [ $((`date '+%s'` - st)) -lt $((10 * sleeptime)) ]; do + (cd $mntpoint; /tmp/fifo2) & + while ! pgrep -q fifo2; do :; done + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt $sleeptime ]; do + pgrep -q fifo2 || break + sleep .5 + done + while pgrep -q fifo2; do pkill -9 fifo2; done + wait +done +pkill -9 swap fifo2 +while pgrep -q "swap|fifo2"; do pkill -9 swap fifo2; done + +for i in `jot 10`; do + mount | grep -q "on $mntpoint " && \ + umount $mntpoint > /dev/null 2>&1 && break + sleep 10 +done +s=0 +mount | grep -q "on $mntpoint " && + { echo "umount $mntpoint failed"; s=1; } +rm -f /tmp/fifo2 +exit $s diff --git a/tools/test/stress2/misc/flock.sh b/tools/test/stress2/misc/flock.sh new file mode 100755 index 000000000000..451fec4b518a --- /dev/null +++ b/tools/test/stress2/misc/flock.sh @@ -0,0 +1,191 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# flock(2) read (shared) lock test. + +# FAIL: Unfair scheduling? +# share[1] = 359171 +# share[2] = 394437 +# share[3] = 359488 +# share[4] = 394429 +# share[5] = 359441 +# share[6] = 394281 +# share[7] = 359314 +# share[8] = 394615 + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/flock.c +mycc -o flock -Wall -Wextra -O0 -g flock.c || exit 1 +rm -f flock.c +cd $odir + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +(cd $mntpoint; /tmp/flock) +e=$? + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -rf /tmp/flock +exit $e + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +volatile u_int *share; +int fd; + +#define RENDEZVOUS 0 + +#define CHILDREN 8 +#define LOOPS 8000 +#define PARALLEL 1 +#define RUNTIME (1 * 60) + +void +chld(int id) +{ + while (share[RENDEZVOUS] == 0) + ; + + while (share[RENDEZVOUS] == 1) { + if (flock(fd, LOCK_SH) == -1) + err(1, "fcntl @ %d", __LINE__); + atomic_add_int(&share[id + 1], 1); + if (flock(fd, LOCK_UN) == -1) + err(1, "fcntl @ %d", __LINE__); + usleep(100); + } + + _exit(0); +} + +void +test(void) +{ + int i; + char file[80]; + + snprintf(file, sizeof(file), "file.%05d", getpid()); + if ((fd = open(file, O_RDWR | O_CREAT, 0640)) == -1) + err(1, "open(%s)", file); + if (flock(fd, LOCK_EX) == -1) + err(1, "fcntl @ %d", __LINE__); + + for (i = 0; i < CHILDREN; i++) { + if (fork() == 0) + chld(i); + } + + usleep(200); + atomic_add_int(&share[RENDEZVOUS], 1); /* start chld */ + for (i = 0; i < LOOPS; i++) { + if (flock(fd, LOCK_UN) == -1) + err(1, "fcntl @ %d", __LINE__); + if (flock(fd, LOCK_EX) == -1) + err(1, "fcntl @ %d", __LINE__); + } + atomic_add_int(&share[RENDEZVOUS], 1); /* stop chld */ + + for (i = 0; i < CHILDREN; i++) + wait(NULL); + + close(fd); + unlink(file); + + _exit(0); +} + +int +main(void) +{ + size_t len; + time_t start; + int i, n, pct; + + len = getpagesize(); + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON | + MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + share[RENDEZVOUS] = 0; + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) + wait(NULL); + } + n = 0; + for (i = 0; i < CHILDREN; i++) + n += share[i + 1]; + n /= CHILDREN; + for (i = 0; i < CHILDREN; i++) { + pct = abs((int)share[i + 1] - n) * 100 / n; + if (pct > 1) { + fprintf(stderr, "Unfair scheduling?\n"); + for (i = 0; i < CHILDREN; i++) { + pct = abs((int)share[i + 1] - n) * 100 / n; + fprintf(stderr, "share[%d] = %d\n", + i+1, share[i+1]); + } + break; + } + } + + return (0); +} diff --git a/tools/test/stress2/misc/flock_open_close.sh b/tools/test/stress2/misc/flock_open_close.sh new file mode 100755 index 000000000000..173cdcbf2e75 --- /dev/null +++ b/tools/test/stress2/misc/flock_open_close.sh @@ -0,0 +1,174 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Demonstrate that close() of an flock'd file is not atomic. +# Fails with "flock_open_close: execv(/mnt/test): Text file busy" + +# Test scenario by: jhb + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > flock_open_close.c +rm -f /tmp/flock_open_close +mycc -o flock_open_close -Wall -Wextra -O2 -g flock_open_close.c -lpthread || exit 1 +rm -f flock_open_close.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +cp /bin/test $mntpoint +chown $testuser $mntpoint/test +chmod +w $mntpoint/test + +su $testuser -c "/tmp/flock_open_close $mntpoint/test" & +pid=$! +while kill -0 $! 2>/dev/null; do + mksnap_ffs $mntpoint $mntpoint/.snap/snap + sleep 2 + rm -f $mntpoint/.snap/snap + sleep 1 +done +wait $pid +s=$? + +for i in `jot 10`; do + mount | grep -q md${mdstart}$part && \ + umount $mntpoint && mdconfig -d -u $mdstart && break + sleep 2 +done +if mount | grep -q md${mdstart}$part; then + fstat $mntpoint + echo "umount $mntpoint failed" + exit 1 +fi +rm -f /tmp/flock_open_close +exit $s +EOF + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void +usage(void) +{ + fprintf(stderr, "Usage: flock_close_race [args]\n"); + exit(1); +} + +static void +child(const char *binary) +{ + int fd; + + /* Exit as soon as our parent exits. */ + while (getppid() != 1) { + fd = open(binary, O_RDWR | O_EXLOCK); + if (fd < 0) { + /* + * This may get ETXTBSY since exit() will + * close its open fd's (thus releasing the + * lock), before it releases the vmspace (and + * mapping of the binary). + */ + if (errno == ETXTBSY) + continue; + err(2, "can't open %s", binary); + } + close(fd); + } + exit(0); +} + +static void +exec_child(char **av) +{ + int fd; + + fd = open(av[0], O_RDONLY | O_SHLOCK); + execv(av[0], av); + /* "flock_open_close: execv(/mnt/test): Text file busy" seen */ + err(127, "execv(%s)", av[0]); +} + +int +main(int ac, char **av) +{ + struct stat sb; + pid_t pid; + int e, i, status; + + if (ac < 2) + usage(); + if (stat(av[1], &sb) != 0) + err(1, "stat(%s)", av[1]); + if (!S_ISREG(sb.st_mode)) + errx(1, "%s not an executable", av[1]); + + pid = fork(); + if (pid < 0) + err(1, "fork"); + if (pid == 0) + child(av[1]); + e = 0; + for (i = 0; i < 200000; i++) { + pid = fork(); + if (pid < 0) + err(1, "vfork"); + if (pid == 0) + exec_child(av + 1); + wait(&status); + if (WIFEXITED(status) && WEXITSTATUS(status) == 127) { + fprintf(stderr, "FAIL\n"); + e = 1; + break; + } + if (WIFEXITED(status) && WEXITSTATUS(status) != 1) { + /* /bin/test returns 1 */ + e = 1; + break; + } + } + return (e); +} diff --git a/tools/test/stress2/misc/force.sh b/tools/test/stress2/misc/force.sh new file mode 100755 index 000000000000..4c5cd6c255f6 --- /dev/null +++ b/tools/test/stress2/misc/force.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# "mdconfig -o force" test scenario. +# Run with marcus.cfg on a 1g swap backed MD with UFS SU fs. + +# Page fault seen in WiP kernel code: +# https://people.freebsd.org/~pho/stress/log/kirk113.txt + +# Deadlock seen: +# https://people.freebsd.org/~pho/stress/log/chs002.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +flags=$newfs_flags +# Disable SUJ tests for now. Known deadlock issue. +#[ `jot -r 1 0 1` -eq 1 ] && flags="-j" +echo "newfs $flags md$mdstart" +newfs $flags md$mdstart > /dev/null 2>&1 +mount /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=3m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 & + +sleep `jot -r 1 10 40` +while mdconfig -l | grep -q md$mdstart; do + mdconfig -d -u $mdstart -o force || sleep 1 +done +sleep 1 +../tools/killall.sh +wait +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +exit 0 diff --git a/tools/test/stress2/misc/force2.sh b/tools/test/stress2/misc/force2.sh new file mode 100755 index 000000000000..35e448afbbba --- /dev/null +++ b/tools/test/stress2/misc/force2.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# "mdconfig -o force" test scenario. +# Run with marcus.cfg on a 1g swap backed MD with UFS SU fs. + +# "panic: softdep_load_inodeblock: nlink we read isn't what we wrote" seen in +# WiP kernel code: https://people.freebsd.org/~pho/stress/log/kirk130.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +dd if=/dev/zero of=$diskimage bs=1m count=1k status=none || exit 1 +mdconfig -a -t vnode -f $diskimage -u $mdstart +flags=$newfs_flags +[ `jot -r 1 0 1` -eq 1 ] && flags="-j" +echo "newfs $flags md$mdstart" +newfs $flags md$mdstart > /dev/null 2>&1 +mount /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=3m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 & + +sleep `jot -r 1 10 40` +while mdconfig -l | grep md$mdstart; do + mdconfig -d -u $mdstart -o force || sleep 1 +done +sleep 1 +../tools/killall.sh +wait +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done + +mdconfig -a -t vnode -f $diskimage -u $mdstart +fsck_ffs -Rfy /dev/md$mdstart > /dev/null; s=$? +if [ $s -eq 0 ]; then + mount /dev/md$mdstart $mntpoint + ls -lR $mntpoint > /dev/null + umount $mntpoint +fi +mdconfig -d -u $mdstart + +rm -f $diskimage +exit $s diff --git a/tools/test/stress2/misc/force3.sh b/tools/test/stress2/misc/force3.sh new file mode 100755 index 000000000000..4bfb0011cbef --- /dev/null +++ b/tools/test/stress2/misc/force3.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "mdconfig -o force" test scenario. +# Copy of force.sh with an added "umount -f" +# Spin seen in umount() with WiP kernel code. + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +flags=$newfs_flags +[ `jot -r 1 0 1` -eq 1 ] && flags="-j" +echo "newfs $flags md$mdstart" +newfs $flags md$mdstart > /dev/null 2>&1 +mount /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=3m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 & + +sleep `jot -r 1 10 40` +while mdconfig -l | grep -q md$mdstart; do + mdconfig -d -u $mdstart -o force || sleep 1 +done +sleep .`jot -r 1 1 9` +../tools/killall.sh +wait +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +exit 0 diff --git a/tools/test/stress2/misc/force4.sh b/tools/test/stress2/misc/force4.sh new file mode 100755 index 000000000000..b1b05dc54efa --- /dev/null +++ b/tools/test/stress2/misc/force4.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "mdconfig -o force" test scenario with nullfs. +# Looping in kernel with WiP kernel code seen: +# https://people.freebsd.org/~pho/stress/log/kirk125.txt + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +flags=$newfs_flags +[ `jot -r 1 0 1` -eq 1 ] && flags="-j" +echo "newfs $flags md$mdstart" +newfs $flags md$mdstart > /dev/null 2>&1 +mount /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +mp2=${mntpoint}2 +mkdir -p $mp2 +mount -t nullfs $mntpoint $mp2 || exit 1 + +export LOAD=80 +export MAXSWAPPCT=80 +export RUNDIR=$mp2/stressX +export runRUNTIME=3m +export rwLOAD=80 +export TESTPROGS=' +testcases/lockf2/lockf2 +testcases/symlink/symlink +testcases/openat/openat +testcases/socket/socket +testcases/rw/rw +testcases/mmap/mmap +testcases/fts/fts +testcases/link/link +testcases/lockf/lockf +testcases/creat/creat +testcases/mkdir/mkdir +testcases/rename/rename +testcases/swap/swap +testcases/mkfifo/mkfifo +testcases/dirnprename/dirnprename +testcases/dirrename/dirrename +' + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > /dev/null 2>&1 & + +sleep `jot -r 1 20 60` +while mdconfig -l | grep -q md$mdstart; do + mdconfig -d -u $mdstart -o force || sleep 1 +done +sleep 1 +../tools/killall.sh +wait +umount $mp2 +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +exit 0 diff --git a/tools/test/stress2/misc/force5.sh b/tools/test/stress2/misc/force5.sh new file mode 100755 index 000000000000..c0aa6436fc1f --- /dev/null +++ b/tools/test/stress2/misc/force5.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# "mdconfig -o force" test scenario. +# Rename focus + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +flags=$newfs_flags +[ `jot -r 1 0 1` -eq 1 ] && flags="-j" +echo "newfs $flags md$mdstart" +newfs $flags md$mdstart > /dev/null 2>&1 +mount /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +export LOAD=80 +export MAXSWAPPCT=80 +export RUNDIR=$mntpoint/stressX +export runRUNTIME=3m +export rwLOAD=80 +export TESTPROGS=' +testcases/fts/fts +testcases/rename/rename +testcases/swap/swap +testcases/dirnprename/dirnprename +testcases/dirrename/dirrename +' + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > /dev/null 2>&1 & + +sleep `jot -r 1 20 60` +while mdconfig -l | grep -q md$mdstart; do + mdconfig -d -u $mdstart -o force || sleep 1 +done +sleep 1 +../tools/killall.sh +wait +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +exit 0 diff --git a/tools/test/stress2/misc/force6.sh b/tools/test/stress2/misc/force6.sh new file mode 100755 index 000000000000..5c7d508241ec --- /dev/null +++ b/tools/test/stress2/misc/force6.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# "mdconfig -o force" test scenario. +# Verify file integrity after a fsync(1) followed by a forced umount +# No problems seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +dd if=/dev/zero of=$diskimage bs=1m count=1k status=none || exit 1 +mdconfig -a -t vnode -f $diskimage -u $mdstart +flags=$newfs_flags +[ `jot -r 1 0 1` -eq 1 ] && flags="-j" +echo "newfs $flags md$mdstart" +newfs $flags md$mdstart > /dev/null 2>&1 +mount /dev/md$mdstart $mntpoint + +file=$mntpoint/file +dd if=/dev/random of=$file bs=1k count=`jot -r 1 1 1024` status=none +s1=`cat $mntpoint/file | md5` +fsync $file + +while mdconfig -l | grep -q md$mdstart; do + mdconfig -d -u $mdstart -o force || sleep 1 +done + +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done + +mdconfig -a -t vnode -f $diskimage -u $mdstart +fsck_ffs -Rfy /dev/md$mdstart > /dev/null; s=$? +if [ $s -eq 0 ]; then + mount /dev/md$mdstart $mntpoint + [ ! -f $file ] && + { echo "Lost $file"; s=111; } + if [ $s -eq 0 ]; then + s2=`cat $mntpoint/file | md5` + [ "$s1" != "$s2" ] && + { echo "Checksum error"; s=222; ls -l $file; } + fi + umount $mntpoint +fi +mdconfig -d -u $mdstart + +rm -f $diskimage +exit $s diff --git a/tools/test/stress2/misc/fork.sh b/tools/test/stress2/misc/fork.sh new file mode 100755 index 000000000000..628ffbd4ce93 --- /dev/null +++ b/tools/test/stress2/misc/fork.sh @@ -0,0 +1,129 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# The test program calls fork(2) from a multi-threaded process. +# Test program stuck in uwrlck seen. +# Fixed in r266609. + +# Note that program erroneously calls exit(3) and not _exit(2). + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > fork.c +mycc -o fork -Wall -Wextra -O2 -g fork.c -lpthread || exit 1 + +for i in `jot 100`; do + /tmp/fork & +done +while ! pgrep -q fork; do + sleep .2 +done +for i in `jot 30`; do + pgrep -q fork || break + sleep 1 +done +if pgrep -q fork; then + echo FAIL + exit 1 +fi +wait + +rm -f /tmp/fork /tmp/fork.c +exit 0 +EOF + +/* + * Written by Love Hörnquist Åstrand , March 2003. + * Public domain. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static pid_t parent; +static int thread_survived = 0; + +static void * +print_pid(void *arg __unused) +{ + sleep(3); + + thread_survived = 1; + if (parent != getpid()) { + exit(1); + } + return NULL; +} + +int +main(void) +{ + int r; + pthread_t p; + pid_t fork_pid; + + parent = getpid(); + + r = pthread_create(&p, NULL, print_pid, NULL); + if (r != 0) + errx(1, "r = %d", r); + + fork_pid = fork(); + if (fork_pid == -1) + err(1, "fork"); + + if (fork_pid) { + int status; + + r = pthread_join(p, NULL); + if (r != 0) + errx(1, "r = %d", r); + if (thread_survived == 0) + errx(1, "thread did not survive in parent"); + + waitpid(fork_pid, &status, 0); + if (WIFEXITED(status) != 1) + printf("WIFEXITED(status) = %d\n", WIFEXITED(status)); + if (WEXITSTATUS(status) != 0) + printf("WEXITSTATUS(status) = %d\n", WEXITSTATUS(status)); + } else { + sleep(5); + exit(thread_survived ? 1 : 0); + } +} diff --git a/tools/test/stress2/misc/forkbomb.sh b/tools/test/stress2/misc/forkbomb.sh new file mode 100755 index 000000000000..9638fe796fee --- /dev/null +++ b/tools/test/stress2/misc/forkbomb.sh @@ -0,0 +1,148 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Fork bomb memory leak test scenario. +# https://en.wikipedia.org/wiki/Fork_bomb + +# OO memory seen: +# https://people.freebsd.org/~pho/stress/log/forkbomb.txt +# Fixed by r289026. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/forkbomb.c +mycc -o forkbomb -Wall -Wextra -O0 -g forkbomb.c || exit 1 +rm -f forkbomb.c +cd $odir + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 512m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +su $testuser -c /tmp/forkbomb + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -rf /tmp/forkbomb +exit 0 + +EOF +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +volatile u_int *share; + +#define R1 1 /* sync start */ +#define R2 2 /* forks */ +#define R3 3 /* exits */ +#define R4 4 /* fork failed */ + +//#define DEBUG +#define MXFAIL 100 +#define MAXPROC 40000 /* Arbitrary cap */ +#define PARALLEL 200 + +void +test(void) +{ + int r; + + alarm(1200); + atomic_add_int(&share[R1], 1); + while (share[R1] != PARALLEL) + ; + atomic_add_int(&share[R2], 1); + + for (;;) { + if (share[R2] >= MAXPROC || share[R4] > MXFAIL) + break; + atomic_add_int(&share[R2], 1); + if ((r = fork()) == -1) { + atomic_add_int(&share[R4], 1); + atomic_add_int(&share[R2], -1); + break; + } + } + + atomic_add_int(&share[R3], 1); + _exit(0); +} + +int +main(void) +{ + struct sigaction sa; + size_t len; + int i; + + alarm(1200); + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGCHLD, &sa, 0) == -1) + err(1, "sigaction"); + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + test(); + } + + while (share[R2] == 0 || share[R3] < share[R2]) + sleep(1); + +#if defined(DEBUG) + fprintf(stderr, "MAXPROC: %d. forks: %u / exits: %u / fails: %u\n", + MAXPROC, share[R2], share[R3], share[R4]); +#endif + + return (0); +} diff --git a/tools/test/stress2/misc/fpclone.sh b/tools/test/stress2/misc/fpclone.sh new file mode 100755 index 000000000000..3b75c5ec8d36 --- /dev/null +++ b/tools/test/stress2/misc/fpclone.sh @@ -0,0 +1,192 @@ +#!/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. +# + +# Test scenario by kib@freebsd.org + +# Test of patch for Giant trick in cdevsw + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -d /usr/src/sys ] || exit 0 +builddir=`sysctl kern.version | grep @ | sed 's/.*://'` +[ -d "$builddir" ] && export KERNBUILDDIR=$builddir || exit 0 +export SYSDIR=`echo $builddir | sed 's#/sys.*#/sys#'` +kldstat -v | grep -q pty || { kldload pty || exit 0; } + +. ../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 ..; ./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 +#include +#include +#include +#include +#include +#include +#include +#include + +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, struct thread *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, struct thread *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/tools/test/stress2/misc/fpclone2.sh b/tools/test/stress2/misc/fpclone2.sh new file mode 100755 index 000000000000..b03f5cced96f --- /dev/null +++ b/tools/test/stress2/misc/fpclone2.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. +# + +# Test scenario by kib@freebsd.org + +# Test of patch for Giant trick in cdevsw + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -d /usr/src/sys ] || exit 0 +builddir=`sysctl kern.version | grep @ | sed 's/.*://'` +[ -d "$builddir" ] && export KERNBUILDDIR=$builddir || exit 0 +export SYSDIR=`echo $builddir | sed 's#/sys.*#/sys#'` + +. ../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 +mycc -o /tmp/fpclone2 -Wall fpclone2.c +rm -f fpclone2.c + +cd $odir +for i in `jot 10`; do + /tmp/fpclone2 & +done + +for i in `jot 10`; do + wait +done +kldstat +kldunload $dir/fpclone.ko +rm -rf $dir /tmp/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/tools/test/stress2/misc/fpu.sh b/tools/test/stress2/misc/fpu.sh new file mode 100755 index 000000000000..f4bc53d2f67f --- /dev/null +++ b/tools/test/stress2/misc/fpu.sh @@ -0,0 +1,103 @@ +#!/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. +# + +# Regression test for FPU changes in r208833 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > fpu.c +mycc -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/tools/test/stress2/misc/fragments.sh b/tools/test/stress2/misc/fragments.sh new file mode 100755 index 000000000000..ea1d095081c6 --- /dev/null +++ b/tools/test/stress2/misc/fragments.sh @@ -0,0 +1,275 @@ +#!/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. +# + +# Scenario that causes "panic: brelse: free buffer onto another queue???" +# Idea for scenario by kib@. Fixed in r203818 + +# When UFS partition is full, then some high load causes +# panic: brelse: free buffer onto another queue??? + +[ `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 +mycc -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 $newfs_flags -m 0 md${mdstart}$part > /dev/null 2>&1 +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +cd $mntpoint +su $testuser -c "/tmp/fragments" +cd $here + +umount $mntpoint +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 +#include + +#define LOOPS 600 +#define PARALLEL 8 + +static pid_t pid; +static char *buf; + +static volatile sig_atomic_t stop; + +void +handler(int i __unused) { + stop = 1; +} + +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); + } + 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(); + signal(SIGALRM, handler); + alarm(30 * 60); + for (j = 0; j < 50 && stop == 0; 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/tools/test/stress2/misc/freepages.sh b/tools/test/stress2/misc/freepages.sh new file mode 100755 index 000000000000..4aaea7453b1c --- /dev/null +++ b/tools/test/stress2/misc/freepages.sh @@ -0,0 +1,130 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# Free page shortage test scenario +# No problems seen + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/freepages.c +mycc -o freepages -Wall -Wextra -O0 -g freepages.c || exit 1 +rm -f freepages.c +cd $odir + +$dir/freepages `sysctl -n hw.usermem` +s=$? +[ -f freepages.core -a $s -eq 0 ] && + { ls -l freepages.core; mv freepages.core /tmp; s=1; } + +rm -rf $dir/freepages +exit $s +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#define PARALLEL 6 +#define RUNTIME (5 * 60) +#define SYNC 0 + +static void +test(char *s) +{ + time_t start; + size_t i, len; + char *cp; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + len = atol(s) / PARALLEL; + len = len / 10 * 8; + if ((cp = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap(%zd)", len); + for (i = 0; i < len; i += PAGE_SIZE) + cp[i] = 1; + if (munmap(cp, len) == -1) + err(1, "unmap"); + } + + _exit(0); +} + +int +main(int argc __unused, char *argv[]) +{ + pid_t pids[PARALLEL]; + size_t len; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(argv[1]); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/fs.sh b/tools/test/stress2/misc/fs.sh new file mode 100755 index 000000000000..dde3f39ed3ef --- /dev/null +++ b/tools/test/stress2/misc/fs.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +# +# Copyright (c) 2008, 2011 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. +# + +# Run a simple test on different FS variations, with and without disk full. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg +flag=/tmp/fs.sh.flag + +ftest () { # option, disk full + local args="$@" + [ $2 -eq 1 ] && df=", disk full" || df="" + echo "`date '+%T'` newfs $1 md${mdstart}${part}$df" + newfs $1 md${mdstart}$part > /dev/null + mount /dev/md${mdstart}$part $mntpoint + chmod 777 $mntpoint + + export RUNDIR=$mntpoint/stressX + export runRUNTIME=1m + disk=$(($2 + 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 2`; do + rm -rf /tmp/stressX.control $RUNDIR + su $testuser -c "(cd ..; ./run.sh disk.cfg)" > \ + /dev/null 2>&1 & + sleep 60 + ../tools/killall.sh + wait + done + + for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + if [ $i -eq 6 ]; then + touch $flag + echo "Test \"$args\" FAIL" + fstat -mf $mntpoint + umount -f $mntpoint + fi + done + checkfs /dev/md${mdstart}$part || touch $flag +} + +mount | grep "on $mntpoint " | grep -q md${mdstart}$part && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 20m -u $mdstart +bsdlabel -w md$mdstart auto + +ftest "-O 1" 0 # ufs1 +ftest "-O 1" 1 # ufs1, disk full +ftest "-O 2" 0 # ufs2 +ftest "-O 2" 1 # ufs2, disk full +ftest "-U" 0 # ufs2 + soft update +ftest "-U" 1 # ufs2 + soft update, disk full +ftest "-j" 0 # ufs2 + SU+J +ftest "-j" 1 # ufs2 + SU+J, disk full + +mdconfig -d -u $mdstart +[ -f $flag ] && s=1 || s=0 +rm -f $flag +exit $s diff --git a/tools/test/stress2/misc/fsck.sh b/tools/test/stress2/misc/fsck.sh new file mode 100755 index 000000000000..a007e722988e --- /dev/null +++ b/tools/test/stress2/misc/fsck.sh @@ -0,0 +1,149 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# fsck_ffs(8) test. +# "UFS /dev/md11 (/mnt11) cylinder checksum failed" seen. +# Fixed by r341510. + +# 'panic: invalid counts on struct mount' seen: +# https://people.freebsd.org/~pho/stress/log/fsck-4.txt + +[ $DEBUG ] || exit 0 # Still WiP + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +cc -o /tmp/flip -Wall -Wextra -O2 ../tools/flip.c || exit 1 + +echo 'int sync(void) { return (0); }' > /tmp/fsck_preload.c +mycc -o /tmp/fsck_preload.so -shared -fpic /tmp/fsck_preload.c || exit 1 +cc -o /tmp/fsck_preload.so -shared -fpic /tmp/fsck_preload.c || exit 1 +rm /tmp/fsck_preload.c + +set -e +u1=$mdstart +u2=$((mdstart + 1)) +mp1=${mntpoint}$u1 +mp2=${mntpoint}$u2 +mkdir -p $mp1 $mp2 +log=$mp1/fsck.sh.log +diskimage=$mp1/fsck.sh.diskimage +backup=/tmp/fsck.sh.diskimage.`date +%Y%m%dT%H%M%S`.gz +asbs=0 +cleans=0 +reruns=0 +waccess=0 + +max=$((10 * 1024 * 1024)) +[ "$newfs_flags" = "-j" ] && + max=$((20 * 1024 * 1024)) + +set +e +mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1 +[ -c /dev/md$u1 ] && mdconfig -d -u $u1 +mdconfig -a -t swap -s 1g -u $u1 +newfs $newfs_flags /dev/md$u1 > /dev/null +mount /dev/md$u1 $mp1 + +[ -c /dev/md$u2 ] && mdconfig -d -u $u2 +dd if=/dev/zero of=$diskimage bs=$max count=1 status=none +mdconfig -a -t vnode -f $diskimage -u $u2 +backups=`newfs -N $newfs_flags md$u2 | grep -A1 "super-block backups" | \ + tail -1 | sed 's/,//g'` +newfs $newfs_flags md$u2 > /dev/null +mount /dev/md$u2 $mp2 +[ -d /usr/include/sys ] && cp -r /usr/include/sys $mp2 +umount $mp2 + +chk() { + local i + + LD_PRELOAD=/tmp/fsck_preload.so \ + fsck_ffs -fy $1 > $log 2>&1 + r=$? + if grep -qE "Cannot find file system superblock|Superblock check-hash failed" $log; then + for b in $backups; do + echo "Using alternate SB $b" + asbs=$((asbs + 1)) + LD_PRELOAD=/tmp/fsck_preload.so \ + fsck_ffs -b $b -fy $1 > $log 2>&1 + r=$? + grep -qE "Cannot find file system superblock|Superblock check-hash failed" $log || + break + done + usedasb=1 + else + usedasb=0 + fi + LANG=C egrep -q "[A-Z][A-Z]" $log && clean=0 + ! grep -Eq "IS CLEAN|MARKED CLEAN" $log; clean=$? + ! grep -q RERUN $log; rerun=$? + ! grep -q "NO WRITE ACCESS" $log; waccess=$? + [ $r -ne 0 -a $clean -eq 1 ] && echo "Exit code $r w/ clean == 1" + +} + +cd /tmp +s=0 +start=`date +%s` +while [ $((`date +%s` - start)) -lt 60 ]; do + gzip < $diskimage > $backup + fsync $backup; sync # ; sleep .2; sync; sleep .2; sync + mount /dev/md$u2 $mp2 || { s=101; break; } + touch $mp2/`jot -rc 8 a z | tr -d '\n'` + umount $mp2 + /tmp/flip -n 4 $diskimage + for i in `jot 3`; do + chk /dev/md$u2 + [ $clean -eq 1 ] && { cleans=$((cleans + 1)); break; } + [ $rerun -eq 1 ] && { reruns=$((reruns + 1)); continue; } + done + [ $r -ne 0 -a $clean -eq 1 ] && + { echo "CLEAN && non zero exit code"; break; } + [ $clean -eq 1 ] && continue + [ $usedasb -eq 1 ] && { echo "Alt. SB failed"; s=103; } + [ $waccess -eq 1 ] && { echo "No write access"; s=555; } + break +done +[ $DEBUG ] && + echo "$cleans cleans, $reruns reruns, $asbs alternate SBs." && cat $log +if [ $clean -ne 1 ]; then + echo "FS still not clean. Last fsck_ffs exit code was $r." + cat $log + cp -v $log /tmp || rm $log + [ $s -eq 0 ] && s=104 +fi +mdconfig -d -u $u2 || exit 1 +[ -f fsck_ffs.core ] && ls -l fsck_ffs.core + +umount $mp1 +mdconfig -d -u $u1 +rm -f /tmp/fsck_preload.so $backup /tmp/flip +exit $s diff --git a/tools/test/stress2/misc/fsck2.sh b/tools/test/stress2/misc/fsck2.sh new file mode 100755 index 000000000000..313efec490d1 --- /dev/null +++ b/tools/test/stress2/misc/fsck2.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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 fsck_ffs exit code + +unit=55 +[ -c /dev/md$unit ] && exit 0 + +fsck_ffs /dev/md$unit > /dev/null 2>&1 +s=$? +[ $s -eq 0 ] && { echo "Bad exit code $s. Expected non zero."; s=1; } || s=0 +exit $s diff --git a/tools/test/stress2/misc/fsck3.sh b/tools/test/stress2/misc/fsck3.sh new file mode 100755 index 000000000000..f9bd29017e35 --- /dev/null +++ b/tools/test/stress2/misc/fsck3.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# fsck_ffs test. +# Test scenario broken superblock, use backup SB. + +. ../default.cfg +set -e +u1=$mdstart +u2=$((mdstart + 1)) +mp1=${mntpoint}$u1 +mp2=${mntpoint}$u2 +mkdir -p $mp1 $mp2 +log=$mp1/fsck3.sh.log +diskimage=$mp1/diskimage + +max=$((10 * 1024 * 1024)) +[ "$newfs_flags" = "-j" ] && + max=$((20 * 1024 * 1024)) + +set -e +mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1 +[ -c /dev/md$u1 ] && mdconfig -d -u $u1 +mdconfig -a -t swap -s 1g -u $u1 +newfs $newfs_flags /dev/md$u1 > /dev/null +mount /dev/md$u1 $mp1 + +[ -c /dev/md$u2 ] && mdconfig -d -u $u2 +dd if=/dev/zero of=$diskimage bs=$max count=1 status=none +mdconfig -a -t vnode -f $diskimage -u $u2 +backups=`newfs -N $newfs_flags md$u2 | grep -A1 "super-block backups" | \ + tail -1 | sed 's/,//g'` +newfs $newfs_flags md$u2 > /dev/null +sblock=`dumpfs md$u2 | grep -m1 "superblock location" | awk '{print $3}'` +mount /dev/md$u2 $mp2 || s=100 +touch $mp2/file +umount $mp2 +set +e + +s=0 +fsck_ffs -y /dev/md$u2 > $log 2>&1 +r=$? +for i in $backups; do + dd if=/dev/random of=$diskimage oseek=$sblock bs=1 count=8 \ + conv=notrunc status=none + fsck_ffs -y /dev/md$u2 > $log 2>&1 + r=$? + echo "fsck_ffs -b $i -y /dev/md$u2" + fsck_ffs -b $i -y /dev/md$u2 > $log 2>&1 + r=$? + mount /dev/md$u2 $mp2 || s=100 + [ -f $mp2/file ] || { echo "$mp2/file not found"; s=101; } + umount $mp2 +done + +mdconfig -d -u $u2 +[ -f fsck_ffs.core ] && { ls -l fsck_ffs.core; s=102; } + +umount $mp1 +mdconfig -d -u $u1 +rm -f $diskimage +exit $s diff --git a/tools/test/stress2/misc/fsck4.sh b/tools/test/stress2/misc/fsck4.sh new file mode 100755 index 000000000000..3e97f7b54340 --- /dev/null +++ b/tools/test/stress2/misc/fsck4.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# "panic: ffs_valloc: dup alloc" seen: +# https://people.freebsd.org/~pho/stress/log/kostik1128.txt + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +md5=c2e2d89745914bf12c5b251c358e1b3f +size=$(((5368709120 + 13964088) / 1024 + 1)) +zimg=tmp.disk.xz +log=fsck4.sh.log + +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print $4}'` -lt $size ] && +{ echo "Not enough disk space."; exit 0; } +[ -z "`which fetch`" ] && exit 0 + +cd `dirname $diskimage` +trap "rm -f $diskimage $zimg" EXIT INT +fetch -q https://people.freebsd.org/~pho/$zimg || exit 0 + +m=`md5 < $zimg` +[ $m != $md5 ] && { echo "md5 diff"; rm $zimg; exit 1; } +unxz < $zimg > $diskimage +rm $zimg + +mdconfig -a -t vnode -f $diskimage -u $mdstart +fsck_ffs -fy $diskimage > $log 2>&1 +if grep -q "MARKED CLEAN" $log; then + mount /dev/md$mdstart $mntpoint + touch $mntpoint/xxxxxxxx # Panics here + umount $mntpoint + s=0 +else + cat $log + s=1 +fi +mdconfig -d -u $mdstart + +exit $s diff --git a/tools/test/stress2/misc/fsck5.sh b/tools/test/stress2/misc/fsck5.sh new file mode 100755 index 000000000000..35381c8c55e7 --- /dev/null +++ b/tools/test/stress2/misc/fsck5.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# "INODE 3: FILE SIZE 1073741824 BEYOND END OF ALLOCATED FILE, SIZE SHOULD +# BE 268435456" seen. +# Original test scenario by Jamie Landeg-Jones +# Fixed by r346185 + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +log1=/tmp/fsck5.sh.1.log +log2=/tmp/fsck5.sh.2.log +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +newfs $newfs_flags -n md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +cd $mntpoint +truncate -s 1g test +ls -lis test > $log1 +sha256 -r test > sha256.out +cd / +umount $mntpoint + +( + fsck -fy /dev/md$mdstart + fsck -fy /dev/md$mdstart + fsck -fy /dev/md$mdstart +) > $log2 2>&1 + +mount /dev/md$mdstart $mntpoint +cd $mntpoint +ls -lis test >> $log1 +sha256 -r test > sha256-2.out +s=0 +cmp sha256.out sha256-2.out || + { cat $log2 $log1 sha256.out sha256-2.out; s=1; } +cd / +umount $mntpoint +mdconfig -d -u $mdstart +rm -f $log1 $log2 +exit $s diff --git a/tools/test/stress2/misc/fsck6.sh b/tools/test/stress2/misc/fsck6.sh new file mode 100755 index 000000000000..e1c5a4f36559 --- /dev/null +++ b/tools/test/stress2/misc/fsck6.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# +# fsck_ffs -p test + +# /dev/md10: CANNOT READ BLK: 320 +# /dev/md10: UNEXPECTED SOFT UPDATE INCONSISTENCY; RUN fsck MANUALLY. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +# Check for lingering threads from the last run +pgrep -x mount && { pgrep -x mount | xargs ps -lp; exit 1; } +../tools/killall.sh || exit 1 + +fsck=/sbin/fsck_ffs +log=/tmp/fsck6.log +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 5g -u $mdstart || exit 1 +md=md$mdstart +newfs -U /dev/$md > /dev/null 2>&1 || exit 1 + +gnop create /dev/$md || exit 1 +mount /dev/$md.nop $mntpoint || exit 1 + +for i in `jot 5`; do + cp -a /usr/include $mntpoint/d$i +done +(cd $mntpoint; umount $mntpoint) +ls -lR $mntpoint > /dev/null +touch $mntpoint/x +sync; sleep 1; sync; sleep 1; sync + +gnop destroy -f /dev/$md.nop + +# Wait until forcible unmount, may be up to about 30 seconds, +# but typically very quick if I/O is in progress +s=`date +%s` +n=0 +while mount | grep -q "on $mntpoint "; do + [ $n -eq 0 ] && /bin/echo -n "Waiting for $mntpoint to force umount ..." + n=$((n + 1)) + sleep 2 + if [ $((`date +%s` - s)) -ge 180 ]; then + echo "Giving up on waiting for umount of $mntpoint" + umount $mntpoint || umount -f $mntpoint + break + fi +done +[ $n -ne 0 ] && echo + +$fsck -p /dev/$md; s=$? +mdconfig -d -u ${md#md} +rm -f $log +exit $s diff --git a/tools/test/stress2/misc/fsgs.sh b/tools/test/stress2/misc/fsgs.sh new file mode 100755 index 000000000000..ba9e81de392d --- /dev/null +++ b/tools/test/stress2/misc/fsgs.sh @@ -0,0 +1,135 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Regression test for r322799: +# Ensure that fs/gs bases are stored in pcb before copying the pcb for +# new process or thread. + +# "Exit status is 139" seen. + +# Test scenario suggestion by kib@ + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/fsgs.c +mycc -o fsgs -Wall -Wextra -O0 -g fsgs.c || exit 1 +rm -f fsgs.c +cd $odir + +$dir/fsgs +s=$? +[ -f $dir/fsgs.core ] && + { file $dir/fsgs.core; s=1; } + +rm -rf $dir/fsgs $dir/fsgs.core +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#define PARALLEL 4 +#define RUNTIME (1 * 60) +#define SYNC 0 + +static void +test(void) +{ + pid_t pid; + int i, status; + volatile char *cp; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + for (i = 0; i < 100; i++) { + if ((pid = fork()) == 0) { + cp = malloc(2); + _exit(0); + } + if (waitpid(pid, &status, 0) != pid) + err(1, "waitpid(%d)", pid); + if (status != 0) { + fprintf(stderr, "Exit status is %d\n", status); + exit(1); + } + } + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/fstat.sh b/tools/test/stress2/misc/fstat.sh new file mode 100755 index 000000000000..441065f8e769 --- /dev/null +++ b/tools/test/stress2/misc/fstat.sh @@ -0,0 +1,178 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# Regression test for r368486 +# https://reviews.freebsd.org/D27513 + +# Problem not seen. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/fstat.c +mycc -o fstat -Wall -Wextra -O0 -g fstat.c || exit 1 +rm -f fstat.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +(cd ../testcases/swap; ./swap -t 10m -i 20 > /dev/null 2>&1) & +cd $mntpoint +$dir/fstat +s=$? +while pkill swap; do :; done +wait +[ -f fstat.core -a $s -eq 0 ] && + { ls -l fstat.core; mv fstat.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/fstat +exit $s + +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static _Atomic(int) *share; + +#define PARALLEL 5 +#define RUNTIME (2 * 60) +#define SYNC 0 +#define DONE 1 + +static void +test(void) +{ + pid_t pid; + time_t start; + int fd[2], i; + char cmd[60]; + + (void)atomic_fetch_add(&share[SYNC], 1); + while (atomic_load(&share[SYNC]) != PARALLEL) + usleep(10); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + share[DONE] = 0; + if ((pid = fork()) == 0) { + (void)atomic_fetch_add(&share[DONE], 1); + for (i = 0; i < 1000; i++) { + if (socketpair(PF_UNIX, SOCK_STREAM, 0, fd) == -1) + err(1, "socketpair()"); + usleep(arc4random() % 1000); + close(fd[0]); + close(fd[1]); + } + (void)atomic_fetch_add(&share[DONE], 1); + _exit(0); + } + if (pid == -1) + err(1, "fork()"); + setproctitle("master"); + while (atomic_load(&share[DONE]) == 0) + usleep(10); + snprintf(cmd, sizeof(cmd), "fstat -p %d > /dev/null 2>&1", + pid); + while (atomic_load(&share[DONE]) == 1) + system(cmd); + system(cmd); + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid()"); + } + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/fsync.sh b/tools/test/stress2/misc/fsync.sh new file mode 100755 index 000000000000..c8c5a8243ae1 --- /dev/null +++ b/tools/test/stress2/misc/fsync.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# vfs_write_suspend() test scenario. +# The unusual combination of newfs(8) flags: J and j triggers: +# fsync: giving up on dirty +# GEOM_JOURNAL: Cannot suspend file system /mnt (error=35). (EAGAIN) + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le 10 ] && + exit 0 + +md1=$mdstart +md2=$((mdstart + 1)) + +size=5g +jsize=3g + +for u in $md1 $md2; do + [ -c /dev/md$u ] && mdconfig -d -u $u + mdconfig -a -t swap -s $size -u $u +done + +gmirror load > /dev/null 2>&1 && unload=1 +gmirror label -v -b split -s 2048 data /dev/md$md1 /dev/md$md2 \ + || exit 1 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) + +gjournal load > /dev/null 2>&1 +gjournal label -s $jsize /dev/mirror/data > /dev/null || + { gmirror stop data; exit 1; } +sleep .5 +s=1 +if [ -c /dev/mirror/data.journal ]; then + newfs -J -j /dev/mirror/data.journal > /dev/null + mount -o async /dev/mirror/data.journal $mntpoint || exit 1 + + chmod 777 $mntpoint + + export runRUNTIME=10m + export RUNDIR=$mntpoint/stressX + + su $testuser -c 'cd ..; ./run.sh disk.cfg' + s=0 + + gjournal sync + umount $mntpoint + while mount | grep $mntpoint | grep -q /mirror/data; do + umount $mntpoint || sleep 1 + done +else + echo "FAIL /dev/mirror/data.journal not found" +fi +gjournal stop /dev/mirror/data +gjournal unload +gmirror stop data +[ $unload ] && gmirror unload + +for u in $md2 $md1; do + mdconfig -d -u $u +done +exit $s diff --git a/tools/test/stress2/misc/fsync2.sh b/tools/test/stress2/misc/fsync2.sh new file mode 100755 index 000000000000..f2e846c4aa20 --- /dev/null +++ b/tools/test/stress2/misc/fsync2.sh @@ -0,0 +1,138 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# Deadlock seen: https://people.freebsd.org/~pho/stress/log/mark169.txt +# Test scenario based on the syzkaller reproducer syzkaller21.sh and comments +# by markj@. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/fsync2.c +mycc -o fsync2 -Wall -Wextra -O0 -g fsync2.c -lpthread || exit 1 +rm -f fsync2.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +(cd $mntpoint; $dir/fsync2) + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/fsync2 +exit 0 +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define RUNTIME 60 + +static time_t start; +static volatile int fd; + +static void * +t1(void *data __unused) +{ + char cwd[1024]; + + if (getcwd(cwd, sizeof(cwd)) == NULL) + err(1, "getcwd()"); + while (time(NULL) - start < RUNTIME) { + if (mkdir("./file0", 0740) == -1) + err(1, "mkdir(file0)"); + if (mkdir("./file1", 0740) == -1) + err(1, "mkdir(file2)"); + if (rename("./file1", "./file0/file0") == -1) + err(1, "rename()"); + if ((fd = open("./file0/file0", O_RDONLY)) == -1) + err(1, "open()"); + if (chdir("./file0/file0") == -1) + err(1, "chdir()"); + if (chdir(cwd) == -1) + err(1, "chdir(HOME)"); + close(fd); + rmdir("./file0/file0"); + rmdir("./file0"); + } + + return (NULL); +} + +static void * +t2(void *data __unused) +{ + while (time(NULL) - start < RUNTIME) { + fsync(fd); + } + + return (NULL); +} + +int +main(void) +{ + pthread_t tid[2]; + int r; + + start = time(NULL); + if ((r = pthread_create(&tid[0], NULL, t1, NULL)) != 0) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&tid[1], NULL, t2, NULL)) != 0) + errc(1, r, "pthread_create"); + + if ((r = pthread_join(tid[0], NULL)) != 0) + errc(1, r, "pthread_join"); + if ((r = pthread_join(tid[1], NULL)) != 0) + errc(1, r, "pthread_join"); + + return (0); +} diff --git a/tools/test/stress2/misc/ftruncate.sh b/tools/test/stress2/misc/ftruncate.sh new file mode 100755 index 000000000000..ddec85b6745a --- /dev/null +++ b/tools/test/stress2/misc/ftruncate.sh @@ -0,0 +1,189 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# ftruncate(2) fuzz. + +# "panic: softdep_deallocate_dependencies: dangling deps" seen in +# 10.3-STABLE: +# https://people.freebsd.org/~pho/stress/log/ftruncate.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=$RUNDIR + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > ftruncate.c +rm -f /tmp/ftruncate +mycc -o ftruncate -Wall -Wextra -O2 -g ftruncate.c -lpthread || exit 1 +rm -f ftruncate.c + +rm -rf $dir +mkdir -p $dir +chmod 777 $dir + +cd $dir +jot 500 | xargs touch +jot 500 | xargs chmod 666 +cd $odir + +(cd /tmp; /tmp/ftruncate $dir) +e=$? + +rm -rf $dir + +rm -f /tmp/ftruncate +exit $e +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define RUNTIME 180 +#define THREADS 2 + +static int fd[900]; +static u_int32_t r[N]; +static char *args[2]; + +static unsigned long +makearg(void) +{ + unsigned long val; + + val = arc4random(); +#if defined(__LP64__) + val = (val << 32) | arc4random(); + val = val & 0x00007fffffffffffUL; +#endif + + return(val); +} + +static void * +test(void *arg __unused) +{ + FTS *fts; + FTSENT *p; + int ftsoptions, i, n; + + ftsoptions = FTS_PHYSICAL; + + for (;;) { + for (i = 0; i < N; i++) + r[i] = arc4random(); + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + i = n = 0; + while ((p = fts_read(fts)) != NULL) { + if (fd[i] > 0) + close(fd[i]); + if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) + if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) + continue; + i++; + i = i % nitems(fd); + } + + if (fts_close(fts) == -1) + err(1, "fts_close()"); + sleep(1); + } + return(0); +} + +static void * +calls(void *arg __unused) +{ + off_t offset; + time_t start; + int fd2; + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + fd2 = makearg() % nitems(fd) + 3; + offset = makearg(); + if (ftruncate(fd2, offset) == 0) { + if (lseek(fd2, offset - 1, SEEK_SET) != -1) + write(fd2, "x", 1); + } + + } + + return (0); +} + +int +main(int argc, char **argv) +{ + struct passwd *pw; + pthread_t rp, cp[THREADS]; + int e, i; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + args[0] = argv[1]; + args[1] = 0; + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "failed to resolve nobody"); + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) + errc(1, e, "pthread_create"); + usleep(1000); + for (i = 0; i < THREADS; i++) + if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) + errc(1, e, "pthread_create"); + for (i = 0; i < THREADS; i++) + pthread_join(cp[i], NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/ftruncate2.sh b/tools/test/stress2/misc/ftruncate2.sh new file mode 100755 index 000000000000..c8c89e7ea5bd --- /dev/null +++ b/tools/test/stress2/misc/ftruncate2.sh @@ -0,0 +1,205 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# A fuzz test triggered a failed block allocation unwinding problem. + +# "panic: ffs_blkfree_cg: freeing free block" seen: +# https://people.freebsd.org/~pho/stress/log/kostik923.txt +# Fixed by r304232. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > ftruncate2.c +rm -f /tmp/ftruncate2 +mycc -o ftruncate2 -Wall -Wextra -O2 -g ftruncate2.c -lpthread || exit 1 +rm -f ftruncate2.c + +echo "Expect: \"/mnt: write failed, filesystem is full\"" +mount | grep $mntpoint | grep -q "on $mntpoint " && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs md${mdstart}$part > /dev/null # Non SU panics +mount /dev/md${mdstart}$part $mntpoint + +dir=$mntpoint +chmod 777 $dir + +cd $dir +jot 500 | xargs touch +jot 500 | xargs chmod 666 +cd $odir + +(cd /tmp; /tmp/ftruncate2 $dir) +e=$? + +rm -rf $dir/* + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/ftruncate2 +exit $e +EOF +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define RUNTIME 180 +#define THREADS 2 + +static int fd[900]; +static u_int32_t r[N]; +static char *args[2]; + +static unsigned long +makearg(void) +{ + unsigned long val; + + val = arc4random(); +#if defined(__LP64__) + val = (val << 32) | arc4random(); + val = val & 0x00007fffffffffffUL; +#endif + + return(val); +} + +static void * +test(void *arg __unused) +{ + FTS *fts; + FTSENT *p; + int ftsoptions, i, n; + + ftsoptions = FTS_PHYSICAL; + + for (;;) { + for (i = 0; i < N; i++) + r[i] = arc4random(); + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + i = n = 0; + while ((p = fts_read(fts)) != NULL) { + if (fd[i] > 0) + close(fd[i]); + if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) + if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) + continue; + if (ftruncate(fd[i], 0) != 0) + err(1, "ftruncate"); + i++; + i = i % nitems(fd); + } + + if (fts_close(fts) == -1) + err(1, "fts_close()"); + sleep(1); + } + return(0); +} + +static void * +calls(void *arg __unused) +{ + off_t offset; + time_t start; + int fd2; + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + fd2 = makearg() % nitems(fd) + 3; + offset = makearg(); + if (lseek(fd2, offset - 1, SEEK_SET) != -1) { + if (write(fd2, "x", 1) != 1) + if (errno != EBADF && errno != ENOSPC && errno != E2BIG && + errno != ESTALE && errno != EFBIG) + warn("write"); + } else + if (errno != EBADF) + warn("lseek"); + if (fsync(fd2) == -1) + if (errno != EBADF) + warn("x"); + } + + return (0); +} + +int +main(int argc, char **argv) +{ + struct passwd *pw; + pthread_t rp, cp[THREADS]; + int e, i; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + args[0] = argv[1]; + args[1] = 0; + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "failed to resolve nobody"); + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) + errc(1, e, "pthread_create"); + usleep(1000); + for (i = 0; i < THREADS; i++) + if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) + errc(1, e, "pthread_create"); + for (i = 0; i < THREADS; i++) + pthread_join(cp[i], NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/fts.sh b/tools/test/stress2/misc/fts.sh new file mode 100755 index 000000000000..b823517f7c3c --- /dev/null +++ b/tools/test/stress2/misc/fts.sh @@ -0,0 +1,144 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Run with marcus.cfg on a 1g swap backed MD +# "panic: vm_radix_remove: invalid key found" seen. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > fts1.c +mycc -o fts1 -Wall -Wextra fts1.c || exit 1 +rm -f fts1.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null & +pid=$! +while kill -0 $pid 2> /dev/null; do + /tmp/fts1 $mntpoint + sleep 1 +done +wait + +s=0 +for i in `jot 6`; do + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && s=1 +mdconfig -d -u $mdstart +rm -f /tmp/fts1 +exit $s +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +test(char *path) +{ + + FTS *fts; + FTSENT *p; + int ftsoptions; + char *args[2]; + + ftsoptions = FTS_PHYSICAL; + args[0] = path; + args[1] = 0; + + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + 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: + 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); +} + +int +main(int argc, char **argv) +{ + int i; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + alarm(600); + for (i = 0; i < 100; i++) + test(argv[1]); + + return (0); +} diff --git a/tools/test/stress2/misc/fts2.sh b/tools/test/stress2/misc/fts2.sh new file mode 100755 index 000000000000..d155393e66ba --- /dev/null +++ b/tools/test/stress2/misc/fts2.sh @@ -0,0 +1,285 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Show invalid fts_info value: + +# FAULT +# -rw------- 1 root wheel - 4 13 jan 09:25 ./lockf.0.3676 +# fts_path: ./lockf.0.3676 +# fts_info: 13 FTS_SLNONE +# fts_errno: 0 No error: 0 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +cat > /tmp/fts2.c < +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 1 +#define PARALLEL 7 + +pid_t pid; +time_t start; +int fd; +char file[128]; + +char *txt[] = { + "NULL", + "FTS_D", + "FTS_DC", + "FTS_DEFAULT", + "FTS_DNR", + "FTS_DOT", + "FTS_DP", + "FTS_ERR", + "FTS_F", + "FTS_INIT", + "FTS_NS", + "FTS_NSOK", + "FTS_SL", + "FTS_SLNONE", + "FTS_W", + "15", + "16", + "17", +}; + +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); +} + +void +tlockf(void) +{ + int i; + int sem = 0; + + usleep(arc4random() % 10000); + 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) + ; + incr(); + } + exit(0); + } else { /* parent */ + for (i = 0; i < 100; i++) { + while ((get() & 1) == 1) + ; + incr(); + } + } + close(fd); + waitpid(pid, &i, 0); + unlink(file); +} + +void +tmkdir(void) +{ + pid_t pid; + int i, j; + char name[80]; + + setproctitle(__func__); + usleep(arc4random() % 10000); + pid = getpid(); + for (j = 0; j < LOOPS; j++) { + for (i = 0; i < 1000; i++) { + snprintf(name, sizeof(name), "dir.%d.%06d", pid, i); + if (mkdir(name, 0644) == -1) + err(1, "mkdir(%s)", name); + } + for (i = 0; i < 1000; i++) { + snprintf(name, sizeof(name), "dir.%d.%06d", pid, i); + if (rmdir(name) == -1) + err(1, "unlink(%s)", name); + } + } +} + +void +tfts(void) +{ + FTS *fts; + FTSENT *p; + int ftsoptions, i; + char *args[2]; + char help[80]; + + usleep(arc4random() % 10000); + ftsoptions = FTS_LOGICAL; + args[0] = "."; + args[1] = 0; + + for (i = 0; i < 10; i++) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + if (p->fts_info == FTS_D || /* preorder directory */ + p->fts_info == FTS_DNR || /* unreadable directory */ + p->fts_info == FTS_DOT || /* dot or dot-dot */ + p->fts_info == FTS_DP || /* postorder directory */ + p->fts_info == FTS_F || /* regular file */ + p->fts_info == FTS_NS) /* stat(2) failed */ + continue; + fprintf(stderr, "FAULT\n"); + sprintf(help, "ls -lo %s", p->fts_path); + system(help); + fprintf(stderr, "fts_path: %s\n", p->fts_path); + fprintf(stderr, "fts_info: %d %s\n", p->fts_info, + txt[p->fts_info]); + fprintf(stderr, "fts_errno: %d %s\n", p->fts_errno, + strerror(p->fts_errno)); + } + + if (errno != 0 && errno != ENOENT) + err(1, "fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } +} + +void +test(void) +{ + + start = time(NULL); + if (fork() == 0) { + while (time(NULL) - start < 60) + tmkdir(); + _exit(0); + } + if (fork() == 0) { + while (time(NULL) - start < 60) + tlockf(); + _exit(0); + } + if (fork() == 0) { + while (time(NULL) - start < 60) + tfts(); + _exit(0); + } + + wait(NULL); + wait(NULL); + wait(NULL); + + _exit(0); +} + +int +main(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + test(); + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} +EOF +mycc -o /tmp/fts2 -Wall -Wextra -O0 -g /tmp/fts2.c || exit 1 + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +(cd $mntpoint; /tmp/fts2) + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm /tmp/fts2 /tmp/fts2.c diff --git a/tools/test/stress2/misc/fts3.sh b/tools/test/stress2/misc/fts3.sh new file mode 100755 index 000000000000..4cb75d8bf6e6 --- /dev/null +++ b/tools/test/stress2/misc/fts3.sh @@ -0,0 +1,133 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# No problems seen. + +. ../default.cfg + +[ -d /usr/include ] || exit 0 +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > fts3.c +mycc -o fts3 -Wall -Wextra fts3.c || exit 1 +rm -f fts3.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 3g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 120 ]; do + pids= + for i in `jot 20`; do + cp -r /usr/include $mntpoint/$i & + pids="$pids $!" + done + for p in $pids; do + wait $p + done + (cd $mntpoint && rm -rf *) +done & + +pid=$! +s=0 +while kill -0 $pid 2> /dev/null; do + /tmp/fts3 $mntpoint || { s=1; break; } +done +kill $pid > /dev/null 2>&1 +wait $pid + +for i in `jot 6`; do + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && s=2 +mdconfig -d -u $mdstart +rm -f /tmp/fts3 +exit $s +EOF +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +test(char *path) +{ + + FTS *fts; + FTSENT *p; + int ftsoptions; + char *args[2]; + + ftsoptions = FTS_PHYSICAL; + args[0] = path; + args[1] = 0; + + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) + ; + + if (errno != 0 && errno != ENOENT) + err(1, "fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + + return (0); +} + +int +main(int argc, char **argv) +{ + int i; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + alarm(120); + for (i = 0; i < 100; i++) + test(argv[1]); + + return (0); +} diff --git a/tools/test/stress2/misc/full.sh b/tools/test/stress2/misc/full.sh new file mode 100755 index 000000000000..ec99ff88138a --- /dev/null +++ b/tools/test/stress2/misc/full.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Run all tests from testcases on a 2g swap backed MD with UFS SU fs. + +# "panic: SACK scoreboard must not be empty" seen: +# https://people.freebsd.org/~pho/stress/log/full.txt +# Fixed by r310547. + +. ../default.cfg +kldstat -v | grep -q pty || kldload pty # ignore any load failure + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export LOAD=80 +export rwLOAD=80 +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX +export MAXSWAPPCT=80 +export TESTPROGS=`cd ..; find testcases/ -perm -1 -type f | \ + egrep -v "/run/"` + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +../tools/killall.sh +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +checkfs /dev/md${mdstart}$part; s=$? +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/fullpath.sh b/tools/test/stress2/misc/fullpath.sh new file mode 100755 index 000000000000..88cee4795009 --- /dev/null +++ b/tools/test/stress2/misc/fullpath.sh @@ -0,0 +1,111 @@ +#!/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. +# + +# Test scenario by marcus@freebsd.org + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -z "`type perl 2>/dev/null`" ] && exit 0 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fullpath.c +mycc -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/tools/test/stress2/misc/fullpath2.sh b/tools/test/stress2/misc/fullpath2.sh new file mode 100755 index 000000000000..e4024c32f317 --- /dev/null +++ b/tools/test/stress2/misc/fullpath2.sh @@ -0,0 +1,214 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC Isilon +# 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. +# + +# fullpath NULL reference problem hunt. + +# From the commit log of r308407: +# vn_fullpath1() checked VV_ROOT and then unreferenced +# vp->v_mount->mnt_vnodecovered unlocked. This allowed unmount to race. +# Lock vnode after we noticed the VV_ROOT flag. See comments for +# explanation why unlocked check for the flag is considered safe. + +# 'panic: namei: garbage in ni_resflags: 1': +# https://people.freebsd.org/~pho/stress/log/fullpath2.txt +# Fixed by r367130 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +cont=/tmp/fullpath2.continue +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/fullpath2.c +mycc -o fullpath2 -Wall -Wextra -O2 -g fullpath2.c -lprocstat || exit 1 +rm -f fullpath2.c +cd $odir + +mount | grep -q "on $mntpoint " && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +gpart create -s GPT md$mdstart > /dev/null || exit 1 +gpart add -t freebsd-ufs md$mdstart > /dev/null || exit 1 +newfs -n $newfs_flags md${mdstart}p1 > /dev/null || exit 1 +mount /dev/md${mdstart}p1 $mntpoint +touch $mntpoint/marker $cont +trap "rm -f $cont" EXIT INT + +daemon sh -c "(cd $odir/../testcases/swap; ./swap -t 4m -i 10 -l 100)" > \ + /dev/null 2>&1 + +for i in `jot $(jot -r 1 2 10)`; do + /tmp/fullpath2 $mntpoint & + pids="$pids $!" +done + +for i in `jot $(jot -r 1 2 5)`; do + while [ -e $cont ]; do find $mntpoint -ls > /dev/null 2>&1; done & + pidf="$pidf $!" +done + +umounts=0 +while pgrep -q fullpath2; do + for i in `jot 30`; do + umount -f $mntpoint && umounts=$((umounts+1)) && + mount /dev/md${mdstart}p1 $mntpoint + sleep 2 + done +done +echo "$umounts umounts" +rm -f $cont +while mount | grep -q "on $mntpoint "; do + umount -f $mntpoint +done +for i in $pids; do + wait $i +done +while pgrep -q swap; do + pkill -9 swap +done + +kill $pidp $pidf > /dev/null 2>&1 +wait + +rm -f $mntpoint/file.* /tmp/fullpath2 fullpath2.core +mdconfig -d -u $mdstart + +exit 0 +EOF +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#define NB 1024 +#define RUNTIME 300 + +/* dtrace -w -n 'fbt::*vn_fullpath1:entry {@rw[execname,probefunc] = count(); }' */ + +static void +getfiles(pid_t pid) +{ + struct filestat_list *head; + struct kinfo_proc *p; + struct procstat *prstat; + unsigned int cnt; + + if ((prstat = procstat_open_sysctl()) == NULL) + err(1, "procstat_open_sysctl"); + + if ((p = procstat_getprocs(prstat, KERN_PROC_PID, + pid, &cnt)) == NULL) + err(1, "procstat_getprocs"); + + if ((head = procstat_getfiles(prstat, p, 0)) == NULL) + err(1, "procstat_getfiles"); + + procstat_freefiles(prstat, head); + procstat_freeprocs(prstat, p); + procstat_close(prstat); +} + +int +main(int argc, char *argv[]) +{ + size_t len; + time_t start; + int fd[NB], i, n; + pid_t pid; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + if ((pid = fork()) == 0) { + setproctitle("getfiles"); + while (share[0] == 0) + getfiles(pid); + _exit(0); + } + + char file[MAXPATHLEN + 1]; + char marker[MAXPATHLEN + 1]; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + + memset(fd, 0, sizeof(fd)); + snprintf(marker, sizeof(marker), "%s/marker", argv[1]); + i = n = 0; + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + snprintf(file, sizeof(file), "%s/file.%06d.%02d", argv[1], getpid(), i); + if (access(marker, R_OK) == -1) + continue; + if (fd[i] > 0) + close(fd[i]); + if ((fd[i] = open(file, O_RDWR | O_CREAT | O_APPEND, + DEFFILEMODE)) == -1) { + if (errno != ENOENT && errno != EBUSY) + warn("open(%s)", file); + continue; + } + n++; + write(fd[i], "a", 1); + usleep(arc4random() % 400); + if (arc4random() % 100 < 10) { + close(fd[i]); + unlink(file); + fd[i] = 0; + } + i++; + i = i % NB; + } + share[0] = 1; + + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid"); + if (n < 100) + errx(1, "Short run: %d", n); + + return (0); +} diff --git a/tools/test/stress2/misc/fuse.sh b/tools/test/stress2/misc/fuse.sh new file mode 100755 index 000000000000..682fdb122845 --- /dev/null +++ b/tools/test/stress2/misc/fuse.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# General Fuse test scenario + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "`type mkntfs 2>/dev/null`" ] && exit 0 +[ -c /dev/fuse ] || kldload fuse.ko + +MOUNT=/usr/local/bin/ntfs-3g + +mount | grep -q "$mntpoint" && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +mkntfs -Ff /dev/md$mdstart > /dev/null 2>&1 || exit 1 + +$MOUNT /dev/md$mdstart $mntpoint || exit 1 + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=20m +(cd ..; ./run.sh marcus.cfg) +rm -rf $RUNDIR + +for i in `jot 10`; do + umount $mntpoint || sleep 2 + mount | grep -q $mntpoint || break +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/fuse2.sh b/tools/test/stress2/misc/fuse2.sh new file mode 100755 index 000000000000..3bd54fa080f5 --- /dev/null +++ b/tools/test/stress2/misc/fuse2.sh @@ -0,0 +1,89 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Parallel mount and umount test +# livelock seen + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -z "`type mkntfs 2>/dev/null`" ] && exit 0 +[ -c /dev/fuse ] || kldload fuse.ko + +. ../default.cfg + +[ -c /dev/fuse ] || kldload fuse.ko +MOUNT=/usr/local/bin/ntfs-3g +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 + mdconfig -l | grep -q md$m && mdconfig -d -u $m + + mdconfig -a -t swap -s 1g -u $m + mkntfs -Ff /dev/md$m > /dev/null 2>&1 || exit 1 + + done + + # start the parallel tests + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find & + done + wait + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + mdconfig -d -u $m + done + +else + if [ $1 = find ]; then + while mount | grep -q fusefs; do + find ${mntpoint}* -type f > /dev/null 2>&1 + sleep 1 + done + else + + # The test: Parallel mount and unmounts + for i in `jot 100`; do + m=$1 + $MOUNT /dev/md$m ${mntpoint}$m || continue + cp -r /usr/include/sys ${mntpoint}$m/file.$m 2>/dev/null + sleep .5 + while mount | grep -q ${mntpoint}$m; do + umount ${mntpoint}$m > /dev/null 2>&1 || + sleep 1 + done + done + fi +fi diff --git a/tools/test/stress2/misc/fuse3.sh b/tools/test/stress2/misc/fuse3.sh new file mode 100755 index 000000000000..d11e9f4140f7 --- /dev/null +++ b/tools/test/stress2/misc/fuse3.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Demonstrate FUSE memory corruption. +# http://people.freebsd.org/~pho/stress/log/fuse3.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Start page stealer +(cd ../testcases/swap; ./swap -t 10m -i 20 -h) & +sleep 10 + +while pgrep -q swap; do + kldload fuse.ko + kldunload fuse.ko +done +wait diff --git a/tools/test/stress2/misc/fuzz.sh b/tools/test/stress2/misc/fuzz.sh new file mode 100755 index 000000000000..bfe783752280 --- /dev/null +++ b/tools/test/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. +# + +# Stress test UFS2 file systems by introducing single bit errors in the FS +# fsck should fix the FS no matter how damaged, but e.g. 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 $newfs_flags /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 +mycc -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 + +static void +usage(void) +{ + fprintf(stderr, "%s {-n \n", getprogname()); + exit(1); +} + +static long +random_long(long mi, long ma) +{ + return (arc4random() % (ma - mi + 1) + mi); +} + +int +main(int argc, char **argv) +{ + long pos; + int ch, fd, i, times = 1, verbose = 0; + 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/tools/test/stress2/misc/gbde.sh b/tools/test/stress2/misc/gbde.sh new file mode 100755 index 000000000000..f47d8e9e15bf --- /dev/null +++ b/tools/test/stress2/misc/gbde.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# "panic: bio_driver1 used by the consumer (geom ffs.md5.bde)" seen +# http://people.freebsd.org/~pho/stress/log/gbde.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart + +gbde init /dev/md$mdstart -P pass-phrase || exit +gbde attach md$mdstart -p pass-phrase || exit + +newfs $newfs_flags /dev/md$mdstart.bde > /dev/null +mount /dev/md$mdstart.bde $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' + +while mount | grep $mntpoint | grep -q bde; do + umount $mntpoint || sleep 1 +done +gbde detach md$mdstart +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/geli.sh b/tools/test/stress2/misc/geli.sh new file mode 100755 index 000000000000..381bd1ea5f8e --- /dev/null +++ b/tools/test/stress2/misc/geli.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Simple geli(8) test +# WIP No problems seen. + +. ../default.cfg + +kldstat -v | grep -q g_eli || + { geli load && unload=1 || exit 0; } +set -e +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart + +dd if=/dev/random of=/tmp/geli.key bs=64 count=1 > /dev/null 2>&1 +echo test | geli init -s 4096 -J - -K /tmp/geli.key /dev/md$mdstart > \ + /dev/null +echo test | geli attach -j - -k /tmp/geli.key /dev/md$mdstart +newfs $newfs_flags /dev/md$mdstart.eli > /dev/null + +mount /dev/md${mdstart}.eli $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=5m + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 & +sleep 300 +../tools/killall.sh +wait + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +set +e +checkfs /dev/md${mdstart}.eli; s=$? +geli kill /dev/md$mdstart.eli +mdconfig -d -u $mdstart +rm -f /tmp/geli.key +[ $unload ] && geli unload +exit $s diff --git a/tools/test/stress2/misc/geomleak.sh b/tools/test/stress2/misc/geomleak.sh new file mode 100755 index 000000000000..0961bc58f8bf --- /dev/null +++ b/tools/test/stress2/misc/geomleak.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# GEOM leak regression test. +# The problem was introduced in r328426 and fixed by r329375. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +set -e +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +old=`vmstat -m | awk '/GEOM/{print $2}'` +for i in `jot 50`; do + mdconfig -a -t swap -s 500m -u $mdstart + newfs $newfs_flags /dev/md$mdstart > /dev/null 2>&1 + mdconfig -d -u $mdstart +done +set +e +new=`vmstat -m | awk '/GEOM/{print $2}'` +if [ $((new - old)) -gt 5 ]; then + s=1 + echo "InUse changed from $old to $new, leaking $((new - old)) GEOMs" +else + s=0 +fi +exit $s diff --git a/tools/test/stress2/misc/geomleak2.sh b/tools/test/stress2/misc/geomleak2.sh new file mode 100755 index 000000000000..19b6f03d6333 --- /dev/null +++ b/tools/test/stress2/misc/geomleak2.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +old=`vmstat -m | awk '/GEOM/{print $2}'` +set -e +mount | grep -q "on $mntpoint " && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +newfs -U /dev/md$mdstart > /dev/null +set +e +start=` date +%s` +while [ $((`date +%s` - start)) -lt 60 ]; do + mount /dev/md$mdstart $mntpoint + while mount | grep -q "on $mntpoint "; do + umount $mntpoint + done +done +mdconfig -d -u $mdstart + +new=`vmstat -m | awk '/GEOM/{print $2}'` +if [ $((new - old)) -gt 5 ]; then + s=1 + vmstat -m | sed -n '1p;/GEOM/p' +else + s=0 +fi +exit $s diff --git a/tools/test/stress2/misc/getrandom.sh b/tools/test/stress2/misc/getrandom.sh new file mode 100755 index 000000000000..fe30a688decb --- /dev/null +++ b/tools/test/stress2/misc/getrandom.sh @@ -0,0 +1,142 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# getrandom() non threaded test +# Reset seen on i386 + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +[ `uname -m` = "i386" ] || exit 0 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/getrandom.c +mycc -o getrandom -Wall -Wextra -O0 -g getrandom.c || exit 1 +rm -f getrandom.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +set +e + +(cd $odir/../testcases/swap; ./swap -t 5m -i 40 -l 100) & +cd $mntpoint +timeout 5m limits -c 0 $dir/getrandom +s=0 +while pgrep -q swap; do pkill swap; done +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/getrandom +exit $s + +EOF +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#define PARALLEL 50 +#define RUNTIME (5 * 60) +#define SYNC 0 + +static void +test(void) +{ + time_t start; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + alarm(65); + start = time(NULL); + while ((time(NULL) - start) < 60) + getrandom((void *)arc4random(), arc4random(), arc4random() & 3); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/getrandom2.sh b/tools/test/stress2/misc/getrandom2.sh new file mode 100755 index 000000000000..941ffb737a6d --- /dev/null +++ b/tools/test/stress2/misc/getrandom2.sh @@ -0,0 +1,188 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# getrandom(2) DoS scenario. + +# panic: pmap_growkernel: no memory to grow kernel +# cpuid = 8 +# time = 1582102582 +# KDB: stack backtrace: +# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe03e6992450 +# vpanic() at vpanic+0x185/frame 0xfffffe03e69924b0 +# panic() at panic+0x43/frame 0xfffffe03e6992510 +# pmap_growkernel() at pmap_growkernel+0x2d4/frame 0xfffffe03e6992550 +# vm_map_insert() at vm_map_insert+0x296/frame 0xfffffe03e69925f0 +# vm_map_find() at vm_map_find+0x617/frame 0xfffffe03e69926d0 +# kva_import() at kva_import+0x3c/frame 0xfffffe03e6992710 +# vmem_try_fetch() at vmem_try_fetch+0xde/frame 0xfffffe03e6992760 +# vmem_xalloc() at vmem_xalloc+0x4bb/frame 0xfffffe03e69927e0 +# kva_import_domain() at kva_import_domain+0x36/frame 0xfffffe03e6992810 +# vmem_try_fetch() at vmem_try_fetch+0xde/frame 0xfffffe03e6992860 +# vmem_xalloc() at vmem_xalloc+0x4bb/frame 0xfffffe03e69928e0 +# vmem_alloc() at vmem_alloc+0x8a/frame 0xfffffe03e6992930 +# kmem_malloc_domainset() at kmem_malloc_domainset+0x92/frame 0xfffffe03e69929a0 +# malloc() at malloc+0x162/frame 0xfffffe03e69929f0 +# read_random_uio() at read_random_uio+0xa5/frame 0xfffffe03e6992a40 +# sys_getrandom() at sys_getrandom+0x7b/frame 0xfffffe03e6992ac0 +# amd64_syscall() at amd64_syscall+0x183/frame 0xfffffe03e6992bf0 +# fast_syscall_common() at fast_syscall_common+0x101/frame 0xfffffe03e6992bf0 +# --- syscall (563, FreeBSD ELF64, sys_getrandom), rip = 0x80041899a, rsp = 0x7ffffffc3cb8, rbp = 0x7ffffffc3cd0 --- +# KDB: enter: panic +# [ thread pid 12095 tid 186584 ] +# Stopped at kdb_enter+0x37: movq $0,0x1084916(%rip) +# db> x/s version +# version: FreeBSD 13.0-CURRENT #0 r358094: Wed Feb 19 06:25:16 CET 2020\012 pho@t2.osted.lan:/usr/src/sys/amd64/compile/PHO\012 +# db> + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/getrandom2.c +mycc -o getrandom2 -Wall -Wextra -O0 -g getrandom2.c || exit 1 +rm -f getrandom2.c +cd $odir + +cd /tmp +$dir/getrandom2 +s=$? +[ -f getrandom2.core -a $s -eq 0 ] && + { ls -l getrandom2.core; s=1; } +cd $odir + +rm -rf $dir/getrandom2 +exit $s + +EOF +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static size_t mx; +static _Atomic(int) *share; +static int parallel; +static char *bp; + +#define PARALLEL 40000 /* Arbitrary cap */ +#define SYNC 0 + +static void +test(void) +{ + int i; + + alarm(180); + (void)atomic_fetch_add(&share[SYNC], 1); + while (atomic_load(&share[SYNC]) != parallel) + usleep(200000); + for (i = 0; i < 10; i++) + getrandom(bp, mx, 0); +// close(66); + + _exit(0); +} + +int +main(void) +{ + pid_t *pids; + struct rlimit rlp; + size_t len; + size_t f, vsz; + u_int pages; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + if (getrlimit(RLIMIT_NPROC, &rlp) < 0) + err(1, "getrlimit"); + parallel = rlp.rlim_cur / 100 * 80; + if (parallel > PARALLEL) + parallel = PARALLEL; + pids = calloc(parallel, sizeof(pid_t)); + + vsz = sizeof(pages); + if (sysctlbyname("vm.stats.vm.v_free_count", &pages, &vsz, NULL, 0) != 0) + err(1, "sysctl(vm.stats.vm.v_free_count)"); + f = pages; + f *= PAGE_SIZE; + + if (getrlimit(RLIMIT_DATA, &rlp) < 0) + err(1,"getrlimit"); + mx = rlp.rlim_cur; + if (mx > f / parallel) + mx = f / parallel; + if ((bp = mmap(NULL, mx, PROT_READ | PROT_WRITE, MAP_ANON, -1, + 0)) == MAP_FAILED) + err(1, "mmap"); + for (;;) { + if (getrandom(bp, mx, 0) != -1) + break; + mx = mx / 2; + } + printf("Max getrandom() buffer size is %zu, %d threads\n", mx, + parallel); + for (i = 0; i < parallel; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < parallel; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/gjournal.sh b/tools/test/stress2/misc/gjournal.sh new file mode 100755 index 000000000000..7ccc7a70760e --- /dev/null +++ b/tools/test/stress2/misc/gjournal.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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. +# + +# Deadlock scenario based on kern/154228, fixed in r217880. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +size="2g" +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +[ `swapinfo -k | tail -1 | awk '{print int($4/1024/1024)}'` -lt \ + ${size%g} ] && exit 0 +m=$((mdstart + 1)) +mp2=${mntpoint}$m +mount | grep $mp2 | grep -q /dev/md && umount -f $mp2 +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +[ -c /dev/md$m ] && mdconfig -d -u $m +mkdir -p $mp2 +mdconfig -a -t swap -s $size -u $mdstart || exit 1 + +gjournal load +gjournal label -s 512m md$mdstart +sleep .5 +newfs -J /dev/md$mdstart.journal > /dev/null +mount -o async /dev/md$mdstart.journal $mntpoint + +here=`pwd` +cd $mntpoint +dd if=/dev/zero of=image bs=1m count=1k status=none +mdconfig -a -t vnode -f image -u $m +bsdlabel -w md$m auto +newfs md${m}$part > /dev/null +mount /dev/md${m}$part $mp2 +# dd will suspend in wdrain +echo "Expect \"$mp2: write failed, filesystem is full\"" +dd if=/dev/zero of=$mp2/zero bs=1M > /dev/null 2>&1 +while mount | grep $mp2 | grep -q /dev/md; do + umount $mp2 || sleep 1 +done +mdconfig -d -u $m +cd $here + +gjournal sync +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +gjournal stop md$mdstart +gjournal unload +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/gjournal2.sh b/tools/test/stress2/misc/gjournal2.sh new file mode 100755 index 000000000000..48d45dc4fab5 --- /dev/null +++ b/tools/test/stress2/misc/gjournal2.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# File system corruption seen + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +size="5g" +jsize="3g" +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le ${size%g} ] && exit 0 +[ `swapinfo -k | tail -1 | awk '{print int($4/1024/1024)}'` -lt \ + ${size%g} ] && exit 0 +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s $size -u $mdstart || exit 1 + +gjournal load +gjournal label -s $jsize md$mdstart +sleep .5 +newfs -J /dev/md$mdstart.journal > /dev/null +mount -o async /dev/md$mdstart.journal $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 + +gjournal sync +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +gjournal stop md$mdstart +gjournal unload +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/gjournal3.sh b/tools/test/stress2/misc/gjournal3.sh new file mode 100755 index 000000000000..a2ed7f57098c --- /dev/null +++ b/tools/test/stress2/misc/gjournal3.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# Deadlock seen: http://people.freebsd.org/~pho/stress/log/gjournal3.txt +# Fixed in r244925 + +# panic: Bio not on queue +# https://people.freebsd.org/~pho/stress/log/gjournal3-2.txt + +# kib@ wrote: +# gjournal is good for exposing the suspension problems. The frequency +# of the suspensions called from the gjournal is not achievable by other +# methods, so the tests allow to uncover the problems. More, the gjournal +# only establishes the suspension, without snapshotting, which also +# makes it easier to see the issues. + +# gjournal / ffs snapshot suspension deadlock: +# https://people.freebsd.org/~pho/stress/log/gjournal3-4.txt +# Originally reported as kern/164252. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +size="12g" +jsize="8g" +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le ${size%g} ] && exit 0 +[ `swapinfo -k | tail -1 | awk '{print int($4/1024/1024)}'` -lt \ + ${size%g} ] && exit 0 +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/mdmd$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s $size -u $mdstart || exit 1 + +gjournal load +gjournal label -s $jsize md$mdstart +sleep .5 +newfs -J /dev/md$mdstart.journal > /dev/null +mount -o async /dev/md$mdstart.journal $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ../testcases/rw + ./rw -t 2m -i 10 -l 100 > /dev/null 2>&1' & +while kill -0 $! 2>/dev/null; do + mksnap_ffs $mntpoint $mntpoint/.snap/snap + sleep .2 + rm -f $mntpoint/.snap/snap +done +wait + +gjournal sync +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +gjournal stop md$mdstart +gjournal unload +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/gjournal4.sh b/tools/test/stress2/misc/gjournal4.sh new file mode 100755 index 000000000000..80dbcafba904 --- /dev/null +++ b/tools/test/stress2/misc/gjournal4.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# Experiment with a sparse MD disk. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `sysctl -n vm.swap_total` -eq 0 ] && exit 0 +[ `sysctl -n hw.physmem` -lt $(( 4 * 1024 * 1024 * 1024)) ] && exit 0 + +. ../default.cfg + +size="100g" +jsize="10g" +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s $size -u $mdstart || exit 1 + +gjournal load +gjournal label -s $jsize md$mdstart +sleep .5 +newfs -J /dev/md$mdstart.journal > /dev/null +mount -o async /dev/md$mdstart.journal $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX +export CTRLDIR=$mntpoint/stressX.control +export swapINCARNATIONS=5 + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 + +gjournal sync +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +checkfs /dev/md$mdstart.journal && s=0 || s=$? +gjournal stop md$mdstart +gjournal unload +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/gnop.sh b/tools/test/stress2/misc/gnop.sh new file mode 100755 index 000000000000..216bcf481ea0 --- /dev/null +++ b/tools/test/stress2/misc/gnop.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test with different sector size using gnop(8). +# Out of VM seen: +# https://people.freebsd.org/~pho/stress/log/gnop.txt + +flag=/tmp/gnop.sh.flag +test() { + . ../default.cfg + + start=`date +%s` + set -e + mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint + [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + + mdconfig -a -t swap -s 2g -u $mdstart + gnop create -S $1 /dev/md$mdstart + newfs $newfs_flags /dev/md$mdstart.nop > /dev/null + mount /dev/md$mdstart.nop $mntpoint + chmod 777 $mntpoint + set +e + + export runRUNTIME=4m + export RUNDIR=$mntpoint/stressX + + su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 + + while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + done + checkfs /dev/md$mdstart.nop || touch $flag + gnop destroy /dev/md$mdstart.nop + mdconfig -d -u $mdstart + t=`date +%s` + echo "Elapsed `date -u -j -f '%s' '+%H:%M' $((t - start))`" +} + +kldstat | grep -q geom_nop || { gnop load 2>/dev/null || exit 0 && + notloaded=1; } +gnop status || exit 1 + +for i in 1k 2k 4k 8k; do + test $i +done + +[ $notloaded ] && gnop unload +[ -f $flag ] && s=1 || s=0 +rm -f $flag +exit $s diff --git a/tools/test/stress2/misc/gnop10.sh b/tools/test/stress2/misc/gnop10.sh new file mode 100755 index 000000000000..80ddc2fe1216 --- /dev/null +++ b/tools/test/stress2/misc/gnop10.sh @@ -0,0 +1,139 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# fsck test with forced unmount of a SUJ FS. +# Variation of gnop8.sh by Kirk McKusick + +# Copy of gnop9.sh. Uses SU instead of SUJ. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +# Check for lingering threads from the last run +pgrep -x mount && { pgrep -x mount | xargs ps -lp; exit 1; } +../tools/killall.sh || exit 1 + +fsck=/sbin/fsck_ffs +fsck_loops=10 +exp=/sbin/fsck_ffs.exp # Experimental version +log=/tmp/gnop10.log +[ -f $exp ] && { echo "Using $exp"; fsck=$exp; } +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 5g -u $mdstart || exit 1 +md=md$mdstart +newfs -U /dev/$md > /dev/null 2>&1 || exit 1 + +export LOAD=80 +export rwLOAD=80 +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX +export CTRLDIR=$mntpoint/stressX.control +export MAXSWAPPCT=80 +export TESTPROGS=' +testcases/lockf2/lockf2 +testcases/symlink/symlink +testcases/openat/openat +testcases/socket/socket +testcases/rw/rw +testcases/fts/fts +testcases/link/link +testcases/lockf/lockf +testcases/creat/creat +testcases/mkdir/mkdir +testcases/rename/rename +testcases/mkfifo/mkfifo +testcases/dirnprename/dirnprename +testcases/dirrename/dirrename +' + +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 / 10 * 7)) +export INODES=$(($2 / 10 * 7)) + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 600 ]; do + gnop create /dev/$md || exit 1 + mount /dev/$md.nop $mntpoint || exit 1 + mkdir -p $RUNDIR $CTRLDIR + chmod 777 $RUNDIR $CTRLDIR + + # start your favorite I/O test here + rm -rf /tmp/stressX.control + (cd $RUNDIR && find . -delete) + + su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' & + + # after some number of seconds + sleep `jot -r 1 30 90` + gnop destroy -f /dev/$md.nop + ../tools/killall.sh || exit 1 + wait + + # Wait until forcible unmount, may be up to about 30 seconds, + # but typically very quick if I/O is in progress + s=`date +%s` + n=0 + while mount | grep -q "on $mntpoint "; do + [ $n -eq 0 ] && /bin/echo -n "Waiting for $mntpoint to force umount ..." + n=$((n + 1)) + sleep 2 + if [ $((`date +%s` - s)) -ge 180 ]; then + echo "Giving up on waiting for umount of $mntpoint" + umount $mntpoint || umount -f $mntpoint + break + fi + done + [ $n -ne 0 ] && echo + + # first fsck will attempt journal recovery + $fsck -fy /dev/$md > $log 2>&1 + + # The second fsck will do traditional check for any errors + # from journal recovery + + # There seems to be a gnop cache issue, which resolves by adding + # delays between each fsck run + for i in `jot $fsck_loops`; do + sleep $((i * i)) # gnop workaround + [ $i -ne 1 ] && + echo "`date +%T` $fsck loop #$((i + 1))" + $fsck -fy /dev/$md > $log 2>&1 + grep -Eq "IS CLEAN|MARKED CLEAN" $log && break + [ $i -eq $fsck_loops ] && + { echo "$fsck did not mark FS as clean"; exit 1; } + [ $i -ne 1 ] && tail -3 $log + sync; sleep 5; sync; sleep 5 + done +done +echo "Final $fsck" +sleep 3; # gnop workaround +$fsck -fy /dev/$md > $log || { tail -5 $log; exit 1; } +mdconfig -d -u ${md#md} +rm -f $log +exit 0 diff --git a/tools/test/stress2/misc/gnop2.sh b/tools/test/stress2/misc/gnop2.sh new file mode 100755 index 000000000000..d38754d58456 --- /dev/null +++ b/tools/test/stress2/misc/gnop2.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "panic: vnode_pager_generic_getpages: sector size 8192 too large" seen +# with an 8k sector size: +# https://people.freebsd.org/~pho/stress/log/gnop2.txt +# Fixed by r307626 + +. ../default.cfg + +kldstat | grep -q geom_nop || { gnop load 2>/dev/null || exit 0 && + notloaded=1; } +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/mmap5.sh > $dir/gnop2.c +mycc -o gnop2 -Wall -Wextra gnop2.c || exit 1 +rm -f gnop2.c +cd $odir + +test() { + . ../default.cfg + + mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint + [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + + set -e + mdconfig -a -t swap -s 2g -u $mdstart + gnop create -S $1 /dev/md$mdstart + newfs $newfs_flags /dev/md$mdstart.nop > /dev/null + mount /dev/md$mdstart.nop $mntpoint + chmod 777 $mntpoint + set +e + + dd if=/dev/zero of=$mntpoint/file bs=1k count=333 status=none + /tmp/gnop2 $mntpoint/file + + while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + done + gnop destroy /dev/md$mdstart.nop + mdconfig -d -u $mdstart +} + +gnop status || exit 1 + +for i in 1k 2k 4k 8k; do + test $i +done + +[ $notloaded ] && gnop unload +rm -f /tmp/gnop2 +exit 0 diff --git a/tools/test/stress2/misc/gnop3.sh b/tools/test/stress2/misc/gnop3.sh new file mode 100755 index 000000000000..3d22e4a74331 --- /dev/null +++ b/tools/test/stress2/misc/gnop3.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# A 8k sector size test. +# "panic: run 8 0xfffff80ff3d1e040 invalid" seen during fix development. + +# OOM: https://people.freebsd.org/~pho/stress/log/gnop3.txt + +. ../default.cfg + +# OOM seen with RAM == 32g +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -lt 32 ] && exit 0 +[ $((`sysctl -n vm.swap_total` / 1024 / 1024 / 1024)) -lt 9 ] && exit 0 + +kldstat | grep -q geom_nop || { gnop load 2>/dev/null || exit 0 && + notloaded=1; } +gnop status || exit 1 + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +set -e +mdconfig -a -t swap -s 8g -u $mdstart +gnop create -S 8k /dev/md$mdstart +newfs $newfs_flags /dev/md$mdstart.nop > /dev/null +mount /dev/md$mdstart.nop $mntpoint +chmod 777 $mntpoint +set +e + +cp -a ../../stress2 $mntpoint +here=`pwd` +cd $mntpoint/stress2/misc + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' + +cd $here +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +gnop destroy /dev/md$mdstart.nop +mdconfig -d -u $mdstart +[ $notloaded ] && gnop unload +exit 0 diff --git a/tools/test/stress2/misc/gnop4.sh b/tools/test/stress2/misc/gnop4.sh new file mode 100755 index 000000000000..2e4cc1a5df35 --- /dev/null +++ b/tools/test/stress2/misc/gnop4.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# A 8k sector size test using buildworld. + +# "panic: DI already started" seen: +# https://people.freebsd.org/~pho/stress/log/kostik1017.txt +# Fixed by r322175 + +. ../default.cfg + +gigs=9 +[ $((`sysctl -n vm.swap_total` / 1024 / 1024 / 1024)) -lt $gigs ] && exit 0 +[ -d /usr/src/sys ] || exit 0 + +kldstat | grep -q geom_nop || { gnop load 2>/dev/null || exit 0 && + notloaded=1; } +gnop status || exit 1 + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +set -e +mdconfig -a -t swap -s ${gigs}g -u $mdstart +gnop create -S 8k /dev/md$mdstart +newfs $newfs_flags /dev/md$mdstart.nop > /dev/null +mount /dev/md$mdstart.nop $mntpoint +chmod 777 $mntpoint +set +e + +start=`date '+%s'` +(cd /usr; tar --exclude compile -cf - src) | (cd $mntpoint; tar xf -) + +cd $mntpoint/src +export MAKEOBJDIRPREFIX=$mntpoint/obj + +p=$((`sysctl -n hw.ncpu`+ 1)) +make -i -j $p buildworld DESTDIR=$mntpoint TARGET=amd64 TARGET_ARCH=amd64 \ + > /dev/null & +e=$((`date '+%s'` - start)) +sleep $((15 * 60 - e)) +kill $! +wait + +cd / +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +gnop destroy /dev/md$mdstart.nop +mdconfig -d -u $mdstart +[ $notloaded ] && gnop unload +exit 0 diff --git a/tools/test/stress2/misc/gnop5.sh b/tools/test/stress2/misc/gnop5.sh new file mode 100755 index 000000000000..2acd0244d80a --- /dev/null +++ b/tools/test/stress2/misc/gnop5.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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 newfs with different sector size. +# newfs(8) issue fixed by r323157. +# mount(8) still fails with a sector size > 8k. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +kldstat | grep -q geom_nop || { gnop load 2>/dev/null || exit 0 && + loaded=1; } +gnop status > /dev/null || exit 1 + +s=0 +set -e +# Fails with a sector size > 8k. +#for i in 1k 2k 4k 8k 16k 32k 64k; do +for i in 1k 2k 4k 8k; do + echo $i + mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint + [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + + mdconfig -a -t swap -s 2g -u $mdstart + gnop create -S $i /dev/md$mdstart + newfs $newfs_flags /dev/md$mdstart.nop > /dev/null || + { s=1; continue; } + mount /dev/md$mdstart.nop $mntpoint || + { gnop destroy /dev/md$mdstart.nop; mdconfig -d -u $mdstart + s=1; break; } + chmod 777 $mntpoint + + (cd $mntpoint; jot 100 | xargs touch) + + while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + done + checkfs /dev/md$mdstart.nop || s=1 + gnop destroy /dev/md$mdstart.nop + mdconfig -d -u $mdstart +done + +[ $loaded ] && gnop unload +exit $s diff --git a/tools/test/stress2/misc/gnop6.sh b/tools/test/stress2/misc/gnop6.sh new file mode 100755 index 000000000000..63301d8fe841 --- /dev/null +++ b/tools/test/stress2/misc/gnop6.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# Read and write delay +# No problems seen + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +kldstat | grep -q geom_nop || { gnop load 2>/dev/null || exit 0 && + notloaded=1; } +gnop status || exit 1 + +. ../default.cfg + +delay=`jot -r 1 1 10` # ms delay +rprob=`jot -r 1 0 100` # read delay in % +wprob=`jot -r 1 0 100` # write delay in % +set -e +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart +gnop create -d $delay -q $rprob -x $wprob /dev/md$mdstart +newfs $newfs_flags /dev/md$mdstart.nop > /dev/null +mount /dev/md$mdstart.nop $mntpoint +chmod 777 $mntpoint +set +e + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +checkfs /dev/md$mdstart.nop || s=1 && s=0 +gnop destroy /dev/md$mdstart.nop +mdconfig -d -u $mdstart + +[ $notloaded ] && gnop unload +exit $s diff --git a/tools/test/stress2/misc/gnop7.sh b/tools/test/stress2/misc/gnop7.sh new file mode 100755 index 000000000000..3f3118ff0fab --- /dev/null +++ b/tools/test/stress2/misc/gnop7.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Failed Disk Test. +# "panic: witness_warn" seen in WiP kernel code. +# https://people.freebsd.org/~pho/stress/log/kirk102.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +kldstat | grep -q geom_nop || { gnop load 2>/dev/null || exit 0 && + notloaded=1; } +gnop status || exit 1 + +. ../default.cfg + +set -e +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart +gnop create /dev/md$mdstart +newfs $newfs_flags /dev/md$mdstart.nop > /dev/null +mount /dev/md$mdstart.nop $mntpoint +chmod 777 $mntpoint +set +e + +export runRUNTIME=3m +export RUNDIR=$mntpoint/stressX +echo "Expect: + g_vfs_done():md10.nop[READ(offset=1077805056, length=32768)]error = 5 + g_vfs_done():md10.nop[WRITE(offset=553680896, length=32768)]error = 5" + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 & +sleep `jot -r 1 60 120` +gnop configure -e 5 -r 100 -w 100 /dev/md$mdstart.nop +sleep 2 +gnop configure -e 0 -r 0 -w 0 /dev/md$mdstart.nop +wait + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint && break + sleep 1 + [ $((n += 1)) -le 10 ] && continue + echo "umount $mntpoint failed" + s=1 + umount -f $mntpoint + break +done +fsck_ffs -Rfy /dev/md$mdstart.nop || s=2 +gnop destroy /dev/md$mdstart.nop +mdconfig -d -u $mdstart + +[ $notloaded ] && gnop unload +exit $s diff --git a/tools/test/stress2/misc/gnop8.sh b/tools/test/stress2/misc/gnop8.sh new file mode 100755 index 000000000000..6916c14e41f4 --- /dev/null +++ b/tools/test/stress2/misc/gnop8.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Kirk McKusick +# +# 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. +# + +# 'panic: Lock (lockmgr) ufs not locked @ kern/kern_lock.c:1271' seen: +# https://people.freebsd.org/~pho/stress/log/gnop8.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +fsck=/sbin/fsck_ffs +exp=/sbin/fsck_ffs.exp # Experimental version +[ -f $exp ] && { echo "Using $exp"; fsck=$exp; } +mdconfig -a -t swap -s 5g -u $mdstart || exit 1 +md=md$mdstart +newfs -j /dev/$md || exit 1 +start=`date +%s` +while [ $((`date +%s` - start)) -lt 120 ]; do + gnop create /dev/$md || exit 1 + mount /dev/$md.nop /mnt || exit 1 + + # start your favorite I/O test here + cp -rp /[a-l]* /[n-z]* /mnt & + + # after some number of seconds + sleep 1 + gnop destroy -f /dev/$md.nop + kill $! + + # wait until forcible unmount, may be up to about 30 seconds, + # but typically very quick if I/O is in progress + while (a=`mount | egrep /mnt`) do sleep 1; done + + # first fsck will attempt journal recovery + $fsck -d -y /dev/$md + + # second fsck will do traditional fsck to check for any errors + # from journal recovery + $fsck -d -y /dev/$md + wait +done +mdconfig -d -u ${md#md} +exit 0 diff --git a/tools/test/stress2/misc/gnop9.sh b/tools/test/stress2/misc/gnop9.sh new file mode 100755 index 000000000000..0389391398f3 --- /dev/null +++ b/tools/test/stress2/misc/gnop9.sh @@ -0,0 +1,139 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# fsck test with forced unmount of a SUJ FS. +# Variation of gnop8.sh by Kirk McKusick + +# https://people.freebsd.org/~pho/stress/log/gnop9.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +# Check for lingering threads from the last run +pgrep -x mount && { pgrep -x mount | xargs ps -lp; exit 1; } +../tools/killall.sh || exit 1 + +fsck=/sbin/fsck_ffs +fsck_loops=10 +exp=/sbin/fsck_ffs.exp # Experimental version +log=/tmp/gnop9.log +[ -f $exp ] && { echo "Using $exp"; fsck=$exp; } +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 5g -u $mdstart || exit 1 +md=md$mdstart +newfs -j /dev/$md > /dev/null 2>&1 || exit 1 + +export LOAD=80 +export rwLOAD=80 +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX +export CTRLDIR=$mntpoint/stressX.control +export MAXSWAPPCT=80 +export TESTPROGS=' +testcases/lockf2/lockf2 +testcases/symlink/symlink +testcases/openat/openat +testcases/socket/socket +testcases/rw/rw +testcases/fts/fts +testcases/link/link +testcases/lockf/lockf +testcases/creat/creat +testcases/mkdir/mkdir +testcases/rename/rename +testcases/mkfifo/mkfifo +testcases/dirnprename/dirnprename +testcases/dirrename/dirrename +' + +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 / 10 * 7)) +export INODES=$(($2 / 10 * 7)) + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 600 ]; do + gnop create /dev/$md || exit 1 + mount /dev/$md.nop $mntpoint || exit 1 + mkdir -p $RUNDIR $CTRLDIR + chmod 777 $RUNDIR $CTRLDIR + + # start your favorite I/O test here + rm -rf /tmp/stressX.control + (cd $RUNDIR && find . -delete) + + su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' & + + # after some number of seconds + sleep `jot -r 1 30 90` + gnop destroy -f /dev/$md.nop + ../tools/killall.sh || exit 1 + wait + + # Wait until forcible unmount, may be up to about 30 seconds, + # but typically very quick if I/O is in progress + s=`date +%s` + n=0 + while mount | grep -q "on $mntpoint "; do + [ $n -eq 0 ] && /bin/echo -n "Waiting for $mntpoint to force umount ..." + n=$((n + 1)) + sleep 2 + if [ $((`date +%s` - s)) -ge 180 ]; then + echo "Giving up on waiting for umount of $mntpoint" + umount $mntpoint || umount -f $mntpoint + break + fi + done + [ $n -ne 0 ] && echo + + # first fsck will attempt journal recovery + $fsck -fy /dev/$md > $log 2>&1 + + # The second fsck will do traditional check for any errors + # from journal recovery + + # There seems to be a gnop cache issue, which resolves by adding + # delays between each fsck run + for i in `jot $fsck_loops`; do + sleep $((i * i)) # gnop workaround + [ $i -ne 1 ] && + echo "`date +%T` $fsck loop #$((i + 1))" + $fsck -fy /dev/$md > $log 2>&1 + grep -Eq "IS CLEAN|MARKED CLEAN" $log && break + [ $i -eq $fsck_loops ] && + { echo "$fsck did not mark FS as clean"; exit 1; } + [ $i -ne 1 ] && tail -3 $log + sync; sleep 5; sync; sleep 5 + done +done +echo "Final $fsck" +sleep 3; # gnop workaround +$fsck -fy /dev/$md > $log || { tail -5 $log; exit 1; } +mdconfig -d -u ${md#md} +rm -f $log +exit 0 diff --git a/tools/test/stress2/misc/gpt.sh b/tools/test/stress2/misc/gpt.sh new file mode 100755 index 000000000000..51b4ba39afda --- /dev/null +++ b/tools/test/stress2/misc/gpt.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Bug 237269 - panic in glabel (g_label_destroy) stop after resizing GPT +# partition. +# "panic: vm_fault_hold: fault on nofault entry, addr: 0 from +# g_slice_spoiled+0x7" +# Test scenario by andrew@tao11.riddles.org.uk + +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +md_unit=$(mdconfig -t swap -s 30MB) +geom part create -s GPT "$md_unit" +geom part add -s 10M -t linux-swap -l tst0 "$md_unit" +geom part resize -i 1 -s 20M "$md_unit" + +# at this point "glabel status" shows two gpt/tst0 entries, +# one of which has no consumer; trying to correct this causes +# a panic: + +glabel stop gpt/tst0 +glabel stop gpt/tst0 # BOOM + +mdconfig -d -u $md_unit + +exit 0 diff --git a/tools/test/stress2/misc/graid0.sh b/tools/test/stress2/misc/graid0.sh new file mode 100755 index 000000000000..5887d50f5739 --- /dev/null +++ b/tools/test/stress2/misc/graid0.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Protection fault seen: +# https://people.freebsd.org/~pho/stress/log/graid0.txt +# Fixed by r327721-23 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +md1=$mdstart +md2=$((mdstart + 1)) +md3=$((mdstart + 2)) + +size=1g +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le 4 ] && + size=512m + +for u in $md1 $md2 $md3; do + mdconfig -l | grep -q md$u && mdconfig -d -u $u + mdconfig -a -t swap -s $size -u $u +done + +gstripe load > /dev/null 2>&1 && unload=1 +gstripe label -v -s 131072 data /dev/md$md1 /dev/md$md2 /dev/md$md3 > \ + /dev/null || exit 1 +[ -c /dev/stripe/data ] || exit 1 +newfs $newfs_flags /dev/stripe/data > /dev/null +mount /dev/stripe/data $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' +while mount | grep $mntpoint | grep -q /stripe/; do + umount $mntpoint || sleep 1 +done +gstripe stop data && s=0 || s=1 +[ $unload ] && gstripe unload + +for u in $md3 $md2 $md1; do + mdconfig -d -u $u +done +exit $s diff --git a/tools/test/stress2/misc/graid1.sh b/tools/test/stress2/misc/graid1.sh new file mode 100755 index 000000000000..eea4aa80b97b --- /dev/null +++ b/tools/test/stress2/misc/graid1.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# No problems seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +md1=$mdstart +md2=$((mdstart + 1)) +md3=$((mdstart + 2)) + +s=0 +size=1g +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le 4 ] && + size=512m + +for u in $md1 $md2 $md3; do + mdconfig -l | grep -q md$u && mdconfig -d -u $u + mdconfig -a -t swap -s $size -u $u +done + +gmirror load > /dev/null 2>&1 && unload=1 +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null +gmirror label -v -b split -s 2048 data /dev/md$md1 /dev/md$md2 \ + /dev/md$md3 > /dev/null || exit 1 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) +[ -c /dev/mirror/data ] || exit 1 +newfs $newfs_flags /dev/mirror/data > /dev/null +mount /dev/mirror/data $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +checkfs /dev/mirror/data || s=1 +gmirror stop data || s=2 +gmirror destroy data 2>/dev/null +[ $unload ] && gmirror unload + +for u in $md3 $md2 $md1; do + mdconfig -d -u $u || s=3 +done +exit $s diff --git a/tools/test/stress2/misc/graid1_10.sh b/tools/test/stress2/misc/graid1_10.sh new file mode 100755 index 000000000000..51a5e0260914 --- /dev/null +++ b/tools/test/stress2/misc/graid1_10.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# Read error handling for synchronization requests +# Test scenario by Mark Johnston +# Fixed by r327779 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +md1=$mdstart +md2=$((mdstart + 1)) + +s=0 +size=1g +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le 4 ] && + size=512m + +for u in $md1 $md2; do + mdconfig -l | grep -q md$u && mdconfig -d -u $u + mdconfig -a -t swap -s $size -u $u +done + +gmirror load > /dev/null 2>&1 && unload=1 +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null +gmirror label -v -b split -s 2048 test /dev/md$md1 /dev/md$md2 \ + > /dev/null || exit 1 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) +[ -c /dev/mirror/test ] || exit 1 +newfs /dev/mirror/test > /dev/null +mount /dev/mirror/test $mntpoint + +gpid=`pgrep -fS "g_mirror test"` +s=0 +start=`date +%s` +roid=debug.fail_point.g_mirror_regular_request_read +while [ $((`date +%s` - start)) -lt 120 ]; do + gmirror forget test md$md2 2>/dev/null + gmirror remove test md$md2 2>/dev/null + sysctl $roid="1%return(5)[pid $gpid]" > /dev/null + gmirror insert test md$md2 + sleep 10 + sysctl $roid="off" > /dev/null + n=0 + while gmirror status test | grep -q DEGRADED; do + sleep 2 + [ $((n += 1)) -gt 30 ] && { s=1; break 2; } + done + sysctl $roid="off" > /dev/null +done +[ $s -ne 0 ] && { echo "Timed out"; gmirror status test; } + +for i in `jot 12`; do + gmirror status test | grep -q SYNCHRONIZING || break + sleep 10 +done +while mount | grep $mntpoint | grep -q /mirror/; do + umount $mntpoint || sleep 1 +done +gmirror stop test || s=2 +gmirror destroy test 2>/dev/null +[ $unload ] && gmirror unload + +for u in $md2 $md1; do + mdconfig -d -u $u || s=3 +done +exit $s diff --git a/tools/test/stress2/misc/graid1_2.sh b/tools/test/stress2/misc/graid1_2.sh new file mode 100755 index 000000000000..94d43d1646c5 --- /dev/null +++ b/tools/test/stress2/misc/graid1_2.sh @@ -0,0 +1,131 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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 scenario by Mark Johnston +# "physwr DL /tmp/graid1_2 /dev/mirror/test" seen. +# Fixed by r307691. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/graid1_2.c +mycc -o graid1_2 -Wall -Wextra -O0 -g graid1_2.c || exit 1 +rm -f graid1_2.c +cd $odir + +gmirror load > /dev/null 2>&1 && unload=1 +[ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; } +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null + +md1=$mdstart +md2=$((mdstart + 1)) +s=0 +size=$((128 * 1024)) + +for u in $md1 $md2; do + dd if=/dev/zero of=/tmp/graid1_2_di$u bs=$size count=1 status=none + [ -c /dev/md$u ] && mdconfig -d -u $u + mdconfig -a -t vnode -f /tmp/graid1_2_di$u -u $u +done +gmirror label test /dev/md$md1 /dev/md$md2 || exit 1 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) +[ -c /dev/mirror/test ] || exit 1 + +for i in `jot 150`; do /tmp/graid1_2 /dev/mirror/test; done & + +sleep 5 +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 300 ]; do + gmirror rebuild test /dev/md$md1 + sleep 2 + n=0 + while ps -lx | grep -v grep | grep graid1_2 | grep -q D; do + opid=$pid + pid=`pgrep graid1_2` + [ -z "$pid" -o "$pid" != "$opid" ] && n=0 + sleep 1 + n=$((n + 1)) + if [ $n -gt 180 ]; then + echo FAIL + ps -lx | grep -v grep | grep graid1_2 | grep D + exit 1 + fi + done +done +kill $! 2>/dev/null +pkill graid1_2 +wait + +while mount | grep $mntpoint | grep -q /mirror/; do + umount $mntpoint || sleep 1 +done +gmirror stop test || s=2 +[ $unload ] && gmirror unload + +for u in $md2 $md1; do + mdconfig -d -u $u || s=4 +done +rm -f /tmp/graid1_2 /tmp/graid1_2_di* +exit $s +EOF +/* Write last sector on disk */ +#include +#include +#include +#include +#include +#include + +static char buf[512]; + +int +main(int argc __unused, char *argv[]) +{ + time_t start; + int fd; + + if ((fd = open(argv[1], O_RDWR)) == -1) + err(1, "open(%s)", argv[1]); + start = time(NULL); + while (time(NULL) - start < 2) { + if (lseek(fd, 254 * sizeof(buf), SEEK_SET) == -1) + err(1, "seek"); + if (write(fd, buf, sizeof(buf)) != sizeof(buf)) + err(1, "write"); + } + close(fd); + + return (0); +} diff --git a/tools/test/stress2/misc/graid1_3.sh b/tools/test/stress2/misc/graid1_3.sh new file mode 100755 index 000000000000..088e395b1f2e --- /dev/null +++ b/tools/test/stress2/misc/graid1_3.sh @@ -0,0 +1,93 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test scenario by Mark Johnston + +# Page fault seen: +# https://people.freebsd.org/~pho/stress/log/graid1_3.txt + +. ../default.cfg + +gmirror load > /dev/null 2>&1 && unload=1 +[ -c /dev/mirror/markj-mirror ] && + { gmirror stop markj-mirror; gmirror destroy markj-mirror; } +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null +u1=$mdstart +u2=$((mdstart + 1)) +size=$((5 * 1024 * 1024)) +for u in $u1 $u2; do + dd if=/dev/zero of=/tmp/graid1_2_di$u bs=$size count=1 \ + status=none + [ -c /dev/md$u ] && mdconfig -d -u $u + mdconfig -a -t vnode -f /tmp/graid1_2_di$u -u $u +done +set -e + +( +gpart create -s GPT md$u1 +gpart create -s GPT md$u2 +gpart add -t freebsd-ufs -s 1M md$u1 +gpart add -t freebsd-ufs -s 1M md$u2 +) > /dev/null + +gmirror label markj-mirror md${u1}p1 +set +e + +while true; do + gmirror label markj-mirror md${u1}p1 + gmirror destroy markj-mirror +done 2>/dev/null & +pid1=$! +while true; do + gmirror insert markj-mirror md${u2}p1 + gmirror remove markj-mirror md${u2}p1 +done 2>/dev/null & +pid2=$! + +for i in `jot 60`; do + gmirror list markj-mirror + sleep 1 +done > /dev/null 2>&1 +sleep 60 + +kill $pid1 $pid2 +wait +sleep 1 + +gmirror remove markj-mirror md${u2}p1 > /dev/null 2>&1 +gmirror destroy markj-mirror > /dev/null 2>&1 + +mdconfig -d -u $u1 || exit 1 +mdconfig -d -u $u2 || exit 1 +rm -f /tmp/graid1_2_di* +[ $unload ] && gmirror unload +exit 0 diff --git a/tools/test/stress2/misc/graid1_4.sh b/tools/test/stress2/misc/graid1_4.sh new file mode 100755 index 000000000000..9f410ef9a645 --- /dev/null +++ b/tools/test/stress2/misc/graid1_4.sh @@ -0,0 +1,97 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Non UFS SU gmirror stop -f test. + +# Page fault seen: +# https://people.freebsd.org/~pho/stress/log/graid1_4.txt +# Fixed in r316867 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +rm -f $diskimage* +need=1024 # MB +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print int($4 / 1024)}'` -lt \ + $need ] && printf "Need %d MB on %s.\n" $need `dirname $diskimage` && exit + +gmirror load > /dev/null 2>&1 && unload=1 +[ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; } +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null + +md1=$mdstart +md2=$((mdstart + 1)) + +s=0 +for u in $md1 $md2; do + disk="$diskimage.$u" + dd if=/dev/zero of=$disk bs=1m count=512 status=none + [ -c /dev/md$u ] && mdconfig -d -u $u + mdconfig -a -t vnode -f $disk -u $u +done + +gmirror label -v -b split -s 2048 test /dev/md$md1 /dev/md$md2 \ + > /dev/null || exit 1 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) +[ -c /dev/mirror/test ] || exit 1 +# Soft Updates issues with removal of backing media +newfs /dev/mirror/test > /dev/null +mount /dev/mirror/test $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' & + +while kill -0 $! > /dev/null 2>&1; do + sleep `jot -r 1 1 5` + gmirror remove test md$md2 + sleep `jot -r 1 1 5` + gmirror insert test md$md2 +done +wait + +gmirror stop -f test # Note the stop *before* umount + +while mount | grep $mntpoint | grep -q /mirror/; do + umount $mntpoint || sleep 1 +done +gmirror stop test || s=1 +gmirror destroy test 2>/dev/null +[ $unload ] && gmirror unload + +for u in $md2 $md1; do + mdconfig -d -u $u || s=3 +done +rm -f $diskimage* +exit $s diff --git a/tools/test/stress2/misc/graid1_5.sh b/tools/test/stress2/misc/graid1_5.sh new file mode 100755 index 000000000000..4200a64150b8 --- /dev/null +++ b/tools/test/stress2/misc/graid1_5.sh @@ -0,0 +1,116 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Mirror tests with gnop(8) errors introduced in 2 out of three partitions. + +# https://people.freebsd.org/~pho/stress/log/graid1_5-2.txt +# Fixed by r327698 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +gmirror load > /dev/null 2>&1 && unload=1 +gmirror status > /dev/null || exit 0 + +gnop load > /dev/null && unload2=1; +gnop status > /dev/null || exit 0 + +[ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; } +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null + +u1=$mdstart +u2=$((mdstart + 1)) +u3=$((mdstart + 2)) +s=0 +for u in $u1 $u2 $u3; do + [ -c /dev/md$u ] && mdconfig -d -u $u + mdconfig -a -t swap -s 341m -u $u + gpart create -s GPT md$u +done > /dev/null + +set -e +( +gpart add -t freebsd-ufs -s 340m md$u1 +gpart add -t freebsd-ufs -s 340m md$u2 +gpart add -t freebsd-ufs -s 340m md$u3 +) > /dev/null +gnop create md$u2 +gnop create md$u3 +gmirror label test md${u1}p1 md$u2.nopp1 md$u3.nopp1 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) +[ -c /dev/mirror/test ] || exit 1 + +newfs /dev/mirror/test > /dev/null +mount /dev/mirror/test $mntpoint +set +e +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX +rm -rf /tmp/stressX.control + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 & +pid=$! + +gnop configure -r 0 -w 1 md$u2.nop +gnop configure -r 0 -w 1 md$u3.nop +while kill -0 $pid > /dev/null 2>&1; do + if ! gmirror status test | grep -q md$u2.nopp1; then + gmirror forget test + gmirror remove test md$u2.nopp1 2>/dev/null + gmirror insert test md$u2.nopp1 2>/dev/null + fi + if ! gmirror status test | grep -q md$u3.nopp1; then + gmirror forget test + gmirror remove test md$u3.nopp1 2>/dev/null + gmirror insert test md$u3.nopp1 2>/dev/null + fi + sleep 1 +done +wait + +while mount | grep $mntpoint | grep -q /mirror/; do + umount $mntpoint || sleep 5 +done +while gmirror status test | grep -q SYNCHRONIZING; do sleep 10; done +for i in `jot 10`; do + gmirror stop test && break || sleep 30 +done +[ $i -eq 10 ] && s=1 +gmirror destroy test 2>/dev/null +[ $unload ] && gmirror unload + +for u in $u1 $u2 $u3; do + mdconfig -d -u $u || s=3 +done +[ $unload2 ] && gnop unload +exit $s diff --git a/tools/test/stress2/misc/graid1_6.sh b/tools/test/stress2/misc/graid1_6.sh new file mode 100755 index 000000000000..dc85c51dad04 --- /dev/null +++ b/tools/test/stress2/misc/graid1_6.sh @@ -0,0 +1,106 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Variation of graid1_4.sh + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +rm -f $diskimage* +need=1024 # MB +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print int($4 / 1024)}'` -lt \ + $need ] && printf "Need %d MB on %s.\n" $need `dirname $diskimage` && exit + +gmirror load > /dev/null 2>&1 && unload=1 +[ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; } +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null + +md1=$mdstart +md2=$((mdstart + 1)) + +s=0 +for u in $md1 $md2; do + disk="$diskimage.$u" + dd if=/dev/zero of=$disk bs=1m count=512 status=none + [ -c /dev/md$u ] && mdconfig -d -u $u + mdconfig -a -t vnode -f $disk -u $u +done + +gmirror label -v -b split -s 2048 test /dev/md$md1 /dev/md$md2 \ + > /dev/null || exit 1 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) +[ -c /dev/mirror/test ] || exit 1 +newfs $newfs_flags /dev/mirror/test > /dev/null +mount /dev/mirror/test $mntpoint +chmod 777 $mntpoint + +mlog=/tmp/graid1_6.log +tail -F -n 0 /var/log/messages > $mlog & mpid=$! +export runRUNTIME=4m +export RUNDIR=$mntpoint/stressX +su $testuser -c 'cd ..; ./run.sh marcus.cfg > /dev/null' & + +while kill -0 $! > /dev/null 2>&1; do + sleep `jot -r 1 1 5` + gmirror remove test md$md2 + sleep `jot -r 1 1 5` + gmirror insert test md$md2 +done +wait $! +i=0 +while ! gmirror status test | grep -q COMPLETE; do + sleep 10 + if [ $((i += 1)) -gt 20 ]; then + echo "FAIL to COMPLETE" + graid status test + s=1 + break + fi +done + +while mount | grep $mntpoint | grep -q /mirror/; do + umount $mntpoint || sleep 1 +done +checkfs /dev/mirror/test || s=2 +gmirror stop -f test ||s=3 +gmirror destroy test 2>/dev/null +[ $unload ] && gmirror unload + +for u in $md2 $md1; do + mdconfig -d -u $u || s=4 +done +rm -f $diskimage* +grep -m 1 "check-hash" $mlog && s=5 +kill $mpid +wait +rm -f $mlog +exit $s diff --git a/tools/test/stress2/misc/graid1_7.sh b/tools/test/stress2/misc/graid1_7.sh new file mode 100755 index 000000000000..8280afb97e3b --- /dev/null +++ b/tools/test/stress2/misc/graid1_7.sh @@ -0,0 +1,127 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Component looses it's name: +# g_dev_taste: make_dev_p() failed +# (gp->name=gptid/7c598e03-19cb-11e7-b62b-001e6756c168, error=17) + +# Deadlock seen: +# https://people.freebsd.org/~pho/stress/log/graid1_7.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +gmirror load > /dev/null 2>&1 && unload=1 +[ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; } +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null + +u1=$mdstart +s=0 +[ -c /dev/md$u1 ] && mdconfig -d -u $u1 +mdconfig -a -t swap -s 1g -u $u1 + +set -e +( +gpart create -s GPT md$u1 +gpart add -t freebsd-ufs -s 341m md$u1 +gpart add -t freebsd-ufs -s 341m md$u1 +gpart add -t freebsd-ufs -s 341m md$u1 +) > /dev/null +gmirror label test md${u1}p1 md${u1}p2 md${u1}p3 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) +[ -c /dev/mirror/test ] || exit 1 + +newfs /dev/mirror/test > /dev/null +mount /dev/mirror/test $mntpoint +set +e +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX +rm -rf /tmp/stressX.control + +su $testuser -c 'cd ..; ./run.sh io.cfg' > /dev/null 2>&1 & +pid=$! + +mlog=/tmp/graid1_6.log +tail -F -n 0 /var/log/messages > $mlog & mpid=$! +sleep 2 +cont=/tmp/graid1_7.cont +touch $cont +for i in `jot 8`; do + while [ -f $cont ]; do + for u in md${u1}p2 md${u1}p3; do + gmirror forget test + gmirror remove test $u + gmirror insert test $u + id=`gmirror status test | grep gptid | awk '{print $1}'` + if [ $i -eq 1 -a -n "$id" ]; then + echo "FAIL Remove component $id" + gmirror remove test $id + fi + done 2>/dev/null + done & +done +while kill -0 $pid 2>/dev/null; do sleep 5; done +rm $cont +wait $! +gmirror status test | grep -qw md${u1}p2 || gmirror insert test md${u1}p2 +gmirror status test | grep -qw md${u1}p3 || gmirror insert test md${u1}p3 +i=0 +while ! gmirror status test | grep -q COMPLETE; do + sleep 5 + if [ $((i += 1)) -gt 20 ]; then + echo "FAIL to COMPLETE" + gmirror status test + s=1 + break + fi +done + +while mount | grep $mntpoint | grep -q /mirror/; do + umount $mntpoint || sleep 5 +done +checkfs /dev/mirror/test || s=2 +while gmirror status test | grep -q SYNCHRONIZING; do sleep 10; done +for i in `jot 10`; do + gmirror stop test && break || sleep 30 +done +[ $i -eq 10 ] && s=3 +gmirror destroy test 2>/dev/null +[ $unload ] && gmirror unload + +mdconfig -d -u $mdstart || s=4 +grep -m 1 "check-hash" $mlog && s=5 +kill $mpid +wait +rm -f $mlog +exit $s diff --git a/tools/test/stress2/misc/graid1_8.sh b/tools/test/stress2/misc/graid1_8.sh new file mode 100755 index 000000000000..d130a6152cf2 --- /dev/null +++ b/tools/test/stress2/misc/graid1_8.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Mirror test where the third disk is partially wiped: +# Silent Data Corruption. +# fsck() will trash your FS in this scenario. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +gmirror load > /dev/null 2>&1 && unload=1 +mount | grep -q "on $mntpoint " && umount $mntpoint +[ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; } +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null + +u1=$mdstart +u2=$((mdstart + 1)) +u3=$((mdstart + 2)) + +for u in $u1 $u2 $u3; do + [ -c /dev/md$u ] && mdconfig -d -u $u + dd if=/dev/zero of=$diskimage.$u bs=1m count=100 status=none + mdconfig -a -t vnode -f $diskimage.$u -u $u +done > /dev/null + +gmirror label test md$u1 md$u2 md$u3 || exit 1 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep 5 +( +gpart create -s BSD mirror/test +gpart add -t freebsd-ufs -s 99m mirror/test +) > /dev/null +[ -c /dev/mirror/testa ] || exit 1 + +newfs -n /dev/mirror/testa > /dev/null +mount /dev/mirror/testa $mntpoint +jot 10 | xargs -P0 -I% cp /etc/passwd $mntpoint/% + +# The test: zap part of the third disk +dd if=/dev/random of=$diskimage.$u3 bs=1m count=80 conv=notrunc status=none +umount $mntpoint +log=/tmp/graid1_8.sh.log + +if [ $# -eq 1 ]; then # This will fix the mirror + gmirror remove test md$u3 + gmirror insert test md$u3 + while gmirror status test | grep -q SYNCHRONIZING; do + sleep 2 + done +fi + +fsck -fy /dev/mirror/testa > $log 2>&1 +grep -q RERUN $log && fsck -fy /dev/mirror/testa > /dev/null 2>&1 +grep -Eq "MODIFIED|BAD" $log && + { s=1; head -5 $log; } || + s=0 +rm $log +mount /dev/mirror/testa $mntpoint +[ `ls $mntpoint | wc -l` -lt 10 ] && ls -l $mntpoint +umount $mntpoint + +while gmirror status test | grep -q SYNCHRONIZING; do sleep 10; done +for i in `jot 10`; do + gmirror stop test && break || sleep 30 +done +[ $i -eq 10 ] && s=1 +gmirror destroy test 2>/dev/null +[ $unload ] && gmirror unload + +for u in $u1 $u2 $u3; do + mdconfig -d -u $u || s=3 + rm $diskimage.$u +done +exit $s diff --git a/tools/test/stress2/misc/graid1_9.sh b/tools/test/stress2/misc/graid1_9.sh new file mode 100755 index 000000000000..8d8d447b25b0 --- /dev/null +++ b/tools/test/stress2/misc/graid1_9.sh @@ -0,0 +1,114 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# Copy of graid1.sh with fail points added. +# https://people.freebsd.org/~pho/stress/log/mark015.txt +# Fixed by r327779 + +# Problem also seen with non SU: +# https://people.freebsd.org/~pho/stress/log/numa027.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +md1=$mdstart +md2=$((mdstart + 1)) +md3=$((mdstart + 2)) + +s=0 +size=1g +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le 4 ] && + size=512m + +for u in $md1 $md2 $md3; do + mdconfig -l | grep -q md$u && mdconfig -d -u $u + mdconfig -a -t swap -s $size -u $u +done + +gmirror load > /dev/null 2>&1 && unload=1 +old=`sysctl -n kern.geom.mirror.debug` +sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || + sysctl kern.geom.mirror.debug=$old > /dev/null +gmirror label -v -b split -s 2048 test /dev/md$md1 /dev/md$md2 \ + /dev/md$md3 > /dev/null || exit 1 +[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && + sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) +[ -c /dev/mirror/test ] || exit 1 +# Do not use SU as it is more intolerant to FS corruption +newfs /dev/mirror/test > /dev/null +mount /dev/mirror/test $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +woid=debug.fail_point.g_mirror_regular_request_write +roid=debug.fail_point.g_mirror_regular_request_read +gpid=`pgrep -fS "g_mirror test"` +sysctl $woid="0.0005%return(5)[pid $gpid]" > /dev/null +sysctl $roid="0.0005%return(5)[pid $gpid]" > /dev/null + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null & + +while kill -0 $! 2>/dev/null; do + if gmirror status test | grep -q DEGRADED; then + for i in $md1 $md2 $md3; do + if ! gmirror status test | grep -q md$i; then + gmirror forget test md$i 2>/dev/null + gmirror remove test md$i 2>/dev/null + gmirror insert test md$i + fi + done + else + sleep 5 + fi +done +wait + +sysctl $woid=off > /dev/null +sysctl $roid=off > /dev/null + +for i in `jot 12`; do + gmirror status test | grep -q SYNCHRONIZING || break + sleep 10 +done +gmirror status test | grep -q SYNCHRONIZING && + { s=1; gmirror status test; } +while mount | grep $mntpoint | grep -q /mirror/; do + umount $mntpoint || sleep 1 +done +# The FS is most likely corrupted at this point, so do not run fsck(8). +gmirror stop test || s=2 +gmirror destroy test 2>/dev/null +[ $unload ] && gmirror unload + +for u in $md3 $md2 $md1; do + mdconfig -d -u $u || s=3 +done +exit $s diff --git a/tools/test/stress2/misc/graid3.sh b/tools/test/stress2/misc/graid3.sh new file mode 100755 index 000000000000..f67ac819a47d --- /dev/null +++ b/tools/test/stress2/misc/graid3.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Probably unrelated mkfifo() problem seen: +# http://people.freebsd.org/~pho/stress/log/graid3.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +md1=$mdstart +md2=$((mdstart + 1)) +md3=$((mdstart + 2)) + +size=1g +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le 4 ] && + size=512m + +for u in $md1 $md2 $md3; do + mdconfig -l | grep -q md$u && mdconfig -d -u $u + mdconfig -a -t swap -s $size -u $u +done + +graid3 load > /dev/null 2>&1 && unload=1 +graid3 label -v -r data md$md1 md$md2 md$md3 > /dev/null || exit 1 +[ -c /dev/raid3/data ] || exit 1 +newfs $newfs_flags /dev/raid3/data > /dev/null +mount /dev/raid3/data $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' + +while mount | grep $mntpoint | grep -q raid3; do + umount $mntpoint || sleep 1 +done + +graid3 stop data && s=0 || s=1 +[ $unload ] && graid3 unload + +for u in $md3 $md2 $md1; do + mdconfig -d -u $u +done +exit $s diff --git a/tools/test/stress2/misc/growfs.sh b/tools/test/stress2/misc/growfs.sh new file mode 100755 index 000000000000..5a2ec3f609d3 --- /dev/null +++ b/tools/test/stress2/misc/growfs.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# growfs(8) test +# "checksum failed: cg 52, cgp: 0x0 != bp: 0xe35de2ca" seen. +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222876 +# Fixed by r324499 + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +s=0 +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 32g -u $mdstart +/sbin/gpart create -s GPT md$mdstart +/sbin/gpart add -t freebsd-ufs -s 2g -a 4k md$mdstart +set +e + +newfs $newfs_flags md${mdstart}p1 > /dev/null +mount /dev/md${mdstart}p1 $mntpoint +cp -r /usr/include $mntpoint/inc1 +umount $mntpoint +checkfs /dev/md${mdstart}p1 || { s=1; echo "Initial fsck 1 fail"; } + +gpart resize -i 1 -s 31g -a 4k md$mdstart +growfs -y md${mdstart}p1 > /dev/null +# This fsck make the checksum error go away +#checkfs /dev/md${mdstart}p1 || { s=1; echo "fsck after growfs fail"; } + +mount /dev/md${mdstart}p1 $mntpoint +cp -r /usr/include $mntpoint/inc2 +umount $mntpoint +checkfs /dev/md${mdstart}p1 || { s=1; echo "Final fsck fail"; } + +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/holdcnt0.sh b/tools/test/stress2/misc/holdcnt0.sh new file mode 100755 index 000000000000..7a35eb1dbf5f --- /dev/null +++ b/tools/test/stress2/misc/holdcnt0.sh @@ -0,0 +1,261 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# "panic: cluster_wbuild: page 0xc2eebc10 failed shared busing" seen. +# "panic: vdrop: holdcnt 0" seen. +# "panic: cleaned vnode isn't" seen. +# OoVM seen with r285808: +# https://people.freebsd.org/~pho/stress/log/holdcnt0.txt + +# Test scenario suggestion by alc@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +[ `sysctl -n hw.physmem` -lt $((32 * 1024 * 1024 * 1024)) ] && exit 0 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > holdcnt0.c +mycc -o holdcnt0 -Wall -Wextra -g holdcnt0.c || exit 1 +rm -f holdcnt0.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 5g -u $mdstart +bsdlabel -w md$mdstart auto +newfs md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +(cd $mntpoint; /tmp/holdcnt0) & +pid=$! +sleep 5 +while kill -0 $! 2> /dev/null; do + (cd ../testcases/swap; ./swap -t 1m -i 1) > /dev/null 2>&1 +done +wait $pid; s=$? + +while mount | grep -q md${mdstart}$part; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/holdcnt0 +exit $s +EOF +/* + A test that causes the page daemon to generate cached pages + within a bunch of files and has some consumer that is trying to + allocate new pages to the same files. +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFSIZE (1024 * 1024) +#define FILES 200 +#define RPARALLEL 8 +#define WPARALLEL 2 + +static jmp_buf jbuf; +static off_t maxsize; +static int ps; +static char *buf; +static volatile char val; + +static void +hand(int i __unused) { /* handler */ + +#if defined(DEBUG) + fprintf(stderr, "%d ", i); +#endif + longjmp(jbuf, 1); +} + +static void +cleanup(void) +{ + int i; + char file[80]; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + unlink(file); + } +} + +static void +init(void) +{ + int fd, i; + char file[80]; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) == + -1) + err(1, "open(%s)", file); + if (write(fd, buf, BUFSIZE) != BUFSIZE) + err(1, "write"); + close(fd); + } + +} + +static void +writer(void) +{ + struct stat statbuf; + time_t start; + int fd, i; + char file[80]; + + setproctitle("writer"); + start = time(NULL); + while (time(NULL) - start < 600) { + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_APPEND)) == -1) { + if (errno != ENOENT) + err(1, "open(%s) append", file); + goto err; + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size < maxsize) { + if (write(fd, buf, ps) != ps) { + warn("writer"); + goto err; + } + } + close(fd); + } + } +err: + cleanup(); + + _exit(0); +} + +static void +reader(void) +{ + struct stat statbuf; + void *p; + size_t len; + int fd, i, j, n; + char file[80]; + + setproctitle("reader"); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + fd = 0; + for (;;) { + (void)setjmp(jbuf); + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if (fd > 0) + close(fd); + if ((fd = open(file, O_RDWR)) == -1) { + if (errno != ENOENT) + warn("reader(%s)", file); + _exit(0); + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size >= maxsize) { + if (ftruncate(fd, ps) == -1) + err(1, "ftruncate"); + continue; + } + len = statbuf.st_size; + if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0)) + == MAP_FAILED) + err(1, "mmap()"); + close(fd); + n = statbuf.st_size / ps; + for (j = 0; j < n; j++) { + val = *(char *)p; + p = p + ps; + } +#if 0 + if (munmap(p, len) == -1) + perror("munmap"); +#endif + } + } + _exit(0); +} +int +main(void) +{ + pid_t rpid[RPARALLEL], wpid[WPARALLEL]; + int e, i, s; + + maxsize = 2LL * 1024 * 1024 * 1024 / FILES; + buf = malloc(BUFSIZE); + ps = getpagesize(); + + init(); + e = 0; + for (i = 0; i < WPARALLEL; i++) { + if ((wpid[i] = fork()) == 0) + writer(); + } + for (i = 0; i < RPARALLEL; i++) { + if ((rpid[i] = fork()) == 0) + reader(); + } + + for (i = 0; i < WPARALLEL; i++) { + waitpid(wpid[i], &s, 0); + if (e == 0) + e = s; + } + for (i = 0; i < RPARALLEL; i++) { + waitpid(rpid[i], &s, 0); + if (e == 0) + e = s; + } + free(buf); + + return (e); +} diff --git a/tools/test/stress2/misc/holdcnt02.sh b/tools/test/stress2/misc/holdcnt02.sh new file mode 100755 index 000000000000..671d068917f0 --- /dev/null +++ b/tools/test/stress2/misc/holdcnt02.sh @@ -0,0 +1,238 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Copy of holdcnt0.sh, but without the memory disk usage. + +# Test scenario suggestion by alc@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +[ `sysctl -n hw.physmem` -lt $((32 * 1024 * 1024 * 1024)) ] && exit 0 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > holdcnt02.c +mycc -o holdcnt02 -Wall -Wextra -g holdcnt02.c || exit 1 +rm -f holdcnt02.c +cd $here + +trap "rm -f /tmp/holdcnt02 `dirname $diskimage`/f000???" EXIT INT +(cd `dirname $diskimage`; /tmp/holdcnt02) & +pid=$! +sleep 5 +while kill -0 $! 2> /dev/null; do + (cd ../testcases/swap; ./swap -t 1m -i 1) > /dev/null 2>&1 +done +wait $pid +exit +EOF +/* + A test that causes the page daemon to generate cached pages + within a bunch of files and has some consumer that is trying to + allocate new pages to the same files. +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFSIZE (1024 * 1024) +#define FILES 200 +#define RPARALLEL 8 +#define WPARALLEL 2 + +static jmp_buf jbuf; +static off_t maxsize; +static int ps; +static char *buf; +static volatile char val; + +static void +hand(int i __unused) { /* handler */ + longjmp(jbuf, 1); +} + +static void +cleanup(void) +{ + int i; + char file[80]; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + unlink(file); + } +} + +static void +init(void) +{ + int fd, i; + char file[80]; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) == + -1) + err(1, "open(%s)", file); + if (write(fd, buf, BUFSIZE) != BUFSIZE) + err(1, "write"); + close(fd); + } + +} + +static void +writer(void) +{ + int fd, i; + char file[80]; + time_t start; + struct stat statbuf; + + setproctitle("writer"); + start = time(NULL); + while (time(NULL) - start < 600) { + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_APPEND)) == -1) { + if (errno != ENOENT) + err(1, "open(%s) append", file); + goto err; + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size < maxsize) { + if (write(fd, buf, ps) != ps) { + warn("writer"); + goto err; + } + } + close(fd); + } + } +err: + cleanup(); + + _exit(0); +} + +static void +reader(void) +{ + int fd, i, j, n; + void *p; + size_t len; + char file[80]; + struct stat statbuf; + + setproctitle("reader"); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + fd = 0; + for (;;) { + (void)setjmp(jbuf); + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if (fd > 0) + close(fd); + if ((fd = open(file, O_RDWR)) == -1) { + if (errno != ENOENT) + warn("reader(%s)", file); + _exit(0); + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size >= maxsize) { + if (ftruncate(fd, ps) == -1) + err(1, "ftruncate"); + continue; + } + len = statbuf.st_size; + if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0)) + == MAP_FAILED) + err(1, "mmap()"); + close(fd); + n = statbuf.st_size / ps; + for (j = 0; j < n; j++) { + val = *(char *)p; + p = p + ps; + } +#if 0 + if (munmap(p, len) == -1) + perror("munmap"); +#endif + } + } + _exit(0); +} +int +main(void) +{ + pid_t rpid[RPARALLEL], wpid[WPARALLEL]; + int e, i, s; + + maxsize = 2LL * 1024 * 1024 * 1024 / FILES; + buf = malloc(BUFSIZE); + ps = getpagesize(); + + init(); + e = 0; + for (i = 0; i < WPARALLEL; i++) { + if ((wpid[i] = fork()) == 0) + writer(); + } + for (i = 0; i < RPARALLEL; i++) { + if ((rpid[i] = fork()) == 0) + reader(); + } + + for (i = 0; i < WPARALLEL; i++) + waitpid(wpid[i], &s, 0); + e += s == 0 ? 0 : 1; + for (i = 0; i < RPARALLEL; i++) + waitpid(rpid[i], &s, 0); + e += s == 0 ? 0 : 1; + + free(buf); + + return (e); +} diff --git a/tools/test/stress2/misc/holdcnt03.sh b/tools/test/stress2/misc/holdcnt03.sh new file mode 100755 index 000000000000..35437c06e707 --- /dev/null +++ b/tools/test/stress2/misc/holdcnt03.sh @@ -0,0 +1,237 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Copy of holdcnt02.sh, but with mmap'ed write. +# Use 16 GB RAM or less. +# Deadlock seen: +# https://people.freebsd.org/~pho/stress/log/alan018.txt + +# Test scenario suggestion by alc@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +[ `sysctl -n hw.physmem` -lt $((32 * 1024 * 1024 * 1024)) ] && exit 0 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > holdcnt03.c +mycc -o holdcnt03 -Wall -Wextra -g holdcnt03.c || exit 1 +rm -f holdcnt03.c +cd $here + +trap "rm -f /tmp/holdcnt03 `dirname $diskimage`/f000???" EXIT INT +(cd `dirname $diskimage`; /tmp/holdcnt03) & +pid=$! +sleep 5 +while kill -0 $! 2> /dev/null; do + (cd ../testcases/swap; ./swap -t 1m -i 1) > /dev/null 2>&1 +done +wait $pid +exit +EOF +/* + A test that causes the page daemon to generate cached pages + within a bunch of files and has some consumer that is trying to + allocate new pages to the same files. +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFSIZE (1024 * 1024) +#define FILES 200 +#define RPARALLEL 8 +#define WPARALLEL 2 + +static jmp_buf jbuf; +static off_t maxsize; +static int ps; +static char *buf; + +static void +hand(int i __unused) { /* handler */ + longjmp(jbuf, 1); +} + +static void +cleanup(void) +{ + int i; + char file[80]; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + unlink(file); + } +} + +static void +init(void) +{ + char file[80]; + int fd, i; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) + err(1, "open(%s)", file); + if (write(fd, buf, BUFSIZE) != BUFSIZE) + err(1, "write"); + close(fd); + } + +} + +static void +writer(void) +{ + int fd, i; + char file[80]; + time_t start; + struct stat statbuf; + + setproctitle("writer"); + start = time(NULL); + while (time(NULL) - start < 600) { + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_APPEND)) == -1) { + if (errno != ENOENT) + err(1, "open(%s) append", file); + goto err; + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size < maxsize) { + if (write(fd, buf, ps) != ps) { + warn("writer"); + goto err; + } + } + close(fd); + } + } +err: + cleanup(); + + _exit(0); +} + +static void +touch(void) +{ + int fd, i, j, n; + void *p; + size_t len; + char file[80]; + struct stat statbuf; + + setproctitle("touch"); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + fd = 0; + for (;;) { + (void)setjmp(jbuf); + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if (fd > 0) + close(fd); + if ((fd = open(file, O_RDWR)) == -1) { + if (errno != ENOENT) + warn("touch(%s)", file); + _exit(0); + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size >= maxsize) { + if (ftruncate(fd, ps) == -1) + err(1, "ftruncate"); + continue; + } + len = statbuf.st_size; + if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) + err(1, "mmap()"); + close(fd); + n = statbuf.st_size / ps; + for (j = 0; j < n; j++) { + *(char *)p = 1; + p = p + ps; + } + if (munmap(p, len) == -1) + perror("munmap"); + } + } + _exit(0); +} + +int +main(void) +{ + pid_t rpid[RPARALLEL], wpid[WPARALLEL]; + int e, i, s; + + maxsize = 2LL * 1024 * 1024 * 1024 / FILES; + buf = malloc(BUFSIZE); + ps = getpagesize(); + + init(); + e = 0; + for (i = 0; i < WPARALLEL; i++) { + if ((wpid[i] = fork()) == 0) + writer(); + } + for (i = 0; i < RPARALLEL; i++) { + if ((rpid[i] = fork()) == 0) + touch(); + } + + for (i = 0; i < WPARALLEL; i++) + waitpid(wpid[i], &s, 0); + e += s == 0 ? 0 : 1; + for (i = 0; i < RPARALLEL; i++) + waitpid(rpid[i], &s, 0); + e += s == 0 ? 0 : 1; + + free(buf); + + return (e); +} diff --git a/tools/test/stress2/misc/holdcnt04.sh b/tools/test/stress2/misc/holdcnt04.sh new file mode 100755 index 000000000000..52aff0e3816d --- /dev/null +++ b/tools/test/stress2/misc/holdcnt04.sh @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Lite version of holdcnt0.sh + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `sysctl -n vm.swap_total` -ne 0 ] && exit 0 +[ `sysctl -n hw.physmem` -lt 5250000000 ] && exit 0 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > holdcnt04.c +mycc -o holdcnt04 -Wall -Wextra -g holdcnt04.c || exit 1 +rm -f holdcnt04.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +(cd $mntpoint; /tmp/holdcnt04) & +pid=$! +sleep 5 +while kill -0 $! 2> /dev/null; do + (cd ../testcases/swap; ./swap -t 1m -i 1) > /dev/null 2>&1 +done +wait $pid; s=$? + +while mount | grep -q md${mdstart}$part; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/holdcnt04 +exit $s +EOF +/* + A test that causes the page daemon to generate cached pages + within a bunch of files and has some consumer that is trying to + allocate new pages to the same files. +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFSIZE (1024 * 1024) +#define FILES 20 +#define RPARALLEL 8 +#define WPARALLEL 2 + +static jmp_buf jbuf; +static off_t maxsize; +static int ps; +static char *buf; +static volatile char val; + +static void +hand(int i __unused) { /* handler */ + longjmp(jbuf, 1); +} + +static void +cleanup(void) +{ + int i; + char file[80]; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + unlink(file); + } +} + +static void +init(void) +{ + int fd, i; + char file[80]; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) == + -1) + err(1, "open(%s)", file); + if (write(fd, buf, BUFSIZE) != BUFSIZE) + err(1, "write"); + close(fd); + } + +} + +static void +writer(void) +{ + struct stat statbuf; + time_t start; + int fd, i; + char file[80]; + + setproctitle("writer"); + start = time(NULL); + while (time(NULL) - start < 600) { + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_APPEND)) == -1) { + if (errno != ENOENT) + err(1, "open(%s) append", file); + goto err; + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size < maxsize) { + if (write(fd, buf, ps) != ps) { + warn("writer"); + goto err; + } + } + close(fd); + } + } +err: + cleanup(); + + _exit(0); +} + +static void +reader(void) +{ + struct stat statbuf; + void *p; + size_t len; + int fd, i, j, n; + char file[80]; + + setproctitle("reader"); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + fd = 0; + for (;;) { + (void)setjmp(jbuf); + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if (fd > 0) + close(fd); + if ((fd = open(file, O_RDWR)) == -1) { + if (errno != ENOENT) + warn("reader(%s)", file); + _exit(0); + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size >= maxsize) { + if (ftruncate(fd, ps) == -1) + err(1, "ftruncate"); + continue; + } + len = statbuf.st_size; + if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0)) + == MAP_FAILED) + err(1, "mmap()"); + close(fd); + n = statbuf.st_size / ps; + for (j = 0; j < n; j++) { + val = *(char *)p; + p = p + ps; + } +#if 0 + if (munmap(p, len) == -1) + perror("munmap"); +#endif + } + } + _exit(0); +} +int +main(void) +{ + pid_t rpid[RPARALLEL], wpid[WPARALLEL]; + int e, i, s; + + maxsize = 1LL * 1024 * 1024 * 1024 / FILES; + buf = malloc(BUFSIZE); + ps = getpagesize(); + + init(); + e = 0; + for (i = 0; i < WPARALLEL; i++) { + if ((wpid[i] = fork()) == 0) + writer(); + } + for (i = 0; i < RPARALLEL; i++) { + if ((rpid[i] = fork()) == 0) + reader(); + } + + for (i = 0; i < WPARALLEL; i++) + waitpid(wpid[i], &s, 0); + e += s == 0 ? 0 : 1; + for (i = 0; i < RPARALLEL; i++) + waitpid(rpid[i], &s, 0); + e += s == 0 ? 0 : 1; + + free(buf); + + return (e); +} diff --git a/tools/test/stress2/misc/holdcnt05.sh b/tools/test/stress2/misc/holdcnt05.sh new file mode 100755 index 000000000000..efafa984bdd8 --- /dev/null +++ b/tools/test/stress2/misc/holdcnt05.sh @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Tmpfs version of holdcnt0.sh +# Test scenario suggestion by alc@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +[ `sysctl -n hw.physmem` -lt $((32 * 1024 * 1024 * 1024)) ] && exit 0 + +. ../default.cfg +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > holdcnt05.c +cc -o holdcnt05 -Wall -Wextra -g holdcnt05.c || exit 1 +rm -f holdcnt05.c +cd $here + +mount | grep $mntpoint && umount -f $mntpoint +mount -t tmpfs null $mntpoint + +cd $mntpoint +/tmp/holdcnt05 +s=$? + +cd / +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +rm -f /tmp/holdcnt05 +[ $s -ne 0 ] && echo "Exit status $s" +exit $s +EOF +/* + A test that causes the page daemon to generate cached pages + within a bunch of files and has some consumer that is trying to + allocate new pages to the same files. +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFSIZE (1024 * 1024) +#define FILES 200 +#define RPARALLEL 8 +#define WPARALLEL 2 + +static jmp_buf jbuf; +static off_t maxsize; +static int ps; +static char *buf; +static volatile char val; + +static void +hand(int i __unused) { /* handler */ + +#if defined(DEBUG) + fprintf(stderr, "%d ", i); +#endif + longjmp(jbuf, 1); +} + +static void +cleanup(void) +{ + int i; + char file[80]; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + unlink(file); + } +} + +static void +init(void) +{ + int fd, i; + char file[80]; + + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) == + -1) + err(1, "open(%s)", file); + if (write(fd, buf, BUFSIZE) != BUFSIZE) + err(1, "write"); + close(fd); + } + +} + +static void +writer(void) +{ + struct stat statbuf; + time_t start; + int fd, i; + char file[80]; + + setproctitle("writer"); + start = time(NULL); + while (time(NULL) - start < 600) { + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if ((fd = open(file, O_RDWR | O_APPEND)) == -1) { + if (errno != ENOENT) + err(1, "open(%s) append", file); + goto err; + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size < maxsize) { + if (write(fd, buf, ps) != ps) { + warn("writer"); + goto err; + } + } + close(fd); + } + } +err: + cleanup(); + + _exit(0); +} + +static void +reader(void) +{ + struct stat statbuf; + void *p; + size_t len; + int fd, i, j, n; + char file[80]; + + setproctitle("reader"); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + fd = 0; + for (;;) { + (void)setjmp(jbuf); + for (i = 0; i < FILES; i++) { + snprintf(file, sizeof(file), "f%06d", i); + if (fd > 0) + close(fd); + if ((fd = open(file, O_RDWR)) == -1) { + if (errno != ENOENT) + warn("reader(%s)", file); + _exit(0); + } + if (fstat(fd, &statbuf) < 0) + err(1, "fstat error"); + if (statbuf.st_size >= maxsize) { + if (ftruncate(fd, ps) == -1) + err(1, "ftruncate"); + continue; + } + len = statbuf.st_size; + if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0)) + == MAP_FAILED) + err(1, "mmap()"); + close(fd); + n = statbuf.st_size / ps; + for (j = 0; j < n; j++) { + val = *(char *)p; + p = p + ps; + } +#if 0 + if (munmap(p, len) == -1) + perror("munmap"); +#endif + } + } + _exit(0); +} +int +main(void) +{ + pid_t rpid[RPARALLEL], wpid[WPARALLEL]; + int e, i, s; + + maxsize = 2LL * 1024 * 1024 * 1024 / FILES; + buf = malloc(BUFSIZE); + ps = getpagesize(); + + init(); + e = 0; + for (i = 0; i < WPARALLEL; i++) { + if ((wpid[i] = fork()) == 0) + writer(); + } + for (i = 0; i < RPARALLEL; i++) { + if ((rpid[i] = fork()) == 0) + reader(); + } + + for (i = 0; i < WPARALLEL; i++) { + waitpid(wpid[i], &s, 0); + if (e == 0) + e = s; + } + for (i = 0; i < RPARALLEL; i++) { + waitpid(rpid[i], &s, 0); + if (e == 0) + e = s; + } + free(buf); + + return (e); +} diff --git a/tools/test/stress2/misc/ifconfig.sh b/tools/test/stress2/misc/ifconfig.sh new file mode 100755 index 000000000000..6359711a0445 --- /dev/null +++ b/tools/test/stress2/misc/ifconfig.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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 scenario from D17599 "Fix for double free when deleting entries from +# epoch managed lists" +# by Hans Petter Selasky + +# "panic: starting DAD on non-tentative address 0xfffff8010c311000" seen. +# https://people.freebsd.org/~pho/stress/log/epoch.txt + +# Fatal trap 9: general protection fault while in kernel mode +# https://people.freebsd.org/~pho/stress/log/epoch-2.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +if=`ifconfig | grep -w mtu | grep -v RUNNING | sed 's/:.*//' | head -1` +[ -z "$if" ] && + if=`ifconfig | \ + awk '/^[a-z].*: / {gsub(":", ""); ifn = $1}; /no car/{print ifn; exit}'` + +[ -z "$if" ] && exit 0 +echo "Using $if for test." +ifconfig $if | grep -q RUNNING && running=1 + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 300 ]; do + for i in `jot 255`; do + (ifconfig $if.$i create + ifconfig $if.$i inet 224.0.0.$i + ifconfig $if.$i destroy) > /dev/null 2>&1 & + done + wait +done +[ $running ] || ifconfig $if down + +exit 0 diff --git a/tools/test/stress2/misc/ifconfig2.sh b/tools/test/stress2/misc/ifconfig2.sh new file mode 100755 index 000000000000..61abbab3dd54 --- /dev/null +++ b/tools/test/stress2/misc/ifconfig2.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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 scenario from D17599 "Fix for double free when deleting entries from +# epoch managed lists" +# by Hans Petter Selasky + +# Page fault in nd6_dad_timer+0x6b seen: +# https://people.freebsd.org/~pho/stress/log/ifconfig2.txt +# https://people.freebsd.org/~pho/stress/log/log0051.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +if=`ifconfig | grep -w mtu | grep -v RUNNING | sed 's/:.*//' | head -1` +[ -z "$if" ] && + if=`ifconfig | \ + awk '/^[a-z].*: / {gsub(":", ""); ifn = $1}; /no car/{print ifn; exit}'` + +[ -z "$if" ] && exit 0 +echo "Using $if for test." +ifconfig $if | grep -q RUNNING && running=1 + +sync=/tmp/`basename $0`.sync +rm -f $sync +for i in `jot 5`; do + ( + while [ ! -f $sync ]; do + sleep .1 + done + while [ -f $sync ]; do + ifconfig $if.$i create + ifconfig $if.$i inet 224.0.0.$i + ifconfig $if.$i destroy + done + ) > /dev/null 2>&1 & +done +touch $sync +sleep 120 +rm -f $sync +wait +[ $running ] || ifconfig $if down + +exit 0 diff --git a/tools/test/stress2/misc/indir.sh b/tools/test/stress2/misc/indir.sh new file mode 100755 index 000000000000..d2d28cd650ab --- /dev/null +++ b/tools/test/stress2/misc/indir.sh @@ -0,0 +1,201 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# Hunt for "panic: ufsdirhash_dirtrunc: bad offset" +# by making the directory inode grow into the indirect blocks. + +# Truncate directories larger than 12 * block_size bytes +# default is 12 * 32768 = 393216, 384k + +# No problems seen. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/indir.c +sed -i '' -e "s#MNTPOINT#$mntpoint#g" $dir/indir.c +mycc -o indir -Wall -Wextra -O0 -g indir.c || exit 1 +rm -f indir.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +newfs -j -n -b 16384 -f 2048 -i 2048 md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +ifree=`df -i $mntpoint | tail -1 | awk '{print $7 - 50}'` +set +e + +if [ $dtrace ]; then + dtrace -w -n '*ufsdirhash_dirtrunc:entry {@rw[execname,probefunc] = \ + count(); }' & + dpid=$! + sleep 2 +fi + +/tmp/indir $mntpoint $ifree + +if [ $dtrace ]; then + kill -s TERM $dpid + wait $dpid +fi + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -f /tmp/indir +if [ $dtrace ]; then + while pgrep -q dtrace; do sleep 1; done + kldstat | grep -q dtraceall && + kldunload dtraceall.ko +fi +exit 0 +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static long files; +static char *path; + +#define PARALLEL 64 +#define RUNTIME (10 * 60) + +static void +test(int idx) +{ + long j; + int fd; + pid_t pid; + char dir[128], file[128], new[128]; + + sleep(1); + + snprintf(dir, sizeof(dir), "%s/d%d", path, idx); + if (mkdir(dir, 0755) == -1) { + if (errno != EEXIST) + err(1, "mkdir(%s)", dir); + } + if (chdir(dir) == -1) + err(1, "chdir(%s)", dir); + + pid = getpid(); + for (j = 0; j < files; j++) { + sprintf(file,"p%05d.%05ld", pid, j); + if ((fd = creat(file, 0660)) == -1) + err(1, "creat(%s). %s:%d", file, __FILE__, __LINE__); + if (fd != -1 && close(fd) == -1) + err(2, "close(%ld)", j); + } + + for (j = 0; j < files; j++) { + sprintf(file,"p%05d.%05ld", pid, j); + sprintf(new,"p%05d.%05ld.old", pid, j); + if (rename(file, new) == -1) + err(1, "rename(%s, %s)", file, new); + } + + for (j = 0; j < files; j++) { + sprintf(file,"p%05d.%05ld", pid, j); + sprintf(new,"p%05d.%05ld.old", pid, j); + if (rename(new, file) == -1) + err(1, "rename(%s, %s)", new, file); + } + + for (j = 0; j < files; j++) { + sprintf(file,"p%05d.%05ld", pid, j); + if (unlink(file) == -1) + warn("unlink(%s)", file); + + } + if (chdir("..") == -1) + err(1, "chdir .."); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + pid_t pids[PARALLEL]; + time_t start; + int e, i, n, status; + + if (argc != 3) { + fprintf(stderr, "Usage %s \n", argv[0]); + exit(1); + } + path = argv[1]; + files = atol(argv[2]) / PARALLEL; + fprintf(stderr, "Using %ld inodes per dir. %d threads. %ld inodes in total\n", + files, PARALLEL, files * PARALLEL); + e = n = 0; + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + fprintf(stderr, "Loop #%d\n", ++n); + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(i); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } +// system("(cd MNTPOINT; umount MNTPOINT) > /dev/null 2>&1"); + } + + return (e); +} diff --git a/tools/test/stress2/misc/indir_trunc.sh b/tools/test/stress2/misc/indir_trunc.sh new file mode 100755 index 000000000000..64c11f3570ee --- /dev/null +++ b/tools/test/stress2/misc/indir_trunc.sh @@ -0,0 +1,231 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# No problems seen. +# Test scenario inspired by: +# syzbot+6532e9aab8911f58beeb@syzkaller.appspotmail.com + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +[ `uname -m` = "i386" ] && exit 0 # OOM killing + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/indir_trunc.c +mycc -o indir_trunc -Wall -Wextra -O0 -g indir_trunc.c -lpthread || exit 1 +rm -f indir_trunc.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 40g -u $mdstart +newfs $newfs_flags -n md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +###(cd ../testcases/swap; ./swap -t 5m -i 20) & +cd $mntpoint +$dir/indir_trunc +s=$? +while pkill swap; do :; done +wait +[ -f indir_trunc.core -a $s -eq 0 ] && + { ls -l indir_trunc.core; mv indir_trunc.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/indir_trunc +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#if defined(__LP64__) +#define MASK 0x7ffffffffffffULL +#else +#define MASK 0xffffffff +#endif +#define PARALLEL 64 +#define RUNTIME (5 * 60) +#define SYNC 0 + +static int fd; + +static void * +t1(void *data __unused) +{ + off_t offset; + time_t start; + char *cmdline[] = { "/usr/bin/true", NULL }; + + start = time(NULL); + while (time(NULL) - start < 60) { + offset = arc4random(); + offset = (offset << 32) | arc4random(); + offset &= MASK; + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek(%jd)", offset); + if (write(fd, "a", 1) != 1) + err(1, "write"); + usleep(10); + if (arc4random() % 1000 < 2) { + if (execve(cmdline[0], cmdline, NULL) == -1) + err(1, "execve"); + } + } + + return (NULL); +} +static void * +t2(void *data __unused) +{ + off_t offset, old; + time_t start; + void *p; + char *c; + + old = 0; + start = time(NULL); + while (time(NULL) - start < 60) { + if (old != 0) + munmap(p, old); + offset = arc4random(); + offset = (offset << 32) | arc4random(); + offset &= MASK; + if (ftruncate(fd, offset) == -1) + err(1, "ftruncate(%jd)", offset); + write(fd, "b", 1); + p = mmap(NULL, offset, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, 0); + if (p == MAP_FAILED) + old = 0; + else { + old = offset; + c = p; + c[offset / 2] = 1; + if (offset > 0) + c[offset - 1] = 2; + } + usleep(10); + } + return (NULL); +} + +static void +test(void) +{ + pthread_t tid[2]; + int r; + char file[80]; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + snprintf(file, sizeof(file), "file.%d", getpid()); + if ((fd = open(file, O_RDWR | O_CREAT, DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + + if ((r = pthread_create(&tid[0], NULL, t1, NULL)) != 0) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&tid[1], NULL, t2, NULL)) != 0) + errc(1, r, "pthread_create"); + + if ((r = pthread_join(tid[0], NULL)) != 0) + errc(1, r, "pthread_join"); + if ((r = pthread_join(tid[1], NULL)) != 0) + errc(1, r, "pthread_join"); + close(fd); + unlink(file); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/inversion.sh b/tools/test/stress2/misc/inversion.sh new file mode 100755 index 000000000000..759549af0233 --- /dev/null +++ b/tools/test/stress2/misc/inversion.sh @@ -0,0 +1,97 @@ +#!/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. +# + +# Provokes a deadlock by lower priority process holding a lock and +# never beeing run + +. ../default.cfg + +dir=$RUNDIR +N=5 # Number of CPUs + 1 +M=25 # Number of lower priority jobs + +odir=`pwd` +mkdir -p $dir || exit 1 +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/inversion.c +mycc -o inversion -Wall inversion.c +rm -f inversion.c + +mp=`df $dir | tail -1 | awk '{print $NF}'` +mp=`mount | grep "on $mp "` +if echo $mp | grep -wq nfs; then + pgrep -q lockd || { echo "lockd not running"; exit 0; } +fi + +for i in `jot $N`; do + ./inversion 600 & +done + +while pgrep inversion > /dev/null; do + ( + 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/tools/test/stress2/misc/isofs.sh b/tools/test/stress2/misc/isofs.sh new file mode 100755 index 000000000000..5f5c26e00b4c --- /dev/null +++ b/tools/test/stress2/misc/isofs.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. +# + +[ `id -u ` -ne 0 ] && echo "Must not be root!" && exit 1 + +[ -z "`type mkisofs 2>/dev/null`" ] && echo "mkisofs not found" && exit 0 + +. ../default.cfg + +D=`dirname $diskimage`/dir +I=`dirname $diskimage`/dir.iso +export here=`pwd` +cd /tmp + +mycc -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 +wait + +umount $mntpoint +mdconfig -d -u $mdstart + +rm -rf $D $I fstool diff --git a/tools/test/stress2/misc/isofs2.sh b/tools/test/stress2/misc/isofs2.sh new file mode 100755 index 000000000000..ad03e7e410b0 --- /dev/null +++ b/tools/test/stress2/misc/isofs2.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Run program from isofs file system +# "panic: userret: returning with the following locks held:" +# https://people.freebsd.org/~pho/stress/log/isofs2.txt +# Fixed by: r292772. + +[ `id -u ` -ne 0 ] && echo "Must not be root!" && exit 1 + +[ -z "`type mkisofs 2>/dev/null`" ] && echo "mkisofs not found" && exit 0 + +. ../default.cfg + +D=`dirname $diskimage`/dir +I=`dirname $diskimage`/dir.iso +here=`pwd` +cd /tmp +rm -rf $D $I +mkdir $D +cp `which date` $D +mkisofs -o $I -r $D > /dev/null 2>&1 +mdconfig -a -t vnode -f $I -u $mdstart +mount -t cd9660 /dev/md$mdstart $mntpoint + +cd $mntpoint +./date > /dev/null +cd $here + +umount $mntpoint +mdconfig -d -u $mdstart + +rm -rf $D $I diff --git a/tools/test/stress2/misc/isofs3.sh b/tools/test/stress2/misc/isofs3.sh new file mode 100755 index 000000000000..476c729568ac --- /dev/null +++ b/tools/test/stress2/misc/isofs3.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC +# 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. +# + +# Simple isofs / union test scenario + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -z "`which mkisofs`" ] && echo "mkisofs not found" && exit 0 + +. ../default.cfg + +D=`dirname $diskimage`/dir +I=`dirname $diskimage`/dir.iso + +rm -rf $D $I +mkdir -p $D +cp -r ../../stress2 $D 2>/dev/null + +mkisofs -o $I -r $D > /dev/null 2>&1 + +mount | grep -q /dev/md${mdstart}$part && umount -f /dev/md${mdstart}$part +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t vnode -f $I -u $mdstart || exit 1 +mount -t cd9660 /dev/md$mdstart $mntpoint || exit 1 + +m2=$((mdstart + 1)) +mdconfig -s 1g -u $m2 +bsdlabel -w md$m2 auto +newfs $newfs_flags md${m2}$part > /dev/null + +mount -o union /dev/md${m2}$part $mntpoint || exit 1 + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=5m +(cd $mntpoint/stress2; ./run.sh marcus.cfg) > /dev/null + +umount $mntpoint +mdconfig -d -u $m2 +umount $mntpoint +mdconfig -d -u $mdstart +rm -rf $D $I +exit 0 diff --git a/tools/test/stress2/misc/jail.sh b/tools/test/stress2/misc/jail.sh new file mode 100755 index 000000000000..2c77033d10a2 --- /dev/null +++ b/tools/test/stress2/misc/jail.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. +# + +# Regression test for problem found with the syscall.sh test + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > jail.c +mycc -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/tools/test/stress2/misc/jail2.sh b/tools/test/stress2/misc/jail2.sh new file mode 100755 index 000000000000..7247eacb73b6 --- /dev/null +++ b/tools/test/stress2/misc/jail2.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. +# + +# Regression test for problem found with the syscall.sh test + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > jail2.c +mycc -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/tools/test/stress2/misc/jail3.sh b/tools/test/stress2/misc/jail3.sh new file mode 100755 index 000000000000..97bc078e8e89 --- /dev/null +++ b/tools/test/stress2/misc/jail3.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. +# + +# Regression test for problem found with the syscall.sh test + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > jail3.c +mycc -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/tools/test/stress2/misc/jail4.sh b/tools/test/stress2/misc/jail4.sh new file mode 100755 index 000000000000..c641c957997d --- /dev/null +++ b/tools/test/stress2/misc/jail4.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. +# + +# 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 +mycc -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/tools/test/stress2/misc/jexec.sh b/tools/test/stress2/misc/jexec.sh new file mode 100755 index 000000000000..c5c2ab605e08 --- /dev/null +++ b/tools/test/stress2/misc/jexec.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# Bug 238032 - "jexec pr_ref leak" by bz@ +# "foo DYING" seen. +# Fixed by r358676 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 +mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint + +here=`pwd` +cd $mntpoint +(cd $here/../testcases/swap; ./swap -t 2m -i 20) & +sleep 10 +jail -c name=foo persist +start=`date +%s` +while [ $((`date +%s`- start)) -lt 120 ]; do + jexec foo <<-EOF + sleep .2 +EOF +done > /dev/null 2>&1 +jail -r foo +jls -dv | grep foo && s=1 || s=0 + +cd $here +for i in `jot 5`; do + umount $mntpoint && break + sleep 2 +done +wait + +# Break into kgdb and type "show prison" +# Check ref count growth + +exit $s diff --git a/tools/test/stress2/misc/jumbo.sh b/tools/test/stress2/misc/jumbo.sh new file mode 100755 index 000000000000..8dcc5aa7aca3 --- /dev/null +++ b/tools/test/stress2/misc/jumbo.sh @@ -0,0 +1,221 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Stress the jumbo mbuf allocation +# vmstat -z | sed -n '1p;/jumbo/p' + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > jumbo.c +mycc -o jumbo -Wall -Wextra -O2 jumbo.c || exit 1 +rm -f jumbo.c + +log=/tmp/mbuf.log +nb=80 +host=localhost +[ $# -eq 1 ] && host=$1 +( + for i in `jot $nb 0`; do + /tmp/jumbo $((12345 + $i)) & + done + sleep 30 + for i in `jot $nb 0`; do + /tmp/jumbo $host $((12345 + $i)) & + done + for i in `jot $nb 0`; do + wait + done +) > $log 2>&1 + +rm -f /tmp/jumbo +grep -q FAIL $log && { cat $log 1>&2; exit 1; } +rm -f $log +exit 0 +EOF +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MX (1024 * 1024) +#define RETRIES 5 +#define TIMEOUT 1200 + +char *host; +int loops, port, server; + +void +ahandler(int s __unused) +{ + if (server) + fprintf(stderr, "FAIL Server timed out after %d loops.\n", + loops); + else + fprintf(stderr, "FAIL Client timed out after %d loops.\n", + loops); + _exit(0); +} + +static void +reader(void) { + socklen_t len; + struct sockaddr_in inetaddr, inetpeer; + int *buf, i, n, msgsock, on, tcpsock; + + setproctitle("reader - init"); + 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); + + signal(SIGALRM, ahandler); + alarm(TIMEOUT); + 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__); + + if ((buf = malloc(MX)) == NULL) + err(1, "malloc(%d), %s:%d", MX, __FILE__, __LINE__); + setproctitle("reader"); + for (i = 4096; i < MX; i += 1024) { + alarm(TIMEOUT); + if ((n = recvfrom(msgsock, buf, i, MSG_WAITALL, NULL, + NULL)) < 0) { + if (errno == EAGAIN) + continue; + err(1, "read(), %s:%d", __FILE__, __LINE__); + } + if (n == 0) + break; + + loops++; + } + close(msgsock); + _exit(0); +} + +static void +writer(void) { + struct sockaddr_in inetaddr; + struct hostent *hostent; + int i, on, r, tcpsock; + char *line; + + setproctitle("writer - init"); + signal(SIGALRM, ahandler); + alarm(TIMEOUT); + on = 1; + for (i = 0; i < RETRIES; 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 ((hostent = gethostbyname (host)) == NULL) + err(1, "gethostbyname(%s)", host); + bzero((char *) &inetaddr, sizeof(inetaddr)); + memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, + sizeof (struct in_addr)); + + inetaddr.sin_family = AF_INET; + 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), %s:%d", host, port, __FILE__, + __LINE__); + + setproctitle("writer"); + if ((line = malloc(MX)) == NULL) + err(1, "malloc(%d), %s:%d", MX, __FILE__, __LINE__); + alarm(TIMEOUT); + for (i = sysconf(_SC_PAGESIZE); i < MX; i += 1024) { + if (write(tcpsock, line, i) < 0) + err(1, "socket write(). %s:%d", __FILE__, __LINE__); + loops++; + } + close(tcpsock); + + return; +} + +int +main(int argc, char **argv) +{ + + if (argc == 2) { + server = 1; + port = atoi(argv[1]); + reader(); + } else if (argc == 3) { + host = argv[1]; + port = atoi(argv[2]); + writer(); + } else + errx(1, "Usage: %s {} \n", argv[0]); + + return (0); +} diff --git a/tools/test/stress2/misc/kern_umtx_inf_loop.sh b/tools/test/stress2/misc/kern_umtx_inf_loop.sh new file mode 100755 index 000000000000..b8088814d7b2 --- /dev/null +++ b/tools/test/stress2/misc/kern_umtx_inf_loop.sh @@ -0,0 +1,148 @@ +#!/bin/sh + +# The program is a test case by Eric which demonstrates the +# bug, unkillable spinning thread, owning a spinlock. + +# "panic: spin lock held too long" seen. +# Fixed in r277970. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > kern_umtx_inf_loop.c +mycc -o kern_umtx_inf_loop -Wall -Wextra -O0 -g kern_umtx_inf_loop.c \ + -lpthread || exit 1 +rm -f kern_umtx_inf_loop.c + +/tmp/kern_umtx_inf_loop + +rm -f /tmp/kern_umtx_inf_loop +exit 0 +EOF +/*- + * Copyright (c) 2015 Eric van Gyzen + * 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 + +pthread_mutex_t the_mutex = PTHREAD_MUTEX_INITIALIZER; + +pthread_t contender; + +static void * +contender_func(void *arg) +{ + int error; + + (void) arg; + + error = pthread_mutex_lock(&the_mutex); + if (error) errc(1, error, "pthread_mutex_lock contender"); + + fprintf(stderr, "contender lock succeeded\n"); + + error = pthread_mutex_unlock(&the_mutex); + if (error) errc(1, error, "pthread_mutex_unlock contender"); + + fprintf(stderr, "contender unlock succeeded; exiting\n"); + + return (NULL); +} + +static void * +signaler_func(void *arg __unused) +{ + int error; + + // Wait for the main thread to sleep. + usleep(100000); + + error = pthread_kill(contender, SIGHUP); + if (error) errc(1, error, "pthread_kill"); + + // Wait for the contender to lock umtx_lock + // in umtx_repropagate_priority. + usleep(100000); + + error = pthread_mutex_lock(&the_mutex); + if (error) errc(1, error, "pthread_mutex_lock signaler"); + + return (NULL); +} + +int +main(void) +{ + int error; + + pthread_mutexattr_t mattr; + + error = pthread_mutexattr_init(&mattr); + if (error) errc(1, error, "pthread_mutexattr_init"); + + error = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT); + if (error) errc(1, error, "pthread_mutexattr_setprotocol"); + + error = pthread_mutex_init(&the_mutex, &mattr); + if (error) errc(1, error, "pthread_mutex_init"); + + error = pthread_mutexattr_destroy(&mattr); + if (error) errc(1, error, "pthread_mutexattr_destroy"); + + //error = pthread_mutex_lock(&the_mutex); + //if (error) errc(1, error, "pthread_mutex_lock"); + + // Hack lock. + *(int *)the_mutex = pthread_getthreadid_np(); + + error = pthread_create(&contender, NULL, contender_func, NULL); + if (error) errc(1, error, "pthread_create"); + + // Wait for the contender to sleep. + usleep(100000); + + pthread_t signaler; + error = pthread_create(&signaler, NULL, signaler_func, NULL); + if (error) errc(1, error, "pthread_create"); + + error = pthread_mutex_lock(&the_mutex); + if (error) errc(1, error, "pthread_mutex_lock recurse"); + + return (0); +} + diff --git a/tools/test/stress2/misc/kevent.sh b/tools/test/stress2/misc/kevent.sh new file mode 100755 index 000000000000..ebcaca639849 --- /dev/null +++ b/tools/test/stress2/misc/kevent.sh @@ -0,0 +1,174 @@ +#!/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. +# + +# panic: KN_INFLUX set when not suppose to be + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent.c +mycc -o kevent -Wall kevent.c -pthread || exit 1 +rm -f kevent.c +[ -d "$RUNDIR" ] || mkdir -p $RUNDIR +cd $RUNDIR + +for i in `jot 10`; do + for j in `jot 12`; do + /tmp/kevent > /dev/null 2>&1 & + done + wait +done +rm -f /tmp/kevent +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]; + +#define RUNTIME 12 + +static void * +thr1(void *arg) +{ + struct kevent ev[3]; + int kq, n, r; + + 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 ((r = pthread_mutex_lock(&mutex)) != 0) + errc(1, r, "pthread_mutex_lock"); + waiting = 0; + if ((r = pthread_cond_signal(&cond)) != 0) + errc(1, r, "pthread_cond_signal"); + if ((r = pthread_mutex_unlock(&mutex)) != 0) + errc(1, r, "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) + warn("kevent(). %s:%d", __FILE__, __LINE__); + close(kq); + + return (0); +} + +static void * +thr2(void *arg) +{ + int r; + + if ((r = pthread_mutex_lock(&mutex)) != 0) + errc(1, r, "pthread_mutex_lock"); + while (waiting == 1) { + if ((r = pthread_cond_wait(&cond, &mutex)) != 0) + errc(1, r, "pthread_cond_wait"); + } + if ((r = pthread_mutex_unlock(&mutex)) != 0) + errc(1, r, "pthread_mutex_unlock"); + 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]; + time_t start; + int r; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + waiting = 1; + if (pipe(fd1) == -1) + err(1, "pipe()"); + if (pipe(fd2) == -1) + err(1, "pipe()"); + if (pipe(fd3) == -1) + err(1, "pipe()"); + + if ((r = pthread_mutex_init(&mutex, 0)) != 0) + errc(1, r, "pthread_mutex_init"); + if ((r = pthread_cond_init(&cond, NULL)) != 0) + errc(1, r, "pthread_cond_init"); + + if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) + errc(1, r, "pthread_create()"); + if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) + errc(1, r, "pthread_create()"); + + if ((r = pthread_join(threads[0], NULL)) != 0) + errc(1, r, "pthread_join(%d)", 0); + if ((r = pthread_join(threads[1], NULL)) != 0) + errc(1, r, "pthread_join(%d)", 1); + if ((r = pthread_mutex_destroy(&mutex)) != 0) + errc(1, r, "pthread_mutex_destroy"); + if ((r = pthread_cond_destroy(&cond)) != 0) + errc(1, r, "pthread_cond_destroy)"); + } + + return (0); +} diff --git a/tools/test/stress2/misc/kevent10.sh b/tools/test/stress2/misc/kevent10.sh new file mode 100755 index 000000000000..d746897cddcf --- /dev/null +++ b/tools/test/stress2/misc/kevent10.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# Regression test for +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=217435 +# by Tim Newsham + +# panic: Assertion size > 0 failed at ../../../kern/subr_vmem.c:1082 +# cpuid = 2 +# time = 1501182301 +# KDB: stack backtrace: +# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe0173117650 +# vpanic() at vpanic+0x19c/frame 0xfffffe01731176d0 +# kassert_panic() at kassert_panic+0x126/frame 0xfffffe0173117740 +# vmem_alloc() at vmem_alloc+0x11b/frame 0xfffffe0173117780 +# kmem_malloc() at kmem_malloc+0x33/frame 0xfffffe01731177b0 +# uma_large_malloc() at uma_large_malloc+0x48/frame 0xfffffe01731177f0 +# malloc() at malloc+0xe3/frame 0xfffffe0173117840 +# ktrgenio() at ktrgenio+0x60/frame 0xfffffe0173117880 +# sys_kevent() at sys_kevent+0x12f/frame 0xfffffe0173117930 +# amd64_syscall() at amd64_syscall+0x7d2/frame 0xfffffe0173117ab0 + +# Fixed by r315155. + +. ../default.cfg + +cat > /tmp/kevent10.c < +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +int +main(void) +{ + struct kevent changes; + struct kevent events; + char *fn = "/tmp/kevent10.trace"; + + if (open(fn, O_RDWR | O_CREAT, 0666) == -1) + err(1, "%s", fn); + if (ktrace(fn, KTRFLAG_DESCEND | KTROP_SET, KTRFAC_GENIO, 0) == -1) + err(1, "ktrace"); + memset(&changes, 0, sizeof(struct kevent)); + memset(&events, 0, sizeof(struct kevent)); + if (kevent(0, &changes, -1, &events, 1, 0) == -1) + if (errno != EBADF) + err(1, "kevent"); + + return (0); +} +EOF + +mycc -o /tmp/kevent10 -Wall -Wextra -O2 /tmp/kevent10.c || exit 1 +rm /tmp/kevent10.c + +/tmp/kevent10 +s=$? + +rm /tmp/kevent10 /tmp/kevent10.trace +exit $s diff --git a/tools/test/stress2/misc/kevent11.sh b/tools/test/stress2/misc/kevent11.sh new file mode 100755 index 000000000000..f3a319f2ecff --- /dev/null +++ b/tools/test/stress2/misc/kevent11.sh @@ -0,0 +1,178 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Variation of kevent5.sh +# OOM seen: https://people.freebsd.org/~pho/stress/log/mark018.txt + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/kevent11.c +mycc -o kevent11 -Wall -Wextra -O0 -g kevent11.c || exit 1 +rm -f kevent11.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +set +e + +(cd $odir/../testcases/swap; ./swap -t 5m -i 20 -h -l 100 > /dev/null) & +cd $mntpoint +$dir/kevent11 +s=$? +[ -f kevent11.core -a $s -eq 0 ] && + { ls -l kevent11.core; mv kevent11.core /tmp; s=1; } +cd $odir +while pkill -9 swap; do :; done +wait + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && exit 1 +mdconfig -d -u $mdstart +rm -rf $dir/kevent11 +exit $s + +EOF +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; +static char *file = "file"; + +#define PARALLEL 256 +#define RUNTIME (3 * 60) +#define SYNC 0 + +static void +test(void) +{ + struct kevent ev[2]; + struct timespec ts; + int kq, fd, n; + + if ((fd = open(file, O_RDONLY, 0)) == -1) + err(1, "open(%s). %s:%d", file, __func__, __LINE__); + + 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()"); + + setproctitle("presync"); + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + usleep(10000); + setproctitle("postsync"); + + memset(&ev, 0, sizeof(ev)); + n = kevent(kq, NULL, 0, ev, 1, &ts); + close(fd); + close(kq); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, fd, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + if ((fd = open(file, O_CREAT | O_TRUNC | O_RDWR, 0660)) == + -1) + err(1, "open(%s)", file); + close(fd); + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + while (share[SYNC] != PARALLEL) + usleep(10000); + if (unlink(file) == -1) + err(1, "unlink(%s). %s:%d\n", file, + __FILE__, __LINE__); + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/kevent12.sh b/tools/test/stress2/misc/kevent12.sh new file mode 100755 index 000000000000..3ae0085f1e5d --- /dev/null +++ b/tools/test/stress2/misc/kevent12.sh @@ -0,0 +1,233 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Bug 228858 - panic when delivering knote to a process who has opened a +# kqueue() is dying +# Page fault seen: https://people.freebsd.org/~pho/stress/log/mark052.txt +# Fixed by r340897. + +# Test scenario based on analysis by siddharthtuli gmail com + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent12.c +mycc -o kevent12 -Wall -Wextra -O2 -g kevent12.c || exit 1 +rm -f kevent12.c +cd $odir + +(cd $odir/../testcases/swap; ./swap -t 5m -i 20 -l 100 > /dev/null 2>&1) & +pid=$! +/tmp/kevent12 +while pgrep -q swap; do + pkill -9 swap +done +wait $pid + +rm -f /tmp/kevent12 +exit 0 +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 64 +#define RUNTIME (5 * 60) + +static pid_t parent; +static int kq; + +static void +hand(int i __unused) { /* handler */ + kill(parent, SIGINT); + _exit(1); +} + +static void +init_kq() +{ + kq = kqueue(); + if (kq == -1) + err(1, "kqueue"); +} + +static void +add_watch(pid_t pid) +{ + struct kevent kev; + char msg[64]; + + bzero(&kev, sizeof(kev)); + kev.ident = pid; + kev.flags = EV_ADD | EV_ENABLE; + kev.filter = EVFILT_PROC; + kev.fflags = NOTE_EXIT | NOTE_EXEC | NOTE_TRACK | NOTE_TRACKERR; + + for (;;) { + int res = kevent(kq, &kev, 1, NULL, 0, NULL); + if (res == -1) { + if (errno == EINTR) + continue; + if (errno == ESRCH) + break; + + snprintf(msg, sizeof(msg), + "kevent - add watch for pid %u", pid); + err(1, "%s", msg); + } + else + break; + } +} + +static void +polling() +{ + struct kevent kev[10]; +#if defined(DEBUG) + pid_t pid; + int i; +#endif + + for (;;) { + bzero(&kev, sizeof(kev)); + if (arc4random() % 100 < 10) { + signal(SIGALRM, hand); + ualarm(10000, 0); + } + 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(1, "kevent"); + } + +#if defined(DEBUG) + 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, + (unsigned int)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); + if (parent == pid) + return; + } + 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); + } + } +#endif + } +} + +void +churn(void) +{ + pid_t pid; + time_t start; + char *cmdline[] = { "/usr/bin/true", NULL }; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if ((pid = fork()) == -1) + err(1, "fork"); + if (pid == 0) { + if (execve(cmdline[0], cmdline, NULL) == -1) + err(1, "execve"); + } + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid(%d):%d", pid, __LINE__); + } + + _exit(0); +} + +int +test(void) +{ + if ((parent = fork()) == 0) + churn(); + + init_kq(); + add_watch(parent); + polling(); + if (waitpid(parent, NULL, 0) != parent) + err(1, "waitpid(%d):%d", parent, __LINE__); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + time_t start; + int i; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) + if (waitpid(pids[i], NULL, 0) != pids[i]) + err(1, "waitpid(%d):%d", pids[i], __LINE__); + } + + return (0); +} diff --git a/tools/test/stress2/misc/kevent13.sh b/tools/test/stress2/misc/kevent13.sh new file mode 100755 index 000000000000..82a7a10b983c --- /dev/null +++ b/tools/test/stress2/misc/kevent13.sh @@ -0,0 +1,141 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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 based on scenario by Babcia Padlina + +# "panic: mutex pipe mutex not owned at sys_pipe.c:1769" seen: +# https://people.freebsd.org/~pho/stress/log/kevent13.txt +# Fixed by r235640. + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent13.c +cc -o kevent13 -Wall kevent13.c -lpthread +rm -f kevent13.c + +[ -d "$RUNDIR" ] || mkdir -p $RUNDIR +cd $RUNDIR +start=`date +%s` +while [ $((`date +%s` - start)) -lt 300 ]; do + for i in `jot 10`; do + /tmp/kevent13 & + /tmp/kevent13 & + wait + done +done + +rm -f /tmp/kevent13 +exit 0 +EOF +/* + * 29.08.2009, babcia padlina + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define LOOPS 200000 + +struct kevent kev[2], ke[2]; +struct timespec timeout; +volatile int go; +int fd[2], kq; + +void +do_thread(void) { + int i; + + go = 1; + for (i = 0; i < LOOPS; i++) { + if (pipe(fd) < 0) + err(1, "pipe"); + memset(&kev, 0, sizeof(kev)); + EV_SET(&kev[0], fd[0], EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, NULL); + EV_SET(&kev[1], fd[1], EVFILT_WRITE, EV_ADD | EV_CLEAR, 0, 0, NULL); + + if (kevent(kq, kev, 2, ke, 2, &timeout) < 0) + err(1, "kevent"); + + close(fd[0]); + close(fd[1]); + } +} + +void +do_thread2(void) { + int i; + + while (go == 0) + usleep(10); + for (i = 0; i < LOOPS; i++) { + if (arc4random() % 2 == 0) { + close(fd[0]); + close(fd[1]); + } else { + close(fd[1]); + close(fd[0]); + } + } +} + +int +main(void) { + pthread_t pth, pth2; + int r; + + if ((kq = kqueue()) < 0) + err(1, "kqueue"); + + if ((r = pthread_create(&pth, NULL, (void *)do_thread, NULL)) != 0) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&pth2, NULL, (void *)do_thread2, NULL)) != 0) + errc(1, r, "pthread_create"); + + timeout.tv_sec = 0; + timeout.tv_nsec = 1; + + if ((r = pthread_join(pth, NULL)) != 0) + errc(1, r, "pthread_join"); + if ((r = pthread_join(pth2, NULL)) != 0) + errc(1, r, "pthread_join"); + + return (0); +} diff --git a/tools/test/stress2/misc/kevent14.sh b/tools/test/stress2/misc/kevent14.sh new file mode 100755 index 000000000000..2531b15caecf --- /dev/null +++ b/tools/test/stress2/misc/kevent14.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# "panic: Bad tailq NEXT(0xfffff815a589e238->tqh_last) != NULL" seen. +# https://people.freebsd.org/~pho/stress/log/kevent14.txt +# Fixed by r340734. + +# Test scenario by: Mark Johnston + +cat > /tmp/kevent14.c < + +#include +#include +#include + +int +main(void) +{ + struct kevent ev[2]; + time_t start; + int kq, ret; + + kq = kqueue(); + if (kq < 0) + err(1, "kqueue"); + + EV_SET(&ev[0], 42, EVFILT_TIMER, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, + 0, 0); + + start = time(NULL); + while (time(NULL) - start < 120) { + ret = kevent(kq, &ev[0], 1, &ev[1], 1, NULL); + if (ret < 0) + err(1, "kevent"); + if (ret == 0) + errx(1, "no events"); + if (ret == 1 && (ev[1].flags & EV_ERROR) != 0) + errc(1, ev[1].data, "kevent"); + } + + return (0); +} +EOF +cc -o /tmp/kevent14 -Wall -Wextra -g -O2 /tmp/kevent14.c +rm /tmp/kevent14.c + +/tmp/kevent14 + +rm -f /tmp/kevent14 +exit 0 diff --git a/tools/test/stress2/misc/kevent15.sh b/tools/test/stress2/misc/kevent15.sh new file mode 100755 index 000000000000..52925365c865 --- /dev/null +++ b/tools/test/stress2/misc/kevent15.sh @@ -0,0 +1,161 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# No problems seen. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/kevent15.c +mycc -o kevent15 -Wall -Wextra -O0 -g kevent15.c || exit 1 +rm -f kevent15.c +cd $odir + +(cd ../testcases/swap; ./swap -t 3m -i 20 -l 80) & +sleep 2 +cd $dir +timeout 5m ./kevent15 +s=$? +while pkill swap; do sleep .1; done +wait +[ -f kevent15.core -a $s -eq 0 ] && + { ls -l kevent15.core; s=1; } +cd $odir + +rm -rf $dir/kevent15 +exit $s + +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static _Atomic(int) *share; + +#define PARALLEL 800 +#define RUNTIME (3 * 60) +#define SYNC 0 +#define ACT 1 + +static void +handler(int i __unused) { + _exit(0); +} + +static void +test(void) +{ + struct kevent ev[2]; + struct timespec ts; + time_t start; + int kq, ret; + + signal(SIGUSR1, handler); + (void)atomic_fetch_add(&share[SYNC], 1); + while (atomic_load(&share[SYNC]) != PARALLEL) + usleep(1); + (void)atomic_fetch_add(&share[ACT], 1); + + if ((kq = kqueue()) < 0) + err(1, "kqueue"); + + EV_SET(&ev[0], 42, EVFILT_TIMER, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, + 0, 0); + + start = time(NULL); + while (time(NULL) - start < 30) { + ts.tv_sec = 0; + ts.tv_nsec = arc4random() % 2000; + if ((ret = kevent(kq, &ev[0], 1, &ev[1], 1, &ts)) == -1) + err(1, "kevent"); + if (ret == 1 && (ev[1].flags & EV_ERROR) != 0) + errc(1, ev[1].data, "kevent"); + } + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int i, status; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + share[ACT] = share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + while (share[ACT] != PARALLEL) + usleep(1); + usleep(arc4random() % 50000); + for (i = 0; i < PARALLEL; i++) { + if (kill(pids[i], SIGUSR1) == -1) + err(1, "kill"); + } + + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status) && WTERMSIG(status) != 2) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + } + } + + return (0); +} diff --git a/tools/test/stress2/misc/kevent2.sh b/tools/test/stress2/misc/kevent2.sh new file mode 100755 index 000000000000..b2ae2a97e422 --- /dev/null +++ b/tools/test/stress2/misc/kevent2.sh @@ -0,0 +1,170 @@ +#!/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. +# + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent2.c +mycc -o kevent2 -Wall kevent2.c -pthread || exit 1 +rm -f kevent2.c +cd $RUNDIR + +for i in `jot 10`; do + for j in `jot 12`; do + /tmp/kevent2 > /dev/null 2>&1 & + done + wait +done +rm -f /tmp/kevent2 +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]; + +static void * +thr1(void *arg) +{ + struct kevent ev[3]; + struct timespec ts; + int kq, n, r; + + 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 ((r = pthread_mutex_lock(&mutex)) != 0) + errc(1, r, "pthread_mutex_lock"); + waiting = 0; + if ((r = pthread_cond_signal(&cond)) != 0) + errc(1, r, "pthread_cond_signal"); + if ((r = pthread_mutex_unlock(&mutex)) != 0) + errc(1, r, "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); + + close(fd1[1]); + close(fd2[1]); + close(fd3[1]); + return (0); +} + +static void * +thr2(void *arg) +{ + int r; + + if ((r = pthread_mutex_lock(&mutex)) != 0) + errc(1, r, "pthread_mutex_lock"); + while (waiting == 1) { + if ((r = pthread_cond_wait(&cond, &mutex)) != 0) + errc(1, r, "pthread_cond_wait"); + } + if ((r = pthread_mutex_unlock(&mutex)) != 0) + errc(1, r, "pthread_mutex_unlock"); + close(fd1[0]); + close(fd2[0]); + close(fd3[0]); + return (0); +} + +int +main(int argc, char **argv) +{ + pthread_t threads[2]; + int i, r; + + for (i = 0; i < 1000; i++) { + waiting = 1; + if (pipe(fd1) == -1) + err(1, "pipe()"); + if (pipe(fd2) == -1) + err(1, "pipe()"); + if (pipe(fd3) == -1) + err(1, "pipe()"); + + if ((r = pthread_mutex_init(&mutex, 0)) != 0) + errc(1, r, "pthread_mutex_init"); + if ((r = pthread_cond_init(&cond, NULL)) != 0) + errc(1, r, "pthread_cond_init"); + + if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) + errc(1, r, "pthread_create()"); + if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) + errc(1, r, "pthread_create()"); + + if ((r = pthread_join(threads[0], NULL)) != 0) + errc(1, r, "pthread_join(%d)", 0); + if ((r = pthread_join(threads[1], NULL)) != 0) + errc(1, r, "pthread_join(%d)", 1); + if ((r = pthread_mutex_destroy(&mutex)) != 0) + errc(1, r, "pthread_mutex_destroy"); + if ((r = pthread_cond_destroy(&cond)) != 0) + errc(1, r, "pthread_condattr_destroy"); + } + + return (0); +} diff --git a/tools/test/stress2/misc/kevent3.sh b/tools/test/stress2/misc/kevent3.sh new file mode 100755 index 000000000000..0ee9706a27b1 --- /dev/null +++ b/tools/test/stress2/misc/kevent3.sh @@ -0,0 +1,74 @@ +#!/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. +# + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent3.c +mycc -o kevent3 -Wall kevent3.c -pthread || exit 1 +rm -f kevent3.c +cd $RUNDIR + +for i in `jot 64`; do + for j in `jot 12`; do + /tmp/kevent3 > /dev/null 2>&1 & + done + for j in `jot 12`; do + wait + done +done +rm -f /tmp/kevent3 +exit 0 +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/tools/test/stress2/misc/kevent4.sh b/tools/test/stress2/misc/kevent4.sh new file mode 100755 index 000000000000..87f421322ed5 --- /dev/null +++ b/tools/test/stress2/misc/kevent4.sh @@ -0,0 +1,174 @@ +#!/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. +# + +# Test scenario by kib@ + +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent4.c +mycc -o kevent4 -Wall kevent4.c -pthread || exit 1 +rm -f kevent4.c + +cd $odir +export runRUNTIME=3m +(cd ..; ./run.sh > /dev/null 2>&1) & +rpid=$! + +(cd $RUNDIR; /tmp/kevent4 $rpid > /dev/null) & + +sleep 120 +kill $rpid +../tools/killall.sh > /dev/null 2>&1 +kill $! +wait +rm -f /tmp/kevent4 + +exit +EOF +#include +#include + +#include +#include +#include +#include +#include +#ifndef true +# define true 1 +#endif + +static int kq; + +static void +err(const char *msg, int err_no) +{ + fprintf(stderr, "%s: %s\n", msg, strerror(err_no)); + exit(1); +} + +static void +init_kq() +{ + kq = kqueue(); + if (kq == -1) + err("kqueue", errno); +} + +static 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; + } +} + +static 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, + (unsigned int)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); + } + 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/tools/test/stress2/misc/kevent5.sh b/tools/test/stress2/misc/kevent5.sh new file mode 100755 index 000000000000..35a9e6e78e72 --- /dev/null +++ b/tools/test/stress2/misc/kevent5.sh @@ -0,0 +1,183 @@ +#!/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. +# + +# 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 > kevent5.c +mycc -o kevent5 -Wall -Wextra -O2 -g kevent5.c || exit 1 +rm -f kevent5.c + +[ -d $RUNDIR ] || mkdir -p $RUNDIR +cd $RUNDIR +/tmp/kevent5 kevent5.xxx kevent5.yyy +s=$? + +rm -f /tmp/kevent5 kevent.xxx kevent.yyy + +exit $s +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +volatile u_int *share; + +static char *file1, *file2; + +#define N 1000 +#define SYNC 0 + +static void +test(void) { + + struct kevent ev[2]; + struct timespec ts; + int fd, kq, n; + + if ((fd = open(file1, O_RDONLY, 0)) == -1) + err(1, "open(%s)(2)", file1); + atomic_add_int(&share[SYNC], 1); + + 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++; + + ts.tv_sec = 5; + ts.tv_nsec = 0; + + if (kevent(kq, ev, n, NULL, 0, &ts) < 0) + err(1, "kevent()"); + + memset(&ev, 0, sizeof(ev)); + n = kevent(kq, NULL, 0, ev, 1, NULL); + 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, &ts); + close(fd); + close(kq); +} + +int +main(int argc, char **argv) { + size_t len; + int e, fd, i, j, status; + + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", + argv[0]); + return (1); + } + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + e = 0; + file1 = argv[1]; + file2 = argv[2]; + + for (j = 0; j < 100 && e == 0; 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); + + share[SYNC] = 0; + for (i = 0; i < N; i++) { + if (fork() == 0) { + test(); + return (0); + } + } + + while (share[SYNC] != N) + usleep(200); + + sleep(1); + if (unlink(file1) == -1) + err(1, "unlink(%s). %s:%d\n", file1, __FILE__, + __LINE__); + sleep(2); + 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__); + if (status != 0) + e = 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/kevent6.sh b/tools/test/stress2/misc/kevent6.sh new file mode 100755 index 000000000000..528bde5e78a1 --- /dev/null +++ b/tools/test/stress2/misc/kevent6.sh @@ -0,0 +1,168 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# "Sleeping thread (tid 101094, pid 13104) owns a non-sleepable lock" seen. +# Fixed in r255798. + +# panic: Memory modified after free: +# https://people.freebsd.org/~pho/stress/log/alan011.txt +# https://people.freebsd.org/~pho/stress/log/kevent6.txt +# Fixed by: r286921 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent6.c +mycc -o kevent6 -Wall -Wextra -O2 -g kevent6.c -lpthread || exit 1 +rm -f kevent6.c +cd $odir + +mount | grep "on $mntpoint " | grep -q md$mdstart && umount -f $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +su $testuser -c "(cd $mntpoint; /tmp/kevent6)" + +while mount | grep -q $mntpoint; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart + +mount -o size=1g -t tmpfs tmpfs $mntpoint +chmod 777 $mntpoint +su $testuser -c "(cd $mntpoint; /tmp/kevent6)" +while mount | grep -q $mntpoint; do + umount $mntpoint || sleep 1 +done +rm -f /tmp/kevent6 + +exit +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 500000 +#define PARALLEL 8 + +static int fd; +static char path[80]; + +static void * +spin(void *arg __unused) +{ + int i; + + for (i= 0;; i++) { + snprintf(path, sizeof(path), "file.%06d.%d", getpid(), i); + if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == + -1) + err(1, "creat()"); + close(fd); + usleep(10000); + fd = 0; + unlink(path); + } + return (NULL); +} + +static void * +test(void *arg __unused) +{ + int kq; + int i, n; + struct kevent ev; + struct timespec ts; + + for (i = 0; i < LOOPS; i++) { + if ((kq = kqueue()) < 0) + err(1, "kqueue()"); + + n = 0; + memset(&ev, 0, sizeof(ev)); + EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, + NOTE_DELETE|NOTE_RENAME|NOTE_EXTEND, 0, 0); + n++; + + if (kevent(kq, &ev, n, NULL, 0, NULL) < 0) { + close(kq); + continue; + } + + memset(&ev, 0, sizeof(ev)); + ts.tv_sec = 0; + ts.tv_nsec = 1000000; + if ((n = kevent(kq, NULL, 0, &ev, 1, &ts)) == -1) + err(1, "kevent()"); + + close(kq); + } + return (NULL); +} + +int +main(void) +{ + pthread_t cp[PARALLEL], sp; + int e, i; + + if ((e = pthread_create(&sp, NULL, spin, NULL)) != 0) + errc(1, e, "pthread_create"); + + for (i = 0; i < PARALLEL; i++) { + if ((e = pthread_create(&cp[i], NULL, test, NULL)) != 0) + errc(1, e, "pthread_create"); + } + + for (i = 0; i < PARALLEL; i++) + pthread_join(cp[i], NULL); + + close(fd); + + return (0); +} diff --git a/tools/test/stress2/misc/kevent7.sh b/tools/test/stress2/misc/kevent7.sh new file mode 100755 index 000000000000..9383918ea134 --- /dev/null +++ b/tools/test/stress2/misc/kevent7.sh @@ -0,0 +1,281 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Threaded syscall(2) fuzz test inspired by the iknowthis test suite +# by Tavis Ormandy + +# kevent(2) with random arguments. +# Spinning threads seen. +# Fixed in r255877. + +# "panic: softclock_call_cc: act 0xfffff801219a0840 0" seen: +# https://people.freebsd.org/~pho/stress/log/kevent7.txt +# Fixed by r315289 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +ulimit -t 200 +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent7.c +rm -f /tmp/kevent7 +mycc -o kevent7 -Wall -Wextra -O2 -g kevent7.c -lpthread || exit 1 +rm -f kevent7.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +for i in `jot 5`; do + (cd $mntpoint; /tmp/kevent7 $* < /dev/null) & + sleep 60 + while pgrep -q kevent7; do + pkill -9 kevent7 + sleep 1 + done +done + +for i in `jot 5`; do + mount | grep -q md${mdstart}$part && \ + umount $mntpoint && mdconfig -d -u $mdstart && break + sleep 10 +done +if mount | grep -q md${mdstart}$part; then + fstat $mntpoint + echo "umount $mntpoint failed" + exit 1 +fi +rm -f /tmp/kevent7 +exit 0 +EOF +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define THREADS 50 + +int fd[900], fds[2], socketpr[2]; +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +static u_int32_t r[N]; +static int syscallno; + +static void +hand(int i __unused) { /* handler */ + _exit(1); +} + +static unsigned long +makearg(void) +{ + unsigned int i; + unsigned long val; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +static void * +test(void *arg __unused) +{ + + FTS *fts; + FTSENT *p; + int ftsoptions; + int i; + char *args[5]; + + ftsoptions = FTS_PHYSICAL; + args[0] = "/dev"; + args[1] = "/proc"; + args[2] = "/usr/compat/linux/proc"; + args[3] = "."; + args[4] = 0; + + for (;;) { + for (i = 0; i < N; i++) + r[i] = arc4random(); + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + i = 0; + while ((p = fts_read(fts)) != NULL) { + if (fd[i] > 0) + close(fd[i]); + if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) + if ((fd[i] = open(p->fts_path, O_WRONLY)) == + -1) + if ((fd[i] = open(p->fts_path, + O_RDONLY)) == -1) + continue; + i++; + i = i % nitems(fd); + } + + if (fts_close(fts) == -1) + if (errno != ENOTDIR) + warn("fts_close()"); + if (pipe(fds) == -1) + err(1, "pipe()"); + if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, socketpr) == -1) + err(1, "socketpair()"); + sleep(1); + close(socketpr[0]); + close(socketpr[1]); + close(fds[0]); + close(fds[1]); + } + return(0); +} + +static void * +calls(void *arg __unused) +{ + unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; + int i, kq, num; + + if ((kq = kqueue()) < 0) + err(1, "kqueue()"); + for (i = 0; i < 1000; i++) { + if (i == 0) + usleep(1000); + num = syscallno; + arg1 = makearg(); + arg2 = makearg(); + arg3 = makearg(); + arg4 = makearg(); + arg5 = makearg(); + arg6 = makearg(); + arg7 = makearg(); + +#if 0 + fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx," + " %lx, %lx)\n", + i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); +#endif + alarm(1); + syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + num = 0; + } + close(kq); + + return (0); +} + +int +main(void) +{ + struct passwd *pw; + time_t start; + pthread_t rp, cp[THREADS]; + int e, j, n; + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + signal(SIGALRM, hand); + signal(SIGILL, hand); + signal(SIGFPE, hand); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + signal(SIGURG, hand); + signal(SIGSYS, hand); + signal(SIGTRAP, hand); + + syscallno = SYS_kevent; + + n = 0; + start = time(NULL); + while (time(NULL) - start < 120) { + if (fork() == 0) { + if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) + errc(1, e, "pthread_create"); + usleep(1000); + for (j = 0; j < THREADS; j++) { + if ((e = pthread_create(&cp[j], NULL, calls, + NULL)) != 0) + errc(1, e, "pthread_create"); + } + for (j = 0; j < THREADS; j++) + pthread_join(cp[j], NULL); + if ((e = pthread_kill(rp, SIGINT)) != 0) + errc(1, e, "pthread_kill"); + _exit(0); + } + wait(NULL); + if (n++ > 5000) + break; + } + + return (0); +} diff --git a/tools/test/stress2/misc/kevent8.sh b/tools/test/stress2/misc/kevent8.sh new file mode 100755 index 000000000000..66007eb5a2b1 --- /dev/null +++ b/tools/test/stress2/misc/kevent8.sh @@ -0,0 +1,163 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Out of VM seen due to missing close of kqueue handle. +# Fixed in 256849 + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +ulimit -k 5000 || { echo FAIL; exit 1; } + +odir=`pwd` + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > kevent8.c +mycc -o kevent8 -Wall -Wextra -O2 -g kevent8.c -lpthread || exit 1 +rm -f kevent8.c +cd $odir + +mount | grep "on $mntpoint " | grep -q md$mdstart && umount -f $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +su $testuser -c "(cd $mntpoint; /tmp/kevent8)" & +for i in `jot 99`; do + sleep 1 + kill -0 $! 2>/dev/null || break +done +umount -f $mntpoint +pkill kevent8 +wait + +while mount | grep -q $mntpoint; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/kevent8 + +exit +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 64 + +static int fd; +static char path[80]; + +static void * +spin(void *arg __unused) +{ + int i; + setproctitle("spin"); + + for (i= 0;; i++) { + snprintf(path, sizeof(path), "file.%06d.%d", getpid(), i); + if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == + -1) + err(1, "creat()"); + close(fd); + fd = 0; + unlink(path); + } + return (NULL); +} + +static void * +test(void *arg __unused) +{ + int kq; + int i, n; + struct kevent ev; + struct timespec ts; + + for (i = 0; i < 500000; i++) { + if ((kq = kqueue()) < 0) + if (errno != ENOMEM) + err(1, "kqueue()"); + + n = 0; + memset(&ev, 0, sizeof(ev)); + EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, + NOTE_DELETE|NOTE_RENAME|NOTE_EXTEND, 0, 0); + n++; + + if (kevent(kq, &ev, n, NULL, 0, NULL) < 0) + continue; /* Note: missing close(kq)! */ + + memset(&ev, 0, sizeof(ev)); + ts.tv_sec = 0; + ts.tv_nsec = 1000000; + if ((n = kevent(kq, NULL, 0, &ev, 1, &ts)) == -1) + err(1, "kevent()"); + + close(kq); + } + return (NULL); +} + +int +main(void) +{ + pthread_t cp[PARALLEL], sp; + int e, i; + + if ((e = pthread_create(&sp, NULL, spin, NULL)) != 0) + errc(1, e, "pthread_create"); + + for (i = 0; i < PARALLEL; i++) { + if ((e = pthread_create(&cp[i], NULL, test, NULL)) != 0) + errc(1, e, "pthread_create"); + } + + for (i = 0; i < PARALLEL; i++) + pthread_join(cp[i], NULL); + + close(fd); + + return (0); +} diff --git a/tools/test/stress2/misc/kevent9.sh b/tools/test/stress2/misc/kevent9.sh new file mode 100755 index 000000000000..e7b88a06ec1b --- /dev/null +++ b/tools/test/stress2/misc/kevent9.sh @@ -0,0 +1,206 @@ +#!/bin/sh + +# Test scenario by Eric Badger + +# userret: returning with the following locks held: +# exclusive sleep mutex process lock (process lock) r = 0 (0xcb714758) +# locked @ kern/kern_event.c:2125 +# panic: witness_warn + +# https://people.freebsd.org/~pho/stress/log/kevent9.txt +# Fixed in r302235. + +. ../default.cfg + +[ `sysctl -n hw.ncpu` -ne 4 ] && echo "For best results use hw.ncpu == 4" + +cd /tmp +cat > /tmp/kevent9-1.c < +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define NUM_PROCS 4000 + +void *procmaker(void *arg __unused) +{ + pthread_set_name_np(pthread_self(), "procmaker"); + for (int i = 0; i < NUM_PROCS; ++i) + { + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 50000; + nanosleep(&ts, NULL); + switch(fork()) + { + case -1: + err(1, "fork"); + break; + case 0: + execl("./kevent9-2", "kevent9-2", NULL); + _exit(127); + break; + default: + break; + } + } + printf("done forking\n"); + return NULL; +} + +void *reaper(void *arg __unused) +{ + pthread_set_name_np(pthread_self(), "reaper"); + int counter = 0; + while (counter < NUM_PROCS) + { + int status; + if (wait(&status) > 0) + { + ++counter; + } + } + printf("Reaped %d\n", counter); + return NULL; +} + +int main() +{ + pthread_set_name_np(pthread_self(), "main"); + + int kqfd = kqueue(); + if (kqfd == -1) + { + err(1, "kqueue()"); + } + + struct kevent change; + memset(&change, 0, sizeof(change)); + change.ident = getpid(); + change.filter = EVFILT_PROC; + change.flags = EV_ADD | EV_ENABLE; + change.fflags = NOTE_EXIT | NOTE_EXEC | NOTE_FORK | NOTE_TRACK; + + if (kevent(kqfd, &change, 1, NULL, 0, NULL) == -1) + { + err(1, "kevent change"); + } + + pthread_t t; + pthread_create(&t, NULL, procmaker, NULL); + pthread_create(&t, NULL, reaper, NULL); + + int numexecs = 0; + int numexits = 0; + int numforks = 0; + int nummults = 0; + int numchlds = 0; + int numterrs = 0; + + while (1) + { + struct kevent event; + struct timespec to; + to.tv_sec = 1; + to.tv_nsec = 0; + int ret = kevent(kqfd, NULL, 0, &event, 1, &to); + if (ret == -1) + { + err(1, "kevent event"); + } + else if (ret == 0) + { + printf("numexecs: %d numexits: %d numforks: %d numchlds: %d numterrs: %d nummults: %d\n", + numexecs, numexits, numforks, numchlds, numterrs, nummults); + + // Sometimes we miss a NOTE_EXIT. If it hasn't arrived by the timeout, bail out since + // it will probably never arrive. + break; + /* + if (numexits == NUM_PROCS) + { + break; + } + else + { + continue; + } + */ + } + + int numflags = 0; + if (event.fflags & NOTE_EXEC) + { + ++numflags; + ++numexecs; + } + if (event.fflags & NOTE_EXIT) + { + ++numflags; + ++numexits; + } + if (event.fflags & NOTE_FORK) + { + ++numflags; + ++numforks; + } + if (event.fflags & NOTE_CHILD) + { + ++numflags; + ++numchlds; + } + if (event.fflags & NOTE_TRACKERR) + { + ++numflags; + ++numterrs; + } + if (numflags > 1) + { + ++nummults; + } + + /* + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 50000; + nanosleep(&ts, NULL); + */ + } + return 0; +} +EOF + +cat > /tmp/kevent9-2.c < + +int main() +{ + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 1000; + nanosleep(&ts, NULL); + return 0; +} +EOF + +mycc -o kevent9-1 -Wall -Wextra -O2 -g kevent9-1.c -lpthread || exit 1 +mycc -o kevent9-2 -Wall -Wextra -O2 -g kevent9-2.c || exit 1 +rm kevent9-1.c kevent9-2.c + +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 300 ]; do + ./kevent9-1 > /dev/null +done +rm kevent9-1 kevent9-2 +exit 0 diff --git a/tools/test/stress2/misc/killpg.sh b/tools/test/stress2/misc/killpg.sh new file mode 100755 index 000000000000..c6af55a3d593 --- /dev/null +++ b/tools/test/stress2/misc/killpg.sh @@ -0,0 +1,155 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Regression test for r241859: +# Return EPERM if processes were found but they were unable to be signaled. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > killpg.c +mycc -o killpg -Wall -Wextra killpg.c || exit 1 +rm -f killpg.c + +/tmp/killpg + +rm -f /tmp/killpg +exit 0 +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static pid_t gid, pid; + +#define LOOPS 100 + +static void +hand(int i __unused) { /* handler */ + _exit(0); +} + +static void +nlooper(void) +{ + int i; + + setproctitle("nlooper"); + setpgrp(0, getpid()); + for (i = 0; i < LOOPS; i++) { + if ((pid = fork()) == 0) { + signal(SIGINFO, hand); + if (arc4random() % 100 < 10) + usleep(arc4random() % 100); + _exit(0); + } + wait(NULL); + } + _exit(0); +} + +static void +looper(void) +{ + int i; + + setproctitle("looper"); + setpgrp(0, getpid()); + for (i = 0; i < LOOPS; i++) { + if ((pid = fork()) == 0) { + signal(SIGINFO, hand); + if (arc4random() % 100 < 10) + usleep(arc4random() % 100); + _exit(0); + } + wait(NULL); + } + unlink("cont"); + _exit(0); +} + +static void +killer(void) +{ + struct passwd *pw; + + setproctitle("killer"); + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + if ((gid = fork()) == 0) + nlooper(); /* nobody looper */ + + sleep(1); + while (access("cont", R_OK) == 0) { + if (killpg(gid, SIGINFO) == -1) { + if (errno == EPERM) + continue; + warn("FAIL killpg"); + } + } + _exit(0); +} + +int +main(void) +{ + int fd; + + if ((fd = open("cont", O_RDWR | O_CREAT, 0666)) == -1) + err(1, "creat"); + close(fd); + signal(SIGINFO, SIG_IGN); + + if ((gid = fork()) == 0) + looper(); + if (fork() == 0) + killer(); + + wait(NULL); + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/kinfo.sh b/tools/test/stress2/misc/kinfo.sh new file mode 100755 index 000000000000..8cd5bdf0fb54 --- /dev/null +++ b/tools/test/stress2/misc/kinfo.sh @@ -0,0 +1,162 @@ +#!/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. +# + +# 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 +mycc -o kinfo -Wall kinfo.c -lutil || exit 1 +rm -f kinfo.c + +mount | grep -q procfs || mount -t procfs procfs /proc +for i in `jot 20`; 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/tools/test/stress2/misc/kinfo2.sh b/tools/test/stress2/misc/kinfo2.sh new file mode 100755 index 000000000000..307763d88144 --- /dev/null +++ b/tools/test/stress2/misc/kinfo2.sh @@ -0,0 +1,186 @@ +#!/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. +# + +# 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 > kinfo2.c +mycc -o kinfo2 -Wall -Wextra kinfo2.c -lutil || exit 1 +rm -f kinfo2.c + +mount | grep -q procfs || mount -t procfs procfs /proc +s=0 +for i in `jot 15`; do + pids="" + for j in `jot 5`; do + /tmp/kinfo2 & + pids="$pids $!" + done + for p in $pids; do + wait $p + [ $? -ne 0 ] && s=1 + done +done + +rm -f /tmp/kinfo2 +exit $s +EOF + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static char buf[8096]; + +static void +handler(int i __unused) { + _exit(0); +} + +/* Stir /dev/proc */ +static void +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 dirent *dp; + struct kinfo_file *freep; + struct kinfo_vmentry *freep_vm; + struct stat sb; + pid_t pid; + off_t base; + long l; + int cnt, fd, n; + int space = sizeof(buf); + char *bp = buf; + char *dummy; + + if ((fd = open("/proc", O_RDONLY)) == -1) + err(1, "open(%s)", "/proc"); + + if (fstat(fd, &sb) == -1) + err(1, "fstat()"); + do { + if ((n = getdirentries(fd, bp, space, &base)) == -1) + err(1, "getdirentries"); + space = space - n; + if (space < sb.st_blksize) + break; + bp = bp + n; + } while (n != 0); + close(fd); + + bp = buf; + dp = (struct dirent *)bp; + for (;;) { +#if defined(DEBUG) + printf("name: %-10s, inode %7ju, type %2d, namelen %d, " + "d_reclen %d\n", + dp->d_name, (uintmax_t)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(void) +{ + 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/tools/test/stress2/misc/kinfo3.sh b/tools/test/stress2/misc/kinfo3.sh new file mode 100755 index 000000000000..9f4d00dbf2fb --- /dev/null +++ b/tools/test/stress2/misc/kinfo3.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. +# + +# 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 > kinfo3.c +mycc -o kinfo3 -Wall -Wextra kinfo3.c -lutil -pthread || exit 1 +rm -f kinfo3.c + +s=0 +mount | grep -q procfs || mount -t procfs procfs /proc +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 1200 ]; do + pids="" + for i in `jot 5`; do + timeout 5m /tmp/kinfo3 & + pids="$pids $!" + done + for pid in $pids; do + wait $pid + r=$? + [ $r -ne 0 ] && { s=1; echo "Exit code $r"; break; } + done +done + +rm -f /tmp/kinfo3 +exit $s +EOF + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char buf[8096]; +static volatile sig_atomic_t more; + +static void +handler(int i __unused) { + + more = 0; +} + +static void * +thr(void *arg __unused) +{ + int fd; + + if ((fd = open("/proc/curproc/mem", O_RDONLY)) == -1) + err(1, "open(/proc/curproc/mem)"); + close(fd); + return (0); +} + +/* Stir /dev/proc */ +static int +churning(void) { + pid_t r; + pthread_t threads[5]; + int i, status;; + + while(more) { + r = fork(); + if (r == 0) { + for (i = 0; i < 5; i++) { + if ((r = pthread_create(&threads[i], NULL, thr, 0)) != 0) + errc(1, r, "pthread_create()"); + } + for (i = 0; i < 5; i++) { + if ((r = pthread_join(threads[i], NULL)) != 0) + errc(1, r, "pthread_join(%d)", i); + } + + bzero(buf, sizeof(buf)); + _exit(0); + } + if (r < 0) { + perror("fork"); + exit(2); + } + wait(&status); + } + _exit(0); +} + +/* Get files for each proc */ +static void +list(void) +{ + struct kinfo_proc *kipp; + struct kinfo_vmentry *freep_vm; + struct kinfo_file *freep, *kif; + size_t len; + long i, j; + int cnt, name[4]; + + 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 < (long)(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(void) +{ + pid_t r; + + signal(SIGALRM, handler); + alarm(30); + + more = 1; + if ((r = fork()) == 0) { + alarm(30); + while(more) + churning(); + } + if (r < 0) { + perror("fork"); + exit(2); + } + + while(more) + list(); + + return (0); +} diff --git a/tools/test/stress2/misc/kpti.sh b/tools/test/stress2/misc/kpti.sh new file mode 100755 index 000000000000..c5ca254a48d6 --- /dev/null +++ b/tools/test/stress2/misc/kpti.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Simple test of kpti (Kernel page-table isolation) enable / disable + +# Page fault seen: https://people.freebsd.org/~pho/stress/log/dougm061.txt +# Fixed by r354132 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +proccontrol -m kpti -q 2> /dev/null || exit 0 +[ `sysctl -n vm.pmap.pti` -eq 1 ] && echo "Page Table Isolation enabled" || + echo "Page Table Isolation disabled" + +prog=date +[ $# -eq 1 ] && prog=$1 +start=`date +%s` +while [ $((`date +%s` - start)) -lt 120 ]; do + for i in `jot 50`; do + proccontrol -m kpti -s disable $prog & + proccontrol -m kpti -s enable $prog & + done > /dev/null + wait +done +exit 0 diff --git a/tools/test/stress2/misc/largepage.sh b/tools/test/stress2/misc/largepage.sh new file mode 100755 index 000000000000..3c8e745ff3ab --- /dev/null +++ b/tools/test/stress2/misc/largepage.sh @@ -0,0 +1,152 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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 scenario for of non-transparent superpages. + +# No problems seen. + +. ../default.cfg +[ `uname -p` = "i386" ] && exit 0 +[ -z "`sysctl -i vm.largepages`" ] && exit 0 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > largepage.c +mycc -o largepage -Wall -Wextra -g -O0 largepage.c || exit 1 +rm -f largepage.c +cd $odir + +/tmp/largepage +s=$? + +for path in `posixshmcontrol ls | grep largepage | awk '{print $NF}'`; do + echo "posixshmcontrol rm $path" + posixshmcontrol rm $path +done +rm -f ./largepage /tmp/largepage.0* /tmp/largepage +exit 0 + +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static size_t ps[MAXPAGESIZES]; +static int fd; + +#define PARALLEL 4 +#define RUNTIME 60 + +static void +work(int idx) +{ + size_t len; + int i,r; + char *p; + volatile char val; + char path[PATH_MAX]; + + len = ps[idx]; + sprintf(path, "/tmp/largepage.%06d", getpid()); + if ((fd = shm_create_largepage(path, O_CREAT | O_RDWR, idx, + SHM_LARGEPAGE_ALLOC_DEFAULT, 0600)) == -1) + err(1,"shm_create_largepage(%zu)", len); + + for (i = 0; i < 100; i++) { + r = ftruncate(fd, len); + if (r == 0) + break; + usleep(200000); + } + if (r == -1) { + shm_unlink(path); + err(1, "ftruncate(%zu)", len); + } + close(fd); + if ((fd = shm_open(path, O_RDWR, 0)) == -1) + err(1, "shm_open()"); + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) { + if (errno == ENOMEM) + return; + err(1, "mmap()"); + } + + val = p[arc4random() % len]; + + close(fd); + if (munmap(p, len) == -1) + err(1, "munmap(%p)", p); + if (shm_unlink(path) == -1) + err(1, "shm_unlink()"); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + time_t start; + int e, i, n, nps, status; + + nps = getpagesizes(ps, MAXPAGESIZES); + e = 0; + n = 1; + start = time(NULL); + while (time(NULL) - start < RUNTIME && e == 0) { + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + work(n); + } + + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) != pids[i]) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) e = 1; + } + n++; + n = n % nps; + if (n == 0) /* skip 4k pages */ + n = 1; + } + close(fd); + + return (e); +} diff --git a/tools/test/stress2/misc/laundry.sh b/tools/test/stress2/misc/laundry.sh new file mode 100755 index 000000000000..5d368432ac3c --- /dev/null +++ b/tools/test/stress2/misc/laundry.sh @@ -0,0 +1,177 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# vm.stats.vm.v_laundry_count test. WiP. No problems seen. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/laundry.c +mycc -o laundry -Wall -Wextra -O0 -g laundry.c || exit 1 +rm -f laundry.c +cd $odir + +size=`sysctl -n hw.usermem` +swaptotal=`sysctl -n vm.swap_total` +[ $swaptotal -eq 0 ] && exit 0 +[ $size -gt $swaptotal ] && size=$swaptotal +size=$((size / 10 * 8)) +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +set +e + +cd $mntpoint +$dir/laundry $size +s=$? +[ -f laundry.core -a $s -eq 0 ] && + { ls -l laundry.core; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && exit 1 +mdconfig -d -u $mdstart +rm -rf $dir/laundry +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; +size_t size; + +#define PARALLEL 4 +#define RUNTIME (5 * 60) +#define SYNC 0 + +static void +test(void) +{ + size_t i, sz; + time_t start; + int n; + char *cp; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + sz = size; + if ((cp = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0)) == + (caddr_t) - 1) + err(1, "mmap size %zd", sz); + + n = 0; + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + n++; + n = n & 0xff; + for (i = 0; i < sz; i += PAGE_SIZE) + cp[i] = n; + usleep(100); + } + munmap(cp, sz); + + _exit(0); +} + +int +main(int argc __unused, char *argv[]) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, status; + u_int i; + + sscanf(argv[1], "%zd", &size); + size /= PARALLEL; + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFEXITED(status)) { + printf("exited, status=%d\n", + WEXITSTATUS(status)); + } else if (WIFSIGNALED(status)) { + printf("killed by signal %d\n", + WTERMSIG(status)); + } else if (WIFSTOPPED(status)) { + printf("stopped by signal %d\n", + WSTOPSIG(status)); + } else if (WIFCONTINUED(status)) { + printf("continued\n"); + } + fprintf(stderr, "pid %d exit code %d\n", + pids[i], status); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} + diff --git a/tools/test/stress2/misc/ldt.sh b/tools/test/stress2/misc/ldt.sh new file mode 100755 index 000000000000..21c7055d76fe --- /dev/null +++ b/tools/test/stress2/misc/ldt.sh @@ -0,0 +1,370 @@ +#!/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 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 + +. ../default.cfg + +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; rm fault_static_i386.core; } +fi +exit 0 diff --git a/tools/test/stress2/misc/ldt2.sh b/tools/test/stress2/misc/ldt2.sh new file mode 100755 index 000000000000..31ee4725bd52 --- /dev/null +++ b/tools/test/stress2/misc/ldt2.sh @@ -0,0 +1,99 @@ +#!/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/tools/test/stress2/misc/libMicro.sh b/tools/test/stress2/misc/libMicro.sh new file mode 100755 index 000000000000..dc60dfd1c304 --- /dev/null +++ b/tools/test/stress2/misc/libMicro.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. +# + +# Test using the OpenSolaris libmicro benchmark +# Has shown page fault with the cascade_lockf test + +if [ $# -eq 0 ]; then + . ../default.cfg + + [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + + [ -x /usr/local/bin/libmicro-bench ] || + { echo "ports/benchmarks/libmicro is not installed"; exit 0; } + + [ `id -un` = $testuser ] && + { echo "\$testuser is identical to current id"; exit 1; } + + rm -f /tmp/libmicro.log + trap "rm -rf /var/tmp/libmicro.[0-9]*" 0 + su $testuser -c "$0 x" + echo "" +else + /usr/local/bin/libmicro-bench > /tmp/libmicro.log & + # Temp. work-around for hanging "c_lockf_10" test. + sleep 60 + kill 0 + wait +fi diff --git a/tools/test/stress2/misc/linger.sh b/tools/test/stress2/misc/linger.sh new file mode 100755 index 000000000000..fee2524ffd3b --- /dev/null +++ b/tools/test/stress2/misc/linger.sh @@ -0,0 +1,168 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Demonstrate premature "out of inodes" problem with SU + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > linger.c +mycc -o linger -Wall -O2 linger.c +rm -f linger.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && 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 +[ $# -eq 1 ] && opt="$1" +[ $# -eq 0 ] && opt=$newfs_flags # No argument == default flag +echo "newfs $opt md${mdstart}$part" +newfs $opt md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +if ! su $testuser -c "cd $mntpoint; /tmp/linger $size"; then + min=2 + [ -r $mntpoint/.sujournal ] && min=3 + r=`df -hi $mntpoint | head -1` + echo " $r" + for i in `jot 10`; do + r=`df -hi $mntpoint | tail -1` + echo "`date '+%T'` $r" + [ `echo $r | awk '{print $6}'` = $min ] && break + sleep 10 + done + ls -lR $mntpoint +fi + +while mount | grep "$mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/linger +exit +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 10 +#define TIMEOUT 1200 +static int size = 6552; /* 10 free inodes */ + +static int +test(void) +{ + int fd, i, j; + pid_t pid; + char file[128]; + + for (;;) { + if (access("rendezvous", R_OK) == 0) + break; + sched_yield(); + } + pid = getpid(); + for (j = 0; j < size; 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__); + unlink("continue"); + break; + } + } + if (fd != -1 && close(fd) == -1) + err(2, "close(%d)", j); + + } + sleep(3); + + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + warn("unlink(%s)", file); + + } + return (0); +} + +int +main(void) +{ + time_t start; + int error = 0, fd, i, j, status; + + umask(0); + if ((fd = open("continue", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + start = time(NULL); + for (i = 0; i < 100; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) { + test(); + exit(0); + } + } + + if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + + for (j = 0; j < PARALLEL; j++) { + wait(&status); + error += status; + } + + unlink("rendezvous"); + if (access("continue", R_OK) == -1) + break; + if (time(NULL) - start > TIMEOUT) { + fprintf(stderr, "FAIL Timeout\n"); + break; + } + } + unlink("continue"); + + return (error != 0); +} diff --git a/tools/test/stress2/misc/linger2.sh b/tools/test/stress2/misc/linger2.sh new file mode 100755 index 000000000000..e5dad8d7e21d --- /dev/null +++ b/tools/test/stress2/misc/linger2.sh @@ -0,0 +1,172 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Variation of linger.sh, with emphasis on blocks. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > linger2.c +mycc -o linger2 -Wall -O2 linger2.c +rm -f linger2.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && 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 +[ $# -eq 1 ] && opt="$1" +[ $# -eq 0 ] && opt=$newfs_flags # No argument == default flag +newfs $opt -n md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint +set `df -i $mntpoint | tail -1 | awk '{print $3, $6}'` + +min=24 +[ -r $mntpoint/.sujournal ] && { size=88; min=8232; } +if ! su $testuser -c "cd $mntpoint; /tmp/linger2 $size 2>/dev/null"; then + r=`df -i $mntpoint | head -1` + echo " $r" + for i in `jot 12`; do + r=`df -ik $mntpoint | tail -1` + [ "$r" != "$old" ] && echo "`date '+%T'` $r" + old=$r + [ `echo $r | awk '{print $3}'` -le $min ] && break + sleep 10 + done +fi + +while mount | grep "$mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/linger2 +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 10 +static int size = 89; + +int +test(void) +{ + int error = 0, fd, i, j; + pid_t pid; + char file[128]; + char *buf; + + for (;;) { + if (access("rendezvous", R_OK) == 0) + break; + sched_yield(); + } + pid = getpid(); + buf = malloc(1024 * 1024); + for (j = 0; j < size; 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__); + unlink("continue"); + error = 1; + break; + } + } + if (write(fd, buf, 1024 * 1024) != 1024 * 1024) { + warn("write()"); + unlink("continue"); + error = 1; + break; + } + if (fd != -1 && close(fd) == -1) + err(2, "close(%d)", j); + + } + sleep(3); + + if (error == 0) + j--; + for (i = j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + warn("unlink(%s)", file); + + } + return (error); +} + +int +main(int argc, char **argv) +{ + int error = 0, fd, i, j, status; + + if (argc == 2) + size = atoi(argv[1]); + + umask(0); + if ((fd = open("continue", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + for (i = 0; i < 200; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + exit(test()); + } + + if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + + for (j = 0; j < PARALLEL; j++) { + wait(&status); + error += status; + } + + unlink("rendezvous"); + if (access("continue", R_OK) == -1) { + break; + } + } + unlink("continue"); + + return (error != 0); +} diff --git a/tools/test/stress2/misc/linger3.sh b/tools/test/stress2/misc/linger3.sh new file mode 100755 index 000000000000..c888d992138a --- /dev/null +++ b/tools/test/stress2/misc/linger3.sh @@ -0,0 +1,134 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 for SU problem with false EMLINK + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > linger3.c +mycc -o linger3 -Wall -Wextra -O2 linger3.c +rm -f linger3.c + +mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +[ $# -eq 1 ] && opt="$1" +[ $# -eq 0 ] && opt=$newfs_flags # No argument == default flag +echo "newfs $opt md${mdstart}$part" +newfs $opt md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +cd $mntpoint +chmod 777 $mntpoint + +su $testuser -c "/tmp/linger3" + +cd $here + +while mount | grep -q $mntpoint; do + umount $mntpoint 2> /dev/null || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/linger3 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define ND ((32767 / PARALLEL) - 2) + +static pid_t p; + +void +setup(int loop) +{ + int d; + char name[128]; + + for (d = 0; d < ND; d++) { + snprintf(name, sizeof(name), "d%06d.%03d", p, d); + if (mkdir(name, 00700) == -1) + err(1, "mkdir(%s) @ loop #%d", name, loop); + } +} + +void +prune(int loop) +{ + int d; + char name[128]; + + for (d = 0; d < ND; d++) { + snprintf(name, sizeof(name), "d%06d.%03d", p, d); + if (rmdir(name) == -1) + err(1, "rmdir(%s) @ loop #%d", name, loop); + } +} + +int +main() +{ + int i, j; + int linger = 0; + + if (getenv("LINGER")) + linger = atoi(getenv("LINGER")); + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) { + p = getpid(); + for (j = 0; j < 10; j++) { + setup(j); + prune(j); + if (linger != 0) + sleep(linger); + } + _exit(0); + } + } + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/linger4.sh b/tools/test/stress2/misc/linger4.sh new file mode 100755 index 000000000000..1578575fa387 --- /dev/null +++ b/tools/test/stress2/misc/linger4.sh @@ -0,0 +1,155 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 for SU problem with "out of inodes" for CREAT + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > linger4.c +mycc -o linger4 -Wall -Wextra -O2 linger4.c +rm -f linger4.c + +mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +[ $# -eq 1 ] && opt="$1" +[ $# -eq 0 ] && opt="$newfs_flags -n" # No argument == default flag +echo "newfs $opt md${mdstart}$part" +newfs $opt md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +cd $mntpoint +chmod 777 $mntpoint + +su $testuser -c "/tmp/linger4" || + { ls -la $mntpoint; df -i $mntpoint; } + +cd $here + +while mount | grep -q $mntpoint; do + umount $mntpoint 2> /dev/null || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/linger4 +exit 0 +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 300 +#define NUMBER 80000 / PARALLEL /* Number of files to use. Max is 131068 */ +#define PARALLEL 4 +#define TIMEOUT (20 * 60) + +void +Creat(int loopno) +{ + int e, fd, i, j; + char file[128]; + char path[128]; + pid_t pid; + + e = 0; + pid = getpid(); + sprintf(path, "f%06d", pid); + if (mkdir(path, 0770) == -1) + warn("mkdir(%s), %s:%d, loop #%d", path, __FILE__, __LINE__, loopno); + chdir(path); + + for (j = 0; j < NUMBER; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if ((fd = creat(file, 0660)) == -1) { + if (errno != EINTR) { + warn("creat(%s). %s:%d, loop #%d", file, __FILE__, __LINE__, loopno); + e = 1; + 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); + + } + chdir (".."); + if (rmdir(path) == -1) + err(1, "rmdir(%s), %s:%d, loop #%d", path, __FILE__, __LINE__, loopno); + + _exit(e); +} + +int +main() +{ + time_t start; + int e, i, j, status; + + e = 0; + start = time(NULL); + for (j = 0; j < LOOPS; j++) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + Creat(j); + } + + for (i = 0; i < PARALLEL; i++) { + wait(&status); + e += WEXITSTATUS(status); + } + if (e != 0) + break; +// sleep(60); /* No problems if this is included */ + if (time(NULL) - start > TIMEOUT) { + fprintf(stderr, "Timeout.\n"); + e++; + break; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/link.sh b/tools/test/stress2/misc/link.sh new file mode 100755 index 000000000000..64f76ca5f3b0 --- /dev/null +++ b/tools/test/stress2/misc/link.sh @@ -0,0 +1,193 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Deadlock seen for file systems which suspend writes on unmount, such as +# UFS and tmpfs. +# http://people.freebsd.org/~pho/stress/log/link.txt +# Fixed by r272130 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > link.c +mycc -o link -Wall -Wextra -O2 -g link.c || exit 1 +rm -f link.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 5m -i 20 -h -l 100)" \ + > /dev/null 2>&1 +/tmp/link $mntpoint > /dev/null 2>&1 & + +for i in `jot 100`; do + umount -f $mntpoint && + mount /dev/md${mdstart}$part $mntpoint + sleep .1 +done +pkill -9 link +wait + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart + +# tmpfs +mount -t tmpfs tmpfs $mntpoint + +/tmp/link $mntpoint > /dev/null 2>&1 & + +for i in `jot 100`; do + umount -f $mntpoint && + mount -t tmpfs tmpfs $mntpoint + sleep .1 +done +pkill -9 link swap +wait + +while pkill -9 swap; do + : +done > /dev/null 2>&1 +while mount | grep $mntpoint | grep -q tmpfs; do + umount $mntpoint || sleep 1 +done +[ -d "$mntpoint" ] && (cd $mntpoint && find . -delete) +rm -f /tmp/link +exit 0 +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 16 +#define RUNTIME 300 + +time_t start; +char *dir; + +void +trename(void) +{ + int fd; + char name1[MAXPATHLEN + 1]; + char name2[MAXPATHLEN + 1]; + + setproctitle(__func__); + snprintf(name1, sizeof(name1), "%s/r1.%05d", dir, getpid()); + snprintf(name2, sizeof(name2), "%s/r2.%05d", dir, getpid()); + if ((fd = open(name1, O_RDWR | O_CREAT, 0644)) == -1) + err(1, "open(%s)", name1); + close(fd); + + while (time(NULL) - start < RUNTIME) { + if (rename(name1, name2) == -1) { + if (errno == ENOENT) { + if ((fd = open(name1, O_RDWR | O_CREAT, 0644)) == -1) + err(1, "open(%s)", name1); + close(fd); + continue; + } else + warn("link(%s, %s)", name1, name2); + } + if (rename(name2, name1) == -1) + warn("link(%s, %s)", name2, name1); + } + unlink(name1); + unlink(name2); + _exit(0); +} + +void +tlink(void) +{ + int fd; + char name1[MAXPATHLEN + 1]; + char name2[MAXPATHLEN + 1]; + + setproctitle(__func__); + snprintf(name1, sizeof(name1), "%s/f1.%05d", dir, getpid()); + snprintf(name2, sizeof(name2), "%s/f2.%05d", dir, getpid()); + if ((fd = open(name1, O_RDWR | O_CREAT, 0644)) == -1) + err(1, "open(%s)", name1); + close(fd); + + while (time(NULL) - start < RUNTIME) { + unlink(name2); + if (link(name1, name2) == -1) { + if (errno == ENOENT) { + if ((fd = open(name1, O_RDWR | O_CREAT, 0644)) == -1) + err(1, "open(%s)", name1); + close(fd); + continue; + } else + warn("link(%s, %s)", name1, name2); + } + } + unlink(name1); + unlink(name2); + _exit(0); +} + +int +main(int argc, char **argv) +{ + int i, type; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + dir = argv[1]; + type = arc4random() % 2; /* test either link() or rename() */ + + start = time(NULL); + for (i = 0; i < PARALLEL; i++) { + if (type == 0 && fork() == 0) + tlink(); + if (type == 1 && fork() == 0) + trename(); + } + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return(0); +} diff --git a/tools/test/stress2/misc/link2.sh b/tools/test/stress2/misc/link2.sh new file mode 100755 index 000000000000..94116c0dc081 --- /dev/null +++ b/tools/test/stress2/misc/link2.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Copy of link.sh with leak detection added + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/link.sh > link.c +mycc -o link -Wall -Wextra -O2 -g link.c || exit 1 +rm -f link.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 5m -i 20 -h -l 100)" \ + > /dev/null 2>&1 +/tmp/link $mntpoint > /dev/null 2>&1 & + +m1=`vmstat -m | awk '/ mount/ {print $2}'` +for i in `jot 100`; do + umount -f $mntpoint && + mount /dev/md${mdstart}$part $mntpoint + sleep .1 +done +m2=`vmstat -m | awk '/ mount/ {print $2}'` +pkill -9 link +while pgrep -q swap; do + pkill -9 swap +done +wait + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart + +[ -d "$mntpoint" ] && (cd $mntpoint && find . -delete) +rm -f /tmp/link +leak=$((m2 - m1)) +[ $leak -gt 2 ] && + { echo "Leaked $leak InUse \"mount\""; s=1; vmstat -m | \ + sed -n '1p;/ mount/p'; } || + s=0 +exit $s diff --git a/tools/test/stress2/misc/linux.sh b/tools/test/stress2/misc/linux.sh new file mode 100755 index 000000000000..1cbbfb8b27a1 --- /dev/null +++ b/tools/test/stress2/misc/linux.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Bug 230144 - Linux emulator does not work on Ryzen / Epic processors +# No problems seen. + +[ -x /compat/linux/bin/date ] || exit 0 +kldstat | grep -q linux.ko && exit 0 + +set -e +kldload linux.ko +mount -t linprocfs linprocfs /compat/linux/proc +mount -t linsysfs linsysfs /compat/linux/sys +mount -t tmpfs -o rw,mode=1777 tmpfs /compat/linux/dev/shm +[ `uname -m` = amd64 ] && kldload linux64.ko +set +e +[ -x /compat/linux/bin/bash ] && + /compat/linux/bin/bash -c "/compat/linux/bin/date" + +[ `uname -m` = amd64 ] && kldunload linux64.ko +umount /compat/linux/dev/shm +kldstat | grep -q tmpfs.ko && kldunload tmpfs.ko +umount /compat/linux/sys +kldunload linsysfs.ko +umount /compat/linux/proc +kldunload linprocfs.ko +kldunload linux.ko + +exit 0 diff --git a/tools/test/stress2/misc/lockd.sh b/tools/test/stress2/misc/lockd.sh new file mode 100755 index 000000000000..01866e39ef74 --- /dev/null +++ b/tools/test/stress2/misc/lockd.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Demonstrate rpc memory leak when remote lockd & statd are not running. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +pgrep -q lockd || { echo "lockd not running."; exit 0; } + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 +mount -t nfs -o tcp -o nfsv3 -o retrycnt=1 -o soft,timeout=1 \ + -o rw $nfs_export $mntpoint || exit 0 + +lockf -t 10 $mntpoint/$$.lock sleep 2 > /tmp/$$.log 2>&1 +if grep -q "No locks available" /tmp/$$.log; then + echo "Is lockd running on the remote host?" + rm /tmp/$$.log +fi + +rpc1=`vmstat -m | grep rpc | tail -1 | awk '{print $2}'` +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 60 ]; do + for i in `jot 10`; do + rm -f $mntpoint/$0.$$.$i + lockf -t 10 $mntpoint/$0.$$.$i sleep 2 & + done + wait +done +rm -f $mntpoint/$0.$$* + +s=0 +for i in `jot 6`; do + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && s=1 +rpc2=`vmstat -m | grep rpc | tail -1 | awk '{print $2}'` +if [ $((rpc2 - rpc1)) -gt 2 ]; then + echo "rpc memory leak. Was $rpc1, is $rpc2" + s=2 +fi +exit $s diff --git a/tools/test/stress2/misc/lockf.sh b/tools/test/stress2/misc/lockf.sh new file mode 100755 index 000000000000..347bd063bfe1 --- /dev/null +++ b/tools/test/stress2/misc/lockf.sh @@ -0,0 +1,73 @@ +#!/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. +# + +# Page fault seen: +# http://people.freebsd.org/~pho/stress/log/lockf.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +pgrep -q lockd || { echo "lockd not running"; exit 0; } +trap "rm -f /tmp/$0.$$.*" EXIT INT +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint + +mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft \ + -o rw $nfs_export $mntpoint +sleep .5 +lockf -t 10 $mntpoint/$$.lock sleep 2 || fail=1 +umount $mntpoint +[ $fail ] && exit 1 + +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 300 ] ; do + mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft \ + -o rw $nfs_export $mntpoint || break + sleep 1 + + for j in `jot 50`; do + lockf -t 10 $mntpoint/$0.$$.$j sleep 3 & + done + + while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 + done + wait +done 2>/dev/null +mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft \ + -o rw $nfs_export $mntpoint || break +sleep .5 +rm $mntpoint/$0.* +while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 +done +exit 0 diff --git a/tools/test/stress2/misc/lockf2.sh b/tools/test/stress2/misc/lockf2.sh new file mode 100755 index 000000000000..6d1501d581b0 --- /dev/null +++ b/tools/test/stress2/misc/lockf2.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +for i in `jot 100`; do + for j in `jot 50`; do + file=/tmp/lockf2.$$.$j + touch $file + lockf -t 10 $file sleep 3 & + done + + for j in `jot 50`; do + rm -f /tmp/lockf2.$$.$j + done + + for j in `jot 50`; do + wait + done +done diff --git a/tools/test/stress2/misc/lockf3.sh b/tools/test/stress2/misc/lockf3.sh new file mode 100755 index 000000000000..4493fa214a33 --- /dev/null +++ b/tools/test/stress2/misc/lockf3.sh @@ -0,0 +1,163 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > lockf3.c +mycc -o lockf3 -Wall -Wextra -O2 lockf3.c || exit 1 +rm -f lockf3.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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +cd $mntpoint +for i in `jot 3`; do + $here/../testcases/swap/swap -t 10m -i 200 > /dev/null & + /tmp/lockf3 || break + pkill swap + wait +done +while pgrep -q swap; do + pkill swap +done +pkill lockf3 +wait +cd $here + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +rm -rf /tmp/lockf3 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 10000 +#define PIDS 100 + +void +handler(int s __unused) +{ +} + +void +int_handler(int s __unused) +{ + _exit(0); +} + +void +ahandler(int s __unused) +{ + fprintf(stderr, "FAIL timed out\n"); + _exit(1); +} + +int +main(void) +{ + int fd, i, j; + char name[128]; + pid_t pid[PIDS]; + struct sigaction sa; + int status; + + signal(SIGALRM, ahandler); + alarm(15 * 60); + for (i = 0; i < PIDS; i++) { + sprintf(name, "lock.%06d", getpid()); + if ((fd = open(name, O_CREAT | O_TRUNC | O_RDWR, 0640)) == -1) + err(1, "open(%s)", name); + if (lockf(fd, F_LOCK, 0) == -1) + err(1, "flock 1"); + + if ((pid[i] = fork()) == -1) + err(1, "fork"); + + if (pid[i] == 0) { + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = handler; + if (sigaction(SIGHUP, &sa, NULL) == -1) + err(1, "signal"); + sa.sa_handler = int_handler; + if (sigaction(SIGINT, &sa, NULL) == -1) + err(1, "signal"); + + for (;;) { + if (lockf(fd, F_LOCK, 0) == -1) + if (errno != EINTR) + warn("lockf"); + } + _exit(0); + } + unlink(name); + } + + usleep(10000); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PIDS; j++) { + if (kill(pid[j], SIGHUP) == -1) { + warn("kill(%d), i = %d, j = %d", pid[j], i, j); + pid[j] = 0; + } + } + } + for (j = 0; j < PIDS; j++) { + if (kill(pid[j], SIGINT) == -1) { + warn("kill(%d), i = %d, j = %d", pid[j], i, j); + pid[j] = 0; + } + } + + for (j = 0; j < PIDS; j++) { + if (waitpid(pid[j], &status, 0) == -1) + err(1, "waitpid(%d)", pid[j]); + } + + return (0); +} diff --git a/tools/test/stress2/misc/lockf4.sh b/tools/test/stress2/misc/lockf4.sh new file mode 100755 index 000000000000..690bad033cf4 --- /dev/null +++ b/tools/test/stress2/misc/lockf4.sh @@ -0,0 +1,183 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# lockf(3) test scenario. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > lockf4.c +rm -f /tmp/lockf4 +mycc -o lockf4 -Wall -Wextra -g -O2 lockf4.c || exit 1 +rm -f lockf4.c +cd $odir + +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +su $testuser -c "(cd $mntpoint; /tmp/lockf4)" & +su $testuser -c "(cd $mntpoint; /tmp/lockf4)" & +su $testuser -c "(cd $mntpoint; /tmp/lockf4)" & +wait + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/lockf4 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include + +#define N (5 * 1024 * 1024) /* 40 MB */ +int fd; +int idx[N]; +char file[] = "lockf4.file"; + +#define TIMEOUT 600 + +int64_t +add(int ix, int val) +{ + int64_t v; + off_t offset; + time_t start; + int r; + + offset = ix * sizeof(v); + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek"); + start = time(NULL); + while (lockf(fd, F_LOCK, sizeof(v)) == -1) { + if (errno != EDEADLK) + err(1, "lockf(%s, F_LOCK)", file); + if (time(NULL) - start > TIMEOUT) + errx(1, "lockf timedout"); + } + v = 0; + r = read(fd, &v, sizeof(v)); + if (r == 0) + v = 0; + else + if (r == -1) + err(1, "read"); + v += val; + + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek"); + if (write(fd, &v, sizeof(v)) < 0) + err(1, "write"); + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek"); + if (lockf(fd, F_ULOCK, sizeof(v)) == -1) + err(1, "lockf(%s, F_ULOCK)", file); + + return (v); +} + +int +check(void) +{ + int64_t v; + int i; + + setproctitle("check"); + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + for (i = 1; i < N; i++) { + if (read(fd, &v, sizeof(v)) < 0) + err(1, "read"); + if (v != 0) + return (1); + } + + return (0); +} + +int +main(void) +{ + int64_t r; + int e, i, j, t; + char help[80]; + + for (i = 1; i < N; i++) + idx[i] = i; + + for (i = 1; i < N; i++) { + j = arc4random() % (N - 1) + 1; + t = idx[i]; + idx[i] = idx[j]; + idx[j] = t; + } + + if ((fd = open(file, O_RDWR | O_CREAT, 0644)) == -1) + err(1, "open(%s)", file); + + add(0, 1); + for (i = 1; i < N; i++) { + if (i % 500 == 0) { + snprintf(help, sizeof(help), "add %d%%", i * 100 / N); + setproctitle("%s", help); + } + add(idx[i], 1); + } + for (i = 1; i < N; i++) { + if (i % 500 == 0) { + snprintf(help, sizeof(help), "sub %d%%", i * 100 / N); + setproctitle("%s", help); + } + add(idx[i], -1); + } + + e = 0; + if ((r = add(0, -1)) == 0) { + e = check(); + if (e == 0) + unlink(file); + else + fprintf(stderr, "FAIL\n"); + } + + close(fd); + + return (e); +} diff --git a/tools/test/stress2/misc/lockf5.sh b/tools/test/stress2/misc/lockf5.sh new file mode 100755 index 000000000000..5b5dbad1015c --- /dev/null +++ b/tools/test/stress2/misc/lockf5.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# "Fatal trap 9: general protection fault while in kernel mode" seen: +# https://people.freebsd.org/~pho/stress/log/lockf5.txt + +# Test scenario by: ngie@FreeBSD.org. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +pgrep -q lockd || { echo "lockd not running."; exit 1; } + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +mount | grep -q "on $mntpoint " && umount -f $mntpoint +mount -t nfs $nfs_export $mntpoint || exit 1 +sleep .5 +rm -rf $mntpoint/$0 +mkdir -p $mntpoint/$0 + +for i in `jot 100`; do + (cd $mntpoint/$0; lockf -t 10 f$i sleep 5) > /dev/null 2>&1 & +done +sleep 3 + +umount -f $mntpoint +wait + +mount -t nfs $nfs_export $mntpoint || exit 1 +sleep .5 +rm -rf $mntpoint/$0 +umount $mntpoint +exit 0 diff --git a/tools/test/stress2/misc/lookup_shared.sh b/tools/test/stress2/misc/lookup_shared.sh new file mode 100755 index 000000000000..935811bee719 --- /dev/null +++ b/tools/test/stress2/misc/lookup_shared.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -z "`sysctl -in vfs.lookup_shared`" ] && exit 0 + +saved=`sysctl vfs.lookup_shared | awk '{print $NF}'` +trap "sysctl vfs.lookup_shared=$saved" EXIT INT + +export runRUNTIME=10m # Run tests for 10 minutes +sysctl vfs.lookup_shared=0 +(cd ..; ./run.sh disk.cfg) +exit 0 diff --git a/tools/test/stress2/misc/lstat.sh b/tools/test/stress2/misc/lstat.sh new file mode 100755 index 000000000000..f89886a4556e --- /dev/null +++ b/tools/test/stress2/misc/lstat.sh @@ -0,0 +1,236 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Hunt for; +# Bug 204764 - Filesystem deadlock, process in vodead state +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=204764 +# No problem seen. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/lstat.c +mycc -o lstat -Wall -Wextra -O0 -g lstat.c || exit 1 +rm -f lstat.c +cd $odir + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs -n -b 4096 -f 512 -i 1024 md${mdstart}$part > /dev/null +mount -o async /dev/md${mdstart}$part $mntpoint || exit 1 + +path=$mntpoint/a/b/c +mkdir -p $path + +$dir/lstat $path + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -rf $dir/lstat $wdir/lstat.tmp.* +exit + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *dirs, *share; +static char *arg; + +#define R1 0 +#define R2 1 + +#define MXDIRS 3000 +#define PARALLEL 2 +#define RUNTIME 600 +#define SLPTIME 400 + +static void +tfts(int idx) +{ + FTS *fts; + FTSENT *p; + struct stat sb; + int ftsoptions; + char *args[2]; + + if (idx != 0) + _exit(0); + + ftsoptions = FTS_PHYSICAL; + args[0] = arg, + args[1] = 0; + + setproctitle("fts"); + while (share[R2] == 0) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + lstat(fts->fts_path, &sb); + if (share[R2] == 1) + break; + } + + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } + + _exit(0); +} + +static int +test(int idx) +{ + struct stat sb; + pid_t fpid, pd, pid; + size_t len; + int i, n, r; + char dir[128], path[128]; + + atomic_add_int(&share[R1], 1); + while (share[R1] != PARALLEL) + ; + + len = PAGE_SIZE; + if ((dirs = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + if ((fpid = fork()) == 0) + tfts(idx); + + pid = getpid(); + snprintf(dir, sizeof(dir), "%s/dir.%d", arg, pid); + if (mkdir(dir, 0777) == -1) + err(1, "mkdir(%s)", dir); + if (chdir(dir) == -1) + err(1, "chdir(%s)", dir); + if ((pd = fork()) == 0) { + setproctitle("mkdir"); + i = 0; + while (share[R2] == 0) { + snprintf(path, sizeof(path), "%s/d.%d.%d", arg, pid, + i); + n = 0; + while (dirs[0] > MXDIRS && share[R2] == 0) + usleep(SLPTIME); + while ((r = mkdir(path, 0777)) == -1) { + if (errno != EMLINK) + err(1, "mkdir(%s) @ %d", path, + __LINE__); + usleep(SLPTIME); + if (share[2] == 1) + break; + } + if (r == 0) { + atomic_add_int(&dirs[0], 1); + i++; + } + } + + _exit(0); + } + + i = 0; + setproctitle("rmdir"); + while (dirs[0] > 0 || share[R2] == 0) { + n = 0; + if (dirs[0] < MXDIRS / 2) + usleep(SLPTIME); + snprintf(path, sizeof(path), "%s/d.%d.%d", arg, pid, i); + while (lstat(path, &sb) == -1 && share[R2] == 0) { + usleep(SLPTIME); + } + if (rmdir(path) == -1) { + if (errno != ENOENT) + err(1, "rmdir(%s)", path); + } else { + atomic_add_int(&dirs[0], -1); + i++; + } + } + waitpid(pd, NULL, 0); + waitpid(fpid, NULL, 0); + + chdir(".."); + if ((rmdir(dir)) == -1) + err(1, "unlink(%s)", dir); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + size_t len; + int e, i, pids[PARALLEL], status; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + arg = argv[1]; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + share[R1] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(i); + } + sleep(RUNTIME); + share[R2] = 1; + for (i = 0; i < PARALLEL; i++) { + waitpid(pids[i], &status, 0); + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/mac.sh b/tools/test/stress2/misc/mac.sh new file mode 100755 index 000000000000..48fc8a323f0e --- /dev/null +++ b/tools/test/stress2/misc/mac.sh @@ -0,0 +1,38 @@ +#!/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. +# + +[ `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 0 +fi + +./crossmp.sh + +sysctl security.mac.test diff --git a/tools/test/stress2/misc/mac_chkexec.sh b/tools/test/stress2/misc/mac_chkexec.sh new file mode 100755 index 000000000000..d3e961b02200 --- /dev/null +++ b/tools/test/stress2/misc/mac_chkexec.sh @@ -0,0 +1,57 @@ +#!/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. +# + +# Regression test for panic in second ls + +exit 0 # Not part of the kernel +[ `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/tools/test/stress2/misc/machipc.sh b/tools/test/stress2/misc/machipc.sh new file mode 100755 index 000000000000..09294d0d0295 --- /dev/null +++ b/tools/test/stress2/misc/machipc.sh @@ -0,0 +1,184 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Threaded Mach IPC test scenario +# https://people.freebsd.org/~pho/stress/log/kip014.txt + +ps -p1 | grep -q launchd || exit 0 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > machipc.c +cc -o machipc -Wall -Wextra -O2 -g machipc.c -lmach -lpthread || exit 1 +rm machipc.c +cd $odir + +(cd ../testcases/swap; ./swap -t 20m -i 20 -h -v) > /dev/null 2>&1 & +sleep 5 +/tmp/machipc +pkill swap +wait +rm -f /tmp/machipc +exit 0 +EOF +#include + +#include + +#include +#include +#include +#include +#include +#include + +typedef struct { + unsigned int msgt_name : 8, + msgt_size : 8, + msgt_number : 12, + msgt_inline : 1, + msgt_longform : 1, + msgt_deallocate : 1, + msgt_unused : 1; +} mach_msg_type_t; + +struct integer_message { + mach_msg_header_t head; + mach_msg_type_t type; + + int inline_integer; +}; + +struct message_recv +{ + mach_msg_header_t head; + mach_msg_type_t type; + int inline_integer; + mach_msg_trailer_t trailer; +}; + +mach_port_t bootstrap_port; + +#define MACH_MSG_TYPE_INTEGER_32 2 +#define N 100000000 + +static void +error(int exitcode, int macherr, const char *funcname) +{ + printf("%s failed with %x\n", funcname, macherr); + exit(exitcode); +} + +void * +client(void *arg) +{ + mach_port_t port = *(mach_port_t *) arg; + struct message_recv message = {}; + int err, i; + + message.head.msgh_local_port = port; + message.head.msgh_size = sizeof(message); + + for (i = 0; i < N; i++) { + /* Receive a message */ + err = mach_msg(&message.head, /* The header */ + MACH_RCV_MSG, /* Flags */ + 0, /* Send size */ + sizeof(message), /* Max receive size */ + port, /* Receive port */ + MACH_MSG_TIMEOUT_NONE, /* No timeout */ + MACH_PORT_NULL); /* No notification */ + if (err) + error(1, err, "server mach_msg MACH_RCV_MSG"); + if (message.inline_integer != i) + errx(1, "FAIL message.inline_integer = %d, i = %d", + message.inline_integer, i); + } + + return(0); +} + +int +main(void) +{ + pthread_t ptd; + mach_port_t port; + struct integer_message message; + int err, i; + + /* Allocate a port */ + err = mach_port_allocate(mach_task_self(), + MACH_PORT_RIGHT_RECEIVE, &port); + if (err) + error(1, err, "mach_port_allocate"); + + err = mach_port_insert_right(mach_task_self(), + port, port, MACH_MSG_TYPE_MAKE_SEND); + + if (err) + error(10, err, "mach_port_insert_right"); + + if ((err = pthread_create(&ptd, NULL, client, &port)) != 0) { + errc(1, err, "pthread_create failed"); + } + + /* Fill the header fields : */ + message.head.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND); + message.head.msgh_size = sizeof( struct integer_message ); + message.head.msgh_local_port = MACH_PORT_NULL; + message.head.msgh_remote_port = port; + message.head.msgh_id = 0; /* Message id */ + message.head.msgh_size = sizeof(message); /* Message size */ + + /* Set the message type */ + message.type.msgt_name = MACH_MSG_TYPE_INTEGER_32; + message.type.msgt_size = sizeof(message); + message.type.msgt_number = 1; + message.type.msgt_inline = TRUE; + message.type.msgt_longform = FALSE; + message.type.msgt_deallocate = FALSE; + + for (i = 0; i < N; i++) { + + message.inline_integer = i; + + /* Send the message */ + err = mach_msg(&message.head, /* The header */ + MACH_SEND_MSG, /* Flags */ + sizeof(message), /* Send size */ + 0, /* Max receive Size */ + port, /* Send port */ + MACH_MSG_TIMEOUT_NONE, /* No timeout */ + MACH_PORT_NULL); /* No notification */ + if (err) + error(3, err, "client mach_msg"); + } + pthread_join(ptd, NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/machipc2.sh b/tools/test/stress2/misc/machipc2.sh new file mode 100755 index 000000000000..bfa4e288495a --- /dev/null +++ b/tools/test/stress2/misc/machipc2.sh @@ -0,0 +1,292 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Non threaded Mach IPC test scenario +# https://people.freebsd.org/~pho/stress/log/kip018.txt + +ps -p1 | grep -q launchd || exit 0 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > machipc2.c +# Test fails without the -lpthread. Need to investigate why. +cc -o machipc2 -Wall -Wextra -O2 -g machipc2.c -lmach -lpthread || exit 1 +rm machipc2.c +cd $odir + +(cd ../testcases/swap; ./swap -t 5m -i 20 -h -v) & +sleep 5 +/tmp/machipc2 +pkill swap +rm -f /tmp/machipc2 +exit 0 +EOF +/* + Inspired by: Michael Weber: http://www.foldr.org/~michaelw/log/2009/03/13/ + */ + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#define MACH_MSG_TYPE_INTEGER_32 2 +#define N 200000000 + +typedef struct { + unsigned int msgt_name : 8, + msgt_size : 8, + msgt_number : 12, + msgt_inline : 1, + msgt_longform : 1, + msgt_deallocate : 1, + msgt_unused : 1; +} mach_msg_type_t; + +struct integer_message { + mach_msg_header_t head; + mach_msg_type_t type; + + int inline_integer; +}; + +struct message_recv +{ + mach_msg_header_t head; + mach_msg_type_t type; + int inline_integer; + mach_msg_trailer_t trailer; +}; + +static task_t child_task = MACH_PORT_NULL; + +mach_port_t bootstrap_port; + +#define CHECK_MACH_ERROR(err, s) \ + do { \ + if (err != KERN_SUCCESS) { \ + fprintf(stderr, "%s: %s", s, mach_error_string(err)); \ + exit(1); \ + } \ + } while (0) + +static int +setup_recv_port (mach_port_t *recv_port) +{ + kern_return_t kerr; + mach_port_t port = MACH_PORT_NULL; + kerr = mach_port_allocate (mach_task_self (), + MACH_PORT_RIGHT_RECEIVE, &port); + CHECK_MACH_ERROR (kerr, "mach_port_allocate failed:"); + + kerr = mach_port_insert_right (mach_task_self (), + port, port, MACH_MSG_TYPE_MAKE_SEND); + CHECK_MACH_ERROR (kerr, "mach_port_insert_right failed:"); + + *recv_port = port; + + return (0); +} + +static int +send_port (mach_port_t remote_port, mach_port_t port) +{ + kern_return_t kerr; + + struct { + mach_msg_header_t header; + mach_msg_body_t body; + mach_msg_port_descriptor_t task_port; + } msg; + + msg.header.msgh_remote_port = remote_port; + msg.header.msgh_local_port = MACH_PORT_NULL; + msg.header.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, 0) | + MACH_MSGH_BITS_COMPLEX; + msg.header.msgh_size = sizeof msg; + + msg.body.msgh_descriptor_count = 1; + msg.task_port.name = port; + msg.task_port.disposition = MACH_MSG_TYPE_COPY_SEND; + msg.task_port.type = MACH_MSG_PORT_DESCRIPTOR; + + kerr = mach_msg_send (&msg.header); + CHECK_MACH_ERROR(kerr, "mach_msg_send failed:"); + + return (0); +} + +static int +recv_port(mach_port_t recv_port, mach_port_t *port) +{ + kern_return_t kerr; + struct { + mach_msg_header_t header; + mach_msg_body_t body; + mach_msg_port_descriptor_t task_port; + mach_msg_trailer_t trailer; + } msg; + + kerr = mach_msg(&msg.header, MACH_RCV_MSG, + 0, sizeof msg, recv_port, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + CHECK_MACH_ERROR(kerr, "mach_msg failed:"); + + *port = msg.task_port.name; + return (0); +} + +void +writeint(mach_port_t port) +{ + struct integer_message message; + int kerr, i; + + /* Fill the header fields : */ + message.head.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND); + message.head.msgh_size = sizeof( struct integer_message ); + message.head.msgh_local_port = MACH_PORT_NULL; + message.head.msgh_remote_port = port; + message.head.msgh_id = 0; /* Message id */ + message.head.msgh_size = sizeof(message); /* Message size */ + + /* Set the message type */ + message.type.msgt_name = MACH_MSG_TYPE_INTEGER_32; + message.type.msgt_size = sizeof(message); + message.type.msgt_number = 1; + message.type.msgt_inline = TRUE; + message.type.msgt_longform = FALSE; + message.type.msgt_deallocate = FALSE; + + for (i = 0; i < N; i++) { + message.inline_integer = i; + + /* Send the message */ + kerr = mach_msg(&message.head, /* The header */ + MACH_SEND_MSG, /* Flags */ + sizeof(message), /* Send size */ + 0, /* Max receive Size */ + port, /* Send port */ + MACH_MSG_TIMEOUT_NONE, /* No timeout */ + MACH_PORT_NULL); /* No notification */ + if (kerr) + errx(1, "client mach_msg: %s", mach_error_string(kerr)); + } +} + +void +readint(mach_port_t port) +{ + struct message_recv rmessage = {}; + int kerr, i; + + rmessage.head.msgh_local_port = port; + rmessage.head.msgh_size = sizeof(rmessage); + + for (i = 0; i < N; i++) { + /* Receive a message */ + kerr = mach_msg(&rmessage.head, /* The header */ + MACH_RCV_MSG, /* Flags */ + 0, /* Send size */ + sizeof(rmessage), /* Max receive size */ + port, /* Receive port */ + MACH_MSG_TIMEOUT_NONE, /* No timeout */ + MACH_PORT_NULL); /* No notification */ + if (kerr) + errx(1, "client mach_msg MACH_RCV_MSG: %s", mach_error_string(kerr)); + if (rmessage.inline_integer != i) + errx(1, "FAIL message.inline_integer = %d, i = %d", + rmessage.inline_integer, i); + } +} + +void +sampling_fork(void) +{ + pid_t pid; + kern_return_t kerr; + mach_port_t parent_recv_port = MACH_PORT_NULL; + mach_port_t child_recv_port = MACH_PORT_NULL; + + if (setup_recv_port(&parent_recv_port) != 0) + return; + kerr = task_set_bootstrap_port(mach_task_self(), parent_recv_port); + CHECK_MACH_ERROR(kerr, "task_set_bootstrap_port failed:"); + + if ((pid = fork()) == -1) + err(1, "fork"); + + if (pid == 0) { + kerr = task_get_bootstrap_port(mach_task_self(), &parent_recv_port); + CHECK_MACH_ERROR(kerr, "task_get_bootstrap_port failed:"); + if (setup_recv_port(&child_recv_port) != 0) + return; + if (send_port(parent_recv_port, mach_task_self()) != 0) + return; + if (send_port(parent_recv_port, child_recv_port) != 0) + return; + if (recv_port(child_recv_port, &bootstrap_port) != 0) + return; + kerr = task_set_bootstrap_port(mach_task_self(), bootstrap_port); + CHECK_MACH_ERROR(kerr, "task_set_bootstrap_port failed:"); + + readint(child_recv_port); + + _exit(0); + } + + /* parent */ + kerr = task_set_bootstrap_port(mach_task_self(), bootstrap_port); + CHECK_MACH_ERROR(kerr, "task_set_bootstrap_port failed:"); + if (recv_port(parent_recv_port, &child_task) != 0) + return; + if (recv_port(parent_recv_port, &child_recv_port) != 0) + return; + if (send_port(child_recv_port, bootstrap_port) != 0) + return; + kerr = mach_port_deallocate(mach_task_self(), parent_recv_port); + CHECK_MACH_ERROR(kerr, "mach_port_deallocate failed:"); + + writeint(child_recv_port); +} + +int +main(void) +{ + sampling_fork(); + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/marcus.sh b/tools/test/stress2/misc/marcus.sh new file mode 100755 index 000000000000..727b1ad56c17 --- /dev/null +++ b/tools/test/stress2/misc/marcus.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Run with marcus.cfg on a 1g swap backed MD with UFS SU fs. + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' + +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +checkfs /dev/md${mdstart}$part; s=$? +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/marcus2.sh b/tools/test/stress2/misc/marcus2.sh new file mode 100755 index 000000000000..1e58c52ddfde --- /dev/null +++ b/tools/test/stress2/misc/marcus2.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Run with marcus.cfg on a 2g swap backed MD with UFS SU fs. +# Copy of marcus.sh, but with maximum load. + +# "panic: vm_radix_remove: invalid key found" seen. +# watchdog fired: https://people.freebsd.org/~pho/stress/log/marcus2.txt + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +n=`find ../testcases -perm -1 -type f | wc -l` +m=`su $testuser -c "limits | awk '/maxprocesses/ {print \\$NF}'"` +export INCARNATIONS=$((m / n)) +export swapINCARNATIONS=$INCARNATIONS + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' & + +sleep 10 +start=`date '+%s'` +while pgrep -q run; do + [ $((`date '+%s'` - start)) -gt 1500 ] && + ../tools/killall.sh + sleep 10 +done +wait + +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +checkfs /dev/md${mdstart}$part; s=$? +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/marcus3.sh b/tools/test/stress2/misc/marcus3.sh new file mode 100755 index 000000000000..f870ebe89115 --- /dev/null +++ b/tools/test/stress2/misc/marcus3.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Watchdog fired: +# https://people.freebsd.org/~pho/stress/log/kostik853.txt +# but runs for a long time without watchdogd and deadlkres. + +. ../default.cfg + +dev=$(df -h `dirname $RUNDIR` | tail -1 | awk '{print $1}') +mount | grep $dev | grep -q journaled && exit 0 +size=$((`sysctl -n hw.physmem` / 1024 / 1024)) +[ $size -gt $((4 * 1024)) ] && + echo "RAM should be capped to 4GB for this test." +[ "`sysctl -n debug.deadlkres.sleepfreq 2>/dev/null`" = "3" ] && + { echo "deadlkres must be disabled for this test."; exit 0; } + +n=`find ../testcases -perm -1 -type f | wc -l` +m=`su $testuser -c "limits | grep maxprocesses | awk '{print \\$NF}'"` +export runRUNTIME=15m +export INCARNATIONS=$((m / n)) +export swapINCARNATIONS=$INCARNATIONS + +timeout 16m su $testuser -c 'cd ..; ./run.sh marcus.cfg' +exit 0 diff --git a/tools/test/stress2/misc/marcus4.sh b/tools/test/stress2/misc/marcus4.sh new file mode 100755 index 000000000000..60f0e4c87605 --- /dev/null +++ b/tools/test/stress2/misc/marcus4.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Copy of marcus3.sh, but without the VM (page stealer) pressure. +# Deadlock and "panic: smp_targeted_tlb_shootdown: interrupts disabled" +# https://people.freebsd.org/~pho/stress/log/marcus4.txt + +# "panic: spin lock held too long" seen. +# Fixed in r313472. + +. ../default.cfg + +pgrep -q watchdogd && { service watchdogd stop > /dev/null && restart=1; } +dev=$(df -h `dirname $RUNDIR` | tail -1 | awk '{print $1}') +mount | grep $dev | grep -q journaled && exit 0 +size=$((`sysctl -n hw.physmem` / 1024 / 1024)) +[ $size -gt $((4 * 1024)) ] && + { echo "RAM should be capped to 4GB for this test."; } +[ "`sysctl -n debug.deadlkres.sleepfreq 2>/dev/null`" = "3" ] && + { echo "deadlkres must be disabled for this test."; exit 0; } + +n=`find ../testcases -perm -1 -type f | wc -l` +m=`su $testuser -c "limits | grep maxprocesses | awk '{print \\$NF}'"` +m=$((m / 2)) + +export INCARNATIONS=$((m / n)) +export runRUNTIME=15m +export LOAD=80 +export symlinkLOAD=80 +export rwLOAD=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/mkfifo/mkfifo +" + +start=`date +%s` +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' & + +sleep $((16 * 60)) +../tools/killall.sh; s=$? +wait +./cleanup.sh +elapsed=$((`date +%s` - start)) +if [ $elapsed -gt $((30 * 60)) ]; then + echo "Runtime is $elapsed seconds" + s=100 +fi + +[ $restart ] && service watchdogd start > /dev/null +exit $s diff --git a/tools/test/stress2/misc/marcus5.sh b/tools/test/stress2/misc/marcus5.sh new file mode 100755 index 000000000000..97c2465ba49c --- /dev/null +++ b/tools/test/stress2/misc/marcus5.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 + +# Copy of marcus4.sh, but with a md(4) disk. +# "panic: userret: Returning with SU cleanup request not handled" seen: +# https://people.freebsd.org/~pho/stress/log/marcus5.txt +# Fixed by r292541. + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 5g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +size=$((`sysctl -n hw.physmem` / 1024 / 1024)) +[ $size -gt $((4 * 1024)) ] && + echo "RAM should be capped to 4GB for this test." +[ "`sysctl -n debug.deadlkres.sleepfreq 2>/dev/null`" = "3" ] && + { echo "deadlkres must be disabled for this test."; exit 0; } + +n=`find ../testcases -perm -1 -type f | wc -l` +m=`su $testuser -c "limits | awk '/maxprocesses/ {print \\$NF}'"` + +export RUNDIR=$mntpoint/stressX +export INCARNATIONS=$((m / n)) +export runRUNTIME=15m +export LOAD=80 +export symlinkLOAD=80 +export rwLOAD=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/mkfifo/mkfifo +" + +timeout 20m su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +checkfs /dev/md${mdstart}$part; s=$! +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/marcus6.sh b/tools/test/stress2/misc/marcus6.sh new file mode 100755 index 000000000000..076a51e1e4a4 --- /dev/null +++ b/tools/test/stress2/misc/marcus6.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 + +# Variation of marcus5.sh +# "panic: Assertion pgrp->pg_jobc > 0 failed at kern_proc.c:740" seen. + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 5g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +size=$((`sysctl -n hw.physmem` / 1024 / 1024)) +[ "`sysctl -n debug.deadlkres.sleepfreq 2>/dev/null`" = "3" ] && + { echo "deadlkres must be disabled for this test."; exit 0; } + +m=`su $testuser -c "limits | awk '/maxprocesses/ {print \\$NF}'"` +[ $m -gt 100000 ] && m=100000 + +rm -rf /tmp/stressX.control +export RUNDIR=$mntpoint/stressX +export INCARNATIONS=$((m / 11)) +export runRUNTIME=3m +export LOAD=80 +export symlinkLOAD=80 +export rwLOAD=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/mkfifo/mkfifo +" + +timeout -s SIGINT -k 2m 1m su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 60 ] && { echo "Timed out"; exit 1; } +done +checkfs /dev/md${mdstart}$part; s=$! +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/marcus7.sh b/tools/test/stress2/misc/marcus7.sh new file mode 100755 index 000000000000..94800c5c5f60 --- /dev/null +++ b/tools/test/stress2/misc/marcus7.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# Variation of marcus5.sh with more rename tests. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 + +# Copy of marcus4.sh, but with a md(4) disk. +# "panic: userret: Returning with SU cleanup request not handled" seen: +# https://people.freebsd.org/~pho/stress/log/marcus5.txt +# Fixed by r292541. + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 5g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +size=$((`sysctl -n hw.physmem` / 1024 / 1024)) +[ $size -gt $((4 * 1024)) ] && + echo "RAM should be capped to 4GB for this test." +[ "`sysctl -n debug.deadlkres.sleepfreq 2>/dev/null`" = "3" ] && + { echo "deadlkres must be disabled for this test."; exit 0; } + +n=`find ../testcases -perm -1 -type f | wc -l` +m=`su $testuser -c "limits | awk '/maxprocesses/ {print \\$NF}'"` + +export RUNDIR=$mntpoint/stressX +export INCARNATIONS=$((m / n)) +export runRUNTIME=10m +export LOAD=80 +export symlinkLOAD=80 +export rwLOAD=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/mkfifo/mkfifo +testcases/dirnprename/dirnprename +testcases/dirrename/dirrename +" + +timeout 12m su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +checkfs /dev/md${mdstart}$part; s=$! +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/maxmemdom.sh b/tools/test/stress2/misc/maxmemdom.sh new file mode 100755 index 000000000000..661de87410f2 --- /dev/null +++ b/tools/test/stress2/misc/maxmemdom.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Demonstrate that "options MAXMEMDOM" is broken. (NUMA test) +# panic: vm_page_alloc: missing page +# https://people.freebsd.org/~pho/stress/log/maxmemdom.txt +# Fixed in r293640. + +. ../default.cfg + +[ `sysctl -n vm.ndomains` -eq 1 ] && exit 0 +size=$((`sysctl -n hw.physmem` / 1024 / 1024)) +need=$((size * 2)) +d1=$diskimage.1 +d2=$diskimage.2 +rm -f $d1 $d2 +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print int($4 / 1024)}'` -lt \ + $need ] && printf "Need %d MB on %s.\n" $need `dirname $diskimage` && exit +timeout 30m sh -ce " + dd if=/dev/zero of=$d1 bs=1m count=$size status=none + cp $d1 $d2 +" +s=$? +[ $s -eq 124 ] && echo "Timed out" + +rm -f $d1 $d2 +exit $s diff --git a/tools/test/stress2/misc/maxproc.sh b/tools/test/stress2/misc/maxproc.sh new file mode 100755 index 000000000000..c425c307e06b --- /dev/null +++ b/tools/test/stress2/misc/maxproc.sh @@ -0,0 +1,167 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test that a non root user can at most have maxproc - 10 processes. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > maxproc.c +mycc -o maxproc -Wall -Wextra maxproc.c -lkvm || exit 1 +rm -f maxproc.c +[ `sysctl -n kern.maxproc` -gt 37028 ] && exit 0 # Excessive run time +cd $here + +/tmp/maxproc + +rm -f /tmp/maxproc +exit +EOF +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + NL_NPROCS, + NL_MAXPROC, + NL_MARKER +}; + +static struct { + int order; + const char *name; +} namelist[] = { + { NL_NPROCS, "_nprocs" }, + { NL_MAXPROC, "_maxproc" }, + { NL_MARKER, "" }, +}; + +#define NNAMES (sizeof(namelist) / sizeof(*namelist)) +#define MULTIUSERFUZZ 5 + +static struct nlist nl[NNAMES]; + +static void +t2(void) +{ + pid_t p; + + for (;;) { + if ((p = fork()) == 0) { + sleep(2); + _exit(0); + } + if (p == -1) + break; + } +} + +static void +t1(int priv) +{ + pid_t p; + struct passwd *pw; + + if ((p = fork()) == 0) { + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + + if (priv == 0) { + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + } + endpwent(); + + t2(); + _exit(0); + } + waitpid(p, NULL, 0); +} + +int +getprocs(void) +{ + kvm_t *kd; + int i, nprocs, maxproc; + char buf[_POSIX2_LINE_MAX]; + char *nlistf, *memf; + + nlistf = memf = NULL; + for (i = 0; i < (int)NNAMES; i++) + nl[namelist[i].order].n_name = strdup(namelist[i].name); + + if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) + errx(1, "kvm_openfile(%s, %s): %s", nlistf, memf, buf); + if (kvm_nlist(kd, nl) == -1) + errx(1, "kvm_nlist: %s", kvm_geterr(kd)); + if (kvm_read(kd, nl[NL_NPROCS].n_value, &nprocs, + sizeof(nprocs)) != sizeof(nprocs)) + errx(1, "kvm_read(): %s", kvm_geterr(kd)); + if (kvm_read(kd, nl[NL_MAXPROC].n_value, &maxproc, + sizeof(maxproc)) != sizeof(maxproc)) + errx(1, "kvm_read(): %s", kvm_geterr(kd)); + kvm_close(kd); + + return (maxproc - nprocs - 1); +} + +int +main(void) +{ + int i, n; + + alarm(1200); + n = getprocs(); + for (i = 0; i < n / 10 * 8; i++) { + if (fork() == 0) { + sleep(2); + _exit(0); + } + } + + t1(0); + + n = getprocs(); + if (n < 10 - MULTIUSERFUZZ) + errx(1, "FAIL: nprocs = %d\n", n); + + return (0); +} diff --git a/tools/test/stress2/misc/maxvnodes.sh b/tools/test/stress2/misc/maxvnodes.sh new file mode 100755 index 000000000000..b962310cbb0e --- /dev/null +++ b/tools/test/stress2/misc/maxvnodes.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test dynamic kern.maxvnodes implementation. + +# "panic: vm_fault_hold: fault on nofault entry, addr: 0xfffffe00b1b3c000" +# seen: https://people.freebsd.org/~pho/stress/log/kostik1175.txt + +. ../default.cfg + +kldstat | grep -q tmpfs.ko || notloaded=1 +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mount -o size=2g -t tmpfs tmpfs $mntpoint || exit 1 +chmod 777 $mntpoint + +oldmx=`sysctl -n kern.maxvnodes` +trap "sysctl kern.maxvnodes=$oldmx > /dev/null" EXIT SIGINT + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX +export TESTPROGS=" +testcases/creat/creat +testcases/mkdir/mkdir +testcases/swap/swap +" +export creatINCARNATIONS=50 +export creatLOAD=100 + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > /dev/null 2>&1 & + +min=1000 +max=$((oldmx * 4)) +while kill -0 $! 2>/dev/null; do + sysctl kern.maxvnodes=`jot -r 1 $min $max` > /dev/null + sleep `jot -r 1 1 3` +done +wait + +while mount | grep $mntpoint | grep -q tmpfs; do + umount $mntpoint || sleep 1 +done +[ $notloaded ] && kldunload tmpfs.ko +exit 0 diff --git a/tools/test/stress2/misc/maxvnodes2.sh b/tools/test/stress2/misc/maxvnodes2.sh new file mode 100755 index 000000000000..798eff1bffd6 --- /dev/null +++ b/tools/test/stress2/misc/maxvnodes2.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC Isilon +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "panic: Bad link elm 0xfffff8015ea20000 prev->next != elm" seen: +# https://people.freebsd.org/~pho/stress/log/mjguzik005.txt +# Fixed by r309067. + +oldmx=`sysctl -n kern.maxvnodes` +trap "sysctl kern.maxvnodes=$oldmx > /dev/null" EXIT SIGINT + +sysctl kern.maxvnodes=2000 + +timeout 10m ../misc/msdos6.sh + +exit diff --git a/tools/test/stress2/misc/md.sh b/tools/test/stress2/misc/md.sh new file mode 100755 index 000000000000..47e491e2b841 --- /dev/null +++ b/tools/test/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. +# + +# 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 +[ -c /dev/md$mdstart ] && 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 20`; do + (cd ../testcases/rw;./rw -t 2m -i 20 > /dev/null 2>&1) +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 +exit 0 diff --git a/tools/test/stress2/misc/md2.sh b/tools/test/stress2/misc/md2.sh new file mode 100755 index 000000000000..939d7e46db39 --- /dev/null +++ b/tools/test/stress2/misc/md2.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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. +# + +# panic: ufs_dirbad: /mnt: bad dir ino 32899 at offset 16896: mangled entry + +# "panic: ffs_read: type 0" seen: +# https://people.freebsd.org/~pho/stress/log/kostik969.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep "on $mntpoint " | grep -q md$mdstart && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t malloc -s 256m -u $mdstart + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m +for i in 1 2; do + echo "newfs -O$i -i1024 /dev/md$mdstart" + newfs -O$i -i1024 /dev/md$mdstart > /dev/null 2>&1 + mount /dev/md$mdstart $mntpoint + + (cd ..; ./run.sh) + + while mount | grep -q "on $mntpoint "; do + umount $mntpoint + done +done +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/md3.sh b/tools/test/stress2/misc/md3.sh new file mode 100755 index 000000000000..626d578e54ae --- /dev/null +++ b/tools/test/stress2/misc/md3.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# +# Copyright (c) 2009-2011 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 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +# Stop FS "out of inodes" problem by only using 70% +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 / 10 * 7)) +export INODES=$(($2 / 10 * 7)) + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m + +(cd ..; ./run.sh marcus.cfg) + +umount $mntpoint +mount | grep -q "$mntpoint" && umount -f $mntpoint +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/md4.sh b/tools/test/stress2/misc/md4.sh new file mode 100755 index 000000000000..484e531e3f6c --- /dev/null +++ b/tools/test/stress2/misc/md4.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# Demonstrate data corruption on the swap-backed md. +# Test scenario by Nigel Williams . +# Fixed in r250966. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +status=0 +MD_DEV=`mdconfig -an -t swap -s 1m -x 63 -y 16` +fdisk -I md$MD_DEV > /dev/null 2>&1 +bsdlabel -w -B md${MD_DEV}s1 || exit 1 +dd if=/dev/md$MD_DEV of=/dev/null bs=64k status=none +bsdlabel md${MD_DEV}s1 > /dev/null || + { echo FAIL; status=1; } +mdconfig -d -u $MD_DEV +exit $status diff --git a/tools/test/stress2/misc/md5.sh b/tools/test/stress2/misc/md5.sh new file mode 100755 index 000000000000..a6655db395b5 --- /dev/null +++ b/tools/test/stress2/misc/md5.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# "dd: /dev/md5: Input/output error" seen. +# kib@: kern_physio() detects EOF due to incorrect calculation +# of bio bio_resid after the bio_length was clipped by the 'excess' code +# in g_io_check() +# Test scenario by Stefan Hegnauer +# Fixed in r259200 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +log=/tmp/md5.log +dd if=/dev/zero of=$diskimage bs=1k count=5k status=none +mdconfig -f $diskimage -u md$mdstart || exit 1 +newfs $newfs_flags /dev/md$mdstart > /dev/null +dd if=/dev/md$mdstart of=/dev/null > $log 2>&1 && s=0 || s=1 +[ $s -eq 1 ] && cat $log +mdconfig -d -u $mdstart +rm -f $diskimage $log +exit $s diff --git a/tools/test/stress2/misc/md6.sh b/tools/test/stress2/misc/md6.sh new file mode 100755 index 000000000000..f24f0d921e8b --- /dev/null +++ b/tools/test/stress2/misc/md6.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Regression test for mmap problem introduced by r271635 +# where mdconfig -l fails due to +# mmap(0,0x1000,PROT_READ,MAP_FILE,0x4,0) +# returning 0. +# Fixed by r271721. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 10m -u $mdstart || exit 1 +[ -c /dev/md$mdstart ] || echo "FAIL" +mdconfig -l -v > /dev/null || echo "FAIL of mdconfig -l" +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/md7.sh b/tools/test/stress2/misc/md7.sh new file mode 100755 index 000000000000..f15377607a97 --- /dev/null +++ b/tools/test/stress2/misc/md7.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Deadlock seen: The softdep code requesting workqueue cleanups while +# owning vnode locks: +# https://people.freebsd.org/~pho/stress/log/kostik812.txt +# Fixed by: r283600 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 # Covered by md3.sh + +swapoff -a +./md3.sh +swapon -a diff --git a/tools/test/stress2/misc/md8.sh b/tools/test/stress2/misc/md8.sh new file mode 100755 index 000000000000..e073271dac15 --- /dev/null +++ b/tools/test/stress2/misc/md8.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 of unmapped unaligned i/o over the vnode-backed md(4) volume. +# "panic: vm_fault: fault on nofault entry, addr: fffffe07f302c000" seen. +# https://people.freebsd.org/~pho/stress/log/md8.txt +# Fixed in r292128. + +# Test scenario by kib@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -d /usr/src/sys ] || exit 0 + +. ../default.cfg + +rm -f $diskimage +dir=`dirname $diskimage` +free=`df -k $dir | tail -1 | awk '{print $4}'` +[ $((free / 1024)) -lt 50 ] && echo "Not enough disk space." && exit + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > md8.c +rm -f /tmp/md8 +mycc -o md8 -Wall -Wextra -g -O2 md8.c || exit 1 +rm -f md8.c + +cd $odir +trap "rm -f $diskimage" EXIT INT +dd if=/dev/zero of=$diskimage bs=1m count=50 status=none +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t vnode -f $diskimage -u $mdstart + +n=`sysctl -n hw.ncpu` +n=$((n + 1)) +(cd /usr/src; make -j $n buildkernel > /dev/null 2>&1) & +sleep 1 +/tmp/md8 /dev/md$mdstart +kill $! +wait + +mdconfig -d -u $mdstart +rm -rf /tmp/md8 +exit 0 +EOF +#include + +#include +#include +#include +#include +#include + +#define LOOPS 2000 + +void +test(char *path) +{ + int fd; + char data[MAXPHYS + 512] __aligned(PAGE_SIZE); + + if ((fd = open(path, O_RDONLY)) == -1) + err(1, "open(%s)", path); + if (read(fd, data + 512, MAXPHYS) != MAXPHYS) + err(1, "read"); + close(fd); + + if ((fd = open(path, O_WRONLY)) == -1) + err(1, "open(%s)", path); + if (write(fd, data + 512, MAXPHYS) != MAXPHYS) + err(1, "write"); + close(fd); + + if ((fd = open(path, O_RDONLY)) == -1) + err(1, "open(%s)", path); + if (read(fd, data + 512, MAXPHYS) != MAXPHYS) + err(1, "read"); + close(fd); +} + +int +main(int argc, char *argv[]) +{ + int i; + char *path; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + + path = argv[1]; + + for (i = 0; i < LOOPS; i++) + test(path); + + return (0); +} diff --git a/tools/test/stress2/misc/md9.sh b/tools/test/stress2/misc/md9.sh new file mode 100755 index 000000000000..a232ade6963f --- /dev/null +++ b/tools/test/stress2/misc/md9.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# memory disk with vnode on a tmpfs file system triggers: +# "g_handleattr(GEOM::ident): md10 bio_length 24 len 31 -> EFAULT" + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +set -e +mp2=${mntpoint}2 +mkdir -p $mp2 +mount | grep "on $mp2 " | grep -q /dev/md && umount -f $mp2 +mount -t tmpfs tmpfs $mp2 + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +diskimage=$mp2/diskimage +dd if=/dev/zero of=$diskimage bs=1m count=2k status=none +mdconfig -a -t vnode -f $diskimage -u $mdstart +bsdlabel -w md$mdstart auto +newfs -U /dev/md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +for i in `jot 10`; do + umount $mntpoint && break + sleep .5 +done +mount | grep "on $mntpoint " && { echo FATAL; exit 1; } +mdconfig -d -u $mdstart +umount $mp2 +tail -5 /var/log/messages | grep g_handleattr && s=1 || s=0 + +exit $s diff --git a/tools/test/stress2/misc/mdconfig.sh b/tools/test/stress2/misc/mdconfig.sh new file mode 100755 index 000000000000..ecfe188a102d --- /dev/null +++ b/tools/test/stress2/misc/mdconfig.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC Isilon +# 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. +# + +. ../default.cfg + +# Regression test for: +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=214721 +# https://people.freebsd.org/~pho/stress/log/mdconfig.txt +# Fixed by: r311964. + +mdconfig -at swap -S 65536 -s 20M -u $mdstart +mdconfig -d -u $mdstart + +exit 0 diff --git a/tools/test/stress2/misc/mdconfig2.sh b/tools/test/stress2/misc/mdconfig2.sh new file mode 100755 index 000000000000..13c13dc55111 --- /dev/null +++ b/tools/test/stress2/misc/mdconfig2.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# /dev/md* fails to be created. +# "kernel: g_dev_taste: make_dev_p() failed (gp->name=md10, error=17)" seen. +# The cause is that the device node is removed asynchronously. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -l | grep -q md$mdstart && + { echo FAIL; ls -l /dev/md$mdstart; mdconfig -lv; exit 1; } + +s=0 +start=`date +%s` +workaround=${workaround:-0} +while [ $((`date +%s` - start)) -lt 60 ]; do + mdconfig -a -t swap -s 100m -u $mdstart || { s=2; break; } + [ -c /dev/md$mdstart ] || + { echo FAIL; ls -l /dev/md$mdstart; mdconfig -lv; exit 3; } + mdconfig -d -u $mdstart || { s=4; break; } + while [ $workaround -eq 1 -a -c /dev/md$mdstart ]; do + echo "Note: Waiting for removal of /dev/md$mdstart" + sleep .1 + done +done +exit $s diff --git a/tools/test/stress2/misc/mdconfig3.sh b/tools/test/stress2/misc/mdconfig3.sh new file mode 100755 index 000000000000..7fbdcbc1a5ff --- /dev/null +++ b/tools/test/stress2/misc/mdconfig3.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# mdconfig(x) option force test. +# Fixed by r345758 + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +rm -df $diskimage +dd if=/dev/zero of=$diskimage bs=1m count=5 status=none +mdconfig -a -t vnode -f $diskimage -u $mdstart +dd if=/dev/random of=/dev/md$mdstart bs=1m count=5 status=none +md1=`md5 < /dev/md$mdstart` +mdconfig -d -u $mdstart -o force + +md2=`md5 < $diskimage` +rm -d $diskimage + +[ "$md1" != "$md2" ] && exit 1 || exit 0 diff --git a/tools/test/stress2/misc/memguard.sh b/tools/test/stress2/misc/memguard.sh new file mode 100755 index 000000000000..9b2a3a964d1b --- /dev/null +++ b/tools/test/stress2/misc/memguard.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# MEMGUARD(9) test scenario: Page fault seen in softdep_setup_inomapdep(). + +. ../default.cfg + +sysctl vm | grep -q memguard || { echo "MEMGUARD(9) not enabled"; exit 0; } + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 20m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 * 2)) +export INODES=$(($2 * 2)) + +sysctl vm.memguard.options=3 > /dev/null +sysctl vm.memguard.desc=inodedep + +su $testuser -c 'cd ..; ./run.sh disk.cfg' > /dev/null + +sysctl vm.memguard.desc="" > /dev/null +sysctl vm.memguard.options=1 > /dev/null + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/memguard2.sh b/tools/test/stress2/misc/memguard2.sh new file mode 100755 index 000000000000..4c4619ef89e3 --- /dev/null +++ b/tools/test/stress2/misc/memguard2.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# MEMGUARD(9) test scenario +# http://people.freebsd.org/~pho/stress/log/memguard4.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +sysctl vm | grep -q memguard || { echo "MEMGUARD(9) not enabled"; exit 1; } + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=30s +export RUNDIR=$mntpoint/stressX +[ -d $RUNDIR ] || mkdir $RUNDIR +chmod 777 $RUNDIR + +sysctl vm.memguard.options=3 > /dev/null +{ vmstat -m; echo dummy; } | sed '1d;s/ [0-9].*//;s/^ *//' | \ + sed 's/ *$//' | tr '\n' ' ' | ../tools/shuffle | \ + tr ' ' '\n' | head -10 | while read type; do + sysctl vm.memguard.desc="$type" + su $testuser -c 'cd ..; ./run.sh disk.cfg' > /dev/null + find /tmp/stressX.control/* $mntpoint/stressX/* -delete 2>/dev/null +done +sysctl vm.memguard.desc="" > /dev/null +sysctl vm.memguard.options=1 > /dev/null + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/memguard3.sh b/tools/test/stress2/misc/memguard3.sh new file mode 100755 index 000000000000..8a7705c71537 --- /dev/null +++ b/tools/test/stress2/misc/memguard3.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# MEMGUARD(9) test scenario using "frequency". +# "panic: __rw_wlock_hard: recursing but non-recursive rw kmem vm object" +# seen. http://people.freebsd.org/~pho/stress/log/memguard5.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +sysctl vm | grep -q memguard || { echo "MEMGUARD(9) not enabled"; exit 1; } + +sysctl vm.memguard.options=3 +sysctl vm.memguard.frequency=1000 + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 5g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +checkfs /dev/md${mdstart}$part; s=$? +mdconfig -d -u $mdstart + +sysctl vm.memguard.frequency=0 > /dev/null +sysctl vm.memguard.options=1 > /dev/null +exit $s diff --git a/tools/test/stress2/misc/memguard4.sh b/tools/test/stress2/misc/memguard4.sh new file mode 100755 index 000000000000..323183caf96d --- /dev/null +++ b/tools/test/stress2/misc/memguard4.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test without using memguard.options + +. ../default.cfg + +sysctl vm | grep -q memguard || { echo "MEMGUARD(9) not enabled"; exit 0; } + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX + +sysctl vm.memguard.desc=inodedep + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 + +sysctl vm.memguard.desc="" > /dev/null + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/midi.sh b/tools/test/stress2/misc/midi.sh new file mode 100755 index 000000000000..47594734b4e0 --- /dev/null +++ b/tools/test/stress2/misc/midi.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Mark Johnston +# +# 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. +# + +# 'panic: vm_fault_hold: fault on nofault entry, addr: 0x33522000' seen. +# Fixed by 351262 + +cat > /tmp/midi.c < +#include +#include +#include +#include +#include + +#define NTHREADS 16 + +static _Atomic(int) threads; +static int fd; + +static void * +t(void *data __unused) +{ + char buf[4096]; + ssize_t n; + off_t off; + + (void)atomic_fetch_add(&threads, 1); + while (atomic_load(&threads) != NTHREADS) + ; + + for (;;) { + arc4random_buf(&off, sizeof(off)); + if ((n = pread(fd, buf, sizeof(buf), off)) >= 0) + write(STDOUT_FILENO, buf, n); + } + + return (NULL); +} + +int +main(void) +{ + pthread_t tid[NTHREADS]; + int error, i; + + fd = open("/dev/midistat", O_RDONLY); + if (fd < 0) + err(1, "open"); + + for (i = 0; i < NTHREADS; i++) + if ((error = pthread_create(&tid[i], NULL, t, NULL)) != 0) + errc(1, error, "pthread_create"); + for (i = 0; i < NTHREADS; i++) + if ((error = pthread_join(tid[i], NULL)) != 0) + errc(1, error, "pthread_join"); + + return (0); +} +EOF +cc -o /tmp/midi -Wall -Wextra -O2 /tmp/midi.c -lpthread + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 120 ]; do + timeout 10 /tmp/midi | strings | head -20 +done + +rm -f /tmp/midi /tmp/midi.c /tmp/midi.core +exit 0 diff --git a/tools/test/stress2/misc/midi2.sh b/tools/test/stress2/misc/midi2.sh new file mode 100755 index 000000000000..91f15aa3cc3b --- /dev/null +++ b/tools/test/stress2/misc/midi2.sh @@ -0,0 +1,114 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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 threaded access to /dev/midistat. + +# "panic: vm_fault_hold: fault on nofault entry, addr: 0x8b352000" seen. +# https://people.freebsd.org/~pho/stress/log/mark089.txt +# Fixed by 351262 + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/midi2.c +mycc -o midi2 -Wall -Wextra -O0 -g midi2.c -lpthread || exit 1 + +$dir/midi2 +s=$? +cat /dev/midistat > /dev/null || s=1 + +rm -rf midi2 midi2.c midi2.core +exit $s + +EOF +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int share; +static int fd; +static char buf[0xbc59], buf2[0x40eddf]; + +#define THREADS 4 +#define RUNTIME (1 * 60) +#define SYNC 0 + +static void * +t1(void *data __unused) +{ + + atomic_add_int(&share, 1); + while (share != THREADS) + ; + + pread(fd, buf, 0xbc59, 0x27dbb298LL); + pread(fd, buf, 0xbc59, 0x104e35c6d22eLL); + pread(fd, buf2, 0x40eddf, 0x405d1df88cbf41LL); + + return (NULL); +} + +int +main(void) +{ + pthread_t tid[THREADS]; + time_t start; + int i, rc; + + if ((fd = open("/dev/midistat", O_RDONLY)) == -1) + err(1, "open(/dev/midistat)"); + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + share = 0; + for (i = 0; i < THREADS; i++) { + if ((rc = pthread_create(&tid[i], NULL, t1, NULL)) != + 0) + errc(1, rc, "pthread_create"); + } + + for (i = 0; i < THREADS; i++) { + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join"); + } + } + + return (0); +} diff --git a/tools/test/stress2/misc/mincore.sh b/tools/test/stress2/misc/mincore.sh new file mode 100755 index 000000000000..85c09cc0ceaf --- /dev/null +++ b/tools/test/stress2/misc/mincore.sh @@ -0,0 +1,157 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# Hunt for https://people.freebsd.org/~pho/stress/log/log0018.txt + +# Test scenario idea by kib@ +# Scenario should be the following (without paging load, so that pages stay +# resident): +# - create some large file, say 2G +# - map it and touch every page to ensure that they all allocated +# - unmap, and map again, so while the pages are resident, they are not +# installed into page table +# Do mincore(2) on the mapped region. +# + +# The problem was not reproduced. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +[ `sysctl -n vm.swap_total` -eq 0 ] && exit 0 +path=`dirname $diskimage` +[ `df -k $path | tail -1 | awk '{print int($4 / 1024 / 1024)}'` -lt 4 ] && exit 0 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mincore.c +mycc -o mincore -Wall -Wextra -O0 -g mincore.c || exit 1 +rm -f mincore.c +cd $odir + +(cd ../testcases/swap; ./swap -t 10m -i 20 -l 100) & +for i in `jot 20`; do + [ `swapinfo | tail -1 | awk '{gsub("%", ""); print $5}'` -gt 0 ] && break + sleep 5 + pgrep -q swap || break +done +echo "`date +%T` Go" + +$dir/mincore $path; s=$? + +while pkill swap; do :; done +wait +rm -rf $dir/mincore +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 2 +#define RUNTIME 300 +#define SIZE (2LL * 1024 * 1024 * 1024) + +static void +test(char *dir) +{ + size_t i, len; + int fd; + char file[128], *p, *vec; + + len = SIZE; + snprintf(file, sizeof(file), "%s/mincore.%d.file", dir, getpid()); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE)) + == -1) + err(1, "open(%s)", file); + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + if (ftruncate(fd, len) == -1) + err(1, "ftruncete()"); + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) + err(1, "mmap()"); + for (i = 0; i < len; i += PAGE_SIZE) + p[i] = 1; + if (munmap(p, len) == -1) + err(1, "munmap()"); + if ((vec = malloc(len / PAGE_SIZE)) == NULL) + err(1, "malloc"); + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) + err(1, "mmap()"); + if (mincore(p, len, vec) == -1) + err(1, "mincore()"); + if (munmap(p, len) == -1) + err(1, "munmap()"); + close(fd); + + _exit(0); +} + +int +main(int argc __unused, char *argv[]) +{ + pid_t pids[PARALLEL]; + time_t start; + int i; + + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(argv[1]); + } + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], NULL, WNOHANG) == pids[i]) { + if ((pids[i] = fork()) == 0) + test(argv[1]); + } + } + } + + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], NULL, 0) != pids[i]) + err(1, "waitpid"); + } + + return (0); +} diff --git a/tools/test/stress2/misc/minherit.sh b/tools/test/stress2/misc/minherit.sh new file mode 100755 index 000000000000..facb018a0337 --- /dev/null +++ b/tools/test/stress2/misc/minherit.sh @@ -0,0 +1,176 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Peter Holm +# +# 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. +# + +# minherit() test scenario inspired by Jeff's collapse.sh test. +# No problems seen. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/minherit.c +mycc -o minherit -Wall -Wextra -O0 -g minherit.c || exit 1 +rm -f minherit.c +cd $odir + +(cd $odir/../testcases/swap; ./swap -t 5m -i 10 -l 50) & +pid=$! +cd /tmp +$dir/minherit +s=$? +while pkill swap; do :; done +wait $oid +[ -f minherit.core -a $s -eq 0 ] && + { ls -l minherit.core; mv minherit.core $dir; s=1; } +cd $odir + +rm -rf $dir/minherit +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static _Atomic(int) *share; + +#define ADRSPACE (1024 * 1024) +#define CHILDREN 200 +#define PARALLEL 10 +#define RUNTIME (5 * 60) +#define SYNC 0 + +static void +test(void) +{ + pid_t pids[CHILDREN]; + off_t len; + void *p; + int i, ix, j, n, shared; + char *cp; + + (void)atomic_fetch_add(&share[SYNC], 1); + while (atomic_load(&share[SYNC]) != PARALLEL) + ; + + if ((p = mmap(NULL, ADRSPACE, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0)) == MAP_FAILED) { + if (errno == ENOMEM) + return; + err(1, "mmap()"); + } + + /* Pick a random bit of address space to change inherit on. */ + for (i = 0; i < ADRSPACE; i += len) { + shared = arc4random() & 0x1; + len = roundup2(arc4random() % ((ADRSPACE - i) / 4), + PAGE_SIZE); + if (minherit(p + i, len, shared ? INHERIT_SHARE : + INHERIT_COPY) != 0) + err(1, "minherit"); + } + + n = arc4random() % CHILDREN + 1; + for (i = 0; i < n; i++) { + pids[i] = fork(); + if (pids[i] == -1) + err(1, "fork()"); + if (pids[i] == 0) { + usleep(arc4random() % 100); + for (j = 0; j < 10; j++) { + cp = p; + for (ix = 0; ix < ADRSPACE; ix += PAGE_SIZE) { + cp[ix] = 1; + if (arc4random() % 100 < 5) + usleep(arc4random() % 50); + } + } + _exit(0); + } + } + for (i = 0; i < n; i++) { + if (waitpid(pids[i], NULL, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + } + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + e = status; + break; + } + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/mkfifo.sh b/tools/test/stress2/misc/mkfifo.sh new file mode 100755 index 000000000000..a0f012da5baa --- /dev/null +++ b/tools/test/stress2/misc/mkfifo.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Hunt for "panic: ufsdirhash_newblk: bad offset" + +# but page fault seen in scheduler() due to a _thread_lock_flags() call on +# an inactive td. + +# Fault seen in "softdep_disk_io_initiation+0x41": +# https://people.freebsd.org/~pho/stress/log/mkfifo.txt + +# Run with mkfifo.cfg on a 2g swap backed MD + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +[ "$newfs_flags" = "-U" ] && opt="-j" +newfs $opt md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +export TESTPROGS=" +testcases/creat/creat +testcases/fts/fts +testcases/link/link +testcases/lockf/lockf +testcases/mkdir/mkdir +testcases/mkfifo/mkfifo +testcases/openat/openat +testcases/rename/rename +testcases/rw/rw +testcases/swap/swap +" +export creatLOAD=100 +export ftsLOAD=100 +export linkLOAD=100 +export lockfLOAD=100 +export mkdirLOAD=100 +export mkfifoLOAD=100 +export openatLOAD=100 +export renameLOAD=100 +export rwLOAD=100 +export swapLOAD=100 + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/mkfifo2c.sh b/tools/test/stress2/misc/mkfifo2c.sh new file mode 100755 index 000000000000..6d83a5aca4a2 --- /dev/null +++ b/tools/test/stress2/misc/mkfifo2c.sh @@ -0,0 +1,89 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "bad offset" panic after up 10:57 on leopard3 + +# Run with mkfifo.cfg on a 2g swap backed MD +# Problem seen with and without +j + +# "panic: ufsdirhash_newblk: bad offset" seen: +# https://people.freebsd.org/~pho/stress/log/mkfifo2c.txt +# https://people.freebsd.org/~pho/stress/log/mkfifo2c-2.txt +# https://people.freebsd.org/~pho/stress/log/kostik932.txt +# Fixed by r305601. + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +[ $# -eq 1 ] && opt="$1" +[ $# -eq 0 ] && opt="-j" +newfs $opt md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=20m +export RUNDIR=$mntpoint/stressX + +export TESTPROGS=" +testcases/fts/fts +testcases/link/link +testcases/mkfifo/mkfifo +testcases/mkdir/mkdir +testcases/rename/rename +testcases/swap/swap +" + +export ftsLOAD=100 +export linkLOAD=100 +export mkdirLOAD=100 +export mkfifoLOAD=100 +export renameLOAD=100 +export swapLOAD=100 + +export renameINCARNATIONS=4 +export swapINCARNATIONS=4 +export linkINCARNATIONS=12 +export mkdirINCARNATIONS=20 +export mkfifoINCARNATIONS=22 +export ftsINCARNATIONS=2 + +export HOG=1 + +su $testuser -c 'cd ..; timeout 15m ./testcases/run/run $TESTPROGS' + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/mkfifo2d.sh b/tools/test/stress2/misc/mkfifo2d.sh new file mode 100755 index 000000000000..74d5875d090f --- /dev/null +++ b/tools/test/stress2/misc/mkfifo2d.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Copy of mkfifo2c.sh, but with a SU file system and async mount +# "panic: ufsdirhash_newblk: bad offset" seen from openat() +# https://people.freebsd.org/~pho/stress/log/mkfifo2d.txt +# Fixed by r305601. + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null +mount -o async /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX + +export TESTPROGS=" +testcases/fts/fts +testcases/link/link +testcases/mkfifo/mkfifo +testcases/mkdir/mkdir +testcases/rename/rename +testcases/swap/swap +" + +export ftsLOAD=100 +export linkLOAD=100 +export mkdirLOAD=100 +export mkfifoLOAD=100 +export renameLOAD=100 +export swapLOAD=100 + +export renameINCARNATIONS=4 +export swapINCARNATIONS=4 +export linkINCARNATIONS=12 +export mkdirINCARNATIONS=20 +export mkfifoINCARNATIONS=22 +export ftsINCARNATIONS=2 + +export HOG=1 + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/mkfifo3.sh b/tools/test/stress2/misc/mkfifo3.sh new file mode 100755 index 000000000000..1f205dbfa98b --- /dev/null +++ b/tools/test/stress2/misc/mkfifo3.sh @@ -0,0 +1,139 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +. ../default.cfg + +# Regression test for +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203162 + +# FAIL +# 1001 82102 907 0 20 0 6484 2480 wait S+ 0 0:00,01 /bin/sh ./mkfifo3.sh +# 1001 82113 82102 0 52 0 3832 1604 fifoow I+ 0 0:03,91 /tmp/mkfifo3 + +# Fixed in r288044. + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mkfifo3.c +mycc -o mkfifo3 -Wall -Wextra -O0 -g mkfifo3.c || exit 1 +rm -f mkfifo3.c +cd $odir + +fifo=/tmp/mkfifo3.fifo +trap "rm -f $fifo /tmp/mkfifo3" EXIT INT + +/tmp/mkfifo3 & + +for i in `jot 12`; do + pgrep -q mkfifo3 || break + sleep 10 +done +s=0 +if pgrep -q mkfifo3; then + s=1 + pgrep mkfifo3 | xargs ps -lp + pkill mkfifo3 +fi +wait + +exit $s +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define ATIME 1 +#define LOOPS 100000 + +char file[] = "/tmp/mkfifo3.fifo"; + +static void +hand(int i __unused) { /* handler */ +} + +int +main(void) +{ + pid_t pid; + struct sigaction sa; + int fd, i, status; + + sa.sa_handler = hand; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGALRM, &sa, NULL) == -1) + err(1, "sigaction"); + + if (unlink(file) == -1) + if (errno != ENOENT) + err(1, "unlink(%s)", file); + if (mkfifo(file, 0640) == -1) + err(1, "mkfifo(%s)", file); + + for (i = 0; i < LOOPS; i++) { + if ((pid = fork()) == 0) { + ualarm(ATIME, 0); + do { + if((fd = open(file, O_RDONLY)) == -1) + if (errno != EINTR) + err(1, "open(%s, O_RDONLY @ %d)", + file, i); + } while (fd == -1); + if (close(fd) == -1) + err(1, "close() in child"); + alarm(0); + _exit(0); + } + ualarm(ATIME, 0); + do { + if ((fd = open(file, O_WRONLY)) == -1) + if (errno != EINTR) + err(1, "open(%s, O_WRONLY @ %d)", + file, i); + } while (fd == -1); + if (close(fd) == -1) + err(1, "close() in parent"); + alarm(0); + if (waitpid(pid, &status, 0) == -1) + err(1, "wait"); + } + + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + + return (0); +} diff --git a/tools/test/stress2/misc/mkfifo4.sh b/tools/test/stress2/misc/mkfifo4.sh new file mode 100755 index 000000000000..0e560ffe7b4e --- /dev/null +++ b/tools/test/stress2/misc/mkfifo4.sh @@ -0,0 +1,186 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +. ../default.cfg + +# "Assertion vap->va_type == VDIR failed" seen on non HEAD. + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mkfifo4.c +mycc -o mkfifo4 -Wall -Wextra -O0 -g mkfifo4.c || exit 1 +rm -f mkfifo4.c +cd $odir + +fifo=/tmp/mkfifo4.fifo +trap "rm -f $fifo /tmp/mkfifo4" EXIT INT + +export runRUNTIME=5m +(cd ..; ./run.sh disk.cfg) > /dev/null 2>&1 & +sleep .2 + +while pgrep -fq run.sh; do + timeout 300 /tmp/mkfifo4 | grep -v Done + [ $? -eq 124 ] && + { echo "Timedout"; exit 1; } +done +wait + +exit $s +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define ATIME 1 +#define MXRETRY 100 +#define LOOPS 1000000 + +volatile int sigs; +char file[] = "/tmp/mkfifo4.fifo"; + +static void +hand(int i __unused) { /* handler */ + sigs++; +} + +int +main(void) +{ + pid_t pid, hpid; + struct sigaction sa; + int e, fd, fd2, i, status; + int failures, r, retries, w; + char c; + + sa.sa_handler = hand; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGALRM, &sa, NULL) == -1) + err(1, "sigaction"); + + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGPIPE, &sa, NULL) == -1) + err(1, "sigaction"); + + unlink(file); + if (mkfifo(file, 0640) == -1) + err(1, "mkfifo(%s)", file); + if ((hpid = fork()) == 0) { + if ((fd2 = open(file, O_WRONLY | O_APPEND)) == -1) + err(1, "hold open of fifo"); + for (;;) + pause(); + _exit(0); + } + + if ((pid = fork()) == 0) { + setproctitle("child"); + r = 0; + for (i = 0; i < LOOPS; i++) { + failures = 0; +restart: + do { + if ((fd = open(file, O_RDONLY | + O_NONBLOCK)) == -1) + if (errno != EINTR) /* on OS X */ + err(1, "open(%s, O_RDONLY)", + file); + } while (fd == -1); + retries = 0; + do { + if ((e = read(fd, &c, 1)) == -1) { + if (errno != EINTR && + errno != EAGAIN) + err(1, "read(%d, ...)", fd); + } else if (retries++ > MXRETRY) { + close(fd); + usleep(1000); + fprintf(stderr, + "Re-open for read @ %d\n", i); + if (failures++ > 100) + errx(1, + "FAIL: Failure to read"); + goto restart; + } + } while (e <= 0); + r++; + ualarm(ATIME, 0); + if (close(fd) == -1) + err(1, "close() in child"); + alarm(0); + } + fprintf(stdout, "Done child. %d reads, %d signals.\n", r, + sigs); + fflush(stdout); + _exit(0); + } + setproctitle("parent"); + w = 0; + for (i = 0; i < LOOPS; i++) { + do { + if ((fd = open(file, O_WRONLY | O_APPEND | + O_NONBLOCK)) == -1) + if (errno != EINTR && errno != ENXIO) + err(1, "open(%s, O_WRONLY)", file); + } while (fd == -1); + do { + if ((e = write(fd, "a", 1)) != 1) + if (errno != EPIPE && errno != EAGAIN) + err(1, "write(%d, ...)", fd); + } while (e == -1); + w++; + ualarm(ATIME, 0); + if (close(fd) == -1) + err(1, "close() in parent"); + alarm(0); + } + fprintf(stdout, "Done parent. %d writes, %d signals.\n", w, sigs); + + if (waitpid(pid, &status, 0) == -1) + err(1, "wait"); + if (kill(hpid, SIGHUP) == -1) + err(1, "kill %d", hpid); + if (waitpid(hpid, NULL, 0) == -1) + err(1, "wait"); + if (unlink(file) == -1) + err(1, "unlink(%s)", file); + + return (WEXITSTATUS(status)); +} diff --git a/tools/test/stress2/misc/mkfifo5.sh b/tools/test/stress2/misc/mkfifo5.sh new file mode 100755 index 000000000000..c0355cef2db0 --- /dev/null +++ b/tools/test/stress2/misc/mkfifo5.sh @@ -0,0 +1,214 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# mkfifo(2), select(2) with tmpfs(5) scenario. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mkfifo5.c +mycc -o mkfifo5 -Wall -Wextra -O0 -g mkfifo5.c || exit 1 +rm -f mkfifo5.c +cd $odir + +mount | grep -q "on $mntpoint " && umount -f $mntpoint +mount -o size=1g -t tmpfs tmpfs $mntpoint + +fifo=$mntpoint/fifo.file +cd $mntpoint +/tmp/mkfifo5 $fifo +s=$? +cd $odir + +while mount | grep "on $mntpoint " | grep -q tmpfs; do + umount $mntpoint || sleep 1 +done +rm -rf /tmp/mkfifo5 +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static char *path; + +#define PARALLEL 1 + +static void +reader(void) +{ + fd_set rset; + struct timeval timeout; + int fd, n, r; + char ch; + + do { + if((fd = open(path, O_RDONLY)) == -1) + if (errno != EINTR) + err(1, "open(%s, O_RDONLY)", + path); + if (fd == -1) + warn("open(%s) ro", path); + } while (fd == -1); + + /* Read one character */ + FD_ZERO(&rset); + FD_SET(fd, &rset); + if ((n = select(fd + 1, &rset, NULL, NULL, NULL)) < 0) + if (errno != EINTR) + err(1, "select()"); + if (n == 1 && FD_ISSET(fd, &rset)) { + r = read(fd, &ch, 1); + if (r == -1) + err(1, "read"); + if (r == 0) + fprintf(stderr, "read(1): EOF\n"); + } + + /* timeout */ + ch = 'z'; + FD_ZERO(&rset); + FD_SET(fd, &rset); + timeout.tv_sec = 1; + timeout.tv_usec = 0; + if ((n = select(fd + 1, &rset, NULL, NULL, &timeout)) < 0) + if (errno != EINTR) + err(1, "select()"); + if (n != 1) + fprintf(stderr, "FAIL Expected n == 0, got %d\n", n); + if (n == 1 && FD_ISSET(fd, &rset)) { + r = read(fd, &ch, 1); + if (r == -1) + err(1, "read"); + if (r == 0) + fprintf(stderr, "read(2): EOF\n"); + } + + /* timeout */ + ch = 'z'; + FD_ZERO(&rset); + FD_SET(fd, &rset); + timeout.tv_sec = 1; + timeout.tv_usec = 0; + if ((n = select(fd + 1, &rset, NULL, NULL, &timeout)) < 0) + if (errno != EINTR) + err(1, "select()"); + if (n != 1) + fprintf(stderr, "FAIL Expected n == 0, got %d\n", n); + if (n == 1 && FD_ISSET(fd, &rset)) { + r = read(fd, &ch, 1); + if (r == -1) + err(1, "read"); + if (r != 0) + fprintf(stderr, "read(3): %c\n", ch); + } + + if (close(fd) == -1) + err(1, "close() in child"); + _exit(n == 1 ? 0 : 1); +} + +static void +writer(void) +{ + int fd; + + do { + if ((fd = open(path, O_WRONLY)) == -1) + if (errno != EINTR) + err(1, "open(%s, O_WRONLY)", + path); + if (fd == -1) + warn("open(%s) wr", path); + } while (fd == -1); + if (write(fd, "a", 1) != 1) + err(1, "write one"); + if (write(fd, "b", 1) != 1) + err(1, "write one"); + if (close(fd) == -1) + warn("close() in parent"); +} + +static void +test(void) +{ + pid_t pid; + int status; + + if ((pid = fork()) == 0) + reader(); + writer(); + + if (waitpid(pid, &status, 0) != pid) + err(1, "waitpid(%d)", pid); + + _exit(status != 0); +} + +int +main(int argc __unused, char *argv[]) +{ + int e, i, pids[PARALLEL], status; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + path = argv[1]; + e = 0; + + unlink(path); + if (mkfifo(path, 0640) == -1) + err(1, "mkfifo(%s)", path); + + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/mkfifo6.sh b/tools/test/stress2/misc/mkfifo6.sh new file mode 100755 index 000000000000..5647bf9493d6 --- /dev/null +++ b/tools/test/stress2/misc/mkfifo6.sh @@ -0,0 +1,183 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# mkfifo(2), select(2) with tmpfs(5) scenario. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mkfifo6.c +mycc -o mkfifo6 -Wall -Wextra -O0 -g mkfifo6.c || exit 1 +rm -f mkfifo6.c +cd $odir + +mount | grep -q "on $mntpoint " && umount -f $mntpoint +mount -o size=1g -t tmpfs tmpfs $mntpoint + +fifo=$mntpoint/fifo.file +cd $mntpoint +/tmp/mkfifo6 $fifo +s=$? +cd $odir + +while mount | grep "on $mntpoint " | grep -q tmpfs; do + umount $mntpoint || sleep 1 +done +rm -rf /tmp/mkfifo6 +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static char *path; + +#define PARALLEL 1 + +static void +reader(void) +{ + fd_set rset; + struct timeval timeout; + int fd, n, r; + char ch; + + do { + if((fd = open(path, O_RDONLY)) == -1) + if (errno != EINTR) + err(1, "open(%s, O_RDONLY)", + path); + if (fd == -1) + warn("open(%s) ro", path); + } while (fd == -1); + + /* timeout */ + ch = 'z'; + FD_ZERO(&rset); + FD_SET(fd, &rset); + timeout.tv_sec = 0; + timeout.tv_usec = 100000; + if ((n = select(fd + 1, &rset, NULL, NULL, &timeout)) < 0) + if (errno != EINTR) + err(1, "select()"); + if (n != 0) + fprintf(stderr, "FAIL Expected n == 0, got %d\n", n); + if (n == 1 && FD_ISSET(fd, &rset)) { + r = read(fd, &ch, 1); + if (r == -1) + err(1, "read"); + if (r != 0) + fprintf(stderr, "read(2): %c\n", ch); + else + fprintf(stderr, "read(2): EOF\n"); + } + + sleep(3); + if (close(fd) == -1) + err(1, "close() in child"); + _exit(n); +} + +static void +writer(void) +{ + int fd; + + do { + if ((fd = open(path, O_WRONLY)) == -1) + if (errno != EINTR) + err(1, "open(%s, O_WRONLY)", + path); + if (fd == -1) + warn("open(%s) wr", path); + } while (fd == -1); + sleep(2); + if (write(fd, "a", 1) != 1) + err(1, "write one"); + if (close(fd) == -1) + warn("close() in parent"); +} + +static void +test(void) +{ + pid_t pid; + int status; + + if ((pid = fork()) == 0) + reader(); + writer(); + + if (waitpid(pid, &status, 0) != pid) + err(1, "waitpid(%d)", pid); + + _exit(status != 0); +} + +int +main(int argc __unused, char *argv[]) +{ + int e, i, pids[PARALLEL], status; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + path = argv[1]; + e = 0; + + unlink(path); + if (mkfifo(path, 0640) == -1) + err(1, "mkfifo(%s)", path); + + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/mkfifo7.sh b/tools/test/stress2/misc/mkfifo7.sh new file mode 100755 index 000000000000..b17e84536bed --- /dev/null +++ b/tools/test/stress2/misc/mkfifo7.sh @@ -0,0 +1,203 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# mkfifo(2), poll(2) with tmpfs(5) scenario. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mkfifo7.c +mycc -o mkfifo7 -Wall -Wextra -O0 -g mkfifo7.c || exit 1 +rm -f mkfifo7.c +cd $odir + +mount | grep -q "on $mntpoint " && umount -f $mntpoint +mount -o size=1g -t tmpfs tmpfs $mntpoint + +fifo=$mntpoint/fifo.file +cd $mntpoint +/tmp/mkfifo7 $fifo +s=$? +cd $odir + +while mount | grep "on $mntpoint " | grep -q tmpfs; do + umount $mntpoint || sleep 1 +done +rm -rf /tmp/mkfifo7 +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char *path; + +#define PARALLEL 1 + +static void +reader(void) +{ + struct pollfd pfd; + int fd, n, r; + char ch; + + do { + if((fd = open(path, O_RDONLY)) == -1) + if (errno != EINTR) + err(1, "open(%s, O_RDONLY)", + path); + if (fd == -1) + warn("open(%s) ro", path); + } while (fd == -1); + + /* Read one character */ + pfd.fd = fd; + pfd.events = POLLIN; + if ((n = poll(&pfd, 1, 0)) == -1) + err(1, "poll()"); + if (n == 1) { + r = read(fd, &ch, 1); + if (r == -1) + err(1, "read"); + if (r != 0) + fprintf(stderr, "read(1): %c\n", ch); + else + fprintf(stderr, "read(1): EOF\n"); + } + + /* timeout */ + ch = 'z'; + if ((n = poll(&pfd, 1, 7000)) == -1) + err(1, "poll()"); + if (n != 1) + fprintf(stderr, "FAIL Expected n == 1, got %d\n", n); + if (n == 1) { + r = read(fd, &ch, 1); + if (r == -1) + err(1, "read"); + if (r == 0) + fprintf(stderr, "read(2): EOF\n"); + } + + /* timeout */ + ch = 'z'; + if ((n = poll(&pfd, 1, 7000)) == -1) + err(1, "poll()"); + if (n != 1) + fprintf(stderr, "FAIL Expected n == 1, got %d\n", n); + if (n == 1) { + r = read(fd, &ch, 1); + if (r == -1) + err(1, "read"); + if (r != 0) + fprintf(stderr, "read(3): %c\n", ch); + } + + if (close(fd) == -1) + err(1, "close() in child"); + _exit(n == 1 ? 0 : 1); +} + +static void +writer(void) +{ + int fd; + + do { + if ((fd = open(path, O_WRONLY)) == -1) + if (errno != EINTR) + err(1, "open(%s, O_WRONLY)", + path); + if (fd == -1) + warn("open(%s) wr", path); + } while (fd == -1); + if (write(fd, "a", 1) != 1) + err(1, "write one"); + if (close(fd) == -1) + warn("close() in parent"); +} + +static void +test(void) +{ + pid_t pid; + int status; + + if ((pid = fork()) == 0) + reader(); + writer(); + + if (waitpid(pid, &status, 0) != pid) + err(1, "waitpid(%d)", pid); + + _exit(status != 0); +} + +int +main(int argc __unused, char *argv[]) +{ + int e, i, pids[PARALLEL], status; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + path = argv[1]; + e = 0; + + unlink(path); + if (mkfifo(path, 0640) == -1) + err(1, "mkfifo(%s)", path); + + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/mkfifo8.sh b/tools/test/stress2/misc/mkfifo8.sh new file mode 100755 index 000000000000..6227070f016e --- /dev/null +++ b/tools/test/stress2/misc/mkfifo8.sh @@ -0,0 +1,200 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Regression test for https://reviews.freebsd.org/D20784 +# "Fix mutual exclusion in pipe_direct_write()" +# https://people.freebsd.org/~pho/stress/log/mkfifo8.txt + +# Reported by syzbot+21811cc0a89b2a87a9e7@syzkaller.appspotmail.com +# Test scenario suggestion by markj@ +# Fixed by r349546 + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mkfifo8.c +mycc -o mkfifo8 -Wall -Wextra -O0 -g mkfifo8.c || exit 1 +rm -f mkfifo8.c +cd $odir + +set -e +mount | grep -q "on $mntpoint " && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +newfs $newfs_flags /dev/md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +cd $mntpoint +$dir/mkfifo8; s=$? +cd $odir + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -rf /tmp/mkfifo8 +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define ACT 1 +#define NPROCS 64 +#define PARALLEL 4 +#define RUNTIME 60 +#define SIZ 8192 +#define SYNC 0 + +static volatile u_int *share; +static int fd; +static char cp[SIZ]; + +static void +tw(void) +{ + int r; + + atomic_add_int(&share[ACT], 1); + r = write(fd, cp, SIZ); + if (r == -1) + warn("write"); + + _exit(0); +} + +static void +tr(void) +{ + int i, r; + char cp[SIZ]; + + while (share[ACT] < NPROCS / 2) + usleep(10); + for (i = 0; i < NPROCS; i++) { + r = read(fd, cp, SIZ); + if (r == -1) + warn("read"); + } + + _exit(0); +} + +static void +test(void) +{ + pid_t pid[NPROCS + 1]; + int i; + char file[80]; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + snprintf(file, sizeof(file), "fifo.%d", getpid()); + if (mkfifo(file, DEFFILEMODE) == -1) + err(1, "mkfifo(%s)", file); + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open(%s)", file); + + for (i = 0; i < NPROCS; i++) { + if ((pid[i] = fork()) == 0) + tw(); + } + if ((pid[NPROCS] = fork()) == 0) + tr(); + + for (i = 0; i < NPROCS + 1; i++) { + if (waitpid(pid[i], NULL, 0) != pid[i]) + err(1, "waitpid"); + } + close(fd); + unlink(file); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + for (i = 0; i < SIZ; i += PAGE_SIZE) + cp[i] = 1; + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + share[ACT] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/mknod.sh b/tools/test/stress2/misc/mknod.sh new file mode 100755 index 000000000000..d2b9aa617577 --- /dev/null +++ b/tools/test/stress2/misc/mknod.sh @@ -0,0 +1,163 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# mknod(2) regression test +# "panic: ffs_write: type 0xca2b02d0 8 (0,3)" seen. +# Reported by: Dmitry Vyukov +# Fixed by r324853 + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mknod.c +mycc -o mknod -Wall -Wextra -O0 -g mknod.c || exit 1 +rm -f mknod.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +set +e + +cd $mntpoint +$dir/mknod $mntpoint +s=$? +[ -f mknod.core -a $s -eq 0 ] && + { ls -l mknod.core; mv mknod.core /tmp; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && exit 1 +mdconfig -d -u $mdstart +rm -rf $dir/mknod +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; +static char *mp; + +#define PARALLEL 4 +#define RUNTIME (1 * 60) +#define SYNC 0 + +static void +test(void) +{ + dev_t dev; + mode_t mode; + time_t start; + int fd, n, r; + char path[128]; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + n = 0; + snprintf(path, sizeof(path), "%s/node.%06d.%d", mp, getpid(), n); + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + dev = makedev(arc4random(), arc4random()); + mode = arc4random() % 0x10000; + r = mknod(path, mode, dev); + if (r == 0) { + if ((fd = open(path, O_RDWR)) != -1) { + write(fd, "x", 1); + close(fd); + } + unlink(path); + n++; + snprintf(path, sizeof(path), "%s/node.%06d.%d", mp, + getpid(), n); + } + } + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + pid_t pids[PARALLEL]; + size_t len; + int e, i, status; + + if (argc != 2) + return (1); + mp = argv[1]; + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/mlockall.sh b/tools/test/stress2/misc/mlockall.sh new file mode 100755 index 000000000000..6171725d8b3d --- /dev/null +++ b/tools/test/stress2/misc/mlockall.sh @@ -0,0 +1,80 @@ +#!/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. +# + +# "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 +mycc -o mlockall -Wall mlockall.c +rm -f mlockall.c + +for i in `jot 10`; do + /tmp/mlockall & + sleep 1 + ps -x | 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/tools/test/stress2/misc/mlockall2.sh b/tools/test/stress2/misc/mlockall2.sh new file mode 100755 index 000000000000..dbeaf729342b --- /dev/null +++ b/tools/test/stress2/misc/mlockall2.sh @@ -0,0 +1,165 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# core dumps seen in watchdogd after mlockall() was added. +# This scenario demonstrates the problem. Fixed in r242012. + +# "panic: freeing mapped page 0xfffff8181b38a5e8" seen: +# https://people.freebsd.org/~pho/stress/log/mark030.txt + +mem=`sysctl -n hw.usermem` +[ `sysctl -n vm.swap_total` -eq 0 ] && mem=$((mem / 100 * 60)) + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mlockall2.c +mycc -o mlockall2 -Wall -Wextra -O2 -g mlockall2.c || exit 1 +rm -f mlockall2.c +cd $here + +rm -f mlockall2.core +/tmp/mlockall2 $mem & +while kill -0 $! 2>/dev/null; do + [ -r mlockall2.core ] && kill $! && break + sleep 10 +done +[ -r mlockall2.core ] && s=1 || s=0 +pkill mlockall2 +wait +rm -f /tmp/mlockall2 mlockall2.core +exit $s +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define LOAD 40 +#define N 90000 +#define PARALLEL 5 +#define RUNTIME 600 + +static long size; + +static void +swap(void) +{ + long i; + int page; + volatile char *c; + + setproctitle("swap"); + c = malloc(size); + while (c == NULL) { + size -= 1024 * 1024; + c = malloc(size); + } + page = getpagesize(); + for (;;) { + i = 0; + while (i < size) { + c[i] = 0; + i += page; + } + } +} + +static void +test(void) +{ + pid_t p; + int i, status; + + setproctitle("test"); + for (i = 0; i < N; i++) { + if ((p = fork()) == 0) { + _exit(0); + } + if (p > 0) + waitpid(p, &status, 0); + if (status != 0) + break; + } + _exit(0); +} + +int +main(int argc __unused, char **argv) +{ + time_t start; + struct rtprio rtp; + pid_t pids[LOAD], pids2[PARALLEL]; + int i; + + size = atol(argv[1]) / LOAD * 1.5; + for (i = 0; i < LOAD; i++) + if ((pids[i] = fork()) == 0) + swap(); + sleep(10); + + rtp.type = RTP_PRIO_REALTIME; + rtp.prio = 0; + if (rtprio(RTP_SET, 0, &rtp) == -1) + err(1, "rtprio"); + + if (madvise(0, 0, MADV_PROTECT) != 0) + err(1, "madvise failed"); + if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) + err(1, "mlockall failed"); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if ((pids2[i] = fork()) == 0) + test(); + } + + for (i = 0; i < PARALLEL; i++) + if (waitpid(pids2[i], NULL, 0) != pids2[i]) + err(1, "waitpid(%d) (2)", pids2[i]); + if (access("mlockall2.core", R_OK) == 0) + break; + } + for (i = 0; i < LOAD; i++) + kill(pids[i], SIGKILL); + for (i = 0; i < LOAD; i++) + if (waitpid(pids[i], NULL, 0) != pids[i]) + err(1, "waitpid(%d)", pids[i]); + + return (0); +} diff --git a/tools/test/stress2/misc/mlockall3.sh b/tools/test/stress2/misc/mlockall3.sh new file mode 100755 index 000000000000..0ff1e24eaa7f --- /dev/null +++ b/tools/test/stress2/misc/mlockall3.sh @@ -0,0 +1,167 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# mlockall(2) test scenario. +# "panic: vm_page_unwire: page xxx's wire count is zero" seen. +# http://people.freebsd.org/~pho/stress/log/mlockall.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mlockall3.c +mycc -o mlockall3 -Wall -Wextra mlockall3.c -lpthread || exit 1 +rm -f mlockall3.c +cd $odir + +/tmp/mlockall3 + +killall mlockall3 > /dev/null 2>&1 +rm -f /tmp/mlockall3 +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +u_int32_t r[N]; + +static void +hand(int i __unused) { /* handler */ + _exit(1); +} + +unsigned long +makearg(void) +{ + unsigned int i; + unsigned long val; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +calls(void *arg __unused) +{ + int i; + unsigned long arg1, arg2, arg3; + + usleep(1000); + for (i = 0; i < 500; i++) { + arg1 = makearg(); + arg2 = makearg(); + arg3 = makearg(); + + alarm(1); + syscall(SYS_mlockall, arg1, arg2, arg3); + } + + return (0); +} + +int +main(void) +{ + struct passwd *pw; + pid_t pid; + pthread_t cp[50]; + int e, i, j; + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + signal(SIGALRM, hand); + signal(SIGILL, hand); + signal(SIGFPE, hand); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + signal(SIGURG, hand); + signal(SIGSYS, hand); + signal(SIGTRAP, hand); + + alarm(180); + for (i = 0; i < 8000; i++) { + if ((pid = fork()) == 0) { + for (j = 0; j < N; j++) + r[j] = arc4random(); + for (j = 0; j < 50; j++) + if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) + errc(1, e, "pthread_create"); + + for (j = 0; j < 50; j++) + pthread_join(cp[j], NULL); + _exit(0); + } + if (pid == -1) + err(1, "fork()"); + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mlockall4.sh b/tools/test/stress2/misc/mlockall4.sh new file mode 100755 index 000000000000..778256fa8976 --- /dev/null +++ b/tools/test/stress2/misc/mlockall4.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# mlockall(2) / nullfs(5) scenario causes: +# http://people.freebsd.org/~pho/stress/log/kostik619.txt +# kern/182661, fixed in r256211. + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mlockall4.c +mycc -o mlockall4 -Wall -Wextra mlockall4.c || exit 1 +rm -f mlockall4.c + +mount | grep -q "on $mntpoint " && umount -f $mntpoint +mount -t nullfs /tmp $mntpoint +$mntpoint/mlockall4 & +sleep 2 +umount -f $mntpoint + +wait +rm -f /tmp/mlockall4 +exit +EOF +#include +#include +#include +#include + +int +main(void) +{ + if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) + err(1, "mlockall(MCL_CURRENT | MCL_FUTURE)"); + sleep(5); + + return (0); +} diff --git a/tools/test/stress2/misc/mlockall5.sh b/tools/test/stress2/misc/mlockall5.sh new file mode 100755 index 000000000000..847909b478c2 --- /dev/null +++ b/tools/test/stress2/misc/mlockall5.sh @@ -0,0 +1,162 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Regression test for r287591: + +# From the commit log: +# Remove a check which caused spurious SIGSEGV on usermode access to the +# mapped address without valid pte installed, when parallel wiring of +# the entry happen. The entry must be copy on write. If entry is COW +# but was already copied, and parallel wiring set +# MAP_ENTRY_IN_TRANSITION, vm_fault() would sleep waiting for the +# MAP_ENTRY_IN_TRANSITION flag to clear. After that, the fault handler +# is restarted and vm_map_lookup() or vm_map_lookup_locked() trip over +# the check. Note that this is race, if the address is accessed after +# the wiring is done, the entry does not fault at all. + +# Test scenario by kib@. + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mlockall5.c +mycc -o mlockall5 -Wall -Wextra -O0 -g mlockall5.c -lpthread || exit 1 +rm -f mlockall5.c +cd $odir + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 512m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags -n md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint || exit 1 + +(cd $mntpoint; /tmp/mlockall5 || echo FAIL) + +n=0 +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 + n=$((n + 1)) + [ $n -gt 10 ] && { echo FAIL; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf /tmp/mlockall5 +exit + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +size_t clen; +volatile u_int share; +int ps; +char *c; + +void * +touch(void *arg __unused) +{ + + int i; + + while (share == 0) + ; + for (i = 0; i < (int)clen; i += ps) + c[i] = 1; + + return (NULL); +} + +void * +ml(void *arg __unused) +{ + while (share == 0) + ; + if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) + err(1, "mlock"); + + return (NULL); +} + +int +test(void) +{ + pthread_t tid[2]; + int i, rc, status; + + if (fork() == 0) { + alarm(60); + rc = pthread_create(&tid[0], NULL, touch, NULL); + if (rc != 0) + errc(1, rc, "pthread_create()"); + rc = pthread_create(&tid[1], NULL, ml, NULL); + if (rc != 0) + errc(1, rc, "pthread_create()"); + share = 1; + for (i = 0; i < (int)nitems(tid); i++) { + rc = pthread_join(tid[i], NULL); + if (rc != 0) + errc(1, rc, "pthread_join(%d)", i); + } + _exit(0); + } + + if (wait(&status) == -1) + err(1, "wait"); + + return (WTERMSIG(status)); +} + +int +main(void) +{ + int s; + + ps = getpagesize(); + clen = 32 * 1024; + if ((c = mmap(NULL, clen, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, + -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + s = test(); + + return (s); +} diff --git a/tools/test/stress2/misc/mlockall6.sh b/tools/test/stress2/misc/mlockall6.sh new file mode 100755 index 000000000000..a755350f673d --- /dev/null +++ b/tools/test/stress2/misc/mlockall6.sh @@ -0,0 +1,203 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# "panic: Lock (rw) vm object not locked @ vm/vm_page.c:1013" seen: +# https://people.freebsd.org/~pho/stress/log/mlockall6-2.txt + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mlockall6.c +mycc -o mlockall6 -Wall -Wextra -O0 -g mlockall6.c || exit 1 +rm -f mlockall6.c +cd $odir + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 512m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags -n md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint || exit 1 + +daemon sh -c "(cd $odir/../testcases/swap; ./swap -t 20m -i 20 -l 100)" \ + > /dev/null 2>&1 +sleep 2 + +(cd $mntpoint; /tmp/mlockall6 || echo FAIL) + +while pgrep -q swap; do + pkill -9 swap +done + +n=0 +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 + n=$((n + 1)) + [ $n -gt 10 ] && { echo FAIL; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf /tmp/mlockall6 +exit 0 + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 2 +#define PARALLEL 8 +#define R0 0 +#define R1 1 +#define R2 2 +#define RUNTIME (10 * 60) + +static volatile u_int *share; +static int ps; +static char c[32 * 1024 * 1024]; + +static void +touch(void) +{ + int i; + + for (i = 0; i < (int)sizeof(c); i += ps) + c[i] = 1; +} + +static void +test2(void) +{ + pid_t pid; + volatile u_int *share2; + size_t len; + int i, status; + + len = ps; + if ((share2 = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + touch(); + usleep(arc4random() % 100000); + alarm(600); + if ((pid = fork()) == 0) { + alarm(600); + while (share2[R1] == 0) /* Wait for parent */ + ; + atomic_add_int(&share2[R1], 1); + if (arc4random() % 100 < 50) + usleep(arc4random() % 1000); + if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) + err(1, "mlock"); + touch(); + atomic_add_int(&share2[R2], 1); + _exit(0); + } + atomic_add_int(&share2[R1], 1); + while (share2[R1] != 2) /* Wait for child */ + ; + + for (i = 0; i < 100000 && share2[R2] == 0; i++) + touch(); /* while child is running */ + + if (waitpid(pid, &status, 0) == -1) + err(1, "wait"); + + if (status != 0) + fprintf(stderr, "Got signal %d\n", WTERMSIG(status)); + _exit(WTERMSIG(status)); +} + +static void +test(void) +{ + pid_t pid; + int i, s, status; + + while (share[R0] == 0) + ; + s = 0; + for (i = 0; i < LOOPS; i++) { + if ((pid = fork()) == 0) + test2(); + waitpid(pid, &status, 0); + s = (s == 0) ? status : s; + } + _exit(s); +} + +int +main(void) +{ + pid_t pid; + size_t len; + time_t start; + int i, s, status; + + ps = getpagesize(); + len = ps; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + start = time(NULL); + s = 0; + while (s == 0 && (time(NULL) - start) < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if ((pid = fork()) == 0) + test(); + } + atomic_add_int(&share[R0], 1); /* Start test() runs */ + for (i = 0; i < PARALLEL; i++) { + waitpid(pid, &status, 0); + if (status != 0) { + fprintf(stderr, "FAIL: status = %d\n", + status); + } + s = (s == 0) ? status : s; + } + atomic_add_int(&share[R0], -1); + } + + return (s); +} diff --git a/tools/test/stress2/misc/mlockall7.sh b/tools/test/stress2/misc/mlockall7.sh new file mode 100755 index 000000000000..987e312f19e7 --- /dev/null +++ b/tools/test/stress2/misc/mlockall7.sh @@ -0,0 +1,262 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Variation of mmap18.sh. +# "panic: vm_page_unwire: page 0xfffff81038d721f0's wire count is zero" seen: +# https://people.freebsd.org/~pho/stress/log/mlockall7.txt +# Fixed by r328880 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mlockall7.c +mycc -o mlockall7 -Wall -Wextra -O2 mlockall7.c -lpthread || exit 1 +rm -f mlockall7.c + +/tmp/mlockall7 `[ $# -eq 0 ] && echo 1 || echo $1` || s=1 + +sleep 2 +rm -f /tmp/mlockall7 /tmp/mlockall7.core +exit $s +EOF +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N 4096 +#define PARALLEL 50 +#define RUNTIME 180 + +static u_int32_t r[N]; +static void *p; + +static unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return (val); +} + +static void * +tmmap(void *arg __unused) +{ + size_t len; + time_t start; + + pthread_set_name_np(pthread_self(), __func__); + len = 128LL * 1024 * 1024; + + start = time(NULL); + while (time(NULL) - start < 60) { + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, + -1, 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + } + } + + return (NULL); +} + +static void * +tmlockall(void *arg __unused) +{ + time_t start; + int flags; + + pthread_set_name_np(pthread_self(), __func__); + start = time(NULL); + while (time(NULL) - start < 60) { + flags = makearg() & 0xff; + mlockall(flags); + usleep(100); + munlockall(); + usleep(1000); + } + + return (NULL); +} + +static void +test(void) +{ + pthread_t tid[2]; + time_t start; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlockall, NULL)) != 0) + errc(1, rc, "tmlock()"); + + start = time(NULL); + while (time(NULL) - start < 60) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + for (i = 0; i < 2; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join"); + _exit(0); +} + +int +testing(unsigned long maxl) +{ + struct passwd *pw; + struct rlimit rl; + rlim_t maxlock; + time_t start; + int i; + + maxlock = maxl; + if ((pw = getpwnam("nobody")) == NULL) + err(1, "failed to resolve nobody"); + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + rl.rlim_max = rl.rlim_cur = 0; + if (setrlimit(RLIMIT_CORE, &rl) == -1) + warn("setrlimit"); + + if (getrlimit(RLIMIT_MEMLOCK, &rl) == -1) + warn("getrlimit"); + if (maxlock <= 0) + errx(1, "Argument is %jd", maxlock); + maxlock = (maxlock / 10 * 8) / PARALLEL * PAGE_SIZE; + if (maxlock < rl.rlim_cur) { + rl.rlim_max = rl.rlim_cur = maxlock; + if (setrlimit(RLIMIT_MEMLOCK, &rl) == -1) + warn("setrlimit"); + } + + for (i = 0; i < N; i++) + r[i] = arc4random(); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + test(); + } + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + } + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + pid_t pid; + size_t len; + int i, loops, s, status; + unsigned long max_wired; + unsigned int wire_count, wire_count_old; + + s = 0; + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + loops = atoi(argv[1]); + + len = sizeof(max_wired); + if (sysctlbyname("vm.max_user_wired", &max_wired, &len, NULL, 0) != 0) + err(1, "vm.max_user_wired"); + + len = sizeof(wire_count); + if (sysctlbyname("vm.stats.vm.v_user_wire_count", &wire_count, &len, + NULL, 0) != 0) + err(1, "vm.stats.vm.v_user_wire_count"); + + for (i = 0; i < loops; i++) { + wire_count_old = wire_count; + + if ((pid = fork()) == 0) + testing(max_wired); + if (waitpid(pid, &status, 0) != pid) + err(1, "waitpid(%d)", pid); + if (status != 0) + errx(1, "Exit status %d from pid %d\n", status, pid); + + len = sizeof(wire_count); + if (sysctlbyname("vm.stats.vm.v_user_wire_count", &wire_count, &len, + NULL, 0) != 0) + err(1, "vm.stats.vm.v_user_wire_count"); + fprintf(stderr, "vm.stats.vm.v_user_wire_count was %d, is %d. %d\n", + wire_count_old, wire_count, wire_count - wire_count_old); + } + + return (s); +} diff --git a/tools/test/stress2/misc/mmap.sh b/tools/test/stress2/misc/mmap.sh new file mode 100755 index 000000000000..95561365a53d --- /dev/null +++ b/tools/test/stress2/misc/mmap.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# 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 +mycc -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/tools/test/stress2/misc/mmap10.sh b/tools/test/stress2/misc/mmap10.sh new file mode 100755 index 000000000000..a29768c36691 --- /dev/null +++ b/tools/test/stress2/misc/mmap10.sh @@ -0,0 +1,273 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# "panic: vm_page_dirty: page is invalid!" seen. +# http://people.freebsd.org/~pho/stress/log/mmap10.txt +# No problems seen after r271681. + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap10.c +mycc -o mmap10 -Wall -Wextra -O2 -g mmap10.c -lpthread || exit 1 +rm -f mmap10.c + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)" +sleep `jot -r 1 0 9` +for i in `jot 2`; do + /tmp/mmap10 & +done +sleep 300 +while pgrep -q mmap10; do + pkill -9 mmap10 + sleep 2 +done +wait +killall -q swap + +rm -f /tmp/mmap10 /tmp/mmap10.core +exit 0 +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 2 +#define MMSIZE (192 * 1024 * 1024) +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define PARALLEL 50 + +void *p; +u_int32_t r[N]; + +unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +makeptr(void) +{ + unsigned long val; + + if (p != MAP_FAILED && p != NULL) + val = (unsigned long)p + arc4random(); + else + val = makearg(); + val = trunc_page(val); + + return ((void *)val); +} + +void * +tmmap(void *arg __unused) +{ + size_t len; + int i, j, fd; + + pthread_set_name_np(pthread_self(), __func__); + len = MMSIZE; + + for (i = 0, j = 0; i < 100; i++) { + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1,"open()"); + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, + fd, 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + j++; + } + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, + -1, 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + j++; + } + close(fd); + } + if (j == 0) + fprintf(stderr, "FAIL: all mmap(2) calls failed.\n"); + + return (NULL); +} + +void * +tmlock(void *arg __unused) +{ + size_t len; + int i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + len = trunc_page(makearg()); + if (mlock(makeptr(), len) == 0) + n++; + len = trunc_page(makearg()); + if (arc4random() % 100 < 50) + if (munlock(makeptr(), len) == 0) + n++; + } + if (n < 10) + fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", + n); + + return (NULL); +} + +void * +tmprotect(void *arg __unused) +{ + size_t len; + void *addr; + int i, n, prot; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + addr = makeptr(); + len = trunc_page(makearg()); + prot = makearg(); + if (mprotect(addr, len, prot) == 0) + n++; + usleep(1000); + } + if (n < 10) + fprintf(stderr, "Note: tmprotect() only succeeded %d times.\n", + n); + + return (NULL); +} + +void * +tmlockall(void *arg __unused) +{ + int flags, i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + flags = makearg(); + if (mlockall(flags) == 0) + n++; + usleep(100); + munlockall(); + usleep(1000); + } + if (n < 10) + fprintf(stderr, "Note: tmlockall() only succeeded %d times.\n", + n); + + return (NULL); +} + +void +test(void) +{ + pthread_t tid[4]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) + errc(1, rc, "tmlock()"); + if ((rc = pthread_create(&tid[2], NULL, tmprotect, NULL)) != 0) + errc(1, rc, "tmprotect()"); + if ((rc = pthread_create(&tid[3], NULL, tmlockall, NULL)) != 0) + errc(1, rc, "tmlockall()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + for (i = 0; i < 4; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(void) +{ + int i, j; + + for (i = 0; i < N; i++) + r[i] = arc4random(); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap11.sh b/tools/test/stress2/misc/mmap11.sh new file mode 100755 index 000000000000..5d2fba6d98b7 --- /dev/null +++ b/tools/test/stress2/misc/mmap11.sh @@ -0,0 +1,301 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Copy of mmap10.sh with msync() added. +# "panic: vm_map_protect: inaccessible wired map entry" seen: +# http://people.freebsd.org/~pho/stress/log/mmap11.txt +# No problems seen after r271681. + +# http://people.freebsd.org/~pho/stress/log/kostik730.txt, Fixed in r273784 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap11.c +mycc -o mmap11 -Wall -Wextra -O2 -g mmap11.c -lpthread || exit 1 +rm -f mmap11.c + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)" +sleep `jot -r 1 0 9` +for i in `jot 2`; do + /tmp/mmap11 & +done +sleep 300 +while pgrep -q mmap11; do + pkill -9 mmap11 + sleep 2 +done +wait +killall -q swap + +rm -f /tmp/mmap11 /tmp/mmap11.core +exit 0 +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 2 +#define MMSIZE (192 * 1024 * 1024) +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define PARALLEL 50 + +void *p; +u_int32_t r[N]; + +unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +makeptr(void) +{ + unsigned long val; + + if (p != MAP_FAILED && p != NULL) + val = (unsigned long)p + arc4random(); + else + val = makearg(); + val = trunc_page(val); + + return ((void *)val); +} + +void * +tmmap(void *arg __unused) +{ + size_t len; + int i, j, fd; + + pthread_set_name_np(pthread_self(), __func__); + len = MMSIZE; + + for (i = 0, j = 0; i < 100; i++) { + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1,"open()"); + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, + fd, 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + j++; + } + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, + -1, 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + j++; + } + close(fd); + } + if (j == 0) + fprintf(stderr, "FAIL: all mmap(2) calls failed.\n"); + + return (NULL); +} + +void * +tmlock(void *arg __unused) +{ + size_t len; + int i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + len = trunc_page(makearg()); + if (mlock(makeptr(), len) == 0) + n++; + len = trunc_page(makearg()); + if (arc4random() % 100 < 50) + if (munlock(makeptr(), len) == 0) + n++; + } + if (n < 10) + fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", + n); + + return (NULL); +} + +void * +tmprotect(void *arg __unused) +{ + size_t len; + void *addr; + int i, n, prot; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + addr = makeptr(); + len = trunc_page(makearg()); + prot = makearg(); + if (mprotect(addr, len, prot) == 0) + n++; + usleep(1000); + } + if (n < 10) + fprintf(stderr, "Note: tmprotect() only succeeded %d times.\n", + n); + return (NULL); +} + +void * +tmlockall(void *arg __unused) +{ + int flags, i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + flags = makearg(); + if (mlockall(flags) == 0) + n++; + usleep(100); + munlockall(); + usleep(1000); + } + if (n < 10) + fprintf(stderr, "Note: tmlockall() only succeeded %d times.\n", + n); + + return (NULL); +} + +void * +tmsync(void *arg __unused) +{ + size_t len; + void *addr; + int flags, i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + addr = makeptr(); + len = trunc_page(makearg()); + flags = makearg(); + if (msync(addr, len, flags) == 0) + n++; + usleep(2000); + } + if (n < 10) + fprintf(stderr, "Note: tmsync() only succeeded %d times.\n", + n); + + return (NULL); +} + +void +test(void) +{ + pthread_t tid[5]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) + errc(1, rc, "tmlock()"); + if ((rc = pthread_create(&tid[2], NULL, tmprotect, NULL)) != 0) + errc(1, rc, "tmprotect()"); + if ((rc = pthread_create(&tid[3], NULL, tmlockall, NULL)) != 0) + errc(1, rc, "tmlockall()"); + if ((rc = pthread_create(&tid[4], NULL, tmsync, NULL)) != 0) + errc(1, rc, "tmlockall()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + for (i = 0; i < 5; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(void) +{ + int i, j; + + for (i = 0; i < N; i++) + r[i] = arc4random(); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap12.sh b/tools/test/stress2/misc/mmap12.sh new file mode 100755 index 000000000000..917c23a6df8b --- /dev/null +++ b/tools/test/stress2/misc/mmap12.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# "panic: vm_map_protect: inaccessible wired map entry" seen: +# http://people.freebsd.org/~pho/stress/log/mmap11.txt +# Fixed in r266780. + +# Test scenario by: Mark Johnston markj@ + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap12.c +mycc -o mmap12 -O2 -Wall -Wextra mmap12.c || exit 1 +rm -f mmap12.c +cd $odir + +/tmp/mmap12 + +rm -f /tmp/mmap12 +exit + +EOF +#include + +#include +#include +#include + +int +main(void) +{ + void *addr; + size_t sz = 1; + +/* + * This is the minimum amount of C code ot takes to panic the kernel. + * This is as submitted and thus not a complete and correct test program. + */ + addr = mmap(NULL, sz, PROT_READ, MAP_ANON, -1, 0); + if (addr == NULL) + err(1, "mmap"); + + if (mlock(addr, sz) != 0) + err(1, "mlock"); + if (mprotect(addr, sz, PROT_NONE) != 0) + err(1, "mprotect 1"); + if (mprotect(addr, sz, PROT_WRITE) != 0) + err(1, "mprotect 2"); + if (munmap(addr, sz) != 0) + err(1, "munmap"); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap13.sh b/tools/test/stress2/misc/mmap13.sh new file mode 100755 index 000000000000..993e1bc2185c --- /dev/null +++ b/tools/test/stress2/misc/mmap13.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Leak of "vm.stats.vm.v_user_wire_count" seen. +# This test must run in single user mode for accurate leak reporting. +# Test scenario by: Mark Johnston markj@ +# Fixed in r269134. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap13.c +mycc -o mmap13 -O2 -Wall -Wextra mmap13.c || exit 1 +rm -f mmap13.c +cd $odir + +# Both the 5000 and 500 are empirical values. +# Combined they demonstrate the leak in a consistent way. + +v1=`sysctl -n vm.stats.vm.v_user_wire_count` +for i in `jot 5000`; do + /tmp/mmap13 +done 2>&1 | tail -5 +v2=`sysctl -n vm.stats.vm.v_user_wire_count` +[ $v2 -gt $((v1 + 500)) ] && + echo "vm.stats.vm.v_user_wire_count changed from $v1 to $v2." + +rm -f /tmp/mmap13 +exit 0 + +EOF +#include + +#include +#include +#include + +int +main(void) +{ + void *addr; + size_t sz; + + sz = getpagesize(); + addr = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + if (addr == NULL) + err(1, "mmap"); + if (mlock(addr, sz) != 0) + err(1, "mlock"); + if (mprotect(addr, sz, PROT_NONE) != 0) + err(1, "mprotect"); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap14.sh b/tools/test/stress2/misc/mmap14.sh new file mode 100755 index 000000000000..e5a59890189b --- /dev/null +++ b/tools/test/stress2/misc/mmap14.sh @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Simplified version of mmap10.sh with focus on core dumps +# Deadlock seen: +# http://people.freebsd.org/~pho/stress/log/kostik673.txt +# No issues seen with r272060. + +# panic: vm_reserv_populate: reserv 0xfffff807cbd46300 is already promoted +# http://people.freebsd.org/~pho/stress/log/kostik764.txt +# Fixed by r280238 + +# panic: vm_reserv_break: reserv 0xfffff807cbe9af00 is full +# https://people.freebsd.org/~pho/stress/log/alan006.txt + +# panic: vm_page_dirty: page is invalid! +# https://people.freebsd.org/~pho/stress/log/kostik818.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap14.c +mycc -o mmap14 -Wall -Wextra -O2 -g mmap14.c -lpthread || exit 1 +rm -f mmap14.c + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k -h)" +sleep `jot -r 1 1 10` +wire=$((`sysctl -n vm.max_user_wired` - \ + `sysctl -n vm.stats.vm.v_user_wire_count`)) +for i in `jot 2`; do + /tmp/mmap14 $wire +done +while pgrep -q swap; do + pkill -9 swap +done + +rm -f /tmp/mmap14 /tmp/mmap14.core +exit 0 +EOF +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 2 +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define PARALLEL 50 + +static void *p; +static u_int32_t r[N]; + +static unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +static void * +makeptr(void) +{ + unsigned long val; + + if (p != MAP_FAILED && p != NULL) + val = (unsigned long)p + arc4random(); + else + val = makearg(); + val = trunc_page(val); + + return ((void *)val); +} + +static void * +tmmap(void *arg __unused) +{ + size_t len; + int i, fd; + + pthread_set_name_np(pthread_self(), __func__); + len = 1LL * 1024 * 1024 * 1024; + + for (i = 0; i < 100; i++) { + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1,"open()"); + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, + 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + } + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) != + MAP_FAILED) { + usleep(100); + munmap(p, len); + } + close(fd); + } + + return (NULL); +} + +static void * +tmlock(void *arg __unused) +{ + size_t len; + int i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + len = trunc_page(makearg()); + if (mlock(makeptr(), len) == 0) + n++; + len = trunc_page(makearg()); + if (arc4random() % 100 < 50) + if (munlock(makeptr(), len) == 0) + n++; + } + if (n < 10) + fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", + n); + + return (NULL); +} + +static void +test(void) +{ + pthread_t tid[4]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) + errc(1, rc, "tmlock()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + raise(SIGSEGV); + + for (i = 0; i < 2; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + struct rlimit rl; + rlim_t maxlock; + int i, j; + + if (argc != 2) { + fprintf(stderr, "Usage:%s \n", argv[0]); + exit(1); + } + if (getrlimit(RLIMIT_MEMLOCK, &rl) == -1) + warn("getrlimit"); + maxlock = atol(argv[1]); + if (maxlock == 0) + errx(1, "Argument is zero"); + maxlock = (maxlock / 10 * 8) / PARALLEL * PAGE_SIZE; + if (maxlock < rl.rlim_cur) { + rl.rlim_max = rl.rlim_cur = maxlock; + if (setrlimit(RLIMIT_MEMLOCK, &rl) == -1) + warn("setrlimit"); + } + + for (i = 0; i < N; i++) + r[i] = arc4random(); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap15.sh b/tools/test/stress2/misc/mmap15.sh new file mode 100755 index 000000000000..a34e8436255b --- /dev/null +++ b/tools/test/stress2/misc/mmap15.sh @@ -0,0 +1,223 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Missing wakeup in the bufobj_wwait(). + +# Snapshot of WiP work. +# http://people.freebsd.org/~pho/stress/log/mmap15.txt +# Not fixed + +# panic: invalid size +# http://people.freebsd.org/~pho/stress/log/kostik738.txt +# Fixed in r274878 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap15.c +mycc -o mmap15 -Wall -Wextra -O2 -g mmap15.c -lpthread || exit 1 +rm -f mmap15.c + +for i in `jot 2`; do + su $testuser -c /tmp/mmap15 & +done +sleep 300 +while pgrep -q mmap15; do + pkill -9 mmap15 + sleep 2 +done +wait + +rm -f /tmp/mmap15 /tmp/mmap15.core +exit 0 +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 2 +#define MMSIZE (256 * 1024) +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define PARALLEL 50 + +void *p; +u_int32_t r[N]; + +unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +makeptr(void) +{ + unsigned long val; + + if (p != MAP_FAILED && p != NULL) + val = (unsigned long)p + arc4random(); + else + val = makearg(); + val = trunc_page(val); + + return ((void *)val); +} + +void * +tmmap(void *arg __unused) +{ + size_t len; + int i, j, fd; + + pthread_set_name_np(pthread_self(), __func__); + len = MMSIZE; + + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1,"open()"); + for (i = 0, j = 0; i < 100; i++) { + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + if (p != MAP_FAILED) + j++; + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + if (p != MAP_FAILED) + j++; + } + if (j == 0) + fprintf(stderr, "FAIL: all mmap(2) calls failed.\n"); + close(fd); + + return (NULL); +} + +void * +tmlock(void *arg __unused) +{ + size_t len; + int i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + len = trunc_page(makearg()); + if (mlock(makeptr(), len) == 0) + n++; + len = trunc_page(makearg()); + if (arc4random() % 100 < 50) + if (munlock(makeptr(), len) == 0) + n++; + } + if (n < 10) + fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", + n); + + return (NULL); +} + +void +test(void) +{ + pthread_t tid[2]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) + errc(1, rc, "tmlock()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + raise(SIGSEGV); + + for (i = 0; i < 2; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(void) +{ + int i, j; + + for (i = 0; i < N; i++) + r[i] = arc4random(); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap16.sh b/tools/test/stress2/misc/mmap16.sh new file mode 100755 index 000000000000..15a310505edd --- /dev/null +++ b/tools/test/stress2/misc/mmap16.sh @@ -0,0 +1,145 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 scenario by kib@ + +[ `uname -m` = "i386" ] || exit 0 + +. ../default.cfg + +grep -q MAP_GUARD /usr/include/sys/mman.h 2>/dev/null || exit 0 +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap16.c +mycc -o mmap16 -Wall -Wextra -O2 -g mmap16.c -lpthread || exit 1 +rm -f mmap16.c /tmp/mmap16.core + +echo "Expect: + mmap16: mprotect: Permission denied" +/tmp/mmap16 > /dev/null +s=$? + +rm -f /tmp/mmap16 /tmp/mmap16.core +exit $s +EOF +/* $Id: map_hole.c,v 1.6 2014/06/16 05:52:03 kostik Exp kostik $ */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static void +sighandler(int signo, siginfo_t *info, void *uap1) +{ + static char scratch; + ucontext_t *uap; + + uap = uap1; + printf("SIG%s(%d) at %p (%%eax %p)\n", + signo < sys_nsig ? sys_signame[signo] : "SOME", signo, + info->si_addr, (void *)(uintptr_t)uap->uc_mcontext.mc_eax); + uap->uc_mcontext.mc_eax = (uintptr_t)&scratch; +} + +static void +access_addr(char *addr) +{ + char r; + + r = '1'; + printf("accessing %p\n", addr); + __asm __volatile("movb %0,(%%eax)" : : "i"(r), "a"(addr) : "memory"); + printf("done\n"); +} + +static int pagesz; + +static void +test_access(char *addr) +{ + struct rusage ru; + long majflt, minflt; + + if (getrusage(RUSAGE_THREAD, &ru) == -1) + err(1, "getrusage"); + majflt = ru.ru_majflt; + minflt = ru.ru_minflt; + access_addr(addr); + if (mprotect(addr, pagesz, PROT_READ | PROT_WRITE) == -1) + warn("mprotect"); + access_addr(addr); + if (getrusage(RUSAGE_THREAD, &ru) == -1) + err(1, "getrusage"); + majflt = ru.ru_majflt - majflt; + minflt = ru.ru_minflt - minflt; + printf("majflt %ld minflt %ld\n", majflt, minflt); +} + +int +main(void) +{ + struct sigaction sa; + char *addr; + char cmd[128]; + + bzero(&sa, sizeof(sa)); + sa.sa_sigaction = sighandler; + sa.sa_flags = SA_SIGINFO; + if (sigaction(SIGSEGV, &sa, NULL) == -1) + err(1, "sigaction"); + pagesz = getpagesize(); + + printf("MAP_GUARD\n"); + addr = mmap(NULL, pagesz, PROT_NONE, MAP_GUARD, -1, 0); + if (addr == (char *)MAP_FAILED) + err(1, "FAIL: mmap(MAP_GUARD)"); + test_access(addr); + + printf("PROT_NONE wire\n"); + addr = mmap(NULL, pagesz, PROT_NONE, MAP_ANON, -1, 0); + if (addr == (char *)MAP_FAILED) + err(1, "mmap(PROT_NONE)"); + if (mlock(addr, pagesz) == -1) + if (errno != ENOMEM) + err(1, "mlock"); + test_access(addr); + + snprintf(cmd, sizeof(cmd), "procstat -v %d", getpid()); + system(cmd); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap17.sh b/tools/test/stress2/misc/mmap17.sh new file mode 100755 index 000000000000..bc67bb2e5a9e --- /dev/null +++ b/tools/test/stress2/misc/mmap17.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 scenario by kib@ + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap17.c +mycc -o mmap17 -Wall -Wextra -O2 -g mmap17.c -lpthread || exit 1 +rm -f mmap17.c /tmp/mmap17.core +rm -f /tmp/mmap17.core + +{ /tmp/mmap17 > /dev/null; } 2>&1 | grep -v worked + +rm -f /tmp/mmap17 /tmp/mmap17.core +exit 0 +EOF +/* $Id: map_excl.c,v 1.2 2014/06/16 06:02:52 kostik Exp kostik $ */ + +#include +#include +#include +#include +#include + +#ifndef MAP_EXCL +#define MAP_EXCL 0x00004000 /* for MAP_FIXED, fail if address is used */ +#endif + +int +main(void) +{ + char *addr, *addr1; + int pagesz; + char cmd[128]; + + pagesz = getpagesize(); + addr = mmap(NULL, pagesz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + if (addr == (char *)MAP_FAILED) + err(1, "mmap 1"); + printf("addr %p\n", addr); + + addr -= pagesz; + addr1 = mmap(addr, 3 * pagesz, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_FIXED | MAP_EXCL, -1, 0); + if (addr1 == MAP_FAILED) + warn("EXCL worked"); + else + fprintf(stderr, "EXCL failed\n"); + + addr1 = mmap(addr, 3 * pagesz, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_FIXED, -1, 0); + printf("addr1 %p\n", addr); + + snprintf(cmd, sizeof(cmd), "procstat -v %d", getpid()); + system(cmd); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap18.sh b/tools/test/stress2/misc/mmap18.sh new file mode 100755 index 000000000000..065b5bb7df6c --- /dev/null +++ b/tools/test/stress2/misc/mmap18.sh @@ -0,0 +1,308 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Copy of mmap10.sh with core dump disabled. +# http://people.freebsd.org/~pho/stress/log/kostik711.txt + +# panic: vm_fault_copy_entry: main object missing page +# http://people.freebsd.org/~pho/stress/log/mmap18.txt +# Fixed by: r316689 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap18.c +mycc -o mmap18 -Wall -Wextra -O2 mmap18.c -lpthread || exit 1 +rm -f mmap18.c + +s=0 +wire=$((`sysctl -n vm.max_user_wired` - \ + `sysctl -n vm.stats.vm.v_user_wire_count`)) +/tmp/mmap18 $wire & +start=`date +%s` +while true; do + e=$((`date +%s` - start)) + pgrep -q mmap18 || break + if [ $e -gt 900 ]; then + pgrep mmap18 | xargs ps -lHp + pkill mmap18 + break; + fi + sleep 10 +done +wait $!; s=$? + +rm -f /tmp/mmap18 /tmp/mmap18.core +exit $s +EOF +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 50 +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define PARALLEL 50 + +static u_int32_t r[N]; +static void *p; + +static unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return (val); +} + +static void * +makeptr(void) +{ + unsigned long val; + + if (p != MAP_FAILED && p != NULL) + val = (unsigned long)p + arc4random(); + else + val = makearg(); + val = trunc_page(val); + + return ((void *)val); +} + +static void * +tmmap(void *arg __unused) +{ + size_t len; + int i, fd; + + pthread_set_name_np(pthread_self(), __func__); + len = 1LL * 1024 * 1024 * 1024; + + for (i = 0; i < 100; i++) { + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1,"open()"); + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, + fd, 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + } + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, + -1, 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + } + close(fd); + } + + return (NULL); +} + +static void * +tmlock(void *arg __unused) +{ + int i, n; + size_t len; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + len = trunc_page(makearg()); + if (mlock(makeptr(), len) == 0) + n++; + len = trunc_page(makearg()); + if (arc4random() % 100 < 50) + if (munlock(makeptr(), len) == 0) + n++; + } +#if defined(DEBUG) + if (n < 10) + fprintf(stderr, "Note: tmlock() only succeeded %d " + "times.\n", n); +#endif + + return (NULL); +} + +static void * +tmprotect(void *arg __unused) +{ + void *addr; + size_t len; + int i, n, prot; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + addr = makeptr(); + len = trunc_page(makearg()); + prot = makearg(); + if (mprotect(addr, len, prot) == 0) + n++; + usleep(1000); + } +#if defined(DEBUG) + if (n < 10) + fprintf(stderr, "Note: tmprotect() only succeeded %d " + "times.\n", n); +#endif + + return (NULL); +} + +static void * +tmlockall(void *arg __unused) +{ + int flags, i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + flags = makearg(); + if (mlockall(flags) == 0) + n++; + usleep(100); + munlockall(); + usleep(1000); + } +#if defined(DEBUG) + if (n < 10) + fprintf(stderr, "Note: tmlockall() only succeeded %d " + "times.\n", n); +#endif + + return (NULL); +} + +static void +test(void) +{ + pthread_t tid[4]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) + errc(1, rc, "tmlock()"); + if ((rc = pthread_create(&tid[2], NULL, tmprotect, NULL)) != 0) + errc(1, rc, "tmprotect()"); + if ((rc = pthread_create(&tid[3], NULL, tmlockall, NULL)) != 0) + errc(1, rc, "tmlockall()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + for (i = 0; i < 4; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + struct rlimit rl; + rlim_t maxlock; + int i, j; + + if (argc != 2) { + fprintf(stderr, "Usage:%s \n", argv[0]); + exit(1); + } + rl.rlim_max = rl.rlim_cur = 0; + if (setrlimit(RLIMIT_CORE, &rl) == -1) + warn("setrlimit"); + + if (getrlimit(RLIMIT_MEMLOCK, &rl) == -1) + warn("getrlimit"); + maxlock = atol(argv[1]); + if (maxlock <= 0) + errx(1, "Bad argument %jd", maxlock); + maxlock = (maxlock / 10 * 8) / PARALLEL * PAGE_SIZE; + if (maxlock < rl.rlim_cur) { + rl.rlim_max = rl.rlim_cur = maxlock; + if (setrlimit(RLIMIT_MEMLOCK, &rl) == -1) + warn("setrlimit"); + } + + for (i = 0; i < N; i++) + r[i] = arc4random(); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap19.sh b/tools/test/stress2/misc/mmap19.sh new file mode 100755 index 000000000000..6a646563499a --- /dev/null +++ b/tools/test/stress2/misc/mmap19.sh @@ -0,0 +1,241 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# panic: pmap active 0xfffff801d22cdae8" seen. +# Variation of mmap18.sh. +# http://people.freebsd.org/~pho/stress/log/kostik712.txt +# Fixed by r271000. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap19.c +mycc -o mmap19 -Wall -Wextra -O2 mmap19.c -lpthread || exit 1 +rm -f mmap19.c + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)" +rnd=`od -An -N1 -t u1 /dev/random | sed 's/ //g'` +sleep $((rnd % 10)) +s=0 +for i in `jot 2`; do + /tmp/mmap19 || s=$? +done +while pgrep -q swap; do + pkill -9 swap +done + +rm -f /tmp/mmap19 /tmp/mmap19.core +exit $s +EOF +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 50 +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define PARALLEL 50 + +u_int32_t r[N]; +void *p; + +unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +makeptr(void) +{ + unsigned long val; + + if (p != MAP_FAILED && p != NULL) + val = (unsigned long)p + arc4random(); + else + val = makearg(); + val = trunc_page(val); + + return ((void *)val); +} + +void * +tmmap(void *arg __unused) +{ + size_t len; + int i, fd; + + pthread_set_name_np(pthread_self(), __func__); + len = 1LL * 1024 * 1024 * 1024; + + for (i = 0; i < 100; i++) { + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1,"open()"); + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, + fd, 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + } + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, + 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + } + close(fd); + } + + return (NULL); +} + +void * +tmprotect(void *arg __unused) +{ + void *addr; + size_t len; + int i, n, prot; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + addr = makeptr(); + len = trunc_page(makearg()); + prot = makearg(); + if (mprotect(addr, len, prot) == 0) + n++; + usleep(1000); + } + if (n < 10) + fprintf(stderr, "Note: tmprotect() only succeeded %d times.\n", + n); + + return (NULL); +} + +void +test(void) +{ + pthread_t tid[2]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmprotect, NULL)) != 0) + errc(1, rc, "tmprotect()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + alarm(120); + for (i = 0; i < 2; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + time_t start; + struct rlimit rl; + int e, i, j, status; + + rl.rlim_max = rl.rlim_cur = 0; + if (setrlimit(RLIMIT_CORE, &rl) == -1) + warn("setrlimit"); + + for (i = 0; i < N; i++) + r[i] = arc4random(); + + e = 0; + start = time(NULL); + for (i = 0; i < LOOPS && e == 0; i++) { + for (j = 0; j < PARALLEL; j++) { + if ((pids[j] = fork()) == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) { + if (waitpid(pids[j], &status, 0) != pids[j]) + err(1, "waitpid(%d)", pids[j]); + if (status != 0 && e == 0 && status != SIGSEGV && status != EFAULT) + e = status; + } + if (time(NULL) - start > 1200) { + fprintf(stderr, "Timed out."); + break; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/mmap2.sh b/tools/test/stress2/misc/mmap2.sh new file mode 100755 index 000000000000..1595f7afacce --- /dev/null +++ b/tools/test/stress2/misc/mmap2.sh @@ -0,0 +1,177 @@ +#!/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. +# + +# Stress mmap by having at most 100 threads mapping random areas within +# a 100 Mb range. + +# Test scenario by kib@ + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mmap2.c +mycc -o mmap2 -Wall -g mmap2.c -lpthread +rm -f mmap2.c + +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 600 ]; 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, %zd, %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) + errc(1, r, "pthread_create()"); + } + + for (i = 0; i < n; i++) { + if ((r = pthread_join(threads[i], NULL)) != 0) + errc(1, r, "pthread_join(%d)", i); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap20.sh b/tools/test/stress2/misc/mmap20.sh new file mode 100755 index 000000000000..da1a55e4b2b0 --- /dev/null +++ b/tools/test/stress2/misc/mmap20.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# "panic: pmap_unwire: pte 0x672d405 is missing PG_W" seen. +# http://people.freebsd.org/~pho/stress/log/mmap20.txt + +# Test scenario by: Mark Johnston markj@ + +# Fixed by r272036 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap20.c +mycc -o mmap20 -O2 -Wall -Wextra mmap20.c || exit 1 +rm -f mmap20.c +cd $odir + +/tmp/mmap20 +s=$? + +rm -f /tmp/mmap20 +exit $s + +EOF +#include +#include + +#include +#include + +int +main(void) +{ + char *ptr; + size_t sz; + + sz = 4096; + ptr = mmap(NULL, sz, PROT_READ, MAP_ANON, -1, 0); + if (ptr == NULL) + err(1, "mmap"); + + if (mlock(ptr, sz) != 0) + err(1, "mlock"); + + if (mprotect(ptr, sz, PROT_EXEC) != 0) + err(1, "mprotect"); + + if (madvise(ptr, sz, MADV_WILLNEED) != 0) + err(1, "madvise"); + + if (munlock(ptr, sz) != 0) + err(1, "munlock"); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap21.sh b/tools/test/stress2/misc/mmap21.sh new file mode 100755 index 000000000000..4b5079160fce --- /dev/null +++ b/tools/test/stress2/misc/mmap21.sh @@ -0,0 +1,165 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# panic: vm_reserv_populate: reserv 0xfffff807cbd3c400 is already promoted +# http://people.freebsd.org/~pho/stress/log/mmap21.txt +# Fixed by r280238 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap21.c +mycc -o mmap21 -Wall -Wextra -O2 -g mmap21.c -lpthread || exit 1 +rm -f mmap21.c + +su $testuser -c /tmp/mmap21 + +rm -f /tmp/mmap21 /tmp/mmap21.core +exit 0 +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 1 +#define NMAPS 50 +#define PARALLEL 2 + +void *p; + +static void * +tmmap(void *arg __unused) +{ + size_t len; + int i; + + pthread_set_name_np(pthread_self(), __func__); + len = 1LL * 128 * 1024 * 1024; + + for (i = 0; i < NMAPS; i++) + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + + return (NULL); +} + +static void * +tmlock(void *arg __unused) +{ + size_t len; + int i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + len = trunc_page(arc4random()); + if (mlock(p, len) == 0) + n++; + len = trunc_page(arc4random()); + if (arc4random() % 100 < 50) + if (munlock(p, len) == 0) + n++; + } + if (n < 10) + fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", + n); + + return (NULL); +} + +static void +test(void) +{ + pid_t pid; + pthread_t tid[2]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) + errc(1, rc, "tmlock()"); + + for (i = 0; i < 100; i++) { + if ((pid = fork()) == 0) { + usleep(10000); + _exit(0); + } + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid(%d)", pid); + } + + raise(SIGSEGV); + + for (i = 0; i < 2; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(void) +{ + + pid_t pids[PARALLEL]; + time_t start; + int e, i, j, status; + + start = time(NULL); + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if ((pids[j] = fork()) == 0) + test(); + } + + e = 0; + for (j = 0; j < PARALLEL; j++) { + if (waitpid(pids[j], &status, 0) == -1) + err(1, "waitpid(%d)", pids[j]); + e += status == 0 ? 0 : 1; + } + if (time(NULL) - start > 1200) { + fprintf(stderr, "Timed out."); + break; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/mmap22.sh b/tools/test/stress2/misc/mmap22.sh new file mode 100755 index 000000000000..4b730100d7dc --- /dev/null +++ b/tools/test/stress2/misc/mmap22.sh @@ -0,0 +1,130 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Core dump wedge +# Trimmed down version of mmap15.sh +# http://people.freebsd.org/~pho/stress/log/mmap15-2.txt +# Fixed in r272534 + r272535. + +# Page fault seen: http://people.freebsd.org/~pho/stress/log/kostik733.txt +# Fixed in r274474. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap22.c +mycc -o mmap22 -Wall -Wextra -O2 -g mmap22.c -lpthread || exit 1 +rm -f mmap22.c + +su $testuser -c /tmp/mmap22 & + +sleep 300 +while pgrep -q mmap22; do + pkill -9 mmap22 + sleep 2 +done +wait + +rm -f /tmp/mmap22 /tmp/mmap22.core +exit 0 +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MMAPS 25 +#define PARALLEL 4 +#define SIZ (64 * 1024 * 1024) + +void * +tmmap(void *arg __unused) +{ + size_t len; + void *p; + int i; + + len = SIZ; + for (i = 0; i < MMAPS; i++) + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + fsync(fileno(stdout)); + + return (NULL); +} + +void +test(void) +{ + pthread_t tid; + int i, rc; + + if ((rc = pthread_create(&tid, NULL, tmmap, NULL)) != 0) + errc(1, rc, "test()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + raise(SIGSEGV); + + if ((rc = pthread_join(tid, NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + test(); + } + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap23.sh b/tools/test/stress2/misc/mmap23.sh new file mode 100755 index 000000000000..6a4a04eecab1 --- /dev/null +++ b/tools/test/stress2/misc/mmap23.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# "panic: vm_object_unwire: missing page" seen. +# https://people.freebsd.org/~pho/stress/log/mmap23.txt +# Test scenario by kib@. +# Fixed by r285878. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap23.c +mycc -o mmap23 -Wall -Wextra mmap23.c || exit 1 +rm -f mmap23.c +cd $odir + +cp /tmp/mmap23 /tmp/mmap23.inputfile +daemon sh -c '(cd ../testcases/swap; ./swap -t 1m -i 2)' > \ + /dev/null 2>&1 + +/tmp/mmap23 /tmp/mmap23.inputfile & +sleep .2 +dd if=/dev/zero of=/tmp/mmap23.inputfile bs=1k count=1 status=none + +while pgrep -q swap; do + pkill -9 swap +done + +rm -f /tmp/mmap23 /tmp/mmap23.inputfile +exit + +EOF +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +const char *file; + +void +test(void) +{ + struct stat st; + char *p; + size_t len; + int error, fd; + + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open %s", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = round_page(st.st_size); + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) + err(1, "mmap"); + p[arc4random() % len] = 1; + if ((error = mlock(p, len)) == -1) + err(1, "mlock"); + sleep(2); + if (munmap(p, len) == -1) + err(1, "unmap()"); + close(fd); +} + +int +main(int argc, char *argv[]) +{ + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + test(); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap24.sh b/tools/test/stress2/misc/mmap24.sh new file mode 100755 index 000000000000..4a25a0e3520f --- /dev/null +++ b/tools/test/stress2/misc/mmap24.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# "panic: vm_page_unwire: page 0xc36cafbc's wire count is zero" seen. +# https://people.freebsd.org/~pho/stress/log/mmap24.txt +# Test scenario by trasz@. +# Fixed by r285878. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap24.c +mycc -o mmap24 -Wall -Wextra mmap24.c || exit 1 +rm -f mmap24.c +cd $odir + +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +cp /tmp/mmap24 $mntpoint +(cd $mntpoint; ./mmap24) & +sleep .2 +umount -f $mntpoint + +kill $! +wait + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart + +rm -f /tmp/mmap24 +exit + +EOF +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +int +main(void) +{ + int error; + + error = mlockall(MCL_CURRENT | MCL_FUTURE); + if (error != 0) + err(1, "mlockall"); + + for (;;) { + sleep(1); + } +} diff --git a/tools/test/stress2/misc/mmap25.sh b/tools/test/stress2/misc/mmap25.sh new file mode 100755 index 000000000000..caad84d9b549 --- /dev/null +++ b/tools/test/stress2/misc/mmap25.sh @@ -0,0 +1,120 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# "panic: vm_page_unwire: page 0xc36cce48's wire count is zero" seen. +# Fixed by r285878. + +# Test scenario by kib@: +# 1. We mapped and mlocked the file. +# 2. The file is truncated +# 3. The file is extended again to cover the whole mapped area. +# 4. The program accesses the mapping past the point of truncation. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap25.c +mycc -o mmap25 -Wall -Wextra mmap25.c || exit 1 +rm -f mmap25.c +cd $odir + +cp /tmp/mmap25 /tmp/mmap25.inputfile +daemon sh -c '(cd ../testcases/swap; ./swap -t 1m -i 2)' > \ + /dev/null 2>&1 +sleep 1 + +/tmp/mmap25 /tmp/mmap25.inputfile + +while pgrep -q swap; do + pkill -9 swap +done +rm -f /tmp/mmap25 /tmp/mmap25.inputfile mmap25.core +exit + +EOF +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +const char *file; +volatile char c; + +void +test(void) +{ + struct stat st; + char *p; + size_t len; + off_t pos; + int error, fd; + + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open %s", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = round_page(st.st_size); + pos = len - getpagesize(); + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) + == MAP_FAILED) + err(1, "mmap"); + if ((error = mlock(p, len)) == -1) + err(1, "mlock"); + + if (ftruncate(fd, pos) == -1) + err(1, "ftruncate 1"); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate 2"); + + c = p[pos]; /* Program received signal SIGSEGV, Segmentation fault. */ + + if (munmap(p, len) == -1) + err(1, "unmap()"); + close(fd); +} + +int +main(int argc, char *argv[]) +{ + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + test(); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap26.sh b/tools/test/stress2/misc/mmap26.sh new file mode 100755 index 000000000000..19479b92461f --- /dev/null +++ b/tools/test/stress2/misc/mmap26.sh @@ -0,0 +1,123 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# "panic: vm_page_unwire: page 0xc36cce48's wire count is zero" seen. +# https://people.freebsd.org/~pho/stress/log/kostik820.txt +# Fixed by r285878. + +# Variation of mmap25.sh: +# Access one byte past the end of the file, which is not wrong, but +# out of specified behaviour. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap26.c +mycc -o mmap26 -Wall -Wextra mmap26.c || exit 1 +rm -f mmap26.c +cd $odir + +cp /tmp/mmap26 /tmp/mmap26.inputfile +daemon sh -c '(cd ../testcases/swap; ./swap -t 1m -i 2)' > \ + /dev/null 2>&1 +sleep 1 + +(cd /tmp; /tmp/mmap26 /tmp/mmap26.inputfile) + +while pkill -9 swap; do :; done +rm -f /tmp/mmap26 /tmp/mmap26.inputfile /tmp/mmap26.core +exit 0 + +EOF +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +const char *file; +volatile char c; + +void +test(void) +{ + struct stat st; + char *p; + size_t len; + int error, fd; + + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open %s", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = round_page(st.st_size); + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) + == MAP_FAILED) + err(1, "mmap"); + if ((error = mlock(p, len)) == -1) + err(1, "mlock"); + + if (ftruncate(fd, (off_t)0) == -1) + err(1, "ftruncate 1"); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate 2"); + + p[len - 1] = 1; + + /* one byte past EOF */ + if (round_page((unsigned long)&p[len]) == + round_page((unsigned long)&p[len - 1])) { + fprintf(stderr, "Expect: Segmentation fault (core dumped)\n"); + c = p[len]; + } + + if (munmap(p, len) == -1) + err(1, "unmap()"); + close(fd); +} + +int +main(int argc, char *argv[]) +{ + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + test(); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap27.sh b/tools/test/stress2/misc/mmap27.sh new file mode 100755 index 000000000000..7f8d4e94583a --- /dev/null +++ b/tools/test/stress2/misc/mmap27.sh @@ -0,0 +1,126 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# 'WARNING: A device driver has set "memattr" inconsistently.' seen on +# console. +# https://people.freebsd.org/~pho/stress/log/mmap27.txt +# Fixed by r298891. + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mmap27.c +mycc -o mmap27 -Wall -Wextra -g -O0 mmap27.c || exit 1 +rm -f mmap27.c +cd $odir + +daemon sh -c '(cd ../testcases/swap; ./swap -t 2m -i 20 -l 100)' > /dev/null 2>&1 +sleep 2 +/tmp/mmap27 +while pgrep -q swap; do + pkill -9 swap +done +rm -f ./mmap27 /tmp/mmap27.0* /tmp/mmap27 +exit 0 + +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +int fd; + +#define ADRSPACE (256 * 1024 * 1024 ) +#define PARALLEL 64 +#define RUNTIME 120 +#define STARTADDR 0x50000000U + +static void +work(void) +{ + size_t left, len; + int i; + char *p; + volatile char val; + + if ((fd = open("/dev/mem", O_RDWR)) == -1) + err(1,"open()"); + + p = (void *)STARTADDR + trunc_page(arc4random() % ADRSPACE); + left = ADRSPACE - (size_t)p + STARTADDR; + len = trunc_page(arc4random() % left) + PAGE_SIZE; + + if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) { + if (errno == ENOMEM) + return; + err(1, "mmap()"); + } + + for (i = 0; i < 100; i++) + val = p[arc4random() % len]; + + if (munmap(p, len) == -1) + err(1, "munmap(%p)", p); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + time_t start; + int i, n; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + n = arc4random() % PARALLEL + 1; + for (i = 0; i < n; i++) { + if ((pids[i] = fork()) == 0) + work(); + } + + for (i = 0; i < n; i++) + if (waitpid(pids[i], NULL, 0) != pids[i]) + err(1, "waitpid(%d)", pids[i]); + } + close(fd); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap28.sh b/tools/test/stress2/misc/mmap28.sh new file mode 100755 index 000000000000..fd64202e3814 --- /dev/null +++ b/tools/test/stress2/misc/mmap28.sh @@ -0,0 +1,131 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# 'panic: vnode_pager_generic_getpages: page 0xc3350b0c offset beyond vp +# 0xcc187000 size' seen. +# https://people.freebsd.org/~pho/stress/log/mmap28.txt +# This was introduced by r292373. +# +# A page fault is seen on a non INVARIANTS kernel w/ r292373, +# whereas this test runs as expected on r292372. +# https://people.freebsd.org/~pho/stress/log/mmap28-2.txt +# https://people.freebsd.org/~pho/stress/log/mmap28-3.txt +# To repeat, run this test with "sysctl vfs.ffs.use_buf_pager=0". +# Fixed by r307626 + +# Test scenario refinement by kib@ + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mmap28.c +mycc -o mmap28 -Wall -Wextra -g -O0 mmap28.c || exit 1 +rm -f mmap28.c +cd $odir + +(cd /tmp; ./mmap28) + +rm -f /tmp/mmap28 /tmp/mmap28.0* /tmp/mmap28.core +exit 0 + +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define ADRSPACE (256 * 1024 * 1024 ) +#define STARTADDR 0x50000000U + +static void +work(void) +{ + size_t indx, left, len; + int fd, rfd; + int i; + char *p; + char path[128]; + volatile char val; + + if ((rfd = open("/dev/random", O_RDONLY)) == -1) + err(1, "open(/dev/random)"); + + snprintf(path, sizeof(path), "/tmp/mmap28.%06d", 0); + if ((fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) + err(1,"open(%s)", path); + + p = (void *)STARTADDR + trunc_page(arc4random() % ADRSPACE); + left = ADRSPACE - (size_t)p + STARTADDR; + len = trunc_page(arc4random() % left) + PAGE_SIZE; + + 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()"); + } + + /* + Truncating the mapped file triggers a panic when accessed beyond + EOF. + */ + if (ftruncate(fd, len / 2) == -1) + err(1, "ftruncate(%s)", path); + + for (i = 0; i < 1000; i++) { + if (read(rfd, &indx, sizeof(indx)) != sizeof(indx)) + err(1, "read(random)"); + val = p[indx % len]; + } + close(rfd); + + if (munmap(p, len) == -1) + err(1, "munmap(%p)", p); + close(fd); + unlink(path); +} + +int +main(void) +{ + + work(); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap29.sh b/tools/test/stress2/misc/mmap29.sh new file mode 100755 index 000000000000..e6aacc15e48e --- /dev/null +++ b/tools/test/stress2/misc/mmap29.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# Test scenario by: David Cross + +# "panic: softdep_deallocate_dependencies: dangling deps" seen. +# https://people.freebsd.org/~pho/stress/log/mmap29.txt +# Fixed by: r302567. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -z "`which timeout`" ] && exit 0 +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs -U md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +mkdir $mntpoint/mmap29 +cd /tmp +cat > mmap29.c < +#include +#include + +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + int fd; + unsigned char *memrange; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + unlink(argv[1]); + if ((fd = open(argv[1], O_RDWR | O_CREAT, DEFFILEMODE)) == -1) + err(1, "open(%s)", argv[1]); + lseek(fd, 0xbfff, SEEK_SET); + write(fd, "\0", 1); + if ((memrange = mmap(0, 0x2b6000, PROT_READ | PROT_WRITE, MAP_SHARED | + MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0)) == MAP_FAILED) + err(1, "mmap"); + memrange[0] = 5; + munmap(memrange, 0x2b6000); + close(fd); + + return (0); +} +EOFHERE + +cc -o mmap29 -Wall -Wextra -O0 -g mmap29.c || exit 1 +rm mmap29.c +./mmap29 $mntpoint/mmap29/mmap291 +old=`sysctl -n kern.maxvnodes` +trap "sysctl kern.maxvnodes=$old" EXIT INT +sysctl kern.maxvnodes=2000 +timeout 60 find / -xdev -print >/dev/null +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm mmap29 +exit 0 diff --git a/tools/test/stress2/misc/mmap3.sh b/tools/test/stress2/misc/mmap3.sh new file mode 100755 index 000000000000..bc5905dd920e --- /dev/null +++ b/tools/test/stress2/misc/mmap3.sh @@ -0,0 +1,167 @@ +#!/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. +# + +# Variation of mmap2.sh with focus on random arguments for mprotect() +# https://people.freebsd.org/~pho/stress/log/kostik209.txt + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mmap3.c +mycc -o mmap3 -Wall mmap3.c -lpthread || exit 1 +rm -f mmap3.c + +start=`date '+%s'` +while [ `date '+%s'` -lt $((start + 5 * 60)) ]; do + ./mmap3 +done +echo "Expect Segmentation faults" +start=`date '+%s'` +while [ `date '+%s'` -lt $((start + 5 * 60)) ]; do + ./mmap3 random +done +rm -f mmap3 mmap3.core /tmp/mmap.0* +exit + +EOF +/* + Stress mmap by having max 100 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) +{ + unsigned long v; + + mprotect(p, 0x570e3d38, 0x2c8fd54f); + if (ra) { + v = arc4random(); +#if defined(__LP64__) + v = v << 32 | arc4random(); +#endif + madvise((void *)v, arc4random(), arc4random()); + mprotect((void *)v, arc4random(), arc4random()); + msync((void *)v, 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, %zd, %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) + errc(1, r, "pthread_create()"); + } + + for (i = 0; i < n; i++) { + if ((r = pthread_join(threads[i], NULL)) != 0) + errc(1, r, "pthread_join(%d)", i); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap30.sh b/tools/test/stress2/misc/mmap30.sh new file mode 100755 index 000000000000..3f1b8cccbc54 --- /dev/null +++ b/tools/test/stress2/misc/mmap30.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# r320344: allow mprotect(2) over the guards to succeed regardless of +# the requested protection. + +. ../default.cfg + +grep -q MAP_GUARD /usr/include/sys/mman.h 2>/dev/null || exit 0 +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap30.c +mycc -o mmap30 -Wall -Wextra -O2 -g mmap30.c || exit 1 +rm -f mmap30.c /tmp/mmap30.core + +/tmp/mmap30 > /dev/null +s=$? + +rm -f /tmp/mmap30 /tmp/mmap30.core +exit $s +EOF +#include +#include + +#include +#include +#include +#include +#include + +int +main(void) +{ + int pagesz; + void *addr; + + pagesz = getpagesize(); + addr = mmap(NULL, pagesz, PROT_NONE, MAP_GUARD, -1, 0); + if (addr == (char *)MAP_FAILED) + err(1, "FAIL: mmap(MAP_GUARD)"); + + if (mprotect(addr, pagesz, PROT_READ | PROT_WRITE) == -1) + err(1, "mprotect(RW)"); + + if (mprotect(addr, pagesz, PROT_NONE) == -1) + err(1, "mprotect(RW)"); + + if (munmap(addr, pagesz) == -1) + err(1, "munmap"); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap31.sh b/tools/test/stress2/misc/mmap31.sh new file mode 100755 index 000000000000..8dd239579fb2 --- /dev/null +++ b/tools/test/stress2/misc/mmap31.sh @@ -0,0 +1,174 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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 scenario for 2MB page promotions. +# No problems seen. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`uname -p`" = "amd64" ] || exit 0 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap31.c +mycc -o mmap31 -Wall -Wextra -O0 -g mmap31.c || exit 1 +rm -f mmap31.c +cd $odir + +(cd ../testcases/swap; ./swap -t 10m -i 20) > /dev/null & + +/tmp/mmap31 +s=$? +kill $! 2>/dev/null +while pkill -9 swap; do :; done +wait + +rm -rf /tmp/mmap31 +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define SEGS 512 +static size_t l[SEGS]; +static char *c[SEGS]; +static volatile char r; +static volatile u_int *share; + +#define PARALLEL 8 +#define RUNTIME (2 * 60) +#define SYNC 0 + +static void +handler(int s __unused) +{ + _exit(0); +} + +static void +touch(void) +{ + time_t t; + int idx; + char *c1; + + t = time(NULL); + while (time(NULL) - t < 5) { + idx = arc4random() % SEGS; + c1 = c[idx]; + idx = arc4random() % l[idx]; + r += c1[idx]; + c1[idx] += 1; + } +} + +static void +test(void) +{ + pid_t pid; + int i, mode, status; + + r = 0; + for (i = 0; i < SEGS; i++) { + l[i] = (arc4random() % 512 + 1) * PAGE_SIZE; + mode = PROT_READ | PROT_WRITE; + if ((c[i] = (char *)mmap(NULL, l[i], mode, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + } + + if ((pid = fork()) == 0) { + signal(SIGHUP, handler); + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + touch(); + pause(); + _exit(0); + } + + while (share[SYNC] != PARALLEL) + ; + touch(); + + kill(pid, SIGHUP); + if (waitpid(pid, &status, 0) != pid) + err(1, "waitpid"); + if (status != 0) + errx(1, "child status = %d", status); + + _exit(status); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/mmap32.sh b/tools/test/stress2/misc/mmap32.sh new file mode 100755 index 000000000000..a775b756084e --- /dev/null +++ b/tools/test/stress2/misc/mmap32.sh @@ -0,0 +1,202 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Bug 223732 - mmap(2) causes unkillable denial of service with specific +# flags +# Test scenario inspired by: Arto Pekkanen + +# Fixed by r326098. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap32.c +mycc -o mmap32 -Wall -Wextra -O0 -g mmap32.c || exit 1 +rm -f mmap32.c + +$dir/mmap32 +s=$? +[ -f mmap32.core -a $s -eq 0 ] && + { ls -l mmap32.core; mv mmap32.core /tmp; s=1; } + +rm -rf $dir/mmap32 +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define N 4096 +static uint32_t r[N]; + +static unsigned long +makearg(void) +{ + unsigned int i; + unsigned long val; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +static void +fuzz(int arg, void *addr, size_t len, int prot, int flags, int fd, + off_t offset) +{ + time_t start; + void *vp; + int n; + + setproctitle("arg%d", arg); + n = 0; + start = time(NULL); + while (time(NULL) - start < 10) { + switch (arg) { + case 1: + addr = (void *)makearg(); + break; + case 2: + len = makearg(); + break; + case 3: + prot = makearg(); + break; + case 4: + flags = makearg(); + break; + case 5: + fd = makearg(); + break; + case 6: + offset = makearg() & 0xffff; + break; + case 34: + prot = makearg(); + flags = makearg(); + break; + default: + errx(1, "Bad argument %d to %s", arg, __func__); + } + vp = mmap(addr, len, prot, flags, fd, offset); + if (vp != MAP_FAILED) { + munmap(vp, len); + n++; + } + } +#if defined(DEBUG) + if (n == 0 && arg != 5) + fprintf(stderr, "%s(%d) failed\n", __func__, arg); +#endif + exit(0); +} + +int +main(void) +{ + off_t offset; + pid_t pid; + size_t len; + struct rlimit rl; + time_t start; + void *addr, *vp; + int e, flags, fd, i, prot, status; + + e = 0; + + rl.rlim_max = rl.rlim_cur = 0; + if (setrlimit(RLIMIT_CORE, &rl) == -1) + warn("setrlimit"); + addr = 0; + len = PAGE_SIZE; + prot = PROT_READ | PROT_WRITE; + flags = MAP_ANON | MAP_SHARED; + fd = -1; + offset = 0; + vp = mmap(addr, len, prot, flags, fd, offset); + if (vp == MAP_FAILED) + err(1, "initail mmap"); + munmap(vp, len); + + start = time(NULL); + while (time(NULL) - start < 120) { + for (i = 0; i < N; i++) + r[i] = arc4random(); + for (i = 0; i < 6; i++) { + if ((pid = fork()) == 0) + fuzz(i + 1, addr, len, prot, flags, fd, + offset); + if (waitpid(pid, &status, 0) != pid) + err(1, "waitpid %d", pid); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pid, WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + if ((pid = fork()) == 0) + fuzz(34, addr, len, prot, flags, fd, offset); + if (waitpid(pid, &status, 0) != pid) + err(1, "waitpid %d", pid); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pid, WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/mmap33.sh b/tools/test/stress2/misc/mmap33.sh new file mode 100755 index 000000000000..70ac054a9934 --- /dev/null +++ b/tools/test/stress2/misc/mmap33.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# +# ftruncate+mmap+fsync fails for small maps +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225586 + +# Original test scenario by tris_vern@hotmail.com + +# Fixed in r328773: +# On pageout, in vnode generic pager, for partially dirty page, only +# clear dirty bits for completely invalid blocks. + +. ../default.cfg + +cat > /tmp/mmap33.c < + +#include +#include +#include +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + size_t i, size1, size2; + int fd; + char *data; + char *filename; + char pattern = 0x01; + + if (argc != 4) { + fprintf(stderr, "Usage: %s filename size1 size2\n", argv[0]); + exit(1); + } + + filename = argv[1]; + size1 = atoi(argv[2]); + size2 = atoi(argv[3]); + + fd = open(filename, O_RDWR | O_TRUNC | O_CREAT, 0644); + for (i = 0; i < size1; i++) + write(fd, &pattern, 1); + close(fd); + + fd = open(filename, O_RDWR, 0644); + if (fd == -1) + err(1, "open(%s)", filename); + if (ftruncate(fd, size2) == -1) + err(1, "ftruncate()"); + data = mmap(NULL, size2, PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0); + if (data == MAP_FAILED) + err(1, "mmap()"); + memset(data, 0xFF, size2); + + if (munmap(data, size2) == -1) + err(1, "munmap"); + close(fd); + + return (0); +} +EOF +cc -o /tmp/mmap33 -Wall -Wextra -O2 -g /tmp/mmap33.c || exit 1 +rm /tmp/mmap33.c + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags -n md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +set +e + +file=file +odir=`pwd` +cd $mntpoint +/tmp/mmap33 $file 1024 511 +s=$? +sum1=`md5 < $mntpoint/$file` +[ -f mmap33.core -a $s -eq 0 ] && + { ls -l mmap33.core; mv mmap33.core /tmp; s=1; } +cd $odir +umount $mntpoint +mount /dev/md${mdstart}$part $mntpoint +# This fails for truncate size < 512 +sum2=`md5 < $mntpoint/$file` +[ $sum1 = $sum2 ] || + { s=2; echo "md5 fingerprint differs."; } +umount $mntpoint + +mdconfig -d -u $mdstart +rm /tmp/mmap33 +exit $s diff --git a/tools/test/stress2/misc/mmap34.sh b/tools/test/stress2/misc/mmap34.sh new file mode 100755 index 000000000000..028d23b4f71f --- /dev/null +++ b/tools/test/stress2/misc/mmap34.sh @@ -0,0 +1,230 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# "panic: caller failed to provide space -546873344 at address 0x20a00000" +# seen. +# https://people.freebsd.org/~pho/stress/log/indir_trunc.txt +# Fixed by r348968 + +# Test scenario inspired by: +# syzbot+6532e9aab8911f58beeb@syzkaller.appspotmail.com + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap34.c +mycc -o mmap34 -Wall -Wextra -O0 -g mmap34.c -lpthread || exit 1 +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 4g -u $mdstart +newfs $newfs_flags -n md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +(cd ../testcases/swap; ./swap -t 5m -i 20) & +cd $mntpoint +$dir/mmap34 +s=$? +while pkill swap; do :; done +wait +[ -f mmap34.core ] && + { ls -l mmap34.core; mv mmap34.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -f $dir/mmap34 +[ $s -eq 0 ] && rm -f mmap34.c +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#if defined(__LP64__) +#define MASK 0x7ffffffffffffULL +#else +#define MASK 0xffffffffULL +#endif +#define PARALLEL 64 +#define RUNTIME (5 * 60) +#define SYNC 0 + +static int fd; + +static void * +t1(void *data __unused) +{ + off_t offset; + time_t start; + + start = time(NULL); + while (time(NULL) - start < 30) { + offset = arc4random(); + offset = (offset << 32) | arc4random(); + offset &= MASK; + if (lseek(fd, offset, SEEK_SET) == -1) + err(1, "lseek(%jd)", offset); + if (write(fd, "a", 1) != 1) + err(1, "write"); + if (fsync(fd) == -1) + err(1, "fsync"); + usleep(100); + } + return (NULL); +} +static void * +t2(void *data __unused) +{ + off_t offset, old; + time_t start; + void *p; + char *c; + + old = 0; + start = time(NULL); + while (time(NULL) - start < 30) { + if (old != 0) + munmap(p, old); + offset = arc4random(); + offset = (offset << 32) | arc4random(); + offset &= MASK; + if (ftruncate(fd, offset) == -1) + err(1, "ftruncate(%jd)", offset); + write(fd, "b", 1); + p = mmap(NULL, offset, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, 0); + if (p == MAP_FAILED) + old = 0; + else { + old = offset; + c = p; + c[offset / 2] = 1; + if (offset > 0) + c[offset - 1] = 2; + } + usleep(20000); + } + return (NULL); +} + +static void +test(void) +{ + pthread_t tid[2]; + int r; + char file[80]; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + snprintf(file, sizeof(file), "file.%d", getpid()); + if ((fd = open(file, O_RDWR | O_CREAT, DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + + if ((r = pthread_create(&tid[0], NULL, t1, NULL)) != 0) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&tid[1], NULL, t2, NULL)) != 0) + errc(1, r, "pthread_create"); + + if ((r = pthread_join(tid[0], NULL)) != 0) + errc(1, r, "pthread_join"); + if ((r = pthread_join(tid[1], NULL)) != 0) + errc(1, r, "pthread_join"); + close(fd); + unlink(file); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/mmap35.sh b/tools/test/stress2/misc/mmap35.sh new file mode 100755 index 000000000000..6e76434e77ec --- /dev/null +++ b/tools/test/stress2/misc/mmap35.sh @@ -0,0 +1,112 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# mmap(2) should fail with "Invalid argument" on i386 +# Fixed by r348843 + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`uname -p`" = "i386" ] || exit 0 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap35.c +mycc -o mmap35 -Wall -Wextra -O0 -g mmap35.c || exit 1 +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 4g -u $mdstart +newfs $newfs_flags -n md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +cd $mntpoint +echo "Expect: mmap35: mmap: Cannot allocate memory" +$dir/mmap35 +s=$? +[ -f mmap35.core ] && + { ls -l mmap35.core; mv mmap35.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -f $dir/mmap35 +[ $s -eq 0 ] && rm -f mmap35.c +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define SIZ 0xfffff0fcULL + +int +main(void) +{ + off_t offset; + int fd; + char *c, file[80]; + + snprintf(file, sizeof(file), "file.%d", getpid()); + if ((fd = open(file, O_RDWR | O_CREAT, DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + + offset = SIZ; + if (ftruncate(fd, offset) == -1) + err(1, "ftruncate(%jd)", offset); + write(fd, "b", 1); + + c = mmap(NULL, offset, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, 0); + if (c == MAP_FAILED) + warn("mmap"); + else + c[offset / 2] = 1; + + unlink(file); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap36.sh b/tools/test/stress2/misc/mmap36.sh new file mode 100755 index 000000000000..2c38fd26890b --- /dev/null +++ b/tools/test/stress2/misc/mmap36.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# mmap(2) should fail with "Invalid argument" and not core dump +# Fixed by + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap36.c +mycc -o mmap36 -Wall -Wextra -O0 -g mmap36.c || exit 1 + +echo "Expect: mmap36: mmap: Cannot allocate memory" +$dir/mmap36 +s=$? +[ -f mmap36.core ] && + { ls -l mmap36.core; mv mmap36.core $dir; s=1; } +cd $odir +[ $s -eq 0 ] && rm -f mmap36.c mmap36 +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +int +main(void) +{ + off_t offset; + char *c; + + offset = SIZE_MAX - 5; + + c = mmap(NULL, offset, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, + -1, 0); + if (c == MAP_FAILED) + warn("mmap"); + else + c[offset / 2] = 1; + + return (0); +} diff --git a/tools/test/stress2/misc/mmap37.sh b/tools/test/stress2/misc/mmap37.sh new file mode 100755 index 000000000000..f5e25a282927 --- /dev/null +++ b/tools/test/stress2/misc/mmap37.sh @@ -0,0 +1,153 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Regression test for https://reviews.freebsd.org/D20800 +# "Use a consistent snapshot of the fd's rights in fget_mmap()" +# https://people.freebsd.org/~pho/stress/log/mmap37.txt + +# Reported by syzbot+ae359438769fda1840f8@syzkaller.appspotmail.com +# Test scenario suggestion by markj@ +# Fixed by r349547 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > mmap37.c +mycc -o mmap37 -Wall -Wextra -O0 mmap37.c -lpthread || exit 1 +rm -f mmap37.c + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +cd $mntpoint +/tmp/mmap37 +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -f /tmp/mmap37 +exit + +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define THREADS 2 +#define SIZ 0x06400000U /* 100 Mb */ + +static volatile int go; +static char path[128]; + +void * +thr(void *arg) +{ + size_t len; + void *p; + int fd; + + fd = 0; + len = SIZ; + if (*(int *)arg == 0) { + while (go == 1) { + if ((fd = open(path, 2)) == -1) + err(1,"open()"); + p = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + munmap(p, len); + close(fd); + usleep(10); + } + } else { + while (go == 1) { + close(fd); + usleep(10); + } + } + + return (0); +} + +int +main(void) +{ + pthread_t threads[THREADS]; + size_t len; + int nr[THREADS]; + int i, fd, r; + + sprintf(path, "mmap37.%06d", getpid()); + if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) + err(1,"open()"); + len = SIZ; + if (ftruncate(fd, len) == -1) + err(1, "ftruncate"); + close(fd); + + go = 1; + for (i = 0; i < THREADS; i++) { + nr[i] = i; + if ((r = pthread_create(&threads[i], NULL, thr, + (void *)&nr[i])) != 0) + errc(1, r, "pthread_create()"); + } + + sleep(30); + go = 0; + + for (i = 0; i < THREADS; i++) { + if ((r = pthread_join(threads[i], NULL)) != 0) + errc(1, r, "pthread_join(%d)", i); + } + if (unlink(path) == -1) + err(1, "unlink(%s)", path); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap38.sh b/tools/test/stress2/misc/mmap38.sh new file mode 100755 index 000000000000..b4cf60afe25b --- /dev/null +++ b/tools/test/stress2/misc/mmap38.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# mmap(2) fuzz test. +# No problems seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +num=`awk '/SYS_mmap/ {print $NF}' < /usr/include/sys/syscall.h` +[ -z "$num" ] && exit 0 +start=`date +%s` + +cd ../misc +while [ $((`date +%s` - start)) -lt 300 ]; do + ./syscall4.sh $num +done +exit 0 diff --git a/tools/test/stress2/misc/mmap39.sh b/tools/test/stress2/misc/mmap39.sh new file mode 100755 index 000000000000..15aa8ec718a3 --- /dev/null +++ b/tools/test/stress2/misc/mmap39.sh @@ -0,0 +1,131 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# Attempt to reproduce +# "panic: pmap_release: pmap 0xfffffe012fb61b08 resident count 1 != 0" +# No problems seen. + +# Test scenario suggestion by kib@ + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +[ `uname -p` != "amd64" ] && exit 0 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap39.c +mycc -o mmap39 -Wall -Wextra -O0 -g mmap39.c -static || exit 1 +rm -f mmap39.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +for i in `jot 128`; do + $dir/mmap39 & + pids="$pids $!" +done +s=0 +for pid in $pids; do + wait $pid + r=$? + [ $s -ne 0 ] && s=$r +done + +[ -f mmap39.core -a $s -eq 0 ] && + { ls -l mmap39.core; mv mmap39.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/mmap39 +exit $s + +EOF +#include +#include +#include + +#include +#include +#include +#include + +void +test(void) +{ + size_t i, len; + void *p; + + p = (void *)0x8000000000; /* 512G */ + len = 0x200000; /* 2M */ + if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) == + MAP_FAILED) + err(1, "mmap"); + + if (p != (void *)0x8000000000) + errx(1, "mmap address fail"); + + for (i = 0; i < len; i += PAGE_SIZE) + *(char *)(p + i) = 1; + + if (munmap(p, len) == -1) + err(1, "munmap()"); + + _exit(0); +} + +int +main(void) +{ + time_t start; + pid_t pid; + + sleep(5); + start = time(NULL); + while (time(NULL) - start < 120) { + if ((pid = fork()) == 0) + test(); + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid"); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap4.sh b/tools/test/stress2/misc/mmap4.sh new file mode 100755 index 000000000000..8c84401fb960 --- /dev/null +++ b/tools/test/stress2/misc/mmap4.sh @@ -0,0 +1,116 @@ +#!/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. +# + +# Test overcommit of the file system capacity +# Causes panic: 1 vncache entries remaining +# Fixed in r202529 + +# Scenario 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 +mycc -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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +/tmp/mmap4 /$mntpoint/file + +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; + volatile char *c; + char *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/tools/test/stress2/misc/mmap40.sh b/tools/test/stress2/misc/mmap40.sh new file mode 100755 index 000000000000..4bf60fc8f44d --- /dev/null +++ b/tools/test/stress2/misc/mmap40.sh @@ -0,0 +1,159 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# Attempt to reproduce "vm_page_assert_xbusied: page XXXX not exclusive busy" +# No problems seen. + +# Test scenario idea by markj@ + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +[ `sysctl -n vm.swap_total` -eq 0 ] && exit 0 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap40.c +mycc -o mmap40 -Wall -Wextra -O0 -g mmap40.c || exit 1 +rm -f mmap40.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +u1=`swapinfo | tail -1 | awk '{print $3}'` +(nice $odir/../testcases/swap/swap -t 10m -i 30 -h -l 100) & +while [ $((`swapinfo | tail -1 | awk '{print $3}'` - $u1)) -le 100 ]; do + sleep 1 +done + +$dir/mmap40 +s=0 +while pkill swap; do :; done +wait +[ -f mmap40.core -a $s -eq 0 ] && + { ls -l mmap40.core; mv mmap40.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/mmap40 +exit $s + +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define PARALLEL 512 +#define RUNTIME 300 + +void +test(void) +{ + pid_t pid; + size_t i, len; + time_t start; + void *p; + char *vec; + + len = 1024 * 1024; + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) == + MAP_FAILED) + err(1, "mmap"); + memset(p, 0, len); /* dirty the memory */ + if ((vec = malloc(len / PAGE_SIZE)) == NULL) + err(1, "malloc"); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + usleep(arc4random() % 1000); + if (mincore(p, len, vec) == -1) + err(1, "mincore"); + for (i = 0; i < len / PAGE_SIZE; i++) { + if ((vec[i] & MINCORE_MODIFIED) == 0) { + _exit(0); + } + } + if ((pid = fork()) == 0) { + _exit(0); + } + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid)"); + } + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + time_t start; + int i; + + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], NULL, WNOHANG) == pids[i]) { + if ((pids[i] = fork()) == 0) + test(); + } + } + } + + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], NULL, 0) != pids[i]) + err(1, "waitpid"); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap5.sh b/tools/test/stress2/misc/mmap5.sh new file mode 100755 index 000000000000..e6dee6d551de --- /dev/null +++ b/tools/test/stress2/misc/mmap5.sh @@ -0,0 +1,129 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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 scenario inspired by alc@ +# "panic: vm_page_dirty: page is invalid!" seen. +# Fixed in r255396. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap5.c +mycc -o mmap5 -Wall -Wextra mmap5.c || exit 1 +rm -f mmap5.c +cd $odir + +cp /tmp/mmap5 /tmp/mmap5.inputfile +(cd ../testcases/swap; ./swap -t 1m -i 2) & +cp /tmp/mmap5 /tmp/mmap5.inputfile +/tmp/mmap5 /tmp/mmap5.inputfile +while killall -9 swap; do + sleep .1 +done > /dev/null 2>&1 +wait +rm -f /tmp/mmap5 /tmp/mmap5.inputfile +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char *file; + +void +test2(void) +{ + struct stat st; + char *p; + size_t len; + int error, fd; + + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open %s", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = round_page(st.st_size); + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) + err(1, "mmap"); + p[arc4random() % len] = 1; + if (arc4random() % 100 < 50) + if ((error = mlock(p, len)) == -1) + err(1, "mlock"); + p[arc4random() % len] = 1; + if (arc4random() % 100 < 50) + if ((error = msync(p, len, MS_SYNC | MS_INVALIDATE)) == -1) + if (errno != EBUSY) + err(1, "msync"); + if (munmap(p, len) == -1) + err(1, "unmap()"); + close(fd); + _exit(0); + +} + +void +test(void) +{ + int i; + + for (i = 0; i < 3; i++) + if (fork() == 0) + test2(); + for (i = 0; i < 3; i++) + wait(NULL); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + int i; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + for (i = 0; i < 30000; i++) { + if (fork() == 0) + test(); + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap6.sh b/tools/test/stress2/misc/mmap6.sh new file mode 100755 index 000000000000..e9efbbea5f8a --- /dev/null +++ b/tools/test/stress2/misc/mmap6.sh @@ -0,0 +1,179 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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 scenario inspired by alc@ +# "panic: vm_page_dirty: page is invalid!" seen. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/wire_no_page.c +mycc -o mmap6 -Wall -Wextra wire_no_page.c || exit 1 +rm -f wire_no_page.c +cd $odir + +cp /tmp/mmap6 /tmp/mmap6.inputfile +(cd ../testcases/swap; ./swap -t 5m -i 2) & +cp /tmp/mmap6 /tmp/mmap6.inputfile +/tmp/mmap6 /tmp/mmap6.inputfile +while killall -9 swap; do + sleep .1 +done > /dev/null 2>&1 +wait +rm -f /tmp/mmap6 /tmp/mmap6.inputfile +exit 0 + +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define RUNTIME 300 + +const char *file; +char c; + +void +rd(void) +{ + struct stat st; + char *p1, *p2; + size_t len; + int error, fd; + + if ((fd = open(file, O_RDONLY)) == -1) + err(1, "open %s", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = round_page(st.st_size); + if ((p1 = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) + err(1, "mmap"); + if ((p2 = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) + err(1, "mmap"); + c = p1[arc4random() % len]; + c = p2[arc4random() % len]; + if (arc4random() % 100 < 50) + if ((error = mlock(p1, len)) == -1) + err(1, "mlock"); + c = p1[arc4random() % len]; + if (munmap(p2, len) == -1) + err(1, "unmap()"); + if (munmap(p1, len) == -1) + err(1, "unmap()"); + close(fd); + +} +void +wr(void) +{ + struct stat st; + char *p1, *p2; + size_t len; + int error, fd; + + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open %s", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = round_page(st.st_size); + if ((p1 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) + err(1, "mmap"); + if ((p2 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) + err(1, "mmap"); + p1[arc4random() % len] = 1; + p2[arc4random() % len] = 1; + if (arc4random() % 100 < 50) + if ((error = mlock(p1, len)) == -1) + err(1, "mlock"); + p1[arc4random() % len] = 1; + if (arc4random() % 100 < 50) + if ((error = msync(p1, len, MS_SYNC | MS_INVALIDATE)) == -1) + if (errno != EBUSY) + err(1, "msync"); + if (munmap(p2, len) == -1) + err(1, "unmap()"); + if (munmap(p1, len) == -1) + err(1, "unmap()"); + close(fd); + +} + +void +test2(void) +{ + if (arc4random() % 100 < 30) + rd(); + else + wr(); + _exit(0); +} + +void +test(void) +{ + int i; + + for (i = 0; i < 3; i++) + if (fork() == 0) + test2(); + for (i = 0; i < 3; i++) + wait(NULL); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + time_t start; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if (fork() == 0) + test(); + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap7.sh b/tools/test/stress2/misc/mmap7.sh new file mode 100755 index 000000000000..7d467c715203 --- /dev/null +++ b/tools/test/stress2/misc/mmap7.sh @@ -0,0 +1,147 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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 scenario inspired by alc@ +# Threaded version in order to "use the same pmap", as pointed out by kib@ + +# https://people.freebsd.org/~pho/stress/log/kostik601.txt +# Fixed by r255396 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/wire_no_page.c +mycc -o mmap7 -Wall -Wextra wire_no_page.c -lpthread || exit 1 +rm -f wire_no_page.c +cd $odir + +(cd ../testcases/swap; ./swap -t 1m -i 2) & +sleep 1 +cp /tmp/mmap7 /tmp/mmap7.inputfile +/tmp/mmap7 /tmp/mmap7.inputfile +while pkill -9 swap; do :; done +wait +rm -f /tmp/mmap7 /tmp/mmap7.inputfile +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char *p1, *p2, *p3; +char c; +const char *file; +int fd; +size_t len; +struct stat st; + +void * +test2(void *arg __unused) +{ + int error, i; + + p1[arc4random() % len] = 1; + p2[arc4random() % len] = 1; + + if (arc4random() % 100 < 30) + i = p3[arc4random() % len]; + + if (arc4random() % 100 < 50) + if ((error = mlock(p1, len)) == -1) + err(1, "mlock"); + if (arc4random() % 100 < 50) + if ((error = msync(p1, len, MS_SYNC | MS_INVALIDATE)) == -1) + if (errno != EBUSY) + err(1, "msync"); + return (0); +} + +void +test(void) +{ + pthread_t cp[3]; + int e, error, i; + + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open %s", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = round_page(st.st_size); + if ((p1 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) + err(1, "mmap"); + if ((p2 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) + err(1, "mmap"); + if ((p3 = mmap(NULL, len, PROT_READ , MAP_SHARED, fd, 0)) == MAP_FAILED) + err(1, "mmap"); + + for (i = 0; i < 3; i++) + if ((e = pthread_create(&cp[i], NULL, test2, NULL)) != 0) + errc(1, e, "pthread_create"); + for (i = 0; i < 3; i++) + pthread_join(cp[i], NULL); + + if (munmap(p3, len) == -1) + err(1, "unmap()"); + if (munmap(p2, len) == -1) + err(1, "unmap()"); + if (munmap(p1, len) == -1) + err(1, "unmap()"); + close(fd); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + int i; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + for (i = 0; i < 30000; i++) { + if (fork() == 0) + test(); + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/mmap8.sh b/tools/test/stress2/misc/mmap8.sh new file mode 100755 index 000000000000..e8fd631ed1e6 --- /dev/null +++ b/tools/test/stress2/misc/mmap8.sh @@ -0,0 +1,89 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# "panic: vm_fault_copy_wired: page missing" seen: +# http://people.freebsd.org/~pho/stress/log/mmap8.txt +# Fixed in r265002. + +# Test scenario by: Mark Johnston markj@ + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap8.c +# At one point during the fix development, only the thread version would panic +mycc -o mmap8 -Wall -Wextra mmap8.c || exit 1 +mycc -o mmap8p -Wall -Wextra mmap8.c -pthread || exit 1 +rm -f mmap8.c +cd $odir + +/tmp/mmap8p +/tmp/mmap8 + +rm -f /tmp/mmap8 /tmp/mmap8p +exit + +EOF +#include +#include + +#include +#include +#include + +int +main(void) +{ + size_t sz = 1; + char *addr; + +/* + * This is the minimum amount of C code it takes to panic the kernel. + * This is as submitted and thus not a complete and correct test program. + */ + addr = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + if (addr == NULL) + err(1, "mmap"); + memset(addr, 0, sz); + + if (fork() != 0) { + if (mprotect(addr, sz, PROT_READ)) + err(1, "mprotect"); + if (mlock(addr, sz)) + err(1, "mlock"); + if (mprotect(addr, sz, PROT_WRITE | PROT_READ)) + err(1, "mprotect"); + if (munmap(addr, sz)) + err(1, "munmap"); + } else + sleep(1); + + return (0); +} diff --git a/tools/test/stress2/misc/mmap9.sh b/tools/test/stress2/misc/mmap9.sh new file mode 100755 index 000000000000..8608df01cb0c --- /dev/null +++ b/tools/test/stress2/misc/mmap9.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# "panic: vm_map_protect: object 0xca6869c0 overcharged" seen: +# http://people.freebsd.org/~pho/stress/log/mmap9.txt +# Fixed in r265843 + +# Test scenario by: Mark Johnston markj@ + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/mmap9.c +# At one point during the fix development, only the thread version would panic +mycc -o mmap9 -O2 -Wall -Wextra mmap9.c || exit 1 +mycc -o mmap9p -O2 -Wall -Wextra mmap9.c -lpthread || exit 1 +rm -f mmap9.c +cd $odir + +/tmp/mmap9 +/tmp/mmap9p + +rm -f /tmp/mmap9 /tmp/mmap9p +exit + +EOF +#include +#include + +#include +#include +#include + +int +main(void) +{ + size_t sz = 1; + char *addr; + +/* + * This is the minimum amount of C code it takes to panic the kernel. + * This is as submitted and thus not a complete and correct test program. + */ + addr = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_ANON, + -1, 0); + if (addr == NULL) + err(1, "mmap"); + memset(addr, 0, sz); + + if (fork() != 0) { + if (mlock(addr, sz)) + err(1, "mlock"); + if (mprotect(addr, sz, PROT_READ)) + err(1, "mprotect"); + if (mprotect(addr, sz, PROT_READ | PROT_WRITE)) + err(1, "mprotect"); + if (mprotect(addr, sz, PROT_READ)) + err(1, "mprotect"); + if (mprotect(addr, sz, PROT_READ | PROT_WRITE)) + err(1, "mprotect"); + } else + /* + * Ensure that shadow objects aren't collapsed by process exit. + */ + sleep(1); + + return (0); +} diff --git a/tools/test/stress2/misc/mount.sh b/tools/test/stress2/misc/mount.sh new file mode 100755 index 000000000000..4b020ca919bd --- /dev/null +++ b/tools/test/stress2/misc/mount.sh @@ -0,0 +1,82 @@ +#!/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. +# + +# 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 + +. ../default.cfg + +mount | grep -q "$mntpoint" && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +# The test: + +echo "Expect: mount: /dev/md5a: Device busy" +mount -r /dev/md${mdstart}$part $mntpoint +mount -r /dev/md${mdstart}$part $mntpoint +umount $mntpoint + +ls -lR $mntpoint > /dev/null # panic + +# End of test +mount | grep -q "$mntpoint" && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/mount2.sh b/tools/test/stress2/misc/mount2.sh new file mode 100755 index 000000000000..d4b30bafe711 --- /dev/null +++ b/tools/test/stress2/misc/mount2.sh @@ -0,0 +1,73 @@ +#!/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. +# + +# Stress test by performing parallel calls to mount and umount. Alternate +# between forced and non-forced unmounts. + +# "kernel: g_dev_taste: make_dev_p() failed (gp->name=md10, error=17)" seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +D=$diskimage + +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 status=none + mdconfig -a -t vnode -f $D$m -u $m || { rm -f $D$m; exit 1; } + bsdlabel -w md$m auto + newfs md${m}$part > /dev/null +done + +# start the parallel tests +for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + start=`date +%s` + while [ $((`date +%s` - start)) -lt 300 ]; do + 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 & +done +wait + +for i in `jot $mounts`; do + m=$((i + mdstart - 1)) + mdconfig -d -u $m + rm -f $D$m +done +exit 0 diff --git a/tools/test/stress2/misc/mountro.sh b/tools/test/stress2/misc/mountro.sh new file mode 100755 index 000000000000..38f6c6e5bd10 --- /dev/null +++ b/tools/test/stress2/misc/mountro.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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. +# + +# Page fault seen: https://people.freebsd.org/~pho/stress/log/mountro.txt +# Fixed by r346031 + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +D=$diskimage +dd if=/dev/zero of=$D bs=1m count=128 status=none || exit 1 + +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 || { rm -f $D; exit 1; } + +bsdlabel -w md$mdstart auto +newfs $newfs_flags 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 ..; ./run.sh disk.cfg > /dev/null 2>&1) & +sleep 10 + +for i in `jot 10`; do + mount -u -o ro $mntpoint + sleep 3 + mount -u -o rw $mntpoint + sleep 3 +done > /dev/null 2>&1 + +umount -f $mntpoint +mdconfig -d -u $mdstart +rm -f $D +pkill run.sh +wait diff --git a/tools/test/stress2/misc/mountro2.sh b/tools/test/stress2/misc/mountro2.sh new file mode 100755 index 000000000000..a57c6776fb03 --- /dev/null +++ b/tools/test/stress2/misc/mountro2.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. +# + +# Test scenario by Matthew D. Fuller + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +D=$diskimage +dd if=/dev/zero of=$D bs=1m count=20 status=none || 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 || { rm -f $D; exit 1; } + +bsdlabel -w md$mdstart auto +newfs $newfs_flags 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/tools/test/stress2/misc/mountro3.sh b/tools/test/stress2/misc/mountro3.sh new file mode 100755 index 000000000000..e1749dfdc391 --- /dev/null +++ b/tools/test/stress2/misc/mountro3.sh @@ -0,0 +1,56 @@ +#!/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. +# + +# Test scenario by barbara +# kern/121809: unable to umount + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +D=$diskimage +dd if=/dev/zero of=$D bs=1m count=64 status=none || 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 || { rm -f $D; exit 1; } +bsdlabel -w md$mdstart auto +newfs $newfs_flags 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/tools/test/stress2/misc/mountro4.sh b/tools/test/stress2/misc/mountro4.sh new file mode 100755 index 000000000000..b6ff922d5ff9 --- /dev/null +++ b/tools/test/stress2/misc/mountro4.sh @@ -0,0 +1,100 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Check that the time stamps are not updated for a RO mount. + +. ../default.cfg + +f1=$mntpoint/f1 +f2=$mntpoint/f2 +s=0 + +# ufs +mount | grep -q "on $mntpoint " && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +newfs $newfs_flags /dev/md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint || exit 1 +touch $f1 +mount -u -o ro $mntpoint +touch $f2 2>/dev/null && { echo "ufs: ro failed"; s=1; } +d1=`stat -f '%a %m %c' $f1` +sleep 1 +cat $f1 > /dev/null +d2=`stat -f '%a %m %c' $f1` +if [ "$d1" != "$d2" ]; then + echo "ufs: Access time was updated. $d1 != $d2" + s=1 +fi +mount -u -o rw $mntpoint +touch $f2 2>/dev/null || { echo "ufs: rw failed"; s=1; } +umount $mntpoint +mdconfig -d -u $mdstart + +# tmpfs +mount -o size=100m -t tmpfs null $mntpoint || exit 1 +touch $f1 +mount -u -o ro $mntpoint +touch $f2 2>/dev/null && { echo "tmpfs: ro failed"; s=1; } +d1=`stat -f '%a %m %c' $f1` +sleep 1 +cat $f1 > /dev/null +d2=`stat -f '%a %m %c' $f1` +if [ "$d1" != "$d2" ]; then + echo "tmpfs: Access time was updated. $d1 != $d2" + s=1 +fi +mount -u -o rw $mntpoint +touch $f2 2>/dev/null || { echo "tmpfs: rw failed"; s=1; } +umount $mntpoint + +# msdosfs +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs_msdos /dev/md${mdstart}$part > /dev/null +mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1 + +touch $f1 +mount -u -o ro $mntpoint +touch $f2 2>/dev/null && { echo "msdosfs: ro failed"; s=1; } +d1=`stat -f '%a %m %c' $f1` +sleep 1 +cat $f1 > /dev/null +d2=`stat -f '%a %m %c' $f1` +if [ "$d1" != "$d2" ]; then + echo "msdosfs: Access time was updated. $d1 != $d2" + s=1 +fi +mount -u -o rw $mntpoint +touch $f2 2>/dev/null || { echo "msdosfs: rw failed"; s=1; } +umount $mntpoint +mdconfig -d -u $mdstart + +exit $s diff --git a/tools/test/stress2/misc/mountro5.sh b/tools/test/stress2/misc/mountro5.sh new file mode 100755 index 000000000000..67663df54145 --- /dev/null +++ b/tools/test/stress2/misc/mountro5.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Toggle a tmpfs file system rw / ro. +# No problems seen. + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +mount | grep "on $mntpoint " | grep -q /md && umount -f $mntpoint +mount -t tmpfs null $mntpoint + +mkdir $mntpoint/stressX +chmod 777 $mntpoint/stressX + +export RUNDIR=$mntpoint/stressX +export CTRLDIR=$mntpoint/stressX.control +export runRUNTIME=4m +export TESTPROGS="testcases/swap/swap testcases/creat/creat \ + testcases/mkdir/mkdir testcases/rw/rw" +(cd ..; ./testcases/run/run $TESTPROGS > /dev/null 2>&1) & +sleep 10 + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 60 ]; do + mount -fu -o ro $mntpoint + sleep .5 + mount -u -o rw $mntpoint + sleep .5 +done + +../tools/killall.sh +wait +while mount | grep -q "on $mntpoint "; do + umount $mntpoint +done diff --git a/tools/test/stress2/misc/mountro6.sh b/tools/test/stress2/misc/mountro6.sh new file mode 100755 index 000000000000..398cbeed4fea --- /dev/null +++ b/tools/test/stress2/misc/mountro6.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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 rw->ro remount when there is a text vnode mapping. +# Fixed by: r347968 + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 512m -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +cd $mntpoint +cp /bin/sleep . +./sleep 20 & +cd / +sleep .1 +mount -u -o ro $mntpoint || s=1 +wait +for i in `jot 5`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 5 +done +mount | grep -q "on $mntpoint " && { umount -f $mntpoint; s=2; } +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/mountu.sh b/tools/test/stress2/misc/mountu.sh new file mode 100755 index 000000000000..1c1b619463cd --- /dev/null +++ b/tools/test/stress2/misc/mountu.sh @@ -0,0 +1,284 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2012 Peter Holm +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# Change mount point from rw to ro with a file mapped rw +# Currently fails for NFS + +# Page fault seen: +# https://people.freebsd.org/~pho/stress/log/mountu.txt +# Fixed by: r285039. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mountu.c +mycc -o mountu -Wall -Wextra -O2 mountu.c || exit 1 +rm -f mountu.c + +pstat() { + local pid + pid=`ps ax | grep -v grep | grep /tmp/mountu | awk '{print $1}'` + [ -n "$pid" ] && procstat -v $pid +} + +ck() { + if mount | grep $mntpoint | grep -q "read-only"; then + if pstat $!| awk "\$2 == \"$map\"" | grep -q " rw-"; then + echo + echo "$1 difference" + mount | grep $mntpoint + printf "RW mount mapping and RO mount mapping:\n%s\n" "$r" + pstat $! | awk "\$2 == \"$map\"" + status=$((status + 1)) + fi + else + echo "$1 mount point RO did not succeed" + mount | grep $mntpoint + status=$((status + 1)) + fi +} + +status=0 +file=$mntpoint/mountu.sh.file +mapfile=/tmp/mountu.sh.map +mount | grep -q "$mntpoint " && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 100m -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +# ufs +exec 5>$mapfile +/tmp/mountu UFS $file & +pid=$! +sleep 1 +map=`cat $mapfile`; rm $mapfile; exec 5>&- + +r=`pstat $! | awk "\\$2 == \"$map\""` +mount -u -o ro $mntpoint 2>/dev/null || mount -fu -o ro $mntpoint +ck UFS +mount -u -o rw $mntpoint +rm -f $file +wait $pid +s=$? +[ $s -ne 139 ] && { echo "UFS exit status is $s"; status=1; } +while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart + +# nfs +if ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1; then + mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export \ + $mntpoint + sleep .2 + rm -f $file + /tmp/mountu NFS $file & + pid=$! + sleep 1 + + r=`pstat $! | awk "\\$2 == \"$map\""` + mount -u -o ro $mntpoint 2>/dev/null || + mount -fu -o ro $mntpoint 2>/dev/null + ck NFS + wait $pid + s=$? + [ $s -ne 139 ] && { echo "NFS exit status is $s"; status=1; } + + mount -u -o rw $mntpoint 2>/dev/null + sleep .2 + [ -f $file ] && rm -f $file + umount $mntpoint || umount $mntpoint +fi + +# msdos +if [ -x /sbin/mount_msdosfs ]; then + mdconfig -a -t swap -s 100m -u $mdstart + bsdlabel -w md$mdstart auto + newfs_msdos -F 16 -b 8192 /dev/md${mdstart}$part > /dev/null 2>&1 + mount_msdosfs -m 777 /dev/md${mdstart}$part $mntpoint + /tmp/mountu MSDOS $file & + pid=$! + + sleep 1 + r=`pstat $! | awk "\\$2 == \"$map\""` + mount -u -o ro $mntpoint 2>/dev/null || mount -fu -o ro $mntpoint + ck MSDOS + wait $pid + s=$? + [ $s -ne 139 ] && { echo "MSDOS exit status is $s"; status=1; } + mount -u -o rw $mntpoint + rm -f $file + + while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 + done + mdconfig -d -u $mdstart +fi + +# tmpfs +mount -t tmpfs null $mntpoint +chmod 777 $mntpoint + +/tmp/mountu TMPFS $file & +pid=$! + +sleep 1 +r=`pstat $! | awk "\\$2 == \"$map\""` +mount -u -o ro $mntpoint 2>/dev/null || mount -fu -o ro $mntpoint +ck TMPFS +sleep 1 +mount -u -o rw $mntpoint +rm -f $file +wait $pid +s=$? +[ $s -ne 139 ] && { echo "TMPFS exit status is $s"; status=1; } +while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 +done + +rm -f /tmp/mountu +exit 0 +EOF +/* kib@ noted: + UFS/NFS/msdosfs reclaim vnode on rw->ro forced remount, and + change the type of the underying object to OBJT_DEAD, but leave + the pages on the object queue and installed in the page tables. + Applications can read/write already mapped pages, but cannot + page in new pages, cannot observe possible further modifications + to already mapped pages (if ro->rw remount happen later), and + their updates to pages are not flushed to file. + + It is impossible to mimic this behaviour for tmpfs. + */ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define STARTADDR 0x0U +#define ADRSPACE 0x0640000U + +static void +sighandler(int signo, siginfo_t *si, void *uc1) +{ + ucontext_t *uc; + + uc = uc1; + printf("SIG%s at %p, addr %p\n", sys_signame[signo], si->si_addr, +#if defined(__i386__) + (void *)uc->uc_mcontext.mc_eip); +#else + (void *)uc->uc_mcontext.mc_rip); +#endif + exit(1); +} + +int +main(int argc __unused, char **argv) +{ + struct passwd *pw; + struct sigaction sa; + void *p; + size_t len; + int fd; + char *name, *path; + volatile char *c; + + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = sighandler; + sa.sa_flags = SA_SIGINFO; + if (sigaction(SIGSEGV, &sa, NULL) == -1) + err(1, "sigaction(SIGSEGV)"); + if (sigaction(SIGBUS, &sa, NULL) == -1) + err(1, "sigaction(SIGBUS)"); + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + p = (void *)STARTADDR; + len = ADRSPACE; + + name = argv[1]; + path = argv[2]; + if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) + err(1,"open(%s)", path); + 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) { + warn("mmap()"); + return (1); + } + err(1, "mmap(1)"); + } + dprintf(5, "%p\n", p); + + for (c = p; (void *)c < p + len; c += PAGE_SIZE) { + *c = 1; + } + + close(fd); + sleep(5); + fprintf(stderr, "%s: Late read start.\n", name); + for (c = p; (void *)c < p + len; c += PAGE_SIZE) { + *c; + } + fprintf(stderr, "%s: Late read complete.\n", name); + + fprintf(stderr, "%s: Late write start.\n", name); + for (c = p; (void *)c < p + len; c += PAGE_SIZE) { + *c = 1; + } + fprintf(stderr, "%s: Late write complete.\n", name); + + return (0); +} diff --git a/tools/test/stress2/misc/mprotect.sh b/tools/test/stress2/misc/mprotect.sh new file mode 100755 index 000000000000..9fde68de56ec --- /dev/null +++ b/tools/test/stress2/misc/mprotect.sh @@ -0,0 +1,75 @@ +#!/bin/sh +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Mark Johnston +# +# 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. +# + +# "panic: pmap_demote_pde: page table page for a wired mapping +# is missing" seen. + +# Fixed by r345382 + +. ../default.cfg + +cd /tmp +cat > mprotect.c < + +#include +#include + +int +main(void) +{ + char *addr, c; + size_t i, len; + + len = 2 * 1024 * 1024; + addr = mmap(NULL, 2 * 1024 * 1024, PROT_READ, + MAP_ANON | MAP_ALIGNED_SUPER, -1, 0); + if (addr == MAP_FAILED) + err(1, "mmap"); + if (mlock(addr, len) != 0) /* hopefully this gets a superpage */ + err(1, "mlock"); + if (mprotect(addr, len, PROT_NONE) != 0) + err(1, "mprotect"); + if (mprotect(addr, len, PROT_READ) != 0) + err(1, "mprotect"); + for (i = 0; i < len; i++) /* preemptive superpage mapping */ + c = *(volatile char *)(addr + i); + if (mprotect(addr, 4096, PROT_NONE) != 0) /* trigger demotion */ + err(1, "mprotect"); + if (munlock(addr, len) != 0) + err(1, "munlock"); + + return (0); +} +EOF +mycc -o mprotect -Wall -Wextra -O2 mprotect.c || exit 1 + +./mprotect; s=$? + +rm mprotect.c mprotect +exit $s diff --git a/tools/test/stress2/misc/mprotect2.sh b/tools/test/stress2/misc/mprotect2.sh new file mode 100755 index 000000000000..c5cdc44a0f39 --- /dev/null +++ b/tools/test/stress2/misc/mprotect2.sh @@ -0,0 +1,97 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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 scenario suggestion by alc@ + +. ../default.cfg + +cd /tmp +cat > mprotect2.c < +#include + +#include +#include +#include +#include +#include +#include + +#define SIZ 0x40000000LL /* 1GB */ + +static void +test(void) +{ + size_t i, len; + char *cp; + + len = SIZ; + if ((cp = mmap(NULL, len, PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0)) + == MAP_FAILED) + err(1, "mmap"); + + for (i = 0; i < SIZ; i += PAGE_SIZE * 2) { + if (mprotect(cp + i, PAGE_SIZE, 0) != 0) + err(1, "mprotect(). %d", __LINE__); + } + if (mprotect(cp, SIZ, PROT_WRITE) != 0) + err(1, "mprotect(). %d", __LINE__); + + if (munmap(cp, SIZ) == -1) + err(1, "munmap()"); +} + +int +main(void) +{ + int i; + + /* Slow run with debug.vmmap_check=1 */ + alarm(120); + + for (i = 0; i < 64; i++) + test(); + + return (0); +} +EOF +mycc -o mprotect2 -Wall -Wextra -O2 mprotect2.c || exit 1 + +./mprotect2; s=$? + +rm mprotect2.c mprotect2 +exit $s diff --git a/tools/test/stress2/misc/msdos.sh b/tools/test/stress2/misc/msdos.sh new file mode 100755 index 000000000000..2324404bfd16 --- /dev/null +++ b/tools/test/stress2/misc/msdos.sh @@ -0,0 +1,60 @@ +#!/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. +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# LOR seen. Fixed by r204467. + +. ../default.cfg + +[ -x /sbin/mount_msdosfs ] || exit +log=/tmp/msdos.sh.log +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}$part > /dev/null +mount -t msdosfs /dev/md${mdstart}$part $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}$part > $log 2>&1 +s=0 +if egrep -q "BAD|INCONSISTENCY|MODIFIED" $log; then + cat $log + rm $log + s=1 +fi +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/msdos10.sh b/tools/test/stress2/misc/msdos10.sh new file mode 100755 index 000000000000..09613a859082 --- /dev/null +++ b/tools/test/stress2/misc/msdos10.sh @@ -0,0 +1,89 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# fsx test of with msdosfs and a 1k block size +# "panic: Assertion ma[i]->dirty == VM_PAGE_BITS_ALL failed" seen. +# Fixed by r324794 + +# Original test scenario by fsu@freebsd.org + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +[ -r /usr/src/tools/regression/fsx/fsx.c ] || exit 0 + +[ -x /sbin/mount_msdosfs ] || exit 0 +dir=/tmp +odir=`pwd` +cd $dir +cc -o fsx -Wall -Wextra -O2 -g /usr/src/tools/regression/fsx/fsx.c || exit 1 +rm -f fsx.c +cd $odir +log=/tmp/fsx.sh.log +mount | grep "$mntpoint" | grep -q md$mdstart && umount -f $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +set -e +mdconfig -a -t swap -s 4g -u $mdstart +bsdlabel -w md$mdstart auto +newfs_msdos -b 1024 /dev/md${mdstart}$part > /dev/null +mount -t msdosfs /dev/md${mdstart}$part $mntpoint +set +e + +cp /tmp/fsx $mntpoint + +cd $mntpoint + +NUM_OPS=2000 +SEED=2016 +( +./fsx -S ${SEED} -N ${NUM_OPS} ./TEST_FILE0 & +./fsx -S ${SEED} -l 5234123 -o 5156343 -N ${NUM_OPS} ./TEST_FILE1 & +./fsx -S ${SEED} -l 2311244 -o 2311200 -N ${NUM_OPS} ./TEST_FILE2 & +./fsx -S ${SEED} -l 8773121 -o 863672 -N ${NUM_OPS} ./TEST_FILE3 & +./fsx -S ${SEED} -l 234521 -o 234521 -N ${NUM_OPS} ./TEST_FILE4 & +./fsx -S ${SEED} -l 454321 -o 33 -N ${NUM_OPS} ./TEST_FILE5 & +./fsx -S ${SEED} -l 7234125 -o 7876728 -N ${NUM_OPS} ./TEST_FILE6 & +wait +) > /dev/null +cd / + +while mount | grep "$mntpoint" | grep -q md$mdstart; do + umount $mntpoint || sleep 1 +done +fsck -t msdosfs -y /dev/md${mdstart}$part > $log 2>&1 +if egrep -q "BAD|INCONSISTENCY|MODIFIED" $log; then + cat $log + s=1 + + mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1 + ls -lR $mntpoint + umount $mntpoint +fi +mdconfig -d -u $mdstart +rm /tmp/fsx $log +exit $s diff --git a/tools/test/stress2/misc/msdos2.sh b/tools/test/stress2/misc/msdos2.sh new file mode 100755 index 000000000000..838585595ec3 --- /dev/null +++ b/tools/test/stress2/misc/msdos2.sh @@ -0,0 +1,58 @@ +#!/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. +# + +# 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 + +[ -x /sbin/mount_msdosfs ] || exit +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}$part > /dev/null +mount -t msdosfs /dev/md${mdstart}$part $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}$part > /dev/null +mount -u /dev/md${u}$part $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/tools/test/stress2/misc/msdos3.sh b/tools/test/stress2/misc/msdos3.sh new file mode 100755 index 000000000000..e251f7bf7ee7 --- /dev/null +++ b/tools/test/stress2/misc/msdos3.sh @@ -0,0 +1,52 @@ +#!/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. +# + +# Page fault seen +# Scenario by kib@ + +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -x /sbin/mount_msdosfs ] || exit +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}$part > /dev/null + +mount -t msdosfs /dev/md${mdstart}$part $mntpoint +mount -t msdosfs /dev/md${mdstart}$part $mntpoint || echo OK + +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/tools/test/stress2/misc/msdos4.sh b/tools/test/stress2/misc/msdos4.sh new file mode 100755 index 000000000000..807c3b5206eb --- /dev/null +++ b/tools/test/stress2/misc/msdos4.sh @@ -0,0 +1,76 @@ +#!/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. +# + +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +# "panic: leaf should be empty" seen + +# "panic: Assertion sq->sq_wchan != NULL" seen: +# https://people.freebsd.org/~pho/stress/log/msdos4.txt + +. ../default.cfg + +[ -x /sbin/mount_msdosfs ] || exit +log=/tmp/msdos4.sh.log +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}$part > /dev/null +mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1 + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m +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 ..; ./testcases/run/run $TESTPROGS) + +while mount | grep "$mntpoint" | grep -q md$mdstart; do + umount $mntpoint || sleep 1 +done +fsck -t msdosfs -y /dev/md${mdstart}$part > $log 2>&1 +s=0 +if egrep -q "BAD|INCONSISTENCY|MODIFIED" $log; then + cat $log + rm $log + s=1 +fi +mdconfig -d -u $mdstart +s=0 # Ignore for now +exit $s diff --git a/tools/test/stress2/misc/msdos5.sh b/tools/test/stress2/misc/msdos5.sh new file mode 100755 index 000000000000..815eeca6fd4c --- /dev/null +++ b/tools/test/stress2/misc/msdos5.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# "panic: Freeing unused sector 79510 22 ff800000" seen. +# http://people.freebsd.org/~pho/stress/log/msdos5.txt +# FS corruption seen: http://people.freebsd.org/~pho/stress/log/msdos5-2.txt +# Fixed by r333693. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -x /sbin/mount_msdosfs ] || exit + +. ../default.cfg + +mycc -o /tmp/fstool -Wall -Wextra -O2 ../tools/fstool.c || exit 1 + +cd /tmp +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 3g -u $mdstart +bsdlabel -w md$mdstart auto +newfs_msdos -F 32 -b 8192 /dev/md${mdstart}$part > /dev/null 2>&1 +mount_msdosfs -m 777 /dev/md${mdstart}$part $mntpoint + +for i in `jot 5`; do + (mkdir $mntpoint/test$i; cd $mntpoint/test$i; /tmp/fstool -l -f 400 -n 200 -s ${i}k) +done + +sleep 1 +rm -rf $mntpoint/* || echo FAIL + +while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 +done +rm -f /tmp/fstool diff --git a/tools/test/stress2/misc/msdos6.sh b/tools/test/stress2/misc/msdos6.sh new file mode 100755 index 000000000000..475989b3fa1c --- /dev/null +++ b/tools/test/stress2/misc/msdos6.sh @@ -0,0 +1,93 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC Isilon +# 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. +# + +# Parallel mount and umount of file systems + +# "panic: userret: Returning with 1 locks held" seen: +# https://people.freebsd.org/~pho/stress/log/mark165.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +cont=/tmp/msdos6.continue +mdstart=$mdstart # Use md unit numbers from this point + +if [ $# -eq 0 ]; then + touch $cont + mycc -o /tmp/fstool -Wall -Wextra -O2 ../tools/fstool.c || exit 1 + 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 + + mdconfig -a -t swap -s 1g -u $m + bsdlabel -w md$m auto + newfs_msdos -F 32 -b 8192 /dev/md${m}$part > /dev/null 2>&1 + mount -t msdosfs /dev/md${m}$part ${mntpoint}$m + (mkdir ${mntpoint}$m/test$i; cd ${mntpoint}$m/test$i; /tmp/fstool -l -f 100 -n 100 -s ${i}k) + umount ${mntpoint}$m > /dev/null 2>&1 + done + + # start the parallel tests + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + ./$0 $m & + ./$0 find & + done + + wait + + for i in `jot $mounts`; do + m=$(( i + mdstart - 1 )) + mdconfig -d -u $m + done + rm -f /tmp/fstool + +else + if [ $1 = find ]; then + while [ -r $cont ]; do + find ${mntpoint}* -type f > /dev/null 2>&1 + done + else + + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt 300 ]; do + m=$1 + mount -t msdosfs /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 $cont + fi +fi diff --git a/tools/test/stress2/misc/msdos7.sh b/tools/test/stress2/misc/msdos7.sh new file mode 100755 index 000000000000..7bebe3703848 --- /dev/null +++ b/tools/test/stress2/misc/msdos7.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC Isilon +# 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. +# + +# Run misc/datamove.sh on a msdos fs. +# Thread waiting on "msdosfs". +# https://people.freebsd.org/~pho/stress/log/kostik958.txt +# Fixed by r308025. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep -q "on $mntpoint " && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs_msdos -F 32 -b 8192 /dev/md${mdstart}$part > /dev/null || exit 1 +mount -t msdosfs /dev/md${mdstart}$part $mntpoint + +here=`pwd` +cd /tmp +sed "1,/^EOF/d" < $here/datamove.sh > msdos7.c +mycc -o msdos7 -Wall msdos7.c +rm -f msdos7.c + +(cd $mntpoint; /tmp/msdos7) + +umount $mntpoint +mdconfig -d -u $mdstart +rm -f /tmp/msdos7 +exit 0 diff --git a/tools/test/stress2/misc/msdos8.sh b/tools/test/stress2/misc/msdos8.sh new file mode 100755 index 000000000000..58f0390e195d --- /dev/null +++ b/tools/test/stress2/misc/msdos8.sh @@ -0,0 +1,157 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# msdosfs rename scenario +# "Invalid long filename entry" seen from fsck + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -x /sbin/mount_msdosfs ] || exit 0 +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/msdos8.c +cc -o msdos8 -Wall -Wextra -O0 -g msdos8.c || exit 1 +rm -f msdos8.c +cd $odir +log=/tmp/msdos8.sh.log +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}$part #> /dev/null +mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1 + +(cd $mntpoint; /tmp/msdos8) +s=$? + +while mount | grep "$mntpoint" | grep -q md$mdstart; do + umount $mntpoint || sleep 1 +done +fsck -t msdosfs -y /dev/md${mdstart}$part > $log 2>&1 +if egrep -q "BAD|INCONSISTENCY|MODIFIED" $log; then + cat $log + s=1 + + mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1 + ls -lR $mntpoint + umount $mntpoint +fi +mdconfig -d -u $mdstart +rm /tmp/msdos8 $log +s=0 # Ignore for now +exit $s +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +# define PARALLEL 10 + +static unsigned long size; + +static void +test(void) +{ + pid_t pid; + int fd, i, j; + char file1[128], file2[128]; + + pid = getpid(); + for (i = 0; i < (int)size; i++) { + sprintf(file1,"p%05d.%05d", pid, i); + if ((fd = open(file1, O_RDONLY|O_CREAT, 0660)) == -1) + err(1, "openat(%s), %s:%d", file1, __FILE__, + __LINE__); + close(fd); + } + for (j = 0; j < 100; j++) { + for (i = 0; i < (int)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 < (int)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 < (int)size; i++) { + sprintf(file1,"p%05d.%05d", pid, i); + if (unlink(file1) == -1) + err(1, "unlink(%s), %s:%d", file1, __FILE__, + __LINE__); + } + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + time_t start; + int e, i, status; + + e = 0; + size = 5; + start = time(NULL); + while ((time(NULL) - start) < 60 && e == 0) { + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (WIFSIGNALED(status)) + fprintf(stderr, "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/msdos9.sh b/tools/test/stress2/misc/msdos9.sh new file mode 100755 index 000000000000..cafabc546aa9 --- /dev/null +++ b/tools/test/stress2/misc/msdos9.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# fsx test of with msdosfs and a 1k block size +# "panic: Assertion ma[i]->dirty == VM_PAGE_BITS_ALL failed" seen. +# Fixed by r324794 + +# Original test scenario by fsu@freebsd.org + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +[ -r /usr/src/tools/regression/fsx/fsx.c ] || exit 0 + +[ -x /sbin/mount_msdosfs ] || exit 0 +dir=/tmp +odir=`pwd` +cd $dir +cc -o fsx -Wall -Wextra -O2 -g /usr/src/tools/regression/fsx/fsx.c || exit 1 +rm -f fsx.c +cd $odir +log=/tmp/fsx.sh.log +mount | grep "$mntpoint" | grep -q md$mdstart && umount -f $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +set -e +mdconfig -a -t swap -s 4g -u $mdstart +bsdlabel -w md$mdstart auto +newfs_msdos -b 1024 /dev/md${mdstart}$part > /dev/null +mount -t msdosfs /dev/md${mdstart}$part $mntpoint +set +e + +cp /tmp/fsx $mntpoint + +cd $mntpoint +./fsx -S 2016 -N 2000 ./TEST_FILE > /dev/null +cd / + +while mount | grep "$mntpoint" | grep -q md$mdstart; do + umount $mntpoint || sleep 1 +done +fsck -t msdosfs -y /dev/md${mdstart}$part > $log 2>&1 +if egrep -q "BAD|INCONSISTENCY|MODIFIED" $log; then + cat $log + s=1 + + mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1 + ls -lR $mntpoint + umount $mntpoint +fi +mdconfig -d -u $mdstart +rm /tmp/fsx $log +exit $s diff --git a/tools/test/stress2/misc/msetdomain.sh b/tools/test/stress2/misc/msetdomain.sh new file mode 100755 index 000000000000..53e792be52e5 --- /dev/null +++ b/tools/test/stress2/misc/msetdomain.sh @@ -0,0 +1,144 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# msetdomain(2) fuzz test. +# No problems seen. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +nm /usr/lib/libc.a | grep -q __sys_msetdomain || exit 0 +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/msetdomain.c +mycc -o msetdomain -Wall -Wextra -O0 -g msetdomain.c || exit 1 +rm -f msetdomain.c +cd $odir + +$dir/msetdomain +s=$? +[ -f msetdomain.core -a $s -eq 0 ] && + { ls -l msetdomain.core; mv msetdomain.core /tmp; s=1; } +rm -rf $dir/msetdomain +exit $s + +EOF +#include +#include +#include +#include +#include + +#include +#include +#include + +/* +struct msetdomain_args { + void *addr; + size_t size; + size_t domainsetsize; + domainset_t *mask; + int policy; + int flags; +*/ + +static long +random_long(long mi, long ma) +{ + return (arc4random() % (ma - mi + 1) + mi); +} + +void +flip(void *ap, size_t len) +{ + unsigned char *cp; + int byte; + unsigned char bit, buf, mask, old; + + cp = (unsigned char *)ap; + byte = random_long(0, len); + bit = random_long(0,7); + mask = ~(1 << bit); + buf = cp[byte]; + old = cp[byte]; + buf = (buf & mask) | (~buf & ~mask); + cp[byte] = buf; +} + +int +main(void) +{ + size_t len; + time_t start; + void *share; + domainset_t rootmask; + int flags, policy; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while (time(NULL) - start < 60) { + if (cpuset_getdomain(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1, + sizeof(rootmask), &rootmask, &policy) != 0) + err(EXIT_FAILURE, "getdomain"); + + flags = 0; + flip(&flags, sizeof(flags)); + msetdomain(share, len, sizeof(rootmask), &rootmask, policy, + flags); + } + + start = time(NULL); + while (time(NULL) - start < 60) { + if (cpuset_getdomain(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1, + sizeof(rootmask), &rootmask, &policy) != 0) + err(EXIT_FAILURE, "getdomain"); + + flip(&policy, sizeof(policy)); + msetdomain(share, len, sizeof(rootmask), &rootmask, policy, + flags); + } + + start = time(NULL); + while (time(NULL) - start < 60) { + if (cpuset_getdomain(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1, + sizeof(rootmask), &rootmask, &policy) != 0) + err(EXIT_FAILURE, "getdomain"); + + flip(&rootmask, sizeof(rootmask)); + msetdomain(share, len, sizeof(rootmask), &rootmask, policy, + flags); + } + + return (0); +} diff --git a/tools/test/stress2/misc/msync.sh b/tools/test/stress2/misc/msync.sh new file mode 100755 index 000000000000..326c7e723774 --- /dev/null +++ b/tools/test/stress2/misc/msync.sh @@ -0,0 +1,201 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# msync(2) / mlockall(2) test scenario. +# "panic: vm_fault_copy_wired: page missing" seen. +# http://people.freebsd.org/~pho/stress/log/msync.txt +# Fixed in r253189. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/msync.c +mycc -o msync -Wall -Wextra msync.c -lpthread || exit 1 +rm -f msync.c +cd $odir + +/tmp/msync & +sleep 180 +while pkill -9 msync; do :; done +wait +rm -f /tmp/msync +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int syscallno = SYS_msync; +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +u_int32_t r[N]; + +static void +hand(int i __unused) { /* handler */ + _exit(1); +} + +unsigned long +makearg(void) +{ + unsigned int i; + unsigned long val; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +calls(void *arg __unused) +{ + int i, num; + unsigned long arg1, arg2, arg3; + + usleep(1000); + num = syscallno; + for (i = 0; i < 500; i++) { + arg1 = makearg(); + arg2 = makearg(); +#if 0 + arg3 = makearg(); + arg3 = arg3 & ~MS_INVALIDATE; /* No problem seen */ +#else + arg3 = MS_INVALIDATE; /* panic */ +#endif + +#if 0 + fprintf(stderr, "%2d : syscall(%3d, 0x%lx, 0x%lx, 0x%lx)\n", + i, num, arg1, arg2, arg3); + usleep(50000); +#endif + alarm(1); + syscall(num, arg1, arg2, arg3); + num = 0; + } + + return (0); +} +void +wd(void) +{ + int i; + + if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) + err(1, "mlockall failed"); + + for (i = 0; i < 800; i++) { + if (fork() == 0) { + usleep(20000); + _exit(0); + } + wait(NULL); + usleep(100000); + } + + _exit(0); +} + +int +main(void) +{ + struct passwd *pw; + pthread_t cp[50]; + int e, i, j; + + if (fork() == 0) + wd(); + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + signal(SIGALRM, hand); + signal(SIGILL, hand); + signal(SIGFPE, hand); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + signal(SIGURG, hand); + signal(SIGSYS, hand); + signal(SIGTRAP, hand); + + alarm(180); + for (i = 0; i < 8000; i++) { + if (fork() == 0) { + for (j = 0; j < N; j++) + r[j] = arc4random(); + for (j = 0; j < 50; j++) + if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) + errc(1, e, "pthread_create"); + + for (j = 0; j < 50; j++) + pthread_join(cp[j], NULL); + _exit(0); + } + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/msync2.sh b/tools/test/stress2/misc/msync2.sh new file mode 100755 index 000000000000..c1a9e4f0e372 --- /dev/null +++ b/tools/test/stress2/misc/msync2.sh @@ -0,0 +1,131 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# "panic: vm_pageout_flush: partially invalid page xx index 0/1" seen. +# Fixed in r255566. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/msync2.c +mycc -o msync2 -Wall -Wextra msync2.c || exit 1 +rm -f msync2.c +cd $odir + +dd if=/dev/zero bs=$((4096 + 1)) of=/tmp/msync2.inputfile count=1 \ + status=none +/tmp/msync2 /tmp/msync2.inputfile +rm -f /tmp/msync2 /tmp/msync2.inputfile +exit + +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define RUNTIME 400 + +const char *file; +char c; + +void +wr(void) +{ + struct stat st; + char *p1; + size_t len; + int error, fd; + + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open %s", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = round_page(st.st_size); + if ((p1 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == + MAP_FAILED) + err(1, "mmap"); +// p1[len - 1] = 1; /* No panic with this */ + p1[arc4random() % len] = 1; /* Need this for the panic */ + + if ((error = msync(p1, len, MS_SYNC | MS_INVALIDATE)) == -1) + if (errno != EBUSY) + err(1, "msync"); + + if (munmap(p1, len) == -1) + err(1, "unmap()"); + close(fd); + + _exit(0); +} + +void +test(void) +{ +#if 1 + int i; + + for (i = 0; i < 3; i++) + if (fork() == 0) + wr(); + for (i = 0; i < 3; i++) + wait(NULL); +#else + wr(); /* No problem here */ +#endif + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + time_t start; + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if (fork() == 0) + test(); + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/multicast.sh b/tools/test/stress2/misc/multicast.sh new file mode 100755 index 000000000000..d95a55cef918 --- /dev/null +++ b/tools/test/stress2/misc/multicast.sh @@ -0,0 +1,118 @@ +#!/bin/sh + +# Multicast test example by Mark Claypool, claypool at cs.wpi.edu +# https://web.cs.wpi.edu/~claypool/courses/4514-B99/samples/multicast.c + +# Kernel page fault seen with WiP branch: +# https://people.freebsd.org/~pho/stress/log/kip036.txt + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/multicast.c +mycc -o multicast -Wall -Wextra -O0 -g multicast.c || exit 1 +rm -f multicast.c +cd $odir + +cd $dir +( + timeout -k 1s 20s ./multicast & + sleep 1 + timeout -k 1s 25s ./multicast 1 +) > /dev/null +wait + +rm -f $dir/multicast +exit $s +EOF +/* +multicast.c + +The following program sends or receives multicast packets. If invoked +with one argument, it sends a packet containing the current time to an +arbitrarily chosen multicast group and UDP port. If invoked with no +arguments, it receives and prints these packets. Start it as a sender on +just one host and as a receiver on all the other hosts + +*/ + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#define EXAMPLE_PORT 6000 +#define EXAMPLE_GROUP "239.0.0.1" + +int +main(int argc, char *argv[] __unused) +{ + struct ip_mreq mreq; + struct sockaddr_in addr; + socklen_t addrlen; + int cnt, sock; + char message[50]; + + /* set up socket */ + sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) { + perror("socket"); + exit(1); + } + bzero((char *)&addr, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = htonl(INADDR_ANY); + addr.sin_port = htons(EXAMPLE_PORT); + addrlen = sizeof(addr); + + if (argc > 1) { + /* send */ + addr.sin_addr.s_addr = inet_addr(EXAMPLE_GROUP); + while (1) { + time_t t = time(0); + sprintf(message, "time is %-24.24s", ctime(&t)); + printf("sending: %s\n", message); + cnt = sendto(sock, message, sizeof(message), 0, + (struct sockaddr *) &addr, addrlen); + if (cnt < 0) { + perror("sendto"); + exit(1); + } + sleep(5); + } + } else { + + /* receive */ + if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + perror("bind"); + exit(1); + } + mreq.imr_multiaddr.s_addr = inet_addr(EXAMPLE_GROUP); + mreq.imr_interface.s_addr = htonl(INADDR_ANY); + if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, + &mreq, sizeof(mreq)) < 0) { + perror("setsockopt mreq"); + exit(1); + } + while (1) { + cnt = recvfrom(sock, message, sizeof(message), 0, + (struct sockaddr *) &addr, &addrlen); + if (cnt < 0) { + perror("recvfrom"); + exit(1); + } else if (cnt == 0) { + break; + } + printf("%s: message = \"%s\"\n", inet_ntoa(addr.sin_addr), message); + } + } +} diff --git a/tools/test/stress2/misc/multicast2.sh b/tools/test/stress2/misc/multicast2.sh new file mode 100755 index 000000000000..bd95cd0bd9e6 --- /dev/null +++ b/tools/test/stress2/misc/multicast2.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# D19886 Fix numerous refcount bugs in multicast + +# Page fault in in6_pcbpurgeif0+0xc8 seen. +# https://people.freebsd.org/~pho/stress/log/mmacy035.txt +# Test scenario by mmacy + +# Fixed by r349507 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -x /usr/local/bin/mDNSResponderPosix ] || + { echo "mDNSResponder not installed"; exit 0; } + +(cd ../testcases/swap; ./swap -t 2m -i 50 -v -h -l 100) & +sleep 2 + +service mdnsd onestart +ifconfig vtnet0 delete 2>/dev/null +ifconfig epair create +ifconfig epair0a 0/24 up +ifconfig epair0a destroy +service mdnsd onestop + +while pkill swap; do :; done +wait diff --git a/tools/test/stress2/misc/namecache.sh b/tools/test/stress2/misc/namecache.sh new file mode 100755 index 000000000000..6ca790b297f8 --- /dev/null +++ b/tools/test/stress2/misc/namecache.sh @@ -0,0 +1,214 @@ +#!/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 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 +mycc -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 + +start=`date '+%s'` +for i in `jot 30`; do + for j in `jot 10`; do + /tmp/namecache & + done + + for j in `jot 10`; do + wait + done + [ $((`date '+%s'` - start)) -gt 1200 ] && break +done + +if ls -l $dir/file.0* 2>&1 | egrep "file.0[0-9]" | grep -q "No such file"; then + echo FAIL + 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; + off_t 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 %7ju, " + "type %2d, namelen %d, d_reclen %d\n", + dp->d_name, (uintmax_t)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/tools/test/stress2/misc/namecache2.sh b/tools/test/stress2/misc/namecache2.sh new file mode 100755 index 000000000000..a5dd4319fc66 --- /dev/null +++ b/tools/test/stress2/misc/namecache2.sh @@ -0,0 +1,192 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# UFS cache inconsistancy for rename(2) demonstrated +# Fails with: +# ls -ali /mnt +# ls: tfa1022: No such file or directory +# Fixed by r248422 + +# Test scenario obtained from Rick Miller + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# This threaded test is designed for MP. +[ `sysctl hw.ncpu | sed 's/.* //'` -eq 1 ] && exit 0 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > namecache2.c +rm -f /tmp/namecache2 +mycc -o namecache2 -Wall -Wextra -g -O2 namecache2.c -lpthread || exit 1 +rm -f namecache2.c +cd $odir + +mount | grep $mntpoint | grep -q /dev/md && 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +(cd $mntpoint; /tmp/namecache2) + +f=`(cd $mntpoint; echo *)` +if [ "$f" != '*' ]; then + echo FAIL + echo "echo $mntpoint/*" + echo $mntpoint/* + echo "" + echo "ls -ali $mntpoint" + ls -ali $mntpoint + echo "" + echo "fsdb -r /dev/md${mdstart}$part" + fsdb -r /dev/md${mdstart}$part <<-EF + ls + quit + EF +fi + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/namecache2 +exit 0 +EOF +/* + * NOTE: This must be run with the current working directory on a local UFS + * disk partition, to demonstrate a FreeBSD namecache bug. I have never seen + * this bug happen with an NFS partition. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int stopping = false; +char *pFilename = 0; + +static void * +statThread(void *arg __unused) +{ + + struct stat statData; + int rc; + + for (;;) { + while (pFilename == 0) { + if (stopping) + return 0; + } + + rc = stat(pFilename, &statData); + if (rc < 0 && errno != ENOENT) { + printf(" statThread stat() on %s failed with errno %d\n", + pFilename, errno); + return 0; + } + } + + return 0; +} + +int +main(void) +{ + char filename1 [20], filename2[20], filename3[20]; + pthread_t threadId; + struct stat statData; + int result, fd; + unsigned int number; + struct timespec period; + time_t start; + + sprintf(filename1, "tfa0"); + fd = open(filename1, O_CREAT, S_IRWXU); + if (fd < 0) { + printf("open(O_CREAT) on %s failed with errno %d\n", filename1, errno); + return 0; + } + if (close(fd) < 0) { + printf("close() on %s failed with errno %d\n", filename1, errno); + return 0; + } + result = pthread_create(&threadId, NULL, statThread, NULL); + if (result < 0) + errc(1, result, "pthread_create()"); + + start = time(NULL); + for (number = 0; number < 0x001FFFFF; number += 2) { + sprintf(filename1, "tfa%u", number); + sprintf(filename2, "tfa%u", number + 1); + sprintf(filename3, "tfa%u", number + 2); + if (rename(filename1, filename2) < 0) { + printf(" rename1() from %s to %s failed with errno %d\n", + filename1, filename2, errno); + return 0; + } + pFilename = filename3; + + if (rename(filename2, filename3) < 0) { + printf(" rename2() from %s to %s failed with errno %d\n", + filename2, filename3, errno); + return 0; + } + pFilename = 0; + period.tv_sec = 0; + period.tv_nsec = 500; + nanosleep(&period, 0); + + if (stat(filename3, &statData) < 0) { + printf("stat(%s) failed with errno %d\n", filename3, errno); + stopping = true; + period.tv_sec = 0; + period.tv_nsec = 500; + nanosleep(&period, 0); + return 0; + } + if (time(NULL) - start > 1200) { + fprintf(stderr, "Test timed out.\n"); + break; + } + } + unlink(filename3); + + return 0; +} diff --git a/tools/test/stress2/misc/nanosleep.sh b/tools/test/stress2/misc/nanosleep.sh new file mode 100755 index 000000000000..79e2d505fb47 --- /dev/null +++ b/tools/test/stress2/misc/nanosleep.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# A simplistic regression test for r200510: + +[ `sysctl -n kern.hz` -lt 1000 ] && exit 0 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > nanosleep.c +mycc -o nanosleep -Wall -Wextra nanosleep.c || exit 1 +rm -f nanosleep.c + +/tmp/nanosleep && s=0 || s=$? + +rm -f /tmp/nanosleep +exit $s +EOF +#include +#include + +#include +#include +#include +#include + +#define N 20000 + +int +main(void) +{ + struct timespec rmt, rqt; + struct timespec finish, start, res; + long m; + int i; + + m = LONG_MAX; + for (i = 0; i < 100; i++) { + rqt.tv_sec = 0; + rqt.tv_nsec = N; + clock_gettime(CLOCK_REALTIME_PRECISE, &start); + if (nanosleep(&rqt, &rmt) == -1) + err(1, "nanosleep"); + clock_gettime(CLOCK_REALTIME_PRECISE, &finish); + timespecsub(&finish, &start, &res); + if (res.tv_nsec < N) + errx(1, "Short sleep: %ld", res.tv_nsec); +// fprintf(stderr, "asked for %f, got %f\n", (double)N / 1e9, +// (double)res.tv_nsec / 1e9); + if (m > res.tv_nsec) + m = res.tv_nsec; + } + if (m > 2 * N) { + fprintf(stderr, "nanosleep(%fs). Best value is %fs.\n", + (double)N / 1e9, (double)m / 1e9); + errx(1, "FAIL"); + } + + return (0); +} diff --git a/tools/test/stress2/misc/nbufkv.sh b/tools/test/stress2/misc/nbufkv.sh new file mode 100755 index 000000000000..db2c45feb496 --- /dev/null +++ b/tools/test/stress2/misc/nbufkv.sh @@ -0,0 +1,156 @@ +#!/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 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 + +dir=`dirname $diskimage` +d1=$dir/diskimage1 +d2=$dir/diskimage2 +rm -f $d1 $d2 + +size=20 # G +avail=$((`sysctl -n hw.physmem` / 1024 / 1024 / 1024)) +[ $((size * 2)) -gt $avail ] && size=$((avail / 2)) +[ `df -k $dir | tail -1 | awk '{print $4}'` -lt \ + $((size * 2 * 1024 * 1024)) ] && + echo "Not enough disk space on $dir." && exit 0 + +odir=`pwd` + +USE_TIMEOUT=1 +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > nbufkv.c +mycc -o nbufkv -Wall nbufkv.c +rm -f nbufkv.c +cd $odir + +u1=$mdstart +u2=$((u1 + 1)) +mp1=$mntpoint +mp2=${mntpoint}2 +[ -d $mp1 ] || mkdir $mp1 +[ -d $mp2 ] || mkdir $mp2 +dd if=/dev/zero of=$d1 bs=1m count=${size}k status=none || exit 1 +cp $d1 $d2 || exit 1 + +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 +[ -c /dev/md$u2 ] && mdconfig -d -u $u2 +[ -c /dev/md$u1 ] && mdconfig -d -u $u1 + +mdconfig -a -t vnode -f $d1 -u $u1 || exit 1 +bsdlabel -w md$u1 auto +newfs -b 65536 -f 65536 -O2 md${u1}$part > /dev/null + +mdconfig -a -t vnode -f $d2 -u $u2 || exit 1 +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 $mp1 & +/tmp/nbufkv $mp2 & +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 $d1 $d2 /tmp/nbufkv +exit +EOF +#include + +#include +#include +#include +#include +#include +#include + +void +handler(int i) { + fprintf(stderr, "FAIL. Timerout.\n"); + _exit(0); +} + +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(%s)", path); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate"); + + signal(SIGALRM, handler); + alarm(1200); + work(fd, len); + + close(fd); + if (unlink(path) == -1) + err(1, "unlink(%s)", path); + + return (0); +} diff --git a/tools/test/stress2/misc/newfs.sh b/tools/test/stress2/misc/newfs.sh new file mode 100755 index 000000000000..8ef7b9eae31e --- /dev/null +++ b/tools/test/stress2/misc/newfs.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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. +# + +# A few UFS1 newfs combinations are known to cause fsck(8) to fail. +# Ignore these for now. Will be fixed: +# newfs -O1 -b 65536 -f 8192 +# newfs -O1 -b 65536 -f 16384 +# newfs -O1 -b 65536 -f 32768 +# newfs -O1 -b 65536 -f 65536 + +[ `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 1g -u $mdstart +bsdlabel -w md$mdstart auto + +echo "Expect warnings from SU and SU+J." +log=/tmp/newfs.sh.log +s=0 +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10s +export RUNTIME=$runRUNTIME +export CTRLDIR=$mntpoint/stressX.control +start=`date '+%s'` +for opt in -O1 -O2 -U -j; do + echo "Testing newfs with option $opt." + blocksize=4096 + while [ $blocksize -le 65536 ]; do + for i in 8 4 2 1; do + fragsize=$((blocksize / i)) + newfs $opt -b $blocksize -f $fragsize \ + md${mdstart}$part > /dev/null 2>&1 || continue + mount /dev/md${mdstart}$part $mntpoint + chmod 777 $mntpoint + rm -rf /tmp/stressX.control + su $testuser -c \ + "(cd ..; ./run.sh disk.cfg > /dev/null 2>&1)" & + sleep 10 + ../tools/killall.sh + wait + while mount | grep "$mntpoint" | \ + grep -q md${mdstart}$part; do + umount $mntpoint > /dev/null 2>&1 || sleep 1 + done + checkfs /dev/md${mdstart}$part > $log 2>&1 || { + cmd="newfs $opt -b $blocksize -f $fragsize" +# if ! grep -q -- "$cmd" $0; then + s=1 + echo "$cmd" + cat $log +# fi + } + done + blocksize=$((blocksize * 2)) + done + if [ $((`date '+%s'` - start)) -gt 1200 ]; then + echo "Timed out" + s=1 + break + fi +done +mdconfig -d -u $mdstart +rm -f $log +exit $s diff --git a/tools/test/stress2/misc/newfs2.sh b/tools/test/stress2/misc/newfs2.sh new file mode 100755 index 000000000000..ac891e7926fb --- /dev/null +++ b/tools/test/stress2/misc/newfs2.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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. +# + +# 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 -q md${mdstart}$part && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +s=0 +start=`date '+%s'` +while [ $size -le $((900 * 1024 * 1024)) ]; do + mb=$((size / 1024 / 1024)) + rm -f $diskimage + dd if=/dev/zero of=$diskimage bs=1m count=$mb status=none + mdconfig -a -t vnode -f $diskimage -u $mdstart || + { rm $diskimage; exit 1; } + bsdlabel -w md$mdstart auto + newfs -b 32768 -f 4096 -O2 md${mdstart}$part > /dev/null 2>&1 + mount /dev/md${mdstart}$part $mntpoint + export RUNDIR=$mntpoint/stressX + export runRUNTIME=30s + export RUNTIME=$runRUNTIME + export CTRLDIR=$mntpoint/stressX.control + (cd ..; ./run.sh disk.cfg) > /dev/null + while mount | grep "$mntpoint" | grep -q md${mdstart}$part; do + umount $mntpoint > /dev/null 2>&1 + done + checkfs md${mdstart}$part || s=1 + mdconfig -d -u $mdstart + size=$((size + 32 * 1024 * 1024)) + if [ $((`date '+%s'` - start)) -gt 1200 ]; then + echo "Timed out" + s=1 + break + fi +done +rm -f $diskimage +exit $s diff --git a/tools/test/stress2/misc/newfs3.sh b/tools/test/stress2/misc/newfs3.sh new file mode 100755 index 000000000000..f6dd84e801bc --- /dev/null +++ b/tools/test/stress2/misc/newfs3.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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. +# + +# 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 -q md${mdstart}$part && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +s=0 +while [ $size -le $((128 * 1024 * 1024)) ]; do + mb=$((size / 1024 / 1024)) + rm -f $diskimage + dd if=/dev/zero of=$diskimage bs=1m count=$mb status=none + mdconfig -a -t vnode -f $diskimage -u $mdstart || + { rm -f $diskimage; exit 1; } + bsdlabel -w md$mdstart auto + blocksize=4096 + while [ $blocksize -le 65536 ]; do + for i in 1 2 4 8; do + fragsize=$((blocksize / i)) + 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=15s + export RUNTIME=$runRUNTIME + export CTRLDIR=$mntpoint/stressX.control + (cd ..; ./run.sh disk.cfg) > /dev/null 2>&1 & + sleep 15 + ../tools/killall.sh + wait + while mount | grep "$mntpoint" | \ + grep -q md${mdstart}$part; do + umount $mntpoint > /dev/null 2>&1 + done + checkfs /dev/md${mdstart}$part || s=1 + done + blocksize=$((blocksize * 2)) + done + mdconfig -d -u $mdstart + size=$((size + 32 * 1024 * 1024)) +done +rm -f $diskimage +exit $s diff --git a/tools/test/stress2/misc/newfs4.sh b/tools/test/stress2/misc/newfs4.sh new file mode 100755 index 000000000000..46d563a49460 --- /dev/null +++ b/tools/test/stress2/misc/newfs4.sh @@ -0,0 +1,128 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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 -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. + +# Threads stuck in newbuf: +# https://people.freebsd.org/~pho/stress/log/newfs4-2.txt + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > newfs4.c +mycc -o newfs4 -Wall -Wextra newfs4.c || exit 1 +rm -f newfs4.c +cd $odir + +mount | grep "$mntpoint" | grep -q md${mdstart}$part && 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 on `dirname $diskimage`." && exit 1 +trap "rm -f $diskimage" EXIT INT +dd if=/dev/zero of=$diskimage bs=1m count=$((size * 1024)) status=none || + exit 1 + +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/newfs4 f1 & +/tmp/newfs4 f2 & +/tmp/newfs4 f3 & +/tmp/newfs4 f4 & +wait + +while mount | grep "$mntpoint" | grep -q md${mdstart}$part; do + umount -f $mntpoint || sleep 1 +done +checkfs /dev/md${mdstart}$part; s=$? + +mdconfig -d -u $mdstart +rm -f /tmp/newfs4 +exit $s + +EOF +#include +#include + +#include +#include +#include +#include +#include + +/* Perform random IO operations on a file */ + +int +main(int argc, char **argv) +{ + struct stat sb; + off_t bp, maxb; + long i; + int fd; + char buf[256]; + + 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; + + 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/tools/test/stress2/misc/newfs5.sh b/tools/test/stress2/misc/newfs5.sh new file mode 100755 index 000000000000..f41da12e28dd --- /dev/null +++ b/tools/test/stress2/misc/newfs5.sh @@ -0,0 +1,116 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# Variation of newfs4.sh, using a swap backed MD disk + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > newfs5.c +mycc -o newfs5 -Wall -Wextra newfs5.c +rm -f newfs5.c +cd $odir + +mount | grep "$mntpoint" | grep md${mdstart}$part > /dev/null && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +blocksize="-b 65536" +opt="-O2 -U" +size=9 # Gb +mdconfig -a -t swap -s ${size}g -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/newfs5 f1 & +/tmp/newfs5 f2 & +/tmp/newfs5 f3 & +/tmp/newfs5 f4 & +wait + +while mount | grep "$mntpoint" | grep -q md${mdstart}$part; do + umount -f $mntpoint || sleep 1 +done +checkfs /dev/md${mdstart}$part; s=$? + +mdconfig -d -u $mdstart +rm -f $diskimage +rm -f /tmp/newfs5 +exit $s + +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; + + 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/tools/test/stress2/misc/nfs.sh b/tools/test/stress2/misc/nfs.sh new file mode 100755 index 000000000000..a38745ce1cc3 --- /dev/null +++ b/tools/test/stress2/misc/nfs.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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. +# + +# No problems seen with this test + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint + +export RUNDIR=$mntpoint/nfs.`jot -rc 8 a z | tr -d '\n'`/stressX +export runRUNTIME=10m + +mkdir -p $RUNDIR +chmod 777 $RUNDIR +su $testuser -c "(cd ..; ./run.sh disk.cfg)" 2>/dev/null +su $testuser -c "rm -rf $RUNDIR 2>/dev/null" +rm -rf $RUNDIR + +umount $mntpoint +while mount | grep "$mntpoint " | grep -q nfs; do + umount -f $mntpoint +done +exit 0 diff --git a/tools/test/stress2/misc/nfs10.sh b/tools/test/stress2/misc/nfs10.sh new file mode 100755 index 000000000000..15f449548f45 --- /dev/null +++ b/tools/test/stress2/misc/nfs10.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# nfsv4 test scenario +# Deadlock seen: http://people.freebsd.org/~pho/stress/log/nfs10.txt +# Lock violation: http://people.freebsd.org/~pho/stress/log/nfs10-2.txt +# Double fault: http://people.freebsd.org/~pho/stress/log/nfs10-3.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +grep -q $mntpoint /etc/exports || + { echo "$mntpoint missing from /etc/exports"; exit 0; } + +m2=${mntpoint}2 +[ -d $m2 ] || mkdir $m2 +mount | grep "on $m2 " | grep -q nfs && umount $m2 +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +mount -t nfs -o nfsv4 -o rw,retrycnt=3 127.0.0.1:$mntpoint $m2 + +export RUNDIR=$m2/stressX +export runRUNTIME=10m # Run tests for 10 minutes + +su $testuser -c "(cd ..; ./run.sh marcus.cfg)" & +sleep 300 +umount $m2 2>/dev/null # Test umount of active FS while here +wait + +while mount | grep "on $m2 " | grep -q nfs; do + umount $m2 +done + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/nfs11.sh b/tools/test/stress2/misc/nfs11.sh new file mode 100755 index 000000000000..e132ad9f894e --- /dev/null +++ b/tools/test/stress2/misc/nfs11.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# nfsv4 test scenario + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +grep -q $mntpoint /etc/exports || + { echo "$mntpoint missing from /etc/exports"; exit 0; } + +m2=${mntpoint}2 +[ -d $m2 ] || mkdir $m2 +mount | grep "on $m2 " | grep -q nfs && umount $m2 +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +mount -t nfs -o nfsv4 -o rw,retrycnt=3 127.0.0.1:$mntpoint $m2 + +export RUNDIR=$m2/stressX +export runRUNTIME=10m # Run tests for 10 minutes + +su $testuser -c "(cd ..; ./run.sh marcus.cfg)" + +while mount | grep "on $m2 " | grep -q nfs; do + umount $m2 +done + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/nfs12.sh b/tools/test/stress2/misc/nfs12.sh new file mode 100755 index 000000000000..e1b6e2c9279e --- /dev/null +++ b/tools/test/stress2/misc/nfs12.sh @@ -0,0 +1,160 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# "umount -f" test scenario (distill of nfs4.sh) +# "panic: vputx: missed vn_close" seen. +# Fixed in r248815 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > nfs12.c +mycc -o nfs12 -Wall -Wextra -O2 -g nfs12.c +rm -f nfs12.c +cd $here + +mount | grep "on $mntpoint " | grep nfs > /dev/null && umount $mntpoint +version="-o nfsv3" # The default +[ $# -eq 1 ] && [ "$1" -eq 4 ] && version="-o nfsv4" +for i in `jot 10`; do + mount -t nfs $version -o tcp -o retrycnt=3 -o intr,soft -o rw \ + $nfs_export $mntpoint + sleep 2 + + if [ $i -eq 10 ]; then + rm -f $mntpoint/nfs12.p* + else + (cd $mntpoint; /tmp/nfs12 > /dev/null 2>&1) & + sleep 2 + fi + + while mount | grep "on $mntpoint " | grep -q nfs; do + umount -f $mntpoint + done + kill -9 $! > /dev/null 2>/dev/null && kill $! + wait +done + +rm -f /tmp/nfs12 +exit +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define INPUTFILE "/bin/date" +#define PARALLEL 5 + +static int +tmmap(void) +{ + struct stat statbuf; + pid_t pid; + char *src, *dst; + int i; + int fdin, fdout; + char file[128]; + + pid = getpid(); + setproctitle("mmap"); + for (i = 0; i < 50000; i++) { + sprintf(file,"nfs12.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); + } + + _exit(0); +} + +int +main(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + tmmap(); + } + + for (i = 0; i < PARALLEL; i++) { + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/nfs13.sh b/tools/test/stress2/misc/nfs13.sh new file mode 100755 index 000000000000..fb65b8a64044 --- /dev/null +++ b/tools/test/stress2/misc/nfs13.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# nfs loopback mount of a tmpfs file system. +# "[tcp] 127.0.0.1:/mnt: Permission denied" seen. + +# " mount_nfs hangs in mntref" seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +grep -q $mntpoint /etc/exports 2>/dev/null || + { echo "$mntpoint missing from /etc/exports"; exit 0; } + +s=0 +m2=${mntpoint}2 +[ -d $m2 ] || mkdir $m2 +mount | grep "on $m2 " | grep -q nfs && umount $m2 +mount | grep "on $mntpoint " | grep -q tmpfs && umount -f $mntpoint + +mount -o size=1g -t tmpfs tmpfs $mntpoint || s=1 +chmod 777 $mntpoint + +[ $s -eq 0 ] && + mount -t nfs -o tcp -o rw,retrycnt=1 127.0.0.1:$mntpoint $m2 || s=2 + +export RUNDIR=$m2/stressX +export runRUNTIME=10m # Run tests for 10 minutes + +[ $s -eq 0 ] && + su $testuser -c "(cd ..; ./run.sh marcus.cfg)" + +while mount | grep "on $m2 " | grep -q nfs; do + umount $m2 +done + +while mount | grep "on $mntpoint " | grep -q tmpfs; do + umount $mntpoint || sleep 1 +done +exit $s diff --git a/tools/test/stress2/misc/nfs14.sh b/tools/test/stress2/misc/nfs14.sh new file mode 100755 index 000000000000..c3b4152c5af4 --- /dev/null +++ b/tools/test/stress2/misc/nfs14.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Bring the network down and up again during NFS tests. + +# "panic: re_txeof: freeing NULL mbufs!" seen: +# https://people.freebsd.org/~pho/stress/log/nfs14.txt + +# This is a very disruptive test, so be aware! +[ -z "$footshoot" ] && exit 0 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +if=`ifconfig -lu | awk '{print $1}'` +[ -z "$if" ] && exit 0 + +[ ! -d $mntpoint ] && mkdir $mntpoint +mount | grep "on $mntpoint " | grep -q nfs && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o soft \ + -o rw $nfs_export $mntpoint + +sleep .5 +export RUNDIR=$mntpoint/nfs14.`jot -rc 8 a z | tr -d '\n'`/stressX +rm -rf $RUNDIR +mkdir -p $RUNDIR +chmod 777 $RUNDIR +export runRUNTIME=3m +rm -rf /tmp/stressX.control/* + +su $testuser -c '(cd ..; ./run.sh rw.cfg) > /dev/null 2>&1' & + +sleep `jot -r 1 5 15`.`jot -r 1 1 9` +downtime=`jot -r 1 100 150` +echo "Testing with $downtime seconds downtime." +ifconfig $if down; sleep $downtime; ifconfig $if up + +wait +rm -rf $RUNDIR +while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 +done +../tools/killall.sh +exit 0 diff --git a/tools/test/stress2/misc/nfs15.sh b/tools/test/stress2/misc/nfs15.sh new file mode 100755 index 000000000000..33546aba8d4b --- /dev/null +++ b/tools/test/stress2/misc/nfs15.sh @@ -0,0 +1,212 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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 effort to reproduce reported: "observed a hang in a multi-threaded +# process that had hit an assertion failure and was attempting to dump core". +# Problem never seen. + +# Most interesting load are: +# - coredumping of the multithreaded program with the current dir on NFS, +# which also accesses NFS files; +# - advisory locking tests on NFS files, while e.g. sending SIGSTOP/SIGCONT +# to the test programs. + +# See also pthread9.sh + +# https://people.freebsd.org/~pho/stress/log/kostik897.txt +# Fixed in r302013. + +# "panic: mutex sleepq chain not owned at subr_sleepqueue.c:1009" seen: +# https://people.freebsd.org/~pho/stress/log/kostik914.txt +# Fixed in r302328. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +USE_TIMEOUT=1 +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > nfs15.c +mycc -o nfs15 -Wall -Wextra -O2 -g nfs15.c -lpthread || exit 1 +rm -f nfs15.c +cd $here + +mount | grep "on $mntpoint " | grep nfs > /dev/null && umount $mntpoint + +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw -o nolockd \ + $nfs_export $mntpoint || exit 1 +sleep 2 +wd=$mntpoint/nfs15.dir +rm -rf $wd +mkdir $wd + +(cd $wd; /tmp/nfs15) +rm -rf $wd + +while mount | grep "on $mntpoint " | grep -q nfs; do + umount $mntpoint || sleep 1 +done + +rm -f /tmp/nfs15 +exit 0 +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define RUNTIME 300 +#define SYNC 0 + +volatile u_int *share; + +static void * +t1(void *data __unused) +{ + atomic_add_int(&share[SYNC], 1); + usleep(arc4random() % 8000); + raise(SIGABRT); + + return (NULL); +} + +static void * +t2(void *data __unused) +{ + int fd, i, r; + char file[80]; + + for (i = 0; i < 100; i++) { + atomic_add_int(&share[SYNC], 1); + snprintf(file, sizeof(file), "file.%06d", i); + if ((fd = open(file, O_WRONLY | O_CREAT | O_APPEND, + DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + do { + r = lockf(fd, F_LOCK, 0); + } while (r == -1 && errno == EDEADLK); + if (r == -1) + err(1, "lockf(%s, F_LOCK)", file); + write(fd, "x", 1); + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + if (lockf(fd, F_ULOCK, 0) == -1) + err(1, "lockf(%s, F_ULOCK)", file); + close(fd); + } + + return (NULL); +} + +int +test(void) +{ + pthread_t tid[3]; + int i, rc; + + for (i = 0; i < 10; i++) { + if ((rc = pthread_create(&tid[0], NULL, t2, NULL)) == -1) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[1], NULL, t2, NULL)) == -1) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[2], NULL, t1, NULL)) == -1) + errc(1, rc, "pthread_create"); + + if ((rc = pthread_join(tid[0], NULL)) == -1) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[1], NULL)) == -1) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[2], NULL)) == -1) + errc(1, rc, "pthread_join"); + } + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int i, status; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + + for(;;) { + if (share[SYNC] > 0) + atomic_add_int(&share[SYNC], -1); + for (i = 0; i < PARALLEL; i++) + kill(pids[i], SIGSTOP); + usleep(100 + arc4random() % 1000); + for (i = 0; i < PARALLEL; i++) + kill(pids[i], SIGCONT); + usleep(100 + arc4random() % 400); + if (share[SYNC] == 0) { /* If all procs are done */ + usleep(500); + if (share[SYNC] == 0) + break; + } + } + + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) != pids[i]) + err(1, "waitpid"); + } + } + + return (0); +} diff --git a/tools/test/stress2/misc/nfs15lockd.sh b/tools/test/stress2/misc/nfs15lockd.sh new file mode 100755 index 000000000000..8e744b967b18 --- /dev/null +++ b/tools/test/stress2/misc/nfs15lockd.sh @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC Isilon +# 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. +# + +# Demonstrate "wrong handling for suspend". +# https://www.mail-archive.com/freebsd-current@freebsd.org/msg166333.html + +# panic: Failed to register NFS lock locally - error=11 +# https://people.freebsd.org/~pho/stress/log/kostik897.txt +# Fixed in r302013. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +pgrep -q lockd || { echo "lockd not running."; exit 1; } + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > nfs15lockd.c +mycc -o nfs15lockd -Wall -Wextra -O2 -g nfs15lockd.c -lpthread || exit 1 +rm -f nfs15lockd.c +cd $here + +mount | grep "on $mntpoint " | grep nfs > /dev/null && umount $mntpoint + +[ $# -ne 0 ] && + # Problem only seen with lockd + { echo "Not using lockd"; debug="-o nolockd"; } +mount -t nfs -o tcp -o retrycnt=3 -o soft -o rw $debug \ + $nfs_export $mntpoint +sleep 2 + +s=0 +lockf -t 10 $mntpoint/$$.lock sleep 2 > /tmp/$$.log 2>&1 +if grep -q "No locks available" /tmp/$$.log; then + echo "Is lockd running on the remote host?" + rm /tmp/$$.log + s=1 +fi + +wd=$mntpoint/nfs15lockd-`jot -rc 8 a z | tr -d '\n'`.dir +rm -rf $wd +mkdir $wd + +echo "Expect: nfs15lockd exited on signal 6 (core dumped)" +(cd $wd; /tmp/nfs15lockd) & +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 600 ]; do + pgrep -q nfs15lockd || break + sleep 2 +done +if pgrep -q nfs15lockd; then + s=2 + echo "Thread suspension issue:" + ps -lx | grep -v grep | grep nfs15lockd | grep "T+" | \ + awk '{print $2}' | while read pid; do + ps -lp$pid + procstat -k $pid + kill -9 $pid + done + pkill nfs15lockd +fi +wait +rm -rf $wd + +n=0 +while mount | grep "on $mntpoint " | grep -q nfs; do + umount $mntpoint && break + n=$((n + 1)) + if [ $n -gt 60 ]; then + fstat -mf $mntpoint + s=3 + break + fi + sleep 2 +done 2>&1 | awk '!seen[$0]++' +mount | grep -q "on $mntpoint " && umount -f $mntpoint + +rm -f /tmp/nfs15lockd nfs15lockd.core +exit $s +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define RUNTIME 300 +#define SYNC 0 + +volatile u_int *share; + +static void * +t1(void *data __unused) +{ + atomic_add_int(&share[SYNC], 1); + usleep(arc4random() % 8000); + raise(SIGABRT); + + return (NULL); +} + +static void * +t2(void *data __unused) +{ + int fd, i, r; + char file[80]; + + for (i = 0; i < 100; i++) { + atomic_add_int(&share[SYNC], 1); + snprintf(file, sizeof(file), "file.%06d", i); + if ((fd = open(file, O_WRONLY | O_CREAT | O_APPEND, + DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + do { + r = lockf(fd, F_LOCK, 0); + } while (r == -1 && (errno == EDEADLK || errno == EINTR)); + if (r == -1) + err(1, "lockf(%s, F_LOCK)", file); + write(fd, "x", 1); + usleep(arc4random() % 1000); + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + if (lockf(fd, F_ULOCK, 0) == -1) + err(1, "lockf(%s, F_ULOCK)", file); + close(fd); + } + + return (NULL); +} + +int +test(void) +{ + pthread_t tid[3]; + int i, rc; + + for (i = 0; i < 10; i++) { + if ((rc = pthread_create(&tid[0], NULL, t2, NULL)) == -1) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[1], NULL, t2, NULL)) == -1) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[2], NULL, t1, NULL)) == -1) + errc(1, rc, "pthread_create"); + + if ((rc = pthread_join(tid[0], NULL)) == -1) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[1], NULL)) == -1) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[2], NULL)) == -1) + errc(1, rc, "pthread_join"); + } + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int i, status; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + + for(;;) { + if (share[SYNC] > 0) + atomic_add_int(&share[SYNC], -1); + for (i = 0; i < PARALLEL; i++) + kill(pids[i], SIGSTOP); + usleep(1000); + for (i = 0; i < PARALLEL; i++) + kill(pids[i], SIGCONT); + usleep(100 + arc4random() % 400); + if (share[SYNC] == 0) { /* If all procs are done */ + usleep(500); + if (share[SYNC] == 0) + break; + } + } + + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) != pids[i]) + err(1, "waitpid"); + } + } + + return (0); +} diff --git a/tools/test/stress2/misc/nfs15lockd2.sh b/tools/test/stress2/misc/nfs15lockd2.sh new file mode 100755 index 000000000000..dcbef1946ce3 --- /dev/null +++ b/tools/test/stress2/misc/nfs15lockd2.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Page fault seen: +# https://people.freebsd.org/~pho/stress/log/kostik907.txt +# Fixed by: r302019 + r302020. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +./nfs15lockd.sh & +sleep 10 +mount | grep "on $mntpoint " | grep -q nfs && umount -f $mntpoint +wait +exit $? diff --git a/tools/test/stress2/misc/nfs15lockd3.sh b/tools/test/stress2/misc/nfs15lockd3.sh new file mode 100755 index 000000000000..fe43efa64a7c --- /dev/null +++ b/tools/test/stress2/misc/nfs15lockd3.sh @@ -0,0 +1,250 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC Isilon +# 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. +# + +# Demonstrate "wrong handling for suspend". +# https://www.mail-archive.com/freebsd-current@freebsd.org/msg166333.html + +# Variation of nfs15lockd.sh + +# Threads marked as stopped, but can not be killed. +# Fixed by r302215. + +# Also seen and not fixed: +# $ fstat -mf /mnt +# USER CMD PID FD MOUNT INUM MODE SZ|DV R/W +# $ umount /mnt +# umount: unmount of /mnt failed: Device busy +# $ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +pgrep -q lockd || { echo "lockd not running."; exit 1; } + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > nfs15lockd3.c +mycc -o nfs15lockd3 -Wall -Wextra -O2 -g nfs15lockd3.c -lpthread || exit 1 +rm -f nfs15lockd3.c +cd $here + +mount | grep "on $mntpoint " | grep nfs > /dev/null && umount $mntpoint + +[ $# -ne 0 ] && + # Problem only seen with lockd + { echo "Not using lockd"; debug="-o nolockd"; } +mount -t nfs -o tcp -o retrycnt=3 -o soft -o rw $debug \ + $nfs_export $mntpoint +sleep 2 + +s=0 +lockf -t 10 $mntpoint/$$.lock sleep 2 > /tmp/$$.log 2>&1 +if grep -q "No locks available" /tmp/$$.log; then + echo "Is lockd running on the remote host?" + rm /tmp/$$.log + s=1 +fi + +wd=$mntpoint/nfs15lockd3-`jot -rc 8 a z | tr -d '\n'`.dir +rm -rf $wd +mkdir $wd + +(cd $wd; /tmp/nfs15lockd3) & +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 600 ]; do + pgrep -q nfs15lockd || break + sleep 2 +done +if pgrep -q nfs15lockd; then + s=2 + echo "Thread suspension issue:" + ps -lx | grep -v grep | grep nfs15lockd | grep "T+" | \ + awk '{print $2}' | while read pid; do + ps -lp$pid + procstat -k $pid + kill -9 $pid + done + pkill nfs15lockd +fi +wait +rm -rf $wd + +n=0 +while mount | grep "on $mntpoint " | grep -q nfs; do + umount $mntpoint && break + n=$((n + 1)) + if [ $n -gt 60 ]; then + fstat -mf $mntpoint + s=3 + break + fi + sleep 2 +done + +rm -f /tmp/nfs15lockd3 nfs15lockd3.core file.0????? +exit $s +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define RUNTIME 300 +#define SYNC 0 + +volatile u_int *share; + +static void * +t1(void *data __unused) +{ + atomic_add_int(&share[SYNC], 1); + usleep(arc4random() % 8000); + raise(SIGABRT); + + return (NULL); +} + +static void * +t2(void *data __unused) +{ + int fd, i, r; + char file[80]; + + for (i = 0; i < 10; i++) { + atomic_add_int(&share[SYNC], 1); + snprintf(file, sizeof(file), "file.%06d", i); + if ((fd = open(file, O_WRONLY | O_CREAT | O_APPEND, + DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + do { + r = lockf(fd, F_LOCK, 0); + } while (r == -1 && (errno == EDEADLK || errno == EINTR)); + if (r == -1) + err(1, "lockf(%s, F_LOCK)", file); + write(fd, "x", 1); + usleep(arc4random() % 1000); + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + if (lockf(fd, F_ULOCK, 0) == -1) + err(1, "lockf(%s, F_ULOCK)", file); + close(fd); + } + + return (NULL); +} + +int +test(void) +{ + pthread_t tid[3]; + int i, rc; + + for (i = 0; i < 5; i++) { + if ((rc = pthread_create(&tid[0], NULL, t2, NULL)) == -1) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[1], NULL, t2, NULL)) == -1) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[2], NULL, t1, NULL)) == -1) + errc(1, rc, "pthread_create"); + + if ((rc = pthread_join(tid[0], NULL)) == -1) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[1], NULL)) == -1) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[2], NULL)) == -1) + errc(1, rc, "pthread_join"); + } + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int i, n, status; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + n = 0; + while (time(NULL) - start < RUNTIME) { + n++; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + + for(;;) { + if (share[SYNC] > 0) + atomic_add_int(&share[SYNC], -1); + for (i = 0; i < PARALLEL; i++) + kill(pids[i], SIGSTOP); + usleep(1000); + for (i = 0; i < PARALLEL; i++) + kill(pids[i], SIGCONT); + usleep(100 + arc4random() % 400); + if (share[SYNC] == 0) { /* If all procs are done */ + usleep(500); + if (share[SYNC] == 0) + break; + } + } + + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) != pids[i]) + err(1, "waitpid"); + } + if (n > 2) + break; + } + + return (0); +} diff --git a/tools/test/stress2/misc/nfs16.sh b/tools/test/stress2/misc/nfs16.sh new file mode 100755 index 000000000000..b8bc0d1237cf --- /dev/null +++ b/tools/test/stress2/misc/nfs16.sh @@ -0,0 +1,196 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Variation of nfs15.sh, using lockd(8). +# "panic: Failed to register NFS lock locally - error=11" seen: +# https://people.freebsd.org/~pho/stress/log/kostik897.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > nfs16.c +mycc -o nfs16 -Wall -Wextra -O2 -g nfs16.c -lpthread || exit 1 +rm -f nfs16.c +cd $here + +mount | grep "on $mntpoint " | grep nfs > /dev/null && umount $mntpoint + +mount -t nfs -o tcp -o retrycnt=3 -o soft -o rw \ + $nfs_export $mntpoint +sleep 2 +wd=$mntpoint/nfs16.dir +rm -rf $wd +mkdir $wd + +(cd $wd; /tmp/nfs16) +rm -rf $wd + +while mount | grep "on $mntpoint " | grep -q nfs; do + umount $mntpoint || sleep 1 +done + +rm -f /tmp/nfs16 +exit 0 +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define RUNTIME 300 +#define SYNC 0 + +volatile u_int *share; + +static void * +t1(void *data __unused) +{ + atomic_add_int(&share[SYNC], 1); + usleep(arc4random() % 8000); + raise(SIGABRT); + + return (NULL); +} + +static void * +t2(void *data __unused) +{ + int fd, i, r; + char file[80]; + + for (i = 0; i < 100; i++) { + atomic_add_int(&share[SYNC], 1); + snprintf(file, sizeof(file), "file.%06d", i); + if ((fd = open(file, O_WRONLY | O_CREAT | O_APPEND, DEFFILEMODE)) == -1) + err(1, "open(%s)", file); + do { + r = lockf(fd, F_LOCK, 0); + } while (r == -1 && errno == EDEADLK); + if (r == -1) + err(1, "lockf(%s, F_LOCK)", file); + write(fd, "x", 1); + usleep(arc4random() % 1000); + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + if (lockf(fd, F_ULOCK, 0) == -1) + err(1, "lockf(%s, F_ULOCK)", file); + close(fd); + } + + return (NULL); +} + +int +test(void) +{ + pthread_t tid[3]; + int i, rc; + + for (i = 0; i < 10; i++) { + if ((rc = pthread_create(&tid[0], NULL, t2, NULL)) == -1) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[1], NULL, t2, NULL)) == -1) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[2], NULL, t1, NULL)) == -1) + errc(1, rc, "pthread_create"); + + if ((rc = pthread_join(tid[0], NULL)) == -1) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[1], NULL)) == -1) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[2], NULL)) == -1) + errc(1, rc, "pthread_join"); + } + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int i, status; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + + for(;;) { + if (share[SYNC] > 0) + atomic_add_int(&share[SYNC], -1); + for (i = 0; i < PARALLEL; i++) + kill(pids[i], SIGSTOP); + usleep(1000); + for (i = 0; i < PARALLEL; i++) + kill(pids[i], SIGCONT); + usleep(100 + arc4random() % 400); + if (share[SYNC] == 0) { /* If all procs are done */ + usleep(500); + if (share[SYNC] == 0) + break; + } + } + + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) != pids[i]) + err(1, "waitpid"); + } + } + + return (0); +} diff --git a/tools/test/stress2/misc/nfs17.sh b/tools/test/stress2/misc/nfs17.sh new file mode 100755 index 000000000000..2a012e476e55 --- /dev/null +++ b/tools/test/stress2/misc/nfs17.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# Copy tests to a NFS FS and run from there. + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +mount | grep "on $mntpoint " | grep -q nfs && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o soft -o rw $nfs_export $mntpoint +grep -q $mntpoint /etc/exports || + { echo "$mntpoint missing from /etc/exports"; exit 0; } + +chmod 777 $mntpoint + +rm -rf $mntpoint/nfs17; mkdir -p $mntpoint/nfs17 +chmod 0777 $mntpoint/nfs17 +cp -r ../../stress2 $mntpoint/nfs17 + +log=/tmp/nfs17.log +export CTRLDIR=$mntpoint/nfs17/stressX.control +export LOAD=80 +export MAXSWAPPCT=80 +export RUNDIR=$mntpoint/nfs17/stressX +export runRUNTIME=5m +export rwLOAD=80 +export TESTPROGS=`cd ..; find testcases/ -perm -1 -type f | \ + egrep -v "/run/|lockf|dirnprename"` + +here=`pwd` +cd $mntpoint/nfs17/stress2/misc || exit 1 +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' 2>&1 | tee $log +cd $here +rm -rf $mntpoint/nfs17/stress2 + +for i in `jot 3`; do + umount $mntpoint && break + sleep 10 +done +mount | grep -q "on $mntpoint " && { s=1; umount -f $mntpoint; } +sed < /tmp/nfs17.log | sed '/Loop/d;/run time/d' +s=0 +[ `sed < /tmp/nfs17.log | sed '/Loop/d;/run time/d' | wc -l` -ne 0 ] && + s=2 +[ $s -ne 0 ] && echo "Exit value is $s" +exit $s diff --git a/tools/test/stress2/misc/nfs2.sh b/tools/test/stress2/misc/nfs2.sh new file mode 100755 index 000000000000..9d470c18e8f0 --- /dev/null +++ b/tools/test/stress2/misc/nfs2.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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 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 +grep -q $mntpoint /etc/exports || + { echo "$mntpoint missing from /etc/exports"; exit 0; } +[ -x /sbin/mount_msdosfs ] || exit + +D=$diskimage +dd if=/dev/zero of=$D bs=1m count=128 status=none || 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}$part > /dev/null +mount -t msdosfs -o rw /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,soft -o rw \ + 127.0.0.1:$mntpoint ${mntpoint}2 + +export INODES=9999 # No inodes on a msdos fs +export RUNDIR=${mntpoint}2/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd ..; ./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/tools/test/stress2/misc/nfs3.sh b/tools/test/stress2/misc/nfs3.sh new file mode 100755 index 000000000000..69ed0275b41d --- /dev/null +++ b/tools/test/stress2/misc/nfs3.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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. +# + +# panic: neg mount point vnode list size + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +[ ! -d $mntpoint ] && mkdir $mntpoint +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint +sleep 1 +rm -rf $mntpoint/stressX/* +rm -rf /tmp/stressX.control + +export RUNDIR=$mntpoint/nfs3.`jot -rc 8 a z | tr -d '\n'`/stressX +mkdir -p $RUNDIR +export runRUNTIME=1m +rm -rf /tmp/stressX.control/* + +su $testuser -c "(cd ..; ./run.sh io.cfg > /dev/null 2>&1)" & +sleep 50 + +while mount | grep -q "on $mntpoint "; do + umount -f $mntpoint || sleep 1 +done +kill -9 $! +../tools/killall.sh +wait +exit 0 diff --git a/tools/test/stress2/misc/nfs4.sh b/tools/test/stress2/misc/nfs4.sh new file mode 100755 index 000000000000..1d986c161154 --- /dev/null +++ b/tools/test/stress2/misc/nfs4.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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. +# + +# panic: vm_fault: fault on nofault entry, from vfs_stdcheckexp+0x74 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +[ ! -d $mntpoint ] && mkdir $mntpoint +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint +rm -rf $mntpoint/stressX/* +rm -rf /tmp/stressX.control + +export RUNDIR=$mntpoint/nfs4.`jot -rc 8 a z | tr -d '\n'`/stressX +mkdir -p $RUNDIR +chmod 777 $RUNDIR +export runRUNTIME=3m +rm -rf /tmp/stressX.control/* + +su $testuser -c '(cd ..; ./run.sh all.cfg) > /dev/null 2>&1' & +sleep 60 + +while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 + sleep 1 +done +kill -9 $! +../tools/killall.sh +wait + +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint +sleep .2 +su $testuser -c "find $RUNDIR -delete 2>/dev/null" +find $RUNDIR -delete +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && exit 1 || exit 0 diff --git a/tools/test/stress2/misc/nfs5.sh b/tools/test/stress2/misc/nfs5.sh new file mode 100755 index 000000000000..1f311ef47baf --- /dev/null +++ b/tools/test/stress2/misc/nfs5.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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. +# + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +D=$diskimage +dd if=dev=zero of=$D bs=1m count=128 status=none || 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 $newfs_flags md${mdstart}$part > /dev/null +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,soft -o rw 127.0.0.1:$mntpoint \ + ${mntpoint}2 + +export RUNDIR=${mntpoint}2/stressX +export runRUNTIME=4m +su $testuser -c "(cd ..; ./run.sh disk.cfg > /dev/null 2>&1)" & +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 $! +../tools/killall.sh +wait +exit 0 diff --git a/tools/test/stress2/misc/nfs6.sh b/tools/test/stress2/misc/nfs6.sh new file mode 100755 index 000000000000..98b2a9d40945 --- /dev/null +++ b/tools/test/stress2/misc/nfs6.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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. +# + +# panic: vn_finished_write: neg cnt +# http://people.freebsd.org/~pho/stress/log/kostik500.txt +# http://people.freebsd.org/~pho/stress/log/nfs6.txt + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +grep -q $mntpoint /etc/exports || + { echo "$mntpoint missing from /etc/exports"; exit 0; } + +D=$diskimage +dd if=/dev/zero of=$D bs=1m count=128 status=none || 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 $newfs_flags md${mdstart}$part > /dev/null +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,soft -o rw 127.0.0.1:$mntpoint \ + ${mntpoint}2 + +export RUNDIR=${mntpoint}2/stressX +export runRUNTIME=4m +su $testuser -c "(cd ..; ./run.sh disk.cfg > /dev/null 2>&1)" & +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 $! +../tools/killall.sh +wait +exit 0 diff --git a/tools/test/stress2/misc/nfs7.sh b/tools/test/stress2/misc/nfs7.sh new file mode 100755 index 000000000000..8fad71000f73 --- /dev/null +++ b/tools/test/stress2/misc/nfs7.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# Copyright (c) 2009-2013 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. +# + +# NFS test excluding lockd + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +[ ! -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,soft -o rw \ + $nfs_export $mntpoint +rm -rf /tmp/stressX.control + +export RUNDIR=$mntpoint/nfs7.`jot -rc 8 a z | tr -d '\n'`/stressX +USE_TIMEOUT=1 +rm -rf $RUNDIR +mkdir -p $RUNDIR +chmod 777 $RUNDIR +export runRUNTIME=10m +rm -rf /tmp/stressX.control/* + +su $testuser -c "(cd ..; ./run.sh marcus.cfg) > /dev/null 2>&1" + +umount $mntpoint +while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 +done + +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint +sleep .2 +su $testuser -c "find $RUNDIR -delete 2>/dev/null" +find $RUNDIR -delete +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && exit 1 || exit 0 diff --git a/tools/test/stress2/misc/nfs8.sh b/tools/test/stress2/misc/nfs8.sh new file mode 100755 index 000000000000..010b3b1ae8e0 --- /dev/null +++ b/tools/test/stress2/misc/nfs8.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. +# + +# 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 + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +[ ! -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,soft -o rw \ + $nfs_export $mntpoint +sleep .2 + +wdir=$mntpoint/nfs8.sh.dir +mkdir -p $wdir +jot 1000 | xargs -I% touch $wdir/% +for i in `jot 10`; do + find $mntpoint > /dev/null 2>&1 & + sleep 0.1 + kill -s STOP $! + pids="$pids $!" +done +rm -rf $wdir + +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 pid in $pids; do + wait $pid +done +exit 0 diff --git a/tools/test/stress2/misc/nfs9.sh b/tools/test/stress2/misc/nfs9.sh new file mode 100755 index 000000000000..b970ab8e564c --- /dev/null +++ b/tools/test/stress2/misc/nfs9.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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. +# + +# 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 + +# "panic: SACK scoreboard must not be empty" seen: +# https://people.freebsd.org/~pho/stress/log/nfs9-2.txt + +# Hang seen: +# $ ps -lp52442 +# UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND +# 0 52442 52120 0 20 0 11336 2868 nfsreq S 0 0:01.48 rm -rf /mnt/nfs9.dktfkpuf/stressX + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +[ ! -d $mntpoint ] && mkdir $mntpoint +export RUNDIR=$mntpoint/nfs9.`jot -rc 8 a z | tr -d '\n'`/stressX +USE_TIMEOUT=1 +s=0 +start=`date +%s` +for i in `jot 10`; do + mount | grep "on $mntpoint " | grep -q nfs && umount $mntpoint + mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft \ + -o rw $nfs_export $mntpoint + sleep .5 + + rm -rf $RUNDIR 2> /dev/null + mkdir -p $RUNDIR || exit 1 + chmod -R 777 $RUNDIR 2> /dev/null + export runRUNTIME=3m + rm -rf /tmp/stressX.control/* + + if [ $i -eq 10 -o $((`date +%s` - start)) -ge 600 ]; then + ../tools/killall.sh + su $testuser -c "rm -rf $RUNDIR" 2> /dev/null + rm -rf `dirname $RUNDIR` || s=1 + done=1 + else + su $testuser -c '(cd ..; ./run.sh all.cfg) > /dev/null \ + 2>&1' & + sleep 60 + fi + + while mount | grep -q $mntpoint; do + umount -f $mntpoint > /dev/null 2>&1 + done + ../tools/killall.sh || break + kill -9 $! 2>/dev/null + wait + [ $done ] && break +done +exit $s diff --git a/tools/test/stress2/misc/nfs_halfpage.sh b/tools/test/stress2/misc/nfs_halfpage.sh new file mode 100755 index 000000000000..b665e84d7ddf --- /dev/null +++ b/tools/test/stress2/misc/nfs_halfpage.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2017 Konstantin Belousov +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +# Regression test for: +# Mark pages after EOF as clean after pageout. +# https://reviews.freebsd.org/D11697 +# Committed as r321580 + r321581. + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/nfs_halfpage.c +mycc -o nfs_halfpage -Wall -Wextra -O0 -g nfs_halfpage.c || exit 1 +rm -f nfs_halfpage.c +cd $odir + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint + +file=$mntpoint/nfs_halfpage.file +/tmp/nfs_halfpage $file + +echo "Reboot now to trigger syncing disks loop." +sleep 60 + +rm $file +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && s=1 || s=0 +rm -f /tmp/nfs_halfpage + +exit $s +EOF +/* $Id: nfs_halfpage.c,v 1.2 2017/07/23 09:36:23 kostik Exp kostik $ */ + +#include +#include +#include +#include + +int +main(int argc __unused, char *argv[]) +{ + char *m; + int error, fd, pgsz, sz; + + pgsz = getpagesize(); + fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0666); + if (fd == -1) + err(1, "open %s", argv[1]); + sz = pgsz / 4; + error = lseek(fd, sz, SEEK_SET); + if (error == -1) + err(1, "lseek"); + error = write(fd, "a", 1); + if (error == -1) + err(1, "write"); + else if (error != 1) + errx(1, "short write"); + m = mmap(NULL, sz + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (m == MAP_FAILED) + err(1, "mmap"); + m[0] = 'x'; +} diff --git a/tools/test/stress2/misc/nfs_halfpage2.sh b/tools/test/stress2/misc/nfs_halfpage2.sh new file mode 100755 index 000000000000..15895da2da21 --- /dev/null +++ b/tools/test/stress2/misc/nfs_halfpage2.sh @@ -0,0 +1,103 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2017 Konstantin Belousov +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +# Variation of nfs_halfpage.sh with a 2GB file. +# Mark pages after EOF as clean after pageout. +# https://reviews.freebsd.org/D11697 +# Committed as r321580 + r321581. + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/nfs_halfpage.c +mycc -o nfs_halfpage -Wall -Wextra -O0 -g nfs_halfpage.c || exit 1 +rm -f nfs_halfpage.c +cd $odir + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint + +file=$mntpoint/nfs_halfpage.file +/tmp/nfs_halfpage $file + +ls -l $file +echo "Reboot now to trigger syncing disks loop." +sleep 60 + +rm $file +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && exit 1 +rm -f /tmp/nfs_halfpage + +exit 0 +EOF +/* $Id: nfs_halfpage.c,v 1.2 2017/07/23 09:36:23 kostik Exp kostik $ */ + +#include +#include +#include +#include +#include + +int +main(int argc __unused, char *argv[]) +{ + off_t sz; + char *m; + int error, fd, pgsz; + + pgsz = getpagesize(); + fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0666); + if (fd == -1) + err(1, "open %s", argv[1]); + sz = pgsz / 4; + sz += 2LL * 1024 * 1024 * 1024; + error = lseek(fd, sz, SEEK_SET); + if (error == -1) + err(1, "lseek"); + error = write(fd, "a", 1); + if (error == -1) + err(1, "write"); + else if (error != 1) + errx(1, "short write"); + m = mmap(NULL, sz + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (m == MAP_FAILED) + err(1, "mmap"); + m[sz - 1] = 'x'; +} diff --git a/tools/test/stress2/misc/nfsdelegation.sh b/tools/test/stress2/misc/nfsdelegation.sh new file mode 100755 index 000000000000..b84b63e96658 --- /dev/null +++ b/tools/test/stress2/misc/nfsdelegation.sh @@ -0,0 +1,169 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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 nfsv4 delegations. Scenario suggestion by kib. +# "(nfsdelegation), uid 0, was killed: text file modification" seen. +# Fixed by r316745 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > nfsdelegation.c +mycc -o nfsdelegation -Wall -Wextra -O0 nfsdelegation.c || exit 1 +rm -f nfsdelegation.c + +[ `sysctl -n sysctl vfs.timestamp_precision` -ne 3 ] && + echo "vfs.timestamp_precision must be set to 3" +[ "`sysctl -ni vfs.nfsd.issue_delegations`" != "1" ] && + { echo "vfs.nfsd.issue_delegations is not enabled"; exit 0; } +pgrep -q nfscbd || { echo "nfscbd is not running"; exit 0; } + +mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint +opt="-o nocto" +opt="$opt -o nolockd -o nfsv4" +mount $opt $nfs_export $mntpoint || exit 1 +sleep .2 + +wdir=$mntpoint/nfsdelegation.`jot -rc 8 a z | tr -d '\n'`/nfsdelegation +mkdir -p $wdir || exit 1 + +delegs=0 +s=0 +(cd $wdir; /tmp/nfsdelegation) & +while kill -0 $! 2>/dev/null; do + r=`nfsstat -ec | grep -A1 Delegs | tail -1 | awk '{print $5}'` + [ $r -gt $delegs ] && { delegs=$r; break; } +done +wait +[ $delegs -eq 0 ] && { echo "No delegations detected"; s=2; } + +rm -rf $wdir +umount $mntpoint +while mount | grep "$mntpoint " | grep -q nfs; do + umount -f $mntpoint +done +tail -3 /var/log/messages | grep -m1 nfsdelegation: && s=2 +rm -f /tmp/nfsdelegation +exit $s +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 100 +#define INPUTFILE "/bin/sleep" +#define PARALLEL 3 + +static volatile u_int *share; + +static int +tmmap(int idx) +{ + struct stat statbuf; + pid_t epid, pid; + int i; + int fdout; + char *cmdline[3], *dst, file[128], help[80]; + + pid = getpid(); + cmdline[1] = ".01"; + cmdline[2] = 0; + for (i = 0; i < LOOPS; i++) { + sprintf(file,"nfsdelegation.p%05d.%05d", pid, i); + cmdline[0] = file; + + snprintf(help, sizeof(help), "cp %s %s; chmod 777 %s", INPUTFILE, file, file); + system(help); + share[idx] = 0; + if ((epid = fork()) == 0) { + alarm(60); + while (share[idx] == 0) + usleep(100); + if (execve(cmdline[0], cmdline, NULL) == -1) + err(1, "execve"); + } + + if ((fdout = open(file, O_RDWR)) < 0) + err(1, "open(%s)", file); + if (fstat(fdout, &statbuf) < 0) + err(1, "fstat error"); + + if ((dst = mmap(0, statbuf.st_size, PROT_READ | PROT_WRITE | + MAP_PRIVATE, MAP_SHARED, fdout, 0)) == (caddr_t) - 1) + err(1, "mmap error for output"); + + dst[statbuf.st_size] = 1; + + close(fdout); + if (munmap(dst, statbuf.st_size) == -1) + err(1, "munmap"); + share[idx] = 1; + if (waitpid(epid, NULL, 0) != epid) + err(1, "waitpid(%d)", epid); + } + + _exit(0); +} + +int +main(void) +{ + size_t len; + int i; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + tmmap(i); + } + + for (i = 0; i < PARALLEL; i++) { + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/nfsdepth.sh b/tools/test/stress2/misc/nfsdepth.sh new file mode 100755 index 000000000000..1abe56e24a80 --- /dev/null +++ b/tools/test/stress2/misc/nfsdepth.sh @@ -0,0 +1,239 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# NFS test with deep directories. + +# Only issue seen is: +# nfsdepth: mkdir(d93) l35: Permission denied + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > nfsdepth.c +mycc -o nfsdepth -Wall -Wextra -g nfsdepth.c || exit 1 +rm -f nfsdepth.c +cd $odir + +mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint +mount -t nfs -o tcp -o rw -o soft $nfs_export $mntpoint + +work=$mntpoint/nfsdepth.`jot -rc 8 a z | tr -d '\n'`.dir +mkdir -p $work +chmod 777 $work + +su $testuser -c "cd $work; /tmp/nfsdepth" +s=$? +if [ $s -eq 0 ]; then + su $testuser -c "rm -rf $work 2>/dev/null" + rm -rf $work +else + find $work -ls +fi + +umount $mntpoint > /dev/null 2>&1 +while mount | grep "$mntpoint" | grep -q nfs; do + umount $mntpoint > /dev/null 2>&1 +done + +rm -f /tmp/nfsdepth +exit $s + +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static unsigned long actual, size; +volatile int done_testing; +int fail; + +#define DEPTH 200 +#define PARALLEL 8 +#define RUNTIME 180 + +void +handler(int s __unused) +{ + done_testing = 1; +} + +void +mkDir(char *path, int level) { + int n, r; + char newPath[MAXPATHLEN + 1]; + + n = 0; + do { + r = mkdir(path, 0770); + if (r == -1 && errno == EACCES && n < 10) { + warn("mkdir(%s) l%d", path, __LINE__); + n++; + errno = EAGAIN; + usleep(10000); + } + if (r == -1 && errno == EINTR) + (void)rmdir(path); + } while (r == -1 && (errno == EINTR || errno == EAGAIN)); + + if (r == -1) { + warn("mkdir(%s), pid %d, l%d", path, getpid(), __LINE__); + fail++; + } else { + actual++; + do { + r = chdir (path); + if (r == -1 && errno == EACCES && n < 10) { + warn("chdir(%s) .%d", path, __LINE__); + n++; + errno = EAGAIN; + usleep(10000); + } + } while (r == -1 && (errno == EINTR || errno == EAGAIN)); + if (r == -1) + err(1, "chdir(%s), pid %d, l%d", path, getpid(), __LINE__); + } + + if (done_testing == 0 && fail == 0 && level < (int)size) { + sprintf(newPath,"d%d", level + 1); + mkDir(newPath, level + 1); + } +} + +void +rmDir(char *path, int level) { + int n, r; + char newPath[MAXPATHLEN + 1]; + + if (level == 0) + return; + + if (level < (int)actual) { + sprintf(newPath,"d%d", level+1); + rmDir(newPath, level+1); + } + n = 0; + do { + r = chdir (".."); + if (r == -1 && errno == EACCES && n < 10) { + warn("chdir(%s) l%d", path, __LINE__); + n++; + errno = EAGAIN; + usleep(10000); + } + } while (r == -1 && (errno == EINTR || errno == EAGAIN)); + if (r == -1) + err(1, "chdir(%s), pid %d, l%d", "..", getpid(), __LINE__); + n = 0; + do { + r = rmdir(path); + if (r == -1 && errno == EACCES && n < 10) { + warn("rmdir(%s) l%d", path, __LINE__); + n++; + errno = EAGAIN; + usleep(10000); + } + } while (r == -1 && (errno == EINTR || errno == EAGAIN)); + if (r == -1) + err(1, "rmdir(%s), pid %d, l%d", path, getpid(), __LINE__); +} + +int +test2(void) +{ + char path[MAXPATHLEN + 1]; + + fail = actual = 0; + umask(0); + sprintf(path,"p%05d.d%d", getpid(), 1); + mkDir(path, 1); + rmDir(path, 1); + + _exit (fail); +} + +int +test(void) +{ + pid_t pid; + time_t start; + int status; + + size = (arc4random() % DEPTH) + 1; + + signal(SIGHUP, handler); + start = time(NULL); + while (time(NULL) - start < RUNTIME && fail == 0) { + if ((pid = fork()) == 0) { + done_testing = 0; + test2(); + } + + status = 0; + while (wait4(pid, &status, WNOHANG, NULL) != pid) { + if (kill(pid, SIGHUP) == -1) + err(1, "kill(%d)", pid); + usleep(100000 + (arc4random() % 10000)); + } + if (status != 0) + fail++; + } + + _exit (status != 0); +} + +int +main(void) +{ + int e, i, pids[PARALLEL], status; + + e = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) { + waitpid(pids[i], &status, 0); + e += status == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/nfsrename.sh b/tools/test/stress2/misc/nfsrename.sh new file mode 100755 index 000000000000..b6513fba1553 --- /dev/null +++ b/tools/test/stress2/misc/nfsrename.sh @@ -0,0 +1,224 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# Test scenario by jhb@ + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > nfsrename.c +mycc -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,soft -o rw $nfs_export $mntpoint + +for i in `jot 10`; do + /tmp/nfsrename $mntpoint/nfsrename.$i > /dev/null 2>&1 & + pids="$pids $!" +done +s=0 +for i in $pids; do + wait $i + [ $? -ne 0 ] && s=1 +done +pkill 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 $s + +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 +#include + +static char *filename; +static char *dir; + +#define RUNTIME 720 + +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) { + 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("fdopen: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) +{ + time_t start; + + start = time(NULL); + for (;;) { + random_sleep(500, 50); + read_file(); + if (time(NULL) - start > RUNTIME) + errx(1, "Timed out"); + } + exit(0); +} + +int +main(int ac, char **av) +{ + time_t start; + 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"); + } + } + + start = time(NULL); + for (i = 0; i < 10000; i++) { + random_sleep(1500, 1000); + write_file(); + if (time(NULL) - start > RUNTIME) + errx(1, "Timed out"); + } + + return (0); +} diff --git a/tools/test/stress2/misc/nfssillyrename.sh b/tools/test/stress2/misc/nfssillyrename.sh new file mode 100755 index 000000000000..8cb63c920533 --- /dev/null +++ b/tools/test/stress2/misc/nfssillyrename.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# "rm: src/: Directory not empty" seen. + +# See also nfsrename.sh + +# Test scenario by bdrewery@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint +mount -t nfs -o tcp -o retrycnt=3 -o soft -o rw $nfs_export $mntpoint || + exit 1 + +mp=$mntpoint/sillyrename +rm -rf $mp +mkdir -p $mp + +status=0 +cd $mp +mkdir src dst +touch src/foo +ln src/foo dst/foo +tail -F dst/foo & +rm -rf src/ || status=1 + +cd / +kill $! +wait +rm -rf $mp +umount $mntpoint +while mount | grep "$mntpoint " | grep -q nfs; do + umount -f $mntpoint +done +exit $status diff --git a/tools/test/stress2/misc/nullfs.sh b/tools/test/stress2/misc/nullfs.sh new file mode 100755 index 000000000000..1424a90eed44 --- /dev/null +++ b/tools/test/stress2/misc/nullfs.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. +# + +# Stress test by performing parallel calls to mount and umount. Alternate +# between forced and non-forced unmounts. + +# https://people.freebsd.org/~pho/stress/log/kostik169.txt +# https://people.freebsd.org/~pho/stress/log/kostik487.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +: ${nullfs_srcdir:=/tmp} +: ${nullfs_dstdir:=$mntpoint} + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + [ ! -d ${nullfs_dstdir}$i ] && mkdir ${nullfs_dstdir}$i + mount | grep -q " ${nullfs_dstdir}$i " && + umount ${nullfs_dstdir}$i + done + + # start the parallel tests + for i in `jot $mounts`; do + ./$0 $i & + done + wait + + for i in `jot $mounts`; do + umount ${nullfs_dstdir}$i > /dev/null 2>&1 + done + exit 0 +else + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ `date '+%s'` -lt $((start + 300)) ]; do + m=$1 + mount_nullfs $nullfs_srcdir ${nullfs_dstdir}$m > \ + /dev/null 2>&1 + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + while mount | grep -q ${nullfs_dstdir}$m; do + umount $opt ${nullfs_dstdir}$m > /dev/null 2>&1 + done + done +fi diff --git a/tools/test/stress2/misc/nullfs10.sh b/tools/test/stress2/misc/nullfs10.sh new file mode 100755 index 000000000000..4444bcca2913 --- /dev/null +++ b/tools/test/stress2/misc/nullfs10.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Regression test: + +# There is an issue, namely, when the lower file is already +# opened r/w, but its nullfs alias is executed. This situation obviously +# shall result in ETXTBUSY, but it currently does not. + +# Test scenario by kib@ + +. ../default.cfg + +mnt2=${mntpoint}2 +mount | grep -q $mnt2 && umount $mnt2 + +[ -d $mnt2 ] || mkdir $mnt2 +mount | grep $mnt2 | grep -q /dev/md && umount -f $mnt2 +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +mount -t nullfs $mntpoint $mnt2 + +cp /bin/ls $mntpoint +chmod +w $mntpoint/ls +sleep 2 >> $mntpoint/ls & +sleep .5 +# This line should cause a "/mnt2/ls: Text file busy" +$mnt2/ls -l /bin/ls $mntpoint $mnt2 && echo FAIL || echo OK +kill $! +wait + +while mount | grep -q "$mnt2 "; do + umount $mnt2 || sleep 1 +done + +while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/nullfs11.sh b/tools/test/stress2/misc/nullfs11.sh new file mode 100755 index 000000000000..9d02abd3b3ca --- /dev/null +++ b/tools/test/stress2/misc/nullfs11.sh @@ -0,0 +1,89 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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. +# + +# nullfs cache / nocache benchmark + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +export LANG=C +CACHE=nullfs11-cache.log +NOCACHE=nullfs11-nocache.log +mp1=$mntpoint +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir $mp2 +rm -f $CACHE $NOCACHE + +mycc -o /tmp/fstool ../tools/fstool.c + +test() { + opt=$1 + mount | grep -wq $mp2 && umount $mp2 + mount | grep -wq $mp1 && umount $mp1 + mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + mdconfig -a -t swap -s 2g -u $mdstart || exit 1 + bsdlabel -w md$mdstart auto + newfs $newfs_flags md${mdstart}$part > /dev/null + mount /dev/md${mdstart}$part $mp1 + + mount -t nullfs $opt $mp1 $mp2 + + i=1 + (mkdir $mp2/test$i; cd $mp2/test$i; /tmp/fstool -l -f 50 -n 500 -s 4k) + rm -rf $mp2/test$i + sync + sleep 5 + + parallel=4 + for j in `jot 5`; do + s=`date '+%s'` + for i in `jot $parallel`; do + (mkdir $mp2/test$i; cd $mp2/test$i; \ + /tmp/fstool -l -f 50 -n 500 -s $((i * 4))k) & + done + for i in `jot $parallel`; do + wait + done + rm -rf $mp2/* + echo $((`date '+%s'` - $s)) + done + while mount | grep -wq $mp2; do + umount $mp2 || sleep 1 + done + while mount | grep $mp1 | grep -q /dev/md; do + umount $mp1 || sleep 1 + done + mdconfig -d -u $mdstart +} + +test "-o nocache" > $NOCACHE +test "-o cache" > $CACHE + +ministat -s -w 60 $NOCACHE $CACHE +rm -f /tmp/fstool $CACHE $NOCACHE diff --git a/tools/test/stress2/misc/nullfs12.sh b/tools/test/stress2/misc/nullfs12.sh new file mode 100755 index 000000000000..12671bb695c1 --- /dev/null +++ b/tools/test/stress2/misc/nullfs12.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "umount -f" test with files open for writing +# "panic: vputx: missed vn_close" seen. +# Scenario by kib@. Fixed in r245262. + +. ../default.cfg + +mnt2=${mntpoint}2 +mount | grep -q $mnt2 && umount $mnt2 + +[ -d $mnt2 ] || mkdir $mnt2 +mount | grep $mntpoint | grep -q /dev/md && 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint +mount -t nullfs $mntpoint $mnt2 + +(sleep 5 > $mnt2/log) & +sleep 1 +umount -f $mnt2 + +kill $! +wait + +while mount | grep -q "$mnt2 "; do + umount $mnt2 || sleep 1 +done + +while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/nullfs13.sh b/tools/test/stress2/misc/nullfs13.sh new file mode 100755 index 000000000000..5c51621a8c94 --- /dev/null +++ b/tools/test/stress2/misc/nullfs13.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# kern/178238 "nullfs don't release i-nodes on unlink" +# See also nullfs16.sh +# Fixed by: r292961. + +. ../default.cfg + +nullfsmp=${mntpoint}2 +mount | grep -q "$nullfsmp " && umount $nullfsmp + +[ -d $nullfsmp ] || mkdir $nullfsmp +mount | grep "$mntpoint " | grep -q /dev/md && 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint +mount -t nullfs $mntpoint $nullfsmp + +(cd $nullfsmp; jot 20 | xargs touch) +rm $nullfsmp/* + +(cd $nullfsmp; jot 20 | xargs touch) +rm $mntpoint/* + +(cd $mntpoint; jot 20 | xargs touch) +rm $mntpoint/* + +(cd $mntpoint; jot 20 | xargs touch) +rm $nullfsmp/* + +ino=`df -i $nullfsmp | tail -1 | awk '{print $6}'` +if [ $ino -ne 2 ]; then + echo FAIL + df -i $mntpoint $nullfsmp + echo "ls -la $mntpoint $nullfsmp" + ls -la $mntpoint $nullfsmp +fi + +while mount | grep -q "$nullfsmp "; do + umount $nullfsmp || sleep 1 +done + +while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/nullfs14.sh b/tools/test/stress2/misc/nullfs14.sh new file mode 100755 index 000000000000..96bcb470dc40 --- /dev/null +++ b/tools/test/stress2/misc/nullfs14.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Page fault seen in fifo_close() + +. ../default.cfg + +nullfsmp=${mntpoint}2 +mount | grep -q "$nullfsmp " && umount $nullfsmp + +[ -d $nullfsmp ] || mkdir $nullfsmp +mount | grep "$mntpoint " | grep -q /dev/md && 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +#chmod 777 $mntpoint +mount -t nullfs $mntpoint $nullfsmp + +mkfifo $nullfsmp/fifo +rm $mntpoint/fifo # Triggers page fault + +while mount | grep -q "$nullfsmp "; do + umount $nullfsmp || sleep 1 +done + +while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/nullfs15.sh b/tools/test/stress2/misc/nullfs15.sh new file mode 100755 index 000000000000..fcaca4af8cb9 --- /dev/null +++ b/tools/test/stress2/misc/nullfs15.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# panic: lockmgr still held. Fixed in r250852. +# Test scenario by antoine@ + +nullfsmp=${mntpoint}2 +mount | grep -q "$nullfsmp " && umount $nullfsmp + +[ -d $nullfsmp ] || mkdir $nullfsmp +mount | grep "$mntpoint " | grep -q /dev/md && 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +mount -t nullfs $mntpoint $nullfsmp + +mkdir $mntpoint/.new_packages $nullfsmp/new_packages +mount -t nullfs $mntpoint/.new_packages $nullfsmp/new_packages +dd if=/dev/zero of=$nullfsmp/new_packages/bar count=20000 status=none +mv $mntpoint/.new_packages/bar /tmp/ +rm -rf $mntpoint/.new_packages +umount -f $nullfsmp/new_packages + +while mount | grep -q "$nullfsmp "; do + umount $nullfsmp || sleep 1 +done + +while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/bar +exit 0 diff --git a/tools/test/stress2/misc/nullfs16.sh b/tools/test/stress2/misc/nullfs16.sh new file mode 100755 index 000000000000..32f6d006bda6 --- /dev/null +++ b/tools/test/stress2/misc/nullfs16.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# [Bug 178238] [nullfs] nullfs don't release i-nodes on unlink. +# Test scenaro by: noah.bergbauer@tum.de +# Fixed by: r292961 + +mount | grep -q "on $mntpoint " && umount -f $mntpoint +mount -o size=1g -t tmpfs tmpfs $mntpoint + +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir -p $mp2 +mount | grep -q "on $mp2 " && umount -f $mp2 +mount -t nullfs $mntpoint $mp2 + +# Expect second dd to fail +for i in `jot 2`; do + dd if=/dev/zero of=$mp2/file bs=1m count=1023 \ + status=none + rm -f $mp2/file +done +if [ `df -i $mp2 | tail -1 | awk '{print $5}'` = "100%" ]; then + echo FAIL + s=1 + ls -al $mntpoint $mp2 + df -i | egrep "${mntpoint}$|${mp2}$" +fi + +umount $mp2 +umount $mntpoint + +exit $s diff --git a/tools/test/stress2/misc/nullfs17.sh b/tools/test/stress2/misc/nullfs17.sh new file mode 100755 index 000000000000..121225f67c00 --- /dev/null +++ b/tools/test/stress2/misc/nullfs17.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Variation of nullfs.sh + +# "panic: LK_RETRY set with incompatible flags (0x202400) or +# an error occured (11)" seen. +# https://people.freebsd.org/~pho/stress/log/matt001.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +: ${nullfs_srcdir:=/tmp} +: ${nullfs_dstdir:=$mntpoint} +CONT=/tmp/nullfs17.continue + +if [ $# -eq 0 ]; then + for i in `jot $mounts`; do + [ ! -d ${nullfs_dstdir}$i ] && mkdir ${nullfs_dstdir}$i + mount | grep -q " ${nullfs_dstdir}$i " && + umount ${nullfs_dstdir}$i + done + + # start the parallel tests + for i in `jot $mounts`; do + ./$0 $i & + ./$0 find $i & + done + wait + + for i in `jot $mounts`; do + umount ${nullfs_dstdir}$i > /dev/null 2>&1 + done + exit 0 +else + if [ $1 = find ]; then + while [ -f $CONT ]; do + find ${nullfs_dstdir}$2 -type f -maxdepth 2 -ls > \ + /dev/null 2>&1 + done + else + # The test: Parallel mount and unmounts + touch $CONT + start=`date '+%s'` + while [ `date '+%s'` -lt $((start + 300)) ]; do + m=$1 + mount_nullfs $nullfs_srcdir ${nullfs_dstdir}$m > \ + /dev/null 2>&1 + opt=`[ $(( m % 2 )) -eq 0 ] && echo -f` + while mount | grep -q ${nullfs_dstdir}$m; do + umount $opt ${nullfs_dstdir}$m > \ + /dev/null 2>&1 + done + done + rm -f $CONT + fi +fi diff --git a/tools/test/stress2/misc/nullfs18.sh b/tools/test/stress2/misc/nullfs18.sh new file mode 100755 index 000000000000..1f3320bff1e6 --- /dev/null +++ b/tools/test/stress2/misc/nullfs18.sh @@ -0,0 +1,133 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Demonstate nullfs(5) inode leak. +# Fixed by r295717. + +. ../default.cfg + +N=3 + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs -n md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 / N)) +export INODES=$(($2 / N)) + +export runRUNTIME=2m +export LOAD=80 +export symlinkLOAD=80 +export rwLOAD=80 +export TESTPROGS=" +testcases/rw/rw +testcases/creat/creat +testcases/mkdir/mkdir +" + +for i in `jot $N 1`; do + eval mp$i=${mntpoint}$i +done + +for i in `jot $N 1`; do + eval mp=\$mp$i + [ -d $mp ] || mkdir -p $mp + mount | grep $mp | grep -q nullfs && umount -f $mp + msrc=$mntpoint/d$i + mkdir -p $msrc + chmod 777 $msrc + mount -t nullfs $msrc $mp + chmod 777 $mp + export RUNDIR=$mp/stressX + export CTRLDIR=$mp/stressX.control + mkdir $RUNDIR $CTRLDIR + chmod 777 $RUNDIR $CTRLDIR + su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > \ + /dev/null 2>&1 & + mps="$mps $mp" +done + +(cd ../testcases/swap; ./swap -t 10m -i 20 > /dev/null 2>&1) & +sleep 1 +while pgrep -q run; do + find $mps -ls > /dev/null 2>&1 +done +while pgrep -q swap; do + pkill -9 swap +done +wait + +(cd $mntpoint; find . -delete) +sync; sleep 1; sync; sleep 1; sync +inodes=`df -i $mntpoint | tail -1 | awk '{print $6}'` +if [ $inodes -ne 4 ]; then + echo "FAIL 1" + e=1 + mount | sed -n "1p;/${mntpoint#/}/p" + echo + df -ik | sed -n "1p;/${mntpoint#/}/p" + printf "\nfind ${mntpoint}* -ls\n" + find ${mntpoint}* -ls + + for i in `jot $N 1`; do + eval mp=\$mp$i + echo "umount $mp" + mount | grep $mp | grep -q nullfs && umount $mp + done + + echo + df -ik | sed -n "1p;/${mntpoint#/}/p" +else + for i in `jot $N 1`; do + eval mp=\$mp$i + mount | grep $mp | grep -q nullfs && umount $mp + done + inodes=`df -i $mntpoint | tail -1 | awk '{print $6}'` + if [ $inodes -ne 1 ]; then + echo "FAIL 2" + e=2 + mount | sed -n "1p;/${mntpoint#/}/p" + echo + df -ik | sed -n "1p;/${mntpoint#/}/p" + fi +fi + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +exit $e diff --git a/tools/test/stress2/misc/nullfs19.sh b/tools/test/stress2/misc/nullfs19.sh new file mode 100755 index 000000000000..fd5f16f4b780 --- /dev/null +++ b/tools/test/stress2/misc/nullfs19.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Simplified version of nullfs18.sh + +. ../default.cfg + +N=3 + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs -n $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 / N)) +export INODES=$(($2 / N)) + +export runRUNTIME=2m +export LOAD=80 +export TESTPROGS=" +testcases/creat/creat +testcases/link/link +testcases/mkdir/mkdir +testcases/fts/fts +" + +for i in `jot $N 1`; do + eval mp$i=${mntpoint}$i +done + +for i in `jot $N 1`; do + eval mp=\$mp$i + [ -d $mp ] || mkdir -p $mp + mount | grep $mp | grep -q nullfs && umount -f $mp + msrc=$mntpoint/d$i + mkdir -p $msrc + chmod 777 $msrc + mount -t nullfs $msrc $mp + chmod 777 $mp + export RUNDIR=$mp/stressX + export CTRLDIR=$mp/stressX.control + mkdir $RUNDIR $CTRLDIR + chmod 777 $RUNDIR $CTRLDIR + su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > \ + /dev/null 2>&1 & +done +wait + +for i in `jot $N 1`; do + eval mp=\$mp$i + mount | grep $mp | grep -q nullfs && umount $mp +done + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/nullfs2.sh b/tools/test/stress2/misc/nullfs2.sh new file mode 100755 index 000000000000..96cf57407f9c --- /dev/null +++ b/tools/test/stress2/misc/nullfs2.sh @@ -0,0 +1,54 @@ +#!/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. +# + +# Simple nullfs test scenario. + +# Deadlock seen: +# https://people.freebsd.org/~pho/stress/log/nullfs2-2.txt +# suj34.sh seems to trigger the same problem. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# NULLFS(5) and SUJ has known issues. +mount | grep "on `df $RUNDIR | sed '1d;s/.* //'` " | \ + grep -q "journaled soft-updates" && + { echo "Skipping test due to SUJ."; exit 0; } + +mount | grep -q "on $mntpoint " && umount -f $mntpoint + +mount -t nullfs $RUNDIR $mntpoint + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m +(cd ..; ./run.sh marcus.cfg) + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done diff --git a/tools/test/stress2/misc/nullfs20.sh b/tools/test/stress2/misc/nullfs20.sh new file mode 100755 index 000000000000..78c5295bae32 --- /dev/null +++ b/tools/test/stress2/misc/nullfs20.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# VOP_LOOKUP: 0xfffff8014d6fe000 is not locked but should be +# https://people.freebsd.org/~pho/stress/log/nullfs20.txt + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs -n -b 4096 -f 512 -i 1024 md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +mp2=$mntpoint$((mdstart + 1)) +[ -d $mp2 ] || mkdir -p $mp2 +mount | grep -wq $mp2 && umount $mp2 +mount -t nullfs $mntpoint $mp2 + +export runRUNTIME=10m +export RUNDIR=$mp2/stressX + +export LOAD=100 +export ftsLOAD=100 +export TESTPROGS=" +testcases/fts/fts +testcases/swap/swap +testcases/link/link +" + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +while mount | grep $mp2 | grep -q nullfs; do + umount $mp2 || sleep 1 +done +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + n=$((n + 1)) + [ $n -gt 30 ] && { echo FAIL; exit 1; } +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/nullfs21.sh b/tools/test/stress2/misc/nullfs21.sh new file mode 100755 index 000000000000..209ed65d1d3f --- /dev/null +++ b/tools/test/stress2/misc/nullfs21.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# mv removes the file. This is OK on FreeBSD. +# This is handled on Linux with "mount --bind". + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 512m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs -n -b 4096 -f 512 -i 1024 md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint + +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir -p $mp2 +mount | grep -wq $mp2 && umount $mp2 +mount -t nullfs $mntpoint $mp2 + +touch $mntpoint/file + +# mv's rename(2) fails as this is a "cross mount" -> +# rm dst; cp src dst; rm src + +mv $mp2/file $mountpoint/file +[ -f $mntpoint/file ] || + { ls -ali $mntpoint $mp2; status=0; } +# { echo FAIL; ls -ali $mntpoint $mp2; status=1; } + +while mount | grep $mp2 | grep -q nullfs; do + umount $mp2 || sleep 1 +done +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + n=$((n + 1)) + [ $n -gt 30 ] && { echo FAIL; status=2; } +done +mdconfig -d -u $mdstart +exit $status diff --git a/tools/test/stress2/misc/nullfs22.sh b/tools/test/stress2/misc/nullfs22.sh new file mode 100755 index 000000000000..f7652d71bf40 --- /dev/null +++ b/tools/test/stress2/misc/nullfs22.sh @@ -0,0 +1,247 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# fcntl(2) locking scenario, using UFS and a nullfs mount. +# No problems seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > nullfs22.c +mycc -o nullfs22 -Wall -Wextra -O0 -g nullfs22.c || exit 1 +rm -f nullfs22.c + +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir -p $mp2 +mount | grep -q "on $mp2 " && umount $mp2 +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 512m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs -n md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +mount -t nullfs $mntpoint $mp2 + +/tmp/nullfs22 $mntpoint $mp2 +status=$? + +while mount | grep -q "on $mp2 "; do + umount $mp2 +done +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/nullfs22 +exit $status +EOF +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 1024 +#define N (512) +#define PARALLEL 4 + +#define DONE 1 +#define SYNC 0 + +int fd; +volatile u_int *share; +char name1[80], name2[80]; + +static void +ahandler(int s __unused) +{ + fprintf(stderr, "In alarm handler\n"); + unlink(name1); + _exit(1); +} + +void +add(int n, int increment) +{ + struct flock fl; + off_t pos; + long val, oval; + int r; + + pos = n * sizeof(val); + memset(&fl, 0, sizeof(fl)); + fl.l_start = pos; + fl.l_len = sizeof(val); + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + + while (fcntl(fd, F_SETLKW, &fl) < 0) { + if (errno != EAGAIN) + err(1, "F_SETLKW (child)"); + usleep(100); + } + + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + oval = 999999; + while ((r = read(fd, &val, sizeof(val)) != sizeof(val))) { + if (r == -1 && errno != EAGAIN) + err(1, "read"); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + } + oval = val; + val = val + increment; +#if defined(DEBUG) + fprintf(stderr, "add(%d, %d) @ pos %ld: %ld = %ld + %d\n", + n, increment, (long)pos, val, oval, increment); +#endif + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + while ((r = write(fd, &val, sizeof(val)) != sizeof(val))) { + if (r == -1 && errno != EAGAIN) + err(1, "write"); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek"); + } + + fl.l_type = F_UNLCK; + if (fcntl(fd, F_SETLK, &fl) < 0) + err(1, "F_UNLCK"); + +} + +void +count(int val) +{ + int i, j; + char help[80], *name; + + if (val == 1) + name = name1; + else + name = name2; + snprintf(help, sizeof(help), "%s %d %s", __func__, val, name); + setproctitle("%s", help); + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != 2 * PARALLEL) + ; + + /* Need to re-open after a fork() */ + close(fd); + if ((fd = open(name, O_RDWR)) == -1) + err(1, "open(%s)", name); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < N; j++) + add(j, val); + } + + atomic_add_int(&share[DONE], 1); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + off_t len; + size_t mlen; + long val, sum; + int i, s, stat; + + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + + mlen = PAGE_SIZE; + if ((share = mmap(NULL, mlen, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + snprintf(name1, sizeof(name1), "%s/work", argv[1]); + snprintf(name2, sizeof(name2), "%s/work", argv[2]); + signal(SIGALRM, ahandler); + alarm(300); + if ((fd = open(name1, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) + err(1, "open(%s)", name1); + len = N * sizeof(val); + if (ftruncate(fd, len) == -1) + err(1, "ftruncate"); + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + count(1); + } + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + count(-1); + } + + while (share[DONE] != 2 * PARALLEL) + usleep(10000); + + if (lseek(fd, 0, SEEK_SET) == -1) + err(1, "lseek"); + sum = 0; + for (i = 0; i < N; i++) { + if (read(fd, &val, sizeof(val)) != sizeof(val)) + err(1, "Final read"); + if (val != 0) + fprintf(stderr, "index %d: %ld\n", i, val); + sum += val; + } + if (sum != 0) + fprintf(stderr, "FAIL\n"); + unlink(name1); + + s = 0; + for (i = 0; i < PARALLEL; i++) { + wait(&stat); + s += WEXITSTATUS(stat); + wait(&stat); + s += WEXITSTATUS(stat); + } + + close(fd); + + return (sum != 0 || s != 0); +} diff --git a/tools/test/stress2/misc/nullfs23.sh b/tools/test/stress2/misc/nullfs23.sh new file mode 100755 index 000000000000..3e91c04d91b4 --- /dev/null +++ b/tools/test/stress2/misc/nullfs23.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# "panic: Lock (lockmgr) nullfs not locked @ kern/kern_lock.c:620." seen: +# https://people.freebsd.org/~pho/stress/log/nullfs23.txt + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +mp2=/media +mount | grep "$mp2" | grep -q nfs && umount $mp2 +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mp2 + +export nullfs_srcdir=$mp2 +../misc/nullfs17.sh + +umount $mp2 +while mount | grep "$mp2 " | grep -q nfs; do + umount -f $mp2 +done +exit 0 diff --git a/tools/test/stress2/misc/nullfs24.sh b/tools/test/stress2/misc/nullfs24.sh new file mode 100755 index 000000000000..d7741c52a73a --- /dev/null +++ b/tools/test/stress2/misc/nullfs24.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# Variation of nullfs.sh + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +: ${nullfs_srcdir:=/tmp} +: ${nullfs_dstdir:=$mntpoint} +runtime=300 + +for i in `jot $mounts`; do + [ ! -d ${nullfs_dstdir}$i ] && mkdir ${nullfs_dstdir}$i + mount | grep -q " ${nullfs_dstdir}$i " && + umount ${nullfs_dstdir}$i +done + +for i in `jot $mounts`; do + start=`date '+%s'` + while [ `date '+%s'` -lt $((start + $runtime)) ]; do + find ${nullfs_dstdir}* -type f -maxdepth 2 -ls > \ + /dev/null 2>&1 + done & +done + +(cd ../testcases/swap; ./swap -t ${runtime}s -i 20) & +for i in `jot $mounts`; do + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ `date '+%s'` -lt $((start + $runtime)) ]; do + mount_nullfs $nullfs_srcdir ${nullfs_dstdir}$i > \ + /dev/null 2>&1 + opt=$([ `jot -r 1 0 1` -eq 0 ] && echo "-f") + while mount | grep -q ${nullfs_dstdir}$i; do + umount $opt ${nullfs_dstdir}$i > \ + /dev/null 2>&1 + done + done & +done +wait +exit 0 diff --git a/tools/test/stress2/misc/nullfs25.sh b/tools/test/stress2/misc/nullfs25.sh new file mode 100755 index 000000000000..5588567ead22 --- /dev/null +++ b/tools/test/stress2/misc/nullfs25.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Variation of nullfs17.sh WiP + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +mounts=4 # Number of parallel scripts +: ${nullfs_srcdir:=$mntpoint} +: ${nullfs_dstdir:=$mntpoint} +CONT=/tmp/nullfs25.continue + +mount | grep $mntpoint | grep -q /dev/md && 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint +(cd $mntpoint; jot 500 | xargs touch) +(cd ../testcases/swap; ./swap -t 5m -i 20 > /dev/null) & + +for i in `jot $mounts $mdstart`; do + [ ! -d ${nullfs_dstdir}$i ] && mkdir ${nullfs_dstdir}$i + mount | grep -q " ${nullfs_dstdir}$i " && + umount ${nullfs_dstdir}$i +done + +# Start the parallel tests +touch $CONT +for i in `jot $mounts $mdstart`; do + while [ -f $CONT ]; do + find ${nullfs_dstdir}$i -type f -maxdepth 2 -ls > \ + /dev/null 2>&1 + done & + # The test: Parallel mount and unmounts + start=`date +%s` + ( + while [ $((`date +%s` - start)) -lt 300 ]; do + mount_nullfs $nullfs_srcdir ${nullfs_dstdir}$i > \ + /dev/null 2>&1 + opt=$([ `jot -r 1 0 1` -eq 0 ] && echo "-f") + while mount | grep -q ${nullfs_dstdir}$i; do + umount $opt ${nullfs_dstdir}$i > \ + /dev/null 2>&1 + done + done + rm -f $CONT + ) & +done +while [ -f $CONT ] ; do sleep 1; done +while pgrep -q swap; do pkill swap; done +wait + +for i in `jot $mounts`; do + umount ${nullfs_dstdir}$i > /dev/null 2>&1 +done +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; } +done +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/nullfs26.sh b/tools/test/stress2/misc/nullfs26.sh new file mode 100755 index 000000000000..720021e9e199 --- /dev/null +++ b/tools/test/stress2/misc/nullfs26.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# +. ../default.cfg + +# nullfs + tmpfs scenario. No problems seen. + +mp1=${mntpoint}$mdstart +mp2=${mntpoint}$((mdstart + 1)) +mkdir -p $mp1 $mp2 +mount -o size=5g -t tmpfs null $mp1 || exit 1 +mount -t nullfs $mp1 $mp2 || exit 1 + +export runRUNTIME=10m +export RUNDIR=$mp2/stressX +mkdir -p $RUNDIR; chmod 0777 $RUNDIR + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' + +umount $mp2 +umount $mp1 +exit 0 diff --git a/tools/test/stress2/misc/nullfs27.sh b/tools/test/stress2/misc/nullfs27.sh new file mode 100755 index 000000000000..02894fba5efb --- /dev/null +++ b/tools/test/stress2/misc/nullfs27.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Run all the rename(2) test scenarios with nullfs. +# Used in connection with WiP work on nullfs. + +. ../default.cfg + +set -e +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +mp2=${mntpoint}2 +[ -d $mp2 ] || mkdir -p $mp2 +mount | grep -wq $mp2 && umount $mp2 +mount -t nullfs $mntpoint $mp2 +chmod 777 $mp2 +set +e + +export LOAD=80 +export MAXSWAPPCT=80 +export RUNDIR=$mp2/stressX +export runRUNTIME=10m +export rwLOAD=80 +export TESTPROGS=' +testcases/lockf2/lockf2 +testcases/symlink/symlink +testcases/openat/openat +testcases/socket/socket +testcases/rw/rw +testcases/mmap/mmap +testcases/fts/fts +testcases/link/link +testcases/lockf/lockf +testcases/creat/creat +testcases/mkdir/mkdir +testcases/rename/rename +testcases/swap/swap +testcases/mkfifo/mkfifo +testcases/dirnprename/dirnprename +testcases/dirrename/dirrename +' + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +while mount | grep $mp2 | grep -q nullfs; do + umount $mp2 || sleep 1 +done +n=0 +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + n=$((n + 1)) + [ $n -gt 30 ] && { echo FAIL; status=2; } +done +mdconfig -d -u $mdstart +exit $status diff --git a/tools/test/stress2/misc/nullfs3.sh b/tools/test/stress2/misc/nullfs3.sh new file mode 100755 index 000000000000..36a606ce7b7e --- /dev/null +++ b/tools/test/stress2/misc/nullfs3.sh @@ -0,0 +1,56 @@ +#!/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 scenario by "Paul B. Mahol" + +# Caused: lock violation + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# NULLFS(5) and SUJ has known issues. +mount | grep "on `df $RUNDIR | sed '1d;s/.* //'` " | \ + grep -q "journaled soft-updates" && + { echo "Skipping test due to SUJ."; exit 0; } + +[ -d $RUNDIR/stressX ] || mkdir -p $RUNDIR/stressX + +mp=$mntpoint +mount | grep -q $mp && umount -f $mp + +mount -t nullfs `dirname $RUNDIR` $mp + +cd $mp/stressX +whereis something > /dev/null +cd / + +umount $mp + +mount | grep -q $mp && umount -f $mp +exit 0 diff --git a/tools/test/stress2/misc/nullfs4.sh b/tools/test/stress2/misc/nullfs4.sh new file mode 100755 index 000000000000..ac328196f56a --- /dev/null +++ b/tools/test/stress2/misc/nullfs4.sh @@ -0,0 +1,50 @@ +#!/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 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/tools/test/stress2/misc/nullfs5.sh b/tools/test/stress2/misc/nullfs5.sh new file mode 100755 index 000000000000..fa73b8179817 --- /dev/null +++ b/tools/test/stress2/misc/nullfs5.sh @@ -0,0 +1,79 @@ +#!/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. +# + +# Composite test: nullfs2.sh + kinfo.sh + +# Kernel page fault with the following non-sleepable locks held from +# nullfs/null_vnops.c:531 + +# Fatal trap 12: page fault while in kernel mode +# https://people.freebsd.org/~pho/stress/log/jeff106.txt + +# panic: vholdl: inactive held vnode: +# https://people.freebsd.org/~pho/stress/log/kostik815.txt + +# umount busy seen: +# https://people.freebsd.org/~pho/stress/log/kostik893.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# NULLFS(5) and SUJ has known issues. +mount | grep "on `df $RUNDIR | sed '1d;s/.* //'` " | \ + grep -q "journaled soft-updates" && + { echo "Skipping test due to SUJ."; exit 0; } + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d;s/60/600/' < $odir/kinfo.sh > kinfo.c +mycc -o kinfo -Wall -g kinfo.c -lutil +rm -f kinfo.c +cd $odir + +mount | grep -q procfs || mount -t procfs procfs /proc + +for j in `jot 5`; do + /tmp/kinfo & +done + +mount | grep -q $mntpoint && umount -f $mntpoint + +mount -t nullfs `dirname $RUNDIR` $mntpoint + +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m +#(cd ..; ./run.sh marcus.cfg) +(cd ..; timeout -k 15m 12m ./run.sh marcus.cfg) + +umount $mntpoint 2>&1 | grep -v busy + +mount | grep -q $mntpoint && umount -f $mntpoint + +wait +rm -f /tmp/kinfo diff --git a/tools/test/stress2/misc/nullfs6.sh b/tools/test/stress2/misc/nullfs6.sh new file mode 100755 index 000000000000..628e2fe2bfd7 --- /dev/null +++ b/tools/test/stress2/misc/nullfs6.sh @@ -0,0 +1,50 @@ +#!/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. +# + +# 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 + +nullfs_srcdir=${nullfs_srcdir:-/tmp} +mount | grep nullfs | grep -q $nullfs_srcdir/1 && umount $nullfs_srcdir/1 + +rm -rf $nullfs_srcdir/1 $nullfs_srcdir/2 +mkdir $nullfs_srcdir/1 $nullfs_srcdir/2 +touch $nullfs_srcdir/1/test.file + +mount -t nullfs $nullfs_srcdir/1 $nullfs_srcdir/2 + +cp $nullfs_srcdir/1/test.file $nullfs_srcdir/2/test.file # scenario by kib +mv $nullfs_srcdir/1/test.file $nullfs_srcdir/2/ # panics with lock violation + +umount $nullfs_srcdir/1 +rm -rf $nullfs_srcdir/1 $nullfs_srcdir/2 diff --git a/tools/test/stress2/misc/nullfs7.sh b/tools/test/stress2/misc/nullfs7.sh new file mode 100755 index 000000000000..329258f5af4d --- /dev/null +++ b/tools/test/stress2/misc/nullfs7.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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. +# + +# "panic: Lock ufs not locked @ ../../../kern/vfs_default.c:508" seen. +# Based on scenario by Subbsd +# Fixed in r226681 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +# NULLFS(5) and SUJ has known issues. +mount | grep "on `df $RUNDIR | sed '1d;s/.* //'` " | \ + grep -q "journaled soft-updates" && + { echo "Skipping test due to SUJ."; exit 0; } + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +[ -d $RUNDIR ] || mkdir -p $RUNDIR +for i in `jot 50`; do + DST="$mntpoint/$i" + [ -d "$DST" ] || mkdir $DST + mount -oro -t nullfs $RUNDIR $DST + mount -orw -t nullfs /bin $DST +done +mount | grep nullfs | awk '{print $3}' | xargs umount + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + [ $((n += 1)) -gt 100 ] && exit 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/nullfs8.sh b/tools/test/stress2/misc/nullfs8.sh new file mode 100755 index 000000000000..c0c19fb48bdb --- /dev/null +++ b/tools/test/stress2/misc/nullfs8.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Based on scenario by rea@, kern/164261. Different panic. +# insmntque: mp-safe fs and non-locked vp: 0xcb413984 is not exclusive +# locked but should be + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +nullfs_srcdir=${nullfs_srcdir:-/tmp} +opt="-o nfsv3,rw,udp,rdirplus,noauto,retrycnt=3" +grep -q $mntpoint /etc/exports || + { echo "$mntpoint missing from /etc/exports"; exit 0; } + +mount | grep -wq $mntpoint && umount $mntpoint +mount -t nullfs $nullfs_srcdir $mntpoint + +mntpoint2=${mntpoint}2 +mntpoint3=${mntpoint}3 +for m in $mntpoint2 $mntpoint3; do + [ -d $m ] || mkdir $m + mount | grep -wq $m && umount $m + mount -t nfs $opt 127.0.0.1:$mntpoint $m +done + +for i in `jot 50` ; do + su $testuser -c "cp -r /usr/include $mntpoint2/nullfs8-2 2>/dev/null" & + su $testuser -c "cp -r /usr/include $mntpoint3/nullfs8-2 2>/dev/null" & + wait + su $testuser -c "find $mntpoint2 > /dev/null 2>&1" & + su $testuser -c "find $mntpoint3 > /dev/null 2>&1" & + wait + rm -rf $nullfs_srcdir/nullfs8-2 +done + +for m in $mntpoint3 $mntpoint2 $mntpoint; do + while mount | grep -wq $m; do + umount $m || sleep 1 + done +done diff --git a/tools/test/stress2/misc/nullfs9.sh b/tools/test/stress2/misc/nullfs9.sh new file mode 100755 index 000000000000..e74cde947924 --- /dev/null +++ b/tools/test/stress2/misc/nullfs9.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# nullfs + tmpfs regression test: +# ETXTBSY problem of executable +# Fails with "./nullfs9.sh: cannot create /mnt2/mp/true: Text file busy" + +. ../default.cfg + +mnt2=${mntpoint}2 +mount | grep -q $mnt2/mp && umount $mnt2/mp + +[ -d $mnt2 ] || mkdir $mnt2 +mount | grep $mnt2 | grep -q /dev/md && umount -f $mnt2 +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mnt2 +chmod 777 $mnt2 + +mount | grep $mntpoint | grep -q tmpfs && umount -f $mntpoint +mount -t tmpfs tmpfs $mntpoint +chmod 777 $mntpoint + +mkdir $mnt2/mp +mount -t nullfs $mntpoint $mnt2/mp + +# OK +cp /usr/bin/true $mnt2/mp/true +$mntpoint/true +if ! > $mntpoint/true ; then + echo FAIL 1 + mount | egrep "tmpfs|nullfs|$mntpoint |$mnt2 " +fi +rm -f $mntpoint/true + +# Fails +cp /usr/bin/true $mnt2/mp/true +$mnt2/mp/true +if ! > $mnt2/mp/true; then + echo FAIL 2 + mount | egrep "tmpfs|nullfs|$mntpoint |$mnt2 " +fi +rm -f $mnt2/mp/true + +umount $mnt2/mp +while mount | grep -q "$mnt2 "; do + umount $mnt2 || sleep 1 +done +mdconfig -d -u $mdstart + +while mount | grep -q "$mntpoint "; do + umount $mntpoint || sleep 1 +done diff --git a/tools/test/stress2/misc/numa.sh b/tools/test/stress2/misc/numa.sh new file mode 100755 index 000000000000..048eb1201714 --- /dev/null +++ b/tools/test/stress2/misc/numa.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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 scenario: Last memory domain significantly smaller than the others. +# https://people.freebsd.org/~pho/stress/log/numa.txt +# Test scenario description by markj@ + +[ `sysctl -n vm.ndomains` -eq 1 ] && exit 0 + +doms=`sysctl -n vm.ndomains` +phys=`sysctl -n hw.physmem` # clamped size +real=`sysctl -n hw.realmem` # HW size + +goal=$((real - (real / doms) + 2 * 1024 * 1024 * 1024)) +mb=$((goal / 1024 / 1024)) +[ $phys -gt $goal ] && + { echo "hw.physmem must be set to ${mb}M for this test."; exit 0; } + +../misc/sort.sh +exit diff --git a/tools/test/stress2/misc/oom.sh b/tools/test/stress2/misc/oom.sh new file mode 100755 index 000000000000..d64ff9e88182 --- /dev/null +++ b/tools/test/stress2/misc/oom.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 OOM killing. + +# https://people.freebsd.org/~pho/stress/log/kostik847.txt +# Fixed by r290915 and r290917 + +# Expect: +# kernel: pid 5654 (sort), uid 0, was killed: out of swap space + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `sysctl -n hw.physmem` -gt $(( 1 * 1024 * 1024 * 1024)) ] && + echo "RAM should be capped to 1GB for this test." +[ `sysctl -n hw.physmem` -gt $(( 8 * 1024 * 1024 * 1024)) ] && exit 0 +[ `sysctl -n vm.swap_total` -gt 0 ] && { swapoff -a; off=1; } + +for i in `jot 4`; do + sort < /dev/zero & +done +wait +[ -n "$off" ] && swapon -a diff --git a/tools/test/stress2/misc/oom2.sh b/tools/test/stress2/misc/oom2.sh new file mode 100755 index 000000000000..a588c1d6cbde --- /dev/null +++ b/tools/test/stress2/misc/oom2.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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 OOM killing. + +# sort stuck in "pfault" seen. +# https://people.freebsd.org/~pho/stress/log/oom2.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `sysctl -n vm.swap_total` -gt 0 ] && { swapoff -a; off=1; } + +[ `sysctl -n hw.physmem` -gt $((32 * 1024 * 1024 * 1024)) ] && + echo "RAM should be capped to no more than 32GB" +n=`sysctl -n hw.ncpu` +n=`jot $n` +start=`date +%s` +while [ $((`date +%s` - $start)) -lt 300 ]; do + for i in $n; do + sort < /dev/zero > /dev/null 2>&1 & + done + wait +done +[ $off ] && swapon -a +exit 0 diff --git a/tools/test/stress2/misc/oovm.sh b/tools/test/stress2/misc/oovm.sh new file mode 100755 index 000000000000..3eb4418c50d6 --- /dev/null +++ b/tools/test/stress2/misc/oovm.sh @@ -0,0 +1,134 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Out of VM deadlock seen. Introduced by r285808. +# https://people.freebsd.org/~pho/stress/log/oovm.txt +# https://people.freebsd.org/~pho/stress/log/oovm-2.txt + +# Fixed by r290047 and + +# Test scenario suggestion by alc@ + +. ../default.cfg + +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +maxsize=$((2 * 1024)) # Limit size due to runtime reasons +size=$((`sysctl -n hw.physmem` / 1024 / 1024)) +[ $size -gt $((4 * 1024)) ] && + echo "RAM should be capped to 4GB for this test." +[ $size -gt $maxsize ] && size=$maxsize +need=$((size * 2)) +d1=$diskimage.1 +d2=$diskimage.2 +rm -f $d1 $d2 +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print int($4 / 1024)}'` -lt \ + $need ] && printf "Need %d MB on %s.\n" $need `dirname $diskimage` && exit +dd if=/dev/zero of=$d1 bs=1m count=$size status=none +cp $d1 $d2 || exit +trap "rm -f $d1 $d2" EXIT INT + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/oovm.c +mycc -o oovm -Wall -Wextra -g oovm.c || exit 1 +rm -f oovm.c +cd $odir + +(cd /tmp; /tmp/oovm $d1) & +(cd /tmp; /tmp/oovm $d2) & +wait + +rm -f /tmp/oovm /tmp/oovm.core +exit + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +const char *file; + +#define RUNTIME 600 + +void +test(void) +{ + struct stat st; + size_t i, olen, len; + time_t start; + int error, fd, ps; + char *p; + + ps = getpagesize(); + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open(%s)", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = olen = round_page(st.st_size); + do { + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, 0)) == MAP_FAILED) { + if (errno == ENOMEM) + len -= ps; + else + err(1, "mmap"); + } + } while (p == MAP_FAILED); + + start = time(NULL); + /* Touch all pages of the file. */ + for (i = 0; i < len; i += ps) + p[i] = 1; + while (time(NULL) - start < RUNTIME) + p[arc4random() % len] = 1; + + if (munmap(p, len) == -1) + err(1, "unmap()"); + close(fd); +} + +int +main(int argc, char *argv[]) +{ + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + test(); + + return (0); +} diff --git a/tools/test/stress2/misc/oovm2.sh b/tools/test/stress2/misc/oovm2.sh new file mode 100755 index 000000000000..b65194ad792b --- /dev/null +++ b/tools/test/stress2/misc/oovm2.sh @@ -0,0 +1,136 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Out of VM deadlock seen. Introduced by r285808. Variation of oovm.sh +# https://people.freebsd.org/~pho/stress/log/oovm2.txt + +# Fixed by r290047 and + +# Test scenario suggestion by alc@ + +. ../default.cfg + +[ `swapinfo | wc -l` -eq 1 ] && exit 0 +maxsize=$((2 * 1024)) # Limit size due to runtime reasons +size=$((`sysctl -n hw.physmem` / 1024 / 1024)) +[ $size -gt $maxsize ] && size=$maxsize +d1=$diskimage.1 +d2=$diskimage.2 +d3=$diskimage.3 +d4=$diskimage.4 +rm -f $d1 $d2 $d3 $d4 +[ `df -k $(dirname $diskimage) | tail -1 | awk '{print int($4 / 1024)}'` -lt \ + $size ] && printf "Need %d MB on %s.\n" $size `dirname $diskimage` && exit +dd if=/dev/zero of=$d1 bs=1m count=$((size / 4)) status=none +cp $d1 $d2 || exit +cp $d1 $d3 || exit +cp $d1 $d4 || exit +trap "rm -f $d1 $d2 $d3 $d4" EXIT INT + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/oovm2.c +mycc -o oovm2 -Wall -Wextra -g oovm2.c || exit 1 +rm -f oovm2.c +cd $odir + +(cd /tmp; /tmp/oovm2 $d1) & +(cd /tmp; /tmp/oovm2 $d2) & +(cd /tmp; /tmp/oovm2 $d3) & +(cd /tmp; /tmp/oovm2 $d4) & +wait + +rm -f /tmp/oovm2 /tmp/oovm2.core +exit + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +const char *file; + +#define RUNTIME 600 + +void +test(void) +{ + struct stat st; + size_t i, olen, len; + time_t start; + int error, fd, ps; + char *p; + + ps = getpagesize(); + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open(%s)", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = olen = round_page(st.st_size); + do { + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, 0)) == MAP_FAILED) { + if (errno == ENOMEM) + len -= ps; + else + err(1, "mmap"); + } + } while (p == MAP_FAILED); + + start = time(NULL); + /* Touch all pages of the file. */ + for (i = 0; i < len; i += ps) + p[i] = 1; + while (time(NULL) - start < RUNTIME) + p[arc4random() % len] = 1; + + if (munmap(p, len) == -1) + err(1, "unmap()"); + close(fd); +} + +int +main(int argc, char *argv[]) +{ + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + test(); + + return (0); +} diff --git a/tools/test/stress2/misc/open.sh b/tools/test/stress2/misc/open.sh new file mode 100755 index 000000000000..e17df339842e --- /dev/null +++ b/tools/test/stress2/misc/open.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Regression test for: +# Bug 202892 open with O_CREAT | O_DIRECTORY when path references a symlink. +# Fixed by r287599. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/open.c +mycc -o open -Wall -Wextra -O0 -g open.c || exit 1 +rm -f open.c + +wdir=/tmp/open.$$ +rm -rf $wdir +mkdir -p $wdir +cd $wdir +status=0 +/tmp/open || { echo FAIL; status=$?; } +[ -f broken -o -f broken2 ] && { ls -l; echo FAIL; status=1; } +cd $odir + +rm -rf /tmp/open $wdir +exit $status + +EOF +#include +#include +#include +#include +#include + +int +main(void) +{ + int fd; + + /* Setup. */ + if (unlink("broken") <= 0 && errno != ENOENT) + err(1, "unlink(broken)"); + if (unlink("target") <= 0 && errno != ENOENT) + err(1, "unlink(target)"); + if (symlink("target", "broken") < 0) + err(1, "symlink(target, broken)"); + + /* Test. */ + fd = open("broken", O_CREAT | O_DIRECTORY, 0600); + if (fd >= 0) + errx(1, "open(broken, O_CREAT | O_DIRECTORY) - no error"); + + fd = open("broken2", O_CREAT | O_DIRECTORY | O_EXCL, 0600); + if (fd != -1) + errx(1, "open() O_CREAT | O_DIRECTORY | O_EXCL"); + + return (0); +} diff --git a/tools/test/stress2/misc/openlock.sh b/tools/test/stress2/misc/openlock.sh new file mode 100755 index 000000000000..71263b79c02f --- /dev/null +++ b/tools/test/stress2/misc/openlock.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Check O_EXLOCK behaviour on different file types +# Regression test for r313549. + +# Test scenario by kib@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q pty || { kldload pty || exit 0; } + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/openlock.c +mycc -o openlock -Wall -Wextra -O0 -g openlock.c || exit 1 +rm -f openlock.c + +e=0 +echo "expect: \"error 45 Operation not supported\"" +/tmp/openlock /dev/ptmx +s=$? +[ $s -eq 45 ] || { echo "Expected error 45, got $s."; e=1; } +/tmp/openlock /bin/ls +s=$? +[ $s -eq 0 ] || { echo "Expected error 0, got $s."; e=$((e + 2)); } +mkfifo openlock.fifo +s=$? +sleep 1 > openlock.fifo & +/tmp/openlock openlock.fifo +s=$? +[ $s -eq 45 ] || { echo "Expected error 45, got $s."; e=$((e + 4)); } +wait + +rm -f /tmp/openlock openlock.fifo +exit $e +EOF + +/* $Id: openlock.c,v 1.1 2017/02/10 14:07:24 kostik Exp kostik $ */ + +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + int e, fd, i; + + for (i = 1; i < argc; i++) { + fd = open(argv[i], O_RDONLY | O_EXLOCK); + if (fd == -1) { + printf("%s error %d %s\n", argv[i], errno, + strerror(errno)); + e = errno; + } else { + printf("%s success\n", argv[i]); + close(fd); + e = 0; + } + } + return (e); +} + diff --git a/tools/test/stress2/misc/overcommit.sh b/tools/test/stress2/misc/overcommit.sh new file mode 100755 index 000000000000..40f60a32f4af --- /dev/null +++ b/tools/test/stress2/misc/overcommit.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 vm.overcommit + +# Setting bit 0 of the vm.overcommit sysctl causes the virtual memory +# system to return failure to the process when allocation of memory +# causes vm.swap_reserved to exceed vm.swap_total. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +old=`sysctl -n vm.overcommit` +[ $old -eq 1 ] && exit + +sysctl vm.overcommit=1 + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +su $testuser -c 'cd ..; ./run.sh marcus.cfg' + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart + +sysctl vm.overcommit=$old diff --git a/tools/test/stress2/misc/overcommit2.sh b/tools/test/stress2/misc/overcommit2.sh new file mode 100755 index 000000000000..aed26689b933 --- /dev/null +++ b/tools/test/stress2/misc/overcommit2.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 vm.overcommit. Variation of overcommit.sh +# Use a swap backed MD disk with the size of 1.2 * hw.usermem. +# Deadlock seen: https://people.freebsd.org/~pho/stress/log/alan007.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `swapinfo | wc -l` -eq 1 ] && exit 0 + +. ../default.cfg + +old=`sysctl -n vm.overcommit` +[ $old -eq 1 ] && exit + +size=$((`sysctl -n hw.usermem` / 1024 / 1024)) # in MB +size=$((size + size / 100 * 20)) # 120% of hw.usermem +sysctl vm.overcommit=1 +trap "sysctl vm.overcommit=$old" EXIT INT + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s ${size}m -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +echo "Expect: + /mnt: write failed, filesystem is full + dd: /mnt/big.1: No space left on device" + +for i in `jot 10`; do + dd if=/dev/zero of=$mntpoint/big.$i bs=1m status=none +done +wait + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/overflow3.sh b/tools/test/stress2/misc/overflow3.sh new file mode 100755 index 000000000000..a5a29721a30b --- /dev/null +++ b/tools/test/stress2/misc/overflow3.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Mark Johnston +# +# 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. +# +# Leaking fp references when truncating SCM_RIGHTS control messages +# Fixed in r343784 + +. ../default.cfg + +cd /tmp +cat > overflow3.c < +#include + +#include +#include +#include +#include + +int +main(void) +{ + struct iovec iov; + struct msghdr hdr, rhdr; + struct cmsghdr *chdr; + int nfds, sv[2]; + char ch; + + if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) != 0) + err(1, "socketpair"); + + nfds = 253; + + memset(&hdr, 0, sizeof(hdr)); + ch = 'a'; + iov.iov_base = &ch; + iov.iov_len = 1; + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + hdr.msg_control = calloc(1, CMSG_SPACE(nfds * sizeof(int))); + hdr.msg_controllen = CMSG_SPACE(nfds * sizeof(int)); + + chdr = (struct cmsghdr *)hdr.msg_control; + chdr->cmsg_len = CMSG_LEN(nfds * sizeof(int)); + chdr->cmsg_level = SOL_SOCKET; + chdr->cmsg_type = SCM_RIGHTS; + + memset(&rhdr, 0, sizeof(rhdr)); + rhdr.msg_iov = &iov; + rhdr.msg_iovlen = 1; + rhdr.msg_control = calloc(1, CMSG_SPACE(0)); + rhdr.msg_controllen = CMSG_SPACE(0); + + for (;;) { + if (sendmsg(sv[0], &hdr, 0) != 1) + err(1, "sendmsg"); + if (recvmsg(sv[1], &rhdr, 0) != 1) + err(1, "recvmsg"); + if ((rhdr.msg_flags & MSG_CTRUNC) == 0) + errx(1, "MSG_CTRUNC not set"); + } + + return (0); +} +EOF +mycc -o overflow3 -Wall -Wextra -O2 overflow3.c || exit 1 +rm overflow3.c + +timeout 2m ./overflow3 + +rm overflow3 +exit diff --git a/tools/test/stress2/misc/overlap.sh b/tools/test/stress2/misc/overlap.sh new file mode 100755 index 000000000000..f7ac00116559 --- /dev/null +++ b/tools/test/stress2/misc/overlap.sh @@ -0,0 +1,160 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test that fails on various non FreeBSD file systems. +# 3.13.0-74-generic #118-Ubuntu SMP: Mismatch @ count 214, 0 != 123 +# OK on OS X (Darwin Kernel Version 15.5.0) + +# Scanario by: Michael Ubell ubell mindspring com. + +. ../default.cfg + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +sed '1,/^EOF/d' < $0 > /tmp/overlap.c +mycc -o /tmp/overlap -Wall -Wextra -O2 /tmp/overlap.c -lpthread || exit 1 +rm -f /tmp/overlap.c + +size="1g" +mdconfig -a -t swap -s $size -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs -U md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +(cd $mntpoint; /tmp/overlap) +s=$? + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/overlap +exit $s +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char file[128]; +int bsiz, siz; + +void +handler(int s __unused) +{ + _exit(0); +} + +void * +writer(void *arg __unused) { + int fdes, count; + ssize_t nwrite; + int *buf; + + if ((fdes = open(file, O_RDWR|O_CREAT, 0664)) == -1) + err(1, "open(%s)", file); + + count = 0; + buf = malloc(bsiz * sizeof(int)); + buf[0] = buf[bsiz - 1] = 0; + while ((nwrite = pwrite(fdes, buf, siz, 0)) != -1) { + if (nwrite < siz) + err(1, "pwrite @ count %d, nwrite %zd", count, nwrite); + buf[0] = ++buf[bsiz - 1]; + count++; + } + + err(1, "pwrite()"); +} + +void * +reader(void *arg __unused) { + int fdes, count; + ssize_t nread; + int *buf; + + if ((fdes = open(file, O_RDWR|O_CREAT, 0664)) == -1) + err(1, "open(%s)", file); + count = 0; + + buf = malloc(bsiz * sizeof(int)); + while ((nread = pread(fdes, buf, siz, 0)) == 0) + continue; + + do { + if (nread < siz) + err(1, "pread @ count %d, nread %zd", count, nread); + if (buf[0] != buf[bsiz - 1]) { + printf("Mismatch @ count %d, %d != %d\n", + count, buf[0], buf[bsiz - 1]); + abort(); + } + count++; + } while ((nread = pread(fdes, buf, siz, 0)) != -1); + + err(1, "pread()"); +} + +int +main(int argc, char **argv) { + pthread_t rp, wp; + int ret; + void *exitstatus; + + snprintf(file, sizeof(file), "test.%0d5", getpid()); + siz = 65536; + if (argc == 2) + siz = atoi(argv[1]); + + bsiz = siz / sizeof(int); + + signal(SIGALRM, handler); + alarm(300); + + if ((ret = pthread_create(&wp, NULL, writer, NULL)) != 0) + errc(1, ret, "pthread_create"); + if ((ret = pthread_create(&rp, NULL, reader, NULL)) != 0) + errc(1, ret, "pthread_create"); + + pthread_join(rp, &exitstatus); + pthread_join(wp, &exitstatus); + + unlink(file); + return (0); +} diff --git a/tools/test/stress2/misc/pageout.sh b/tools/test/stress2/misc/pageout.sh new file mode 100755 index 000000000000..5497a1135ff4 --- /dev/null +++ b/tools/test/stress2/misc/pageout.sh @@ -0,0 +1,144 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Trigger the two EDEADLK in vm/vm_pageout.c +# OOVM deadlock seen +# https://people.freebsd.org/~pho/stress/log/pageout.txt + +# "panic: handle_written_filepage: not started" seen: +# https://people.freebsd.org/~pho/stress/log/pageout-2.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/pageout.c +mycc -o pageout -Wall -Wextra -g pageout.c || exit 1 +rm -f pageout.c +cd $odir + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +f1=$mntpoint/f1 +dd if=/dev/zero of=$f1 bs=1m count=1k status=none + +daemon sh -c "(cd ../testcases/swap; ./swap -t 5m -i 20 -l 100 -h)" > /dev/null +(cd /tmp; /tmp/pageout $f1) & +sleep .2 +while kill -0 $! 2> /dev/null; do + mksnap_ffs $mntpoint $mntpoint/.snap/stress2 && + rm -f $mntpoint/.snap/stress2 +done +while pgrep -q swap; do + pkill swap +done +wait + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/pageout /tmp/pageout.core +exit + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +const char *file; + +#define RUNTIME 600 + +void +test(void) +{ + struct stat st; + size_t i, len; + time_t start; + int error, fd, ps; + char *p; + + ps = getpagesize(); + if ((fd = open(file, O_RDWR)) == -1) + err(1, "open(%s)", file); + if ((error = fstat(fd, &st)) == -1) + err(1, "stat(%s)", file); + len = round_page(st.st_size); + do { + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, 0)) == MAP_FAILED) { + if (errno == ENOMEM) + len -= ps; + else + err(1, "mmap"); + } + } while (p == MAP_FAILED); + + start = time(NULL); + /* Touch all pages of the file. */ + for (i = 0; i < len; i += ps) + p[i] = 1; + while (time(NULL) - start < RUNTIME) + p[arc4random() % len] = 1; + + if (munmap(p, len) == -1) + err(1, "unmap()"); + close(fd); +} + +int +main(int argc, char *argv[]) +{ + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + file = argv[1]; + + test(); + + return (0); +} diff --git a/tools/test/stress2/misc/parallelmount.sh b/tools/test/stress2/misc/parallelmount.sh new file mode 100755 index 000000000000..5292efbed97a --- /dev/null +++ b/tools/test/stress2/misc/parallelmount.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Parallel mount and unmount of the same mount point +# http://people.freebsd.org/~pho/stress/log/parallelumount3.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +parallel=40 + +if [ $# -eq 0 ]; then + [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + mdconfig -a -t swap -s 10m -u $mdstart || exit 1 + bsdlabel -w md$mdstart auto + newfs $newfs_flags md${mdstart}$part > /dev/null + + # start the parallel tests + for i in `jot $parallel`; do + ./$0 $i & + done + + while kill -0 $! 2> /dev/null; do + for i in `jot 100`; do + find $mntpoint > /dev/null 2>&1 + done + done + wait + + while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + done + mdconfig -d -u $mdstart + exit 0 +else + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt 600 ]; do + mount /dev/md${mdstart}$part $mntpoint + umount $mntpoint + mount + done > /dev/null 2>&1 +fi diff --git a/tools/test/stress2/misc/parallelmount2.sh b/tools/test/stress2/misc/parallelmount2.sh new file mode 100755 index 000000000000..454a7b4b01ed --- /dev/null +++ b/tools/test/stress2/misc/parallelmount2.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC +# 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. +# + +# Quota version of parallelmount.sh +# "umount busy seen: +# https://people.freebsd.org/~pho/stress/log/parallelmount2.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -z "$DEBUG" ] && exit 0 # Waiting for fix +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +. ../default.cfg + +parallel=40 + +if [ $# -eq 0 ]; then + [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + mdconfig -a -t swap -s 10m -u $mdstart || exit 1 + bsdlabel -w md$mdstart auto + newfs $newfs_flags md${mdstart}$part > /dev/null + export PATH_FSTAB=/var/tmp/fstab.$$ + echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" > $PATH_FSTAB + mount /dev/md${mdstart}$part $mntpoint + set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` + export QK=$(($1 / 10 * 8)) + export QI=$(($2 / 10 * 8)) + edquota -u -f $mntpoint -e $mntpoint:$((QK - 50)):$QK:$((QI - 50 )):$QI $testuser + quotaon $mntpoint + umount $mntpoint + + # start the parallel tests + for i in `jot $parallel`; do + ./$0 $i & + done + + while kill -0 $! 2> /dev/null; do + for i in `jot 100`; do + find $mntpoint > /dev/null 2>&1 + done + done + wait + rm -f $PATH_FSTAB + + for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + done + [ $i -eq 6 ] && exit 1 + mdconfig -d -u $mdstart + exit 0 +else + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt 600 ]; do + mount /dev/md${mdstart}$part $mntpoint + quotaon $mntpoint + umount $mntpoint + mount + done > /dev/null 2>&1 +fi diff --git a/tools/test/stress2/misc/pathconf.sh b/tools/test/stress2/misc/pathconf.sh new file mode 100755 index 000000000000..5de6b4e3728d --- /dev/null +++ b/tools/test/stress2/misc/pathconf.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# "panic: _PC_ASYNC_IO should not get here" seen: +# https://people.freebsd.org/~pho/stress/log/pathconf.txt +# Fixed by r320900 + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +mp=${mntpoint}2 +[ -z "$nfs_export" ] && exit 0 +ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || + exit 0 + +syscall=`grep lpathconf /usr/include/sys/syscall.h 2>/dev/null` +[ -z "$syscall" ] && exit 0 +syscall=`echo $syscall | sed 's/.*[\t ]//'` + +mkdir -p $mp/nfs || exit 1 +mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mp/nfs +chmod a+rw $mp/nfs + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 600 ]; do + ../misc/syscall4.sh $syscall +done + +umount $mp/nfs +rm -rf $mp +exit 0 diff --git a/tools/test/stress2/misc/pathconf2.sh b/tools/test/stress2/misc/pathconf2.sh new file mode 100755 index 000000000000..962f26e1aa53 --- /dev/null +++ b/tools/test/stress2/misc/pathconf2.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# "panic: _PC_ASYNC_IO should not get here" seen: +# https://people.freebsd.org/~pho/stress/log/pathconf2.txt +# Fixed by r320900 + +# Test scenario by: Ngie Cooper + +getconf _POSIX_ASYNC_IO /usr/src/ > /dev/null + +exit diff --git a/tools/test/stress2/misc/pause.sh b/tools/test/stress2/misc/pause.sh new file mode 100755 index 000000000000..e786dd6cce0c --- /dev/null +++ b/tools/test/stress2/misc/pause.sh @@ -0,0 +1,159 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Hunt for lost wakeup problem. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/pause.c +mycc -o pause -Wall -Wextra -O0 -g pause.c || exit 1 +rm -f pause.c + +pkill pause +$dir/pause & +pid=$! +start=`date +%s` +while pgrep -q pause; do + sleep .5 + [ $((`date +%s` - $start)) -gt 1200 ] && + { echo "Timed out"; pgrep pause | xargs ps -lp; exit 1; } +done +wait $pid +s=$? + +cd $odir +rm -rf $dir/pause +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#define PARALLEL 400 +#define RUNTIME (5 * 60) +#define SYNC 0 + +void +hand(int i __unused) { +} + +static void +test(int idx) +{ + pid_t pid; + time_t start; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + usleep(1); + share[idx] = 0; + + if ((pid = fork()) == 0) { + share[idx] = 1; + for (;;) + pause(); + _exit(0); + } + while (share[idx] == 0) + usleep(10); + start = time(NULL); + while (time(NULL) - start < 60) { + usleep(arc4random() % 100); + if (kill(pid, SIGHUP) == -1) + err(1, "kill(%d)", pid); + } + kill(pid, SIGTERM); + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid(%d)", pid); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + struct sigaction sa; + size_t len; + time_t start; + int e, i, status; + + sa.sa_handler = hand; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGHUP, &sa, NULL) == -1) + err(1, "sigaction"); + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(i + 1); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/pcatch.sh b/tools/test/stress2/misc/pcatch.sh new file mode 100755 index 000000000000..f1db7de253f2 --- /dev/null +++ b/tools/test/stress2/misc/pcatch.sh @@ -0,0 +1,154 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# The issue makes it possible for applications to get wrong EINTR +# or ERESTART (the later is not directly visible) when doing write +# to the file on suspended UFS volume. I.e. the thread is sleeping +# when fs is suspended, and process is signaled. + +# Test scenario mostly by kib. +# Fixed in r275744. + +# Deadlock seen: +# https://people.freebsd.org/~pho/stress/log/pcatch.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -z "$DEBUG" ] && exit 0 # Waiting for fix + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pcatch.c +mycc -o pcatch -Wall -Wextra -O0 -g pcatch.c || exit 1 +rm -f pcatch.c +cd $here + +mount | grep -q "$mntpoint" && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint + +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 120 ]; do + /tmp/pcatch $mntpoint +done + +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/pcatch +exit 0 +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static void +hand_sigaction(int signo __unused, siginfo_t *si __unused, void *c __unused) +{ +} + +static void +suspend(char *path) +{ + struct statfs s; + int fd, error; + + if (fork() == 0) { + if ((error = statfs(path, &s)) != 0) + err(1, "statfs %s", path); + fd = open("/dev/ufssuspend", O_RDWR); + if ((error = ioctl(fd, UFSSUSPEND, &s.f_fsid)) != 0) + err(1, "UFSSUSPEND"); + sleep(1); + if ((error = ioctl(fd, UFSRESUME, &s.f_fsid)) != 0) + err(1, "UFSRESUME"); + _exit(0); + } +} + +static void +test(char *mp) +{ + pid_t pid; + struct sigaction sa; + int fd; + char buf[80], file[80]; + + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = hand_sigaction; + if (sigaction(SIGUSR1, &sa, NULL) == -1) + err(1, "sigaction"); + + snprintf(file, sizeof(file), "%s/file", mp); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) + err(1, "open(%s). %s:%d", file, __FILE__, __LINE__); + + suspend(mp); + + if ((pid = fork()) == 0) { + if (write(fd, buf, sizeof(buf)) == -1) + warn("FAIL: write"); + _exit(0); + } + usleep(10000); + if (kill(pid, SIGUSR1) == -1) + err(1, "kill"); + wait(NULL); + wait(NULL); + close(fd); +} + +int +main(int argc, char *argv[]) +{ + + if (argc != 2) + errx(1, "Usage: %s ", argv[0]); + + test(argv[1]); + + return (0); +} diff --git a/tools/test/stress2/misc/pcatch2.sh b/tools/test/stress2/misc/pcatch2.sh new file mode 100755 index 000000000000..1c36406fec6f --- /dev/null +++ b/tools/test/stress2/misc/pcatch2.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# Copyright (c) 2016 Dell EMC +# 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. +# + +# Process stuck in "suspfs": +# https://people.freebsd.org/~pho/stress/log/kostik944.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ -z "$DEBUG" ] && exit 0 # Waiting for fix + +for i in `jot 10`; do + ./pcatch.sh & + sleep `jot -r 1 1 5` + kill -INT $! + ./cleanup.sh + pgrep -q pcatch || break + wait +done +pgrep -q pcatch && s=1 || s=0 +exit $s diff --git a/tools/test/stress2/misc/pdfork.sh b/tools/test/stress2/misc/pdfork.sh new file mode 100755 index 000000000000..6c258a83521f --- /dev/null +++ b/tools/test/stress2/misc/pdfork.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# truss / pdfork regression test. +# Test scenario by: Ryan Stone rstone@, slightly mangled by pho@ + +# Interruptable hang seen: +# $ ps -lp992 +# UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND +# 1001 992 991 0 27 0 4168 1908 - TX+ 0 0:00.00 /tmp/pdfork -p +# $ + +cat > /tmp/pdfork.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + pid_t pid; + int fd; + + if (argc > 1 && strcmp(argv[1], "-p") == 0) { + pid = pdfork(&fd, 0); + } else { + pid = fork(); + } + + if (pid == 0) { + sleep(1); + exit(0); + } else if (pid < 0) { + err(1, "fork() failed"); + } else { + int status = 0; + if (argc > 1 && strcmp(argv[1], "-p") != 0) { + int error = wait4(pid, &status, WEXITED, NULL); + if (error < 0) + err(1, "wait4 failed"); + } + exit(status); + } +} +EOF +cc -o /tmp/pdfork -Wall -Wextra -O2 /tmp/pdfork.c || exit 1 + +timeout 20s truss -f /tmp/pdfork 2> /dev/null; s1=$? +timeout 20s truss -f /tmp/pdfork -p 2> /dev/null; s2=$? + +rm -f /tmp/pdfork /tmp/pdfork.c +return $((s1 + s2)) diff --git a/tools/test/stress2/misc/perf.sh b/tools/test/stress2/misc/perf.sh new file mode 100755 index 000000000000..89e9dd8d371c --- /dev/null +++ b/tools/test/stress2/misc/perf.sh @@ -0,0 +1,151 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# O_CREAT / unlink() timing test with different FFS options. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ `uname -m` = "i386" ] && exit 0 # very long runtime + +. ../default.cfg +[ $# -eq 0 ] && half=1 # SU and SUJ workaround +first=1 +export LANG=en_US.ISO8859-1 +odir=`pwd` +dir=$mntpoint + +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > perf.c +mycc -o perf -Wall -Wextra perf.c || exit 1 +rm -f perf.c +cd $odir + +mount | grep -q "on $mntpoint " && umount $mntpoint +mdconfig -l | grep md$mdstart > /dev/null && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart + +tst() { + local i j k s + + s=0 + cd $dir + inodes=`df -ik $mntpoint | tail -1 | \ + awk '{printf "%d\n", $7}'` +# SU and SUJ tests fail with ENOSPC + [ $half ] && + i=$((inodes / 4)) || + i=$(((inodes - 500) / 2)) + [ $first -eq 1 ] && + printf "Using %'\''d inodes out of a total of %'\''d.\n" \ + $((i * 2)) $inodes + first=0 + + for k in `jot 3`; do + pids="" + for j in `jot 2`; do + /tmp/perf $i & + pids="$pids $!" + done + for pid in $pids; do + wait $pid; r=$? + [ $r -ne 0 ] && s=$r + done + done + cd $odir + return $s +} + +s=0 +for i in "" "-U" "-j"; do + newfs $i /dev/md$mdstart > /dev/null 2>&1 + mount /dev/md$mdstart $mntpoint + + t1=`date +%s` + tst; r=$? + t2=$((`date +%s` - t1)) + + umount -f $mntpoint + t2=$((`date +%s` - t1)) + [ $t2 -eq 0 ] && t2=1 + [ -z "$base" ] && base=$t2 + pct=$(((t2 - base) * 100 / base)) + printf '%3d seconds elapsed for newfs option "%2s" (%+4d%%)\n' \ + $t2 "$i" $pct + [ $pct -gt 10 ] && s=111 + [ $s -eq 0 -a $r -ne 0 ] && s=$r +done +rm -f /tmp/perf +mdconfig -d -u $mdstart +exit $s +EOF +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(int argc __unused, char **argv) +{ + pid_t pid; + int64_t size; + int e, fd, i, j; + char file[128]; + + size = atol(argv[1]); + + e = 0; + pid = getpid(); + for (j = 0; j < size; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, + DEFFILEMODE)) == -1) { + e = errno; + if (errno != EINTR) { + warn("open(%s)", file); + printf("break out at %d, errno %d\n", j, + errno); + break; + } + } + close(fd); + } + + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + } + + return (e); +} diff --git a/tools/test/stress2/misc/pfl.sh b/tools/test/stress2/misc/pfl.sh new file mode 100755 index 000000000000..6d590b5cf225 --- /dev/null +++ b/tools/test/stress2/misc/pfl.sh @@ -0,0 +1,188 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test scenario for the change of a global SU lock to a per filesystem lock. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pfl.c +mycc -o pfl -Wall -Wextra pfl.c || exit 1 +rm -f pfl.c +cd $here + +md1=$mdstart +md2=$((mdstart + 1)) +mp1=${mntpoint}$md1 +mp2=${mntpoint}$md2 +mkdir -p $mp1 $mp2 + +usermem=`sysctl -n hw.usermem` +[ `swapinfo | wc -l` -eq 1 ] && usermem=$((usermem/100*80)) +size=$((2 * 1024 * 1024 * 1024)) # Ideal disk size is 2G +[ $((size * 2)) -gt $usermem ] && size=$((usermem / 2)) +size=$((size / 1024 / 1024)) + +opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-j" || echo "-U") +[ "$newfs_flags" = "-U" ] || opt="" +mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1 +[ -c /dev/md$md1 ] && mdconfig -d -u $md1 +mdconfig -a -t swap -s ${size}m -u $md1 +bsdlabel -w md$md1 auto +newfs $opt md${md1}$part > /dev/null +mount /dev/md${md1}$part $mp1 +chmod 777 $mp1 + +mount | grep "on $mp2 " | grep -q /dev/md && umount -f $mp2 +[ -c /dev/md$md2 ] && mdconfig -d -u $md2 +mdconfig -a -t swap -s ${size}m -u $md2 +bsdlabel -w md$md2 auto +newfs $opt md${md2}$part > /dev/null +mount /dev/md${md2}$part $mp2 +chmod 777 $mp2 + +su $testuser -c "cd $mp1; /tmp/pfl" & +pids=$! +su $testuser -c "cd $mp2; /tmp/pfl" & +pids="$pids $!" +sleep .5 +s=0 +start=`date '+%s'` +while pgrep -q pfl; do + if [ $((`date '+%s'`- start)) -gt 900 ]; then + s=1 + echo "$0 timed out." + pkill -9 pfl + fi + sleep 10 +done +for p in $pids; do + wait $p + [ $? -ne 0 ] && s=2 +done + +while mount | grep "$mp2 " | grep -q /dev/md; do + umount $mp2 || sleep 1 +done +mdconfig -d -u $md2 +while mount | grep "$mp1 " | grep -q /dev/md; do + umount $mp1 || sleep 1 +done +rm -f /tmp/pfl +mdconfig -d -u $md1 +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 10 + +static void +test(void) +{ + pid_t pid; + int fd, i, j; + char file[128]; + + pid = getpid(); + sprintf(file,"d%05d", pid); + if (mkdir(file, 0740) == -1) + err(1, "mkdir(%s)", file); + chdir(file); + for (j = 0; j < 10000; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if ((fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0644)) == + -1) { + if (errno != EINTR) { + warn("mkdir(%s). %s:%d", file, __FILE__, + __LINE__); + unlink("continue"); + break; + } + } + if (arc4random() % 100 < 10) + if (write(fd, "1", 1) != 1) + err(1, "write()"); + close(fd); + + } + sleep(3); + + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + } + chdir(".."); + sprintf(file,"d%05d", pid); + if (rmdir(file) == -1) + err(3, "unlink(%s)", file); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + int e, fd, j, k, s; + + umask(0); + if ((fd = open("continue", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + e = 0; + for (j = 0; j < PARALLEL; j++) { + if ((pids[j] = fork()) == 0) { + for (k = 0; k < 40; k++) + test(); + _exit(0); + } + } + + for (j = 0; j < PARALLEL; j++) { + if (waitpid(pids[j], &s, 0) == -1) + err(1, "waitpid(%d)", pids[j]); + e += s == 0 ? 0 : 1; + } + + return (e); +} diff --git a/tools/test/stress2/misc/pfl2.sh b/tools/test/stress2/misc/pfl2.sh new file mode 100755 index 000000000000..9b6497294242 --- /dev/null +++ b/tools/test/stress2/misc/pfl2.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Test scenario for the change of a global SU lock to a per filesystem lock. +# "panic: softdep_write_inodeblock: indirect pointer #0 mismatch ..." seen. +# http://people.freebsd.org/~pho/stress/log/kirk063.txt + +# https://people.freebsd.org/~pho/stress/log/kirk080.txt + +. ../default.cfg + +[ `swapinfo | wc -l` -eq 1 ] && exit 0 + +md1=$mdstart +md2=$((mdstart + 1)) +mp1=${mntpoint}$md1 +mp2=${mntpoint}$md2 +mkdir -p $mp1 $mp2 + +usermem=`sysctl -n hw.usermem` +size=$((2 * 1024 * 1024 * 1024)) # Ideal disk size is 2G +[ $((size * 2)) -gt $usermem ] && size=$((usermem / 2)) +size=$((size / 1024 / 1024)) + +opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-j" || echo "-U") +[ "$newfs_flags" = "-U" ] || opt="" +mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1 +mdconfig -l | grep -q md$md1 && mdconfig -d -u $md1 +mdconfig -a -t swap -s ${size}m -u $md1 +bsdlabel -w md$md1 auto +newfs $opt md${md1}$part > /dev/null +mount /dev/md${md1}$part $mp1 +chmod 777 $mp1 + +mount | grep "on $mp2 " | grep -q /dev/md && umount -f $mp2 +mdconfig -l | grep -q md$md2 && mdconfig -d -u $md2 +mdconfig -a -t swap -s ${size}m -u $md2 +bsdlabel -w md$md2 auto +newfs $opt md${md2}$part > /dev/null +mount /dev/md${md2}$part $mp2 +chmod 777 $mp2 + +export runRUNTIME=10m +export RUNDIR=$mp1/stressX +export CTRLDIR=$mp1/stressX.control +export LOAD=80 +export symlinkLOAD=80 +export rwLOAD=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/mkfifo/mkfifo +" +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > /dev/null 2>&1 & + +export TESTPROGS="$TESTPROGS testcases/swap/swap" +export RUNDIR=$mp2/stressX +export CTRLDIR=$mp2/stressX.control +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > /dev/null 2>&1 & +wait + +while mount | grep "$mp2 " | grep -q /dev/md; do + umount $mp2 || sleep 1 +done +mdconfig -d -u $md2 +while mount | grep "$mp1 " | grep -q /dev/md; do + umount $mp1 || sleep 1 +done +mdconfig -d -u $md1 diff --git a/tools/test/stress2/misc/pfl3.sh b/tools/test/stress2/misc/pfl3.sh new file mode 100755 index 000000000000..8c2bb2396e9d --- /dev/null +++ b/tools/test/stress2/misc/pfl3.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Start pfl.sh and "umount -f" the two mount points in use. +# "panic: handle_written_inodeblock: live inodedep" seen. +# http://people.freebsd.org/~pho/stress/log/pfl3.txt + +# Not seen on FreeBSD 14.0-CURRENT #0 main-n244671-b3c6fe663bb + +. ../default.cfg + +./pfl.sh > /dev/null 2>&1 & +sleep `jot -r 1 10 60` +while mount | grep -q "$mntpoint"; do + umount -f ${mntpoint}$mdstart & pid=$! + umount -f ${mntpoint}$((mdstart + 1)) + wait $pid +done +wait +exit 0 diff --git a/tools/test/stress2/misc/pfl4.sh b/tools/test/stress2/misc/pfl4.sh new file mode 100755 index 000000000000..8128fa1f585c --- /dev/null +++ b/tools/test/stress2/misc/pfl4.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# "panic: invalid queue 255" seen: +# https://people.freebsd.org/~pho/stress/log/pfl4.txt + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le 8 ] && exit 0 + +mounts=4 +newfs_flags="" + +export runRUNTIME=10m +export LOAD=80 +export symlinkLOAD=80 +export rwLOAD=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/mkfifo/mkfifo +" + +prefix=$mntpoint +start=$mdstart +for i in `jot $mounts $start`; do + mdstart=$i + mntpoint=${prefix}$i + [ -d $mntpoint ] || mkdir -p $mntpoint + + mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint + mdconfig -a -t swap -s 2g -u $mdstart + bsdlabel -w md$mdstart auto + newfs $newfs_flags md${mdstart}$part > /dev/null + mount /dev/md${mdstart}$part $mntpoint + chmod 777 $mntpoint + + export RUNDIR=$mntpoint/stressX + export CTRLDIR=$mntpoint/stressX.control + set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` + export KBLOCKS=$(($1 / 1)) + export INODES=$(($2 / 1)) + su $testuser -c 'sleep 2; cd ..; ./testcases/run/run $TESTPROGS' > \ + /dev/null 2>&1 & +done +su $testuser -c "sleep 2; cd ..; ./testcases/swap/swap -t 10m -i 20" & + +wait + +s=0 +for i in `jot $mounts $start`; do + mdstart=$i + mntpoint=${prefix}$i + n=0 + while mount | grep -q "on $mntpoint "; do + umount $mntpoint && mdconfig -d -u $mdstart || sleep 1 + n=$((n += 1)) + [ $n -gt 60 ] && exit 1 + done + checkfs /dev/md${mdstart}$part || s=$? +done +exit $s diff --git a/tools/test/stress2/misc/ping.sh b/tools/test/stress2/misc/ping.sh new file mode 100755 index 000000000000..2594c6d5e43c --- /dev/null +++ b/tools/test/stress2/misc/ping.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# Regression test for r351461. Handle missing time stamp from SO_TIMESTAMP. +# Fixed by r352229 + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +[ -z "$nfs_export" ] && exit 0 +ip=`echo $nfs_export | sed 's/:.*//'` +ping -c 2 $ip > /dev/null 2>&1 || exit 0 + +log=/tmp/ping.log +tail -F -n 0 /var/log/messages > $log & +sleep .5 +pid=$! +for i in `jot 10`; do + ping -c 1 $ip & + pids="$pids $!" +done > /dev/null +for i in $pids; do wait $i; done +kill $pid +wait +grep "(ping)" $log && s=1 || s=0 +rm -f $log +exit $s diff --git a/tools/test/stress2/misc/pipe.sh b/tools/test/stress2/misc/pipe.sh new file mode 100755 index 000000000000..3a27a3dd7d88 --- /dev/null +++ b/tools/test/stress2/misc/pipe.sh @@ -0,0 +1,132 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Stress vm object collapse. + +# "panic: backing_object 0xfffff800a018f420 was somehow re-referenced during +# collapse!" seen with uma_zalloc_arg fail point enabled. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/pipe.c +mycc -o pipe -Wall -Wextra -O0 -g pipe.c || exit 1 +rm -f pipe.c +cd $odir + +daemon sh -c '(cd ../testcases/swap; ./swap -t 10m -i 20)' > /dev/null 2>&1 +sleep 1 +e=0 +export e +start=`date '+%s'` +while [ $((`date '+%s'` - start)) -lt 300 ]; do + for i in `jot $(sysctl -n hw.ncpu)`; do + /tmp/pipe & + pids="$pids $!" + done + for i in $pids; do + wait $i + [ $? -ne 0 ] && e=$((e + 1)) + done + pids="" + [ $e -ne 0 ] && break +done +while pgrep -q swap; do + pkill -9 swap +done +rm -rf /tmp/pipe pipe.core +exit $e + +EOF +#include + +#include +#include +#include +#include + +#define PIPES 64 +#define RUNTIME 300 + +int +test(void) +{ + int c, e, status; + int fds[PIPES][2]; + int i; + + for (i = 0; i < PIPES; i++) { + if (pipe(fds[i]) == -1) + err(1, "pipe"); + } + c = e = 0; + if (write(fds[0][1], &c, sizeof(c)) != sizeof(c)) + err(1, "pipe write"); + for (i = 0; i < PIPES; i++) { + if (fork() == 0) { + close(fds[i][1]); + if (read(fds[i][0], &c, sizeof(c)) != sizeof(c)) + err(1, "pipe read"); +#if defined(DEBUG) + fprintf(stderr, "pid %d: i = %d: read %d\n", getpid(), + i, c); +#endif + c++; + if (i != PIPES - 1) + if (write(fds[i + 1][1], &c, sizeof(c)) != + sizeof(c)) + err(1, "pipe write"); + + _exit(0); + } + close(fds[i][0]); + close(fds[i][1]); + } + for (i = 0; i < PIPES; i++) { + wait(&status); + e += status == 0 ? 0 : 1; + } + + return (e); +} + +int +main(void) +{ + time_t start; + int e; + + e = 0; + start = time(NULL); + while (time(NULL) - start < RUNTIME && e == 0) + e = test(); + + return (e); +} diff --git a/tools/test/stress2/misc/pipe2.sh b/tools/test/stress2/misc/pipe2.sh new file mode 100755 index 000000000000..b20318c45a98 --- /dev/null +++ b/tools/test/stress2/misc/pipe2.sh @@ -0,0 +1,163 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# pipe(2) test + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/pipe2.c +mycc -o pipe2 -Wall -Wextra -O0 -g pipe2.c || exit 1 +rm -f pipe2.c + +daemon sh -c "(cd $odir/../testcases/swap; ./swap -t 10m -i 20)" > \ + /dev/null 2>&1 +sleep 10 + +su $testuser -c /tmp/pipe2 +s=$? + +while pgrep -q swap; do + pkill -9 swap +done + +rm -rf /tmp/pipe2 +exit $s + +EOF +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +volatile u_int *share, *share2; + +#define R1 1 /* sync start */ +#define R2 2 /* forks */ + +#define PIPES 128 +#define PARALLEL 32 + +static void +hand(int i __unused) { /* handler */ + fprintf(stderr, "Timed out\n"); + _exit(1); +} + +void +test(void) +{ + size_t len; + int fds[2], r; + int token; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + if (pipe(fds) == -1) + err(1, "pipe"); + token = 0; + write(fds[1], &token, sizeof(token)); + for (;;) { + if (share[R2] >= PIPES) + break; + if ((r = fork()) == 0) { + atomic_add_int(&share[R2], 1); + if (read(fds[0], &token, sizeof(token)) != sizeof(token)) + err(1, "read"); + close(fds[0]); + if (pipe(fds) == -1) + err(1, "pipe"); + token++; + if (write(fds[1], &token, sizeof(token)) != sizeof(token)) + err(1, "write"); + } + if (r == -1) + err(1, "fork()"); + if (r != 0) + _exit(0); + } + + if (share[R2] == PIPES) { +#if defined(DEBUG) + if (read(fds[0], &token, sizeof(token)) != sizeof(token)) + err(1, "final read"); + fprintf(stderr, "FINAL read %d from %d\n", token, fds[0]); +#endif + atomic_add_int(&share2[R1], 1); + } + _exit(0); +} + +int +main(void) +{ + struct sigaction sa; + size_t len; + int i; + + len = PAGE_SIZE; + if ((share2 = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGCHLD, &sa, 0) == -1) + err(1, "sigaction"); + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + test(); + } + + signal(SIGALRM, hand); + alarm(300); + while (share2[R1] != PARALLEL) { + sleep(1); +#if defined(DEBUG) + fprintf(stderr, "share2 = %d\n", share2[R1]); +#endif + } + + return (0); +} diff --git a/tools/test/stress2/misc/pipe3.sh b/tools/test/stress2/misc/pipe3.sh new file mode 100755 index 000000000000..6208e1a52f90 --- /dev/null +++ b/tools/test/stress2/misc/pipe3.sh @@ -0,0 +1,148 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Peter Holm +# +# 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. +# + +# pipe(2) tests. +# "panic: vm_page_dequeue: queued unlocked page 0xfffffe0019a73518" seen. + +# Reported by syzkaller +# Fixed by r354400 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/pipe3.c +mycc -o pipe3 -Wall -Wextra -O0 -g pipe3.c || exit 1 +rm -f pipe3.c +cd $odir + +(cd ../testcases/swap; ./swap -t 5m -i 20 -l 100) & +sleep 1 +for i in `jot 25`; do + /tmp/pipe3 & +done +while pkill -0 pipe3; do sleep 2; done +while pkill -9 swap; do sleep 1; done +wait +rm -rf /tmp/pipe3 +exit 0 + +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 64 +#define RUNTIME (5 * 60) + +static void +handler(int i __unused) { + _exit(0); +} + +void +test(void) +{ + int fds[2], r; + char c; + + if (pipe(fds) == -1) + err(1, "pipe"); + + if (fork() == 0) { + signal(SIGALRM, handler); + ualarm(1 + arc4random() % 10000, 0); + close(fds[1]); + if ((r = write(fds[0], &c, sizeof(c))) != sizeof(c)) + if (r == -1) + err(1, "pipe write"); + _exit(0); + } + signal(SIGALRM, handler); + ualarm(1 + arc4random() % 10000, 0); + close(fds[0]); + if ((r = read(fds[1], &c, sizeof(c))) != sizeof(c)) + if (r == -1) + err(1, "pipe read"); + wait(NULL); + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL], rpid; + time_t start; + int i, running, status; + bool done; + + for (i = 0; i < PARALLEL; i++) + pids[i] = 0; + running = 0; + start = time(NULL); + for (;;) { + done = (time(NULL) - start) >= RUNTIME; + for (i = 0; i < PARALLEL; i++) { + if (pids[i] == 0 && !done) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + running++; + } + } + for (i = 0; i < PARALLEL; i++) { + if (pids[i] != 0) { + if ((rpid = waitpid(pids[i], &status, + WNOHANG)) == -1) + err(1, "waitpid(%d)", pids[i]); + if (rpid == 0) + continue; + if (rpid != pids[i]) + err(1, "waitpid(%d)", pids[i]); + running --; + pids[i] = 0; + break; + } + } + if (running == 0 && done) + break; + usleep(100); + } + + return (0); +} diff --git a/tools/test/stress2/misc/pipe_enomem.sh b/tools/test/stress2/misc/pipe_enomem.sh new file mode 100755 index 000000000000..92558b164336 --- /dev/null +++ b/tools/test/stress2/misc/pipe_enomem.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Konstantin Belousov +# +# 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. +# + +# Pipe test scenario from https://reviews.freebsd.org/D23993 +# https://gist.github.com/kostikbel/b2844258b7fba6e8ce3ccd8ef9422e5a + +. ../default.cfg + +cd /tmp +cat > pipe_enomem.c < +#include +#include +#include +#include + +struct pipepair { + int pp[2]; +}; + +static struct pipepair *p; + +int +main(void) +{ + int error, pp[2]; + size_t i, k, nsz, sz; + char x; + + sz = 1024; + p = calloc(sz, sizeof(struct pipepair)); + if (p == NULL) { + fprintf(stderr, "calloc: %s\n", strerror(errno)); + exit(1); + } + + for (i = 0;; i++) { + if (pipe(pp) == -1) { + printf("created %zd pipes. syscall error %s\n", + i, strerror(errno)); + break; + } + if (i >= sz) { + nsz = sz * 2; + p = reallocf(p, nsz * sizeof(struct pipepair)); + if (p == NULL) { + fprintf(stderr, "reallocf: %s\n", + strerror(errno)); + exit(1); + } + memset(p + sz, 0, (nsz - sz) * sizeof(struct pipepair)); + sz = nsz; + } + p[i].pp[0]= pp[0]; + p[i].pp[1]= pp[1]; + } + + x = 'a'; + for (k = 0; k < i; k++) { + error = write(p[k].pp[1], &x, 1); + if (error == -1) + printf("pipe %zd fds %d %d error %s\n", + k, p[k].pp[0], p[k].pp[1], strerror(errno)); + else if (error == 0) + printf("pipe %zd fds %d %d EOF\n", + k, p[k].pp[0], p[k].pp[1]); + } +} +EOF + +mycc -o pipe_enomem -Wall -Wextra -O2 pipe_enomem.c || exit 1 +./pipe_enomem 2>&1 | head -5 +rm -f pipe_enomem.c pipe_enomem +exit 0 diff --git a/tools/test/stress2/misc/pkru.sh b/tools/test/stress2/misc/pkru.sh new file mode 100755 index 000000000000..9ac0a5000daf --- /dev/null +++ b/tools/test/stress2/misc/pkru.sh @@ -0,0 +1,512 @@ +#/bin/sh +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Konstantin Belousov +# +# 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 scenario for Intel userspace protection keys feature on Skylake Xeons + +grep -qw PKU /var/run/dmesg.boot || exit 0 +cd /tmp +cat > /tmp/pkru_exec.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TEST_COMPILE +int x86_pkru_get_perm(unsigned int keyidx, int *access, int *modify); +int x86_pkru_set_perm(unsigned int keyidx, int access, int modify); +int x86_pkru_protect_range(void *addr, unsigned long len, unsigned int keyidx, + int flag); +int x86_pkru_unprotect_range(void *addr, unsigned long len); +uint32_t rdpkru(void); +void wrpkru(uint32_t); +#define AMD64_PKRU_PERSIST 0x0001 +#endif + +extern char **environ; + +#define OPKEY 1 + +int +main(void) +{ + char *args[3] = { + "/bin/date", + NULL + }; + struct rlimit rl; + + if (getrlimit(RLIMIT_STACK, &rl) != 0) + err(1, "getrlimit RLIMIT_STACK"); + if (x86_pkru_protect_range(0, 0x800000000000 - rl.rlim_max, OPKEY, + AMD64_PKRU_PERSIST) != 0) + err(1, "x86_pkru_protect_range"); + if (x86_pkru_set_perm(1, 1, 0) != 0) + err(1, "x86_pkru_set_perm"); + execve("/bin/date", args, environ); +} +EOF +cc -Wall -Wextra -g -O -o pkru_exec64 pkru_exec.c || exit 1 +cc -Wall -Wextra -g -O -o pkru_exec32 pkru_exec.c -m32 || exit 1 +rm pkru_exec.c +echo "Expect: Segmentation fault (core dumped)" +LD_BIND_NOW=1 ./pkru_exec64 +LD_BIND_NOW=1 ./pkru_exec32 +rm -f pkru_exec64 pkru_exec32 pkru_exec64.core pkru_exec32.core + +cat > /tmp/pkru_fork.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TEST_COMPILE +int x86_pkru_get_perm(unsigned int keyidx, int *access, int *modify); +int x86_pkru_set_perm(unsigned int keyidx, int access, int modify); +int x86_pkru_protect_range(void *addr, unsigned long len, unsigned int keyidx, + int flag); +int x86_pkru_unprotect_range(void *addr, unsigned long len); +uint32_t rdpkru(void); +void wrpkru(uint32_t); +#endif + +static volatile char *mapping; + +#define OPKEY 1 + +int +main(void) +{ + int error; + pid_t child; + + mapping = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (mapping == MAP_FAILED) + err(1, "mmap"); + error = x86_pkru_protect_range((void *)mapping, getpagesize(), + OPKEY, 0); + if (error != 0) + err(1, "x86_pkru_protect_range"); + error = x86_pkru_set_perm(OPKEY, 0, 0); + if (error != 0) + err(1, "x86_pkru_set_perm"); + child = fork(); + if (child == -1) + err(1, "fork"); + if (child == 0) { + *mapping = 0; + printf("Still alive, pkru did not worked after fork"); + } + waitpid(child, NULL, 0); +} +EOF +cc -Wall -Wextra -g -O -o pkru_fork64 pkru_fork.c || exit 1 +cc -Wall -Wextra -g -O -o pkru_fork32 -m32 pkru_fork.c || exit 1 +rm pkru_fork.c +./pkru_fork64 +./pkru_fork32 +rm -f pkru_fork64 pkru_fork64.core pkru_fork32 pkru_fork32.core + +cat > /tmp/pkru_perm.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TEST_COMPILE +int x86_pkru_get_perm(unsigned int keyidx, int *access, int *modify); +int x86_pkru_set_perm(unsigned int keyidx, int access, int modify); +int x86_pkru_protect_range(void *addr, unsigned long len, unsigned int keyidx, + int flag); +int x86_pkru_unprotect_range(void *addr, unsigned long len); +uint32_t rdpkru(void); +void wrpkru(uint32_t); +#define AMD64_PKRU_PERSIST 0x0001 +#endif + +static void +sighandler(int signo __unused, siginfo_t *si __unused, void *uc1 __unused) +{ + + exit(0); +} + +static volatile char *mapping; + +#define OPKEY 1 + +int +main(void) +{ + struct sigaction sa; + char *mapping1; + int error; + + error = x86_pkru_set_perm(OPKEY, 0, 0); + if (error != 0) + err(1, "x86_pkru_set_perm"); + mapping = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (mapping == MAP_FAILED) + err(1, "mmap"); + error = x86_pkru_protect_range((void *)mapping, getpagesize(), + OPKEY, 0); + if (error != 0) + err(1, "x86_pkru_protect_range"); + error = munmap((void *)mapping, getpagesize()); + if (error != 0) + err(1, "munmap"); + mapping1 = mmap((void *)mapping, getpagesize(), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_EXCL, -1, 0); + if (mapping1 == MAP_FAILED) + err(1, "mmap 2"); + *mapping = 0; + error = x86_pkru_protect_range((void *)mapping, getpagesize(), + OPKEY, AMD64_PKRU_PERSIST); + mapping1 = mmap((void *)mapping, getpagesize(), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0); + if (mapping1 == MAP_FAILED) + err(1, "mmap 3"); + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = sighandler; + sa.sa_flags = SA_SIGINFO; + if (sigaction(SIGSEGV, &sa, NULL) == -1) + err(1, "sigaction"); + *mapping = 0; + printf("Still alive, pkru persist did not worked"); + exit(1); +} +EOF +cc -Wall -Wextra -g -O -o pkru_perm64 pkru_perm.c || exit 1 +cc -Wall -Wextra -g -O -o pkru_perm32 -m32 pkru_perm.c || exit 1 +rm pkru_perm.c +./pkru_perm64 +./pkru_perm32 +rm -f pkru_perm64 pkru_perm32 + +cat > /tmp/pkru.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TEST_COMPILE +int x86_pkru_get_perm(unsigned int keyidx, int *access, int *modify); +int x86_pkru_set_perm(unsigned int keyidx, int access, int modify); +int x86_pkru_protect_range(void *addr, unsigned long len, unsigned int keyidx, + int flag); +int x86_pkru_unprotect_range(void *addr, unsigned long len); +uint32_t rdpkru(void); +void wrpkru(uint32_t); +#endif + +static char *mut_region; +static size_t mut_region_len; +static unsigned *mut_region_keys; +static pthread_t bga_thr; +static int signal_seen; +static siginfo_t si_seen; +static ucontext_t *uc_seen; +static u_int rpku_offset; + +static void +handler(int i __unused) { + _exit(0); +} + +static void +report_sig(int signo, siginfo_t *si, ucontext_t *uc) +{ + + printf("signal %d %s", signo, strsignal(signo)); + printf(" si_code %d si_status %d si_addr %p", si->si_code, + si->si_status, si->si_addr); + printf(" mc_err %#jx", (uintmax_t)uc->uc_mcontext.mc_err); + if (uc->uc_mcontext.mc_xfpustate != 0 && + (unsigned long)uc->uc_mcontext.mc_xfpustate_len >= + rpku_offset) { + printf(" pkru 0x%08x", *(uint32_t *)( + uc->uc_mcontext.mc_xfpustate + rpku_offset)); + } + printf("\n"); +} + +static void +sighandler(int signo, siginfo_t *si, void *u) +{ + ucontext_t *uc; + pthread_t thr; + size_t len; + uint32_t *pkrup; + + uc = u; + thr = pthread_self(); + if (thr == bga_thr) { + printf("Fault from background access thread\n"); + report_sig(signo, si, uc); + exit(1); + } + signal_seen = signo; + si_seen = *si; + + len = sizeof(ucontext_t); + if (uc->uc_mcontext.mc_xfpustate != 0) + len += uc->uc_mcontext.mc_xfpustate_len; + uc_seen = malloc(len); + if (uc_seen == NULL) + err(1, "malloc(%d)", (int)len); + memcpy(uc_seen, uc, sizeof(*uc)); +#if 0 +printf("signal %d xpfustate %p len %ld rpkuo %u\n", signo, (void *)uc->uc_mcontext.mc_xfpustate, uc->uc_mcontext.mc_xfpustate_len, rpku_offset); +#endif + if (uc->uc_mcontext.mc_xfpustate != 0) { + uc_seen->uc_mcontext.mc_xfpustate = (uintptr_t)uc_seen + + sizeof(*uc); + memcpy((void *)uc_seen->uc_mcontext.mc_xfpustate, + (void *)uc->uc_mcontext.mc_xfpustate, + uc->uc_mcontext.mc_xfpustate_len); + + if ((unsigned long)uc->uc_mcontext.mc_xfpustate_len >= + rpku_offset + sizeof(uint32_t)) { + pkrup = (uint32_t *)(rpku_offset + + (char *)uc->uc_mcontext.mc_xfpustate); +#if 0 +printf("signal %d *pkru %08x\n", signo, *pkrup); +#endif + *pkrup = 0; + } + } +} + +static void * +bg_access_thread_fn(void *arg __unused) +{ + char *c, x; + + pthread_set_name_np(pthread_self(), "bgaccess"); + for (x = 0, c = mut_region;;) { + *c = x; + if (++c >= mut_region + mut_region_len) { + c = mut_region; + x++; + } + } + return (NULL); +} + +static void +clear_signal_report(void) +{ + + signal_seen = 0; + free(uc_seen); + uc_seen = NULL; +} + +static void +check_signal(unsigned key, int check_access, int check_modify) +{ + + if (signal_seen == 0) { + printf("Did not get signal, key %d check_access %d " + "check_modify %d\n", key, check_access, check_modify); + printf("pkru 0x%08x\n", rdpkru()); + exit(1); + } +} + +static void +check_no_signal(void) +{ + + if (signal_seen != 0) { + printf("pkru 0x%08x\n", rdpkru()); + printf("Got signal\n"); + report_sig(signal_seen, &si_seen, uc_seen); + exit(1); + } +} + +static void +check(char *p, unsigned key, int check_access, int check_modify) +{ + int access, error, modify, orig_access, orig_modify; + + error = x86_pkru_get_perm(key, &orig_access, &orig_modify); + if (error != 0) + err(1, "x86_pkru_get_perm"); + access = check_access ? 0 : 1; + modify = check_modify ? 0 : 1; + error = x86_pkru_set_perm(key, access, modify); + if (error != 0) + err(1, "x86_pkru_set_perm access"); + clear_signal_report(); + if (check_modify) + *(volatile char *)p = 1; + else if (check_access) + *(volatile char *)p; + if (key == mut_region_keys[(p - mut_region) / getpagesize()]) + check_signal(key, check_access, check_modify); + else + check_no_signal(); + error = x86_pkru_set_perm(key, orig_access, orig_modify); + if (error != 0) + err(1, "x86_pkru_set_perm access restore"); + clear_signal_report(); + if (check_modify) + *(volatile char *)p = 1; + else if (check_access) + *(volatile char *)p; + check_no_signal(); +} + +static void +mutate_perms(void) +{ + unsigned key; + char *p; + + for (p = mut_region;;) { + for (key = 1; key < 0x10; key++) { + check(p, key, 1, 0); + check(p, key, 0, 1); + check(p, key, 1, 1); + } + p += getpagesize(); + if (p >= mut_region + mut_region_len) + p = mut_region; + } +} + +int +main(void) +{ + struct sigaction sa; + char *p; + unsigned i; + u_int regs[4]; + int error; + + cpuid_count(0xd, 0x9, regs); + rpku_offset = regs[1]; + if (rpku_offset != 0) +#if defined(__i386__) + rpku_offset -= sizeof(union savefpu); +#else + rpku_offset -= sizeof(struct savefpu); +#endif + + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = sighandler; + sa.sa_flags = SA_SIGINFO; + if (sigaction(SIGSEGV, &sa, NULL) == -1) + err(1, "sigaction SIGSEGV"); + if (sigaction(SIGBUS, &sa, NULL) == -1) + err(1, "sigaction SIGBUS"); + + mut_region_len = getpagesize() * 100; + mut_region_keys = calloc(mut_region_len, sizeof(unsigned)); + if (mut_region_keys == NULL) + err(1, "calloc keys"); + mut_region = mmap(NULL, mut_region_len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0); + if (mut_region == MAP_FAILED) + err(1, "mmap"); + for (i = 1, p = mut_region; p < mut_region + mut_region_len; + p += getpagesize()) { + error = x86_pkru_protect_range(p, getpagesize(), i, 0); + if (error != 0) + err(1, "x86_pkru_protect_range key %d", i); + mut_region_keys[(p - mut_region) / getpagesize()] = i; + if (++i > 0xf) + i = 1; + } + + signal(SIGALRM, handler); + alarm(5); + error = pthread_create(&bga_thr, NULL, bg_access_thread_fn, NULL); + if (error != 0) + errc(1, error, "pthread create background access thread"); + + mutate_perms(); +} +EOF +cc -Wall -Wextra -g -O -o pkru64 pkru.c -lpthread || exit 1 +cc -Wall -Wextra -g -O -o pkru32 -m32 pkru.c -lpthread || exit 1 +rm pkru.c +./pkru64 +./pkru32 +rm -f pkru64 pkru32 + +exit diff --git a/tools/test/stress2/misc/pkru2.sh b/tools/test/stress2/misc/pkru2.sh new file mode 100755 index 000000000000..cf9fac187793 --- /dev/null +++ b/tools/test/stress2/misc/pkru2.sh @@ -0,0 +1,108 @@ +#/bin/sh + +# Test scenario for Intel userspace protection keys feature on Skylake Xeons +# Based on tests by kib@ + +grep -qw PKU /var/run/dmesg.boot || exit 0 +cd /tmp + +cat > /tmp/pkru2a.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile char *mapping; + +#define OPKEY 1 + +int +main(void) +{ + time_t start; + int error; + + start = time(NULL); + while (time(NULL) - start < 60) { + mapping = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (mapping == MAP_FAILED) + err(1, "mmap"); + error = x86_pkru_protect_range((void *)mapping, + getpagesize(), OPKEY, 0); + error = x86_pkru_protect_range((void *)mapping, + getpagesize() * 64, OPKEY, 0); + if (error != 0) + err(1, "x86_pkru_protect_range"); + error = x86_pkru_set_perm(OPKEY, 0, 0); + if (error != 0) + err(1, "x86_pkru_set_perm"); + if (munmap((void *)mapping, getpagesize()) == -1) + err(1, "munmap()"); + } + return (0); +} +EOF +cc -Wall -Wextra -g -O -o pkru2a64 pkru2a.c || exit 1 +cc -Wall -Wextra -g -O -o pkru2a32 -m32 pkru2a.c || exit 1 +rm pkru2a.c +./pkru2a64 +./pkru2a32 +rm -f pkru2a64 pkru2a32 + +cat > /tmp/pkru2b.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile char *mapping; + +#define OPKEY 1 + +int +main(void) +{ + time_t start; + int error; + + start = time(NULL); + while (time(NULL) - start < 60) { + mapping = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (mapping == MAP_FAILED) + err(1, "mmap"); + error = x86_pkru_protect_range((void *)mapping, + getpagesize() * 64, OPKEY, 0); + if (error != 0) + err(1, "x86_pkru_protect_range"); + error = x86_pkru_set_perm(OPKEY, 0, 0); + if (error != 0) + err(1, "x86_pkru_set_perm"); + if (munmap((void *)mapping, getpagesize()) == -1) + err(1, "munmap()"); + } + return (0); +} +EOF + +cc -Wall -Wextra -g -O -o pkru2b64 pkru2b.c || exit 1 +cc -Wall -Wextra -g -O -o pkru2b32 -m32 pkru2b.c || exit 1 +rm pkru2b.c +./pkru2b64 +./pkru2b32 +rm -f pkru2b64 pkru2b32 + +exit diff --git a/tools/test/stress2/misc/pmc.sh b/tools/test/stress2/misc/pmc.sh new file mode 100755 index 000000000000..b36cfa89c779 --- /dev/null +++ b/tools/test/stress2/misc/pmc.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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. +# + +# Simple pmc test + +# "panic: [pmc,4950] pm=0x2ddfe880 runcount 0" seen. +# https://people.freebsd.org/~pho/stress/log/pmc.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q hwpmc || { kldload hwpmc; loaded=1; } + +event=`pmcstat -L 2>/dev/null | tr -d '\t' | sort -R | head -1` +if [ -n "$event" ]; then + for i in `jot 2`; do + pmcstat -P $event -O /tmp/sample.out.$i find -x /var \ + -name not.there & + done + sleep 1 + + export runRUNTIME=5m + pgrep -q pmcstat && + (cd ..; ./run.sh vfs.cfg) + wait +fi +[ $loaded ] && kldunload hwpmc +rm -f /tmp/sample.out.* +exit 0 diff --git a/tools/test/stress2/misc/pmc2.sh b/tools/test/stress2/misc/pmc2.sh new file mode 100755 index 000000000000..1e773e1448f8 --- /dev/null +++ b/tools/test/stress2/misc/pmc2.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Page fault seen: +# https://people.freebsd.org/~pho/stress/log/pmc2.txt + +# https://people.freebsd.org/~pho/stress/log/mmacy004.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q hwpmc || { kldload hwpmc; loaded=1; } + +event=`pmcstat -L 2>/dev/null | tr -d '\t' | sort -R | head -1` +if [ -n "$event" ]; then + ../misc/churn.sh & + pid=$! + while ! pgrep -q churn; do sleep .5; done + pmcstat -P $event -t churn -O /tmp/pmc2.log + wait $pid + rm /tmp/pmc2.log +fi +[ $loaded ] && kldunload hwpmc + +exit 0 diff --git a/tools/test/stress2/misc/pmc3.sh b/tools/test/stress2/misc/pmc3.sh new file mode 100755 index 000000000000..cdfee000d352 --- /dev/null +++ b/tools/test/stress2/misc/pmc3.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# syscall fuzz of hwpmc.ko + +# Page fault seen: +# https://people.freebsd.org/~pho/stress/log/hwpmc3-1.txt + +kldstat | grep -q hwpmc || { kldload hwpmc.ko; loaded=1; } + +num=`kldstat -d -m hwpmc | awk -F ',' '/hwpmc/ {print $2}'` +[ $num ] || exit 1 + +for i in `jot 2`; do + noswap=1 sleeptime=18 ../misc/syscall4.sh $num +done + +[ $loaded ] && kldunload hwpmc +exit 0 diff --git a/tools/test/stress2/misc/pmc4.sh b/tools/test/stress2/misc/pmc4.sh new file mode 100755 index 000000000000..949e97073750 --- /dev/null +++ b/tools/test/stress2/misc/pmc4.sh @@ -0,0 +1,124 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# pmc fuzz test + +. ../default.cfg + +kldstat -v | grep -q hwpmc || { kldload hwpmc; loaded=1; } +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/pmc4.c +mycc -o pmc4 -Wall -Wextra -O0 -g pmc4.c -lpmc -lpthread || exit 0 +rm -f pmc4.c + +for i in `jot 100`; do + ./pmc4 +done > /dev/null 2>&1 + +rm -rf pmc4 pmc4.core +[ $loaded ] && kldunload hwpmc +exit 0 + +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +static int fd1[2]; +static int kq; +#define THREADS 20 + +static void * +test(void *arg __unused) +{ + + void *rfd; + char *cmdline[] = { "/usr/bin/true", NULL }; + + if ((rfd = pmclog_open(kq)) == NULL) + err(1, "pmclog_open(%d)", kq); + if (pmc_configure_logfile(kq) < 0) + err(1, "ERROR: Cannot configure log file"); + sleep(1); + usleep(arc4random() % 20000); + if (execve(cmdline[0], cmdline, NULL) == -1) + err(1, "execve"); + + return (0); +} + +int +main(void) +{ + struct kevent ev[3]; + pthread_t tid[THREADS]; + int i, n, rc; + + if (pmc_init() == -1) + err(1, "pmc_init"); + + if (pipe(fd1) == -1) + err(1, "pipe()"); + + 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++; + + if (kevent(kq, ev, n, NULL, 0, NULL) < 0) + err(1, "kevent(). %s:%d", __FILE__, __LINE__); + 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) + warn("kevent(). %s:%d", __FILE__, __LINE__); + + for (i = 0; i < THREADS; i++) { + if ((rc = pthread_create(&tid[i], NULL, test, NULL)) != 0) + errc(1, rc, "test()"); + } + for (i = 0; i < THREADS; i++) { + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + } + + return (0); +} diff --git a/tools/test/stress2/misc/pmc5.sh b/tools/test/stress2/misc/pmc5.sh new file mode 100755 index 000000000000..c7305aa4d470 --- /dev/null +++ b/tools/test/stress2/misc/pmc5.sh @@ -0,0 +1,138 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# pmc fuzz test + +. ../default.cfg + +kldstat -v | grep -q hwpmc || { kldload hwpmc; loaded=1; } +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/pmc5.c +mycc -o pmc5 -Wall -Wextra -O0 -g pmc5.c -lpmc -lpthread || exit 1 +rm -f pmc5.c + +for i in `jot 100`; do + ./pmc5 +done > /dev/null 2>&1 + +rm -rf pmc5 pmc5.core +[ $loaded ] && kldunload hwpmc +exit 0 + +EOF +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; +static int fd1[2]; +static int kq; +#define THREADS 20 +#define SYNC 0 + +void * +test(void *arg __unused) +{ + + void *rfd; + char *cmdline[] = { "/usr/bin/true", NULL }; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != THREADS) + ; + if ((rfd = pmclog_open(kq)) == NULL) + err(1, "pmclog_open(%d)", kq); +// if (pmc_configure_logfile(fd1[1]) < 0) + if (pmc_configure_logfile(kq) < 0) + err(1, "ERROR: Cannot configure log file"); + sleep(1); + usleep(arc4random() % 20000); + if (execve(cmdline[0], cmdline, NULL) == -1) + err(1, "execve"); + + return (0); +} + +int +main(void) +{ + struct kevent ev[3]; + pthread_t tid[THREADS]; + size_t len; + int i, n, rc; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + if (pmc_init() == -1) + err(1, "pmc_init"); + + if (pipe(fd1) == -1) + err(1, "pipe()"); + + 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++; + + if (kevent(kq, ev, n, NULL, 0, NULL) < 0) + err(1, "kevent(). %s:%d", __FILE__, __LINE__); + 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) + warn("kevent(). %s:%d", __FILE__, __LINE__); + + for (i = 0; i < THREADS; i++) { + if ((rc = pthread_create(&tid[i], NULL, test, NULL)) != 0) + errc(1, rc, "test()"); + } + for (i = 0; i < THREADS; i++) { + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + } + + return (0); +} diff --git a/tools/test/stress2/misc/pmc6.sh b/tools/test/stress2/misc/pmc6.sh new file mode 100755 index 000000000000..4cbdf278125f --- /dev/null +++ b/tools/test/stress2/misc/pmc6.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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 scenario from: +# [Bug 230985] pmcstat triggers assertion "pmcval outside of expected range" +# by markj@FreeBSD.org + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +kldstat -v | grep -q hwpmc || { kldload hwpmc; loaded=1; } + +event=inst_retired.any +pmcstat -L 2>/dev/null | grep -q $event || exit 0 +pmcstat -P $event -- find -x / -name foo > /dev/null 2>&1 + +[ $loaded ] && kldunload hwpmc diff --git a/tools/test/stress2/misc/pmc7.sh b/tools/test/stress2/misc/pmc7.sh new file mode 100755 index 000000000000..6a4726b24203 --- /dev/null +++ b/tools/test/stress2/misc/pmc7.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# From https://reviews.freebsd.org/D17011 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +cd /tmp +kldstat -v | grep -q hwpmc || { kldload hwpmc; loaded=1; } +pmcstat -S unhalted_core_cycles -O ppid.pmcstat sleep 10 +pmcstat -R ppid.pmcstat -z100 -G ppid.stacks +[ $loaded ] && kldunload hwpmc +rm -f ppid.pmcstat ppid.stacks diff --git a/tools/test/stress2/misc/poll.sh b/tools/test/stress2/misc/poll.sh new file mode 100755 index 000000000000..c345ffae9817 --- /dev/null +++ b/tools/test/stress2/misc/poll.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# A pipe_poll() regression test. +# Python test scenario by Alexander Motin +# https://reviews.freebsd.org/D21333 + +# Hang seen: +# $ procstat -k 19529 +# PID TID COMM KSTACK +# 19529 101381 python3.7 - ... _sleep kqueue_kevent kern_kevent_fp kern_kevent kern_kevent_generic sys_kevent amd64_syscall fast_syscall_common +# 19529 101630 python3.7 - ... _sleep pipe_read dofileread kern_readv sys_read amd64_syscall fast_syscall_common +# 19529 101631 python3.7 - ... _sleep umtxq_sleep do_sem2_wait __umtx_op_sem2_wait amd64_syscall fast_syscall_common +# $ + +# Fixed by r351348 + +[ -z "`type python3 2>/dev/null`" ] && exit 0 +cat > /tmp/poll.py < $log & +pid=$! +sleep 60 +s1=`wc -l < $log` +sleep 60 +s2=`wc -l < $log` +while pgrep -qf poll.py; do pkill -f poll.py; done +wait $pid +[ $s2 -gt $s1 ] && s=0 || s=1 + +rm -f /tmp/poll.py $log +exit $s + +dtrace -wn '*::pipe_poll:entry {@rw[execname,probefunc] = count(); }' diff --git a/tools/test/stress2/misc/poll2.sh b/tools/test/stress2/misc/poll2.sh new file mode 100755 index 000000000000..13db2d0d22d3 --- /dev/null +++ b/tools/test/stress2/misc/poll2.sh @@ -0,0 +1,212 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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 of pipe_poll() +# https://reviews.freebsd.org/D21333 + +# No problems seen. + +# markj@ write: +# A simplified reproducible might be tricky to come up with. I think this +# would do it: +# +# - Thread W writes 8KB (PIPE_MINDIRECT) of data to a pipe at a time. +# - Thread P poll()s the pipe for POLLIN. +# - Thread R reads 8KB of data from the pipe at a time. +# +# Thread P uses non-blocking poll() (timeout == 0). When thread P does +# not see POLLIN, it signals the reader and the writer and continues +# polling in a loop. When thread P sees POLLIN it signals the reader and +# sleeps until the reader returns and wakes it up. After threads R and W +# finish their respective system calls, they always wait for another +# signal from P before doing anything. +# +# Basically, if all three threads are executing their respective system +# calls, and the reader has drained the writer's data and awoken the +# writer, there is a window where poll() will return POLLIN even though +# all data has been read. If the reader then attempts to read() from the +# pipe again, it will block and the application appears to be hung. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +rm -f $dir/poll2.c || exit 1 +sed '1,/^EOF/d' < $odir/$0 > $dir/poll2.c +mycc -o poll2 -Wall -Wextra -O0 -g poll2.c -lpthread || exit 1 + +cpuset -l 0 $dir/poll2 +s=$? +pkill swap +wait + +rm -rf poll2 poll2.c poll2.core +exit $s + +EOF +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile int done, frd, fwr, fpl; +static int fds[2]; +static char b1[8192], b2[8192]; + +#define RUNTIME (2 * 60) +#define LOOP 400000 + +static void * +wr(void *data __unused) +{ + int i; + + for (i = 0; i < LOOP; i++) { + pthread_set_name_np(pthread_self(), "wr-idle"); + while (fwr == 0) + usleep(5); + pthread_set_name_np(pthread_self(), "wr-act"); + fpl = 1; + if (write(fds[1], b1, sizeof(b1)) != sizeof(b1)) + err(1, "write"); + fpl = 1; + fwr = 0; + } + + return (NULL); +} + +static void * +rd(void *data __unused) +{ + int i; + + for (i = 0; i < LOOP; i++) { + fpl = 1; + pthread_set_name_np(pthread_self(), "rd-idle"); + while (frd == 0) + usleep(5); + pthread_set_name_np(pthread_self(), "rd-act"); + if (read(fds[0], b2, sizeof(b2)) != sizeof(b2)) + err(1, "read"); + frd = 0; + fpl = 1; + } + done = 1; + + return (NULL); +} + +static void * +pl(void *data __unused) +{ + struct pollfd pfd; + int i, r; + + pfd.fd = fds[0]; + pfd.events = POLLIN; + for (i = 0; done == 0; i++) { + pfd.fd = fds[0]; + pfd.events = POLLIN; + pthread_set_name_np(pthread_self(), "pl-idle"); + pthread_set_name_np(pthread_self(), "pl-act"); + while (fpl == 0) + usleep(5); +again: + if ((r = poll(&pfd, 1, 0)) == -1) + err(1, "poll"); + if (done == 1) + return (NULL); + if (r == 0) { + frd = fwr = 1; + goto again; + } else { + fpl = 0; + frd = fwr = 1; + } + } + + return (NULL); +} + +void +test(void) +{ + pthread_t tid[3]; + int rc; + + if (pipe(fds) == -1) + err(1, "pipe"); + done = 0; + fpl = 0; + frd = 0; + fwr = 0; + if ((rc = pthread_create(&tid[0], NULL, rd, NULL)) != 0) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[1], NULL, wr, NULL)) != 0) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[2], NULL, pl, NULL)) != 0) + errc(1, rc, "pthread_create"); + + frd = 1; + fwr = 1; + + if ((rc = pthread_join(tid[0], NULL)) != 0) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[1], NULL)) != 0) + errc(1, rc, "pthread_join"); + if ((rc = pthread_join(tid[2], NULL)) != 0) + errc(1, rc, "pthread_join"); + + close(fds[0]); + close(fds[1]); +} + +int +main(void) +{ + time_t start; + + alarm(600); + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + test(); + } + + return (0); +} diff --git a/tools/test/stress2/misc/posix_fadvise.sh b/tools/test/stress2/misc/posix_fadvise.sh new file mode 100755 index 000000000000..df0995570783 --- /dev/null +++ b/tools/test/stress2/misc/posix_fadvise.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Memory leak. Fixed in r232702. + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > posix_fadvise.c +mycc -o posix_fadvise -Wall -Wextra -O2 -g posix_fadvise.c + +n1=`vmstat -m | grep fadvise | awk '{print $2 + 0}'` +/tmp/posix_fadvise +n2=`vmstat -m | grep fadvise | awk '{print $2 + 0}'` +if [ $((n2 - n1)) -gt 10 ]; then + echo FAIL + vmstat -m | sed -n '1p;/fadvise/p' +fi + +rm -f /tmp/posix_fadvise posix_fadvise.c +exit +EOF +#include +#include +#include +#include +#include + +int +main(void) +{ + off_t len, offset; + int advise, fd, i; + + for (i = 0; i < 500; i++) { + if ((fd = open("posix_fadvise.c", O_RDONLY)) == -1) + err(1, "open()"); + offset = arc4random(); + len = arc4random(); + advise = arc4random() % 6; + if (posix_fadvise(fd, offset, len, advise) == -1) + warn("posix_fadvise"); + close(fd); + } + return (0); +} diff --git a/tools/test/stress2/misc/posix_fadvise2.sh b/tools/test/stress2/misc/posix_fadvise2.sh new file mode 100755 index 000000000000..de9562e6c57b --- /dev/null +++ b/tools/test/stress2/misc/posix_fadvise2.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Looping thread seen: +# https://people.freebsd.org/~pho/stress/log/kostik850.txt +# Fixed by r292326. + +. ../default.cfg +[ -f /usr/libexec/sendmail/sendmail ] || exit 0 + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > posix_fadvise2.c +mycc -o posix_fadvise2 -Wall -Wextra -O2 posix_fadvise2.c || exit 1 +rm -f posix_fadvise2.c + +/tmp/posix_fadvise2 + +rm -f /tmp/posix_fadvise2 /tmp/posix_fadvise2 +exit +EOF +#include + +#include +#include +#include +#include +#include + +char *file[2] = { + "/usr/libexec/sendmail/sendmail", + "/tmp/posix_fadvise2"}; + +int +main(void) +{ + int fd, i, r; + + for (i = 0; i < 2; i++) { + fprintf(stderr, "Testing with %s.\n", file[i]); + if ((fd = open(file[i], O_RDONLY)) == -1) + err(1, "open(%s)", file[i]); + +/* Arguments from syscall4.sh test as seen in kostik850.txt */ + if ((r = posix_fadvise(fd, 0x1e9cda7a9ada8319, + 0x1e9d1deee0401abd, POSIX_FADV_DONTNEED)) != 0) + errc(1, r, "posix_fadvise(%s)", file[i]); + + close(fd); + } + + return(0); +} diff --git a/tools/test/stress2/misc/posix_fadvise3.sh b/tools/test/stress2/misc/posix_fadvise3.sh new file mode 100755 index 000000000000..c9dc5895d8ea --- /dev/null +++ b/tools/test/stress2/misc/posix_fadvise3.sh @@ -0,0 +1,120 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Looping thread seen: +# https://people.freebsd.org/~pho/stress/log/kostik855.txt +# Fixed by r293197. + +# Again on i386: +# https://people.freebsd.org/~pho/stress/log/kostik867.txt +# Fixed by r295716. + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > posix_fadvise3.c +mycc -o posix_fadvise3 -Wall -Wextra -O2 -g posix_fadvise3.c + +data=/tmp/posix_fadvise3.data +dd if=/dev/zero of=$data bs=1m count=64 status=none +/tmp/posix_fadvise3 + +rm $data +truncate -s 64m $data +/tmp/posix_fadvise3 + +rm -f /tmp/posix_fadvise3 posix_fadvise3.c $data +exit +EOF +#include +#include +#include +#include +#include + +#define LOOPS 10000 +#define N (128 * 1024 / (int)sizeof(u_int32_t)) + +u_int32_t r[N]; + +unsigned long +makearg(void) +{ + unsigned int i; + unsigned long val; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +int +main(void) +{ + off_t len, offset; + int advise, fd, i, j; + + if ((fd = open("/tmp/posix_fadvise3.data", O_RDONLY)) == -1) + err(1, "open()"); + offset = 0; + len = 0x7fffffffffffffff; + advise = 4; + if (posix_fadvise(fd, offset, len, advise) == -1) + warn("posix_fadvise"); + close(fd); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < N; j++) + r[j] = arc4random(); + if ((fd = open("/tmp/posix_fadvise3.data", O_RDONLY)) == -1) + err(1, "open()"); + offset = makearg(); + len = makearg(); + advise = arc4random() % 6; + if (posix_fadvise(fd, offset, len, advise) == -1) + warn("posix_fadvise"); + close(fd); + } + + return (0); +} diff --git a/tools/test/stress2/misc/posix_openpt.sh b/tools/test/stress2/misc/posix_openpt.sh new file mode 100755 index 000000000000..8457b8c4fe55 --- /dev/null +++ b/tools/test/stress2/misc/posix_openpt.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# "panic: Assertion ttyinq_getsize(&tp->t_inq) == 0 failed" seen. +# https://people.freebsd.org/~pho/stress/log/posix_openpt.txt +# Test scenario by brde@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > posix_openpt.c +mycc -o posix_openpt -Wall -Wextra -O2 posix_openpt.c || exit 1 +rm -f posix_openpt.c + +for i in `jot 10`; do + /tmp/posix_openpt & +done + +me=`tty` +stty -f /dev/ptmx 300 2>/dev/null +for i in /dev/pts/*; do + [ $i = $me ] && continue + stty -f $i 300 2>/dev/null +done +wait +rm -f /tmp/posix_openpt + +exit +EOF +#include +#include +#include +#include + +int +main(void) +{ + int masterfd, slavefd; + char *slave; + + if ((masterfd = posix_openpt(O_RDWR | O_NOCTTY)) == -1) + err(1, "posix_openpt"); + if ((slave = ptsname (masterfd)) == NULL) + err(1, "ptsname"); + if ((slavefd = open(slave, O_RDWR|O_NOCTTY)) == -1) + err(1, "open(%s)", slave); + + sleep(arc4random() % 60 + 1); + + return (0); +} diff --git a/tools/test/stress2/misc/posix_openpt2.sh b/tools/test/stress2/misc/posix_openpt2.sh new file mode 100755 index 000000000000..2d3427c26ea1 --- /dev/null +++ b/tools/test/stress2/misc/posix_openpt2.sh @@ -0,0 +1,152 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# "panic: Assertion !tty_gone(tp) failed at ttydevsw.h:153" seen. +# https://people.freebsd.org/~pho/stress/log/posix_openpt2.txt +# Fixed by r312077 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > posix_openpt2.c +mycc -o posix_openpt2 -Wall -Wextra -O2 posix_openpt2.c -lutil || exit 1 +rm -f posix_openpt2.c + +/tmp/posix_openpt2 & + +while kill -0 $! 2>/dev/null; do + $here/../testcases/swap/swap -t 2m -i 20 +done +wait + +rm -f /tmp/posix_openpt2 +exit 0 +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 10 +#define PARALLEL 2 +#define RUNTIME 300 + +void +churn(char *path) +{ + FTS *fts; + FTSENT *p; + time_t start; + int fd, ftsoptions; + char *args[2]; + + ftsoptions = FTS_PHYSICAL; + args[0] = path; + args[1] = 0; + + setproctitle("churn"); + start = time(NULL); + while (time(NULL) - start < RUNTIME / LOOPS) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + if (p->fts_info == FTS_D || + p->fts_info == FTS_DP) + continue; + if ((fd = open(p->fts_path, O_RDONLY)) > 0) + close(fd); + + } + + if (errno != 0 && errno != ENOENT) + err(1, "fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } + + _exit(0); +} + +void +pty(void) +{ + time_t start; + int masterfd, slavefd; + char *slave; + + start = time(NULL); + while (time(NULL) - start < RUNTIME / LOOPS) { + if ((masterfd = posix_openpt(O_RDWR | O_NOCTTY)) == -1) + err(1, "posix_openpt"); + if ((slave = ptsname (masterfd)) == NULL) + err(1, "ptsname"); + if ((slavefd = open(slave, O_RDWR|O_NOCTTY)) == -1) + err(1, "open(%s)", slave); + usleep(arc4random() % 10000); + close(slavefd); + close(masterfd); + } + _exit(0); +} + +int +main(void) +{ + int i, j; + + for (j = 0; j < LOOPS; j++) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + pty(); + } + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + churn("/dev/pts"); + } + for (i = 0; i < 2 * PARALLEL; i++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/pread.sh b/tools/test/stress2/misc/pread.sh new file mode 100755 index 000000000000..fecdc18675c9 --- /dev/null +++ b/tools/test/stress2/misc/pread.sh @@ -0,0 +1,190 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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. +# + +# pread(2) fuzzing inspired by the iknowthis test suite +# by Tavis Ormandy + +# Fixed in r227527. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pread.c +mycc -o pread -Wall -Wextra pread.c +rm -f pread.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mount -t tmpfs tmpfs $mntpoint +cp -a /usr/include $mntpoint +echo "Testing tmpfs(5)" +/tmp/pread $mntpoint +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done + +echo "Testing fdescfs(5)" +mount -t fdescfs null /dev/fd +for i in `jot 100`; do + /tmp/pread /dev/fd +done + +while mount | grep -q "on /dev/fd "; do + umount /dev/fd || sleep 1 +done + +echo "Testing procfs(5)" +mount -t procfs procfs $mntpoint +/tmp/pread $mntpoint +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +cp -a /usr/include $mntpoint +echo "Testing FFS" +/tmp/pread $mntpoint +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart + +mount -t nullfs /bin $mntpoint +echo "Testing nullfs(5)" +/tmp/pread $mntpoint +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done + +echo "Testing procfs(5)" +mount -t procfs procfs $mntpoint +/tmp/pread $mntpoint +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done + +echo "Testing devfs(8)" +mount -t devfs devfs $mntpoint +/tmp/pread $mntpoint +while mount | grep -q "on $mntpoint "; do + umount $mntpoint || sleep 1 +done + +rm -f /tmp/pread +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void +hand(int i __unused) { /* handler */ + _exit(1); +} + +int +test(char *path) +{ + + FTS *fts; + FTSENT *p; + int ftsoptions; + char *args[2]; + int buf[64], fd; + + signal(SIGSEGV, hand); + signal(SIGABRT, hand); + ftsoptions = FTS_PHYSICAL; + args[0] = path; + args[1] = 0; + + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + if ((fd = open(p->fts_path, O_RDONLY)) == -1) { + if (errno != EACCES && errno != ENXIO) + warn("open(%s)", p->fts_path); + continue; + } + alarm(1); + pread(fd, (void *)0xdeadc0de, 0x7ffffff, 0xffffffff); + pread(fd, buf, 0x7ffffff, 0xffffffff); + pread(fd, buf, sizeof(buf), 0xffffffff); + pread(fd, buf, sizeof(buf), 0); + close(fd); + } + fts_close(fts); + + exit(0); +} + +int +main(int argc __unused, char **argv) +{ + int i; + struct passwd *pw; + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + if (daemon(0, 0) == -1) + err(1, "daemon()"); + + for (i = 0; i < 10; i++) { + if (fork() == 0) + test(argv[1]); + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/proccontrol.sh b/tools/test/stress2/misc/proccontrol.sh new file mode 100755 index 000000000000..52f7cc824372 --- /dev/null +++ b/tools/test/stress2/misc/proccontrol.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# A brif test of proccontrol(1). No problems seen. + +[ -x /usr/bin/proccontrol ] || exit 0 + +sleep 60 & pid=$! +proccontrol -m aslr -s disable sleep 1 +proccontrol -m aslr -s enable sleep 1 +proccontrol -m aslr sleep 1 +proccontrol -m aslr -s disable -p $pid +proccontrol -m aslr -s enable -p $pid +proccontrol -m aslr -q -p $pid + +proccontrol -m trace -s disable sleep 1 +proccontrol -m trace -s enable sleep 1 +proccontrol -m trace sleep 1 +proccontrol -m trace -q -p $pid + +proccontrol -m trapcap -s disable sleep 1 +proccontrol -m trapcap -s enable sleep 1 +proccontrol -m trapcap sleep 1 +proccontrol -m trapcap -s disable -p $pid +proccontrol -m trapcap -s enable -p $pid +proccontrol -m trapcap -q -p $pid +kill $pid +wait diff --git a/tools/test/stress2/misc/procfs.sh b/tools/test/stress2/misc/procfs.sh new file mode 100755 index 000000000000..6b445b0d7e48 --- /dev/null +++ b/tools/test/stress2/misc/procfs.sh @@ -0,0 +1,69 @@ +#!/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. +# + +[ `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 > /dev/null 2>&1 & + done + wait +else + if [ $1 = find ]; then + while [ -r /tmp/$0 ]; do + ls -lR ${mntpoint}* + done + else + + # The test: Parallel mount and unmounts + for i in `jot 128`; 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 + fi +fi diff --git a/tools/test/stress2/misc/procfs2.sh b/tools/test/stress2/misc/procfs2.sh new file mode 100755 index 000000000000..dd0f1074f9b2 --- /dev/null +++ b/tools/test/stress2/misc/procfs2.sh @@ -0,0 +1,37 @@ +#!/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. +# + +# panic: not suspended thread 0xc674c870 +# Found by scrashme and fixed in r216120 + +mount | grep -q "/proc " || { mount -t procfs procfs /proc || exit 1; } +for i in `find /proc ! -type d`; do + dd if=$i of=/dev/null > /dev/null 2>&1 + dd if=/dev/random of=$i > /dev/null 2>&1 +done +exit 0 diff --git a/tools/test/stress2/misc/procfs3.sh b/tools/test/stress2/misc/procfs3.sh new file mode 100755 index 000000000000..c9c4820adbff --- /dev/null +++ b/tools/test/stress2/misc/procfs3.sh @@ -0,0 +1,154 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# procfs(5) test scenario. +# "panic: wchan 0xc10a4f68 has no wmesg" seen + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep -q "/proc " || { mount -t procfs procfs /proc || exit 1; } +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > procfs3.c +mycc -o procfs3 -Wall -Wextra -O2 procfs3.c || exit 1 +rm -f procfs3.c +cd $here + +su $testuser -c /tmp/procfs3 + +rm -f /tmp/procfs3 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 10 + +void +handler(int i __unused) +{ +} + +int +test(void) +{ + + FTS *fts; + FTSENT *p; + int ftsoptions; + char *args[2]; + int fd, i; + char buf[1629]; + + ftsoptions = FTS_PHYSICAL; + args[0] = "/proc"; + args[1] = 0; + + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + switch (p->fts_info) { + case FTS_F: /* Ignore. */ + break; + case FTS_D: /* Ignore. */ + continue; + case FTS_DP: + continue; + case FTS_DC: /* Ignore. */ + continue; + case FTS_SL: /* Ignore. */ + continue; + case FTS_DNR: + continue; + case FTS_NS: + continue; + case FTS_ERR: + case FTS_DEFAULT: + warnx("%s: %s. fts_info = %d", p->fts_path, strerror(p->fts_errno), + p->fts_info); + continue; + default: + printf("%s: default, %d\n", getprogname(), p->fts_info); + break; + } + + if ((fd = open(p->fts_path, O_RDONLY)) == -1) + continue; + signal(SIGALRM, handler); + alarm(1); + + for (i = 0; i < 2; i++) { + read(fd, buf, 1629); + } + close(fd); + } + + if (errno != 0 && errno != ENOENT) + err(1, "fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + + return (0); +} + +int +main(void) +{ + int i, j; + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) { + for (j = 0; j < 50; j++) { + test(); + } + _exit(0); + } + } + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/procfs4.sh b/tools/test/stress2/misc/procfs4.sh new file mode 100755 index 000000000000..ffa812a7f73d --- /dev/null +++ b/tools/test/stress2/misc/procfs4.sh @@ -0,0 +1,156 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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 scenario idea by kib@ + +# "panic: double fault" seen due to recursion + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep -q procfs || mount -t procfs procfs /proc +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > procfs4.c +mycc -o procfs4 -Wall -Wextra -O2 procfs4.c || exit 1 +rm -f procfs4.c +cd $here + +su $testuser -c /tmp/procfs4 +e=$? + +rm -f /tmp/procfs4 +exit $e +EOF +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 1000 +#define MAXRUN 1200 +#define PARALLEL 10 + +char *files[] = { + "cmdline", + "ctl", + "dbregs", + "etype", + "file", + "fpregs", + "map", + "mem", + "note", + "notepg", + "osrel", + "regs", + "rlimit", + "status" +}; + +void +test(void) +{ + pid_t p; + int fd, i, j, n, opens; + char path[128]; + + for (i = 0; i < 64; i++) { + if ((p = fork()) == 0) { + setproctitle("Sleeper"); + usleep(20000); + usleep(arc4random() % 200); + for (j = 0; j < 10000; j++) + getpid(); + _exit(0); + } + opens = 0; + setproctitle("load"); + for (j = 0; j < 14; j++) { + snprintf(path, sizeof(path), "/proc/%d/%s", p, files[j]); + if ((fd = open(path, O_RDWR)) == -1) + if ((fd = open(path, O_RDONLY)) == -1) + continue; + + ioctl(fd, FIONREAD, &n); + if (ioctl(fd, FIONBIO, &n) != -1) + opens++; + + close(fd); + } + kill(p, SIGHUP); +#if 0 + if (opens < 1) + fprintf(stderr, "Warn %d open(s) for pid %d\n", opens, getpid()); +#endif + } + + for (i = 0; i < 64; i++) + wait(NULL); + + _exit(0); +} + +int +main(void) +{ + time_t start; + int e, i, j; + + e = 0; + start = time(NULL); + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + usleep(10000); + if (time(NULL) - start > MAXRUN) { + fprintf(stderr, "FAIL Timeout\n"); + e = 1; + break; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/procfs5.sh b/tools/test/stress2/misc/procfs5.sh new file mode 100755 index 000000000000..70cd3214db02 --- /dev/null +++ b/tools/test/stress2/misc/procfs5.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Issue involving signed overflow. +# Test scenario based on panic seen in +# http://people.freebsd.org/~pho/stress/log/kostik640.txt +# Fixed in r258365, r258397. + +# Scenario by kib@ + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep -q "/proc " || mount -t procfs procfs /proc + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > procfs_lr.c +mycc -o procfs_lr -Wall -Wextra -O2 procfs_lr.c || exit 1 +rm -f procfs_lr.c + +/tmp/procfs_lr 2>/dev/null + +rm -f /tmp/procfs_lr + +exit 0 +EOF +/* $Id: procfs_lr.c,v 1.1 2013/11/16 07:06:46 kostik Exp kostik $ */ + +#include +#include +#include +#include +#include +#include +#include + +int +main(void) +{ + static const char name[] = "/proc/curproc/map"; + const off_t uio_offset = 0x6f51f3a1185bced9; +#if defined(__LP64__) + const size_t uio_resid = 0x4c330b10965a61af; +#else + const size_t uio_resid = 0x965a61af; +#endif + char buf[1]; + int error, fd; + + fd = open(name, O_RDONLY); + if (fd == -1) + err(1, "open"); + error = pread(fd, buf, uio_resid, uio_offset); + if (error == -1) + fprintf(stderr, "pread: %s\n", strerror(errno)); + return (0); +} diff --git a/tools/test/stress2/misc/procfs6.sh b/tools/test/stress2/misc/procfs6.sh new file mode 100755 index 000000000000..b4cc4c1eb4c0 --- /dev/null +++ b/tools/test/stress2/misc/procfs6.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Peter Holm +# +# 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. +# + +# Regression test for problem introduced by r351741 and fixed by 351815. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +if ! mount | grep -q /proc; then + mount -t procfs null /proc || exit 1 + mounted=1 +fi +[ `ls /proc | wc -l` -eq 0 ] && { ls -l /proc; exit 1; } +[ `ls /proc/$$ | wc -l` -eq 0 ] && { ls -l /proc; exit 1; } + +[ $mounted ] && umount /proc +exit 0 diff --git a/tools/test/stress2/misc/procstat.sh b/tools/test/stress2/misc/procstat.sh new file mode 100755 index 000000000000..91a846ba91ee --- /dev/null +++ b/tools/test/stress2/misc/procstat.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# procstat -k test scenario +# Page fault seen in stack_save_td() +# https://people.freebsd.org/~pho/stress/log/procstat.txt + +[ `uname -m` = "i386" ] || exit 0 # XXX Known issue on i386 XXX +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +./fifo4.sh & +sleep .1 +while pgrep -fq fifo4.sh; do + pgrep fifo2 | xargs procstat -k > /dev/null 2>&1 +done +echo done +wait +exit 0 diff --git a/tools/test/stress2/misc/procstat2.sh b/tools/test/stress2/misc/procstat2.sh new file mode 100755 index 000000000000..712f53c11b3b --- /dev/null +++ b/tools/test/stress2/misc/procstat2.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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. +# + +# This test scenario would trigger an NMI. +# https://people.freebsd.org/~pho/stress/log/mjguzik022.txt + +# Test scenario idea by Mark Johnston +# Fixed by r357334 + +../misc/marcus.sh > /dev/null 2>&1 & +start=`date +%s` +while [ $((`date +%s` - start)) -lt 300 ]; do + procstat -kka > /dev/null 2>&1 +done +../tools/killall.sh +wait + +exit 0 diff --git a/tools/test/stress2/misc/pthread.sh b/tools/test/stress2/misc/pthread.sh new file mode 100755 index 000000000000..9bb45a11465d --- /dev/null +++ b/tools/test/stress2/misc/pthread.sh @@ -0,0 +1,137 @@ +#!/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. +# + +# 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 +mycc -o pth -Wall pth.c -pthread +rm -f pth.c +cd $odir + +for i in `jot 2000`; do + /tmp/pth 2>/dev/null +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/tools/test/stress2/misc/pthread2.sh b/tools/test/stress2/misc/pthread2.sh new file mode 100755 index 000000000000..08236647fcad --- /dev/null +++ b/tools/test/stress2/misc/pthread2.sh @@ -0,0 +1,296 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Threaded producer-consumer test. + +. ../default.cfg + +export LANG=C +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pthread2.c +mycc -o pthread2 -Wall -Wextra -O2 -g pthread2.c -lpthread || exit 1 +rm -f pthread2.c /tmp/pthread2.core + +log=/tmp/pthread2.`date '+%Y%m%d-%H%M'` +for i in `jot 5`; do + [ $i -eq 1 ] && echo "# `uname -v`" + time sh -c ' + for i in `jot 8`; do + /tmp/pthread2 & + done + wait + ' +done > $log 2>&1 +rm -f /tmp/pthread2 + +if [ -n "$bench" ]; then + pair=`ls /tmp/pthread2* | egrep "pthread2\.[0-9]{8}-" | sort | + tail -2 | tr '\n' ' '` + ministat -w 72 $pair +else + rm -f $log +fi + +# __thr_umutex_lock() may call abort(3) under VM pressure. +[ -r /tmp/pthread2.core ] && echo FAIL +exit 0 +EOF +/* + * Threaded producer-consumer test. + * Loosly based on work by + * Andrey Zonov (c) 2012 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __FreeBSD__ +#include +#define __NP__ +#endif +#include +#include +#include +#include +#include +#include +#include + +#define LOCK(x) plock(&x.mtx) +#define UNLOCK(x) punlock(&x.mtx) +#define SIGNAL(x) psig(&x.wait) +#define WAIT(x) pwait(&x.wait, &x.mtx) + +long ncreate, nrename, nunlink; +int bench, max; +char *dirname1; +char *dirname2; + +struct file { + char *name; + STAILQ_ENTRY(file) next; +}; + +struct files { + pthread_mutex_t mtx; + pthread_cond_t wait; + STAILQ_HEAD(, file) list; +}; + +static struct files newfiles; +static struct files renamedfiles; + +#define MAXQ 100000 /* Max create queue length */ +#define MESSAGES 10000000; + +static void +hand(int i __unused) { /* handler */ + fprintf(stderr, "max = %d, ncreate = %ld, nrename = %ld, nunlink = %ld\n", + max, ncreate, nrename, nunlink); +} + +static void +ahand(int i __unused) { /* handler */ + fprintf(stderr, "FAIL\n"); + hand(0); + _exit(0); +} + +void +plock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_lock(l)) != 0) + errc(1, rc, "pthread_mutex_lock"); +} + +void +punlock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_unlock(l)) != 0) + errc(1, rc, "pthread_mutex_unlock"); +} + +void +psig(pthread_cond_t *c) +{ + int rc; + + if ((rc = pthread_cond_signal(c)) != 0) + errc(1, rc, "pthread_cond_signal"); +} + +void +pwait(pthread_cond_t *c, pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_cond_wait(c, l)) != 0) + errc(1, rc, "pthread_cond_wait"); +} + +void * +loop_create(void *arg __unused) +{ + int i; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + for (i = 0; i < max; i++) { + file = malloc(sizeof(*file)); + asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); + LOCK(newfiles); + STAILQ_INSERT_TAIL(&newfiles.list, file, next); + ncreate++; + UNLOCK(newfiles); + SIGNAL(newfiles); + if (ncreate - nrename > MAXQ) + usleep(400); + } + return (NULL); +} + +void * +loop_rename(void *arg __unused) +{ + char *filename, *newname; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nrename < max) { + LOCK(newfiles); + while (STAILQ_EMPTY(&newfiles.list)) { + WAIT(newfiles); + } + file = STAILQ_FIRST(&newfiles.list); + STAILQ_REMOVE_HEAD(&newfiles.list, next); + UNLOCK(newfiles); + filename = strrchr(file->name, '/'); + asprintf(&newname, "%s/%s", dirname2, filename); + nrename++; + free(file->name); + file->name = newname; + LOCK(renamedfiles); + STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); + UNLOCK(renamedfiles); + SIGNAL(renamedfiles); + } + return (NULL); +} + +void * +loop_unlink(void *arg __unused) +{ + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nunlink < max) { + LOCK(renamedfiles); + while (STAILQ_EMPTY(&renamedfiles.list)) { + WAIT(renamedfiles); + } + file = STAILQ_FIRST(&renamedfiles.list); + STAILQ_REMOVE_HEAD(&renamedfiles.list, next); + nunlink++; + UNLOCK(renamedfiles); + free(file->name); + free(file); + } + return (NULL); +} + +int +main(void) +{ + int i; + int rc; + pthread_t tid[3]; + + bench = getenv("bench") != NULL; + asprintf(&dirname1, "%s.1", "f1"); + asprintf(&dirname2, "%s.2", "f2"); + max = MESSAGES; + + STAILQ_INIT(&newfiles.list); + STAILQ_INIT(&renamedfiles.list); + + if ((rc = pthread_mutex_init(&newfiles.mtx, NULL)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&newfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + if ((rc = pthread_mutex_init(&renamedfiles.mtx, NULL)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&renamedfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + + signal(SIGINFO, hand); + signal(SIGALRM, ahand); + alarm(300); + if ((rc = pthread_create(&tid[0], NULL, loop_create, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[1], NULL, loop_rename, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[2], NULL, loop_unlink, NULL)) != 0) + errc(1, rc, "pthread_create()"); + + for (i = 0; i < 3; i++) { + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + } + + if ((rc = pthread_mutex_destroy(&newfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(newfiles)"); + if ((rc = pthread_cond_destroy(&newfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(newfiles)"); + if ((rc = pthread_mutex_destroy(&renamedfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); + if ((rc = pthread_cond_destroy(&renamedfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(renamedfiles)"); + free(dirname1); + free(dirname2); + + return (0); +} diff --git a/tools/test/stress2/misc/pthread3.sh b/tools/test/stress2/misc/pthread3.sh new file mode 100755 index 000000000000..71ec35141ef4 --- /dev/null +++ b/tools/test/stress2/misc/pthread3.sh @@ -0,0 +1,304 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# _exit(2) test scenario with focus on shared channel tear down. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pthread3.c +mycc -o pthread3 -Wall -Wextra -O2 -g -gdwarf-2 pthread3.c -lpthread || exit 1 +rm -f pthread3.c + +for i in `jot 8`; do + /tmp/pthread3 & + pids="$pids $!" +done +s=0 +for i in $pids; do + wait $i + e=$? + [ $e -ne 0 ] && s=$e +done + +rm -f /tmp/pthread3 + +exit $s +EOF +/* + * Threaded producer-consumer test. + * Loosly based on work by + * Andrey Zonov (c) 2012 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __FreeBSD__ +#include +#define __NP__ +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOCK(x) plock(&x.mtx) +#define UNLOCK(x) punlock(&x.mtx) +#define SIGNAL(x) psig(&x.wait) +#define WAIT(x) pwait(&x.wait, &x.mtx) + +long ncreate, nrename, nunlink; +int max; +char *dirname1; +char *dirname2; + +struct file { + char *name; + STAILQ_ENTRY(file) next; +}; + +struct files { + pthread_mutex_t mtx; + pthread_cond_t wait; + STAILQ_HEAD(, file) list; +}; + +static struct files newfiles; +static struct files renamedfiles; + +static void +hand(int i __unused) { /* handler */ + fprintf(stderr, "max = %d, ncreate = %ld, nrename = %ld, nunlink = %ld\n", + max, ncreate, nrename, nunlink); +} + +static void +ahand(int i __unused) { /* handler */ + fprintf(stderr, "FAIL\n"); + hand(0); + _exit(0); +} + +void +plock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_lock(l)) != 0) + errc(1, rc, "pthread_mutex_lock"); +} + +void +punlock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_unlock(l)) != 0) + errc(1, rc, "pthread_mutex_unlock"); +} + +void +psig(pthread_cond_t *c) +{ + int rc; + + if ((rc = pthread_cond_signal(c)) != 0) + errc(1, rc, "pthread_cond_signal"); +} + +void +pwait(pthread_cond_t *c, pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_cond_wait(c, l)) != 0) + errc(1, rc, "pthread_cond_wait"); +} + +void * +loop_create(void *arg __unused) +{ + int i, j; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + for (i = 0; i < max; i++) { + file = malloc(sizeof(*file)); + asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); + LOCK(newfiles); + STAILQ_INSERT_TAIL(&newfiles.list, file, next); + ncreate++; + UNLOCK(newfiles); + SIGNAL(newfiles); + if ((i > 0) && (i % 100000 == 0)) + for (j = 0; j < 10 && ncreate != nrename; j++) + usleep(400); + } + return (NULL); +} + +void * +loop_rename(void *arg __unused) +{ + char *filename, *newname; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nrename < max) { + LOCK(newfiles); + while (STAILQ_EMPTY(&newfiles.list)) { + WAIT(newfiles); + } + file = STAILQ_FIRST(&newfiles.list); + STAILQ_REMOVE_HEAD(&newfiles.list, next); + UNLOCK(newfiles); + filename = strrchr(file->name, '/'); + asprintf(&newname, "%s/%s", dirname2, filename); + nrename++; + free(file->name); + file->name = newname; + LOCK(renamedfiles); + STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); + UNLOCK(renamedfiles); + SIGNAL(renamedfiles); + } + return (NULL); +} + +void * +loop_unlink(void *arg __unused) +{ + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nunlink < max) { + LOCK(renamedfiles); + while (STAILQ_EMPTY(&renamedfiles.list)) { + WAIT(renamedfiles); + } + file = STAILQ_FIRST(&renamedfiles.list); + STAILQ_REMOVE_HEAD(&renamedfiles.list, next); + nunlink++; + UNLOCK(renamedfiles); + free(file->name); + free(file); + if (arc4random() % 100 == 1) + if (arc4random() % 100 == 1) + if (arc4random() % 100 < 10) + _exit(0); + } + return (NULL); +} + +void +test(void) +{ + int i; + int rc; + pthread_t tid[3]; + + asprintf(&dirname1, "%s.1", "f1"); + asprintf(&dirname2, "%s.2", "f2"); +// max = 15000000; + max = 50000; + + STAILQ_INIT(&newfiles.list); + STAILQ_INIT(&renamedfiles.list); + + if ((rc = pthread_mutex_init(&newfiles.mtx, NULL)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&newfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + if ((rc = pthread_mutex_init(&renamedfiles.mtx, NULL)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&renamedfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + + signal(SIGINFO, hand); + signal(SIGALRM, ahand); + alarm(300); + if ((rc = pthread_create(&tid[0], NULL, loop_create, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[1], NULL, loop_rename, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[2], NULL, loop_unlink, NULL)) != 0) + errc(1, rc, "pthread_create()"); + + for (i = 0; i < 3; i++) { + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + } + + if ((rc = pthread_mutex_destroy(&newfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(newfiles)"); + if ((rc = pthread_cond_destroy(&newfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(newfiles)"); + if ((rc = pthread_mutex_destroy(&renamedfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); + if ((rc = pthread_cond_destroy(&renamedfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(renamedfiles)"); + free(dirname1); + free(dirname2); + + _exit(0); +} + +int +main(void) +{ + int i; + + alarm(1200); + for (i = 0; i < 1000; i++) { + if (fork() == 0) + test(); + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/pthread4.sh b/tools/test/stress2/misc/pthread4.sh new file mode 100755 index 000000000000..8733ac6e2cf0 --- /dev/null +++ b/tools/test/stress2/misc/pthread4.sh @@ -0,0 +1,296 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP version of pthread2.sh + +. ../default.cfg + +export LANG=C +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pthread4.c +mycc -o pthread4 -Wall -Wextra -O2 -g -gdwarf-2 pthread4.c -lpthread || exit 1 +rm -f pthread4.c /tmp/pthread4.core + +log=/tmp/pthread4.`date '+%Y%m%d-%H%M'` +for i in `jot 5`; do + [ $i -eq 1 ] && echo "# `uname -v`" + time sh -c ' + for i in `jot 8`; do + /tmp/pthread4 & + done + wait + ' +done > $log 2>&1 +rm -f /tmp/pthread4 + +if [ -n "$bench" ]; then + pair=`ls /tmp/pthread4* | egrep "pthread4\.[0-9]{8}-" | sort | + tail -2 | tr '\n' ' '` + ministat -w 72 $pair +else + rm -f $log +fi + +exit 0 +EOF +/* + * Threaded producer-consumer test. + * Loosly based on work by + * Andrey Zonov (c) 2012 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __FreeBSD__ +#include +#define __NP__ +#endif +#include +#include +#include +#include +#include +#include +#include + +#define LOCK(x) plock(&x.mtx) +#define UNLOCK(x) punlock(&x.mtx) +#define SIGNAL(x) psig(&x.wait) +#define WAIT(x) pwait(&x.wait, &x.mtx) + +long ncreate, nrename, nunlink; +int bench, max; +char *dirname1; +char *dirname2; + +struct file { + char *name; + STAILQ_ENTRY(file) next; +}; + +struct files { + pthread_mutex_t mtx; + pthread_cond_t wait; + STAILQ_HEAD(, file) list; +}; + +static struct files newfiles; +static struct files renamedfiles; + +static void +hand(int i __unused) { /* handler */ + fprintf(stderr, "max = %d, ncreate = %ld, nrename = %ld, nunlink = %ld\n", + max, ncreate, nrename, nunlink); +} + +static void +ahand(int i __unused) { /* handler */ + fprintf(stderr, "FAIL\n"); + hand(0); + _exit(0); +} + +void +plock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_lock(l)) != 0) + errc(1, rc, "pthread_mutex_lock"); +} + +void +punlock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_unlock(l)) != 0) + errc(1, rc, "pthread_mutex_unlock"); +} + +void +psig(pthread_cond_t *c) +{ + int rc; + + if ((rc = pthread_cond_signal(c)) != 0) + errc(1, rc, "pthread_cond_signal"); +} + +void +pwait(pthread_cond_t *c, pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_cond_wait(c, l)) != 0) + errc(1, rc, "pthread_cond_wait"); +} + +void * +loop_create(void *arg __unused) +{ + int i, j; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + for (i = 0; i < max; i++) { + file = malloc(sizeof(*file)); + asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); + LOCK(newfiles); + STAILQ_INSERT_TAIL(&newfiles.list, file, next); + ncreate++; + UNLOCK(newfiles); + SIGNAL(newfiles); + if ((bench == 0) && (i > 0) && (i % 100000 == 0)) + for (j = 0; j < 10 && ncreate != nrename; j++) + usleep(400); + } + return (NULL); +} + +void * +loop_rename(void *arg __unused) +{ + char *filename, *newname; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nrename < max) { + LOCK(newfiles); + while (STAILQ_EMPTY(&newfiles.list)) { + WAIT(newfiles); + } + file = STAILQ_FIRST(&newfiles.list); + STAILQ_REMOVE_HEAD(&newfiles.list, next); + UNLOCK(newfiles); + filename = strrchr(file->name, '/'); + asprintf(&newname, "%s/%s", dirname2, filename); + nrename++; + free(file->name); + file->name = newname; + LOCK(renamedfiles); + STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); + UNLOCK(renamedfiles); + SIGNAL(renamedfiles); + } + return (NULL); +} + +void * +loop_unlink(void *arg __unused) +{ + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nunlink < max) { + LOCK(renamedfiles); + while (STAILQ_EMPTY(&renamedfiles.list)) { + WAIT(renamedfiles); + } + file = STAILQ_FIRST(&renamedfiles.list); + STAILQ_REMOVE_HEAD(&renamedfiles.list, next); + nunlink++; + UNLOCK(renamedfiles); + free(file->name); + free(file); + } + return (NULL); +} + +int +main(void) +{ + int i; + int rc; + pthread_t tid[3]; + pthread_mutexattr_t attr, *pattr = NULL; + + bench = getenv("bench") != NULL; + asprintf(&dirname1, "%s.1", "f1"); + asprintf(&dirname2, "%s.2", "f2"); + max = 15000000; + + STAILQ_INIT(&newfiles.list); + STAILQ_INIT(&renamedfiles.list); + + pthread_mutexattr_init (&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP); + pattr = &attr; + if ((rc = pthread_mutex_init(&newfiles.mtx, pattr)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&newfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + if ((rc = pthread_mutex_init(&renamedfiles.mtx, NULL)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&renamedfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + + signal(SIGINFO, hand); + signal(SIGALRM, ahand); + alarm(300); + if ((rc = pthread_create(&tid[0], NULL, loop_create, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[1], NULL, loop_rename, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[2], NULL, loop_unlink, NULL)) != 0) + errc(1, rc, "pthread_create()"); + + for (i = 0; i < 3; i++) { + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + } + + if ((rc = pthread_mutex_destroy(&newfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(newfiles)"); + if ((rc = pthread_cond_destroy(&newfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(newfiles)"); + if ((rc = pthread_mutex_destroy(&renamedfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); + if ((rc = pthread_cond_destroy(&renamedfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(renamedfiles)"); + free(dirname1); + free(dirname2); + + return (0); +} diff --git a/tools/test/stress2/misc/pthread5.sh b/tools/test/stress2/misc/pthread5.sh new file mode 100755 index 000000000000..02093ae48ed5 --- /dev/null +++ b/tools/test/stress2/misc/pthread5.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# Stress shchan allocations. + +. ../default.cfg +[ `swapinfo | wc -l` -eq 1 ] && exit 0 # kstack allocation failed + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pthread5.c +mycc -o pthread5 -Wall -Wextra -O2 pthread5.c -lpthread || exit 1 +rm -f pthread5.c + +/tmp/pthread5 + +rm -f /tmp/pthread5 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ITER 2 +#define PARALLEL 1000 +#define THREADS 100 + +pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +static void * +nicethreads(void *data __unused) +{ + struct timespec ts; + struct timeval tp; + + pthread_mutex_lock(&mutex); + gettimeofday(&tp, NULL); + + ts.tv_sec = tp.tv_sec; + ts.tv_nsec = tp.tv_usec * 1000; + ts.tv_sec += 30; + + pthread_cond_timedwait(&cond, &mutex, &ts); + pthread_mutex_unlock(&mutex); + + return (NULL); +} + +int +test(void) +{ + int num_thread = THREADS; + pthread_t tid[num_thread]; + int i, iter, rc; + + for (iter = 0; iter < ITER; iter++) { + for (i = 0; i < num_thread; i++) { + if ((rc = pthread_create(&tid[i], NULL, nicethreads, + NULL)) != 0) + errc(1, rc, "pthread_create"); + } + usleep(20000); + for (i = 0; i < num_thread; i++) { + rc = pthread_mutex_lock(&mutex); + rc = pthread_cond_signal(&cond); + rc = pthread_mutex_unlock(&mutex); + } + for (i = 0; i < num_thread; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join"); + } + + _exit(0); +} + +int +main(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + test(); + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/pthread6.sh b/tools/test/stress2/misc/pthread6.sh new file mode 100755 index 000000000000..052dd2c5f678 --- /dev/null +++ b/tools/test/stress2/misc/pthread6.sh @@ -0,0 +1,308 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# "panic: pmap active 0xfffff80128cd84b8" seen: +# http://people.freebsd.org/~pho/stress/log/attilio101.txt + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pthread6.c +mycc -o pthread6 -Wall -Wextra -O2 -g -gdwarf-2 pthread6.c -lpthread || exit 1 +rm -f pthread6.c /tmp/pthread6.core + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)" +sleep `jot -r 1 1 9` +echo "Expect SIGABRT" +for i in `jot 50`; do + /tmp/pthread6 +done +while pgrep -q swap; do + pkill swap + sleep 1 +done + +rm -f /tmp/pthread6 /tmp/pthread6.core +exit 0 +EOF +/* + * Threaded producer-consumer test. + * Loosly based on work by + * Andrey Zonov (c) 2012 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __FreeBSD__ +#include +#define __NP__ +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOCK(x) plock(&x.mtx) +#define UNLOCK(x) punlock(&x.mtx) +#define SIGNAL(x) psig(&x.wait) +#define WAIT(x) pwait(&x.wait, &x.mtx) + +#define PARALLEL 4 +#define LOOPS 2 + +long ncreate, nrename, nunlink; +int bench, max; +char *dirname1; +char *dirname2; + +struct file { + char *name; + STAILQ_ENTRY(file) next; +}; + +struct files { + pthread_mutex_t mtx; + pthread_cond_t wait; + STAILQ_HEAD(, file) list; +}; + +static struct files newfiles; +static struct files renamedfiles; + +static void +hand(int i __unused) { /* handler */ +} + +static void +ahand(int i __unused) { /* handler */ + abort(); +} + +void +plock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_lock(l)) != 0) + errc(1, rc, "pthread_mutex_lock"); +} + +void +punlock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_unlock(l)) != 0) + errc(1, rc, "pthread_mutex_unlock"); +} + +void +psig(pthread_cond_t *c) +{ + int rc; + + if ((rc = pthread_cond_signal(c)) != 0) + errc(1, rc, "pthread_cond_signal"); +} + +void +pwait(pthread_cond_t *c, pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_cond_wait(c, l)) != 0) + errc(1, rc, "pthread_cond_wait"); +} + +void * +loop_create(void *arg __unused) +{ + int i, j; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + for (i = 0; i < max; i++) { + file = malloc(sizeof(*file)); + asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); + LOCK(newfiles); + STAILQ_INSERT_TAIL(&newfiles.list, file, next); + ncreate++; + UNLOCK(newfiles); + SIGNAL(newfiles); + if ((bench == 0) && (i > 0) && (i % 100000 == 0)) + for (j = 0; j < 10 && ncreate != nrename; j++) + usleep(400); + } + return (NULL); +} + +void * +loop_rename(void *arg __unused) +{ + char *filename, *newname; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nrename < max) { + LOCK(newfiles); + while (STAILQ_EMPTY(&newfiles.list)) { + WAIT(newfiles); + } + file = STAILQ_FIRST(&newfiles.list); + STAILQ_REMOVE_HEAD(&newfiles.list, next); + UNLOCK(newfiles); + filename = strrchr(file->name, '/'); + asprintf(&newname, "%s/%s", dirname2, filename); + nrename++; + free(file->name); + file->name = newname; + LOCK(renamedfiles); + STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); + UNLOCK(renamedfiles); + SIGNAL(renamedfiles); + } + return (NULL); +} + +void * +loop_unlink(void *arg __unused) +{ + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nunlink < max) { + LOCK(renamedfiles); + while (STAILQ_EMPTY(&renamedfiles.list)) { + WAIT(renamedfiles); + } + file = STAILQ_FIRST(&renamedfiles.list); + STAILQ_REMOVE_HEAD(&renamedfiles.list, next); + nunlink++; + UNLOCK(renamedfiles); + free(file->name); + free(file); + } + return (NULL); +} + +void +test(void) +{ + int i; + int rc; + pthread_t tid[3]; + pthread_mutexattr_t attr, *pattr = NULL; + + bench = getenv("bench") != NULL; + bench = 1; + asprintf(&dirname1, "%s.1", "f1"); + asprintf(&dirname2, "%s.2", "f2"); + max = 15000000; + + STAILQ_INIT(&newfiles.list); + STAILQ_INIT(&renamedfiles.list); + + pthread_mutexattr_init (&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP); + pattr = &attr; + if ((rc = pthread_mutex_init(&newfiles.mtx, pattr)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&newfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + if ((rc = pthread_mutex_init(&renamedfiles.mtx, NULL)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&renamedfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + + signal(SIGINFO, hand); + signal(SIGALRM, ahand); + if ((rc = pthread_create(&tid[0], NULL, loop_create, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[1], NULL, loop_rename, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[2], NULL, loop_unlink, NULL)) != 0) + errc(1, rc, "pthread_create()"); + + usleep(1000); + ualarm(arc4random() % 100000, 0); + for (i = 0; i < 3; i++) { + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + } + + if ((rc = pthread_mutex_destroy(&newfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(newfiles)"); + if ((rc = pthread_cond_destroy(&newfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(newfiles)"); + if ((rc = pthread_mutex_destroy(&renamedfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); + if ((rc = pthread_cond_destroy(&renamedfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(renamedfiles)"); + free(dirname1); + free(dirname2); + + _exit(0); +} + +int +main(void) +{ + int i, j; + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/pthread7.sh b/tools/test/stress2/misc/pthread7.sh new file mode 100755 index 000000000000..41190190bd22 --- /dev/null +++ b/tools/test/stress2/misc/pthread7.sh @@ -0,0 +1,285 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# PTHREAD_PRIO_INHERIT version of pthread2.sh + +. ../default.cfg + +export LANG=C +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pthread7.c +mycc -o pthread7 -Wall -Wextra -O2 -g pthread7.c -lpthread || exit 1 +rm -f pthread7.c + +for i in `jot 5`; do + for i in `jot 8`; do + /tmp/pthread7 & + done + wait +done +rm -f /tmp/pthread7 +exit 0 +EOF +/* + * Threaded producer-consumer test. + * Loosly based on work by + * Andrey Zonov (c) 2012 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __FreeBSD__ +#include +#define __NP__ +#endif +#include +#include +#include +#include +#include +#include +#include + +#define LOCK(x) plock(&x.mtx) +#define UNLOCK(x) punlock(&x.mtx) +#define SIGNAL(x) psig(&x.wait) +#define WAIT(x) pwait(&x.wait, &x.mtx) + +long ncreate, nrename, nunlink; +int max; +char *dirname1; +char *dirname2; + +struct file { + char *name; + STAILQ_ENTRY(file) next; +}; + +struct files { + pthread_mutex_t mtx; + pthread_cond_t wait; + STAILQ_HEAD(, file) list; +}; + +static struct files newfiles; +static struct files renamedfiles; + +#define MAXQ 100000 /* Max create queue length */ +#define MESSAGES 10000000; + +static void +hand(int i __unused) { /* handler */ + fprintf(stderr, "max = %d, ncreate = %ld, nrename = %ld, nunlink = %ld\n", + max, ncreate, nrename, nunlink); +} + +static void +ahand(int i __unused) { /* handler */ + fprintf(stderr, "FAIL\n"); + hand(0); + _exit(0); +} + +void +plock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_lock(l)) != 0) + errc(1, rc, "pthread_mutex_lock"); +} + +void +punlock(pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_mutex_unlock(l)) != 0) + errc(1, rc, "pthread_mutex_unlock"); +} + +void +psig(pthread_cond_t *c) +{ + int rc; + + if ((rc = pthread_cond_signal(c)) != 0) + errc(1, rc, "pthread_cond_signal"); +} + +void +pwait(pthread_cond_t *c, pthread_mutex_t *l) +{ + int rc; + + if ((rc = pthread_cond_wait(c, l)) != 0) + errc(1, rc, "pthread_cond_wait"); +} + +void * +loop_create(void *arg __unused) +{ + int i; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + for (i = 0; i < max; i++) { + file = malloc(sizeof(*file)); + asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); + LOCK(newfiles); + STAILQ_INSERT_TAIL(&newfiles.list, file, next); + ncreate++; + UNLOCK(newfiles); + SIGNAL(newfiles); + if (ncreate - nrename > MAXQ) + usleep(400); + } + return (NULL); +} + +void * +loop_rename(void *arg __unused) +{ + char *filename, *newname; + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nrename < max) { + LOCK(newfiles); + while (STAILQ_EMPTY(&newfiles.list)) { + WAIT(newfiles); + } + file = STAILQ_FIRST(&newfiles.list); + STAILQ_REMOVE_HEAD(&newfiles.list, next); + UNLOCK(newfiles); + filename = strrchr(file->name, '/'); + asprintf(&newname, "%s/%s", dirname2, filename); + nrename++; + free(file->name); + file->name = newname; + LOCK(renamedfiles); + STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); + UNLOCK(renamedfiles); + SIGNAL(renamedfiles); + } + return (NULL); +} + +void * +loop_unlink(void *arg __unused) +{ + struct file *file; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + + while (nunlink < max) { + LOCK(renamedfiles); + while (STAILQ_EMPTY(&renamedfiles.list)) { + WAIT(renamedfiles); + } + file = STAILQ_FIRST(&renamedfiles.list); + STAILQ_REMOVE_HEAD(&renamedfiles.list, next); + nunlink++; + UNLOCK(renamedfiles); + free(file->name); + free(file); + } + return (NULL); +} + +int +main(void) +{ + int i; + int rc; + pthread_t tid[3]; + pthread_mutexattr_t attr, *pattr = NULL; + + asprintf(&dirname1, "%s.1", "f1"); + asprintf(&dirname2, "%s.2", "f2"); + max = MESSAGES; + + STAILQ_INIT(&newfiles.list); + STAILQ_INIT(&renamedfiles.list); + + pthread_mutexattr_init (&attr); + if ((rc = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT)) != 0) + errc(1, rc, "PTHREAD_PRIO_INHERIT"); + pattr = &attr; + if ((rc = pthread_mutex_init(&newfiles.mtx, pattr)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&newfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + if ((rc = pthread_mutex_init(&renamedfiles.mtx, NULL)) != 0) + errc(1, rc, "pthread_mutex_init()"); + if ((rc = pthread_cond_init(&renamedfiles.wait, NULL)) != 0) + errc(1, rc, "pthread_cond_init()"); + + signal(SIGINFO, hand); + signal(SIGALRM, ahand); + alarm(300); + if ((rc = pthread_create(&tid[0], NULL, loop_create, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[1], NULL, loop_rename, NULL)) != 0) + errc(1, rc, "pthread_create()"); + if ((rc = pthread_create(&tid[2], NULL, loop_unlink, NULL)) != 0) + errc(1, rc, "pthread_create()"); + + for (i = 0; i < 3; i++) { + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + } + + if ((rc = pthread_mutex_destroy(&newfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(newfiles)"); + if ((rc = pthread_cond_destroy(&newfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(newfiles)"); + if ((rc = pthread_mutex_destroy(&renamedfiles.mtx)) != 0) + errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); + if ((rc = pthread_cond_destroy(&renamedfiles.wait)) != 0) + errc(1, rc, "pthread_cond_destroy(renamedfiles)"); + free(dirname1); + free(dirname2); + + return (0); +} diff --git a/tools/test/stress2/misc/pthread8.sh b/tools/test/stress2/misc/pthread8.sh new file mode 100755 index 000000000000..d6461daa0f46 --- /dev/null +++ b/tools/test/stress2/misc/pthread8.sh @@ -0,0 +1,137 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# PTHREAD_PRIO_INHERIT test scenario + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pthread8.c +mycc -o pthread8 -Wall -Wextra -O0 -g pthread8.c -lpthread || exit 1 +rm -f pthread8.c /tmp/pthread8.core + +/tmp/pthread8 + +rm -f /tmp/pthread8 +exit 0 +EOF +/* $Id: pi.c,v 1.2 2015/01/31 11:36:07 kostik Exp kostik $ */ + +#include +#include +#include +#include +#include +#include +#include + +struct runner_arg { + pthread_mutex_t *locks; + u_int lock_cnt; +}; + +int stop; + +void * +runner(void *arg) +{ + struct runner_arg *ra; + pthread_mutex_t *l; + u_int i; + int error; + + ra = arg; + while (stop == 0) { + for (i = 0; i < ra->lock_cnt; i++) { + l = &ra->locks[i]; + error = pthread_mutex_lock(l); + if (error != 0) + errc(1, error, "pthread_mutex_lock"); + pthread_yield(); + } + for (i = 0; i < ra->lock_cnt; i++) { + l = &ra->locks[i]; + error = pthread_mutex_unlock(l); + if (error != 0) + errc(1, error, "pthread_mutex_lock"); + pthread_yield(); + } + } + return (NULL); +} + +int +main(void) +{ + struct runner_arg ra; + time_t start; + pthread_t *threads; + pthread_mutexattr_t mattr; + u_int i, ncpus; + int error; + size_t ncpus_len; + + ncpus_len = sizeof(ncpus); + error = sysctlbyname("hw.ncpu", &ncpus, &ncpus_len, NULL, 0); + if (error != 0) + err(1, "sysctl hw.ncpus"); + threads = calloc(ncpus, sizeof(pthread_t)); + if (threads == NULL) + err(1, "calloc threads"); + + ra.lock_cnt = 100; + ra.locks = calloc(ra.lock_cnt, sizeof(pthread_mutex_t)); + if (ra.locks == NULL) + err(1, "calloc locks"); + error = pthread_mutexattr_init(&mattr); + if (error != 0) + errc(1, error, "pthread_mutexattr_init"); + error = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT); + if (error != 0) + errc(1, error, "pthread_mutexattr_setprotocol PRIO_INHERIT"); + for (i = 0; i < ra.lock_cnt; i++) { + error = pthread_mutex_init(&ra.locks[i], &mattr); + if (error != 0) + errc(1, error, "pthread_mutex_init"); + } + + for (i = 0; i < ncpus; i++) { + error = pthread_create(&threads[i], NULL, runner, &ra); + if (error != 0) + errc(1, error, "pthread_create"); + } + start = time(NULL); + while (time(NULL) - start < 180) + sleep(1); + stop = 1; + for (i = 0; i < ncpus; i++) + pthread_join(threads[i], NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/pthread9.sh b/tools/test/stress2/misc/pthread9.sh new file mode 100755 index 000000000000..a5aaeeab9af0 --- /dev/null +++ b/tools/test/stress2/misc/pthread9.sh @@ -0,0 +1,185 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# Thread suspend deadlock seen: +# https://people.freebsd.org/~pho/stress/log/pthread9.txt + +# Test scenario by Conrad Meyer. +# Fixed by r283320. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pthread9.c +mycc -o pthread9 -Wall -Wextra -O2 pthread9.c -lpthread || exit 1 +rm -f pthread9.c + +status=0 +if ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1; then + mount -t nfs -o nfsv3,tcp,nolockd,retrycnt=3,intr $nfs_export \ + $mntpoint || exit 1 + sleep .5 + echo "Expect core dumps" + (cd $mntpoint; /tmp/pthread9) & + sleep 200 + if pgrep -q pthread9; then + echo FAIL + procstat -k `pgrep pthread9 | grep -v $!` + status=1 + fi + rm -f $mntpoint/pthread9.core + umount -f $mntpoint + wait +fi + +rm -f /tmp/pthread9 /tmp/pthread9.core +exit $status +EOF +#include + +#include + +#include +#include +#include +#include +#ifdef __FreeBSD__ +#include +#define __NP__ +#endif +#include +#include +#include +#include +#include + +#define LOOPS 50 +#define RUNTIME 180 + +volatile u_int go; +int fd; +char file[] = "pthread9.file"; + +static void * +t1(void *data __unused) +{ + int i; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + while (go == 0) + pthread_yield(); + + atomic_add_int(&go, 1); + for (i = 0; i < 100; i++) + if (ftruncate(fd, 0) == -1) + err(1, "truncate"); + + return (NULL); +} + +static void * +t2(void *data __unused) +{ + int i; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + while (go == 0) + pthread_yield(); + + atomic_add_int(&go, 1); + for (i = 0; i < 100; i++) + if (ftruncate(fd, 0) == -1) + err(1, "truncate"); + + return (NULL); +} + +static void * +t3(void *data __unused) +{ + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + while (go != 3) + pthread_yield(); + abort(); + + return (NULL); +} + +int +test(void) +{ + pthread_t tid[3]; + int i, rc; + + go = 0; + if ((rc = pthread_create(&tid[0], NULL, t1, NULL)) != 0) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[1], NULL, t2, NULL)) != 0) + errc(1, rc, "pthread_create"); + if ((rc = pthread_create(&tid[2], NULL, t3, NULL)) != 0) + errc(1, rc, "pthread_create"); + usleep(200); + atomic_add_int(&go, 1); + + for (i = 0; i < 3; i++) { + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join"); + } + + _exit(0); +} + +int +main(void) +{ + time_t start; + + if ((fd = open(file, O_RDWR | O_CREAT, 0644)) == -1) + err(1, "open(%s)", file); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if (fork() == 0) + test(); + wait(NULL); + } + close(fd); + unlink(file); + + return (0); +} diff --git a/tools/test/stress2/misc/ptrace.sh b/tools/test/stress2/misc/ptrace.sh new file mode 100755 index 000000000000..7e747378624e --- /dev/null +++ b/tools/test/stress2/misc/ptrace.sh @@ -0,0 +1,106 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# wait4(2) / ptrace(2) regression test. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > ptrace.c +mycc -o ptrace -Wall -Wextra -g ptrace.c || exit 1 +rm -f ptrace.c +cd $here + +/tmp/ptrace + +rm -f /tmp/ptrace +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void +test(void) +{ + pid_t pid, rpid; + struct rusage ru; + int status; + + if ((pid = fork()) == 0) { + usleep(2000); + _exit(64); + } + if (pid == -1) + err(1, "fork()"); + if (ptrace(PT_ATTACH, pid, NULL, 0) == -1) + err(1, "ptrace(%d) attach", pid); + if (wait(NULL) == -1) + err(1, "wait"); + bzero(&ru, sizeof(ru)); + usleep(2000); + if ((rpid = wait4(-1, &status, WNOHANG, &ru)) == -1) { + if (errno == ECHILD) + warn("FAIL"); + else + err(1, "wait4"); + } + if (rpid == 0) { +// fprintf(stderr, "No rusage info.\n"); + if (ptrace(PT_DETACH, pid, NULL, 0) == -1) + err(1, "ptrace(%d) detach", pid); + if (wait(&status) == -1) + err(1, "wait"); + } else { + fprintf(stderr, "FAIL Got unexpected rusage.\n"); + if (ru.ru_utime.tv_sec != 0) + fprintf(stderr, "FAIL tv_sec\n"); + } + if (status != 0x4000) + fprintf(stderr, "FAIL Child exit status 0x%x\n", status); + + _exit(0); +} + +int +main(void) +{ + test(); + + return (0); +} diff --git a/tools/test/stress2/misc/ptrace10.sh b/tools/test/stress2/misc/ptrace10.sh new file mode 100755 index 000000000000..c2dec736a240 --- /dev/null +++ b/tools/test/stress2/misc/ptrace10.sh @@ -0,0 +1,161 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 Mark Johnston +# +# 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. +# + +# ptrace(2) test scenario by Mark Johnston +# https://people.freebsd.org/~markj/ptrace_stop_mt.c +# Fixed by r303423. + +# stopped on signal 17 after detach +# UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND +# 1001 47125 62778 0 52 0 6568 2456 wait S+ 2 0:00.01 /bin/sh ./ptrace10.sh +# 1001 47146 47125 0 23 0 6108 1928 nanslp S+ 2 0:00.00 ./ptrace10 +# 1001 47148 47146 0 24 0 6240 1932 - T+ 2 0:00.00 ./ptrace10 +# 1001 47148 47146 0 24 0 6240 1932 - T+ 2 0:00.00 ./ptrace10 + +. ../default.cfg + +cd /tmp +cat > ptrace10.c < +#include +#include + +#include +#include +#include +#include +#include +#include + +static void +sighup(int sig __unused) +{ +} + +static void +sleep_forever(void) +{ + + while (1) + sleep(1); +} + +static void * +thread(void *arg __unused) +{ + + sleep_forever(); + return (NULL); +} + +int +main(void) +{ + struct sigaction act; + sigset_t set; + pthread_t t; + pid_t pid, ret; + int e, try, limit, r, status; + + e = 0; + pid = fork(); + if (pid < 0) + err(1, "fork"); + if (pid == 0) { + act.sa_handler = sighup; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + if (sigaction(SIGHUP, &act, NULL) != 0) + err(1, "sigaction"); + + r = pthread_create(&t, NULL, thread, NULL); + if (r != 0) + errc(1, r, "pthread_create"); + + /* Force SIGHUP to be delivered to the new thread. */ + sigemptyset(&set); + sigaddset(&set, SIGHUP); + r = pthread_sigmask(SIG_BLOCK, &set, NULL); + if (r != 0) + errc(1, r, "pthread_sigmask"); + + sleep_forever(); + } else { + sleep(1); /* give the child a chance to set itself up */ + + limit = 100; + for (try = 1; try <= limit; try++) { + if (kill(pid, SIGHUP) != 0) + err(1, "kill(SIGHUP)"); + if (ptrace(PT_ATTACH, pid, NULL, 0) != 0) + err(1, "ptrace(PT_ATTACH)"); + if (waitpid(pid, &status, WUNTRACED) != pid) + err(1, "waitpid 1"); + if (!WIFSTOPPED(status)) + errx(1, "unexpected status %d after PT_ATTACH", + status); + if (ptrace(PT_DETACH, pid, NULL, 0) != 0) + err(1, "ptrace(PT_DETACH)"); + + sleep(1); + ret = waitpid(pid, &status, WUNTRACED | WNOHANG); + if (ret < 0) + err(1, "waitpid"); + if (ret == 0) + continue; + if (!WIFSTOPPED(status)) + errx(1, "unexpected status %d after PT_DETACH", + status); + printf("stopped on signal %d after detach\n", + WSTOPSIG(status)); + e = 1; + break; + } + } + kill(pid, SIGINT); + + return (e); +} +EOF + +mycc -o ptrace10 -Wall -Wextra -O2 -g ptrace10.c -lpthread || exit 1 +rm ptrace10.c + +./ptrace10 +s=$? +if [ $s -ne 0 ]; then + ps -lxH | grep -v grep | egrep "UID|ptrace10" + while pgrep -q ptrace10; do + pkill -9 ptrace10 + done +fi +wait + +rm -f ptrace10 +exit $s diff --git a/tools/test/stress2/misc/ptrace11.sh b/tools/test/stress2/misc/ptrace11.sh new file mode 100755 index 000000000000..9fbd44481624 --- /dev/null +++ b/tools/test/stress2/misc/ptrace11.sh @@ -0,0 +1,124 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# markj@ wrote: +# I found a kernel bug that caused init to consume 100% CPU if the +# following steps occurred: +# - process A forks and creates process B +# - process C ptrace attaches to process B +# - process A exits +# - process C detaches from process B +# - process B exits +# +# Process B gets reparented to init, and the bug causes wait() to return +# an error each time init attempts to reap process B. + +. ../default.cfg +cd /tmp +cat > ptrace11.c < +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; +#define SYNC 0 + +int +main(void) +{ + pid_t pida, pidb; + size_t len; + int status; + + setproctitle("A"); + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + pida = fork(); + if (pida < 0) + err(1, "fork"); + if (pida == 0) { + setproctitle("B"); + while (share[SYNC] != 2) + usleep(10); + _exit(0); + } else { + sleep(1); + pidb = fork(); + if (pidb < 0) + err(1, "fork"); + if (pidb == 0) { + setproctitle("C"); + if (ptrace(PT_ATTACH, pida, NULL, 0) != 0) + err(1, "ptrace(PT_ATTACH)"); + wait4(pida, &status, 0, NULL); + share[SYNC] = 1; /* A to exit */ + usleep(1000); + if (ptrace(PT_DETACH, pida, NULL, 0) != 0) + err(1, "ptrace(PT_DETACH)"); + share[SYNC] = 2; /* B to exit */ + _exit(0); + } else { + while (share[SYNC] != 1) + usleep(10); + _exit(0); + } + } + + return (0); +} +EOF + +mycc -o ptrace11 -Wall -Wextra -O2 -g ptrace11.c || exit 1 +rm ptrace11.c +old=`ps auxwwl | grep -v grep | grep "" | wc -l` + +./ptrace11 + +new=`ps auxwwl | grep -v grep | grep "" | wc -l` +if [ $old -ne $new ]; then + ps auxwwl | sed -n '1p;//p' + echo FAIL + s=1 +fi + +rm -f ptrace11 +exit $s diff --git a/tools/test/stress2/misc/ptrace2.sh b/tools/test/stress2/misc/ptrace2.sh new file mode 100755 index 000000000000..7e689f981fc8 --- /dev/null +++ b/tools/test/stress2/misc/ptrace2.sh @@ -0,0 +1,143 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Regression test for kern/142757, race condition in traced process signal +# handling. Fixed in r202692. + +# Test scenario by Tijl Coosemans, tijl@ + +. ../default.cfg + +cd /tmp + +cat > race1.c < +#include +#include +#include +#include +#include + +int +main(void) +{ + pid_t pid; + int i, status; + + alarm(120); + /* fork dummy child process */ + pid = fork(); + if (pid == 0) { + /* child does nothing */ + for (;;) { + sleep(1); + } + } else { + /* parent */ + sleep(1); + for (i = 0; i < 100000; i++) { + /* loop: attach, wait, detach */ + printf("attach "); + fflush(stdout); + ptrace(PT_ATTACH, pid, (caddr_t) 0, 0); + + printf("wait "); + fflush(stdout); + wait4(pid, &status, 0, NULL); + + printf("detach "); + fflush(stdout); + ptrace(PT_DETACH, pid, (caddr_t) 1, 0); + + printf("ok\n"); + fflush(stdout); + } + } + kill(pid, SIGINT); + + return (0); +} +EOF + +cat > race2.c < +#include +#include +#include +#include +#include + +int +main(void) +{ + pid_t pid; + int i, status; + + alarm(120); + /* fork dummy child process */ + pid = fork(); + if (pid == 0) { + /* child does nothing */ + for (;;) { + sleep(1); + } + } else { + /* parent */ + sleep(1); + ptrace(PT_ATTACH, pid, (caddr_t) 0, 0); + wait4(pid, &status, 0, NULL); + for (i = 0; i < 100000; i++) { + /* loop: continue, kill, wait */ + printf("continue "); + fflush(stdout); + ptrace(PT_CONTINUE, pid, (caddr_t) 1, 0); + + printf("kill "); + fflush(stdout); + kill(pid, SIGINT); + + printf("wait "); + fflush(stdout); + wait4(pid, &status, 0, NULL); + + printf("ok\n"); + fflush(stdout); + } + } + + return (0); +} +EOF + +mycc -o race1 -Wall -Wextra race1.c +mycc -o race2 -Wall -Wextra race2.c + +./race1 > /dev/null || echo "FAIL #1" +./race2 > /dev/null || echo "FAIL #2" + +rm -f race1.c race1 race2.c race2 diff --git a/tools/test/stress2/misc/ptrace3.sh b/tools/test/stress2/misc/ptrace3.sh new file mode 100755 index 000000000000..9b8cd4c39670 --- /dev/null +++ b/tools/test/stress2/misc/ptrace3.sh @@ -0,0 +1,130 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# A regression test for a bug introduced in r269656. +# Page fault in proc_realparent+0x70 seen. +# Fixed in r270024. + +# Test scenario by Mark Johnston markj@ + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > ptrace3.c +mycc -o ptrace3 -Wall -Wextra -g ptrace3.c || exit 1 +rm -f ptrace3.c +cd $here + +/tmp/ptrace3 + +rm -f /tmp/ptrace3 +exit +EOF +#include +#include +#include + +#include +#include +#include + +/* + * A regression test for a bug introduced in r269656. The test process p creates + * child processes c1 and c2 which do nothing but sleep; a third child process + * (c3) uses ptrace(2) to reparent c1 and c2 from p to c3. Then c3 detaches from + * c1 and c2, causing a crash when c1 and c2 are removed from p's now-corrupt + * orphan list. + */ + +pid_t +sleeper() +{ + pid_t p; + + p = fork(); + if (p == -1) + err(1, "fork"); + else if (p == 0) + while (1) + sleep(1000000); + return (p); +} + +void +attach(pid_t p) +{ + int status; + + if (ptrace(PT_ATTACH, p, 0, 0) == -1) + err(1, "ptrace"); + + if (waitpid(p, &status, 0) == -1) + err(1, "waitpid"); + else if (!WIFSTOPPED(status)) + errx(1, "failed to stop child"); +} + +void +detach(pid_t p) +{ + + if (ptrace(PT_DETACH, p, 0, 0) == -1) + err(1, "ptrace"); +} + +int +main(void) +{ + int status; + pid_t c1, c2, p; + + c1 = sleeper(); + c2 = sleeper(); + + p = fork(); + if (p == -1) { + err(1, "fork"); + } else if (p == 0) { + attach(c1); + attach(c2); + detach(c1); + detach(c2); + } else { + if (waitpid(p, &status, 0) == -1) + err(1, "waitpid"); + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) + errx(1, "child exited abnormally"); + } + + /* Clean up. */ + (void)kill(c1, SIGKILL); + (void)kill(c2, SIGKILL); + + return (0); +} diff --git a/tools/test/stress2/misc/ptrace4.sh b/tools/test/stress2/misc/ptrace4.sh new file mode 100755 index 000000000000..88d9893c165a --- /dev/null +++ b/tools/test/stress2/misc/ptrace4.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# ptrace(2) test scenario + +# Test program can not be killed: +# https://people.freebsd.org/~pho/stress/log/kostik836.txt +# Fixed by r289660. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +export sleeptime=24 +./syscall4.sh 26 & + +sleep 240 +l=0 +while ps -Unobody | grep -v grep | grep -q syscall4; do + l=$((l + 1)) + if [ $l -gt 10 ]; then + ps -HlUnobody | grep syscall4 + echo FAIL + break + fi + sleep 10 +done +kill $! 2>/dev/null +pkill -9 swap syscall4 +while pgrep -q swap; do + pkill -9 swap +done +wait diff --git a/tools/test/stress2/misc/ptrace5.sh b/tools/test/stress2/misc/ptrace5.sh new file mode 100755 index 000000000000..5ff80cd68ca9 --- /dev/null +++ b/tools/test/stress2/misc/ptrace5.sh @@ -0,0 +1,200 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# It seems to be possible for ptrace(PT_ATTACH) to race with the delivery +# of a signal to the same process. + +# "panic: Assertion TD_IS_SLEEPING(td) failed at subr_sleepqueue.c:958". +# https://people.freebsd.org/~pho/stress/log/ptrace5.txt +# https://people.freebsd.org/~pho/stress/log/ptrace5-2.txt +# Fixed by r303426. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/ptrace5.c +mycc -o ptrace5 -Wall -Wextra -O0 -g ptrace5.c -pthread || exit 1 +rm -f ptrace5.c +cd $odir + +/tmp/ptrace5 +s=$? + +rm -rf /tmp/ptrace5 +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static pid_t pid; +static pthread_barrier_t barr; +static int cont; + +#define PARALLEL 4 +#define RUNTIME (5 * 60) + +static void +ahandler(int i __unused) +{ + system("ps -Hl"); + fprintf(stderr, "SIGALRM pid %d\n", pid); + exit(1); +} + +static void +handler(int i __unused) +{ +} + +static void * +t1(void *data __unused) +{ + int status; + + while (cont == 1) { + if (ptrace(PT_ATTACH, pid, 0, 0) == -1) + err(1, "ptrace(%d)", pid); + + if (waitpid(pid, &status, 0) == -1) + err(1, "waitpid"); + else if (!WIFSTOPPED(status)) + errx(1, "failed to stop child"); + if (ptrace(PT_DETACH, pid, 0, 0) == -1) + err(1, "ptrace"); + usleep(arc4random() % 200); + } + + return (NULL); +} + +static void * +t2(void *data __unused) +{ + while (cont == 1) { + if (kill(pid, SIGHUP) == -1) + err(1, "kill"); + usleep(arc4random() % 200); + } + + return (NULL); +} + +static void +test(void) +{ + pthread_t tid[2]; + struct sigaction sa; + int r, status; + + r = pthread_barrier_wait(&barr); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + errc(1, r, "pthread_barrier_wait"); + + sa.sa_handler = ahandler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGALRM, &sa, NULL) == -1) + err(1, "sigaction"); + alarm(2 * RUNTIME); + sa.sa_handler = handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGHUP, &sa, NULL) == -1) + err(1, "sigaction"); + + if ((pid = fork()) == 0) { + for(;;) + usleep(20); + + _exit(0); + } + + cont = 1; + if ((r = pthread_create(&tid[0], NULL, t1, NULL)) == -1) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&tid[1], NULL, t2, NULL)) == -1) + errc(1, r, "pthread_create"); + + sleep(RUNTIME); + + cont = 0; + if ((r = pthread_join(tid[0], NULL)) == -1) + errc(1, r, "pthread_join"); + if ((r = pthread_join(tid[1], NULL)) == -1) + errc(1, r, "pthread_join"); + if (kill(pid, SIGKILL) != 0) + err(1, "kill(%d)", pid); + waitpid(pid, &status, 0); + + exit(0); +} + +int +main(void) +{ + pthread_barrierattr_t attr; + int e, i, pids[PARALLEL], r, status; + + if ((r = pthread_barrierattr_init(&attr)) != 0) + errc(1, r, "pthread_barrierattr_init"); + if ((r = pthread_barrierattr_setpshared(&attr, + PTHREAD_PROCESS_SHARED)) != 0) + errc(1, r, "pthread_barrierattr_setpshared"); + if ((r = pthread_barrier_init(&barr, &attr, PARALLEL)) != 0) + errc(1, r, "pthread_barrier_init"); + + e = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) { + waitpid(pids[i], &status, 0); + e += status == 0 ? 0 : 1; + } + + if ((r = pthread_barrier_destroy(&barr)) > 0) + errc(1, r, "pthread_barrier_destroy"); + + return (e); +} diff --git a/tools/test/stress2/misc/ptrace6.sh b/tools/test/stress2/misc/ptrace6.sh new file mode 100755 index 000000000000..872c1c0d202c --- /dev/null +++ b/tools/test/stress2/misc/ptrace6.sh @@ -0,0 +1,204 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# panic: Assertion TD_IS_SLEEPING(td) failed at subr_sleepqueue.c:958. +# Fixed by r303426. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/ptrace6.c +mycc -o ptrace6 -Wall -Wextra -O0 -g ptrace6.c -pthread || exit 1 +rm -f ptrace6.c +cd $odir + +/tmp/ptrace6 +s=$? + +while pgrep -q swap; do + pkill -9 swap +done +rm -rf /tmp/ptrace6 +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static pid_t pid; +static pthread_barrier_t barr; +static int cont; +static int state; + +#define PARALLEL 4 +#define RUNTIME (4 * 60) + +static void +ahandler(int i __unused) +{ + system("ps -Hl"); + fprintf(stderr, "SIGALRM state %d, pid %d\n", state, pid); + exit(1); +} + +static void +handler(int i __unused) +{ +} + +static void * +t1(void *data __unused) +{ + int status; + + while (cont == 1) { + state = 1; + if (ptrace(PT_ATTACH, pid, 0, 0) == -1) + err(1, "ptrace(%d)", pid); + + state = 2; + if (waitpid(pid, &status, 0) == -1) + err(1, "waitpid"); + else if (!WIFSTOPPED(status)) + errx(1, "failed to stop child"); + state = 3; + if (ptrace(PT_DETACH, pid, 0, 0) == -1) + err(1, "ptrace"); + state = 4; + usleep(arc4random() % 200); + } + + return (NULL); +} + +static void * +t2(void *data __unused) +{ + while (cont == 1) { + if (kill(pid, SIGHUP) == -1) + err(1, "kill"); + usleep(arc4random() % 200); + } + + return (NULL); +} + +static void +test(void) +{ + pthread_t tid[2]; + struct sigaction sa; + int r; + + r = pthread_barrier_wait(&barr); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + errc(1, r, "pthread_barrier_wait"); + + sa.sa_handler = ahandler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGALRM, &sa, NULL) == -1) + err(1, "sigaction"); + alarm(RUNTIME + 60); + + sa.sa_handler = handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGHUP, &sa, NULL) == -1) + err(1, "sigaction"); + + if ((pid = fork()) == 0) { + for(;;) + usleep(arc4random() % 1000); + + _exit(0); + } + + cont = 1; + if ((r = pthread_create(&tid[0], NULL, t1, NULL)) == -1) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&tid[1], NULL, t2, NULL)) == -1) + errc(1, r, "pthread_create"); + + sleep(RUNTIME); + + cont = 0; + if ((r = pthread_join(tid[0], NULL)) == -1) + errc(1, r, "pthread_join"); + if ((r = pthread_join(tid[1], NULL)) == -1) + errc(1, r, "pthread_join"); + if (kill(pid, SIGKILL) != 0) + err(1, "kill(%d)", pid); + waitpid(pid, NULL, 0); + + exit(0); +} + +int +main(void) +{ + pthread_barrierattr_t attr; + int e, i, pids[PARALLEL], r, status; + + if ((r = pthread_barrierattr_init(&attr)) != 0) + errc(1, r, "pthread_barrierattr_init"); + if ((r = pthread_barrierattr_setpshared(&attr, + PTHREAD_PROCESS_SHARED)) != 0) + errc(1, r, "pthread_barrierattr_setpshared"); + if ((r = pthread_barrier_init(&barr, &attr, PARALLEL)) != 0) + errc(1, r, "pthread_barrier_init"); + + e = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) { + waitpid(pids[i], &status, 0); + e += status == 0 ? 0 : 1; + } + + if ((r = pthread_barrier_destroy(&barr)) > 0) + errc(1, r, "pthread_barrier_destroy"); + + return (e); +} diff --git a/tools/test/stress2/misc/ptrace7.sh b/tools/test/stress2/misc/ptrace7.sh new file mode 100755 index 000000000000..c6c810b60d01 --- /dev/null +++ b/tools/test/stress2/misc/ptrace7.sh @@ -0,0 +1,238 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# It seems to be possible for ptrace(PT_ATTACH) to race with the delivery +# of a signal to the same process. + +# $ while ./pt.sh; do date; done +# 15. juli 2016 kl. 05.59.05 CEST +# 15. juli 2016 kl. 06.03.07 CEST +# UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND +# 1001 863 862 0 44 0 13880 5268 wait Is 0 0:00,13 -bash (bash) +# 1001 21053 863 0 52 0 13188 3088 wait I+ 0 0:00,01 /bin/sh ./pt.sh +# 1001 21096 21053 0 52 0 10544 2308 wait I+ 0 0:00,00 /tmp/pt +# 1001 21103 21096 0 20 0 12852 2456 wait S+ 0 0:00,00 pt: main (pt) +# 1001 21103 21096 0 35 0 12852 2456 wait I+ 0 0:55,30 pt: main (pt) +# 1001 21104 21096 0 72 0 0 0 - Z+ 0 0:00,00 +# 1001 21105 21096 0 72 0 0 0 - Z+ 0 0:00,00 +# 1001 21116 21103 0 103 0 10544 2336 - RX+ 0 4:22,41 pt: spinner (pt) +# 1001 37711 21103 0 20 0 21200 2960 - R+ 0 0:00,00 ps -Hl +# 1001 890 879 0 20 0 22184 6196 select Ss+ 1 1:21,86 top -s 1 +# 1001 85222 85221 0 21 0 13880 5276 ttyin Is+ 2 0:00,23 -bash (bash) +# SIGALRM state 2, pid 21116 +# $ + +# Fixed by r303423. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/ptrace7.c +mycc -o ptrace7 -Wall -Wextra -O0 -g ptrace7.c -pthread || exit 1 +rm -f ptrace7.c +cd $odir + +/tmp/ptrace7 +s=$? + +while pgrep -q swap; do + pkill -9 swap +done +rm -rf /tmp/ptrace7 +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#ifdef __FreeBSD__ +#include +#define __NP__ +#endif +#include +#include +#include +#include +#include + +static pid_t pid; +static pthread_barrier_t barr; +static int cont; +static int state; + +#define PARALLEL 8 +#define RUNTIME (4 * 60) + +static void +ahandler(int i __unused) +{ + system("ps -Hl"); + fprintf(stderr, "SIGALRM state %d, pid %d\n", state, pid); + exit(1); +} + +static void +handler(int i __unused) +{ +} + +static void * +t1(void *data __unused) +{ + int status; + +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + while (cont == 1) { + state = 1; + if (ptrace(PT_ATTACH, pid, 0, 0) == -1) + err(1, "ptrace(%d)", pid); + + state = 2; + if (waitpid(pid, &status, 0) == -1) + err(1, "waitpid"); + else if (!WIFSTOPPED(status)) + errx(1, "failed to stop child"); + state = 3; + if (ptrace(PT_DETACH, pid, 0, 0) == -1) + err(1, "ptrace"); + state = 4; + usleep(arc4random() % 100 + 50); + } + + return (NULL); +} + +static void * +t2(void *data __unused) +{ +#ifdef __NP__ + pthread_set_name_np(pthread_self(), __func__); +#endif + while (cont == 1) { + if (kill(pid, SIGHUP) == -1) + err(1, "kill"); + usleep(arc4random() % 100 + 50); + } + + return (NULL); +} + +static void +test(void) +{ + pthread_t tid[2]; + struct sigaction sa; + int r, status; + + r = pthread_barrier_wait(&barr); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + errc(1, r, "pthread_barrier_wait"); + + sa.sa_handler = ahandler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGALRM, &sa, NULL) == -1) + err(1, "sigaction"); + alarm(RUNTIME + 60); + + sa.sa_handler = handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGHUP, &sa, NULL) == -1) + err(1, "sigaction"); + + setproctitle("%s", "spinner"); + if ((pid = fork()) == 0) { + for(;;) + getuid(); + + _exit(0); + } + + cont = 1; + if ((r = pthread_create(&tid[0], NULL, t1, NULL)) == -1) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&tid[1], NULL, t2, NULL)) == -1) + errc(1, r, "pthread_create"); + + setproctitle("%s", "main"); + sleep(RUNTIME); + + cont = 0; + if ((r = pthread_join(tid[0], NULL)) == -1) + errc(1, r, "pthread_join"); + if ((r = pthread_join(tid[1], NULL)) == -1) + errc(1, r, "pthread_join"); + if (kill(pid, SIGKILL) != 0) + err(1, "kill(%d)", pid); + if (waitpid(pid, &status, 0) == -1) + err(1, "waitpid(%d)", pid); + + exit(0); +} + +int +main(void) +{ + pthread_barrierattr_t attr; + int e, i, pids[PARALLEL], r, status; + + if ((r = pthread_barrierattr_init(&attr)) != 0) + errc(1, r, "pthread_barrierattr_init"); + if ((r = pthread_barrierattr_setpshared(&attr, + PTHREAD_PROCESS_SHARED)) != 0) + errc(1, r, "pthread_barrierattr_setpshared"); + if ((r = pthread_barrier_init(&barr, &attr, PARALLEL)) != 0) + errc(1, r, "pthread_barrier_init"); + + e = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid%d)", pids[i]); + e += status == 0 ? 0 : 1; + } + + if ((r = pthread_barrier_destroy(&barr)) > 0) + errc(1, r, "pthread_barrier_destroy"); + + return (e); +} diff --git a/tools/test/stress2/misc/ptrace8.sh b/tools/test/stress2/misc/ptrace8.sh new file mode 100755 index 000000000000..2021c47905b4 --- /dev/null +++ b/tools/test/stress2/misc/ptrace8.sh @@ -0,0 +1,122 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# A regression test for r302919. +# Triggered a witness message: +# +# vmspace_free() called with the following non-sleepable locks held: +# shared rw vm object (vm object) r = 0 locked @ kern/sys_process.c:432 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/ptrace8.c +mycc -o ptrace8 -Wall -Wextra -O0 -g ptrace8.c || exit 1 +rm -f ptrace8.c +cd $odir + +/tmp/ptrace8 +s=$? + +rm -rf /tmp/ptrace8 +exit $s + +EOF +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +volatile u_int *share; + +#define SYNC 0 + +int +main(void) +{ + struct ptrace_vm_entry ent; + size_t len; + int pid, r, status; + char path[MAXPATHLEN + 1]; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + if ((pid = fork()) == 0) { + while (share[SYNC] == 0) + sleep(1); + + _exit(0); + } + + if (ptrace(PT_ATTACH, pid, 0, 0) == -1) + err(1, "ptrace"); + + if (waitpid(pid, &status, 0) == -1) + err(1, "waitpid"); + else if (!WIFSTOPPED(status)) + errx(1, "failed to stop child"); + + ent.pve_entry = 0; + ent.pve_path = path; + ent.pve_pathlen = sizeof(path); + do { + r = ptrace(PT_VM_ENTRY, pid, (caddr_t)&ent, 0); +#if defined(DEBUG) + if (r == 0) + fprintf(stderr, "path = %s 0x%lx - 0x%lx\n", + ent.pve_path, ent.pve_start, ent.pve_end); +#endif + } while (r == 0); + if (r == -1 && errno != ENOENT) + err(1, "ptrace(PT_VM_ENTRY)"); + + share[SYNC] = 1; + if (ptrace(PT_DETACH, pid, 0, 0) == -1) + err(1, "ptrace"); + + if (waitpid(pid, &status, 0) == -1) + err(1, "waitpid(%d)", pid); + + return (status != 0); +} diff --git a/tools/test/stress2/misc/ptrace9.sh b/tools/test/stress2/misc/ptrace9.sh new file mode 100755 index 000000000000..ac1329fd1a2a --- /dev/null +++ b/tools/test/stress2/misc/ptrace9.sh @@ -0,0 +1,133 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2016 Mark Johnston +# +# 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. +# + +# ptrace(2) test scenario by Mark Johnston +# https://people.freebsd.org/~markj/ptrace_stop.c +# Fixed by r303423. + +. ../default.cfg + +cd /tmp +cat > ptrace9.c < +#include +#include + +#include +#include +#include +#include + +static void +sigalrm(int sig __unused) +{ + _exit(0); +} + +static void +sighup(int sig __unused) +{ +} + +int +main(void) +{ + struct sigaction act; + pid_t pid; + int e, status; + + signal(SIGALRM, sigalrm); + e = 1; + pid = fork(); + if (pid < 0) + err(1, "fork"); + if (pid == 0) { + act.sa_handler = sighup; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + if (sigaction(SIGHUP, &act, NULL) != 0) + err(1, "sigaction"); + alarm(5); + while (1) { + sleep(1); + } + } else { + alarm(5); + sleep(1); /* give the child a chance to call sigaction */ + + if (kill(pid, SIGSTOP) != 0) + err(1, "kill(SIGSTOP)"); + + printf("waiting for child to stop...\n"); + if (waitpid(pid, &status, WUNTRACED) != pid) + err(1, "waitpid"); + if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP) + errx(1, "unexpected status %d after SIGSTOP", status); + + if (kill(pid, SIGHUP) != 0) + err(1, "kill(SIGHUP)"); + + if (ptrace(PT_ATTACH, pid, NULL, 0) != 0) + err(1, "ptrace(PT_ATTACH)"); + if (waitpid(pid, &status, WUNTRACED) != pid) + err(1, "waitpid"); + if (!WIFSTOPPED(status)) + errx(1, "unexpected status %d after PT_ATTACH", status); + printf("stopping signal is %d\n", WSTOPSIG(status)); + if (ptrace(PT_DETACH, pid, NULL, 0) != 0) + err(1, "ptrace(PT_DETACH)"); + + /* if ptrace works as expected, we'll block here */ + printf("waiting on child...\n"); fflush(stdout); + if (waitpid(pid, &status, WUNTRACED) != pid) + err(1, "waitpid"); + if (!WIFSTOPPED(status)) + errx(1, "unexpected status %d after PT_DETACH", status); + printf("child is stopped after detach (sig %d)\n", + WSTOPSIG(status)); fflush(stdout); + e = 1; + } + + return (e); +} +EOF + +mycc -o ptrace9 -Wall -Wextra -O2 -g ptrace9.c || exit 1 +rm ptrace9.c + +echo "Expect: + waiting for child to stop... + stopping signal is 17 + waiting on child..." +./ptrace9 +s=$? + +pkill -9 ptrace9 +rm -f ptrace9 +exit $s diff --git a/tools/test/stress2/misc/pts.sh b/tools/test/stress2/misc/pts.sh new file mode 100755 index 000000000000..f994c1f89bc6 --- /dev/null +++ b/tools/test/stress2/misc/pts.sh @@ -0,0 +1,154 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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. +# + +# Page fault in ttydev_open+0x2d seen. Fixed in r237219. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pts.c +mycc -o pts -Wall -Wextra -O2 pts.c -lutil || exit 1 +rm -f pts.c + +/tmp/pts & +pid=$! + +while kill -0 $! 2>/dev/null; do + $here/../testcases/swap/swap -t 2m -i 20 > /dev/null +done +wait $pid +status=$? + +rm -f /tmp/pts +exit $status +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 10 +#define RUNTIME 60 + +void +churn(char *path) +{ + FTS *fts; + FTSENT *p; + time_t start; + int fd, ftsoptions; + char *args[2]; + + ftsoptions = FTS_PHYSICAL; + args[0] = path; + args[1] = 0; + + setproctitle("churn"); + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + if (p->fts_info == FTS_D || + p->fts_info == FTS_DP) + continue; + if ((fd = open(p->fts_path, O_RDONLY)) > 0) + close(fd); + + } + + if (errno != 0 && errno != ENOENT) + err(1, "fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } + + _exit(0); +} + +void +pty(void) +{ + time_t start; + int master, slave; + char slname[1025]; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if (openpty(&master, &slave, slname, NULL, NULL) == -1) + err(1, "openpty"); + usleep(arc4random() % 10000); + if (close(master) == -1) + err(1, "close(master)"); + if (close(slave) == -1) + err(1, "close(%s)", slname); + } + _exit(0); +} + +int +main(void) +{ + int i, j, s, status; + + status = 0; + for (j = 0; j < LOOPS && status == 0; j++) { + for (i = 0; i < 2; i++) { + if (fork() == 0) + pty(); + } + for (i = 0; i < 2; i++) { + if (fork() == 0) + churn("/dev/pts"); + } + for (i = 0; i < 4; i++) { + wait(&s); + if (s != 0) + status = 1; + } + } + + return (status); +} diff --git a/tools/test/stress2/misc/pts2.sh b/tools/test/stress2/misc/pts2.sh new file mode 100755 index 000000000000..84f7bbd78255 --- /dev/null +++ b/tools/test/stress2/misc/pts2.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# pts leak seen. +# Fixed in r313496. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +kldstat -v | grep -q pty || { kldload pty || exit 0; } + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pts2.c +mycc -o pts2 -Wall -Wextra -O2 pts2.c || exit 1 +rm -f pts2.c + +pts=`vmstat -m | grep pts | awk '{print $2}'` +for i in `jot 10`; do + /tmp/pts2 +done +new=`vmstat -m | grep pts | awk '{print $2}'` +s=0 +[ $((new - pts)) -gt 1 ] && { s=1; echo "Leaked $((new - pts)) pts."; } + +rm -f /tmp/pts2 +exit $s +EOF +#include + +#include +#include +#include + +const char *master = "/dev/ptmx"; +int +main(void) +{ + int fd, fd2, slave; + char sl[80]; + + if ((fd = open(master, O_RDONLY)) == -1) + err(1, "open(%s)", master); + + if (ioctl(fd, TIOCGPTN, &slave) == -1) + err(1, "ioctl"); + + snprintf(sl, sizeof(sl), "/dev/pts/%d", slave); + + if ((fd2 = open(sl, O_RDONLY | O_EXLOCK)) == -1) + err(1, "open(%s)", sl); + + return (0); +} diff --git a/tools/test/stress2/misc/pts3.sh b/tools/test/stress2/misc/pts3.sh new file mode 100755 index 000000000000..b398e92916af --- /dev/null +++ b/tools/test/stress2/misc/pts3.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# "panic: Most recently used by tty" seen. +# Reported by syzbot+c9b6206303bf47bac87e@syzkaller.appspotmail.com +# Fixed by r349733 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +kldstat -v | grep -q pty || { kldload pty || exit 0; } + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pts3.c +mycc -o pts3 -Wall -Wextra -O2 pts3.c || exit 1 +rm -f pts3.c + +/tmp/pts3; s=$? + +rm -f /tmp/pts3 +exit $s +EOF +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; +#define SYNC 0 + +int +main(void) +{ + pid_t p, pid; + size_t len; + time_t start; + int fd; + char path[128]; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + p = getpid(); + sprintf(path, "/dev/ptmx"); + start = time(NULL); + while (time(NULL) - start < 60) { + share[SYNC] = 0; + if ((fd = open(path, O_RDWR)) == -1) + err(1,"open()"); + if ((pid = fork()) == 0) { + while (share[SYNC] == 0) + ; + _exit(0); + } + share[SYNC] = 1; + if (fcntl(fd, F_SETOWN, p) == -1) + warn("fcntl()"); + close(fd); + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid()"); + } + + return (0); +} diff --git a/tools/test/stress2/misc/pty.sh b/tools/test/stress2/misc/pty.sh new file mode 100755 index 000000000000..a2b8ecbcc574 --- /dev/null +++ b/tools/test/stress2/misc/pty.sh @@ -0,0 +1,161 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# pty(4) test scenario. + +# "panic: make_dev_credv: bad si_name (error=17, si_name=ptysn)" seen. +# https://people.freebsd.org/~pho/stress/log/pty.txt + +# /dev/pty[l-sL-S][0-9a-v] Pseudo-terminal master devices. +# /dev/tty[l-sL-S][0-9a-v] Pseudo-terminal slave devices. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q pty || { kldload pty || exit 0; } + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pty.c +mycc -o pty -Wall -Wextra -O2 pty.c || exit 1 +rm -f pty.c + +su $testuser -c /tmp/pty + +rm -f /tmp/pty +exit +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define RUNTIME 300 + +char path[80]; + +void +churn(char *path) +{ + + FTS *fts; + FTSENT *p; + time_t start; + int fd, ftsoptions; + char *args[2]; + + ftsoptions = FTS_PHYSICAL; + args[0] = path; + args[1] = 0; + + setproctitle("churn"); + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) + err(1, "fts_open"); + + while ((p = fts_read(fts)) != NULL) { + if (p->fts_info == FTS_D || + p->fts_info == FTS_DP) + continue; + if ((fd = open(p->fts_path, O_RDWR)) == -1) + if ((fd = open(p->fts_path, O_WRONLY)) == -1) + if ((fd = open(p->fts_path, O_RDONLY)) == -1) + continue; + usleep(arc4random() % 1000); + close(fd); + + } + + if (errno != 0 && errno != ENOENT) + err(1, "fts_read"); + if (fts_close(fts) == -1) + err(1, "fts_close()"); + } + + _exit(0); +} + +void +pty(void) +{ + int fd[512], i, j, n; + char c1, c2; + + n = 0; + c1 = 'l'; + for (i = 0; i < 16; i++) { + c2 = '0'; + for (j = 0; j < 32; j++) { + snprintf(path, sizeof(path), "/dev/pty%c%c", c1, c2); + fd[n++] = open(path, O_RDWR); + if (c2 == '9') + c2 = 'a'; + else + c2++; + } + if (c1 == 's') + c1 = 'L'; + else + c1++; + } + + for (i = 0; i < n; i++) + if (fd[i] != -1) + close(fd[i]); +} + +int +main(void) +{ + int i; + + time_t start; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + churn("/dev"); + + start = time(NULL); + while (time(NULL) - start < RUNTIME) + pty(); + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/pty2.sh b/tools/test/stress2/misc/pty2.sh new file mode 100755 index 000000000000..b7cf346c994f --- /dev/null +++ b/tools/test/stress2/misc/pty2.sh @@ -0,0 +1,101 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# pty(4) test scenario. + +# "panic: make_dev_sv: bad si_name (error=17, si_name=ptyp0)" seen. +# Fixed by r293825. + +# Based on test scenario by Bruce Evans. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +kldstat -v | grep -q pty || { kldload pty || exit 0; } + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > pty2.c +mycc -o pty2 -Wall -Wextra -O2 pty2.c || exit 1 +rm -f pty2.c + +/tmp/pty2 + +rm -f /tmp/pty2 +exit +EOF +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 3 +#define RUNTIME 180 + +#define IN "/dev/ptyp0" + +void +test(void) +{ + time_t start; + int fd; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if ((fd = open(IN, O_RDONLY)) == -1) { + if (errno != EBUSY && errno != ENXIO && errno != ENOENT) + err(1, "open(%s)", IN); + } else + close(fd); + + } + _exit(0); +} + +int +main(void) +{ + int i; + + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + test(); + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return(0); +} + diff --git a/tools/test/stress2/misc/quota1.sh b/tools/test/stress2/misc/quota1.sh new file mode 100755 index 000000000000..38e0fcd9c351 --- /dev/null +++ b/tools/test/stress2/misc/quota1.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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 -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". +# This is not really a quota test. + +. ../default.cfg + +D=$diskimage +trap "rm -f $D" 0 +dd if=/dev/zero of=$D bs=1m count=128 status=none || 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 $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd ..; ./run.sh disk.cfg) +while mount | grep -q $mntpoint; do + umount $mntpoint > /dev/null 2>&1 || sleep 1 +done +mdconfig -d -u $mdstart +rm -f $D +exit 0 diff --git a/tools/test/stress2/misc/quota10.sh b/tools/test/stress2/misc/quota10.sh new file mode 100755 index 000000000000..1452f68538cf --- /dev/null +++ b/tools/test/stress2/misc/quota10.sh @@ -0,0 +1,105 @@ +#!/bin/sh + +# +# Copyright (c) 2008, 2011 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. +# + +# Hunt for deadlock that could occur running umount and quota at the same time +# "panic: dqsync: file" seen: +# https://people.freebsd.org/~pho/stress/log/quota10.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +. ../default.cfg + +mounts=15 # Number of parallel scripts +mdstart=$mdstart # Use md unit numbers from this point +D=$diskimage +export PATH_FSTAB=/tmp/fstab + +if [ $# -eq 0 ]; then + rm -f $PATH_FSTAB + 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 + [ -c /dev/md$m ] && mdconfig -d -u $m + + dd if=/dev/zero of=$D$m bs=1m count=1 status=none + 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" \ + >> $PATH_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 + wait + + for i in `jot $mounts`; do + m=$((i + mdstart - 1)) + mdconfig -d -u $m + rm -f $D$m + done + rm -f $PATH_FSTAB +else + if [ $1 = find ]; then + while [ -r /tmp/$0 ]; do + ( + quotaon ${mntpoint}$2 + quotaoff ${mntpoint}$2 + ) 2>&1 | egrep -v "No such file or directory" + done + else + + # The test: Parallel mount and unmounts + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt 1200 ]; 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 + fi +fi +exit 0 diff --git a/tools/test/stress2/misc/quota11.sh b/tools/test/stress2/misc/quota11.sh new file mode 100755 index 000000000000..bf08f9e15db4 --- /dev/null +++ b/tools/test/stress2/misc/quota11.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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. +# + +# "panic: share->excl" seen. +# http://people.freebsd.org/~pho/stress/log/kostik715.txt +# Fixed in r270795 and r270797 + +# Test scenario by Hiroki Sato + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +. ../default.cfg + +mount | grep "on $mntpoint " | grep -q md${mdstart}$part && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +export PATH_FSTAB=/tmp/fstab +trap "rm -f $PATH_FSTAB" 0 +echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" > $PATH_FSTAB +mount $mntpoint +edquota -u -f $mntpoint -e $mntpoint:1000:2000:100:200 root +quotaon $mntpoint + +while true; do repquota -av > /dev/null; done & + +dd if=/dev/random of=$mntpoint/foo.data bs=512 count=1024x1024 2>&1 | + egrep -v "trans|record" +kill $! +wait + +n=0 +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 + n=$((n + 1)) + [ $n -gt 60 ] && exit 1 +done +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/quota12.sh b/tools/test/stress2/misc/quota12.sh new file mode 100755 index 000000000000..78a5e0c0cd81 --- /dev/null +++ b/tools/test/stress2/misc/quota12.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Run marcus.cfg on a quota enabled FS + +# "Inability to allocate buffers" seen with WiP kernel code: +# https://people.freebsd.org/~pho/stress/log/kostik1218.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +. ../default.cfg + +mount | grep "on $mntpoint " | grep -q md${mdstart}$part && umount $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +export PATH_FSTAB=/tmp/fstab +trap "rm -f $PATH_FSTAB" 0 +echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" > $PATH_FSTAB +mount $mntpoint +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$1 +export INODES=$2 +s=0 + +export QK=$((KBLOCKS / 1)) +export QI=$((INODES / 1)) +edquota -u -f $mntpoint -e \ + ${mntpoint}:$((QK - 50)):$QK:$((QI - 50 )):$QI $testuser > \ + /dev/null 2>&1 +quotaon $mntpoint + +chmod 777 $mntpoint +export runRUNTIME=15m +export RUNDIR=$mntpoint/stressX +su $testuser -c 'cd ..; ./run.sh marcus.cfg > /dev/null 2>&1' + +while ! quotaoff $mntpoint; do + sync + sleep 1 +done +quotacheck $mntpoint + +n=0 +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 + n=$((n + 1)) + [ $n -gt 60 ] && exit 1 +done +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/quota2.sh b/tools/test/stress2/misc/quota2.sh new file mode 100755 index 000000000000..9deb97726d60 --- /dev/null +++ b/tools/test/stress2/misc/quota2.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +. ../default.cfg + +D=$diskimage +export PATH_FSTAB=/tmp/fstab +trap "rm -f $D $PATH_FSTAB" 0 +dd if=/dev/zero of=$D bs=1m count=128 status=none || exit 1 + +mount | grep "$mntpoint" | grep md${mdstart}$part > /dev/null && umount $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 $newfs_flags md${mdstart}$part > /dev/null +echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" > $PATH_FSTAB +mount $mntpoint +edquota -u -f $mntpoint -e $mntpoint:100000:110000:15000:16000 root +quotacheck $mntpoint +quotaon $mntpoint +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd ..; ./run.sh disk.cfg) 2>/dev/null +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +exit 0 diff --git a/tools/test/stress2/misc/quota3.sh b/tools/test/stress2/misc/quota3.sh new file mode 100755 index 000000000000..de4c60ec2810 --- /dev/null +++ b/tools/test/stress2/misc/quota3.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +. ../default.cfg + +D=$diskimage +export PATH_FSTAB=/tmp/fstab +trap "rm -f $D $PATH_FSTAB" 0 +dd if=/dev/zero of=$D bs=1m count=1k status=none || exit 1 + +mount | grep "$mntpoint" | grep -q md${mdstart}$part && 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 $newfs_flags md${mdstart}$part > /dev/null +echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" > $PATH_FSTAB +mount $mntpoint +edquota -u -f $mntpoint -e $mntpoint:850000:900000:130000:140000 root +quotacheck $mntpoint +quotaon $mntpoint +mksnap_ffs $mntpoint $mntpoint/.snap/stress2 +export RUNDIR=$mntpoint/stressX +export runRUNTIME=10m # Run tests for 10 minutes +(cd ..; ./run.sh disk.cfg) +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/quota4.sh b/tools/test/stress2/misc/quota4.sh new file mode 100755 index 000000000000..3eeae263cac2 --- /dev/null +++ b/tools/test/stress2/misc/quota4.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. +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +# Has shown a deadlock after 7 hours of testing +# https://people.freebsd.org/~pho/stress/log/quota4.txt + +. ../default.cfg + +D=$diskimage +trap "rm -f $D" 0 +dd if=/dev/zero of=$D bs=1m count=1k status=none || 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 $newfs_flags 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 2>/dev/null & +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 +exit 0 diff --git a/tools/test/stress2/misc/quota5.sh b/tools/test/stress2/misc/quota5.sh new file mode 100755 index 000000000000..050ea4a822d9 --- /dev/null +++ b/tools/test/stress2/misc/quota5.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# +# Copyright (c) 2008-2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +mount | grep -q "on /tmp (ufs," || exit 0 +if ! grep /tmp /etc/fstab | grep -q quota ; then + echo "Note: /tmp must have quota enabled for this test." + exit 0 +fi +edquota -u -f /tmp -e /tmp:1500000:1400000:200000:180000 $testuser +edquota -g -f /tmp -e /tmp:1500000:1400000:200000:180000 $testuser +quotaon /tmp + +su $testuser -c "export runRUNTIME=60m; cd ../testcases/mkdir; \ + ./mkdir -t 30m -i 200 -v -v" + +quotaoff /tmp diff --git a/tools/test/stress2/misc/quota6.sh b/tools/test/stress2/misc/quota6.sh new file mode 100755 index 000000000000..9cb3f5187f65 --- /dev/null +++ b/tools/test/stress2/misc/quota6.sh @@ -0,0 +1,69 @@ +#!/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. +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +. ../default.cfg + +# Deadlock in umount(1) while out of disk space + +D=$diskimage +truncate -s 250M $D + +mount | grep $mntpoint | grep -q md${mdstart}$part && umount $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 $newfs_flags md${mdstart}$part > /dev/null +export PATH_FSTAB=/tmp/fstab +echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" > \ + $PATH_FSTAB +mount $mntpoint +edquota -u -f $mntpoint -e $mntpoint:850000:900000:130000:140000 root > \ + /dev/null 2>&1 +quotaon $mntpoint +export RUNDIR=$mntpoint/stressX +timeout 12m ../testcases/rw/rw -t 10m -i 200 -h -n & +pid=$! +for i in `jot 5`; do + echo "`date '+%T'` mksnap_ffs $mntpoint $mntpoint/.snap/snap$i" + mksnap_ffs $mntpoint $mntpoint/.snap/snap$i +done +for i in `jot 5`; do + rm -f $mntpoint/.snap/snap1 +done +kill $pid +wait +while mount | grep -q $mntpoint; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f $D $PATH_FSTAB +exit 0 diff --git a/tools/test/stress2/misc/quota7.sh b/tools/test/stress2/misc/quota7.sh new file mode 100755 index 000000000000..f098fceb0939 --- /dev/null +++ b/tools/test/stress2/misc/quota7.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. +# + +# 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 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +. ../default.cfg + +D=$diskimage +trap "rm -f $D" 0 +dd if=/dev/zero of=$D bs=1m count=1k status=none + +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 $newfs_flags md${mdstart}$part > /dev/null +export PATH_FSTAB=/tmp/fstab +echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" > $PATH_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 +export RUNDIR=$mntpoint/stressX +mkdir $mntpoint/stressX +chmod 777 $mntpoint/stressX +rm -rf /tmp/stressX.control/* +su $testuser -c "(cd ..;runRUNTIME=20m ./run.sh disk.cfg)"& # panic: vfs_allocate_syncvnode: insmntque failed +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 $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f $D $PATH_FSTAB diff --git a/tools/test/stress2/misc/quota8.sh b/tools/test/stress2/misc/quota8.sh new file mode 100755 index 000000000000..a11418aba5d9 --- /dev/null +++ b/tools/test/stress2/misc/quota8.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. +# + +# Quota / snapshot test scenario by Kris@ +# Causes spin in ffs_sync or panic in panic: vfs_allocate_syncvnode: +# insmntque failed + +# "Fatal double fault" seen when compiling selected files +# with "-O0" on i386: +# https://people.freebsd.org/~pho/stress/log/quota8.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +. ../default.cfg + +D=$diskimage +trap "rm -f $D" 0 +dd if=/dev/zero of=$D bs=1m count=1k status=none || exit 1 + +mount | grep "$mntpoint" | grep -q md$mdstart && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t vnode -f $D -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags 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 > \ + /dev/null 2>&1)"&' +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 +# Remove random snapshot file +i=$((`date +%S` % 20 + 1)) +echo "rm -f $mntpoint/.snap/snap$i" +rm -f $mntpoint/.snap/snap$i +wait + +su $testuser -c 'sh -c "../tools/killall.sh"' +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 +exit 0 diff --git a/tools/test/stress2/misc/quota9.sh b/tools/test/stress2/misc/quota9.sh new file mode 100755 index 000000000000..01681bce8a01 --- /dev/null +++ b/tools/test/stress2/misc/quota9.sh @@ -0,0 +1,93 @@ +#!/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. +# + +# Test if quotacheck reports actual usage. + +. ../default.cfg + +export tmp=/tmp/$(basename $0).$$ +export D=$diskimage + +qc() { + local s + umount $1 + s=0 + quotacheck -v $1 > $tmp 2>&1 + grep -q fixed $tmp && { cat $tmp; s=1; } + mount $1 + return $s +} + +trap "rm -f $D $tmp" 0 +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0 + +dd if=/dev/zero of=$D bs=1m count=50 status=none || exit 1 + +mount | grep "$mntpoint" | grep -q md$mdstart && + umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t vnode -f $D -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +export PATH_FSTAB=/tmp/fstab +echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" \ + > $PATH_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 + +qc $mntpoint + +su $testuser -c ' + for i in `jot 20`; do + dd if=/dev/zero of=$mntpoint/stressX/d$i bs=1m count=1 \ + status=none + done + ' + +qc $mntpoint; s=$? + +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 $PATH_FSTAB +exit $s diff --git a/tools/test/stress2/misc/r335171.sh b/tools/test/stress2/misc/r335171.sh new file mode 100755 index 000000000000..2d2e9ad72fee --- /dev/null +++ b/tools/test/stress2/misc/r335171.sh @@ -0,0 +1,158 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2018 Dell EMC Isilon +# +# 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. +# + +# Handle the race between fork/vm_object_split() and faults. +# +# If fault started before vmspace_fork() locked the map, and then during +# fork, vm_map_copy_entry()->vm_object_split() is executed, it is +# possible that the fault instantiate the page into the original object +# when the page was already copied into the new object (see +# vm_map_split() for the orig/new objects terminology). This can happen +# if split found a busy page (e.g. from the fault) and slept dropping +# the objects lock, which allows the swap pager to instantiate +# read-behind pages for the fault. Then the restart of the scan can see +# a page in the scanned range, where it was already copied to the upper +# object. + +# No problems seen. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/template.c +mycc -o template -Wall -Wextra -O0 -g template.c || exit 1 +rm -f template.c +export MAXSWAPPCT=101 +(cd $odir/../testcases/swap; ./swap -t 5m -i 30 -l 100 -h) > /dev/null & +$dir/template > /dev/null +s=$? +[ -f template.core -a $s -eq 0 ] && + { ls -l template.core; mv template.core $dir; s=1; } +wait + +rm -rf $dir/template +exit $s +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; +static volatile char *cp; + +#define PARALLEL 16 +#define RUNTIME (5 * 60) +#define SYNC 0 + +static void +test(void) +{ + size_t len; + pid_t pid; + int i; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + usleep(200); + len = 1280 * PAGE_SIZE; + if ((cp = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + for (i = 0; i < (int)(len / sizeof(char)); i += PAGE_SIZE) + cp[i] = 1; + usleep(arc4random() % 500000); + if ((pid = fork()) == 0) { + usleep(arc4random() % 1000); + for (i = 0; i < (int)(len); i += PAGE_SIZE) + cp[i] = 2; + fprintf(stdout, ".\n"); fflush(stdout); + _exit(0); + } + if (pid == -1) + err(1, "fork()"); + for (i = 0; i < (int)(len / sizeof(char)); i += PAGE_SIZE) + cp[i] = 3; + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid(%d)", pid); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/racct.sh b/tools/test/stress2/misc/racct.sh new file mode 100755 index 000000000000..8249d7acf388 --- /dev/null +++ b/tools/test/stress2/misc/racct.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Dell EMC Isilon +# 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. +# + +# Regression test inspired by Andriy Gapon for Bug 222027 - panic on +# non-zero RACCT destroy. + +# "panic: destroying non-empty racct ..." seen. +# https://people.freebsd.org/~pho/stress/log/racct.txt +# "Page fault in slab_free_item()" seen: +# https://people.freebsd.org/~pho/stress/log/racct-2.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +[ "`sysctl -in kern.racct.enable`" != "1" ] && + echo "Note: kern.racct.enable is disabled" +pgrep -Sq accounting || { service accounting onestart && started=1; } +(cd ../testcases/swap; ./swap -t 2m -i 5 -v -l 100) > /dev/null & +sleep .5 +start=`date +%s` +while [ $((`date +%s` - start)) -lt 120 ]; do + pids="" + for i in `jot 5`; do + for i in `jot 500`; do + exec su -c xuser -m root -c ':' & + done & + pids="$pids $!" + done + wait $pids + while [ `pgrep su | wc -l` -gt 100 ]; do sleep 1; done +done +wait +[ $started ] && service accounting onestop +exit 0 diff --git a/tools/test/stress2/misc/radix.sh b/tools/test/stress2/misc/radix.sh new file mode 100755 index 000000000000..4bca761c08b9 --- /dev/null +++ b/tools/test/stress2/misc/radix.sh @@ -0,0 +1,271 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# Consume VM radix nodes + +# "panic: default pager with handle" seen with WiP kernel code. +# https://people.freebsd.org/~pho/stress/log/kostik1243.txt + +[ `sysctl vm.swap_total | sed 's/.* //'` -eq 0 ] && exit 0 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/radix.c +mycc -o radix -Wall -Wextra radix.c || exit 1 +rm -f radix.c +cd $odir + +set -e +parallel=1 +usermem=`sysctl hw.usermem | sed 's/.* //'` +pagesize=`pagesize` +start=`date +%s` +while true; do + /tmp/radix $parallel > /tmp/radix.log 2>&1 + used=`awk '{print $4}' < /tmp/radix.log` + [ -z "$used" ] && break + [ $((`date +%s` - start)) -gt 300 ] && break + [ $used -gt $((usermem / pagesize)) ] && break + [ $parallel -eq 1 ] && + parallel=$((usermem / pagesize / used)) + parallel=$((parallel + 1)) + echo "`date +%T` parallel=$parallel" # XXX +done +cat /tmp/radix.log + +rm -f /tmp/radix #/tmp/radix.log +exit + +EOF +/* + On Wed, 17 Apr 2013 18:57:00 -0500 alc wrote: + + Suppose that I write a program for i386 that creates giant VM objects, + perhaps, using shm_open() + ftruncate(), and touches pages 0, 1, 8, 9, + 64, 65, 72, 73, 512, 513, 520, 521, 576, 577, 584, 585, 4096, 4097, + 4104, 4105, ... in each of the VM objects. (The sequence would be + different on amd64.) I could work around the 32-bit address space + limitation by mmap(2)ing and munmap(2)ing windows onto a VM object. + Each of the VM objects would have only one less interior node in the + radix tree than pages. If I create enough of these VM objects, then I + can consume all of the available pages and an almost equal number of + interior nodes. (Maybe it's worth writing this program so that some + experiments could be done?) +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __LP64__ +#define WIDTH 4 +#else +#define WIDTH 3 +#endif +#define N (int)howmany(sizeof(uint64_t) * NBBY, WIDTH) + +typedef uint64_t state_t[N]; + +static uint64_t pgs; +static int fds[2]; +static int parallel; +static volatile sig_atomic_t s1; +static int ps; + +static void +init(state_t state) +{ + int i; + + for (i = 0; i < N; i++) + state[i] = 0; +} + +static uint64_t +generator(state_t state) +{ + uint64_t value; + int i; + + value = 0; + for (i = 0; i < N; i++) + value += state[i] << (i * WIDTH); + for (i = 0; i < N; i++) + if (state[i] == 0) + break; + if (i < N) + state[i]++; + for (i--; i >= 0; i--) + state[i]--; + return (value); +} + +static int +wr(int fd, off_t pno) +{ + off_t len, offset; + void *p; + + offset = pno * ps; + len = ps; + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NOSYNC, + fd, offset); + if (p == MAP_FAILED) { + if (errno == ENOMEM) + return (1); + err(1, "mmap(len 0x%jx, offset 0x%jx). %s:%d", len, offset, + __FILE__, __LINE__); + } + *(char *)p = 1; + pgs++; + + return (0); +} + +static void +handler(int s __unused) +{ + s1++; +} + +static void +ihandler(int s __unused) +{ + _exit(0); +} + +static int +radix(void) +{ + FILE *f; + int r; + + if ((f = popen("vmstat -z | grep RADIX | awk -F',' '{print $3}'", "r")) == NULL) + err(1, "popen"); + fscanf(f, "%d", &r); + pclose(f); + + return (r); +} + +static void +test(void) +{ + state_t state; + off_t offset; + int fd; + + signal(SIGHUP, ihandler); + for (;;) { + if (access("rendezvous", R_OK) == 0) + break; + usleep(2000); + } + + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1, "open()"); + + init(state); + offset = generator(state); + do { + if (wr(fd, offset) != 0) + break; + offset = generator(state); + } while (offset != 0); + + if (write(fds[1], &pgs, sizeof(pgs)) != sizeof(pgs)) + err(1, "ewrite pipe"); + kill(getppid(), SIGHUP); + for (;;) + sleep(1); + close(fd); + + _exit(0); +} + +int +main(int argc, char **argv) +{ + uint64_t pages; + pid_t *pids; + int i, r1, r2, rfd; + + if (argc != 2) + errx(1, "Usage: %s .", argv[0]); + parallel = atoi(argv[1]); + + ps = getpagesize(); + signal(SIGHUP, handler); + unlink("rendezvous"); + pids = malloc(parallel * sizeof(pid_t)); + if (pipe(fds) == -1) + err(1, "pipe"); + r1 = radix(); + for (i = 0; i < parallel; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + if ((rfd = open("rendezvous", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(rfd); + alarm(60); + while (s1 != parallel) + usleep(10000); + alarm(0); + r2 = radix(); + pages = 0; + for (i = 0; i < parallel; i++) { + kill(pids[i], SIGHUP); + if (read(fds[0], &pgs, sizeof(pgs)) != sizeof(pgs)) + err(1, "read pipe"); + pages += pgs; + } + fprintf(stderr, "A total of %jd pages (%.1f MB) touched, %d" + " RADIX nodes used, p/r = %.1f, parallel = %d.\n", + pages, pages * ps / 1024. / 1024, r2 - r1, + pages / (r2 - r1 + 0.), parallel); + + for (i = 0; i < parallel; i++) { + wait(NULL); + } + unlink("rendezvous"); + return (0); +} diff --git a/tools/test/stress2/misc/random.sh b/tools/test/stress2/misc/random.sh new file mode 100755 index 000000000000..04a0075d0c2c --- /dev/null +++ b/tools/test/stress2/misc/random.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# A regression test for short AES mode reads +# https://people.freebsd.org/~pho/stress/log/fsck-2.txt +# Fixed by r349176 + +for i in `jot 1024 1`; do + dd if=/dev/random of=/dev/null bs=$i count=1 status=none +done +exit 0 diff --git a/tools/test/stress2/misc/rdgsbase.sh b/tools/test/stress2/misc/rdgsbase.sh new file mode 100755 index 000000000000..66a44592d419 --- /dev/null +++ b/tools/test/stress2/misc/rdgsbase.sh @@ -0,0 +1,182 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2017 Konstantin Belousov +# +# 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 scenario for "D12023: Make WRFSBASE and WRGSBASE functional." + +[ `uname -m` = "amd64" ] || exit 0 + +. ../default.cfg + +cat > /tmp/rdgsbase.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void +hand(int i __unused) { /* handler */ + _exit(0); +} + +static void * +rungs(void *arg __unused) +{ + volatile char x[1024]; + unsigned i; + uint64_t y, oldbase; + + oldbase = rdgsbase(); + for (i = 0;;) { + wrgsbase((uintptr_t)&x[i]); + if (rdgsbase() != (uintptr_t)&x[i]) { + wrgsbase(oldbase); + printf("bug1 %lx %lx\n", rdgsbase(), (uintptr_t)&x[i]); + exit(1); + } + sysarch(AMD64_GET_GSBASE, &y); + if (y != (uintptr_t)&x[i]) { + wrgsbase(oldbase); + printf("bug2 %lx %lx\n", y, (uintptr_t)&x[i]); + exit(1); + } + i++; + if (i >= nitems(x)) + i = 0; + } + return (NULL); +} + +static void * +runfs(void *arg __unused) +{ + volatile char x[1024]; + unsigned i; + uint64_t y, oldbase; + + oldbase = rdfsbase(); + for (i = 0;;) { + wrfsbase((uintptr_t)&x[i]); + if (rdfsbase() != (uintptr_t)&x[i]) { + wrfsbase(oldbase); + printf("bug3 %lx %lx\n", rdfsbase(), (uintptr_t)&x[i]); + exit(1); + } + sysarch(AMD64_GET_FSBASE, &y); + if (y != (uintptr_t)&x[i]) { + wrfsbase(oldbase); + printf("bug4 %lx %lx\n", y, (uintptr_t)&x[i]); + exit(1); + } + i++; + if (i > nitems(x)) + i = 0; + } + return (NULL); +} + +static void +start(int nthreads) +{ + pthread_t thrs[nthreads * 2]; + int error, i; + + for (i = 0; i < nthreads; i++) { + error = pthread_create(&thrs[i], NULL, rungs, NULL); + if (error != 0) + errc(1, error, "pthread_create"); + } + for (; i < 2 * nthreads; i++) { + error = pthread_create(&thrs[i], NULL, runfs, NULL); + if (error != 0) + errc(1, error, "pthread_create"); + } +} + +int +main(void) +{ + static const int mib[2] = {CTL_HW, HW_NCPU}; + int error, nthreads; + u_int p[4]; + size_t len; + + do_cpuid(0, p); + if (p[0] < 0x7) { + fprintf(stderr, "CPU does not support extended functions\n"); + return (1); + } + cpuid_count(0x7, 0x0, p); + if ((p[1] & CPUID_STDEXT_FSGSBASE) == 0) { + fprintf(stderr, "CPU does not support RDGSBASE\n"); + return (0); + } + + len = sizeof(nthreads); + error = sysctl(mib, nitems(mib), &nthreads, &len, NULL, 0); + if (error == -1) + err(1, "sysctl hw.ncpu"); + signal(SIGALRM, hand); + alarm(10); + start(nthreads); + for (;;) + pause(); +} +EOF + +mycc -o /tmp/rdgsbase /tmp/rdgsbase.c -lpthread || exit 1 +rm /tmp/rdgsbase.c + +(cd /tmp; /tmp/rdgsbase) +s=$? + +rm -f /tmp/rdgsbase /tmp/rdgsbase.core +exit $s diff --git a/tools/test/stress2/misc/rdwr.sh b/tools/test/stress2/misc/rdwr.sh new file mode 100755 index 000000000000..c77c955dc210 --- /dev/null +++ b/tools/test/stress2/misc/rdwr.sh @@ -0,0 +1,118 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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 with read/write length of INT_MAX (i386) or INT_MAX+1 (amd64) + +. ../default.cfg + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > rdwr.c +mycc -o rdwr -Wall rdwr.c || exit +rm -f rdwr.c + +oldclamp=`sysctl debug.devfs_iosize_max_clamp 2>/dev/null | + awk '{print $NF}'` +if [ `uname -m` = amd64 ]; then + [ "$oldclamp" = "1" ] && sysctl debug.devfs_iosize_max_clamp=0 +fi +for j in `jot 10`; do + /tmp/rdwr || { echo FAIL; break; } +done +if [ `uname -m` = amd64 ]; then + [ "$oldclamp" = "1" ] && sysctl debug.devfs_iosize_max_clamp=1 +fi + +rm -f /tmp/rdwr +exit +EOF +#include +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + int fd1, fd2; + size_t len; + void *p; + struct iovec iov; + + alarm(120); + if ((fd1 = open("/dev/null", O_RDWR, 0)) == -1) + err(1, "open /dev/null"); + + if ((fd2 = open("/dev/zero", O_RDWR)) == -1) + err(1, "open /dev/zero"); + + if (sizeof(size_t) == sizeof(int32_t)) + len = (size_t)INT_MAX; /* i386 */ + else + len = (size_t)INT_MAX + 1; /* amd64 */ + + if ((p = mmap(0, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd2, 0)) == + MAP_FAILED) + err(1, "mmap"); + + if (read(fd2, p, len) != len) + err(1, "read"); + + if (write(fd1, p, len) != len) + err(1, "write"); + + if (pread(fd2, p, len, 0) != len) + err(1, "pread"); + + if (pwrite(fd1, p, len, 0) != len) + err(1, "pwrite"); + + iov.iov_base = p; + iov.iov_len = len; + if (readv(fd2, &iov, 1) != len) + err(1, "readv"); + + if (writev(fd1, &iov, 1) != len) + err(1, "writev"); + + if (preadv(fd2, &iov, 1, 0) != len) + err(1, "preadv"); + + if (pwritev(fd1, &iov, 1, 0) != len) + err(1, "pwritev"); + + close(fd1); + close(fd2); + + return (0); +} diff --git a/tools/test/stress2/misc/readdir.sh b/tools/test/stress2/misc/readdir.sh new file mode 100755 index 000000000000..16523982d859 --- /dev/null +++ b/tools/test/stress2/misc/readdir.sh @@ -0,0 +1,179 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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. +# + +# readdir(3) fuzzing inspired by the iknowthis test suite +# by Tavis Ormandy + +# "panic: kmem_malloc(1328054272): kmem_map too small" seen + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > readdir.c +mycc -o readdir -Wall -Wextra readdir.c || exit 1 +rm -f readdir.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mount -t tmpfs tmpfs $mntpoint +echo "Testing tmpfs(5)" +cp -a /usr/include $mntpoint +/tmp/readdir $mntpoint +umount $mntpoint + +echo "Testing fdescfs(5)" +kldstat -v | grep -q fdescfs || { kldload fdescfs.ko; loaded=1; } +mount -t fdescfs null /dev/fd +/tmp/readdir /dev/fd +umount /dev/fd +[ $unload ] && kldunload fdescfs.ko + +echo "Testing procfs(5)" +mount -t procfs procfs $mntpoint +/tmp/readdir $mntpoint +umount $mntpoint + +if ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1; then + echo "Testing nfs" + mount -t nfs -o nfsv3,tcp,nolockd,retrycnt=3,soft,timeout=1 \ + $nfs_export $mntpoint + /tmp/readdir $mntpoint + umount $mntpoint +fi + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +cp -a /usr/include $mntpoint +echo "Testing UFS" +/tmp/readdir $mntpoint +umount $mntpoint +mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +cp -a /usr/include $mntpoint +echo "Testing FFS" +/tmp/readdir $mntpoint +umount $mntpoint +mdconfig -d -u $mdstart + +mount -t nullfs /bin $mntpoint +echo "Testing nullfs(5)" +/tmp/readdir $mntpoint +umount $mntpoint + +rm -f /tmp/readdir +exit 0 +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RUNTIME 120 + +/* copy from /usr/src/lib/libc/gen/gen-private.h */ +struct _telldir; /* see telldir.h */ +struct pthread_mutex; + +/* + * Structure describing an open directory. + * + * NOTE. Change structure layout with care, at least dd_fd field has to + * remain unchanged to guarantee backward compatibility. + */ +struct _dirdesc { + int dd_fd; /* file descriptor associated with directory */ + long dd_loc; /* offset in current buffer */ + long dd_size; /* amount of data returned by getdirentries */ + char *dd_buf; /* data buffer */ + int dd_len; /* size of data buffer */ + long dd_seek; /* magic cookie returned by getdirentries */ + long dd_rewind; /* magic cookie for rewinding */ + int dd_flags; /* flags for readdir */ + struct pthread_mutex *dd_lock; /* lock */ + struct _telldir *dd_td; /* telldir position recording */ +}; +/* End copy */ + +static void +hand(int i __unused) { /* handler */ + _exit(1); +} + +static void +test(char *path) +{ + DIR *dirp, fuzz; + int i; + + signal(SIGSEGV, hand); + alarm(300); + for (i = 0; i < 2000; i++) { + if ((dirp = opendir(path)) == NULL) + break; + bcopy(dirp, &fuzz, sizeof(fuzz)); + fuzz.dd_len = arc4random(); + readdir(&fuzz); + closedir(dirp); + } + + _exit(0); +} + +int +main(int argc __unused, char **argv) +{ + time_t start; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if (fork() == 0) + test(argv[1]); + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/recursiveflushes.sh b/tools/test/stress2/misc/recursiveflushes.sh new file mode 100755 index 000000000000..1da843a2f1d1 --- /dev/null +++ b/tools/test/stress2/misc/recursiveflushes.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. +# + +# Test recursive flushes in bdwrite(). + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +snap() { + for i in `jot 5`; do + mksnap_ffs $1 $2 + [ $? -eq 0 ] && break + done +} + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 4g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +old=`sysctl vfs.recursiveflushes | awk '{print $NF}'` +cd $mntpoint +rm -f $mntpoint/.snap/stress2.* +snap $mntpoint $mntpoint/.snap/stress2.1 +snap $mntpoint $mntpoint/.snap/stress2.2 +snap $mntpoint $mntpoint/.snap/stress2.3 +snap $mntpoint $mntpoint/.snap/stress2.4 +snap $mntpoint $mntpoint/.snap/stress2.5 + +for i in `jot 32`; do + # Create 32 Mb files + dd if=/dev/zero of=big.$i bs=16k count=2048 status=none +done +wait +for i in `jot 32`; do + rm -f big.$i +done + +rm -f $mntpoint/.snap/stress2.* +new=`sysctl vfs.recursiveflushes | awk '{print $NF}'` +[ $old != $new ] && echo "vfs.recursiveflushes changed from $old to $new" + +cd / +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/rename.sh b/tools/test/stress2/misc/rename.sh new file mode 100755 index 000000000000..93a1c9338ae4 --- /dev/null +++ b/tools/test/stress2/misc/rename.sh @@ -0,0 +1,130 @@ +#!/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 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 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename.c +mycc -o rename -Wall rename.c || exit 1 +rm -f rename.c + +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.* /tmp/rename +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RUNTIME 30 + +static char dir1[128]; +static char dir2[128]; + +int +main(int argc, char **argv) +{ + time_t start; + int status; + struct stat sb; + pid_t p; + + sprintf(dir1, "rename.dir.%d", getpid()); + sprintf(dir2, "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) { + setproctitle("child"); + if (chdir("..") == -1) + err(1, "chdir(%s)", ".."); + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + 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 { + setproctitle("parent"); + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if (stat("..", &sb) == -1) + err(1, "stat(..)"); + } + } + if (waitpid(p, &status, 0) == -1) + err(1, "waitpid()"); + if (chdir("..") == -1) + err(1, "chdir(%s)", ".."); + if (rmdir(dir1) == -1) + err(1, "rmdir(%s)", dir1); + + return (0); +} diff --git a/tools/test/stress2/misc/rename10.sh b/tools/test/stress2/misc/rename10.sh new file mode 100755 index 000000000000..5cbf39f3d3d2 --- /dev/null +++ b/tools/test/stress2/misc/rename10.sh @@ -0,0 +1,184 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Regression test for rename(2) problem with missing reference release of +# a busy "to" vnode, resulting in a leak. +# Fixed in r253998. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename10.c +mycc -o rename10 -Wall -Wextra -g -O2 rename10.c || exit 1 +rm -f rename10.c +cd $here + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 4g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +avail=`df -k $mntpoint | tail -1 | awk '{print $4}'` + +cd $mntpoint +/tmp/rename10; s=$? +cd $here + +for i in `jot 3`; do + sync + sleep 2 +done + +if [ `df -k $mntpoint | tail -1 | awk '{print $4}'` -lt $avail ]; then + echo FAIL + ls -ial $mntpoint + df -i $mntpoint +fi + +n=0 +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 + n=$((n + 1)) + [ $n -gt 5 ] && { umount -f $mntpoint; break; } +done + +checkfs /dev/md${mdstart}$part || s=$? +rm -f /tmp/rename10 +mdconfig -d -u $mdstart +exit $s +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define SIZE (1 * 1024 * 1024) + +static char *logfile = "logfile"; +static char *oldfiles[] = { + "logfile.0", "logfile.1", "logfile.2", "logfile.3", "logfile.4" +}; + +void * +logger(void) +{ + int fd; + char * cp; + + setproctitle("logger"); + cp = calloc(1, SIZE); + for(;;) { + if ((fd = open(logfile, O_RDWR | O_APPEND)) != -1) { + if (write(fd, cp, SIZE) != SIZE) + err(1, "write()"); + close(fd); + } + usleep(1); + } + + _exit(0); +} + +void * +spin(void) +{ + int fd, i; + + setproctitle("spin"); + for(;;) { + for (i = 0; i < 5; i++) { + if ((fd = open(oldfiles[i], O_RDWR | O_APPEND)) != -1) + close(fd); + } + usleep(1); + } + _exit(0); +} + +void +renamer() +{ + int fd, i; + time_t start; + + setproctitle("renamer"); + start = time(NULL); + i = 0; + while (time(NULL) - start < 60) { + if ((fd = open(logfile, O_RDWR | O_CREAT | O_EXCL, 0644)) == -1) + err(1, "creat(%s)", logfile); + close(fd); + if (rename(logfile, oldfiles[i]) == -1) + err(1, "rename(%s, %s)", logfile, oldfiles[i]); + i = (i + 1) % 5; + } + for (i = 0; i < 5; i++) { + unlink(oldfiles[i]); + } + unlink(logfile); + +} + +int +main() { + pid_t pids[PARALLEL], spids[PARALLEL]; + int i; + + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + logger(); + if ((spids[i] = fork()) == 0) + spin(); + } + + renamer(); + + for (i = 0; i < PARALLEL; i++) { + if (kill(pids[i], SIGINT) == -1) + err(1, "kill(%d)", pids[i]); + if (kill(spids[i], SIGINT) == -1) + err(1, "kill(%d)", spids[i]); + } + for (i = 0; i < PARALLEL * 2; i++) + wait(NULL); + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/rename11.sh b/tools/test/stress2/misc/rename11.sh new file mode 100755 index 000000000000..19aaa16f92ea --- /dev/null +++ b/tools/test/stress2/misc/rename11.sh @@ -0,0 +1,139 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# SU problem with "mkdir(d.008740.000987): Too many links" seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename11.c +mycc -o rename11 -Wall -Wextra rename11.c || exit 1 +rm -f rename11.c + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +[ $# -eq 1 ] && newfs_flags=$1 # Problem only seen with SU +echo newfs $newfs_flags md${mdstart}$part +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +mkdir $mntpoint/dir +( + cd $mntpoint/dir + /tmp/rename11 || echo FAIL +) + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done + +checkfs /dev/md${mdstart}$part; s=$? +mdconfig -d -u $mdstart +rm -rf /tmp/rename11 +exit $s +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS 10 +#define PARALLEL 3 +#define ND 5000 + +static void +check(char *name) +{ + struct stat sb; + + if (stat(name, &sb) == -1) + warn("stat(%s)", name); + else + warnx("stat(%s) succeeded!", name); +} + +static void +dirs(void) +{ + pid_t pid; + int i, j; + char name[80], to[80]; + + pid = getpid(); + + for (j = 0; j < LOOPS; j++) { + for (i = 0; i < ND; i++) { + snprintf(name, sizeof(name), "d.%06d.%06d", pid, i); + if (mkdir(name, 0700) == -1) + err(1, "mkdir(%s)", name); + snprintf(to , sizeof(to ), "d2.%06d.%06d", pid, i); + if (rename(name, to) == -1) + warn("rename(%s, %s)", name, to); + if (rename(to, name) == -1) + warn("rename(%s, %s)", to, name); + if (rmdir(name) == -1) { + check(name); + err(1, "rmdir(%s)", name); + } + } + } + + _exit(0); +} + +int +main(void) +{ + int i, r, s; + + r = 0; + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + dirs(); + } + + for (i = 0; i < PARALLEL; i++) { + wait(&s); + r += WEXITSTATUS(s); + } + + return (r); +} diff --git a/tools/test/stress2/misc/rename12.sh b/tools/test/stress2/misc/rename12.sh new file mode 100755 index 000000000000..3000e59b70d3 --- /dev/null +++ b/tools/test/stress2/misc/rename12.sh @@ -0,0 +1,192 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# 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. +# + +# No problems seen with SU. Panics with SU+J, just like suj30.sh + +# Triggers "known LOR in SU code" when crossmp8.sh is run first: +# https://people.freebsd.org/~pho/stress/log/rename12.txt. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename12.c +mycc -o rename12 -Wall -Wextra rename12.c || exit 1 +rm -f rename12.c + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 4g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +inodes=`df -i $mntpoint | tail -1 | awk '{print $7}'` +loops=4 +parallel=12 +timeout=1200 +start=`date '+%s'` +for i in `jot $loops`; do + for j in `jot $parallel`; do + mkdir -p $mntpoint/d$j/dir1 + mkdir -p $mntpoint/d$j/dir2 + (cd $mntpoint/d$j; /tmp/rename12 $((inodes/parallel)) ) & + done + wait + for j in `jot $parallel`; do + rmdir $mntpoint/d$j/dir1 + rmdir $mntpoint/d$j/dir2 + done + [ $((`date '+%s'` - start)) -lt $timeout ] && break +done + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done + +checkfs /dev/md${mdstart}$part; s=$? +mdconfig -d -u $mdstart +rm -rf /tmp/rename12 +exit $s +EOF +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +pid_t crpid; +long n; +int mvpipe[2], rmpipe[2]; + +void +cr(void) +{ + pid_t pid; + int i; + char name[80]; + + setproctitle("cr"); + pid = getpid(); + usleep(arc4random() & 1000); + for (i = 0; i < n; i++) { + snprintf(name, sizeof(name), "dir1/d.%06d.%06d", pid, i); + if (mkdir(name, 0700) == -1) + err(1, "mkdir(%s). %s:%d", name, __FILE__, __LINE__); + if (write(mvpipe[1], &i, sizeof(i)) != sizeof(i)) + err(1, "write mvpipe"); + } + + _exit(0); +} + +void +mv(void) +{ + pid_t pid; + int i; + char name[80], to[80]; + + setproctitle("mv"); + pid = crpid; + i = 0; + while (i != n - 1 && + read(mvpipe[0], &i, sizeof(i)) == sizeof(i)) { + snprintf(name, sizeof(name), "dir1/d.%06d.%06d", pid, i); + snprintf(to , sizeof(to ), "dir2/d.%06d.%06d", pid, i); + if (rename(name, to) == -1) + warn("rename(%s, %s)", name, to); + if (write(rmpipe[1], &i, sizeof(i)) != sizeof(i)) + err(1, "write rmpipe"); + } + _exit(0); +} + +void +rm(void) +{ + pid_t pid; + int i; + char to[80]; + + setproctitle("rm"); + pid = crpid; + i = 0; + while (i != n - 1 && + read(rmpipe[0], &i, sizeof(i)) == sizeof(i)) { + snprintf(to, sizeof(to ), "dir2/d.%06d.%06d", pid, i); + if (rmdir(to) == -1) + warn("rmdir(%s)", to); + } + _exit(0); +} + +int +main(int argc, char **argv) +{ + int r, s; + + if (argc != 2) + errx(1, "Usage %s ", argv[0]); + n = atol(argv[1]); + if (n > 32765) { + n = 32765 - 1; + } + + if (pipe(mvpipe) == -1) + err(1, "pipe()"); + if (pipe(rmpipe) == -1) + err(1, "pipe()"); + + r = 0; + if ((crpid = fork()) == 0) + cr(); + if (fork() == 0) + mv(); + if (fork() == 0) + rm(); + + wait(&s); + r += WEXITSTATUS(s); + wait(&s); + r += WEXITSTATUS(s); + wait(&s); + r += WEXITSTATUS(s); + + return (r); +} diff --git a/tools/test/stress2/misc/rename13.sh b/tools/test/stress2/misc/rename13.sh new file mode 100755 index 000000000000..9234d4454751 --- /dev/null +++ b/tools/test/stress2/misc/rename13.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Regression test for crossmp scenario: +# Bug 216380 - mv /[dir == mountpoint] causes kernel panic +# "panic: No vop_rename(0xfffff80033049000, 0xfffffe104d1e48a8)" seen. +# Fixed by r312645. + +# Test scenario by: fnacl@protonmail.com + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep -q "on $mntpoint " && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 512m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +s=0 +to=/tmp/rename13.dir +mkdir $to +mv $mntpoint $to 2>/dev/null && s=1 + +for i in `jot 10`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint || sleep 1 +done +mount | grep -q "on $mntpoint " && { s=2; umount -f $mntpoint; } +mdconfig -d -u $mdstart +rm -rf $to +exit $s diff --git a/tools/test/stress2/misc/rename14.sh b/tools/test/stress2/misc/rename14.sh new file mode 100755 index 000000000000..83612a2632df --- /dev/null +++ b/tools/test/stress2/misc/rename14.sh @@ -0,0 +1,198 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# "panic: handle_workitem_remove: DIRCHG and worklist not empty." seen: +# https://people.freebsd.org/~pho/stress/log/rename14.txt +# Fixed by r356714 + +# Based on a syzkaller scenario reported by tuexen@freebsd.org + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed -e '1,/^EOF/d' < $odir/$0 > $dir/rename14.c +mycc -o rename14 -Wall -Wextra -O0 -g rename14.c -lpthread || exit 1 +rm -f rename14.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +[ `jot -r 1 0 1` -eq 1 ] && opt="-U -n" || opt="-j -n" +newfs -j -n md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +s=0 +(cd /mnt; /tmp/rename14) +[ -f rename14.core -a $s -eq 0 ] && + { ls -l rename14.core; mv rename14.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +checkfs /dev/md$mdstart || s=2 +mdconfig -d -u $mdstart +rm -rf $dir/rename14 +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static sig_atomic_t done_testing; +static volatile u_int *share; + +#define PARALLEL 10 +#define RUNTIME (3 * 60) +#define SYNC 0 + +static void * +t1(void *data __unused) +{ + char n1[80]; + + snprintf(n1, sizeof(n1), "file1.%d", getpid()); + while (done_testing == 0) { + rmdir(n1); + usleep(50000); + } + + return (NULL); +} + +static void * +t2(void *data __unused) +{ + time_t start; + char n0[80], n00[80], n1[80]; + + snprintf(n0, sizeof(n0), "file0.%d", getpid()); + snprintf(n00, sizeof(n00), "file0.%d/file0", getpid()); + snprintf(n1, sizeof(n1), "file1.%d", getpid()); + if (mkdir(n0, 0) == -1) + err(1, "mkdir(%s)", n0); + + start = time(NULL); + while (time(NULL) - start < 60) { + if (mkdir(n00, 0) == -1) + err(1, "mkdir(%s)", n00); + if (rename(n00, n1) == -1) + err(1, "rename(i%s, %s)", n00, n1); + } + if (rmdir(n0) == -1) + err(1, "rmdir(%s)", n0); + done_testing = 1; + + return (NULL); +} + +static void +test(void) +{ + pthread_t tid[2]; + int r; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + done_testing = 0; + if ((r = pthread_create(&tid[0], NULL, t1, NULL)) != 0) + errc(1, r, "pthread_create"); + if ((r = pthread_create(&tid[1], NULL, t2, NULL)) != 0) + errc(1, r, "pthread_create"); + + if ((r = pthread_join(tid[0], NULL)) != 0) + errc(1, r, "pthread_join"); + if ((r = pthread_join(tid[1], NULL)) != 0) + errc(1, r, "pthread_join"); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/rename15.sh b/tools/test/stress2/misc/rename15.sh new file mode 100755 index 000000000000..aa884e045010 --- /dev/null +++ b/tools/test/stress2/misc/rename15.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2020 Peter Holm +# +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# "panic: flush_newblk_dep: Bad newblk 0xfffff8015fd9e800" seen: +# https://people.freebsd.org/~pho/stress/log/rename15.txt + +. ../default.cfg + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +fl=$newfs_flags +fl='-j' +[ $fl = "-U" -a `jot -r 1 0 1` -eq 1 ] && fl="-j" +echo "newfs $fl md$mdstart" +newfs $fl md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +chmod 777 $mntpoint + +export LOAD=80 +export MAXSWAPPCT=80 +export RUNDIR=$mntpoint/stressX +export dirnprenameLOAD=100 +export dirrenameLOAD=100 +export renameLOAD=100 +export runRUNTIME=10m +export rwLOAD=80 +export TESTPROGS=' +testcases/lockf2/lockf2 +testcases/symlink/symlink +testcases/openat/openat +testcases/rw/rw +testcases/fts/fts +testcases/link/link +testcases/creat/creat +testcases/mkdir/mkdir +testcases/rename/rename +testcases/swap/swap +testcases/dirnprename/dirnprename +testcases/dirrename/dirrename +' + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +../tools/killall.sh +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +checkfs /dev/md$mdstart; s=$? +mdconfig -d -u $mdstart +exit $s diff --git a/tools/test/stress2/misc/rename2.sh b/tools/test/stress2/misc/rename2.sh new file mode 100755 index 000000000000..2c9781602d2c --- /dev/null +++ b/tools/test/stress2/misc/rename2.sh @@ -0,0 +1,103 @@ +#!/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. +# + +# With lookup_shared=1 rename() will fail from time to time with ENOENT and +# the following stat() will succeed. (Variation of rename.sh) + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename2.c +mycc -o rename2 -Wall rename2.c || exit 1 +rm -f rename2.c +cd $here + +rm -rf /tmp/rename.dir.* +start=`date +%s` +while [ $((`date +%s` - start -lt 300 ]; do + for j in `jot 10`; do + /tmp/rename2 & + done + wait +done +rm -rf /tmp/rename.dir.* /tmp/rename2 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char dir1[128]; +static char dir2[128]; + +int +main(int argc, char **argv) +{ + struct stat sb; + time_t start; + + 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)", ".."); + + start = time(NULL); + while ((time(NULL) - start) < 120) { + 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/tools/test/stress2/misc/rename3.sh b/tools/test/stress2/misc/rename3.sh new file mode 100755 index 000000000000..c7ce91f0d359 --- /dev/null +++ b/tools/test/stress2/misc/rename3.sh @@ -0,0 +1,51 @@ +#!/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 vulnerability to transient failures when a directory closer +# to the root directory is renamed + +# Deadlocks seen: +# https://people.freebsd.org/~pho/stress/log/kostik447.txt +# https://people.freebsd.org/~pho/stress/log/kirk058.txt + +# 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/tools/test/stress2/misc/rename4.sh b/tools/test/stress2/misc/rename4.sh new file mode 100755 index 000000000000..1a8b1e0046e8 --- /dev/null +++ b/tools/test/stress2/misc/rename4.sh @@ -0,0 +1,62 @@ +#!/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. +# + +# 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 +mycc -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/tools/test/stress2/misc/rename5.sh b/tools/test/stress2/misc/rename5.sh new file mode 100755 index 000000000000..89779b79ec32 --- /dev/null +++ b/tools/test/stress2/misc/rename5.sh @@ -0,0 +1,137 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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. +# + +# Rename scenario from kern/156545 by Konstantin, +# konstantin malov kaspersky com + +# On 8.2-STABLE fsck reports +# "xxx IS AN EXTRANEOUS HARD LINK TO DIRECTORY yyy" +# Fixed by r220986 + +[ `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 1g -u $mdstart +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename5.c +mycc -o rename5 -Wall -Wextra -O2 rename5.c +rm -f rename5.c + +cd $mntpoint + +/tmp/rename5 + +cd $here +rm -f /tmp/rename5 + +while mount | grep -q md${mdstart}$part; do + umount $mntpoint || sleep 1 +done + +checkfs /dev/md${mdstart}$part; s=$? + +mdconfig -d -u $mdstart +exit $s +EOF +#include +#include + +#include +#include +#include +#include +#include +#include + +#define N 1000 +#define RUNTIME (5 * 60) + +void +test(void) +{ + pid_t pid; + int i; + char from[128], to[128]; + + pid = getpid(); + for (i = 0; i < N; i++) { + snprintf(from, sizeof(from), "src/dir.%06d", i); + snprintf(to , sizeof(to), "src/dir.%06d.%06d", i, pid); + (void)rename(from, to); + } + _exit(0); +} + +int +main() +{ + time_t start; + int fd, i; + char dir[128], file[128]; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + if (mkdir("src", 0700) == -1) + err(1, "mkdir(src)"); + + for (i = 0; i < N; i++) { + snprintf(dir, sizeof(dir), "src/dir.%06d", i); + if (mkdir(dir, 0700) == -1) + err(1, "mkdir(%s)", dir); + snprintf(file, sizeof(file), "%s/meta", dir); + if ((fd = open(file, O_RDWR | O_CREAT, 0600)) < 0) + err(1, "open(%s)", file); + close(fd); + snprintf(file, sizeof(file), "%s/data", dir); + if ((fd = open(file, O_RDWR | O_CREAT, 0600)) < 0) + err(1, "open(%s)", file); + close(fd); + } + + for (i = 0; i < 2; i++) { + if (fork() == 0) + test(); + } + for (i = 0; i < 2; i++) + wait(NULL); + + system("rm -rf src > /dev/null 2>&1"); + } + + return (0); +} diff --git a/tools/test/stress2/misc/rename6.sh b/tools/test/stress2/misc/rename6.sh new file mode 100755 index 000000000000..6c27c5601d2a --- /dev/null +++ b/tools/test/stress2/misc/rename6.sh @@ -0,0 +1,149 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Demonstrate rename(2) cache problem, where the original name lingers in the VFS cache. + +# Original test scenario by Anton Yuzhaninov + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename6.c +mycc -o rename6 -Wall -Wextra -O2 rename6.c +rm -f rename6.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +su $testuser -c "cd $mntpoint; /tmp/rename6" + +while mount | grep -q md${mdstart}$part; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/rename6 +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +pid_t spid; +const char *logfile = "test.log"; + +void +cleanup() +{ + if (kill(spid, SIGINT) == -1 && errno != ESRCH) + err(1, "kill(%d)", spid); +} + +static void +Stat() +{ + struct stat sb; + int i; + + setproctitle("Stat"); + for (;;) { + for (i = 0; i < 1000; i++) { + stat(logfile, &sb); + } + usleep(1000); + } +} + +int +main(void) +{ + struct stat sb1, sb2; + int fd, i; + char new[128]; + + if ((spid = fork()) == 0) + Stat(); + + setproctitle("main"); + atexit(cleanup); + for (i = 0; i < 20000; i++) { + sprintf(new, "test.log.%05d", i); + if ((fd = open(logfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) + err(1, "creat(%s)", logfile); + close(fd); +#if 1 + if (rename(logfile, new) == -1) + warn("rename(%s, %s)", logfile, new); +#else + /* No cache problem is seen */ + if (link(logfile, new) == -1) + err(1, "link(%s, %s)", logfile, new); + if (unlink(logfile) == -1) + err(1, "unlink(%s)", logfile); +#endif + /* + * stat() for logfile and new will be identical sometimes, + * but only when Stat() is running. + */ + if (stat(logfile, &sb1) == 0 && stat(new, &sb2) == 0 && + bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { + fprintf(stderr, "At loop #%d\n", i); + fprintf(stderr, "%-15s: ino = %ju, nlink = %ju," + " size = %jd\n", logfile, (uintmax_t)sb1.st_ino, + (uintmax_t)sb1.st_nlink, sb1.st_blocks); + fprintf(stderr, "%-15s: ino = %ju, nlink = %ju, " + "size = %jd\n", new , (uintmax_t)sb2.st_ino, + (uintmax_t)sb2.st_nlink, sb2.st_blocks); + } + unlink(new); + } + + kill(spid, SIGINT); + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/rename7.sh b/tools/test/stress2/misc/rename7.sh new file mode 100755 index 000000000000..89edcd17e827 --- /dev/null +++ b/tools/test/stress2/misc/rename7.sh @@ -0,0 +1,150 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# After a few runs this will happen: +# $ umount /mnt +# umount: unmount of /mnt failed: Device busy +# $ umount -f /mnt +# $ + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename7.c +mycc -o rename7 -Wall -Wextra -O2 rename7.c || exit +rm -f rename7.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +su $testuser -c "cd $mntpoint; /tmp/rename7 || echo FAIL" + +for i in `jot 10`; do + mount | grep -q md${mdstart}$part && \ + umount $mntpoint && mdconfig -d -u $mdstart && break +done +if mount | grep -q md${mdstart}$part; then + echo "Test failed" + exit 1 +fi +rm -f /tmp/rename7 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char *logfile = "test.log"; +pid_t wpid, spid; + +void +r1(void) +{ + int i; + struct stat sb1, sb2; + + for (i = 0; i < 800000; i++) { + rename(logfile, "r1"); + if (stat("r1", &sb1) == 0 && stat("r2", &sb2) == 0 && + bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { + fprintf(stderr, "r1 and r2 are identical after rename(%s, \"r1\")\n", logfile); + system("ls -ail"); + _exit(1); + } + } + _exit(0); +} + +void +r2(void) +{ + int i; + struct stat sb1, sb2; + +// _exit(0); /* No problems with only r1 running */ + for (i = 0; i < 800000; i++) { + rename(logfile, "r2"); + if (stat("r1", &sb1) == 0 && stat("r2", &sb2) == 0 && + bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { + usleep(10000); + fprintf(stderr, "r1 and r2 are identical after rename(%s, \"r2\")\n", logfile); + system("ls -ail"); + _exit(1); + } + } + _exit(0); +} +int +main(void) +{ + pid_t wpid, spid; + int e, fd, i, status; + + if ((wpid = fork()) == 0) + r1(); + if ((spid = fork()) == 0) + r2(); + + setproctitle("main"); + e = 0; + + for (i = 0; i < 800000; i++) { + if ((fd = open(logfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) + warn("creat(%s)", logfile); + close(fd); + } + + kill(wpid, SIGINT); + kill(spid, SIGINT); + wait(&status); + e += WEXITSTATUS(status); + wait(&status); + e += WEXITSTATUS(status); + + return (e); +} diff --git a/tools/test/stress2/misc/rename8.sh b/tools/test/stress2/misc/rename8.sh new file mode 100755 index 000000000000..e0019cb353fa --- /dev/null +++ b/tools/test/stress2/misc/rename8.sh @@ -0,0 +1,173 @@ +#!/bin/sh + +# +# Copyright (c) 2011 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Cache inconsistency seen on "to" file for rename(2). + +# Scenario by jhb@ + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename8.c +mycc -o rename8 -Wall -Wextra -O2 rename8.c +rm -f rename8.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +su $testuser -c "cd $mntpoint; mkdir r; /tmp/rename8 r" +ls -li $mntpoint/r | egrep -v "^total" + +for i in `jot 10`; do + mount | grep -q md${mdstart}$part && \ + umount $mntpoint && mdconfig -d -u $mdstart && break + sleep 1 +done +if mount | grep -q md${mdstart}$part; then + fuser $mntpoint + echo "umount $mntpoint failed" + exit 1 +fi + +mdconfig -l | grep -q md$mdstart && + mdconfig -d -u $mdstart +rm -f /tmp/rename8 +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char *always, *file1, *file2; +static ino_t always_ino; + +static void +usage(void) +{ + fprintf(stderr, "Usage: rename_race \n"); + exit(1); +} + +static void +child(void) +{ + struct stat sb; + + /* Exit as soon as our parent exits. */ + while (getppid() != 1) { + stat(file1, &sb); + } + exit(0); +} + +static void +create_file(const char *path) +{ + int fd; + + fd = open(path, O_CREAT, 0666); + if (fd < 0) + err(1, "open(%s)", path); + close(fd); +} + +int +main(int ac, char **av) +{ + struct stat sb, sb2; + pid_t pid; + int i, r; + + if (ac != 2) + usage(); + if (stat(av[1], &sb) != 0) + err(1, "stat(%s)", av[1]); + if (!S_ISDIR(sb.st_mode)) + errx(1, "%s not a directory", av[1]); + + asprintf(&always, "%s/file.always", av[1]); + asprintf(&file1, "%s/file1", av[1]); + asprintf(&file2, "%s/file2", av[1]); + + create_file(always); + if (stat(always, &sb) != 0) + err(1, "stat(%s)", always); + always_ino = sb.st_ino; + + pid = fork(); + if (pid < 0) + err(1, "fork"); + if (pid == 0) + child(); + r = 0; + for (i = 0; i < 100000; i++) { + if (unlink(file1) < 0 && errno != ENOENT) + err(1, "unlink(%s)", file1); + if (link(always, file1) < 0) + err(1, "link(%s, %s)", always, file1); + create_file(file2); + if (stat(file2, &sb2) < 0) + err(1, "stat(%s)", file2); + if (rename(file2, file1) < 0) + err(1, "rename(%s, %s)", file2, file1); + if (stat(file1, &sb) < 0) + err(1, "stat(%s)", file1); + if (sb.st_ino != sb2.st_ino || + sb.st_ino == always_ino) { + printf("FAIL. Bad stat: always: %ju file1: %ju (should be %ju)\n", + (uintmax_t)always_ino, (uintmax_t)sb.st_ino, + (uintmax_t)sb2.st_ino); + r = EXIT_FAILURE; + break; + } + } + kill(pid, SIGINT); + wait(NULL); + if (r == 0) { + unlink(always); + unlink(file1); + unlink(file2); + } + return (r); +} diff --git a/tools/test/stress2/misc/rename9.sh b/tools/test/stress2/misc/rename9.sh new file mode 100755 index 000000000000..e169c64af5ea --- /dev/null +++ b/tools/test/stress2/misc/rename9.sh @@ -0,0 +1,169 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Variation of rename6.sh. Cache problem of "to" file name seen. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename9.c +mycc -o rename9 -Wall -Wextra -O2 rename9.c +rm -f rename9.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +rm -rf $mntpoint/.snap +chmod 777 $mntpoint + +(while true; do ls -lRi $mntpoint > /dev/null 2>&1; done) & +su $testuser -c "cd $mntpoint; /tmp/rename9" +kill $! > /dev/null 2>&1 +wait +ls -ilR $mntpoint | egrep -v "^total " + +while mount | grep -q md${mdstart}$part; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/rename9 +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +pid_t spid; +char *fromFile = "fromFile.log"; +char toFile[128]; + +void +cleanup() +{ + kill(spid, SIGINT); +} + +static void +statFrom() +{ + struct stat sb; + + setproctitle("Stat"); + for (;;) { + stat(fromFile, &sb); + } +} + +int +main(void) +{ + struct stat fb, tb, fa, ta; + int fd, i; + + if ((spid = fork()) == 0) + statFrom(); + + setproctitle("main"); + atexit(cleanup); + for (i = 0;i < 100000; i++) { + bzero(&fb, sizeof(fb)); + bzero(&tb, sizeof(tb)); + bzero(&fa, sizeof(fa)); + bzero(&ta, sizeof(ta)); + + if ((fd = open(fromFile, O_RDWR | O_CREAT | O_TRUNC, 0644)) + == -1) + err(1, "creat(%s)", fromFile); + close(fd); + + sprintf(toFile, "toFile.log.%05d", i); + if ((fd = open(toFile, O_RDWR | O_CREAT | O_TRUNC, 0644)) + == -1) + err(1, "creat(%s)", toFile); + write(fd, "xxx", 3); + close(fd); + + stat(fromFile, &fb); + stat(toFile, &tb); + if (rename(fromFile, toFile) == -1) + warn("rename(%s, %s)", fromFile, toFile); + stat(fromFile, &fa); + if (stat(toFile, &ta) == -1) + err(1, "stat(%s)", toFile); + + if (tb.st_ino == ta.st_ino) { + fprintf(stderr, "FAIL: old and new \"To\" inode " + "number is identical\n"); + fprintf(stderr, "stat() before the rename():\n"); + fprintf(stderr, + "%-16s: ino = %4ju, nlink = %ju, size = %jd\n", + fromFile, (uintmax_t)fb.st_ino, (uintmax_t)fb.st_nlink, + fb.st_blocks); + fprintf(stderr, + "%-16s: ino = %4ju, nlink = %ju, size = %jd\n", + toFile, (uintmax_t)tb.st_ino, (uintmax_t)tb.st_nlink, + tb.st_blocks); + fprintf(stderr, "\nstat() after the rename():\n"); + if (fa.st_ino != 0) + fprintf(stderr, + "%-16s: ino = %4ju, nlink = %ju, size = " + "%jd\n", fromFile, (uintmax_t)fa.st_ino, + (uintmax_t)fa.st_nlink, fa.st_blocks); + fprintf(stderr, + "%-16s: ino = %4ju, nlink = %ju, size = %jd\n", + toFile, (uintmax_t)ta.st_ino, (uintmax_t)ta.st_nlink, + ta.st_blocks); + kill(spid, SIGINT); + exit(1); + } + unlink(toFile); + } + + kill(spid, SIGINT); + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/revoke.sh b/tools/test/stress2/misc/revoke.sh new file mode 100755 index 000000000000..453cbc1001a5 --- /dev/null +++ b/tools/test/stress2/misc/revoke.sh @@ -0,0 +1,116 @@ +#!/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. +# + +# Regression test. Causes panic on 6.1 + +. ../default.cfg + +odir=`pwd` +dir=/tmp + +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/revoke.c +mycc -o revoke -Wall revoke.c || exit 1 +rm -f revoke.c + +n=100 # Number of times to test +for i in `jot $n`; do + ./revoke /dev/ttyv9 > /dev/null 2>&1 & + ./revoke /dev/ttyva > /dev/null 2>&1 & + ./revoke /dev/ttyvb > /dev/null 2>&1 & + ./revoke /dev/ttyvc > /dev/null 2>&1 & + wait +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/tools/test/stress2/misc/rot.sh b/tools/test/stress2/misc/rot.sh new file mode 100755 index 000000000000..b658f35aad1b --- /dev/null +++ b/tools/test/stress2/misc/rot.sh @@ -0,0 +1,142 @@ +#!/bin/sh + +# +# Copyright (c) 2012 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Unmapped I/O test scenario: +# http://people.freebsd.org/~pho/stress/log/kostik515.txt + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rot.c +mycc -o rot -Wall -Wextra -O2 -g rot.c || exit 1 +rm -f rot.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +(cd $mntpoint; /tmp/rot) +(cd `dirname $diskimage`; /tmp/rot) + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/rot +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include + +#define N 10240 /* 40 Mb */ +#define PARALLEL 20 +#define RUNTIME (60 * 15) + +int +test(void) +{ + int fd, i, j, s; + unsigned char *buf; + char path[128]; + + s = getpagesize(); + + sprintf(path,"%s.%05d", getprogname(), getpid()); + if ((fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) + err(1, "open(%s)", path); + if (lseek(fd, s * N - 1, SEEK_SET) == -1) + err(1, "lseek error"); + + /* write a dummy byte at the last location */ + if (write(fd, "", 1) != 1) + err(1, "write error"); + + for (i = 0; i < N; i++) { + if ((buf = mmap(0, s, PROT_READ | PROT_WRITE, MAP_SHARED, fd, + i * s)) == MAP_FAILED) + err(1, "write map"); + for (j = 0; j < s; j++) + buf[j] = i % 256; + } + if (munmap(buf, s) == -1) + err(1, "unmap (write)"); + close(fd); + + if ((fd = open(path, O_RDONLY)) < 0) + err(1, "open(%s)", path); + for (i = 0; i < N; i++) { + if ((buf = mmap(0, s, PROT_READ, MAP_SHARED, fd, i * s)) == + MAP_FAILED) + err(1, "write map"); + for (j = 0; j < s; j++) + if (buf[j] != i % 256) + fprintf(stderr, "read %d, expected %d at %d\n", + buf[j], i % 256, i); + } + if (munmap(buf, s) == -1) + err(1, "unmap (read)"); + close(fd); + unlink(path); + + _exit(0); +} + +int +main(void) +{ + time_t start; + int i; + + start = time(NULL); + while (time(NULL) - start < RUNTIME) { + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + test(); + for (i = 0; i < PARALLEL; i++) + wait(NULL); + } + + return(0); +} diff --git a/tools/test/stress2/misc/routetbl.sh b/tools/test/stress2/misc/routetbl.sh new file mode 100755 index 000000000000..0a2b936f15e4 --- /dev/null +++ b/tools/test/stress2/misc/routetbl.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Demonstrate memory leak of routetbl allegedly caused by use free() in +# vfs_free_addrlist_af(), instead of rn_detachhead(). +# "routetbl grew 3868" seen on amd64. + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +pgrep -q mountd || exit 0 +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 128m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null + +routetbl=`vmstat -m | grep routetbl | awk '{print $2}'` +s=0 +start=`date +%s` +while [ $((`date +%s` - start)) -lt 60 ]; do + mount /dev/md${mdstart}$part $mntpoint && + umount $mntpoint +done +routetbl=$((`vmstat -m | grep routetbl | awk '{print $2}'` - routetbl)) +[ $routetbl -gt 0 ] && + { echo "routetbl grew $routetbl"; s=1; } + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && exit 1 +mdconfig -d -u $mdstart +rm -rf /tmp/template +exit $s diff --git a/tools/test/stress2/misc/ruby.sh b/tools/test/stress2/misc/ruby.sh new file mode 100755 index 000000000000..2ed1b023d0ec --- /dev/null +++ b/tools/test/stress2/misc/ruby.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# "small MAP_STACK requests" scenario. + +# "
: warning: pthread_create failed for timer: Resource temporarily +# unavailable, scheduling broken" seen. +# Fixed by r320339. + +[ -x "`which ruby`" ] || exit 0 + +ruby -v 2>&1 | tee $log | grep warning && s=1 || s=0 +exit $s diff --git a/tools/test/stress2/misc/rw.sh b/tools/test/stress2/misc/rw.sh new file mode 100755 index 000000000000..2cba9587c925 --- /dev/null +++ b/tools/test/stress2/misc/rw.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Simple read / write test scenario with VM pressure. + +# Out of VM seen: +# 100135 D vmwait 0xffffffff81d1a348 [CAM taskq] +# https://people.freebsd.org/~pho/stress/log/rw.txt + +. ../default.cfg + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs $newfs_flags md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=10m +export RUNDIR=$mntpoint/stressX + +export rwLOAD=100 +export swapLOAD=100 +export TESTPROGS=" +testcases/rw/rw +testcases/swap/swap +" + +su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' + +while mount | grep "on $mntpoint " | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart diff --git a/tools/test/stress2/misc/rwlock_ronly.sh b/tools/test/stress2/misc/rwlock_ronly.sh new file mode 100755 index 000000000000..4a9b761ad98e --- /dev/null +++ b/tools/test/stress2/misc/rwlock_ronly.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +# +# Copyright (c) 2013 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 scenario by kib@ +# Demonstrate process looping in kernel mode. +# Fixed in r251684. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/rwlock_ronly.c +mycc -o rwlock_ronly -Wall -Wextra rwlock_ronly.c || exit 1 +rm -f rwlock_ronly.c +cd $odir + +/tmp/rwlock_ronly || echo OK + +rm -f /tmp/rwlock_ronly +exit + +EOF +/* $Id: rwlock_ronly.c,v 1.2 2013/06/10 04:44:08 kostik Exp kostik $ */ + +#include +#include +#include +#include +#include +#include + +int +main(void) +{ + char *p; + struct urwlock *rw; + int error; + + p = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + if (p == (char *)MAP_FAILED) + err(1, "mmap"); + + rw = (struct urwlock *)p; + rw->rw_state = URWLOCK_READ_WAITERS; + + error = mprotect(p, getpagesize(), PROT_READ); + if (error == -1) + err(1, "mprotect"); + + error = _umtx_op(p, UMTX_OP_RW_RDLOCK, 0, NULL, NULL); + if (error != 0) + err(1, "rdlock"); + + return (0); +} diff --git a/tools/test/stress2/misc/sched.sh b/tools/test/stress2/misc/sched.sh new file mode 100755 index 000000000000..f91055b3c289 --- /dev/null +++ b/tools/test/stress2/misc/sched.sh @@ -0,0 +1,161 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# 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 -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +# Show scheduler fairness for ULE vs. 4BSD. + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > sched.c +mycc -o sched -Wall -Wextra -O0 sched.c || exit 1 +rm -f sched.c +cd $here + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +cpus=`sysctl hw.ncpu | sed 's/.*: //'` +uname -v +(cd $mntpoint; /tmp/sched $((cpus + 1))) > /dev/null 2>&1 & +sleep 30 +export LANG=C +top -U nobody -d 1 | grep nobody | awk '{print $11}' | sed 's/%//' | + ministat -A -w 73 | tail -1 | awk '{if ($NF > 1.0) exit 1}' || +{ echo Broken; top -U nobody -d 1 | grep nobody; } +killall sched +wait + +for i in `jot 3`; do + echo "run #$i" + (cd $mntpoint; /tmp/sched $((cpus + 1))) +done + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +rm -f /tmp/sched +mdconfig -d -u $mdstart +exit +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N 100 * 1024 * 1024 + +double r; +int parallel; + +void +work(void) +{ + struct passwd *pw; + struct timespec start, finish; + double d1, d2; + int i, j; + volatile char *cp; + + while (access("rendezvous", R_OK) != 0) + usleep(1); + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + d1 = d2 = 0; + cp = malloc(N); + clock_gettime(CLOCK_REALTIME_PRECISE, &start); + for (i = 0; i < 1; i++) { + for (j = 0; j < INT_MAX; j++) { + d1 = d1 + 1.0 / j; + d2 = d1 + 0.8 / j; + if (j % 1000 == 0) { + cp[arc4random() % N] = j % 255; + } + } + } + r = d1 + d2; + clock_gettime(CLOCK_REALTIME_PRECISE, &finish); + timespecsub(&finish, &start, &finish); +#if defined(DEBUG) + fprintf(stderr, "Elapsed time for pid %d: %.4f\n", getpid(), + finish.tv_sec + (double)finish.tv_nsec / 1e9); +#endif + + _exit(0); +} + +int +main(int argc, char **argv) +{ + int fd, i; + + if (argc == 2) + parallel = atoi(argv[1]); + else + errx(1, "Usage: %s ", argv[0]); + + for (i = 0; i < parallel; i++) { + if (fork() == 0) + work(); + } + if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) + err(1, "open()"); + close(fd); + for (i = 0; i < parallel; i++) + wait(NULL); + + return (0); +} diff --git a/tools/test/stress2/misc/schedfuzz.sh b/tools/test/stress2/misc/schedfuzz.sh new file mode 100755 index 000000000000..c1a7918cc4fb --- /dev/null +++ b/tools/test/stress2/misc/schedfuzz.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# Sched fuzz test scenario. + +# "panic: sleeping thread" seen: +# https://people.freebsd.org/~pho/stress/log/schedfuzz.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +sysctl kern.sched_fuzz.prof_on > /dev/null 2>&1 || exit 0 + +: ${pct1:=0.01} +: ${pct2:=0.1} +export pct1 pct2 + +seton() { + sysctl kern.sched_fuzz.sched_fuzz_scheduler="${pct1}%return(1)" + sysctl kern.sched_fuzz.sched_fuzz_sx_slock_delay="${pct1}%schedfuzz(82)" + sysctl kern.sched_fuzz.sched_fuzz_sx_xlock_delay="${pct1}%schedfuzz(82)" + sysctl kern.sched_fuzz.sched_fuzz_sx_slock_sleep="${pct1}%schedfuzz(82)" + sysctl kern.sched_fuzz.sched_fuzz_sx_xlock_sleep="${pct1}%schedfuzz(82)" + sysctl kern.sched_fuzz.sched_fuzz_mtx_spin_lock="${pct1}%schedfuzz(44)" + sysctl kern.sched_fuzz.sched_fuzz_mtx_spin_unlock="${pct1}%schedfuzz(44)" + sysctl kern.sched_fuzz.sched_fuzz_malloc="${pct1}%schedfuzz(62)" + sysctl kern.sched_fuzz.sched_fuzz_cv_wait="${pct2}%schedfuzz(100)" + sysctl kern.sched_fuzz.sched_fuzz_cv_timed_wait="${pct2}%schedfuzz(100)" + sysctl kern.sched_fuzz.sched_fuzz_cv_timed_wait_sig="${pct2}%schedfuzz(100)" + sysctl kern.sched_fuzz.sched_fuzz_mtx_lock="${pct1}%schedfuzz(22)" + sysctl kern.sched_fuzz.sched_fuzz_mtx_unlock="${pct1}%schedfuzz(22)" + sysctl kern.sched_fuzz.sched_fuzz_sleepq="${pct1}%schedfuzz(150)" + + sysctl kern.sched_fuzz.prof_on=1 +} + +setoff() { + sysctl kern.sched_fuzz.prof_on=0 +} + +if [ $# -eq 1 ]; then + case "$1" in + on) seton + ;; + off) setoff + ;; + *) echo "Usage: $0 [on|off]" + exit 1 + ;; + esac +else + seton + ./procfs.sh + setoff +fi diff --git a/tools/test/stress2/misc/sctp.sh b/tools/test/stress2/misc/sctp.sh new file mode 100755 index 000000000000..7e28deb5b300 --- /dev/null +++ b/tools/test/stress2/misc/sctp.sh @@ -0,0 +1,158 @@ +#!/bin/sh + +# Based on https://gist.github.com/zonque/7d03568eab14a2bb57cb by +# Daniel Mack github@zonque.org + +# "panic: general protection fault" seen: +# https://people.freebsd.org/~pho/stress/log/sctp.txt +# Fixed by r350626 + +kldstat -v | grep -q sctp || kldload sctp.ko +cat > /tmp/sctp.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int my_port_num; + +static void +die(const char *s) +{ + perror(s); + exit(1); +} + + static void +server(void) +{ + struct sctp_sndrcvinfo sndrcvinfo; + struct sockaddr_in servaddr = { + .sin_family = AF_INET, + .sin_addr.s_addr = htonl(INADDR_ANY), + .sin_port = htons(my_port_num), + }; + struct sctp_initmsg initmsg = { + .sinit_num_ostreams = 5, + .sinit_max_instreams = 5, + .sinit_max_attempts = 4, + }; + int listen_fd, conn_fd, flags, ret, in; + + listen_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); + if (listen_fd < 0) + die("socket"); + + ret = bind(listen_fd, (struct sockaddr *) &servaddr, sizeof(servaddr)); + if (ret < 0) + die("bind"); + + ret = setsockopt(listen_fd, IPPROTO_SCTP, SCTP_INITMSG, &initmsg, + sizeof(initmsg)); + if (ret < 0) + die("setsockopt"); + + ret = listen(listen_fd, initmsg.sinit_max_instreams); + if (ret < 0) + die("listen"); + + for (;;) { + char buffer[1024]; + + printf("Waiting for connection\n"); + fflush(stdout); + + conn_fd = accept(listen_fd, (struct sockaddr *) NULL, NULL); + if(conn_fd < 0) + die("accept()"); + + printf("New client connected\n"); + fflush(stdout); + + /* Note that flags is uninitialized here */ + in = sctp_recvmsg(conn_fd, buffer, sizeof(buffer), NULL, 0, + &sndrcvinfo, &flags); + if (in > 0) { + printf("Received data: %s\n", buffer); + fflush(stdout); + } + + close(conn_fd); + } +} + +static void +client(void) +{ + struct sockaddr_in servaddr = { + .sin_family = AF_INET, + .sin_port = htons(my_port_num), + .sin_addr.s_addr = inet_addr("127.0.0.1"), + }; + int conn_fd, ret; + const char *msg = "Hello, Server!"; + + conn_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); + if (conn_fd < 0) + die("socket()"); + + ret = connect(conn_fd, (struct sockaddr *) &servaddr, sizeof(servaddr)); + if (ret < 0) + die("connect()"); + + ret = sctp_sendmsg(conn_fd, (void *) msg, strlen(msg) + 1, NULL, 0, 0, 0, 0, 0, 0 ); + if (ret < 0) + die("sctp_sendmsg"); + + close(conn_fd); +} + +int +main(int argc __unused, char *argv[]) +{ + + my_port_num = atoi(argv[1]); + if (strstr(basename(argv[0]), "server")) + server(); + else + client(); + + return (0); +} +EOF + +cc -o /tmp/server -Wall -Wextra -O2 /tmp/sctp.c || exit +ln -sf /tmp/server /tmp/client + +parallel=100 +for i in `jot $parallel 62324`; do + /tmp/server $i > /dev/null & +done +(cd ../testcases/swap; ./swap -t 1m -i 20 -l 100) & +sleep 2 + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 60 ]; do + pids= + for i in `jot 50`; do + for j in `jot $parallel 62324`; do + /tmp/client $j & + pids="$pids $!" + done + done + for i in $pids; do + wait $i + done +done +pkill server +wait +while pkill swap; do :; done +wait +rm -f /tmp/sctp.c /tmp/server /tmp/client +exit 0 diff --git a/tools/test/stress2/misc/sctp2.sh b/tools/test/stress2/misc/sctp2.sh new file mode 100755 index 000000000000..45727e03c206 --- /dev/null +++ b/tools/test/stress2/misc/sctp2.sh @@ -0,0 +1,169 @@ +#!/bin/sh + +# Based on https://gist.github.com/zonque/7d03568eab14a2bb57cb by +# Daniel Mack github@zonque.org + +# Modified version of sctp.sh by Michael Tuexen : +# * Use loopback as the address of the server on both side initialized using +# htonl(INADDR_LOOPBACK). +# * Negotiate only 1 stream in both directions since only one stream is used. +# * Don't use initmsg.sinit_max_instreams as an argument in listen(), which +# does not make sense. +# Use an arbitrary positive integer, 5 in this case. +# * Initialize flags before calling sctp_recvmsg(). + +# "panic: Don't own TCB lock" seen: +# https://people.freebsd.org/~pho/stress/log/sctp2.txt + +# "panic: soclose: SS_NOFDREF on enter" seen: +# https://people.freebsd.org/~pho/stress/log/sctp2-2.txt + +kldstat -v | grep -q sctp || kldload sctp.ko +cat > /tmp/sctp2.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int my_port_num; + +static void +die(const char *s) +{ + perror(s); + exit(1); +} + +static void +server(void) +{ + struct sctp_sndrcvinfo sndrcvinfo; + struct sockaddr_in servaddr = { + .sin_family = AF_INET, + .sin_addr.s_addr = htonl(INADDR_LOOPBACK), + .sin_port = htons(my_port_num), + }; + struct sctp_initmsg initmsg = { + .sinit_num_ostreams = 1, + .sinit_max_instreams = 1, + .sinit_max_attempts = 4, + }; + int listen_fd, conn_fd, flags, ret, in; + + listen_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); + if (listen_fd < 0) + die("socket"); + + ret = bind(listen_fd, (struct sockaddr *) &servaddr, sizeof(servaddr)); + if (ret < 0) + die("bind"); + + ret = setsockopt(listen_fd, IPPROTO_SCTP, SCTP_INITMSG, &initmsg, + sizeof(initmsg)); + if (ret < 0) + die("setsockopt"); + + ret = listen(listen_fd, 5); + if (ret < 0) + die("listen"); + + for (;;) { + char buffer[1024]; + + printf("Waiting for connection\n"); + fflush(stdout); + + conn_fd = accept(listen_fd, (struct sockaddr *) NULL, NULL); + if(conn_fd < 0) + die("accept()"); + + printf("New client connected\n"); + fflush(stdout); + + flags = 0; + in = sctp_recvmsg(conn_fd, buffer, sizeof(buffer), NULL, 0, + &sndrcvinfo, &flags); + if (in > 0) { + printf("Received data: %s\n", buffer); + fflush(stdout); + } + + close(conn_fd); + } +} + +static void +client(void) +{ + struct sockaddr_in servaddr = { + .sin_family = AF_INET, + .sin_port = htons(my_port_num), + .sin_addr.s_addr = htonl(INADDR_LOOPBACK), + }; + int conn_fd, ret; + const char *msg = "Hello, Server!"; + + conn_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); + if (conn_fd < 0) + die("socket()"); + + ret = connect(conn_fd, (struct sockaddr *) &servaddr, sizeof(servaddr)); + if (ret < 0) + die("connect()"); + + ret = sctp_sendmsg(conn_fd, (void *) msg, strlen(msg) + 1, NULL, 0, 0, 0, 0, 0, 0 ); + if (ret < 0) + die("sctp_sendmsg"); + + close(conn_fd); +} + +int +main(int argc __unused, char *argv[]) +{ + + my_port_num = atoi(argv[1]); + if (strstr(basename(argv[0]), "server")) + server(); + else + client(); + + return (0); +} +EOF + +cc -o /tmp/server -Wall -Wextra -O2 /tmp/sctp2.c || exit +ln -sf /tmp/server /tmp/client + +parallel=100 +for i in `jot $parallel 62324`; do + /tmp/server $i > /dev/null & +done +(cd ../testcases/swap; ./swap -t 1m -i 20 -l 100) & +sleep 2 + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 60 ]; do + pids= + for i in `jot 50`; do + for j in `jot $parallel 62324`; do + /tmp/client $j & + pids="$pids $!" + done + done + for i in $pids; do + wait $i + done +done +pkill server +wait +while pkill swap; do :; done +wait +rm -f /tmp/sctp2.c /tmp/server /tmp/client +exit 0 diff --git a/tools/test/stress2/misc/sctp3.sh b/tools/test/stress2/misc/sctp3.sh new file mode 100755 index 000000000000..74017bb5194f --- /dev/null +++ b/tools/test/stress2/misc/sctp3.sh @@ -0,0 +1,172 @@ +#!/bin/sh + +# Based on https://gist.github.com/zonque/7d03568eab14a2bb57cb by +# Daniel Mack github@zonque.org + +# Modified version of sctp.sh by Michael Tuexen : +# Basically it is the first test without calling sctp_recvmsg() on +# the server side and the required cleanups to avoid unused variables. +# This program triggers pretty quickly the "Queues are not empty when +# handling SHUTDOWN-COMPLETE" panic. This happened "by accident" with +# the original sctp.sh, if the flags argument contained the value +# MSG_DONTWAIT and sctp_recvmsg() returned -1 indicating EAGAIN. This +# way no successful sctp_recvmsg() call happened. + +# "panic: Queues are not empty when handling SHUTDOWN-COMPLETE" seen. + +kldstat -v | grep -q sctp || kldload sctp.ko +cat > /tmp/sctp3.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int my_port_num; + +static void +die(const char *s) +{ + perror(s); + exit(1); +} + +static void +server(void) +{ +#if 0 + struct sctp_sndrcvinfo sndrcvinfo; +#endif + struct sockaddr_in servaddr = { + .sin_family = AF_INET, + .sin_addr.s_addr = htonl(INADDR_LOOPBACK), + .sin_port = htons(my_port_num), + }; + struct sctp_initmsg initmsg = { + .sinit_num_ostreams = 1, + .sinit_max_instreams = 1, + .sinit_max_attempts = 4, + }; + int listen_fd, conn_fd, ret; +#if 0 + int flags, in; +#endif + + listen_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); + if (listen_fd < 0) + die("socket"); + + ret = bind(listen_fd, (struct sockaddr *) &servaddr, sizeof(servaddr)); + if (ret < 0) + die("bind"); + + ret = setsockopt(listen_fd, IPPROTO_SCTP, SCTP_INITMSG, &initmsg, + sizeof(initmsg)); + if (ret < 0) + die("setsockopt"); + + ret = listen(listen_fd, 5); + if (ret < 0) + die("listen"); + + for (;;) { +#if 0 + char buffer[1024]; +#endif + printf("Waiting for connection\n"); + fflush(stdout); + + conn_fd = accept(listen_fd, (struct sockaddr *) NULL, NULL); + if(conn_fd < 0) + die("accept()"); + + printf("New client connected\n"); + fflush(stdout); + +#if 0 + flags = 0; + in = sctp_recvmsg(conn_fd, buffer, sizeof(buffer), NULL, 0, + &sndrcvinfo, &flags); + if (in > 0) { + printf("Received data: %s\n", buffer); + fflush(stdout); + } +#endif + close(conn_fd); + } +} + +static void +client(void) +{ + struct sockaddr_in servaddr = { + .sin_family = AF_INET, + .sin_port = htons(my_port_num), + .sin_addr.s_addr = htonl(INADDR_LOOPBACK), + }; + int conn_fd, ret; + const char *msg = "Hello, Server!"; + + conn_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); + if (conn_fd < 0) + die("socket()"); + + ret = connect(conn_fd, (struct sockaddr *) &servaddr, sizeof(servaddr)); + if (ret < 0) + die("connect()"); + + ret = sctp_sendmsg(conn_fd, (void *) msg, strlen(msg) + 1, NULL, 0, 0, 0, 0, 0, 0 ); + if (ret < 0) + die("sctp_sendmsg"); + + close(conn_fd); +} + +int +main(int argc __unused, char *argv[]) +{ + + my_port_num = atoi(argv[1]); + if (strstr(basename(argv[0]), "server")) + server(); + else + client(); + + return (0); +} +EOF + +cc -o /tmp/server -Wall -Wextra -O2 /tmp/sctp3.c || exit +ln -sf /tmp/server /tmp/client + +parallel=100 +for i in `jot $parallel 62324`; do + /tmp/server $i > /dev/null & +done +(cd ../testcases/swap; ./swap -t 1m -i 20 -l 100) & +sleep 2 + +start=`date +%s` +while [ $((`date +%s` - start)) -lt 60 ]; do + pids= + for i in `jot 50`; do + for j in `jot $parallel 62324`; do + /tmp/client $j & + pids="$pids $!" + done + done + for i in $pids; do + wait $i + done +done +pkill server +wait +while pkill swap; do :; done +wait +rm -f /tmp/sctp3.c /tmp/server /tmp/client +exit 0 diff --git a/tools/test/stress2/misc/seekdir.sh b/tools/test/stress2/misc/seekdir.sh new file mode 100755 index 000000000000..a6f3a3a6d19f --- /dev/null +++ b/tools/test/stress2/misc/seekdir.sh @@ -0,0 +1,157 @@ +#!/bin/sh + +# A regression test for seekdir/telldir +# submitted by julian@freebsd.org +# https://reviews.freebsd.org/D2410. +# Fixed by r282485 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > seekdir.c +rm -f /tmp/seekdir +mycc -o seekdir -O2 seekdir.c || exit 1 +rm -f seekdir.c +cd $odir + +mount | grep -q "$mntpoint " && umount -f $mntpoint +mount -o size=1g -t tmpfs tmpfs $mntpoint + +cd $mntpoint +mkdir test2 +/tmp/seekdir > /dev/null +[ `echo $mntpoint/test2/* | wc -w` -eq 1 ] || + { echo FAIL; status=1; } +cd $odir + +while mount | grep $mntpoint | grep -q tmpfs; do + umount $mntpoint || sleep 1 +done +rm -f /tmp/seekdir +exit $status +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CHUNKSIZE 5 +#define TOTALFILES 40 + +static void +SeekDir(DIR *dirp, long loc) +{ + printf("Seeking back to location %ld\n", loc); + seekdir(dirp, loc); +} + +static long +TellDir(DIR *dirp) +{ + long loc; + + loc = telldir(dirp); + printf("telldir assigned location %ld\n", loc); + return (loc); +} + +int +main(int argc, char *argv[]) +{ + DIR *dirp; + int i; + int j; + long offset = 0, prev_offset = 0; + char *files[100]; + char filename[100]; + int fd; + struct dirent *dp = NULL; + + if (chdir("./test2") != 0) { + err(EX_OSERR, "chdir"); + } + + /*****************************************************/ + /* Put a set of sample files in the target directory */ + /*****************************************************/ + + for (i=1; i < TOTALFILES ; i++) + { + sprintf(filename, "file-%d", i); + fd = open(filename, O_CREAT, 0666); + if (fd == -1) { + err(EX_OSERR, "open"); + } + close(fd); + } + dirp = opendir("."); + offset = TellDir(dirp); + for (i = 0; i < 20; i++) + files[i] = malloc(20); + + /*******************************************************/ + /* enumerate and delete small sets of files, one group */ + /* at a time. */ + /*******************************************************/ + do { + + /*****************************************/ + /* Read in up to CHUNKSIZE file names */ + /* i will be the number of files we hold */ + /*****************************************/ + for (i = 0; i < CHUNKSIZE; i++) { + if ((dp = readdir(dirp)) != NULL) { + strcpy(files[i], dp->d_name); + + printf("readdir (%ld) returned file %s\n", + offset, files[i]); + + prev_offset = offset; + offset = TellDir(dirp); + + } else { + printf("readdir returned null\n"); + break; + } + } + +/****************************************************************/ + /* Simuate the last entry not fitting into our (samba's) buffer */ + /* If we read someting in on the last slot, push it back */ + /* Pretend it didn't fit. This is approximately what SAMBA does.*/ +/****************************************************************/ + if (dp != NULL) { + /* Step back */ + SeekDir(dirp, prev_offset); + offset = TellDir(dirp); + i--; + printf("file %s returned\n", files[i]); + } + + /*****************************************/ + /* i is the number of names we have left.*/ + /* Delete them. */ + /*****************************************/ + for (j = 0; j < i; j++) { + if (*files[j] == '.') { + printf ("skipping %s\n", files[j]); + } else { + printf("Unlinking file %s\n", files[j]); + if (unlink(files[j]) != 0) { + err(EX_OSERR, "unlink"); + } + } + } + } while (dp != NULL); + + closedir(dirp); + //chdir(".."); + +} diff --git a/tools/test/stress2/misc/segnp.sh b/tools/test/stress2/misc/segnp.sh new file mode 100755 index 000000000000..3dbe91e04550 --- /dev/null +++ b/tools/test/stress2/misc/segnp.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2017 Konstantin Belousov +# +# 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. +# + +# Trigger a SIGSEGV/SIGBUS _not_ caused by an access to the unmapped page. + +uname -a | egrep -q "i386|amd64" || exit 0 +. ../default.cfg + +cat > /tmp/segnp.c < + +int +main(void) +{ + + __asm __volatile ("movw %w0,%%ds\n" : : "q" (0x1117) : "memory"); + printf("Huh ?\n"); +} +EOF +mycc -o /tmp/segnp -Wall -Wextra -O2 /tmp/segnp.c || exit 1 +rm /tmp/segnp.c + +echo "expect: Bus error (core dumped)" +(cd /tmp; /tmp/segnp) +s=$? +[ $s -ne 138 ] && { echo "Expected 138, got $s", exit 1; } + +rm /tmp/segnp /tmp/segnp.core +exit 0 diff --git a/tools/test/stress2/misc/segregs.sh b/tools/test/stress2/misc/segregs.sh new file mode 100755 index 000000000000..0ecc3565546a --- /dev/null +++ b/tools/test/stress2/misc/segregs.sh @@ -0,0 +1,144 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2017 Konstantin Belousov +# +# 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. +# + +# Maxime Villard spotted this problem: +# Issue with segment registers on freebsd-i386 + +# Fixed in r323722 + +[ `uname -m` = "i386" ] || exit 0 + +. ../default.cfg + +cat > /tmp/mvillard_nest.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int b, s; + +static void * +dealloc_ldt(void *arg __unused) +{ + u_int sl; + + for (;;) { + while (atomic_load_acq_int(&b) == 0) + ; + sl = s; + s = 0; + if (sl != 0) + i386_set_ldt(sl, NULL, 1); + atomic_store_rel_int(&b, 0); + } + return (NULL); +} + +static void +func(void) +{ + union descriptor desc; + u_int sel, sl; + + bzero(&desc, sizeof(desc)); + desc.sd.sd_type = SDT_MEMRWA; + desc.sd.sd_dpl = SEL_UPL; + desc.sd.sd_p = 1; + desc.sd.sd_def32 = 1; + desc.sd.sd_gran = 1; + desc.sd.sd_lolimit = 0xffff; + desc.sd.sd_hilimit = 0xf; + sl = i386_set_ldt(LDT_AUTO_ALLOC, &desc, 1); + if ((int)sl == -1) + err(1, "i386_set_ldt"); + sel = LSEL(sl, SEL_UPL); + s = sl; + __asm volatile("movw\t%w0,%%es" : : "r" (sel)); + atomic_store_rel_int(&b, 1); + while (atomic_load_acq_int(&b) != 0) + ; + getpid(); +} + +static void +sigsegv_handler(int signo __unused, siginfo_t *si __unused, void *rctx) +{ + ucontext_t *uc; + + uc = rctx; + uc->uc_mcontext.mc_es = uc->uc_mcontext.mc_ds; +} + +int +main(void) +{ + pthread_t thr; + time_t start; + struct sigaction sa; + int error; + + bzero(&sa, sizeof(sa)); + sa.sa_sigaction = sigsegv_handler; + sa.sa_flags = SA_SIGINFO; + error = sigaction(SIGSEGV, &sa, NULL); + if (error != 0) + err(1, "sigaction SIGSEGV"); + error = sigaction(SIGBUS, &sa, NULL); + if (error != 0) + err(1, "sigaction SIGBUS"); + + error = pthread_create(&thr, NULL, dealloc_ldt, NULL); + if (error != 0) + errc(1, error, "pthread_create"); + + start = time(NULL); + while (time(NULL) - start < 120) + func(); +} +EOF + +mycc -o /tmp/mvillard_nest -Wall -Wextra -O2 -g /tmp/mvillard_nest.c \ + -l pthread || exit 1 +rm /tmp/mvillard_nest.c + +/tmp/mvillard_nest; s=$? + +rm /tmp/mvillard_nest +exit $s diff --git a/tools/test/stress2/misc/select.sh b/tools/test/stress2/misc/select.sh new file mode 100755 index 000000000000..92652b0d41aa --- /dev/null +++ b/tools/test/stress2/misc/select.sh @@ -0,0 +1,168 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# 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. +# + +# The combination of ualarm() firing before and after the select(2) timeout +# triggers select() to return EINTR a number of times. +# Problem only seen on i386. + +# Test scenario suggestion by kib@ + +# "FAIL n = 2389" seen on r302369, no debug build. +# Fixed by: r302573. + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/select.c +mycc -o select -Wall -Wextra -O0 -g select.c -lpthread || exit 1 +rm -f select.c +cd $odir + +/tmp/select +s=$? + +rm -f /tmp/select +exit $s +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static pthread_barrier_t barr; +static sig_atomic_t alarms; +static int lines; + +#define LINES 128000 +#define N 2000 /* also seen fail with N = 20.000 */ +#define PARALLEL 16 /* Fails seen with 1 - 16 */ +#define RUNTIME (10 * 60) + +static void +handler(int i __unused) { + alarms++; +} + +static void +test(void) +{ + struct timeval tv; + int i, n, r, s; + + r = pthread_barrier_wait(&barr); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + errc(1, r, "pthread_barrier_wait"); + + signal(SIGALRM, handler); + s = 0; + for (i = 0; i < lines; i++) { + alarms = 0; + if (arc4random() % 100 < 50) + ualarm(N / 2, 0); + else + ualarm(N * 2, 0); + tv.tv_sec = 0; + tv.tv_usec = N; + n = 0; + do { + r = select(1, NULL, NULL, NULL, &tv); + n++; + } while (r == -1 && errno == EINTR); + if (r == -1) + err(1, "select"); + ualarm(0, 0); + if (n > 2) { + fprintf(stderr, "FAIL n = %d, tv = %ld.%06ld\n", + n, (long)tv.tv_sec, tv.tv_usec); + s = 1; + break; + } + if (alarms > 1) { + fprintf(stderr, "FAIL alarms = %d\n", (int)alarms); + s = 2; + break; + } + + } + + exit(s); +} + +int +main(void) +{ + pthread_barrierattr_t attr; + time_t start; + int e, i, j, pids[PARALLEL], r, status; + + lines = LINES / PARALLEL; + if (lines == 0) + lines = 1; + e = 0; + if ((r = pthread_barrierattr_init(&attr)) != 0) + errc(1, r, "pthread_barrierattr_init"); + if ((r = pthread_barrierattr_setpshared(&attr, + PTHREAD_PROCESS_SHARED)) != 0) + errc(1, r, "pthread_barrierattr_setpshared"); + if ((r = pthread_barrier_init(&barr, &attr, PARALLEL)) != 0) + errc(1, r, "pthread_barrier_init"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + } + for (i = 0; i < PARALLEL; i++) { + waitpid(pids[i], &status, 0); + e += status == 0 ? 0 : 1; + if (status != 0) { + for (j = i + 1; j < PARALLEL; j++) + kill(pids[j], SIGINT); + } + } + } + + if ((r = pthread_barrier_destroy(&barr)) > 0) + errc(1, r, "pthread_barrier_destroy"); + + return (e); +} diff --git a/tools/test/stress2/misc/select3.sh b/tools/test/stress2/misc/select3.sh new file mode 100755 index 000000000000..fde3a5c5430a --- /dev/null +++ b/tools/test/stress2/misc/select3.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Check if M_SELECT leaks: nselect > threads + +m=`vmstat -m | grep -w select | awk '{print $2}'` +threads=`vmstat -z | sed 's/,/ /g' | grep THREAD | awk '{print $4}'` +free=`vmstat -z | sed 's/,/ /g' | grep THREAD | awk '{print $5}'` +[ $m -le $((threads + free)) ] && exit 0 + +echo FAIL +vmstat -m | sed -n '1p; /select/p' +vmstat -z | sed -n '1p;/THREAD/p' +exit 1 diff --git a/tools/test/stress2/misc/selfd.sh b/tools/test/stress2/misc/selfd.sh new file mode 100755 index 000000000000..5af48f0ec34c --- /dev/null +++ b/tools/test/stress2/misc/selfd.sh @@ -0,0 +1,152 @@ +#!/bin/sh + +# +# Copyright (c) 2015 EMC Corp. +# 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. +# + +# selfd regression test attempt for r285310. Not reproduced. +# Watchdog fired seen: https://people.freebsd.org/~pho/stress/log/selfd.txt + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/selfd.c +mycc -o selfd -Wall -Wextra -O0 -g selfd.c -lpthread || exit 1 +rm -f selfd.c +cd $odir + +rm -rf /tmp/stressX.control +daemon sh -c "(cd ../testcases/swap; ./swap -t 10m -i 20 -l 100)" > \ + /dev/null 2>&1 +sleep 2 + +/tmp/selfd +s=$? + +while pgrep -q swap; do + pkill -9 swap +done + +rm -rf /tmp/selfd +exit $s + +EOF +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static pthread_barrier_t barr; + +#define PARALLEL 16 +#define PIPES 32 +#define RUNTIME (5 * 60) + +static void +handler(int s __unused) +{ +} + +static void +test(void) +{ + fd_set rset, tmpl; + struct sigaction sa; + struct timeval timeout; + time_t start; + int fds[PIPES][2], i, n, r; + + r = pthread_barrier_wait(&barr); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + errc(1, r, "pthread_barrier_wait"); + + FD_ZERO(&tmpl); + for (i = 0; i < PIPES; i++) { + if (pipe(fds[i]) == -1) + err(1, "pipe()"); + FD_SET(fds[i][0], &tmpl); + } + sa.sa_handler = handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGALRM, &sa, NULL) == -1) + err(1, "sigaction"); + start = time(NULL); + while ((time(NULL) - start) < 10) { + rset = tmpl; + timeout.tv_sec = 0; + timeout.tv_usec = arc4random() % 10000 + 100; + n = arc4random() % PIPES; + ualarm(arc4random() % 10000 + 100, 0); + write(fds[n][1], "a", 1); + if ((n = select(PIPES, &rset, NULL, NULL, &timeout)) < 0) + if (errno != EINTR) + err(1, "select()"); + ualarm(0, 0); + } + + _exit(0); + +} + +int +main(void) +{ + pthread_barrierattr_t attr; + time_t start; + int i, r; + + if ((r = pthread_barrierattr_init(&attr)) != 0) + errc(1, r, "pthread_barrierattr_init"); + if ((r = pthread_barrierattr_setpshared(&attr, + PTHREAD_PROCESS_SHARED)) != 0) + errc(1, r, "pthread_barrierattr_setpshared"); + if ((r = pthread_barrier_init(&barr, &attr, PARALLEL)) != 0) + errc(1, r, "pthread_barrier_init"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + for (i = 0; i < PARALLEL; i++) + if (fork() == 0) + test(); + for (i = 0; i < PARALLEL; i++) + wait(NULL); + } + + return (0); +} diff --git a/tools/test/stress2/misc/sem.sh b/tools/test/stress2/misc/sem.sh new file mode 100755 index 000000000000..9b229ab662f5 --- /dev/null +++ b/tools/test/stress2/misc/sem.sh @@ -0,0 +1,142 @@ +#!/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. +# + +# 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 +mycc -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/tools/test/stress2/misc/sem_post.sh b/tools/test/stress2/misc/sem_post.sh new file mode 100755 index 000000000000..2f1d7c4c004f --- /dev/null +++ b/tools/test/stress2/misc/sem_post.sh @@ -0,0 +1,107 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# No problems seen. + +cat > /tmp/sem_post.c < +#include +#include +#include +#include +#include +#include +#include +#include + +static sem_t semaphore; + +static void * +threadfunc(void *data __unused) { + + for (;;) { + usleep(arc4random() % 100); + if (sem_wait(&semaphore) == -1) + err(1, "sem_wait"); + usleep(arc4random() % 100); + if (arc4random() % 100 < 3) + sleep(1); + if (sem_post(&semaphore) == -1) + err(1, "sem_post"); + } + + return (NULL); +} + +int +main(void) { + pthread_t mythread; + time_t start; + int r; + + // initialize semaphore and set value to 1 + if (sem_init(&semaphore, 0, 1) == -1) + err(1, "sem_init"); + + r = pthread_create(&mythread, NULL, threadfunc, NULL); + if (r != 0) + errc(1, r, "pthread_create"); + + usleep(50); + alarm(300); + start = time(NULL); + while (time(NULL) - start < 120) { + usleep(arc4random() % 100); + if (sem_wait(&semaphore) == -1) + err(1, "sem_wait"); + usleep(arc4random() % 100); + if (arc4random() % 100 < 3) + sleep(1); + if (sem_post(&semaphore) == -1) + err(1, "sem_post"); + } + if ((r = pthread_kill(mythread, SIGINT)) != 0) + errc(1, r, "pthread_kill"); + if ((r = pthread_join(mythread, NULL)) != 0) + errc(1, r, "pthread_join"); + + return (0); +} +EOF +cc -o /tmp/sem_post -Wall -Wextra -O2 /tmp/sem_post.c -lpthread || exit 1 +(cd ../testcases/swap; ./swap -t 3m -i 30 -h -l 100) & +sleep 20 +for i in `jot 128`; do + /tmp/sem_post > /dev/null & +done +while pgrep -q sem_post; do sleep .5; done +while pkill swap; do :; done +wait +rm -f /tmp/sem_post /tmp/sem_post.c +exit 0 diff --git a/tools/test/stress2/misc/sem_timedwait.sh b/tools/test/stress2/misc/sem_timedwait.sh new file mode 100755 index 000000000000..33e5c1933f37 --- /dev/null +++ b/tools/test/stress2/misc/sem_timedwait.sh @@ -0,0 +1,161 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# No problems seen. + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/sem_timedwait.c +mycc -o sem_timedwait -Wall -Wextra -O0 -g sem_timedwait.c || exit 1 +rm -f sem_timedwait.c +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart +newfs $newfs_flags md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +(cd $odir/../testcases/swap; ./swap -t 5m -i 20 -h -l 100) > /dev/null & +cd $mntpoint +nice $dir/sem_timedwait +s=$? +[ -f sem_timedwait.core -a $s -eq 0 ] && + { ls -l sem_timedwait.core; mv sem_timedwait.core $dir; s=1; } +cd $odir + +while pkill swap; do :; done +wait +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +rm -rf $dir/sem_timedwait +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#define PARALLEL 64 +#define RUNTIME (5 * 60) +#define SYNC 0 + +static void +test(void) +{ + struct timespec tm; + sem_t sem; + int i; + + atomic_add_int(&share[SYNC], 1); + while (share[SYNC] != PARALLEL) + ; + + sem_init(&sem, 0, 0); + i = 0; + do { + clock_gettime(CLOCK_REALTIME, &tm); + tm.tv_nsec += 1000; + if (tm.tv_nsec >= 1000000000L) { + tm.tv_nsec -= 1000000000L; + tm.tv_sec++; + } + + if (++i == 1000) + sem_post(&sem); + else + usleep(10000); + } while (sem_timedwait(&sem, &tm) == -1); + + _exit(0); +} + +int +main(void) +{ + pid_t pids[PARALLEL]; + size_t len; + time_t start; + int e, i, status; + + e = 0; + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + start = time(NULL); + while ((time(NULL) - start) < RUNTIME && e == 0) { + share[SYNC] = 0; + for (i = 0; i < PARALLEL; i++) { + if ((pids[i] = fork()) == 0) + test(); + if (pids[i] == -1) + err(1, "fork()"); + } + for (i = 0; i < PARALLEL; i++) { + if (waitpid(pids[i], &status, 0) == -1) + err(1, "waitpid(%d)", pids[i]); + if (status != 0) { + if (WIFSIGNALED(status)) + fprintf(stderr, + "pid %d exit signal %d\n", + pids[i], WTERMSIG(status)); + } + e += status == 0 ? 0 : 1; + } + } + + return (e); +} diff --git a/tools/test/stress2/misc/sem_wait.sh b/tools/test/stress2/misc/sem_wait.sh new file mode 100755 index 000000000000..6d8bc49c9199 --- /dev/null +++ b/tools/test/stress2/misc/sem_wait.sh @@ -0,0 +1,109 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Dell EMC Isilon +# +# 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. +# + +# "panic: vm_page_free_prep: freeing mapped page 0x657936c" seen. +# https://people.freebsd.org/~pho/stress/log/sem_wait.txt +# Fixed by r350005 + +. ../default.cfg + +cat > /tmp/sem_wait.c < +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static sem_t *semaphore; + +static void * +test(void) { + + setproctitle("%s", __func__); + alarm(300); + for (;;) { + if (sem_wait(semaphore) == -1) + err(1, "sem_wait"); + if (sem_post(semaphore) == -1) + err(1, "sem_post"); + } +} + +int +main(void) { + pid_t pid; + size_t len; + time_t start; + + setproctitle("%s", __func__); + alarm(300); + len = PAGE_SIZE; + if ((semaphore = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + // initialize semaphore and set value to 1 + if (sem_init(semaphore, 1, 1) == -1) + err(1, "sem_init"); + + if ((pid = fork()) == 0) + test(); + if (pid == -1) + err(1, "fork()"); + + usleep(50); + alarm(300); + start = time(NULL); + while (time(NULL) - start < 60) { + if (sem_wait(semaphore) == -1) + err(1, "sem_wait"); + if (sem_post(semaphore) == -1) + err(1, "sem_post"); + } + kill(pid, SIGHUP); + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid()"); + + return (0); +} +EOF +mycc -o /tmp/sem_wait -Wall -Wextra -O2 /tmp/sem_wait.c || exit 1 +timeout 6m /tmp/sem_wait; s=$? +[ $s -eq 124 ] && echo "Timed out" +rm -f /tmp/sem_wait /tmp/sem_wait.c +exit $s diff --git a/tools/test/stress2/misc/sendfile.sh b/tools/test/stress2/misc/sendfile.sh new file mode 100755 index 000000000000..408564bef0e2 --- /dev/null +++ b/tools/test/stress2/misc/sendfile.sh @@ -0,0 +1,213 @@ +#!/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 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 +mycc -o sendfile -Wall sendfile.c -pthread +rm -f sendfile.c +[ -d "$RUNDIR" ] || mkdir -p $RUNDIR +cd $RUNDIR + +in=inputFile +out=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 status=none + /tmp/sendfile $in $out 12345 + cmp $in $out || { echo FAIL; 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_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/tools/test/stress2/misc/sendfile10.sh b/tools/test/stress2/misc/sendfile10.sh new file mode 100755 index 000000000000..0bfc4a83da71 --- /dev/null +++ b/tools/test/stress2/misc/sendfile10.sh @@ -0,0 +1,313 @@ +#!/bin/sh + +# +# Copyright (c) 2017 Dell EMC Isilon +# 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. +# + +# Copy of sendfile8.sh with size validation added. + +# No problems seen (after r315910). + +. ../default.cfg +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/sendfile10.c +mycc -o sendfile10 -Wall -Wextra -O0 -g sendfile10.c || exit 1 +rm -f sendfile10.c +cd $odir + +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 1g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags -n md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +cd $mntpoint +dd if=/dev/random of=template bs=1m count=50 status=none +/tmp/sendfile10 template in out 76543 +s=$? +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 +done +[ $i -eq 6 ] && exit 1 +mdconfig -d -u $mdstart +rm -rf /tmp/sendfile10 +exit $s + +EOF +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile off_t *share; +static int port; +static char *input, *output; + +#define BUFSIZE 4096 +#define MX (100 * 1024 * 1024) +#define OSZ 1 +#define PARALLEL 1 +#define RUNTIME (2 * 60) +#define SZ 0 + +static void +mess(void) +{ + off_t length; + int fd; + + if ((fd = open(input, O_RDWR)) == -1) + err(1, "open(%s)", input); + length = arc4random() % MX; + if (ftruncate(fd, length) == -1) + err(1, "truncate(%jd)", length); + share[SZ] = length; + close(fd); +} + +static void +reader(void) { + off_t t; + int tcpsock, msgsock; + int on; + socklen_t len; + struct sockaddr_in inetaddr, inetpeer; + int n, *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); + alarm(10); + if ((msgsock = accept(tcpsock, + (struct sockaddr *)&inetpeer, &len)) < 0) + err(1, "accept(), %s:%d", __FILE__, __LINE__); + alarm(0); + + t = 0; + if ((buf = malloc(BUFSIZE)) == NULL) + err(1, "malloc(%d), %s:%d", BUFSIZE, __FILE__, __LINE__); + + if ((fd = open(output, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) + err(1, "open(%s)", output); + + 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); +#if 0 + if (t != share[SZ] && t != share[OSZ]) { + fprintf(stderr, "1) Send size %lu, original size %lu, " + "receive size %lu\n", + (unsigned long)share[SZ], + (unsigned long)share[OSZ], + (unsigned long)t); + exit(1); + } +#endif + return; +} + +static void +writer(void) { + struct sockaddr_in inetaddr; + struct hostent *hostent; + struct stat statb; + off_t off = 0; + size_t size; + int i, r, fd; + int tcpsock, on; + + 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__); + + size = getpagesize() -4; + if (setsockopt(tcpsock, + SOL_SOCKET, SO_SNDBUF, (void *)&size, sizeof(size)) < 0) + err(1, "setsockopt(SO_SNDBUF), %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_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 ((fd = open(input, O_RDONLY)) == -1) + err(1, "open(%s)", input); + + if (fstat(fd, &statb) != 0) + err(1, "stat(%s)", input); + share[SZ] = statb.st_size; + if (sendfile(fd, tcpsock, 0, statb.st_size, NULL, &off, 0) == -1) + err(1, "sendfile"); + close(fd); + close(tcpsock); + + return; +} + +static void +test(void) +{ + pid_t pid; + + if ((pid = fork()) == 0) { + writer(); + _exit(0); + } + reader(); + kill(pid, SIGINT); + if (waitpid(pid, NULL, 0) != pid) + err(1, "waitpid(%d)", pid); + + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + struct stat statin, statorig, statout; + size_t len; + time_t start; + int e, i, pids[PARALLEL], status; + char help[80], *template; + + if (argc != 5) { + fprintf(stderr, "Usage: %s