svn commit: r305766 - user/pho/stress2/misc

Peter Holm pho at FreeBSD.org
Tue Sep 13 13:23:26 UTC 2016


Author: pho
Date: Tue Sep 13 13:23:24 2016
New Revision: 305766
URL: https://svnweb.freebsd.org/changeset/base/305766

Log:
  Added new regression tests.
  
  Sponsored by:	Dell EMC Isilon

Added:
  user/pho/stress2/misc/ftruncate.sh   (contents, props changed)
  user/pho/stress2/misc/mmap29.sh   (contents, props changed)
  user/pho/stress2/misc/tmpfs14.sh   (contents, props changed)
  user/pho/stress2/misc/unix_socket_detach2.sh   (contents, props changed)

Added: user/pho/stress2/misc/ftruncate.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/ftruncate.sh	Tue Sep 13 13:23:24 2016	(r305766)
@@ -0,0 +1,195 @@
+#!/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.
+#
+# $FreeBSD$
+#
+
+# 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 <sys/param.h>
+#include <sys/resource.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fts.h>
+#include <libutil.h>
+#include <pthread.h>
+#include <pwd.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#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 <dir>\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();
+
+	arc4random_stir();
+	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);
+}

Added: user/pho/stress2/misc/mmap29.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/mmap29.sh	Tue Sep 13 13:23:24 2016	(r305766)
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+# $FreeBSD$
+
+# Test scenario by: David Cross <dcrosstech at gmail.com>
+
+# "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 /mnt/mmap29
+cd /tmp
+cat > mmap29.c <<EOFHERE
+#include <sys/param.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(int argc, char **argv)
+{
+        int fd;
+        unsigned char *memrange;
+
+	if (argc != 2) {
+		fprintf(stderr, "Usage: %s <file>\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 /mnt/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
+rm mmap29
+exit 0

Added: user/pho/stress2/misc/tmpfs14.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/tmpfs14.sh	Tue Sep 13 13:23:24 2016	(r305766)
@@ -0,0 +1,114 @@
+#!/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.
+#
+# $FreeBSD$
+#
+
+# Verify that mmap access updates mtime and ctime on files located on a
+# tmpfs FS.
+# Fixed by r277828 and r277969.
+
+[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
+
+. ../default.cfg
+
+odir=`pwd`
+cd /tmp
+sed '1,/^EOF/d' < $odir/$0 > tmpfs14.c
+rm -f /tmp/tmpfs14
+mycc -o tmpfs14 -Wall -Wextra -g -O2 tmpfs14.c || exit 1
+rm -f tmpfs14.c
+cd $odir
+
+mount | grep -q "$mntpoint " && umount -f $mntpoint
+mount -t tmpfs tmpfs /mnt
+
+(cd $mntpoint; /tmp/tmpfs14) &
+
+sleep .5
+set `stat -f "%m %c" $mntpoint/test`
+m1=$1
+c1=$2
+while pgrep -q tmpfs14; do
+	set `stat -f "%m %c" $mntpoint/test`
+	[ "$m1" != "$1" ] && break
+	[ "$c1" != "$2" ] && break
+	sleep 1
+done
+[ "$m1" = "$1" -o "$c1" = "$2" ] &&
+    echo "FAIL Unchanged time $m1 $c1 / $1 $2"
+wait
+
+while mount | grep $mntpoint | grep -q /dev/md; do
+	umount $mntpoint || sleep 1
+done
+rm -f /tmp/tmpfs14
+exit 0
+EOF
+
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+
+char *file = "test";
+
+int
+main(void)
+{
+	char *p;
+	size_t len;
+	int fd, i;
+
+	if ((fd = open(file, O_RDWR | O_CREAT, 0644)) == -1)
+		err(1, "open(%s)", file);
+	if (write(fd, "abcdef", 7) < 0)
+		err(1, "write");
+	close(fd);
+
+	len = getpagesize();
+	for (i = 0; i < 10; i++) {
+		sleep(1);
+		if ((fd = open(file, O_RDWR | O_CREAT, 0644)) == -1)
+			err(1, "open(%s)", file);
+
+		if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED)
+			err(1, "mmap");
+
+		p[0] = '0' + i;
+		munmap(p, len);
+		close(fd);
+	}
+
+	return 0;
+}

Added: user/pho/stress2/misc/unix_socket_detach2.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/unix_socket_detach2.sh	Tue Sep 13 13:23:24 2016	(r305766)
@@ -0,0 +1,159 @@
+#!/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.
+#
+# $FreeBSD$
+#
+
+# Threaded version of unix_socket_detach.sh by
+# Mark Johnston <markj at FreeBSD.org>
+
+# "panic: __rw_wlock_hard: recursing but non-recursive rw unp_link_rwlock @
+#  ../../../kern/uipc_usrreq.c:655" seen.
+# Fixed in r303855.
+
+. ../default.cfg
+
+cd /tmp
+cat > unix_socket_detach2.c <<EOF
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <machine/atomic.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static sig_atomic_t done_testing;
+static struct sockaddr_un sun;
+static long success;
+static char *file;
+
+static void
+handler(int i __unused) {
+	done_testing = 1;
+}
+
+static void *
+t1(void *data __unused)
+{
+	int one, sd;
+
+	while (done_testing == 0) {
+		sd = socket(PF_LOCAL, SOCK_STREAM, 0);
+		if (sd < 0)
+			err(1, "socket");
+		one = 1;
+		if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &one,
+		    sizeof(one)) < 0)
+			err(1, "setsockopt");
+		if (bind(sd, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
+			close(sd);
+			continue;
+		}
+		if (listen(sd, 10) != 0)
+			err(1, "listen");
+		usleep(random() % 10);
+		success++;
+		(void)close(sd);
+		(void)unlink(file);
+	}
+
+	return (NULL);
+}
+
+static void *
+t2(void *data __unused)
+{
+	int flags, sd;
+
+	while (done_testing == 0) {
+		sd = socket(PF_LOCAL, SOCK_STREAM, 0);
+		if (sd < 0)
+			err(1, "socket");
+		if ((flags = fcntl(sd, F_GETFL, 0)) < 0)
+			err(1, "fcntl(F_GETFL)");
+		flags |= O_NONBLOCK;
+		if (fcntl(sd, F_SETFL, flags) < 0)
+			err(1, "fcntl(F_SETFL)");
+		(void)connect(sd, (struct sockaddr *)&sun, sizeof(sun));
+		usleep(random() % 10);
+		(void)close(sd);
+	}
+
+	return (NULL);
+}
+
+int
+main(void)
+{
+	pthread_t tid[2];
+	int r;
+
+	file = "unix_socket_detach2.socket";
+	memset(&sun, 0, sizeof(sun));
+	sun.sun_family = AF_LOCAL;
+	sun.sun_len = sizeof(sun);
+	snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", file);
+
+	signal(SIGALRM, handler);
+	alarm(300);
+
+	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");
+
+	if (success < 100) {
+		fprintf(stderr, "FAIL with only %ld\n", success);
+		return (1);
+	}
+
+	return (0);
+}
+EOF
+
+mycc -o unix_socket_detach2 -Wall -Wextra -O2 -g unix_socket_detach2.c \
+    -lpthread || exit 1
+
+rm -f unix_socket_detach2.socket
+/tmp/unix_socket_detach2
+s=$?
+
+rm -f unix_socket_detach2.c unix_socket_detach2 unix_socket_detach2.socket
+exit $s


More information about the svn-src-user mailing list