xref: /freebsd/usr.bin/sed/tests/inplace_race_test.sh (revision 3a92d97ff0f22d21608e1c19b83104c4937523b6)
1*3a92d97fSJulio Merino#!/bin/sh
2*3a92d97fSJulio Merino
3*3a92d97fSJulio Merino#-
4*3a92d97fSJulio Merino# Copyright (c) 2011 Jilles Tjoelker
5*3a92d97fSJulio Merino# All rights reserved.
6*3a92d97fSJulio Merino#
7*3a92d97fSJulio Merino# Redistribution and use in source and binary forms, with or without
8*3a92d97fSJulio Merino# modification, are permitted provided that the following conditions
9*3a92d97fSJulio Merino# are met:
10*3a92d97fSJulio Merino# 1. Redistributions of source code must retain the above copyright
11*3a92d97fSJulio Merino#    notice, this list of conditions and the following disclaimer.
12*3a92d97fSJulio Merino# 2. Redistributions in binary form must reproduce the above copyright
13*3a92d97fSJulio Merino#    notice, this list of conditions and the following disclaimer in the
14*3a92d97fSJulio Merino#    documentation and/or other materials provided with the distribution.
15*3a92d97fSJulio Merino#
16*3a92d97fSJulio Merino# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*3a92d97fSJulio Merino# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*3a92d97fSJulio Merino# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*3a92d97fSJulio Merino# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*3a92d97fSJulio Merino# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*3a92d97fSJulio Merino# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*3a92d97fSJulio Merino# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*3a92d97fSJulio Merino# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*3a92d97fSJulio Merino# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*3a92d97fSJulio Merino# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*3a92d97fSJulio Merino# SUCH DAMAGE.
27*3a92d97fSJulio Merino#
28*3a92d97fSJulio Merino# $FreeBSD$
29*3a92d97fSJulio Merino
30*3a92d97fSJulio Merino: "${SED=sed}"
31*3a92d97fSJulio Merino
32*3a92d97fSJulio Merino# This test really needs an SMP system. On an UP system, it will
33*3a92d97fSJulio Merino# usually pass even if the race condition exists.
34*3a92d97fSJulio Merinoif command -v cpuset >/dev/null; then
35*3a92d97fSJulio Merino	case `cpuset -g -p $$` in
36*3a92d97fSJulio Merino	*,*) ;;
37*3a92d97fSJulio Merino	*)
38*3a92d97fSJulio Merino		echo '1..0 # Skipped: not an SMP system'
39*3a92d97fSJulio Merino		exit 0 ;;
40*3a92d97fSJulio Merino	esac
41*3a92d97fSJulio Merinofi
42*3a92d97fSJulio Merino
43*3a92d97fSJulio Merinoecho "1..1"
44*3a92d97fSJulio Merino
45*3a92d97fSJulio Merinodata=abababab
46*3a92d97fSJulio Merinodata=$data$data$data$data
47*3a92d97fSJulio Merinodata=$data$data$data$data
48*3a92d97fSJulio Merinodata=$data$data$data$data
49*3a92d97fSJulio Merinodata=$data$data$data$data
50*3a92d97fSJulio Merinodata="BEGIN
51*3a92d97fSJulio Merino$data
52*3a92d97fSJulio MerinoEND"
53*3a92d97fSJulio Merinofor i in 0 1 2 3 4 5 6 7 8 9; do
54*3a92d97fSJulio Merino	echo "$data" >file$i
55*3a92d97fSJulio Merinodone
56*3a92d97fSJulio Merinolen=${#data}
57*3a92d97fSJulio Merino
58*3a92d97fSJulio Merinoi=0
59*3a92d97fSJulio Merinowhile [ $i -lt 100 ]; do
60*3a92d97fSJulio Merino	${SED} -i.prev "s/$i/ab/" file[0-9]
61*3a92d97fSJulio Merino	i=$((i+1))
62*3a92d97fSJulio Merinodone &
63*3a92d97fSJulio Merinosedproc=$!
64*3a92d97fSJulio Merino
65*3a92d97fSJulio Merinowhile :; do
66*3a92d97fSJulio Merino	set -- file[0-9]
67*3a92d97fSJulio Merino	if [ $# -ne 10 ]; then
68*3a92d97fSJulio Merino		echo "not ok 1 inplace_race"
69*3a92d97fSJulio Merino		exit 3
70*3a92d97fSJulio Merino	fi
71*3a92d97fSJulio Merinodone &
72*3a92d97fSJulio Merinocheckproc=$!
73*3a92d97fSJulio Merino
74*3a92d97fSJulio Merinowait $sedproc
75*3a92d97fSJulio Merinokill $checkproc 2>/dev/null
76*3a92d97fSJulio Merinowait $checkproc >/dev/null 2>&1
77*3a92d97fSJulio Merinoif [ $? -ne 3 ]; then
78*3a92d97fSJulio Merino	echo "ok 1 inplace_race"
79*3a92d97fSJulio Merinofi
80