svn commit: r215853 - projects/stress2/misc
Peter Holm
pho at FreeBSD.org
Fri Nov 26 05:29:19 UTC 2010
Author: pho
Date: Fri Nov 26 05:29:19 2010
New Revision: 215853
URL: http://svn.freebsd.org/changeset/base/215853
Log:
Vnode reference leak tests added.
Added:
projects/stress2/misc/vunref.sh (contents, props changed)
projects/stress2/misc/vunref2.sh (contents, props changed)
Added: projects/stress2/misc/vunref.sh
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/stress2/misc/vunref.sh Fri Nov 26 05:29:19 2010 (r215853)
@@ -0,0 +1,225 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2010 Peter Holm <pho at FreeBSD.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (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: projects/stress2/misc/umountf4.sh 197027 2009-09-09 10:13:56Z pho $
+#
+
+# Vnode reference leak test scenario by kib at .
+# Will fail with "umount: unmount of /mnt5 failed: Device busy"
+# vnode leak not seen on HEAD.
+
+[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
+
+. ../default.cfg
+here=`pwd`
+mounts=2 # Number of parallel scripts
+D=$diskimage
+
+[ -d "$RUNDIR" ] || mkdir $RUNDIR
+cd $RUNDIR
+
+if [ $# -eq 0 ]; then
+ sed '1,/^EOF/d' < $here/$0 > vunref.c
+ cc -o vunref -Wall -Wextra -O2 vunref.c
+ rm -f vunref.c
+ cd $here
+
+ rm -f $RUNDIR/active.*
+ for i in `jot $mounts`; do
+ m=$(( i + mdstart - 1 ))
+ [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m
+ mount | grep "$mntpoint" | grep -q md$m && umount -f ${mntpoint}$m
+ mdconfig -l | grep -q md$m && mdconfig -d -u $m
+
+ dede $D.$m 1m 10
+ mdconfig -a -t vnode -f $D.$m -u $m
+ bsdlabel -w md$m auto
+ newfs md${m}$part > /dev/null 2>&1
+ done
+
+ # start the parallel tests
+ for i in `jot $mounts`; do
+ m=$((i + mdstart - 1))
+ $0 mmap $m &
+ sleep 0.2
+ $0 $m &
+ done
+
+ sleep 2
+
+ while [ ! -z "`ls $RUNDIR/active.* 2>/dev/null`" ] ; do
+ ../testcases/swap/swap -t 2m -i 20
+ done
+
+ for i in `jot $mounts`; do
+ wait; wait
+ done
+
+ for i in `jot $mounts`; do
+ m=$((i + mdstart - 1))
+ mdconfig -d -u $m
+ rm -f $D$m
+ done
+ rm -f $RUNDIR/vunref $RUNDIR/active.* $diskimage.* ${mntpoint}*/p*
+
+else
+ if [ $1 = mmap ]; then
+ touch $RUNDIR/active.$2
+ for i in `jot 500`; do
+ cd ${mntpoint}$2
+ $RUNDIR/vunref > /dev/null 2>&1
+ cd /
+ [ -f $RUNDIR/active.$2 ] || exit
+ sleep 0.1
+ done
+ rm -f $RUNDIR/active.$2
+ else
+ # The test: Parallel mount and unmounts
+ m=$1
+ mount $opt /dev/md${m}$part ${mntpoint}$m
+ while [ -f $RUNDIR/active.$m ] ; do
+ sleep 0.1
+ n=0
+ while mount | grep -qw $mntpoint$m; do
+ umount ${mntpoint}$m > /dev/null 2>&1 && n=0
+ n=$((n + 1))
+ if [ $n -gt 600 ]; then
+ echo "*** Leak detected ***"
+ fstat $mntpoint$m
+ rm -f $RUNDIR/active.*
+ exit 1
+ fi
+ sleep 0.1
+ done
+ mount $opt /dev/md${m}$part ${mntpoint}$m
+ done
+ mount | grep "$mntpoint" | grep -q md$m && umount ${mntpoint}$m
+ fi
+fi
+exit
+EOF
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <unistd.h>
+#include <err.h>
+
+#define INPUTFILE "/bin/date"
+
+int
+test(void)
+{
+ int i;
+ pid_t pid;
+ char file[128];
+ int fdin, fdout;
+ char *src, *dst;
+ struct stat statbuf;
+
+ pid = getpid();
+ for (i = 0; i < 100; i++) {
+ sprintf(file,"p%05d.%05d", pid, i);
+
+ if ((fdin = open(INPUTFILE, O_RDONLY)) < 0)
+ err(1, INPUTFILE);
+
+ if ((fdout = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0)
+ err(1, "%s", file);
+
+ if (fstat(fdin, &statbuf) < 0)
+ err(1, "fstat error");
+
+ if (lseek(fdout, statbuf.st_size - 1, SEEK_SET) == -1)
+ err(1, "lseek error");
+
+ /* write a dummy byte at the last location */
+ if (write(fdout, "", 1) != 1)
+ err(1, "write error");
+
+ if ((src = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0)) ==
+ (caddr_t) - 1)
+ err(1, "mmap error for input");
+
+ if ((dst = mmap(0, statbuf.st_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fdout, 0)) == (caddr_t) - 1)
+ err(1, "mmap error for output");
+
+ memcpy(dst, src, statbuf.st_size);
+
+
+ if (munmap(src, statbuf.st_size) == -1)
+ err(1, "munmap");
+ close(fdin);
+
+ if (munmap(dst, statbuf.st_size) == -1)
+ err(1, "munmap");
+ close(fdout);
+
+ if (unlink(file) == -1)
+ err(3, "unlink(%s)", file);
+ }
+
+
+ return (0);
+}
+
+int
+main()
+{
+ int i;
+ char path[MAXPATHLEN+1];
+ struct statfs buf;
+
+ if (getcwd(path, sizeof(path)) == NULL)
+ err(1, "getcwd()");
+
+ if (statfs(path, &buf) < 0)
+ err(1, "statfs(%s)", path);
+
+ if (!strcmp(buf.f_mntonname, "/"))
+ return (1);
+
+ for (i = 0; i < 2; i++) {
+ if (fork() == 0)
+ test();
+ }
+ for (i = 0; i < 2; i++)
+ wait(NULL);
+
+ return (0);
+}
Added: projects/stress2/misc/vunref2.sh
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/stress2/misc/vunref2.sh Fri Nov 26 05:29:19 2010 (r215853)
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2010 Peter Holm <pho at FreeBSD.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (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: projects/stress2/misc/umountf4.sh 197027 2009-09-09 10:13:56Z pho $
+#
+
+# Vnode reference leak test scenario.
+# Will fail with "umount: unmount of /mnt5 failed: Device busy"
+# vnode leak not seen on HEAD.
+
+[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
+
+. ../default.cfg
+
+mount | grep "${mntpoint}" | grep -q md${mdstart}${part} && umount -f $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 -U md${mdstart}${part} > /dev/null
+mount /dev/md${mdstart}${part} $mntpoint
+chmod 777 ${mntpoint}
+
+export runRUNTIME=5m
+export LOAD=100
+export swapLOAD=100
+export RUNDIR=${mntpoint}/stressX
+
+for i in `jot 10`; do
+ su $testuser -c "\
+ cd ..; testcases/run/run testcases/mmap/mmap testcases/swap/swap
+ "
+
+ sync;sync;sync
+ sleep 5
+ n=0
+ while mount | grep -qw $mntpoint; do
+ umount ${mntpoint} > /dev/null 2>&1 || sleep 0.1
+ n=$((n + 1))
+ if [ $n -gt 25 ]; then
+ echo "*** Leak detected ***"
+ fstat $mntpoint
+ exit 1
+ fi
+ done
+ mount /dev/md${mdstart}${part} $mntpoint
+done
+
+umount $mntpoint
+mdconfig -d -u $mdstart
More information about the svn-src-projects
mailing list