git: 8296d2f9a3bf - main - stress2: Added new tests

From: Peter Holm <pho_at_FreeBSD.org>
Date: Wed, 15 Dec 2021 08:57:50 UTC
The branch main has been updated by pho:

URL: https://cgit.FreeBSD.org/src/commit/?id=8296d2f9a3bf8e68de2f8e3f98f911b9b9542dad

commit 8296d2f9a3bf8e68de2f8e3f98f911b9b9542dad
Author:     Peter Holm <pho@FreeBSD.org>
AuthorDate: 2021-12-15 08:57:15 +0000
Commit:     Peter Holm <pho@FreeBSD.org>
CommitDate: 2021-12-15 08:57:15 +0000

    stress2: Added new tests
---
 tools/test/stress2/misc/all.exclude |   1 +
 tools/test/stress2/misc/avx_sig.sh  |  16 +++++
 tools/test/stress2/misc/unionfs7.sh | 103 ++++++++++++++++++++++++++++++++
 tools/test/stress2/misc/vm_fault.sh | 113 ++++++++++++++++++++++++++++++++++++
 4 files changed, 233 insertions(+)

diff --git a/tools/test/stress2/misc/all.exclude b/tools/test/stress2/misc/all.exclude
index f14a83668079..0898673a53e3 100644
--- a/tools/test/stress2/misc/all.exclude
+++ b/tools/test/stress2/misc/all.exclude
@@ -73,6 +73,7 @@ syzkaller43.sh		WiP								20210906
 syzkaller46.sh		WiP								20210925
 syzkaller47.sh		WiP								20210925
 truss3.sh		WiP								20200915
+unionfs7.sh		https://people.freebsd.org/~pho/stress/log/log0202.txt		20211215
 
 # Test not to run for other reasons:
 
