1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)mmap_write_001_pos.ksh	1.3	07/07/31 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32
33# ##########################################################################
34#
35# __stc_assertion_start
36#
37# ID: mmap_write_001_pos
38#
39# DESCRIPTION:
40# Writing to a file and mmaping that file at the
41# same time does not result in a deadlock.
42#
43# STRATEGY:
44# 1. Make sure this test executes on multi-processes system.
45# 2. Call mmapwrite binary.
46# 3. wait 120s and make sure the test file existed.
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2005-07-04)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "both"
59
60# Default is 120 seconds or 2 minutes
61WAITTIME=${WAITTIME-120}
62
63log_assert "write()s to a file and mmap() that file at the same time does not "\
64	"result in a deadlock."
65
66# Detect and make sure this test must be executed on a multi-process system
67NCPUS=`sysctl -a | awk -F '"' '/cpu count="[0-9+]"/ {print $2; exit}'`
68if [[ $? -ne 0 || -z $NCPUS || $NCPUS -le 1 ]]; then
69	log_unsupported "This test must be executed on a multi-processor system."
70fi
71
72log_must $CHMOD 777 $TESTDIR
73$MMAPWRITE $TESTDIR/$TESTFILE &
74PID_MMAPWRITE=$!
75log_note "$MMAPWRITE $TESTDIR/$TESTFILE pid: $PID_MMAPWRITE"
76log_must $SLEEP 10
77
78typeset -i i=0
79while (( i < $WAITTIME )); do
80	if ! $PS -ef | $PGREP $MMAPWRITE > /dev/null ; then
81		log_must $WAIT $PID_MMAPWRITE
82		break
83	fi
84	$SLEEP 1
85	(( i += 1 ))
86done
87
88if $PS -ef | $PGREP $MMAPWRITE > /dev/null ; then
89	log_must $KILL -9 $PID_MMAPWRITE
90fi
91log_must $LS -l $TESTDIR/$TESTFILE
92
93log_pass "write(2) a mmap(2)'ing file succeeded."
94