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 29*3a92d97fSJulio Merino: "${SED=sed}" 30*3a92d97fSJulio Merino 31*3a92d97fSJulio Merino# This test really needs an SMP system. On an UP system, it will 32*3a92d97fSJulio Merino# usually pass even if the race condition exists. 33*3a92d97fSJulio Merinoif command -v cpuset >/dev/null; then 34*3a92d97fSJulio Merino case `cpuset -g -p $$` in 35*3a92d97fSJulio Merino *,*) ;; 36*3a92d97fSJulio Merino *) 37*3a92d97fSJulio Merino echo '1..0 # Skipped: not an SMP system' 38*3a92d97fSJulio Merino exit 0 ;; 39*3a92d97fSJulio Merino esac 40*3a92d97fSJulio Merinofi 41*3a92d97fSJulio Merino 42*3a92d97fSJulio Merinoecho "1..1" 43*3a92d97fSJulio Merino 44*3a92d97fSJulio Merinodata=abababab 45*3a92d97fSJulio Merinodata=$data$data$data$data 46*3a92d97fSJulio Merinodata=$data$data$data$data 47*3a92d97fSJulio Merinodata=$data$data$data$data 48*3a92d97fSJulio Merinodata=$data$data$data$data 49*3a92d97fSJulio Merinodata="BEGIN 50*3a92d97fSJulio Merino$data 51*3a92d97fSJulio MerinoEND" 52*3a92d97fSJulio Merinofor i in 0 1 2 3 4 5 6 7 8 9; do 53*3a92d97fSJulio Merino echo "$data" >file$i 54*3a92d97fSJulio Merinodone 55*3a92d97fSJulio Merinolen=${#data} 56*3a92d97fSJulio Merino 57*3a92d97fSJulio Merinoi=0 58*3a92d97fSJulio Merinowhile [ $i -lt 100 ]; do 59*3a92d97fSJulio Merino ${SED} -i.prev "s/$i/ab/" file[0-9] 60*3a92d97fSJulio Merino i=$((i+1)) 61*3a92d97fSJulio Merinodone & 62*3a92d97fSJulio Merinosedproc=$! 63*3a92d97fSJulio Merino 64*3a92d97fSJulio Merinowhile :; do 65*3a92d97fSJulio Merino set -- file[0-9] 66*3a92d97fSJulio Merino if [ $# -ne 10 ]; then 67*3a92d97fSJulio Merino echo "not ok 1 inplace_race" 68*3a92d97fSJulio Merino exit 3 69*3a92d97fSJulio Merino fi 70*3a92d97fSJulio Merinodone & 71*3a92d97fSJulio Merinocheckproc=$! 72*3a92d97fSJulio Merino 73*3a92d97fSJulio Merinowait $sedproc 74*3a92d97fSJulio Merinokill $checkproc 2>/dev/null 75*3a92d97fSJulio Merinowait $checkproc >/dev/null 2>&1 76*3a92d97fSJulio Merinoif [ $? -ne 3 ]; then 77*3a92d97fSJulio Merino echo "ok 1 inplace_race" 78*3a92d97fSJulio Merinofi 79