diff --git a/tools/test/stress2/misc/avx_sig.sh b/tools/test/stress2/misc/avx_sig.sh
new file mode 100755
index 000000000000..2a328daa340d
--- /dev/null
+++ b/tools/test/stress2/misc/avx_sig.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# Test AVX context integrity under ctx switches and signals (amd64)
+
+src=/usr/src/tools/test/avx_sig/avx_sig.c
+[ -f $src ] || exit 0
+[ `uname -p` != "amd64" ] && exit 0
+
+cd /tmp
+cc -Wall -Wextra -O -g -o avx_sig $src -lpthread || exit 1
+
+timeout 1m /tmp/avx_sig; s=$?
+[ $s -eq 124 ] && s=0
+
+rm /tmp/avx_sig
+exit $s
diff --git a/tools/test/stress2/misc/unionfs7.sh b/tools/test/stress2/misc/unionfs7.sh
new file mode 100755
index 000000000000..58fad6183517
--- /dev/null
+++ b/tools/test/stress2/misc/unionfs7.sh
@@ -0,0 +1,103 @@
+#!/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.
+#
+
+# unionfs(8) test
+
+# "unionfs_get_node_status: 0xfffffe018f356770 is not exclusive locked but
+# should be" seen.
+# https://people.freebsd.org/~pho/stress/log/log0202.txt
+
+[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
+. ../default.cfg
+
+md1=$mdstart
+md2=$((md1 + 1))
+mp1=/mnt$md1
+mp2=/mnt$md2
+mkdir -p $mp1 $mp2
+set -e
+for i in $mp1 $mp2; do
+	mount | grep -q "on $i " && umount -f $i
+done
+for i in $md1 $md2; do
+	mdconfig -l | grep -q md$i && mdconfig -d -u $i
+done
+
+mdconfig -a -t swap -s 4g -u $md1
+mdconfig -a -t swap -s 4g -u $md2
+newfs $newfs_flags -n md$md1 > /dev/null
+newfs $newfs_flags -n md$md2 > /dev/null
+mount /dev/md$md1 $mp1
+mount /dev/md$md2 $mp2
+
+mount -t unionfs -o noatime $mp1 $mp2
+set +e
+mount | grep -E "$mp1|$mp2"
+
+export CTRLDIR=$mp2/stressX.control
+export INCARNATIONS=10
+export LOAD=80
+export RUNDIR=$mp2/stressX
+export runRUNTIME=5m
+export rwLOAD=80
+export symlinkLOAD=80
+
+export TESTPROGS="
+testcases/lockf2/lockf2
+testcases/symlink/symlink
+testcases/openat/openat
+testcases/rw/rw
+testcases/fts/fts
+testcases/link/link
+testcases/lockf/lockf
+testcases/creat/creat
+testcases/mkdir/mkdir
+testcases/rename/rename
+testcases/mkfifo/mkfifo
+testcases/dirnprename/dirnprename
+testcases/dirrename/dirrename
+testcases/swap/swap
+"
+
+cp -r ../../stress2 $mp2
+export TESTPROGS=`echo $TESTPROGS | sed 's/\n/ /g'`
+
+set +e
+chmod 777 $mp2
+su $testuser -c \
+	"(cd $mp2/stress2; ./testcases/run/run $TESTPROGS)"
+
+umount $mp2	# The unionfs mount
+umount $mp2
+n=`find $mp1/stressX | wc -l`
+[ $n -eq 1 ] && s=0 || { find $mp1/stressX -ls | head -12; s=1; }
+umount $mp1
+mdconfig -d -u $md2
+mdconfig -d -u $md1
+exit $s
diff --git a/tools/test/stress2/misc/vm_fault.sh b/tools/test/stress2/misc/vm_fault.sh
new file mode 100755
index 000000000000..540aa609a301
--- /dev/null
+++ b/tools/test/stress2/misc/vm_fault.sh
@@ -0,0 +1,113 @@
+#!/bin/sh
+
+# Regression test for D33416 vm_fault: Fix vm_fault_populate()'s handling of VM_FAULT_WIRE
+# Bug report: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260347
+
+# Test scenario by: martin
+
+# Fixed by 88642d978a99
+
+[ `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/skeleton
+mkdir -p $dir
+
+cd $dir
+cat > skeleton.c <<EOF
+/*
+ * KLD Skeleton
+ * Inspired by Andrew Reiter's Daemonnews article
+ */
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/systm.h>  /* uprintf */
+#include <sys/errno.h>
+#include <sys/param.h>  /* defines used in kernel.h */
+#include <sys/kernel.h> /* types used in module initialization */
+
+#define BUFFER_SIZE 10*1000*1024 // 10 MB
+static char gBuffer[BUFFER_SIZE];
+
+static int demo_init (void)
+{
+  for (int i=0; i<BUFFER_SIZE; i++)
+  {
+    gBuffer[i] = 'A';
+  }
+  return 0;
+}
+
+static void demo_exit (void)
+{
+  for (int i=0; i<BUFFER_SIZE; i++)
+  {
+    gBuffer[i] += 1;
+  }
+}
+
+/*
+ * Load handler that deals with the loading and unloading of a KLD.
+ */
+
+static int
+skel_loader(struct module *m, int what, void *arg)
+{
+  int err = 0;
+
+  switch (what) {
+  case MOD_LOAD:                /* kldload */
+    uprintf("Skeleton KLD loaded.\n");
+    demo_init();
+    break;
+  case MOD_UNLOAD:
+    uprintf("Skeleton KLD unloaded.\n");
+    demo_exit();
+    break;
+  default:
+    err = EOPNOTSUPP;
+    break;
+  }
+  return(err);
+}
+
+/* Declare this module to the rest of the kernel */
+
+static moduledata_t skel_mod = {
+  "skel",
+  skel_loader,
+  NULL
+};
+
+DECLARE_MODULE(skeleton, skel_mod, SI_SUB_KLD, SI_ORDER_ANY);
+EOF
+
+cat > Makefile <<EOF
+KMOD= skeleton
+SRCS= skeleton.c
+
+.include <bsd.kmod.mk>
+EOF
+
+make
+old=`sysctl -n vm.stats.vm.v_wire_count`
+kldload $dir/skeleton.ko
+kldunload $dir/skeleton.ko
+leak=$((`sysctl -n vm.stats.vm.v_wire_count` - old))
+if [ $leak -gt 25 ]; then
+	echo "Test leaked $leak pages in the skeleton.ko module"
+	s=1
+else
+	s=0
+fi
+
+cd $odir
+rm -rf $dir
+exit $s