1217134Sjilles#!/bin/sh
2217134Sjilles
3217134Sjilles#-
4217134Sjilles# Copyright (c) 2011 Jilles Tjoelker
5217134Sjilles# All rights reserved.
6217134Sjilles#
7217134Sjilles# Redistribution and use in source and binary forms, with or without
8217134Sjilles# modification, are permitted provided that the following conditions
9217134Sjilles# are met:
10217134Sjilles# 1. Redistributions of source code must retain the above copyright
11217134Sjilles#    notice, this list of conditions and the following disclaimer.
12217134Sjilles# 2. Redistributions in binary form must reproduce the above copyright
13217134Sjilles#    notice, this list of conditions and the following disclaimer in the
14217134Sjilles#    documentation and/or other materials provided with the distribution.
15217134Sjilles#
16217134Sjilles# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17217134Sjilles# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18217134Sjilles# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19217134Sjilles# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20217134Sjilles# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21217134Sjilles# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22217134Sjilles# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23217134Sjilles# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24217134Sjilles# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25217134Sjilles# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26217134Sjilles# SUCH DAMAGE.
27217134Sjilles#
28217134Sjilles# $FreeBSD$
29217134Sjilles
30217134Sjilles: "${SED=sed}"
31217134Sjilles
32217134Sjilles# This test really needs an SMP system. On an UP system, it will
33217134Sjilles# usually pass even if the race condition exists.
34217134Sjillesif command -v cpuset >/dev/null; then
35217134Sjilles	case `cpuset -g -p $$` in
36217134Sjilles	*,*) ;;
37217134Sjilles	*)
38217134Sjilles		echo '1..0 # Skipped: not an SMP system'
39217134Sjilles		exit 0 ;;
40217134Sjilles	esac
41217134Sjillesfi
42217134Sjilles
43217134Sjillesecho "1..1"
44217134Sjilles
45217134Sjillesdata=abababab
46217134Sjillesdata=$data$data$data$data
47217134Sjillesdata=$data$data$data$data
48217134Sjillesdata=$data$data$data$data
49217134Sjillesdata=$data$data$data$data
50217134Sjillesdata="BEGIN
51217134Sjilles$data
52217134SjillesEND"
53217134Sjillesfor i in 0 1 2 3 4 5 6 7 8 9; do
54217134Sjilles	echo "$data" >file$i
55217134Sjillesdone
56217134Sjilleslen=${#data}
57217134Sjilles
58217134Sjillesi=0
59217134Sjilleswhile [ $i -lt 100 ]; do
60217134Sjilles	${SED} -i.prev "s/$i/ab/" file[0-9]
61217134Sjilles	i=$((i+1))
62217134Sjillesdone &
63217134Sjillessedproc=$!
64217134Sjilles
65217134Sjilleswhile :; do
66217134Sjilles	set -- file[0-9]
67217134Sjilles	if [ $# -ne 10 ]; then
68217134Sjilles		echo "not ok 1 inplace_race"
69217134Sjilles		exit 3
70217134Sjilles	fi
71217134Sjillesdone &
72217134Sjillescheckproc=$!
73217134Sjilles
74217134Sjilleswait $sedproc
75217134Sjilleskill $checkproc 2>/dev/null
76217134Sjilleswait $checkproc >/dev/null 2>&1
77217134Sjillesif [ $? -ne 3 ]; then
78217134Sjilles	echo "ok 1 inplace_race"
79217134Sjillesfi
80