From owner-svn-src-user@FreeBSD.ORG Sat May 24 11:42:51 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 54E6842E; Sat, 24 May 2014 11:42:51 +0000 (UTC) Received: from svn.freebsd.org (svn.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 427772430; Sat, 24 May 2014 11:42:51 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4OBgpHp050145; Sat, 24 May 2014 11:42:51 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4OBgp1P050144; Sat, 24 May 2014 11:42:51 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201405241142.s4OBgp1P050144@svn.freebsd.org> From: Peter Holm Date: Sat, 24 May 2014 11:42:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r266613 - 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.18 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 May 2014 11:42:51 -0000 Author: pho Date: Sat May 24 11:42:50 2014 New Revision: 266613 URL: http://svnweb.freebsd.org/changeset/base/266613 Log: Added a regression test. Sponsored by: EMC / Isilon storage division Added: user/pho/stress2/misc/fork.sh (contents, props changed) Added: user/pho/stress2/misc/fork.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/fork.sh Sat May 24 11:42:50 2014 (r266613) @@ -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. +# +# $FreeBSD$ +# + +# 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). + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > fork.c +cc -o fork -Wall -Wextra -O2 -g fork.c -lpthread || exit 1 + +for i in `jot 100`; do + /tmp/fork & +done +sleep 10 +if ps -l | grep -v grep | egrep "fork\$"; then + echo FAIL + exit 1 +fi + +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); + } +}