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 37*e8f8624dSMax Reitz_init_error() 38*e8f8624dSMax Reitz{ 39*e8f8624dSMax Reitz echo "$iam: $1" >&2 406bf19c94SChristoph Hellwig exit 1 41*e8f8624dSMax Reitz} 42*e8f8624dSMax Reitz 43*e8f8624dSMax Reitzif [ -L "$0" ] 44*e8f8624dSMax Reitzthen 45*e8f8624dSMax Reitz # called from the build tree 46*e8f8624dSMax Reitz source_iotests=$(dirname "$(readlink "$0")") 47*e8f8624dSMax Reitz if [ -z "$source_iotests" ] 48*e8f8624dSMax Reitz then 49*e8f8624dSMax Reitz _init_error "failed to obtain source tree name from check symlink" 50*e8f8624dSMax Reitz fi 51*e8f8624dSMax Reitz source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" 52*e8f8624dSMax Reitz build_iotests=$PWD 53*e8f8624dSMax Reitzelse 54*e8f8624dSMax Reitz # called from the source tree 55*e8f8624dSMax Reitz source_iotests=$PWD 56*e8f8624dSMax Reitz # this may be an in-tree build (note that in the following code we may not 57*e8f8624dSMax Reitz # assume that it truly is and have to test whether the build results 58*e8f8624dSMax Reitz # actually exist) 59*e8f8624dSMax Reitz build_iotests=$PWD 60*e8f8624dSMax Reitzfi 61*e8f8624dSMax Reitz 62*e8f8624dSMax Reitzbuild_root="$build_iotests/../.." 63*e8f8624dSMax Reitz 64*e8f8624dSMax Reitzif [ -x "$build_iotests/socket_scm_helper" ] 65*e8f8624dSMax Reitzthen 66*e8f8624dSMax Reitz export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper" 67*e8f8624dSMax Reitzfi 68*e8f8624dSMax Reitz 69*e8f8624dSMax Reitz# if ./qemu exists, it should be prioritized and will be chosen by common.config 70*e8f8624dSMax Reitzif [[ -z "$QEMU_PROG" && ! -x './qemu' ]] 71*e8f8624dSMax Reitzthen 72*e8f8624dSMax Reitz arch=$(uname -m 2> /dev/null) 73*e8f8624dSMax Reitz 74*e8f8624dSMax Reitz if [[ -n $arch && -x "$build_root/$arch-softmmu/qemu-system-$arch" ]] 75*e8f8624dSMax Reitz then 76*e8f8624dSMax Reitz export QEMU_PROG="$build_root/$arch-softmmu/qemu-system-$arch" 77*e8f8624dSMax Reitz else 78*e8f8624dSMax Reitz pushd "$build_root" > /dev/null 79*e8f8624dSMax Reitz for binary in *-softmmu/qemu-system-* 80*e8f8624dSMax Reitz do 81*e8f8624dSMax Reitz if [ -x "$binary" ] 82*e8f8624dSMax Reitz then 83*e8f8624dSMax Reitz export QEMU_PROG="$build_root/$binary" 84*e8f8624dSMax Reitz break 85*e8f8624dSMax Reitz fi 86*e8f8624dSMax Reitz done 87*e8f8624dSMax Reitz popd > /dev/null 88*e8f8624dSMax Reitz fi 89*e8f8624dSMax Reitzfi 90*e8f8624dSMax Reitz 91*e8f8624dSMax Reitzif [[ -z $QEMU_IMG_PROG && -x "$build_root/qemu-img" && ! -x './qemu-img' ]] 92*e8f8624dSMax Reitzthen 93*e8f8624dSMax Reitz export QEMU_IMG_PROG="$build_root/qemu-img" 94*e8f8624dSMax Reitzfi 95*e8f8624dSMax Reitz 96*e8f8624dSMax Reitzif [[ -z $QEMU_IO_PROG && -x "$build_root/qemu-io" && ! -x './qemu-io' ]] 97*e8f8624dSMax Reitzthen 98*e8f8624dSMax Reitz export QEMU_IO_PROG="$build_root/qemu-io" 99*e8f8624dSMax Reitzfi 100*e8f8624dSMax Reitz 101*e8f8624dSMax Reitzif [[ -z $QEMU_NBD_PROG && -x "$build_root/qemu-nbd" && ! -x './qemu-nbd' ]] 102*e8f8624dSMax Reitzthen 103*e8f8624dSMax Reitz export QEMU_NBD_PROG="$build_root/qemu-nbd" 104*e8f8624dSMax Reitzfi 105*e8f8624dSMax Reitz 106*e8f8624dSMax Reitz# we need common.config 107*e8f8624dSMax Reitzif ! . "$source_iotests/common.config" 108*e8f8624dSMax Reitzthen 109*e8f8624dSMax Reitz _init_error "failed to source common.config" 1106bf19c94SChristoph Hellwigfi 1116bf19c94SChristoph Hellwig 1126bf19c94SChristoph Hellwig# we need common.rc 113*e8f8624dSMax Reitzif ! . "$source_iotests/common.rc" 1146bf19c94SChristoph Hellwigthen 115*e8f8624dSMax Reitz _init_error "failed to source common.rc" 1166bf19c94SChristoph Hellwigfi 1176bf19c94SChristoph Hellwig 11889004368SKevin Wolf# we need common 119*e8f8624dSMax Reitz. "$source_iotests/common" 12089004368SKevin Wolf 1216bf19c94SChristoph Hellwig#if [ `id -u` -ne 0 ] 1226bf19c94SChristoph Hellwig#then 1236bf19c94SChristoph Hellwig# echo "check: QA must be run as root" 1246bf19c94SChristoph Hellwig# exit 1 1256bf19c94SChristoph Hellwig#fi 1266bf19c94SChristoph Hellwig 1276bf19c94SChristoph Hellwig_wallclock() 1286bf19c94SChristoph Hellwig{ 1296bf19c94SChristoph Hellwig date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }' 1306bf19c94SChristoph Hellwig} 1316bf19c94SChristoph Hellwig 1326bf19c94SChristoph Hellwig_timestamp() 1336bf19c94SChristoph Hellwig{ 1346bf19c94SChristoph Hellwig now=`date "+%T"` 1356bf19c94SChristoph Hellwig echo -n " [$now]" 1366bf19c94SChristoph Hellwig} 1376bf19c94SChristoph Hellwig 1386bf19c94SChristoph Hellwig_wrapup() 1396bf19c94SChristoph Hellwig{ 1406bf19c94SChristoph Hellwig # for hangcheck ... 1416bf19c94SChristoph Hellwig # remove files that were used by hangcheck 1426bf19c94SChristoph Hellwig # 1436bf19c94SChristoph Hellwig [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid 1446bf19c94SChristoph Hellwig [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts 1456bf19c94SChristoph Hellwig 1466bf19c94SChristoph Hellwig if $showme 1476bf19c94SChristoph Hellwig then 1486bf19c94SChristoph Hellwig : 1496bf19c94SChristoph Hellwig elif $needwrap 1506bf19c94SChristoph Hellwig then 1516bf19c94SChristoph Hellwig if [ -f check.time -a -f $tmp.time ] 1526bf19c94SChristoph Hellwig then 1536bf19c94SChristoph Hellwig cat check.time $tmp.time \ 1546bf19c94SChristoph Hellwig | $AWK_PROG ' 1556bf19c94SChristoph Hellwig { t[$1] = $2 } 1566bf19c94SChristoph HellwigEND { if (NR > 0) { 1576bf19c94SChristoph Hellwig for (i in t) print i " " t[i] 1586bf19c94SChristoph Hellwig } 1596bf19c94SChristoph Hellwig }' \ 1606bf19c94SChristoph Hellwig | sort -n >$tmp.out 1616bf19c94SChristoph Hellwig mv $tmp.out check.time 1626bf19c94SChristoph Hellwig fi 1636bf19c94SChristoph Hellwig 1646bf19c94SChristoph Hellwig if [ -f $tmp.expunged ] 1656bf19c94SChristoph Hellwig then 1666bf19c94SChristoph Hellwig notrun=`wc -l <$tmp.expunged | sed -e 's/ *//g'` 1676bf19c94SChristoph Hellwig try=`expr $try - $notrun` 1686bf19c94SChristoph Hellwig list=`echo "$list" | sed -f $tmp.expunged` 1696bf19c94SChristoph Hellwig fi 1706bf19c94SChristoph Hellwig 1716bf19c94SChristoph Hellwig echo "" >>check.log 1726bf19c94SChristoph Hellwig date >>check.log 1736bf19c94SChristoph Hellwig echo $list | fmt | sed -e 's/^/ /' >>check.log 1746bf19c94SChristoph Hellwig $interrupt && echo "Interrupted!" >>check.log 1756bf19c94SChristoph Hellwig 1766bf19c94SChristoph Hellwig if [ ! -z "$notrun" ] 1776bf19c94SChristoph Hellwig then 1786bf19c94SChristoph Hellwig echo "Not run:$notrun" 1796bf19c94SChristoph Hellwig echo "Not run:$notrun" >>check.log 1806bf19c94SChristoph Hellwig fi 1816bf19c94SChristoph Hellwig if [ ! -z "$n_bad" -a $n_bad != 0 ] 1826bf19c94SChristoph Hellwig then 1836bf19c94SChristoph Hellwig echo "Failures:$bad" 1846bf19c94SChristoph Hellwig echo "Failed $n_bad of $try tests" 1856bf19c94SChristoph Hellwig echo "Failures:$bad" | fmt >>check.log 1866bf19c94SChristoph Hellwig echo "Failed $n_bad of $try tests" >>check.log 1876bf19c94SChristoph Hellwig else 1886bf19c94SChristoph Hellwig echo "Passed all $try tests" 1896bf19c94SChristoph Hellwig echo "Passed all $try tests" >>check.log 1906bf19c94SChristoph Hellwig fi 1916bf19c94SChristoph Hellwig needwrap=false 1926bf19c94SChristoph Hellwig fi 1936bf19c94SChristoph Hellwig 1946bf19c94SChristoph Hellwig rm -f /tmp/*.out /tmp/*.err /tmp/*.time 1956bf19c94SChristoph Hellwig rm -f /tmp/check.pid /tmp/check.sts 1966bf19c94SChristoph Hellwig rm -f $tmp.* 1976bf19c94SChristoph Hellwig} 1986bf19c94SChristoph Hellwig 1996bf19c94SChristoph Hellwigtrap "_wrapup; exit \$status" 0 1 2 3 15 2006bf19c94SChristoph Hellwig 2016bf19c94SChristoph Hellwig# for hangcheck ... 2026bf19c94SChristoph Hellwig# Save pid of check in a well known place, so that hangcheck can be sure it 2036bf19c94SChristoph Hellwig# has the right pid (getting the pid from ps output is not reliable enough). 2046bf19c94SChristoph Hellwig# 2056bf19c94SChristoph Hellwigrm -rf /tmp/check.pid 2066bf19c94SChristoph Hellwigecho $$ >/tmp/check.pid 2076bf19c94SChristoph Hellwig 2086bf19c94SChristoph Hellwig# for hangcheck ... 2096bf19c94SChristoph Hellwig# Save the status of check in a well known place, so that hangcheck can be 2106bf19c94SChristoph Hellwig# sure to know where check is up to (getting test number from ps output is 2116bf19c94SChristoph Hellwig# not reliable enough since the trace stuff has been introduced). 2126bf19c94SChristoph Hellwig# 2136bf19c94SChristoph Hellwigrm -rf /tmp/check.sts 2146bf19c94SChristoph Hellwigecho "preamble" >/tmp/check.sts 2156bf19c94SChristoph Hellwig 2166bf19c94SChristoph Hellwig# don't leave old full output behind on a clean run 2176bf19c94SChristoph Hellwigrm -f check.full 2186bf19c94SChristoph Hellwig 2196bf19c94SChristoph Hellwig[ -f check.time ] || touch check.time 2206bf19c94SChristoph Hellwig 2216bf19c94SChristoph HellwigFULL_IMGFMT_DETAILS=`_full_imgfmt_details` 2229cdfa1b3SMORITA KazutakaFULL_IMGPROTO_DETAILS=`_full_imgproto_details` 2236bf19c94SChristoph HellwigFULL_HOST_DETAILS=`_full_platform_details` 2246bf19c94SChristoph Hellwig#FULL_MKFS_OPTIONS=`_scratch_mkfs_options` 2256bf19c94SChristoph Hellwig#FULL_MOUNT_OPTIONS=`_scratch_mount_options` 2266bf19c94SChristoph Hellwig 2276bf19c94SChristoph Hellwigcat <<EOF 228df4b627eSLucas Meneghel RodriguesQEMU -- $QEMU 229df4b627eSLucas Meneghel RodriguesQEMU_IMG -- $QEMU_IMG 230df4b627eSLucas Meneghel RodriguesQEMU_IO -- $QEMU_IO 2319c468a01SWenchao XiaQEMU_NBD -- $QEMU_NBD 2326bf19c94SChristoph HellwigIMGFMT -- $FULL_IMGFMT_DETAILS 2339cdfa1b3SMORITA KazutakaIMGPROTO -- $FULL_IMGPROTO_DETAILS 2346bf19c94SChristoph HellwigPLATFORM -- $FULL_HOST_DETAILS 23530b005d9SWenchao XiaSOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER 2366bf19c94SChristoph Hellwig 2376bf19c94SChristoph HellwigEOF 2386bf19c94SChristoph Hellwig#MKFS_OPTIONS -- $FULL_MKFS_OPTIONS 2396bf19c94SChristoph Hellwig#MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS 2406bf19c94SChristoph Hellwig 2416bf19c94SChristoph Hellwigseq="check" 2426bf19c94SChristoph Hellwig 2436bf19c94SChristoph Hellwig[ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG 2446bf19c94SChristoph Hellwig 2456bf19c94SChristoph Hellwigfor seq in $list 2466bf19c94SChristoph Hellwigdo 2476bf19c94SChristoph Hellwig err=false 2486bf19c94SChristoph Hellwig echo -n "$seq" 2496bf19c94SChristoph Hellwig if [ -n "$TESTS_REMAINING_LOG" ] ; then 2506bf19c94SChristoph Hellwig sed -e "s/$seq//" -e 's/ / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp 2516bf19c94SChristoph Hellwig mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG 2526bf19c94SChristoph Hellwig sync 2536bf19c94SChristoph Hellwig fi 2546bf19c94SChristoph Hellwig 2556bf19c94SChristoph Hellwig if $showme 2566bf19c94SChristoph Hellwig then 2576bf19c94SChristoph Hellwig echo 2586bf19c94SChristoph Hellwig continue 2596bf19c94SChristoph Hellwig elif [ -f expunged ] && $expunge && egrep "^$seq([ ]|\$)" expunged >/dev/null 2606bf19c94SChristoph Hellwig then 2616bf19c94SChristoph Hellwig echo " - expunged" 2626bf19c94SChristoph Hellwig rm -f $seq.out.bad 2636bf19c94SChristoph Hellwig echo "/^$seq\$/d" >>$tmp.expunged 264*e8f8624dSMax Reitz elif [ ! -f "$source_iotests/$seq" ] 2656bf19c94SChristoph Hellwig then 2666bf19c94SChristoph Hellwig echo " - no such test?" 2676bf19c94SChristoph Hellwig echo "/^$seq\$/d" >>$tmp.expunged 2686bf19c94SChristoph Hellwig else 2696bf19c94SChristoph Hellwig # really going to try and run this one 2706bf19c94SChristoph Hellwig # 2716bf19c94SChristoph Hellwig rm -f $seq.out.bad 2726bf19c94SChristoph Hellwig lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time` 2736bf19c94SChristoph Hellwig if [ "X$lasttime" != X ]; then 2746bf19c94SChristoph Hellwig echo -n " ${lasttime}s ..." 2756bf19c94SChristoph Hellwig else 2766bf19c94SChristoph Hellwig echo -n " " # prettier output with timestamps. 2776bf19c94SChristoph Hellwig fi 2786bf19c94SChristoph Hellwig rm -f core $seq.notrun 2796bf19c94SChristoph Hellwig 2806bf19c94SChristoph Hellwig # for hangcheck ... 2816bf19c94SChristoph Hellwig echo "$seq" >/tmp/check.sts 2826bf19c94SChristoph Hellwig 2836bf19c94SChristoph Hellwig start=`_wallclock` 2846bf19c94SChristoph Hellwig $timestamp && echo -n " ["`date "+%T"`"]" 285*e8f8624dSMax Reitz export OUTPUT_DIR=$PWD 286*e8f8624dSMax Reitz (cd "$source_iotests"; 28704129606SStefan Hajnoczi MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \ 288*e8f8624dSMax Reitz ./$seq >$tmp.out 2>&1) 2896bf19c94SChristoph Hellwig sts=$? 2906bf19c94SChristoph Hellwig $timestamp && _timestamp 2916bf19c94SChristoph Hellwig stop=`_wallclock` 2926bf19c94SChristoph Hellwig 2936bf19c94SChristoph Hellwig if [ -f core ] 2946bf19c94SChristoph Hellwig then 2956bf19c94SChristoph Hellwig echo -n " [dumped core]" 2966bf19c94SChristoph Hellwig mv core $seq.core 2976bf19c94SChristoph Hellwig err=true 2986bf19c94SChristoph Hellwig fi 2996bf19c94SChristoph Hellwig 3006bf19c94SChristoph Hellwig if [ -f $seq.notrun ] 3016bf19c94SChristoph Hellwig then 3026bf19c94SChristoph Hellwig $timestamp || echo -n " [not run] " 3036bf19c94SChristoph Hellwig $timestamp && echo " [not run]" && echo -n " $seq -- " 3046bf19c94SChristoph Hellwig cat $seq.notrun 3056bf19c94SChristoph Hellwig notrun="$notrun $seq" 3066bf19c94SChristoph Hellwig else 3076bf19c94SChristoph Hellwig if [ $sts -ne 0 ] 3086bf19c94SChristoph Hellwig then 3096bf19c94SChristoph Hellwig echo -n " [failed, exit status $sts]" 3106bf19c94SChristoph Hellwig err=true 3116bf19c94SChristoph Hellwig fi 3128f94b077SKevin Wolf 313*e8f8624dSMax Reitz reference="$source_iotests/$seq.out" 3143baa8449SFam Zheng if [ "$CACHEMODE" = "none" ]; then 315*e8f8624dSMax Reitz [ -f "$source_iotests/$seq.out.nocache" ] && reference="$source_iotests/$seq.out.nocache" 3168f94b077SKevin Wolf fi 3178f94b077SKevin Wolf 318*e8f8624dSMax Reitz if [ ! -f "$reference" ] 3196bf19c94SChristoph Hellwig then 3206bf19c94SChristoph Hellwig echo " - no qualified output" 3216bf19c94SChristoph Hellwig err=true 3226bf19c94SChristoph Hellwig else 323*e8f8624dSMax Reitz if diff -w "$reference" $tmp.out >/dev/null 2>&1 3246bf19c94SChristoph Hellwig then 3256bf19c94SChristoph Hellwig echo "" 3266bf19c94SChristoph Hellwig if $err 3276bf19c94SChristoph Hellwig then 3286bf19c94SChristoph Hellwig : 3296bf19c94SChristoph Hellwig else 3306bf19c94SChristoph Hellwig echo "$seq `expr $stop - $start`" >>$tmp.time 3316bf19c94SChristoph Hellwig fi 3326bf19c94SChristoph Hellwig else 3336bf19c94SChristoph Hellwig echo " - output mismatch (see $seq.out.bad)" 3346bf19c94SChristoph Hellwig mv $tmp.out $seq.out.bad 335*e8f8624dSMax Reitz $diff -w "$reference" $seq.out.bad 3366bf19c94SChristoph Hellwig err=true 3376bf19c94SChristoph Hellwig fi 3386bf19c94SChristoph Hellwig fi 3396bf19c94SChristoph Hellwig fi 3406bf19c94SChristoph Hellwig 3416bf19c94SChristoph Hellwig fi 3426bf19c94SChristoph Hellwig 3436bf19c94SChristoph Hellwig # come here for each test, except when $showme is true 3446bf19c94SChristoph Hellwig # 3456bf19c94SChristoph Hellwig if $err 3466bf19c94SChristoph Hellwig then 3476bf19c94SChristoph Hellwig bad="$bad $seq" 3486bf19c94SChristoph Hellwig n_bad=`expr $n_bad + 1` 3496bf19c94SChristoph Hellwig quick=false 3506bf19c94SChristoph Hellwig fi 3516bf19c94SChristoph Hellwig [ -f $seq.notrun ] || try=`expr $try + 1` 3526bf19c94SChristoph Hellwig 3536bf19c94SChristoph Hellwig seq="after_$seq" 3546bf19c94SChristoph Hellwigdone 3556bf19c94SChristoph Hellwig 3566bf19c94SChristoph Hellwiginterrupt=false 3576bf19c94SChristoph Hellwigstatus=`expr $n_bad` 3586bf19c94SChristoph Hellwigexit 359