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 Hellwigstatus=0 236bf19c94SChristoph Hellwigneedwrap=true 246bf19c94SChristoph Hellwigtry=0 256bf19c94SChristoph Hellwign_bad=0 266bf19c94SChristoph Hellwigbad="" 276bf19c94SChristoph Hellwignotrun="" 286bf19c94SChristoph Hellwiginterrupt=true 296bf19c94SChristoph Hellwig 306bf19c94SChristoph Hellwig# by default don't output timestamps 316bf19c94SChristoph Hellwigtimestamp=${TIMESTAMP:=false} 326bf19c94SChristoph Hellwig 33e8f8624dSMax Reitz_init_error() 34e8f8624dSMax Reitz{ 35*4e670492SPaolo Bonzini echo "check: $1" >&2 366bf19c94SChristoph Hellwig exit 1 37e8f8624dSMax Reitz} 38e8f8624dSMax Reitz 39e8f8624dSMax Reitzif [ -L "$0" ] 40e8f8624dSMax Reitzthen 41e8f8624dSMax Reitz # called from the build tree 42e8f8624dSMax Reitz source_iotests=$(dirname "$(readlink "$0")") 43e8f8624dSMax Reitz if [ -z "$source_iotests" ] 44e8f8624dSMax Reitz then 45e8f8624dSMax Reitz _init_error "failed to obtain source tree name from check symlink" 46e8f8624dSMax Reitz fi 47e8f8624dSMax Reitz source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" 48e8f8624dSMax Reitz build_iotests=$PWD 49e8f8624dSMax Reitzelse 50e8f8624dSMax Reitz # called from the source tree 51e8f8624dSMax Reitz source_iotests=$PWD 52e8f8624dSMax Reitz # this may be an in-tree build (note that in the following code we may not 53e8f8624dSMax Reitz # assume that it truly is and have to test whether the build results 54e8f8624dSMax Reitz # actually exist) 55e8f8624dSMax Reitz build_iotests=$PWD 56e8f8624dSMax Reitzfi 57e8f8624dSMax Reitz 58e8f8624dSMax Reitzbuild_root="$build_iotests/../.." 59e8f8624dSMax Reitz 607fed1a49SMax Reitz# we need common.env 617fed1a49SMax Reitzif ! . "$build_iotests/common.env" 627fed1a49SMax Reitzthen 637fed1a49SMax Reitz _init_error "failed to source common.env (make sure the qemu-iotests are run from tests/qemu-iotests in the build tree)" 647fed1a49SMax Reitzfi 657fed1a49SMax Reitz 66e8f8624dSMax Reitz# we need common.config 67e8f8624dSMax Reitzif ! . "$source_iotests/common.config" 68e8f8624dSMax Reitzthen 69e8f8624dSMax Reitz _init_error "failed to source common.config" 706bf19c94SChristoph Hellwigfi 716bf19c94SChristoph Hellwig 7289004368SKevin Wolf# we need common 73e8f8624dSMax Reitz. "$source_iotests/common" 7489004368SKevin Wolf 7536bd4228SDaniel P. BerrangeTIMESTAMP_FILE=check.time-$IMGPROTO-$IMGFMT 7636bd4228SDaniel P. Berrange 776bf19c94SChristoph Hellwig_wallclock() 786bf19c94SChristoph Hellwig{ 799ee4b6f8SPaolo Bonzini date "+%H %M %S" | awk '{ print $1*3600 + $2*60 + $3 }' 806bf19c94SChristoph Hellwig} 816bf19c94SChristoph Hellwig 826bf19c94SChristoph Hellwig_timestamp() 836bf19c94SChristoph Hellwig{ 846bf19c94SChristoph Hellwig now=`date "+%T"` 85b43671f8SEric Blake printf %s " [$now]" 866bf19c94SChristoph Hellwig} 876bf19c94SChristoph Hellwig 886bf19c94SChristoph Hellwig_wrapup() 896bf19c94SChristoph Hellwig{ 906bf19c94SChristoph Hellwig if $showme 916bf19c94SChristoph Hellwig then 926bf19c94SChristoph Hellwig : 936bf19c94SChristoph Hellwig elif $needwrap 946bf19c94SChristoph Hellwig then 9536bd4228SDaniel P. Berrange if [ -f $TIMESTAMP_FILE -a -f $tmp.time ] 966bf19c94SChristoph Hellwig then 9736bd4228SDaniel P. Berrange cat $TIMESTAMP_FILE $tmp.time \ 989ee4b6f8SPaolo Bonzini | awk ' 996bf19c94SChristoph Hellwig { t[$1] = $2 } 1006bf19c94SChristoph HellwigEND { if (NR > 0) { 1016bf19c94SChristoph Hellwig for (i in t) print i " " t[i] 1026bf19c94SChristoph Hellwig } 1036bf19c94SChristoph Hellwig }' \ 1046bf19c94SChristoph Hellwig | sort -n >$tmp.out 10536bd4228SDaniel P. Berrange mv $tmp.out $TIMESTAMP_FILE 1066bf19c94SChristoph Hellwig fi 1076bf19c94SChristoph Hellwig 1086bf19c94SChristoph Hellwig if [ -f $tmp.expunged ] 1096bf19c94SChristoph Hellwig then 1106bf19c94SChristoph Hellwig notrun=`wc -l <$tmp.expunged | sed -e 's/ *//g'` 1116bf19c94SChristoph Hellwig try=`expr $try - $notrun` 1126bf19c94SChristoph Hellwig list=`echo "$list" | sed -f $tmp.expunged` 1136bf19c94SChristoph Hellwig fi 1146bf19c94SChristoph Hellwig 1156bf19c94SChristoph Hellwig echo "" >>check.log 1166bf19c94SChristoph Hellwig date >>check.log 1176bf19c94SChristoph Hellwig echo $list | fmt | sed -e 's/^/ /' >>check.log 1186bf19c94SChristoph Hellwig $interrupt && echo "Interrupted!" >>check.log 1196bf19c94SChristoph Hellwig 1206bf19c94SChristoph Hellwig if [ ! -z "$notrun" ] 1216bf19c94SChristoph Hellwig then 1226bf19c94SChristoph Hellwig echo "Not run:$notrun" 1236bf19c94SChristoph Hellwig echo "Not run:$notrun" >>check.log 1246bf19c94SChristoph Hellwig fi 1256bf19c94SChristoph Hellwig if [ ! -z "$n_bad" -a $n_bad != 0 ] 1266bf19c94SChristoph Hellwig then 1276bf19c94SChristoph Hellwig echo "Failures:$bad" 1286bf19c94SChristoph Hellwig echo "Failed $n_bad of $try tests" 1296bf19c94SChristoph Hellwig echo "Failures:$bad" | fmt >>check.log 1306bf19c94SChristoph Hellwig echo "Failed $n_bad of $try tests" >>check.log 1316bf19c94SChristoph Hellwig else 1326bf19c94SChristoph Hellwig echo "Passed all $try tests" 1336bf19c94SChristoph Hellwig echo "Passed all $try tests" >>check.log 1346bf19c94SChristoph Hellwig fi 1356bf19c94SChristoph Hellwig needwrap=false 1366bf19c94SChristoph Hellwig fi 1376bf19c94SChristoph Hellwig 1380145b4e1SSascha Silbe rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.time 1390145b4e1SSascha Silbe rm -f "${TEST_DIR}"/check.pid "${TEST_DIR}"/check.sts 1406bf19c94SChristoph Hellwig rm -f $tmp.* 1416bf19c94SChristoph Hellwig} 1426bf19c94SChristoph Hellwig 1436bf19c94SChristoph Hellwigtrap "_wrapup; exit \$status" 0 1 2 3 15 1446bf19c94SChristoph Hellwig 14536bd4228SDaniel P. Berrange[ -f $TIMESTAMP_FILE ] || touch $TIMESTAMP_FILE 1466bf19c94SChristoph Hellwig 1476bf19c94SChristoph HellwigFULL_IMGFMT_DETAILS=`_full_imgfmt_details` 1486bf19c94SChristoph HellwigFULL_HOST_DETAILS=`_full_platform_details` 1496bf19c94SChristoph Hellwig 1506bf19c94SChristoph Hellwigcat <<EOF 151934659c4SMax ReitzQEMU -- "$QEMU_PROG" $QEMU_OPTIONS 152934659c4SMax ReitzQEMU_IMG -- "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS 153934659c4SMax ReitzQEMU_IO -- "$QEMU_IO_PROG" $QEMU_IO_OPTIONS 154934659c4SMax ReitzQEMU_NBD -- "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS 1556bf19c94SChristoph HellwigIMGFMT -- $FULL_IMGFMT_DETAILS 156657c572aSCleber RosaIMGPROTO -- $IMGPROTO 1576bf19c94SChristoph HellwigPLATFORM -- $FULL_HOST_DETAILS 158b8aff7d6SFam ZhengTEST_DIR -- $TEST_DIR 15930b005d9SWenchao XiaSOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER 1606bf19c94SChristoph Hellwig 1616bf19c94SChristoph HellwigEOF 1626bf19c94SChristoph Hellwig 1636bf19c94SChristoph Hellwigseq="check" 1646bf19c94SChristoph Hellwig 1656bf19c94SChristoph Hellwig[ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG 1666bf19c94SChristoph Hellwig 1676bf19c94SChristoph Hellwigfor seq in $list 1686bf19c94SChristoph Hellwigdo 1696bf19c94SChristoph Hellwig err=false 170b43671f8SEric Blake printf %s "$seq" 1716bf19c94SChristoph Hellwig if [ -n "$TESTS_REMAINING_LOG" ] ; then 1726bf19c94SChristoph Hellwig sed -e "s/$seq//" -e 's/ / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp 1736bf19c94SChristoph Hellwig mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG 1746bf19c94SChristoph Hellwig sync 1756bf19c94SChristoph Hellwig fi 1766bf19c94SChristoph Hellwig 1776bf19c94SChristoph Hellwig if $showme 1786bf19c94SChristoph Hellwig then 1796bf19c94SChristoph Hellwig echo 1806bf19c94SChristoph Hellwig continue 1816bf19c94SChristoph Hellwig elif [ -f expunged ] && $expunge && egrep "^$seq([ ]|\$)" expunged >/dev/null 1826bf19c94SChristoph Hellwig then 1836bf19c94SChristoph Hellwig echo " - expunged" 1846bf19c94SChristoph Hellwig rm -f $seq.out.bad 1856bf19c94SChristoph Hellwig echo "/^$seq\$/d" >>$tmp.expunged 186e8f8624dSMax Reitz elif [ ! -f "$source_iotests/$seq" ] 1876bf19c94SChristoph Hellwig then 1886bf19c94SChristoph Hellwig echo " - no such test?" 1896bf19c94SChristoph Hellwig echo "/^$seq\$/d" >>$tmp.expunged 1906bf19c94SChristoph Hellwig else 1916bf19c94SChristoph Hellwig # really going to try and run this one 1926bf19c94SChristoph Hellwig # 1936bf19c94SChristoph Hellwig rm -f $seq.out.bad 19436bd4228SDaniel P. Berrange lasttime=`sed -n -e "/^$seq /s/.* //p" <$TIMESTAMP_FILE` 1956bf19c94SChristoph Hellwig if [ "X$lasttime" != X ]; then 196b43671f8SEric Blake printf %s " ${lasttime}s ..." 1976bf19c94SChristoph Hellwig else 198b43671f8SEric Blake printf " " # prettier output with timestamps. 1996bf19c94SChristoph Hellwig fi 2006bf19c94SChristoph Hellwig rm -f core $seq.notrun 2016bf19c94SChristoph Hellwig 2026bf19c94SChristoph Hellwig start=`_wallclock` 203b43671f8SEric Blake $timestamp && printf %s " [$(date "+%T")]" 204ea81ca9dSMax Reitz 205ea81ca9dSMax Reitz if [ "$(head -n 1 "$source_iotests/$seq")" == "#!/usr/bin/env python" ]; then 206ea81ca9dSMax Reitz run_command="$PYTHON $seq" 207ea81ca9dSMax Reitz else 208ea81ca9dSMax Reitz run_command="./$seq" 209ea81ca9dSMax Reitz fi 210e8f8624dSMax Reitz export OUTPUT_DIR=$PWD 211aa4f592aSFam Zheng if $debug; then 212aa4f592aSFam Zheng (cd "$source_iotests"; 213aa4f592aSFam Zheng MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \ 214aa4f592aSFam Zheng $run_command -d 2>&1 | tee $tmp.out) 215aa4f592aSFam Zheng else 216e8f8624dSMax Reitz (cd "$source_iotests"; 21704129606SStefan Hajnoczi MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \ 218ea81ca9dSMax Reitz $run_command >$tmp.out 2>&1) 219aa4f592aSFam Zheng fi 2206bf19c94SChristoph Hellwig sts=$? 2216bf19c94SChristoph Hellwig $timestamp && _timestamp 2226bf19c94SChristoph Hellwig stop=`_wallclock` 2236bf19c94SChristoph Hellwig 2246bf19c94SChristoph Hellwig if [ -f core ] 2256bf19c94SChristoph Hellwig then 226b43671f8SEric Blake printf " [dumped core]" 2276bf19c94SChristoph Hellwig mv core $seq.core 2286bf19c94SChristoph Hellwig err=true 2296bf19c94SChristoph Hellwig fi 2306bf19c94SChristoph Hellwig 2316bf19c94SChristoph Hellwig if [ -f $seq.notrun ] 2326bf19c94SChristoph Hellwig then 233b43671f8SEric Blake $timestamp || printf " [not run] " 234b43671f8SEric Blake $timestamp && echo " [not run]" && printf %s " $seq -- " 2356bf19c94SChristoph Hellwig cat $seq.notrun 2366bf19c94SChristoph Hellwig notrun="$notrun $seq" 2376bf19c94SChristoph Hellwig else 2386bf19c94SChristoph Hellwig if [ $sts -ne 0 ] 2396bf19c94SChristoph Hellwig then 240b43671f8SEric Blake printf %s " [failed, exit status $sts]" 2416bf19c94SChristoph Hellwig err=true 2426bf19c94SChristoph Hellwig fi 2438f94b077SKevin Wolf 244e8f8624dSMax Reitz reference="$source_iotests/$seq.out" 245e166b414SBo Tu reference_machine="$source_iotests/$seq.$QEMU_DEFAULT_MACHINE.out" 246e166b414SBo Tu if [ -f "$reference_machine" ]; then 247e166b414SBo Tu reference="$reference_machine" 248e166b414SBo Tu fi 249e166b414SBo Tu 250217a0683SStefan Hajnoczi reference_format="$source_iotests/$seq.out.$IMGFMT" 251217a0683SStefan Hajnoczi if [ -f "$reference_format" ]; then 252217a0683SStefan Hajnoczi reference="$reference_format" 253217a0683SStefan Hajnoczi fi 254217a0683SStefan Hajnoczi 2553baa8449SFam Zheng if [ "$CACHEMODE" = "none" ]; then 256e8f8624dSMax Reitz [ -f "$source_iotests/$seq.out.nocache" ] && reference="$source_iotests/$seq.out.nocache" 2578f94b077SKevin Wolf fi 2588f94b077SKevin Wolf 259e8f8624dSMax Reitz if [ ! -f "$reference" ] 2606bf19c94SChristoph Hellwig then 2616bf19c94SChristoph Hellwig echo " - no qualified output" 2626bf19c94SChristoph Hellwig err=true 2636bf19c94SChristoph Hellwig else 264e8f8624dSMax Reitz if diff -w "$reference" $tmp.out >/dev/null 2>&1 2656bf19c94SChristoph Hellwig then 2666bf19c94SChristoph Hellwig echo "" 2676bf19c94SChristoph Hellwig if $err 2686bf19c94SChristoph Hellwig then 2696bf19c94SChristoph Hellwig : 2706bf19c94SChristoph Hellwig else 2716bf19c94SChristoph Hellwig echo "$seq `expr $stop - $start`" >>$tmp.time 2726bf19c94SChristoph Hellwig fi 2736bf19c94SChristoph Hellwig else 2746bf19c94SChristoph Hellwig echo " - output mismatch (see $seq.out.bad)" 2756bf19c94SChristoph Hellwig mv $tmp.out $seq.out.bad 27693e53fb6SFam Zheng $diff -w "$reference" $(realpath $seq.out.bad) 2776bf19c94SChristoph Hellwig err=true 2786bf19c94SChristoph Hellwig fi 2796bf19c94SChristoph Hellwig fi 2806bf19c94SChristoph Hellwig fi 2816bf19c94SChristoph Hellwig 2826bf19c94SChristoph Hellwig fi 2836bf19c94SChristoph Hellwig 2846bf19c94SChristoph Hellwig # come here for each test, except when $showme is true 2856bf19c94SChristoph Hellwig # 2866bf19c94SChristoph Hellwig if $err 2876bf19c94SChristoph Hellwig then 2886bf19c94SChristoph Hellwig bad="$bad $seq" 2896bf19c94SChristoph Hellwig n_bad=`expr $n_bad + 1` 2906bf19c94SChristoph Hellwig quick=false 2916bf19c94SChristoph Hellwig fi 2926bf19c94SChristoph Hellwig [ -f $seq.notrun ] || try=`expr $try + 1` 2936bf19c94SChristoph Hellwig 2946bf19c94SChristoph Hellwig seq="after_$seq" 2956bf19c94SChristoph Hellwigdone 2966bf19c94SChristoph Hellwig 2976bf19c94SChristoph Hellwiginterrupt=false 2986bf19c94SChristoph Hellwigstatus=`expr $n_bad` 2996bf19c94SChristoph Hellwigexit 300