From owner-svn-src-user@freebsd.org  Wed Jul 15 14:29:01 2015
Return-Path: <owner-svn-src-user@freebsd.org>
Delivered-To: svn-src-user@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id DE69499B1CC
 for <svn-src-user@mailman.ysv.freebsd.org>;
 Wed, 15 Jul 2015 14:29:01 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id C25161A15;
 Wed, 15 Jul 2015 14:29:01 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from svnmir.geo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6FET1uI096895;
 Wed, 15 Jul 2015 14:29:01 GMT (envelope-from pho@FreeBSD.org)
Received: (from pho@localhost)
 by svnmir.geo.freebsd.org (8.14.9/8.14.9/Submit) id t6FESwtI096876;
 Wed, 15 Jul 2015 14:28:58 GMT (envelope-from pho@FreeBSD.org)
Message-Id: <201507151428.t6FESwtI096876@svnmir.geo.freebsd.org>
X-Authentication-Warning: svnmir.geo.freebsd.org: pho set sender to
 pho@FreeBSD.org using -f
From: Peter Holm <pho@FreeBSD.org>
Date: Wed, 15 Jul 2015 14:28:58 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r285602 - user/pho/stress2/misc
X-SVN-Group: user
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-user@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 15 Jul 2015 14:29:02 -0000

Author: pho
Date: Wed Jul 15 14:28:57 2015
New Revision: 285602
URL: https://svnweb.freebsd.org/changeset/base/285602

Log:
  Fix use of pthread_create(3).
  
  Sponsored by:	EMC / Isilon storage division
  Pointed out by:	 ngie

Modified:
  user/pho/stress2/misc/fifo2.sh
  user/pho/stress2/misc/kevent6.sh
  user/pho/stress2/misc/kevent7.sh
  user/pho/stress2/misc/kevent8.sh
  user/pho/stress2/misc/mlockall3.sh
  user/pho/stress2/misc/mmap7.sh
  user/pho/stress2/misc/msync.sh
  user/pho/stress2/misc/sigreturn.sh
  user/pho/stress2/misc/sndstat.sh
  user/pho/stress2/misc/umountf7.sh

Modified: user/pho/stress2/misc/fifo2.sh
==============================================================================
--- user/pho/stress2/misc/fifo2.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/fifo2.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -172,7 +172,7 @@ main(void)
 	struct rlimit limit;
 	pthread_t cp[50];
 	time_t start;
-	int j;
+	int e, j;
 
 	if ((pw = getpwnam("nobody")) == NULL)
 		err(1, "no such user: nobody");
@@ -201,8 +201,8 @@ main(void)
 		if (fork() == 0) {
 			arc4random_stir();
 			for (j = 0; j < 1; j++)
-				if (pthread_create(&cp[j], NULL, calls, NULL) != 0)
-					perror("pthread_create");
+				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);

