1#!/bin/sh 2 3# 4# Copyright (c) 2008-2009, 2012-13 Peter Holm <pho@FreeBSD.org> 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# 28 29# Run all the scripts in stress2/misc. 30 31[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 32 33# Log and config files: 34sdir=/tmp/stress2.d 35mkdir -p $sdir 36allconfig=$sdir/`hostname` # config file 37allfaillog=$sdir/fail # Tests that failed 38alllast=$sdir/last # Last test run 39alllist=$sdir/list # -o list 40alllog=$sdir/log # Tests run 41alloutput=$sdir/output # Output from current test 42allexcess=$sdir/excessive # Tests with excessive runtime 43allelapsed=$sdir/elapsed # Test runtime 44alllocal=$sdir/all.exclude # Local exclude list 45loops=0 # Times to run the tests 46# Get kernel config + revision 47rev=`uname -a | awk '{print $7}' | sed 's/://'` 48rev="`uname -a | sed 's#.*/compile/##; s/ .*//'` $rev" 49 50args=`getopt acl:m:no "$@"` 51[ $? -ne 0 ] && 52 echo "Usage $0 [-a] [-c] [-l <val>] [-m <min.>] [-n] [-o] [<tests>]" && 53 exit 1 54set -- $args 55for i; do 56 case "$i" in 57 -a) all=1 # Run all tests 58 echo "Note: including known problem tests." 59 shift 60 ;; 61 -c) rm -f $alllast # Clear last know test 62 rm -f $alllist 63 shift 64 ;; 65 -l) loops=$2 # Number of time to run 66 shift; shift 67 ;; 68 -m) minutes=$(($2 * 60)) # Run for minutes 69 shift; shift 70 ;; 71 -n) noshuffle=1 # Do not shuffle the list of tests 72 shift # Resume test after last test 73 ;; 74 -o) loops=1 # Only run once 75 shift 76 ;; 77 --) 78 shift 79 break 80 ;; 81 esac 82done 83 84export allconfig 85if [ ! -f $allconfig ]; then 86 echo "Creating local configuration file: $allconfig." 87 ../tools/setup.sh || exit 1 88fi 89 90. ../default.cfg 91 92# Sanity checks 93minspace=$((1024 * 1024)) # in k 94[ -d `dirname "$diskimage"` ] || 95 { echo "diskimage dir: $diskimage not found"; exit 1; } 96[ `df -k $(dirname $diskimage) | tail -1 | awk '{print $4}'` -lt \ 97 $minspace ] && 98 echo "Warn: Not enough disk space on `dirname $diskimage` " \ 99 "for \$diskimage" 100[ ! -d $(dirname $RUNDIR) ] && 101 echo "No such \$RUNDIR \"`dirname $RUNDIR`\"" && 102 exit 1 103[ `sysctl -n hw.physmem` -le $((3 * 1024 * 1024 * 1024)) ] && 104 echo "Warn: Small RAM size for stress tests `sysctl -n hw.physmem`" 105[ `df -k $(dirname $RUNDIR) | tail -1 | awk '{print $4}'` -lt \ 106 $minspace ] && 107 echo "Warn: Not enough disk space on `dirname $RUNDIR` for \$RUNDIR" 108id $testuser > /dev/null 2>&1 || 109 { echo "\$testuser \"$testuser\" not found."; exit 1; } 110probe=`dirname $RUNDIR`/probe 111su $testuser -c "touch $probe" > /dev/null 2>&1 112[ -f $probe ] && rm $probe || 113 { echo "No write access to `dirname $RUNDIR`."; exit 1; } 114[ `swapinfo | wc -l` -eq 1 ] && 115 echo "Consider adding a swap disk. Many tests rely on this." 116mount | grep -wq $mntpoint && 117 echo "\$mntpoint ($mntpoint) is already in use" && exit 1 118[ -x ../testcases/run/run ] || 119 (cd ..; make) 120ping -c 2 -t 2 $BLASTHOST > /dev/null 2>&1 || 121 { echo "Note: Can not ping \$BLASTHOST: $BLASTHOST"; } 122echo "$loops" | grep -Eq "^[0-9]+$" || 123 { echo "The -l argument must be a positive number"; exit 1; } 124[ `grep "^[a-zA-Z].*\.sh" $alllocal 2>/dev/null | wc -l` -ne 0 ] && 125 echo "Using $alllocal" 126 127find `dirname $alllast` -maxdepth 1 -name $alllast -mtime +12h -delete 128touch $alllast $alllog 129chmod 640 $alllast $alllog 130find ../testcases -perm -1 \( -name "*.debug" -o -name "*.full" \) -delete 131tail -2000 $alllog > ${alllog}.new; mv ${alllog}.new $alllog 132touch $allelapsed 133tail -20000 $allelapsed > ${allelapsed}.new; mv ${allelapsed}.new $allelapsed 134 135console=/dev/console 136printf "\r\n" > $console & 137pid=$! 138sleep 1 139kill -0 $pid > /dev/null 2>&1 && 140{ console=/dev/null; kill -9 $pid; } 141while pgrep -q fsck; do sleep 10; done 142 143status() { 144 local s2 r 145 146 s2=`date +%s` 147 r=$(echo "elapsed $(((s2 - s1) / 86400)) day(s)," \ 148 "`date -u -j -f '%s' '+%H:%M.%S' $((s2 - s1))`") 149 printf "`date '+%Y%m%d %T'` all.sh done, $r\n" 150 printf "`date '+%Y%m%d %T'` all.sh done, $r\r\n" > $console 151} 152 153intr() { 154 printf "\nExit all.sh\n" 155 ./cleanup.sh 156 exit 1 157} 158trap status EXIT 159trap intr INT 160 161[ -f all.debug.inc ] && . all.debug.inc 162s1=`date +%s` 163while true; do 164 exclude=`cat all.exclude $alllocal 2>/dev/null | sed '/^#/d' | 165 grep "^[a-zA-Z].*\.sh" | awk '{print $1}'` 166 list=`echo *.sh` 167 [ $# -ne 0 ] && list=$* 168 list=`echo $list | 169 sed "s/[[:<:]]all\.sh[[:>:]]//g;\ 170 s/[[:<:]]cleanup\.sh[[:>:]]//g"` 171 172 if [ -n "$noshuffle" -a $# -eq 0 ]; then 173 last=`cat $alllast` 174 if [ -n "$last" ]; then 175 last=`basename $last` 176 l=`cat "$alllist" | sed "s/.*$last//"` 177 [ -z "$l" ] && l=$list # start over 178 list=$l 179 echo "Last test was $last,"\ 180 "resuming test at" \ 181 "`echo "$list" | awk '{print $1}'`" 182 fi 183 fi 184 [ -n "$noshuffle" ] || 185 list=`echo $list | tr ' ' '\n' | sort -R | 186 tr '\n' ' '` 187 188 lst="" 189 for i in $list; do 190 [ -z "$all" ] && echo $exclude | grep -qw `basename $i` && 191 continue 192 lst="$lst $i" 193 done 194 [ -z "$lst" ] && exit 195 echo "$lst" > $alllist 196 197 pgrep -fq vmstat.sh || 198 daemon ../tools/vmstat.sh > /tmp/stress2.d/vmstat 2>&1 199 200 n1=0 201 n2=`echo $lst | wc -w | sed 's/ //g'` 202 for i in $lst; do 203 i=`basename $i` 204 [ ! -f ./$i ] && { echo "No such file ./$i"; continue; } 205 n1=$((n1 + 1)) 206 echo $i > $alllast 207 ./cleanup.sh || exit 1 208 ts=`date '+%Y%m%d %T'` 209 echo "$ts all: $i" 210 printf "$ts all ($n1/$n2): $i\n" >> $alllog 211 printf "$ts all ($n1/$n2): $i\r\n" > $console 212 logger "Starting stress2 test all.sh: $i" 213 [ $all_debug ] && pre_debug 214 [ -f $i ] || loops=1 # break 215 sync; sleep .5; sync; sleep .5 216 grep -E "^USE_TIMEOUT=1" $i && TIMEOUT_ONE=1 || 217 unset TIMEOUT_ONE 218 start=`date '+%s'` 219 ( 220 if [ $USE_TIMEOUT ] || [ $TIMEOUT_ONE ]; then 221 timeout -k 1m 1h ./$i 222 else 223 ./$i 224 fi 225 e=$? 226 [ $e -ne 0 ] && 227 echo "FAIL $i exit code $e" 228 ) 2>&1 | tee $alloutput 229 ts=`date '+%Y%m%d %T'` 230 grep -qw FAIL $alloutput && 231 echo "$ts $rev $i" >> $allfaillog && 232 logger "stress2 test $i failed" 233 grep -qw FATAL $alloutput && exit $e 234 rm -f $alloutput 235 printf "$ts $rev $i $((`date '+%s'` - start))\n" >> \ 236 $allelapsed 237 [ -f ../tools/ministat.sh ] && 238 ../tools/ministat.sh $allelapsed $i 239 [ $((`date '+%s'` - start)) -gt 1980 ] && 240 printf "$ts $rev $i %d min\n" \ 241 $(((`date '+%s'` - start) / 60)) >> $allexcess 242 while pgrep -q "^swap$"; do 243 echo "swap still running" 244 sleep 2 245 done 246 [ $USE_SWAPOFF ] && { swapoff -a; swapon -a; } 247 [ $all_debug ] && post_debug 248 [ $minutes ] && [ $((`date +%s` - s1)) -ge $minutes ] && 249 break 2 250 done 251 [ $((loops -= 1)) -eq 0 ] && break 252done 253[ -x ../tools/fail.sh ] && ../tools/fail.sh 254find /tmp . -name "*.core" -mtime -2 -maxdepth 2 -ls 2>/dev/null 255