1908eaf68SStefan Hajnoczi#!/bin/bash 26bf19c94SChristoph Hellwig# 36bf19c94SChristoph Hellwig# Copyright (C) 2009 Red Hat, Inc. 46bf19c94SChristoph Hellwig# Copyright (c) 2000-2002,2006 Silicon Graphics, Inc. All Rights Reserved. 56bf19c94SChristoph Hellwig# 66bf19c94SChristoph Hellwig# This program is free software; you can redistribute it and/or 76bf19c94SChristoph Hellwig# modify it under the terms of the GNU General Public License as 86bf19c94SChristoph Hellwig# published by the Free Software Foundation. 96bf19c94SChristoph Hellwig# 106bf19c94SChristoph Hellwig# This program is distributed in the hope that it would be useful, 116bf19c94SChristoph Hellwig# but WITHOUT ANY WARRANTY; without even the implied warranty of 126bf19c94SChristoph Hellwig# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136bf19c94SChristoph Hellwig# GNU General Public License for more details. 146bf19c94SChristoph Hellwig# 156bf19c94SChristoph Hellwig# You should have received a copy of the GNU General Public License 16e8c212d6SChristoph Hellwig# along with this program. If not, see <http://www.gnu.org/licenses/>. 176bf19c94SChristoph Hellwig# 186bf19c94SChristoph Hellwig# 196bf19c94SChristoph Hellwig# Control script for QA 206bf19c94SChristoph Hellwig# 216bf19c94SChristoph Hellwig 226bf19c94SChristoph Hellwigtmp=/tmp/$$ 236bf19c94SChristoph Hellwigstatus=0 246bf19c94SChristoph Hellwigneedwrap=true 256bf19c94SChristoph Hellwigtry=0 266bf19c94SChristoph Hellwign_bad=0 276bf19c94SChristoph Hellwigbad="" 286bf19c94SChristoph Hellwignotrun="" 296bf19c94SChristoph Hellwiginterrupt=true 306bf19c94SChristoph Hellwig 316bf19c94SChristoph Hellwig# by default don't output timestamps 326bf19c94SChristoph Hellwigtimestamp=${TIMESTAMP:=false} 336bf19c94SChristoph Hellwig 346bf19c94SChristoph Hellwig# generic initialization 356bf19c94SChristoph Hellwigiam=check 366bf19c94SChristoph Hellwig 376bf19c94SChristoph Hellwig# we need common.config 386bf19c94SChristoph Hellwigif ! . ./common.config 396bf19c94SChristoph Hellwigthen 406bf19c94SChristoph Hellwig echo "$iam: failed to source common.config" 416bf19c94SChristoph Hellwig exit 1 426bf19c94SChristoph Hellwigfi 436bf19c94SChristoph Hellwig 446bf19c94SChristoph Hellwig# we need common 456bf19c94SChristoph Hellwig. ./common 466bf19c94SChristoph Hellwig 476bf19c94SChristoph Hellwig# we need common.rc 486bf19c94SChristoph Hellwigif ! . ./common.rc 496bf19c94SChristoph Hellwigthen 506bf19c94SChristoph Hellwig echo "check: failed to source common.rc" 516bf19c94SChristoph Hellwig exit 1 526bf19c94SChristoph Hellwigfi 536bf19c94SChristoph Hellwig 546bf19c94SChristoph Hellwig#if [ `id -u` -ne 0 ] 556bf19c94SChristoph Hellwig#then 566bf19c94SChristoph Hellwig# echo "check: QA must be run as root" 576bf19c94SChristoph Hellwig# exit 1 586bf19c94SChristoph Hellwig#fi 596bf19c94SChristoph Hellwig 606bf19c94SChristoph Hellwig_wallclock() 616bf19c94SChristoph Hellwig{ 626bf19c94SChristoph Hellwig date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }' 636bf19c94SChristoph Hellwig} 646bf19c94SChristoph Hellwig 656bf19c94SChristoph Hellwig_timestamp() 666bf19c94SChristoph Hellwig{ 676bf19c94SChristoph Hellwig now=`date "+%T"` 686bf19c94SChristoph Hellwig echo -n " [$now]" 696bf19c94SChristoph Hellwig} 706bf19c94SChristoph Hellwig 716bf19c94SChristoph Hellwig_wrapup() 726bf19c94SChristoph Hellwig{ 736bf19c94SChristoph Hellwig # for hangcheck ... 746bf19c94SChristoph Hellwig # remove files that were used by hangcheck 756bf19c94SChristoph Hellwig # 766bf19c94SChristoph Hellwig [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid 776bf19c94SChristoph Hellwig [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts 786bf19c94SChristoph Hellwig 796bf19c94SChristoph Hellwig if $showme 806bf19c94SChristoph Hellwig then 816bf19c94SChristoph Hellwig : 826bf19c94SChristoph Hellwig elif $needwrap 836bf19c94SChristoph Hellwig then 846bf19c94SChristoph Hellwig if [ -f check.time -a -f $tmp.time ] 856bf19c94SChristoph Hellwig then 866bf19c94SChristoph Hellwig cat check.time $tmp.time \ 876bf19c94SChristoph Hellwig | $AWK_PROG ' 886bf19c94SChristoph Hellwig { t[$1] = $2 } 896bf19c94SChristoph HellwigEND { if (NR > 0) { 906bf19c94SChristoph Hellwig for (i in t) print i " " t[i] 916bf19c94SChristoph Hellwig } 926bf19c94SChristoph Hellwig }' \ 936bf19c94SChristoph Hellwig | sort -n >$tmp.out 946bf19c94SChristoph Hellwig mv $tmp.out check.time 956bf19c94SChristoph Hellwig fi 966bf19c94SChristoph Hellwig 976bf19c94SChristoph Hellwig if [ -f $tmp.expunged ] 986bf19c94SChristoph Hellwig then 996bf19c94SChristoph Hellwig notrun=`wc -l <$tmp.expunged | sed -e 's/ *//g'` 1006bf19c94SChristoph Hellwig try=`expr $try - $notrun` 1016bf19c94SChristoph Hellwig list=`echo "$list" | sed -f $tmp.expunged` 1026bf19c94SChristoph Hellwig fi 1036bf19c94SChristoph Hellwig 1046bf19c94SChristoph Hellwig echo "" >>check.log 1056bf19c94SChristoph Hellwig date >>check.log 1066bf19c94SChristoph Hellwig echo $list | fmt | sed -e 's/^/ /' >>check.log 1076bf19c94SChristoph Hellwig $interrupt && echo "Interrupted!" >>check.log 1086bf19c94SChristoph Hellwig 1096bf19c94SChristoph Hellwig if [ ! -z "$notrun" ] 1106bf19c94SChristoph Hellwig then 1116bf19c94SChristoph Hellwig echo "Not run:$notrun" 1126bf19c94SChristoph Hellwig echo "Not run:$notrun" >>check.log 1136bf19c94SChristoph Hellwig fi 1146bf19c94SChristoph Hellwig if [ ! -z "$n_bad" -a $n_bad != 0 ] 1156bf19c94SChristoph Hellwig then 1166bf19c94SChristoph Hellwig echo "Failures:$bad" 1176bf19c94SChristoph Hellwig echo "Failed $n_bad of $try tests" 1186bf19c94SChristoph Hellwig echo "Failures:$bad" | fmt >>check.log 1196bf19c94SChristoph Hellwig echo "Failed $n_bad of $try tests" >>check.log 1206bf19c94SChristoph Hellwig else 1216bf19c94SChristoph Hellwig echo "Passed all $try tests" 1226bf19c94SChristoph Hellwig echo "Passed all $try tests" >>check.log 1236bf19c94SChristoph Hellwig fi 1246bf19c94SChristoph Hellwig needwrap=false 1256bf19c94SChristoph Hellwig fi 1266bf19c94SChristoph Hellwig 1276bf19c94SChristoph Hellwig rm -f /tmp/*.out /tmp/*.err /tmp/*.time 1286bf19c94SChristoph Hellwig rm -f /tmp/check.pid /tmp/check.sts 1296bf19c94SChristoph Hellwig rm -f $tmp.* 1306bf19c94SChristoph Hellwig} 1316bf19c94SChristoph Hellwig 1326bf19c94SChristoph Hellwigtrap "_wrapup; exit \$status" 0 1 2 3 15 1336bf19c94SChristoph Hellwig 1346bf19c94SChristoph Hellwig# for hangcheck ... 1356bf19c94SChristoph Hellwig# Save pid of check in a well known place, so that hangcheck can be sure it 1366bf19c94SChristoph Hellwig# has the right pid (getting the pid from ps output is not reliable enough). 1376bf19c94SChristoph Hellwig# 1386bf19c94SChristoph Hellwigrm -rf /tmp/check.pid 1396bf19c94SChristoph Hellwigecho $$ >/tmp/check.pid 1406bf19c94SChristoph Hellwig 1416bf19c94SChristoph Hellwig# for hangcheck ... 1426bf19c94SChristoph Hellwig# Save the status of check in a well known place, so that hangcheck can be 1436bf19c94SChristoph Hellwig# sure to know where check is up to (getting test number from ps output is 1446bf19c94SChristoph Hellwig# not reliable enough since the trace stuff has been introduced). 1456bf19c94SChristoph Hellwig# 1466bf19c94SChristoph Hellwigrm -rf /tmp/check.sts 1476bf19c94SChristoph Hellwigecho "preamble" >/tmp/check.sts 1486bf19c94SChristoph Hellwig 1496bf19c94SChristoph Hellwig# don't leave old full output behind on a clean run 1506bf19c94SChristoph Hellwigrm -f check.full 1516bf19c94SChristoph Hellwig 1526bf19c94SChristoph Hellwig[ -f check.time ] || touch check.time 1536bf19c94SChristoph Hellwig 1546bf19c94SChristoph HellwigFULL_IMGFMT_DETAILS=`_full_imgfmt_details` 1559cdfa1b3SMORITA KazutakaFULL_IMGPROTO_DETAILS=`_full_imgproto_details` 1566bf19c94SChristoph HellwigFULL_HOST_DETAILS=`_full_platform_details` 1576bf19c94SChristoph Hellwig#FULL_MKFS_OPTIONS=`_scratch_mkfs_options` 1586bf19c94SChristoph Hellwig#FULL_MOUNT_OPTIONS=`_scratch_mount_options` 1596bf19c94SChristoph Hellwig 1606bf19c94SChristoph Hellwigcat <<EOF 161df4b627eSLucas Meneghel RodriguesQEMU -- $QEMU 162df4b627eSLucas Meneghel RodriguesQEMU_IMG -- $QEMU_IMG 163df4b627eSLucas Meneghel RodriguesQEMU_IO -- $QEMU_IO 1646bf19c94SChristoph HellwigIMGFMT -- $FULL_IMGFMT_DETAILS 1659cdfa1b3SMORITA KazutakaIMGPROTO -- $FULL_IMGPROTO_DETAILS 1666bf19c94SChristoph HellwigPLATFORM -- $FULL_HOST_DETAILS 1676bf19c94SChristoph Hellwig 1686bf19c94SChristoph HellwigEOF 1696bf19c94SChristoph Hellwig#MKFS_OPTIONS -- $FULL_MKFS_OPTIONS 1706bf19c94SChristoph Hellwig#MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS 1716bf19c94SChristoph Hellwig 1726bf19c94SChristoph Hellwigseq="check" 1736bf19c94SChristoph Hellwig 1746bf19c94SChristoph Hellwig[ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG 1756bf19c94SChristoph Hellwig 1766bf19c94SChristoph Hellwigfor seq in $list 1776bf19c94SChristoph Hellwigdo 1786bf19c94SChristoph Hellwig err=false 1796bf19c94SChristoph Hellwig echo -n "$seq" 1806bf19c94SChristoph Hellwig if [ -n "$TESTS_REMAINING_LOG" ] ; then 1816bf19c94SChristoph Hellwig sed -e "s/$seq//" -e 's/ / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp 1826bf19c94SChristoph Hellwig mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG 1836bf19c94SChristoph Hellwig sync 1846bf19c94SChristoph Hellwig fi 1856bf19c94SChristoph Hellwig 1866bf19c94SChristoph Hellwig if $showme 1876bf19c94SChristoph Hellwig then 1886bf19c94SChristoph Hellwig echo 1896bf19c94SChristoph Hellwig continue 1906bf19c94SChristoph Hellwig elif [ -f expunged ] && $expunge && egrep "^$seq([ ]|\$)" expunged >/dev/null 1916bf19c94SChristoph Hellwig then 1926bf19c94SChristoph Hellwig echo " - expunged" 1936bf19c94SChristoph Hellwig rm -f $seq.out.bad 1946bf19c94SChristoph Hellwig echo "/^$seq\$/d" >>$tmp.expunged 1956bf19c94SChristoph Hellwig elif [ ! -f $seq ] 1966bf19c94SChristoph Hellwig then 1976bf19c94SChristoph Hellwig echo " - no such test?" 1986bf19c94SChristoph Hellwig echo "/^$seq\$/d" >>$tmp.expunged 1996bf19c94SChristoph Hellwig else 2006bf19c94SChristoph Hellwig # really going to try and run this one 2016bf19c94SChristoph Hellwig # 2026bf19c94SChristoph Hellwig rm -f $seq.out.bad 2036bf19c94SChristoph Hellwig lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time` 2046bf19c94SChristoph Hellwig if [ "X$lasttime" != X ]; then 2056bf19c94SChristoph Hellwig echo -n " ${lasttime}s ..." 2066bf19c94SChristoph Hellwig else 2076bf19c94SChristoph Hellwig echo -n " " # prettier output with timestamps. 2086bf19c94SChristoph Hellwig fi 2096bf19c94SChristoph Hellwig rm -f core $seq.notrun 2106bf19c94SChristoph Hellwig 2116bf19c94SChristoph Hellwig # for hangcheck ... 2126bf19c94SChristoph Hellwig echo "$seq" >/tmp/check.sts 2136bf19c94SChristoph Hellwig 2146bf19c94SChristoph Hellwig start=`_wallclock` 2156bf19c94SChristoph Hellwig $timestamp && echo -n " ["`date "+%T"`"]" 2166bf19c94SChristoph Hellwig [ ! -x $seq ] && chmod u+x $seq # ensure we can run it 2176bf19c94SChristoph Hellwig ./$seq >$tmp.out 2>&1 2186bf19c94SChristoph Hellwig sts=$? 2196bf19c94SChristoph Hellwig $timestamp && _timestamp 2206bf19c94SChristoph Hellwig stop=`_wallclock` 2216bf19c94SChristoph Hellwig 2226bf19c94SChristoph Hellwig if [ -f core ] 2236bf19c94SChristoph Hellwig then 2246bf19c94SChristoph Hellwig echo -n " [dumped core]" 2256bf19c94SChristoph Hellwig mv core $seq.core 2266bf19c94SChristoph Hellwig err=true 2276bf19c94SChristoph Hellwig fi 2286bf19c94SChristoph Hellwig 2296bf19c94SChristoph Hellwig if [ -f $seq.notrun ] 2306bf19c94SChristoph Hellwig then 2316bf19c94SChristoph Hellwig $timestamp || echo -n " [not run] " 2326bf19c94SChristoph Hellwig $timestamp && echo " [not run]" && echo -n " $seq -- " 2336bf19c94SChristoph Hellwig cat $seq.notrun 2346bf19c94SChristoph Hellwig notrun="$notrun $seq" 2356bf19c94SChristoph Hellwig else 2366bf19c94SChristoph Hellwig if [ $sts -ne 0 ] 2376bf19c94SChristoph Hellwig then 2386bf19c94SChristoph Hellwig echo -n " [failed, exit status $sts]" 2396bf19c94SChristoph Hellwig err=true 2406bf19c94SChristoph Hellwig fi 2416bf19c94SChristoph Hellwig if [ ! -f $seq.out ] 2426bf19c94SChristoph Hellwig then 2436bf19c94SChristoph Hellwig echo " - no qualified output" 2446bf19c94SChristoph Hellwig err=true 2456bf19c94SChristoph Hellwig else 246*92ab69b6SKevin Wolf if diff -w $seq.out $tmp.out >/dev/null 2>&1 2476bf19c94SChristoph Hellwig then 2486bf19c94SChristoph Hellwig echo "" 2496bf19c94SChristoph Hellwig if $err 2506bf19c94SChristoph Hellwig then 2516bf19c94SChristoph Hellwig : 2526bf19c94SChristoph Hellwig else 2536bf19c94SChristoph Hellwig echo "$seq `expr $stop - $start`" >>$tmp.time 2546bf19c94SChristoph Hellwig fi 2556bf19c94SChristoph Hellwig else 2566bf19c94SChristoph Hellwig echo " - output mismatch (see $seq.out.bad)" 2576bf19c94SChristoph Hellwig mv $tmp.out $seq.out.bad 258*92ab69b6SKevin Wolf $diff -w $seq.out $seq.out.bad 2596bf19c94SChristoph Hellwig err=true 2606bf19c94SChristoph Hellwig fi 2616bf19c94SChristoph Hellwig fi 2626bf19c94SChristoph Hellwig fi 2636bf19c94SChristoph Hellwig 2646bf19c94SChristoph Hellwig fi 2656bf19c94SChristoph Hellwig 2666bf19c94SChristoph Hellwig # come here for each test, except when $showme is true 2676bf19c94SChristoph Hellwig # 2686bf19c94SChristoph Hellwig if $err 2696bf19c94SChristoph Hellwig then 2706bf19c94SChristoph Hellwig bad="$bad $seq" 2716bf19c94SChristoph Hellwig n_bad=`expr $n_bad + 1` 2726bf19c94SChristoph Hellwig quick=false 2736bf19c94SChristoph Hellwig fi 2746bf19c94SChristoph Hellwig [ -f $seq.notrun ] || try=`expr $try + 1` 2756bf19c94SChristoph Hellwig 2766bf19c94SChristoph Hellwig seq="after_$seq" 2776bf19c94SChristoph Hellwigdone 2786bf19c94SChristoph Hellwig 2796bf19c94SChristoph Hellwiginterrupt=false 2806bf19c94SChristoph Hellwigstatus=`expr $n_bad` 2816bf19c94SChristoph Hellwigexit 282