inplace_race_test.sh revision 217134
152419Sjulian#!/bin/sh
252419Sjulian
3139823Simp#-
4139823Simp# Copyright (c) 2011 Jilles Tjoelker
5139823Simp# All rights reserved.
652419Sjulian#
752419Sjulian# Redistribution and use in source and binary forms, with or without
852419Sjulian# modification, are permitted provided that the following conditions
952419Sjulian# are met:
1052419Sjulian# 1. Redistributions of source code must retain the above copyright
1152419Sjulian#    notice, this list of conditions and the following disclaimer.
1252419Sjulian# 2. Redistributions in binary form must reproduce the above copyright
1352419Sjulian#    notice, this list of conditions and the following disclaimer in the
1452419Sjulian#    documentation and/or other materials provided with the distribution.
1552419Sjulian#
1652419Sjulian# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1752419Sjulian# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1852419Sjulian# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1952419Sjulian# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2052419Sjulian# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2152419Sjulian# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2252419Sjulian# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2352419Sjulian# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2452419Sjulian# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2552419Sjulian# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2652419Sjulian# SUCH DAMAGE.
2752419Sjulian#
2852419Sjulian# $FreeBSD: head/tools/regression/usr.bin/sed/inplace_race.t 217134 2011-01-08 00:06:22Z jilles $
2952419Sjulian
3052419Sjulian: "${SED=sed}"
3152419Sjulian
3252419Sjulian# This test really needs an SMP system. On an UP system, it will
3352419Sjulian# usually pass even if the race condition exists.
3452419Sjulianif command -v cpuset >/dev/null; then
3552419Sjulian	case `cpuset -g -p $$` in
3652419Sjulian	*,*) ;;
3752419Sjulian	*)
3867506Sjulian		echo '1..0 # Skipped: not an SMP system'
3952419Sjulian		exit 0 ;;
4052419Sjulian	esac
4152752Sjulianfi
4252419Sjulian
4352419Sjulianecho "1..1"
4452419Sjulian
4552419SjulianT=$(mktemp -d "${TMPDIR:-/tmp}/sed-test.XXXXXX")
4652419Sjuliantrap 'cd /; rm -rf "$T"' 0
4752419Sjuliancd "$T"
4852419Sjulian
4952419Sjuliandata=abababab
5052419Sjuliandata=$data$data$data$data
5170784Sjuliandata=$data$data$data$data
5252419Sjuliandata=$data$data$data$data
5352419Sjuliandata=$data$data$data$data
5452419Sjuliandata="BEGIN
5552419Sjulian$data
5652419SjulianEND"
5752419Sjulianfor i in 0 1 2 3 4 5 6 7 8 9; do
5852419Sjulian	echo "$data" >file$i
5952419Sjuliandone
6070700Sjulianlen=${#data}
6152752Sjulian
6252752Sjuliani=0
6352752Sjulianwhile [ $i -lt 100 ]; do
6452419Sjulian	${SED} -i.prev "s/$i/ab/" file[0-9]
6552419Sjulian	i=$((i+1))
6652419Sjuliandone &
67129823Sjuliansedproc=$!
68129823Sjulian
69129823Sjulianwhile :; do
70129823Sjulian	set -- file[0-9]
71129823Sjulian	if [ $# -ne 10 ]; then
72129823Sjulian		echo "not ok 1 inplace_race"
7352419Sjulian		exit 3
7452419Sjulian	fi
7552419Sjuliandone &
7670700Sjuliancheckproc=$!
7770700Sjulian
7870700Sjulianwait $sedproc
7970700Sjuliankill $checkproc 2>/dev/null
8070700Sjulianwait $checkproc >/dev/null 2>&1
8170700Sjulianif [ $? -ne 3 ]; then
8252419Sjulian	echo "ok 1 inplace_race"
8352419Sjulianfi
8452419Sjulian