Modified: user/pho/stress2/misc/kevent6.sh
==============================================================================
--- user/pho/stress2/misc/kevent6.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/kevent6.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -135,15 +135,15 @@ test(void *arg __unused)
 int
 main(void)
 {
-	int i;
 	pthread_t cp[PARALLEL], sp;
+	int e, i;
 
-	if (pthread_create(&sp, NULL, spin, NULL) != 0)
-		perror("pthread_create");
+	if ((e = pthread_create(&sp, NULL, spin, NULL)) != 0)
+		errc(1, e, "pthread_create");
 
 	for (i = 0; i < PARALLEL; i++) {
-		if (pthread_create(&cp[i], NULL, test, NULL) != 0)
-			perror("pthread_create");
+		if ((e = pthread_create(&cp[i], NULL, test, NULL)) != 0)
+			errc(1, e, "pthread_create");
 	}
 
 

Modified: user/pho/stress2/misc/kevent7.sh
==============================================================================
--- user/pho/stress2/misc/kevent7.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/kevent7.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -221,7 +221,7 @@ main(void)
 	struct passwd *pw;
 	time_t start;
 	pthread_t rp, cp[50];
-	int j;
+	int e, j;
 
 	if ((pw = getpwnam("nobody")) == NULL)
 		err(1, "no such user: nobody");
@@ -247,12 +247,12 @@ main(void)
 	while (time(NULL) - start < 120) {
 		if (fork() == 0) {
 			arc4random_stir();
-			if (pthread_create(&rp, NULL, test, NULL) != 0)
-				perror("pthread_create");
+			if ((e = pthread_create(&rp, NULL, test, NULL)) != 0)
+				errc(1, e, "pthread_create");
 			usleep(1000);
 			for (j = 0; j < 50; j++)
-				if (pthread_create(&cp[j], NULL, calls, NULL) != 0)
-					perror("pthread_create");
+				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);

Modified: user/pho/stress2/misc/kevent8.sh
==============================================================================
--- user/pho/stress2/misc/kevent8.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/kevent8.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -140,15 +140,15 @@ test(void *arg __unused)
 int
 main(void)
 {
-	int i;
 	pthread_t cp[PARALLEL], sp;
+	int e, i;
 
-	if (pthread_create(&sp, NULL, spin, NULL) != 0)
-		perror("pthread_create");
+	if ((e = pthread_create(&sp, NULL, spin, NULL)) != 0)
+		errc(1, e, "pthread_create");
 
 	for (i = 0; i < PARALLEL; i++) {
-		if (pthread_create(&cp[i], NULL, test, NULL) != 0)
-			perror("pthread_create");
+		if ((e = pthread_create(&cp[i], NULL, test, NULL)) != 0)
+			errc(1, e, "pthread_create");
 	}
 
 

Modified: user/pho/stress2/misc/mlockall3.sh
==============================================================================
--- user/pho/stress2/misc/mlockall3.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/mlockall3.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -127,7 +127,7 @@ main(void)
 	struct passwd *pw;
 	pid_t pid;
 	pthread_t cp[50];
-	int i, j;
+	int e, i, j;
 
 	if ((pw = getpwnam("nobody")) == NULL)
 		err(1, "no such user: nobody");
@@ -154,8 +154,8 @@ main(void)
 			for (j = 0; j < N; j++)
 				r[j] = arc4random();
 			for (j = 0; j < 50; j++)
-				if (pthread_create(&cp[j], NULL, calls, NULL) != 0)
-					perror("pthread_create");
+				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);

Modified: user/pho/stress2/misc/mmap7.sh
==============================================================================
--- user/pho/stress2/misc/mmap7.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/mmap7.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -40,20 +40,19 @@ 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
+mycc -o mmap7 -Wall -Wextra wire_no_page.c -lpthread || exit 1
 rm -f wire_no_page.c
 cd $odir
 
-cp /tmp/mmap7  /tmp/mmap7.inputfile
 (cd ../testcases/swap; ./swap -t 1m -i 2) &
 cp /tmp/mmap7 /tmp/mmap7.inputfile
-/tmp/mmap7  /tmp/mmap7.inputfile
+/tmp/mmap7 /tmp/mmap7.inputfile
 while ps | grep -v grep | grep -qw swap; do
 	killall -9 swap 2>/dev/null
 	sleep .1
 done
 wait
-rm -f /tmp/mmap7  /tmp/mmap7.inputfile
+rm -f /tmp/mmap7 /tmp/mmap7.inputfile
 exit
 
 EOF
@@ -101,8 +100,8 @@ test2(void *arg __unused)
 void
 test(void)
 {
-	int error, i;
 	pthread_t cp[3];
+	int e, error, i;
 
 	if ((fd = open(file, O_RDWR)) == -1)
 		err(1, "open %s", file);
@@ -117,8 +116,8 @@ test(void)
 		err(1, "mmap");
 
 	for (i = 0; i < 3; i++)
-		if (pthread_create(&cp[i], NULL, test2, NULL) != 0)
-			perror("pthread_create");
+		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);
 

Modified: user/pho/stress2/misc/msync.sh
==============================================================================
--- user/pho/stress2/misc/msync.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/msync.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -159,7 +159,7 @@ main(void)
 {
 	struct passwd *pw;
 	pthread_t cp[50];
-	int i, j;
+	int e, i, j;
 
 	if (fork() == 0)
 		wd();
@@ -189,8 +189,8 @@ main(void)
 			for (j = 0; j < N; j++)
 				r[j] = arc4random();
 			for (j = 0; j < 50; j++)
-				if (pthread_create(&cp[j], NULL, calls, NULL) != 0)
-					perror("pthread_create");
+				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);

Modified: user/pho/stress2/misc/sigreturn.sh
==============================================================================
--- user/pho/stress2/misc/sigreturn.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/sigreturn.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -95,6 +95,7 @@ int
 main(void)
 {
 	pthread_t cp;
+	int e;
 
 	signal(SIGALRM, hand);
 	signal(SIGILL,  hand);
@@ -106,8 +107,8 @@ main(void)
 	signal(SIGTRAP, hand);
 
 	if (fork() == 0) {
-		if (pthread_create(&cp, NULL, calls, NULL) != 0)
-			perror("pthread_create");
+		if ((e = pthread_create(&cp, NULL, calls, NULL)) != 0)
+			errc(1, e, "pthread_create");
 
 		pthread_join(cp, NULL);
 		_exit(0);

Modified: user/pho/stress2/misc/sndstat.sh
==============================================================================
--- user/pho/stress2/misc/sndstat.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/sndstat.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -112,12 +112,12 @@ int
 main(void)
 {
         pthread_t rp[10];
-        int i, j;
+        int e, i, j;
 
 	/* Parallel open test */
         for (i = 0; i < 10; i++) {
-                if (pthread_create(&rp[i], NULL, test1, NULL) != 0)
-                        perror("pthread_create");
+                if ((e = pthread_create(&rp[i], NULL, test1, NULL)) != 0)
+                        errc(1, e, "pthread_create");
         }
         for (i = 0; i < 10; i++)
                 pthread_join(rp[i], NULL);
@@ -129,8 +129,8 @@ main(void)
 			continue;
 		}
 		for (j = 0; j < 4; j++)
-			if (pthread_create(&rp[j], NULL, test2, NULL) != 0)
-				perror("pthread_create");
+			if ((e = pthread_create(&rp[j], NULL, test2, NULL)) != 0)
+				errc(1, e, "pthread_create");
 		for (j = 0; j < 4; j++)
 			pthread_join(rp[j], NULL);
 

Modified: user/pho/stress2/misc/umountf7.sh
==============================================================================
--- user/pho/stress2/misc/umountf7.sh	Wed Jul 15 13:28:25 2015	(r285601)
+++ user/pho/stress2/misc/umountf7.sh	Wed Jul 15 14:28:57 2015	(r285602)
@@ -30,6 +30,7 @@
 
 # "panic: handle_written_inodeblock: live inodedep 0xcc731200" seen.
 # http://people.freebsd.org/~pho/stress/log/umountf7.txt
+# https://people.freebsd.org/~pho/stress/log/kostik824.txt
 # Problem only seen with SU+J.
 
 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
@@ -48,7 +49,8 @@ mount | grep "on $mntpoint " | grep -q /
 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 -j md${mdstart}$part > /dev/null
+[ "$newfs_flags" = "-U" ] && opt="-j"
+newfs $opt md${mdstart}$part > /dev/null
 mount /dev/md${mdstart}$part $mntpoint
 
 daemon sh -c '(cd ../testcases/swap; ./swap -t 2m -i 4)'
@@ -144,7 +146,7 @@ int
 main(int argc, char **argv)
 {
         pthread_t rp[3];
-	int i;
+	int e, i;
 
 	if (argc != 2)
 		errx(1, "Usage: %s <number of files>", argv[0]);
@@ -152,14 +154,14 @@ main(int argc, char **argv)
 	n = n2 = -1;
 	pid = getpid();
 
-	if (pthread_create(&rp[0], NULL, cr, NULL) != 0)
-		err(1, "pthread_create");
+	if ((e = pthread_create(&rp[0], NULL, cr, NULL)) != 0)
+		errc(1, e, "pthread_create");
 	usleep(arc4random() % 1000);
-	if (pthread_create(&rp[1], NULL, mv, NULL) != 0)
-		err(1, "pthread_mv");
+	if ((e = pthread_create(&rp[1], NULL, mv, NULL)) != 0)
+		errc(1, e, "pthread_mv");
 	usleep(arc4random() % 1000);
-	if (pthread_create(&rp[2], NULL, rm, NULL) != 0)
-		perror("pthread_rm");
+	if ((e = pthread_create(&rp[2], NULL, rm, NULL)) != 0)
+		errc(1, e, "pthread_rm");
 
         for (i = 0; i < 3; i++)
                 pthread_join(rp[i], NULL);

From owner-svn-src-user@freebsd.org  Thu Jul 16 10:12:13 2015
Return-Path: <owner-svn-src-user@freebsd.org>
Delivered-To: svn-src-user@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 17E6B9A2F6C
 for <svn-src-user@mailman.ysv.freebsd.org>;
 Thu, 16 Jul 2015 10:12:13 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id ED24715BA;
 Thu, 16 Jul 2015 10:12:12 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6GACCEW016476;
 Thu, 16 Jul 2015 10:12:12 GMT (envelope-from pho@FreeBSD.org)
Received: (from pho@localhost)
 by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6GACBOU016471;
 Thu, 16 Jul 2015 10:12:11 GMT (envelope-from pho@FreeBSD.org)
Message-Id: <201507161012.t6GACBOU016471@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org
 using -f
From: Peter Holm <pho@FreeBSD.org>
Date: Thu, 16 Jul 2015 10:12:11 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r285625 - user/pho/stress2/misc
X-SVN-Group: user
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-user@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 16 Jul 2015 10:12:13 -0000

Author: pho
Date: Thu Jul 16 10:12:10 2015
New Revision: 285625
URL: https://svnweb.freebsd.org/changeset/base/285625

Log:
  Do not use hardcoded "/tmp" for temporary files.
  
  Sponsored by:	EMC / Isilon storage division

Modified:
  user/pho/stress2/misc/sendfile.sh
  user/pho/stress2/misc/sendfile3.sh
  user/pho/stress2/misc/sendfile5.sh
  user/pho/stress2/misc/sendfile7.sh
  user/pho/stress2/misc/sendfile_shm.sh

Modified: user/pho/stress2/misc/sendfile.sh
==============================================================================
--- user/pho/stress2/misc/sendfile.sh	Thu Jul 16 09:08:36 2015	(r285624)
+++ user/pho/stress2/misc/sendfile.sh	Thu Jul 16 10:12:10 2015	(r285625)
@@ -43,8 +43,8 @@ rm -f sendfile.c
 [ -d "$RUNDIR" ] || mkdir -p $RUNDIR
 cd $RUNDIR
 
-in=/tmp/inputFile
-out=/tmp/outputFile
+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

Modified: user/pho/stress2/misc/sendfile3.sh
==============================================================================
--- user/pho/stress2/misc/sendfile3.sh	Thu Jul 16 09:08:36 2015	(r285624)
+++ user/pho/stress2/misc/sendfile3.sh	Thu Jul 16 10:12:10 2015	(r285625)
@@ -44,8 +44,8 @@ rm -f sendfile3.c
 [ -d "$RUNDIR" ] || mkdir -p $RUNDIR
 cd $RUNDIR
 
-in=/tmp/inputFile
-out=/tmp/outputFile
+in=inputFile
+out=outputFile
 parallel=20
 
 for i in 50m 100m; do
@@ -56,9 +56,7 @@ for i in 50m 100m; do
 		rm -f ${out}$j
 		/tmp/sendfile3 $in ${out}$j 1234$j &
 	done
-	for j in `jot $parallel`; do
-		wait
-	done
+	wait
 	for j in `jot $parallel`; do
 		rm -f ${out}$j
 	done

Modified: user/pho/stress2/misc/sendfile5.sh
==============================================================================
--- user/pho/stress2/misc/sendfile5.sh	Thu Jul 16 09:08:36 2015	(r285624)
+++ user/pho/stress2/misc/sendfile5.sh	Thu Jul 16 10:12:10 2015	(r285625)
@@ -36,11 +36,13 @@
 . ../default.cfg
 
 here=`pwd`
+file=`basename $diskimage`
+dir=`dirname $diskimage`
 cd /tmp
 sed '1,/^EOF/d' < $here/$0 > sendfile5.c
 mycc -o sendfile5 -Wall -Wextra -O2 sendfile5.c
 rm -f sendfile5.c
-dd if=/dev/zero of=/tmp/big bs=1m count=1k 2>&1 | egrep -v "records|transferred"
+dd if=/dev/zero of=$diskimage bs=1m count=1k 2>&1 | egrep -v "records|transferred"
 cd $here
 
 mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint
@@ -48,8 +50,8 @@ mdconfig -l | grep -q md$mdstart &&  mdc
 
 mount -t tmpfs tmpfs $mntpoint
 echo "Testing tmpfs(5)"
-cp /tmp/big $mntpoint
-/tmp/sendfile5 $mntpoint/big
+cp $diskimage $mntpoint
+/tmp/sendfile5 $mntpoint/$file
 umount $mntpoint
 
 mdconfig -l | grep -q md$mdstart &&  mdconfig -d -u $mdstart
@@ -58,16 +60,16 @@ bsdlabel -w md$mdstart auto
 newfs $newfs_flags md${mdstart}$part > /dev/null
 mount /dev/md${mdstart}$part $mntpoint
 echo "Testing FFS"
-cp /tmp/big $mntpoint
-/tmp/sendfile5 $mntpoint/big
+cp $diskimage $mntpoint
+/tmp/sendfile5 $mntpoint/$file
 umount $mntpoint
 
-mount -t nullfs /tmp $mntpoint
+mount -t nullfs $dir $mntpoint
 echo "Testing nullfs(5)"
-/tmp/sendfile5 $mntpoint/big
+/tmp/sendfile5 $mntpoint/$file
 umount $mntpoint
 
-rm -f /tmp/sendfile5 /tmp/big
+rm -f /tmp/sendfile5 $diskimage
 exit
 EOF
 #include <sys/types.h>

Modified: user/pho/stress2/misc/sendfile7.sh
==============================================================================
--- user/pho/stress2/misc/sendfile7.sh	Thu Jul 16 09:08:36 2015	(r285624)
+++ user/pho/stress2/misc/sendfile7.sh	Thu Jul 16 10:12:10 2015	(r285625)
@@ -36,6 +36,6 @@
 ./sendfile5.sh &
 
 while kill -0 $! 2>/dev/null; do
-	../testcases/swap/swap -t 2m -i 40
+	../testcases/swap/swap -t 2m -i 40 > /dev/null 2>&1
 done
 wait

Modified: user/pho/stress2/misc/sendfile_shm.sh
==============================================================================
--- user/pho/stress2/misc/sendfile_shm.sh	Thu Jul 16 09:08:36 2015	(r285624)
+++ user/pho/stress2/misc/sendfile_shm.sh	Thu Jul 16 10:12:10 2015	(r285625)
@@ -37,6 +37,7 @@
 
 [ -r /boot/kernel/kernel ] || exit 0
 here=`pwd`
+dir=`dirname $diskimage`
 cd /tmp
 sed '1,/^EOF/d' < $here/$0 > sendfile_shm.c
 mycc -o sendfile_shm -Wall -Wextra -O2 sendfile_shm.c || exit 1
@@ -46,7 +47,7 @@ cd $here
 daemon ../testcases/swap/swap -t 2m -i 20 > /dev/null 2>&1
 sleep 5
 for i in `jot 10`; do
-	/tmp/sendfile_shm /boot/kernel/kernel /tmp/sendfile_shm.$i > \
+	/tmp/sendfile_shm /boot/kernel/kernel $dir/sendfile_shm.$i > \
 	    /dev/null &
 done
 for i in `jot 10`; do
@@ -56,9 +57,9 @@ while pkill -9 swap; do
 	sleep .5
 done
 for i in `jot 10`; do
-	cmp -s /boot/kernel/kernel /tmp/sendfile_shm.$i 2>/dev/null ||
+	cmp -s /boot/kernel/kernel $dir/sendfile_shm.$i 2>/dev/null ||
 	    e=1
-	rm -f /tmp/sendfile_shm.$i
+	rm -f $dir/sendfile_shm.$i
 done
 [ -n "$e" ] && echo FAIL
 wait

From owner-svn-src-user@freebsd.org  Fri Jul 17 07:30:01 2015
Return-Path: <owner-svn-src-user@freebsd.org>
Delivered-To: svn-src-user@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id CAD0A9A4317
 for <svn-src-user@mailman.ysv.freebsd.org>;
 Fri, 17 Jul 2015 07:30:01 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id B26F21696;
 Fri, 17 Jul 2015 07:30:01 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6H7U13U047807;
 Fri, 17 Jul 2015 07:30:01 GMT (envelope-from pho@FreeBSD.org)
Received: (from pho@localhost)
 by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6H7U1Fr047805;
 Fri, 17 Jul 2015 07:30:01 GMT (envelope-from pho@FreeBSD.org)
Message-Id: <201507170730.t6H7U1Fr047805@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org
 using -f
From: Peter Holm <pho@FreeBSD.org>
Date: Fri, 17 Jul 2015 07:30:01 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r285649 - user/pho/stress2/misc
X-SVN-Group: user
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-user@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Fri, 17 Jul 2015 07:30:02 -0000

Author: pho
Date: Fri Jul 17 07:30:00 2015
New Revision: 285649
URL: https://svnweb.freebsd.org/changeset/base/285649

Log:
  Added two Mach IPC test scenarios.
  
  Sponsored by:	EMC / Isilon storage division

Added:
  user/pho/stress2/misc/machipc.sh   (contents, props changed)
  user/pho/stress2/misc/machipc2.sh   (contents, props changed)

Added: user/pho/stress2/misc/machipc.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/machipc.sh	Fri Jul 17 07:30:00 2015	(r285649)
@@ -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.
+#
+# $FreeBSD$
+#
+
+# 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
+rm -f /tmp/machipc
+exit 0
+EOF
+#include <sys/types.h>
+
+#include <mach/mach.h>
+
+#include <err.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+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);
+}

Added: user/pho/stress2/misc/machipc2.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/machipc2.sh	Fri Jul 17 07:30:00 2015	(r285649)
@@ -0,0 +1,294 @@
+#!/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$
+#
+
+# 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 <sys/types.h>
+#include <sys/wait.h>
+
+#include <mach/mach.h>
+#include <servers/bootstrap.h>
+
+#include <err.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#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);
+}