1*6bf19c94SChristoph Hellwig#!/bin/sh 2*6bf19c94SChristoph Hellwig# 3*6bf19c94SChristoph Hellwig# Copyright (C) 2009 Red Hat, Inc. 4*6bf19c94SChristoph Hellwig# Copyright (c) 2000-2002,2006 Silicon Graphics, Inc. All Rights Reserved. 5*6bf19c94SChristoph Hellwig# 6*6bf19c94SChristoph Hellwig# This program is free software; you can redistribute it and/or 7*6bf19c94SChristoph Hellwig# modify it under the terms of the GNU General Public License as 8*6bf19c94SChristoph Hellwig# published by the Free Software Foundation. 9*6bf19c94SChristoph Hellwig# 10*6bf19c94SChristoph Hellwig# This program is distributed in the hope that it would be useful, 11*6bf19c94SChristoph Hellwig# but WITHOUT ANY WARRANTY; without even the implied warranty of 12*6bf19c94SChristoph Hellwig# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*6bf19c94SChristoph Hellwig# GNU General Public License for more details. 14*6bf19c94SChristoph Hellwig# 15*6bf19c94SChristoph Hellwig# You should have received a copy of the GNU General Public License 16*6bf19c94SChristoph Hellwig# along with this program; if not, write the Free Software Foundation, 17*6bf19c94SChristoph Hellwig# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18*6bf19c94SChristoph Hellwig# 19*6bf19c94SChristoph Hellwig# 20*6bf19c94SChristoph Hellwig# Control script for QA 21*6bf19c94SChristoph Hellwig# 22*6bf19c94SChristoph Hellwig 23*6bf19c94SChristoph Hellwigtmp=/tmp/$$ 24*6bf19c94SChristoph Hellwigstatus=0 25*6bf19c94SChristoph Hellwigneedwrap=true 26*6bf19c94SChristoph Hellwigtry=0 27*6bf19c94SChristoph Hellwign_bad=0 28*6bf19c94SChristoph Hellwigbad="" 29*6bf19c94SChristoph Hellwignotrun="" 30*6bf19c94SChristoph Hellwiginterrupt=true 31*6bf19c94SChristoph Hellwig 32*6bf19c94SChristoph Hellwig# by default don't output timestamps 33*6bf19c94SChristoph Hellwigtimestamp=${TIMESTAMP:=false} 34*6bf19c94SChristoph Hellwig 35*6bf19c94SChristoph Hellwig# generic initialization 36*6bf19c94SChristoph Hellwigiam=check 37*6bf19c94SChristoph Hellwig 38*6bf19c94SChristoph Hellwig# we need common.config 39*6bf19c94SChristoph Hellwigif ! . ./common.config 40*6bf19c94SChristoph Hellwigthen 41*6bf19c94SChristoph Hellwig echo "$iam: failed to source common.config" 42*6bf19c94SChristoph Hellwig exit 1 43*6bf19c94SChristoph Hellwigfi 44*6bf19c94SChristoph Hellwig 45*6bf19c94SChristoph Hellwig# we need common 46*6bf19c94SChristoph Hellwig. ./common 47*6bf19c94SChristoph Hellwig 48*6bf19c94SChristoph Hellwig# we need common.rc 49*6bf19c94SChristoph Hellwigif ! . ./common.rc 50*6bf19c94SChristoph Hellwigthen 51*6bf19c94SChristoph Hellwig echo "check: failed to source common.rc" 52*6bf19c94SChristoph Hellwig exit 1 53*6bf19c94SChristoph Hellwigfi 54*6bf19c94SChristoph Hellwig 55*6bf19c94SChristoph Hellwig#if [ `id -u` -ne 0 ] 56*6bf19c94SChristoph Hellwig#then 57*6bf19c94SChristoph Hellwig# echo "check: QA must be run as root" 58*6bf19c94SChristoph Hellwig# exit 1 59*6bf19c94SChristoph Hellwig#fi 60*6bf19c94SChristoph Hellwig 61*6bf19c94SChristoph Hellwig_wallclock() 62*6bf19c94SChristoph Hellwig{ 63*6bf19c94SChristoph Hellwig date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }' 64*6bf19c94SChristoph Hellwig} 65*6bf19c94SChristoph Hellwig 66*6bf19c94SChristoph Hellwig_timestamp() 67*6bf19c94SChristoph Hellwig{ 68*6bf19c94SChristoph Hellwig now=`date "+%T"` 69*6bf19c94SChristoph Hellwig echo -n " [$now]" 70*6bf19c94SChristoph Hellwig} 71*6bf19c94SChristoph Hellwig 72*6bf19c94SChristoph Hellwig_wrapup() 73*6bf19c94SChristoph Hellwig{ 74*6bf19c94SChristoph Hellwig # for hangcheck ... 75*6bf19c94SChristoph Hellwig # remove files that were used by hangcheck 76*6bf19c94SChristoph Hellwig # 77*6bf19c94SChristoph Hellwig [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid 78*6bf19c94SChristoph Hellwig [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts 79*6bf19c94SChristoph Hellwig 80*6bf19c94SChristoph Hellwig if $showme 81*6bf19c94SChristoph Hellwig then 82*6bf19c94SChristoph Hellwig : 83*6bf19c94SChristoph Hellwig elif $needwrap 84*6bf19c94SChristoph Hellwig then 85*6bf19c94SChristoph Hellwig if [ -f check.time -a -f $tmp.time ] 86*6bf19c94SChristoph Hellwig then 87*6bf19c94SChristoph Hellwig cat check.time $tmp.time \ 88*6bf19c94SChristoph Hellwig | $AWK_PROG ' 89*6bf19c94SChristoph Hellwig { t[$1] = $2 } 90*6bf19c94SChristoph HellwigEND { if (NR > 0) { 91*6bf19c94SChristoph Hellwig for (i in t) print i " " t[i] 92*6bf19c94SChristoph Hellwig } 93*6bf19c94SChristoph Hellwig }' \ 94*6bf19c94SChristoph Hellwig | sort -n >$tmp.out 95*6bf19c94SChristoph Hellwig mv $tmp.out check.time 96*6bf19c94SChristoph Hellwig fi 97*6bf19c94SChristoph Hellwig 98*6bf19c94SChristoph Hellwig if [ -f $tmp.expunged ] 99*6bf19c94SChristoph Hellwig then 100*6bf19c94SChristoph Hellwig notrun=`wc -l <$tmp.expunged | sed -e 's/ *//g'` 101*6bf19c94SChristoph Hellwig try=`expr $try - $notrun` 102*6bf19c94SChristoph Hellwig list=`echo "$list" | sed -f $tmp.expunged` 103*6bf19c94SChristoph Hellwig fi 104*6bf19c94SChristoph Hellwig 105*6bf19c94SChristoph Hellwig echo "" >>check.log 106*6bf19c94SChristoph Hellwig date >>check.log 107*6bf19c94SChristoph Hellwig echo $list | fmt | sed -e 's/^/ /' >>check.log 108*6bf19c94SChristoph Hellwig $interrupt && echo "Interrupted!" >>check.log 109*6bf19c94SChristoph Hellwig 110*6bf19c94SChristoph Hellwig if [ ! -z "$notrun" ] 111*6bf19c94SChristoph Hellwig then 112*6bf19c94SChristoph Hellwig echo "Not run:$notrun" 113*6bf19c94SChristoph Hellwig echo "Not run:$notrun" >>check.log 114*6bf19c94SChristoph Hellwig fi 115*6bf19c94SChristoph Hellwig if [ ! -z "$n_bad" -a $n_bad != 0 ] 116*6bf19c94SChristoph Hellwig then 117*6bf19c94SChristoph Hellwig echo "Failures:$bad" 118*6bf19c94SChristoph Hellwig echo "Failed $n_bad of $try tests" 119*6bf19c94SChristoph Hellwig echo "Failures:$bad" | fmt >>check.log 120*6bf19c94SChristoph Hellwig echo "Failed $n_bad of $try tests" >>check.log 121*6bf19c94SChristoph Hellwig else 122*6bf19c94SChristoph Hellwig echo "Passed all $try tests" 123*6bf19c94SChristoph Hellwig echo "Passed all $try tests" >>check.log 124*6bf19c94SChristoph Hellwig fi 125*6bf19c94SChristoph Hellwig needwrap=false 126*6bf19c94SChristoph Hellwig fi 127*6bf19c94SChristoph Hellwig 128*6bf19c94SChristoph Hellwig rm -f /tmp/*.out /tmp/*.err /tmp/*.time 129*6bf19c94SChristoph Hellwig rm -f /tmp/check.pid /tmp/check.sts 130*6bf19c94SChristoph Hellwig rm -f $tmp.* 131*6bf19c94SChristoph Hellwig} 132*6bf19c94SChristoph Hellwig 133*6bf19c94SChristoph Hellwigtrap "_wrapup; exit \$status" 0 1 2 3 15 134*6bf19c94SChristoph Hellwig 135*6bf19c94SChristoph Hellwig# for hangcheck ... 136*6bf19c94SChristoph Hellwig# Save pid of check in a well known place, so that hangcheck can be sure it 137*6bf19c94SChristoph Hellwig# has the right pid (getting the pid from ps output is not reliable enough). 138*6bf19c94SChristoph Hellwig# 139*6bf19c94SChristoph Hellwigrm -rf /tmp/check.pid 140*6bf19c94SChristoph Hellwigecho $$ >/tmp/check.pid 141*6bf19c94SChristoph Hellwig 142*6bf19c94SChristoph Hellwig# for hangcheck ... 143*6bf19c94SChristoph Hellwig# Save the status of check in a well known place, so that hangcheck can be 144*6bf19c94SChristoph Hellwig# sure to know where check is up to (getting test number from ps output is 145*6bf19c94SChristoph Hellwig# not reliable enough since the trace stuff has been introduced). 146*6bf19c94SChristoph Hellwig# 147*6bf19c94SChristoph Hellwigrm -rf /tmp/check.sts 148*6bf19c94SChristoph Hellwigecho "preamble" >/tmp/check.sts 149*6bf19c94SChristoph Hellwig 150*6bf19c94SChristoph Hellwig# don't leave old full output behind on a clean run 151*6bf19c94SChristoph Hellwigrm -f check.full 152*6bf19c94SChristoph Hellwig 153*6bf19c94SChristoph Hellwig[ -f check.time ] || touch check.time 154*6bf19c94SChristoph Hellwig 155*6bf19c94SChristoph HellwigFULL_IMGFMT_DETAILS=`_full_imgfmt_details` 156*6bf19c94SChristoph HellwigFULL_HOST_DETAILS=`_full_platform_details` 157*6bf19c94SChristoph Hellwig#FULL_MKFS_OPTIONS=`_scratch_mkfs_options` 158*6bf19c94SChristoph Hellwig#FULL_MOUNT_OPTIONS=`_scratch_mount_options` 159*6bf19c94SChristoph Hellwig 160*6bf19c94SChristoph Hellwigcat <<EOF 161*6bf19c94SChristoph HellwigIMGFMT -- $FULL_IMGFMT_DETAILS 162*6bf19c94SChristoph HellwigPLATFORM -- $FULL_HOST_DETAILS 163*6bf19c94SChristoph Hellwig 164*6bf19c94SChristoph HellwigEOF 165*6bf19c94SChristoph Hellwig#MKFS_OPTIONS -- $FULL_MKFS_OPTIONS 166*6bf19c94SChristoph Hellwig#MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS 167*6bf19c94SChristoph Hellwig 168*6bf19c94SChristoph Hellwigseq="check" 169*6bf19c94SChristoph Hellwig 170*6bf19c94SChristoph Hellwig[ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG 171*6bf19c94SChristoph Hellwig 172*6bf19c94SChristoph Hellwigfor seq in $list 173*6bf19c94SChristoph Hellwigdo 174*6bf19c94SChristoph Hellwig err=false 175*6bf19c94SChristoph Hellwig echo -n "$seq" 176*6bf19c94SChristoph Hellwig if [ -n "$TESTS_REMAINING_LOG" ] ; then 177*6bf19c94SChristoph Hellwig sed -e "s/$seq//" -e 's/ / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp 178*6bf19c94SChristoph Hellwig mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG 179*6bf19c94SChristoph Hellwig sync 180*6bf19c94SChristoph Hellwig fi 181*6bf19c94SChristoph Hellwig 182*6bf19c94SChristoph Hellwig if $showme 183*6bf19c94SChristoph Hellwig then 184*6bf19c94SChristoph Hellwig echo 185*6bf19c94SChristoph Hellwig continue 186*6bf19c94SChristoph Hellwig elif [ -f expunged ] && $expunge && egrep "^$seq([ ]|\$)" expunged >/dev/null 187*6bf19c94SChristoph Hellwig then 188*6bf19c94SChristoph Hellwig echo " - expunged" 189*6bf19c94SChristoph Hellwig rm -f $seq.out.bad 190*6bf19c94SChristoph Hellwig echo "/^$seq\$/d" >>$tmp.expunged 191*6bf19c94SChristoph Hellwig elif [ ! -f $seq ] 192*6bf19c94SChristoph Hellwig then 193*6bf19c94SChristoph Hellwig echo " - no such test?" 194*6bf19c94SChristoph Hellwig echo "/^$seq\$/d" >>$tmp.expunged 195*6bf19c94SChristoph Hellwig else 196*6bf19c94SChristoph Hellwig # really going to try and run this one 197*6bf19c94SChristoph Hellwig # 198*6bf19c94SChristoph Hellwig rm -f $seq.out.bad 199*6bf19c94SChristoph Hellwig lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time` 200*6bf19c94SChristoph Hellwig if [ "X$lasttime" != X ]; then 201*6bf19c94SChristoph Hellwig echo -n " ${lasttime}s ..." 202*6bf19c94SChristoph Hellwig else 203*6bf19c94SChristoph Hellwig echo -n " " # prettier output with timestamps. 204*6bf19c94SChristoph Hellwig fi 205*6bf19c94SChristoph Hellwig rm -f core $seq.notrun 206*6bf19c94SChristoph Hellwig 207*6bf19c94SChristoph Hellwig # for hangcheck ... 208*6bf19c94SChristoph Hellwig echo "$seq" >/tmp/check.sts 209*6bf19c94SChristoph Hellwig 210*6bf19c94SChristoph Hellwig start=`_wallclock` 211*6bf19c94SChristoph Hellwig $timestamp && echo -n " ["`date "+%T"`"]" 212*6bf19c94SChristoph Hellwig [ ! -x $seq ] && chmod u+x $seq # ensure we can run it 213*6bf19c94SChristoph Hellwig ./$seq >$tmp.out 2>&1 214*6bf19c94SChristoph Hellwig sts=$? 215*6bf19c94SChristoph Hellwig $timestamp && _timestamp 216*6bf19c94SChristoph Hellwig stop=`_wallclock` 217*6bf19c94SChristoph Hellwig 218*6bf19c94SChristoph Hellwig if [ -f core ] 219*6bf19c94SChristoph Hellwig then 220*6bf19c94SChristoph Hellwig echo -n " [dumped core]" 221*6bf19c94SChristoph Hellwig mv core $seq.core 222*6bf19c94SChristoph Hellwig err=true 223*6bf19c94SChristoph Hellwig fi 224*6bf19c94SChristoph Hellwig 225*6bf19c94SChristoph Hellwig if [ -f $seq.notrun ] 226*6bf19c94SChristoph Hellwig then 227*6bf19c94SChristoph Hellwig $timestamp || echo -n " [not run] " 228*6bf19c94SChristoph Hellwig $timestamp && echo " [not run]" && echo -n " $seq -- " 229*6bf19c94SChristoph Hellwig cat $seq.notrun 230*6bf19c94SChristoph Hellwig notrun="$notrun $seq" 231*6bf19c94SChristoph Hellwig else 232*6bf19c94SChristoph Hellwig if [ $sts -ne 0 ] 233*6bf19c94SChristoph Hellwig then 234*6bf19c94SChristoph Hellwig echo -n " [failed, exit status $sts]" 235*6bf19c94SChristoph Hellwig err=true 236*6bf19c94SChristoph Hellwig fi 237*6bf19c94SChristoph Hellwig if [ ! -f $seq.out ] 238*6bf19c94SChristoph Hellwig then 239*6bf19c94SChristoph Hellwig echo " - no qualified output" 240*6bf19c94SChristoph Hellwig err=true 241*6bf19c94SChristoph Hellwig else 242*6bf19c94SChristoph Hellwig if diff $seq.out $tmp.out >/dev/null 2>&1 243*6bf19c94SChristoph Hellwig then 244*6bf19c94SChristoph Hellwig echo "" 245*6bf19c94SChristoph Hellwig if $err 246*6bf19c94SChristoph Hellwig then 247*6bf19c94SChristoph Hellwig : 248*6bf19c94SChristoph Hellwig else 249*6bf19c94SChristoph Hellwig echo "$seq `expr $stop - $start`" >>$tmp.time 250*6bf19c94SChristoph Hellwig fi 251*6bf19c94SChristoph Hellwig else 252*6bf19c94SChristoph Hellwig echo " - output mismatch (see $seq.out.bad)" 253*6bf19c94SChristoph Hellwig mv $tmp.out $seq.out.bad 254*6bf19c94SChristoph Hellwig $diff $seq.out $seq.out.bad 255*6bf19c94SChristoph Hellwig err=true 256*6bf19c94SChristoph Hellwig fi 257*6bf19c94SChristoph Hellwig fi 258*6bf19c94SChristoph Hellwig fi 259*6bf19c94SChristoph Hellwig 260*6bf19c94SChristoph Hellwig fi 261*6bf19c94SChristoph Hellwig 262*6bf19c94SChristoph Hellwig # come here for each test, except when $showme is true 263*6bf19c94SChristoph Hellwig # 264*6bf19c94SChristoph Hellwig if $err 265*6bf19c94SChristoph Hellwig then 266*6bf19c94SChristoph Hellwig bad="$bad $seq" 267*6bf19c94SChristoph Hellwig n_bad=`expr $n_bad + 1` 268*6bf19c94SChristoph Hellwig quick=false 269*6bf19c94SChristoph Hellwig fi 270*6bf19c94SChristoph Hellwig [ -f $seq.notrun ] || try=`expr $try + 1` 271*6bf19c94SChristoph Hellwig 272*6bf19c94SChristoph Hellwig seq="after_$seq" 273*6bf19c94SChristoph Hellwigdone 274*6bf19c94SChristoph Hellwig 275*6bf19c94SChristoph Hellwiginterrupt=false 276*6bf19c94SChristoph Hellwigstatus=`expr $n_bad` 277*6bf19c94SChristoph Hellwigexit 278