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 45exitonerror=0 # -e option 46loops=0 # Times to run the tests 47# Get kernel config + revision 48rev=`uname -a | awk '{print $7}' | sed 's/://'` 49rev="`uname -a | sed 's#.*/compile/##; s/ .*//'` $rev" 50 51args=`getopt acel:m:no "$@"` 52[ $? -ne 0 ] && 53 echo "Usage $0 [-a] [-c] [-e] [-l <val>] [-m <min.>] [-n] [-o] [<tests>]" && 54 exit 1 55set -- $args 56for i; do 57 case "$i" in 58 -a) all=1 # Run all tests 59 echo "Note: including known problem tests." 60 shift 61 ;; 62 -c) rm -f $alllast # Clear last know test 63 rm -f $alllist 64 shift 65 ;; 66 -e) exitonerror=1 67 shift 68 ;; 69 -l) loops=$2 # Number of time to run 70 shift; shift 71 ;; 72 -m) minutes=$(($2 * 60)) # Run for minutes 73 shift; shift 74 ;; 75 -n) noshuffle=1 # Do not shuffle the list of tests 76 shift # Resume test after last test 77 ;; 78 -o) loops=1 # Only run once 79 shift 80 ;; 81 --) 82 shift 83 break 84 ;; 85 esac 86done 87 88export allconfig 89if [ ! -f $allconfig ]; then 90 echo "Creating local configuration file: $allconfig." 91 ../tools/setup.sh || exit 1 92fi 93 94. ../default.cfg 95 96# Sanity checks 97minspace=$((1024 * 1024)) # in k 98[ -d `dirname "$diskimage"` ] || 99 { echo "diskimage dir: $diskimage not found"; exit 1; } 100[ `df -k $(dirname $diskimage) | tail -1 | awk '{print $4}'` -lt \ 101 $minspace ] && 102 echo "Warn: Not enough disk space on `dirname $diskimage` " \ 103 "for \$diskimage" 104[ ! -d $(dirname $RUNDIR) ] && 105 echo "No such \$RUNDIR \"`dirname $RUNDIR`\"" && 106 exit 1 107[ `sysctl -n hw.physmem` -le $((3 * 1024 * 1024 * 1024)) ] && 108 echo "Warn: Small RAM size for stress tests `sysctl -n hw.physmem`" 109[ `df -k $(dirname $RUNDIR) | tail -1 | awk '{print $4}'` -lt \ 110 $minspace ] && 111 echo "Warn: Not enough disk space on `dirname $RUNDIR` for \$RUNDIR" 112id $testuser > /dev/null 2>&1 || 113 { echo "\$testuser \"$testuser\" not found."; exit 1; } 114probe=`dirname $RUNDIR`/probe 115su $testuser -c "touch $probe" > /dev/null 2>&1 116[ -f $probe ] && rm $probe || 117 { echo "No write access to `dirname $RUNDIR`."; exit 1; } 118[ `swapinfo | wc -l` -eq 1 ] && 119 echo "Consider adding a swap disk. Many tests rely on this." 120mount | grep -wq $mntpoint && 121 echo "\$mntpoint ($mntpoint) is already in use" && exit 1 122[ -x ../testcases/run/run ] || 123 (cd ..; make) 124ping -c 2 -t 2 $BLASTHOST > /dev/null 2>&1 || 125 { echo "Note: Can not ping \$BLASTHOST: $BLASTHOST"; } 126echo "$loops" | grep -Eq "^[0-9]+$" || 127 { echo "The -l argument must be a positive number"; exit 1; } 128[ `grep "^[a-zA-Z].*\.sh" $alllocal 2>/dev/null | wc -l` -ne 0 ] && 129 echo "Using $alllocal" 130 131find `dirname $alllast` -maxdepth 1 -name $alllast -mtime +12h -delete 132touch $alllast $alllog 133chmod 640 $alllast $alllog 134find ../testcases -perm -1 \( -name "*.debug" -o -name "*.full" \) -delete 135tail -2000 $alllog > ${alllog}.new; mv ${alllog}.new $alllog 136touch $allelapsed 137tail -20000 $allelapsed > ${allelapsed}.new; mv ${allelapsed}.new $allelapsed 138 139console=/dev/console 140printf "\r\n" > $console & 141pid=$! 142sleep 1 143kill -0 $pid > /dev/null 2>&1 && 144{ console=/dev/null; kill -9 $pid; } 145while pgrep -q fsck; do sleep 10; done 146 147status() { 148 local s2 r 149 150 s2=`date +%s` 151 r=$(echo "elapsed $(((s2 - s1) / 86400)) day(s)," \ 152 "`date -u -j -f '%s' '+%H:%M.%S' $((s2 - s1))`") 153 printf "`date '+%Y%m%d %T'` all.sh done, $r\n" 154 printf "`date '+%Y%m%d %T'` all.sh done, $r\r\n" > $console 155} 156 157intr() { 158 printf "\nExit all.sh\n" 159 ./cleanup.sh 160 exit 1 161} 162trap status EXIT 163trap intr INT 164 165[ -f all.debug.inc ] && . all.debug.inc 166s1=`date +%s` 167touch $sdir/starttime 168while true; do 169 exclude=`cat all.exclude $alllocal 2>/dev/null | sed '/^#/d' | 170 grep "^[a-zA-Z].*\.sh" | awk '{print $1}'` 171 list=`echo *.sh` 172 [ $# -ne 0 ] && list=$* 173 list=`echo $list | 174 sed "s/[[:<:]]all\.sh[[:>:]]//g;\ 175 s/[[:<:]]cleanup\.sh[[:>:]]//g"` 176 177 if [ -n "$noshuffle" -a $# -eq 0 ]; then 178 last=`cat $alllast` 179 if [ -n "$last" ]; then 180 last=`basename $last` 181 l=`cat "$alllist" | sed "s/.*$last//"` 182 [ -z "$l" ] && l=$list # start over 183 list=$l 184 echo "Last test was $last,"\ 185 "resuming test at" \ 186 "`echo "$list" | awk '{print $1}'`" 187 fi 188 fi 189 [ -n "$noshuffle" ] || 190 list=`echo $list | tr ' ' '\n' | sort -R | 191 tr '\n' ' '` 192 193 lst="" 194 for i in $list; do 195 [ -z "$all" ] && echo $exclude | grep -qw `basename $i` && 196 continue 197 lst="$lst $i" 198 done 199 [ -z "$lst" ] && exit 200 echo "$lst" > $alllist 201 202 pgrep -fq vmstat.sh || 203 daemon ../tools/vmstat.sh > /tmp/stress2.d/vmstat 2>&1 204 205 n1=0 206 n2=`echo $lst | wc -w | sed 's/ //g'` 207 for i in $lst; do 208 i=`basename $i` 209 [ ! -f ./$i ] && { echo "No such file ./$i"; continue; } 210 n1=$((n1 + 1)) 211 echo $i > $alllast 212 ./cleanup.sh || exit 1 213 ts=`date '+%Y%m%d %T'` 214 echo "$ts all: $i" 215 printf "$ts all ($n1/$n2): $i\n" >> $alllog 216 printf "$ts all ($n1/$n2): $i\r\n" > $console 217 logger "Starting stress2 test all.sh: $i" 218 [ $all_debug ] && pre_debug 219 [ -f $i ] || loops=1 # break 220 sync; sleep .5; sync; sleep .5 221 grep -E "^USE_TIMEOUT=1" $i && TIMEOUT_ONE=1 || 222 unset TIMEOUT_ONE 223 start=`date '+%s'` 224 ( 225 if [ $USE_TIMEOUT ] || [ $TIMEOUT_ONE ]; then 226 timeout -k 1m 1h ./$i 227 else 228 ./$i 229 fi 230 e=$? 231 [ $e -ne 0 ] && 232 echo "FAIL $i exit code $e" 233 ) 2>&1 | tee $alloutput 234 grep -qw FAIL $alloutput && e=1 || e=0 235 ts=`date '+%Y%m%d %T'` 236 grep -qw FAIL $alloutput && 237 echo "$ts $rev $i" >> $allfaillog && 238 logger "stress2 test $i failed" 239 grep -qw FATAL $alloutput && exit $e 240 rm -f $alloutput 241 printf "$ts $rev $i $((`date '+%s'` - start))\n" >> \ 242 $allelapsed 243 [ -f ../tools/ministat.sh ] && 244 ../tools/ministat.sh $allelapsed $i 245 [ $((`date '+%s'` - start)) -gt 1980 ] && 246 printf "$ts $rev $i %d min\n" \ 247 $(((`date '+%s'` - start) / 60)) >> $allexcess 248 while pgrep -q "^swap$"; do 249 echo "swap still running" 250 sleep 2 251 done 252 [ $USE_SWAPOFF ] && { swapoff -a; swapon -a; } 253 [ $all_debug ] && post_debug 254 [ $minutes ] && [ $((`date +%s` - s1)) -ge $minutes ] && 255 break 2 256 [ $exitonerror -eq 1 -a $e -ne 0 ] && break 2 257 done 258 [ $((loops -= 1)) -eq 0 ] && break 259done 260[ -x ../tools/fail.sh ] && ../tools/fail.sh 261find /tmp . -name "*.core" -mtime -2 -maxdepth 2 -ls 2>/dev/null 262