source: trunk/packages/xen-common/xen-common/tools/xm-test/runtest.sh @ 95

Last change on this file since 95 was 34, checked in by hartmans, 17 years ago

Add xen and xen-common

  • Property svn:executable set to *
File size: 8.3 KB
Line 
1#!/bin/sh
2
3##
4## Test driver script
5##
6
7usage() {
8    echo "Usage: $0 [opts] <report>"
9    echo "  Where report is a name that will be used for report files"
10    echo ""
11    echo "  Where opts are:"
12    echo "  -d          : do not submit a report for this run"
13    echo "  -b          : do not ask any questions (batch mode)"
14    echo "  -g          : run a group test set"
15    echo "  -e <email>  : set email address for report"
16    echo "  -r <url>    : url of test results repository to use"
17    echo "  -s <report> : just submit report <report>"
18    echo "  -u          : unsafe -- do not run the sanity checks before starting"
19    echo "  -md         : all created domains are xend-'managed' domains"
20    echo "  -h | --help : show this help"
21}
22
23# Just submit the report
24submit_report() {
25
26    reportfile=$1
27
28    ./lib/XmTestReport/Report.py $reportserver $reportfile
29}
30
31# Generate XML result report from output file
32make_result_report() {
33    output=$1
34    reportfile=$2
35    if ! ./lib/XmTestReport/ResultReport.py $output > $reportfile; then
36        echo "Unable to generate clean ResultReport"
37        echo "Take a look at $report"
38        exit 1
39    fi
40}
41
42# Collect environment information for XML report
43make_environment_report() {
44    os=$1
45    prog=$2
46    if ! ./lib/XmTestReport/OSReport.py > $os; then
47        echo "Unable to generate clean OSReport"
48        echo "Take a look at $os"
49        exit 1
50    fi
51    if ! ./lib/XmTestReport/ProgReport.py > $prog; then
52        echo "Unable to generate clean ProgReport"
53        echo "Take a look at $prog"
54        exit 1
55    fi
56}
57
58# Check conditions needed to actually run the tests
59runnable_tests() {     
60    # Make sure we're root
61    uid=$(id -u)
62    if [ $uid != 0 ]; then
63        echo "ERROR: I must be run as root!"
64        exit 1
65    fi
66
67    # See if the ramdisk has been built
68    rdsize=$(stat -Lc %s ramdisk/initrd.img 2>/dev/null)
69    if [ -z "$rdsize" ] || [ $rdsize -le 16384 ]; then
70        echo "Cannot find a valid ramdisk.  You need to run \"make\" or"
71        echo "copy in a previously-built ramdisk to the ramdisk/ directory"
72        exit 1
73    fi
74
75    # Figure out the version of the ramdisk link and compare it
76    # to what it should be as a cheap way of making sure we're
77    # using the right version
78    realrd=$(readlink ramdisk/initrd.img)
79    eval $(./lib/XmTestReport/xmtest.py)
80    ARCH=$(uname -m | sed -e s/i.86/i386/ -e 's/ppc\(64\)*/powerpc/')
81    rrdver="initrd-${XM_TEST_MAJ}.${XM_TEST_MIN}-${ARCH}.img"
82    exp_flag=0
83    realarch=`echo $realrd | awk -F- '{print $3}' | awk -F. '{print $1}'`
84    rrdarch=`echo $rrdver | awk -F- '{print $3}' | awk -F. '{print $1}'`
85    if [ "$realarch" = "i386" -a "$rrdarch" = "x86_64" ]; then
86        exp_flag=1
87    fi
88    if [ $exp_flag -eq 0 -a "$realrd" != "$rrdver" ]; then
89        echo "Error: ramdisk/initrd.img is from an old version, or is not for this "
90        echo "architecture ($ARCH)."
91        echo "You need to build a ramdisk from at least ${XM_TEST_MAJ}.${XM_TEST_MIN}"
92        exit 1
93    fi
94
95    # See if xend is running
96    if ! xm list >/dev/null 2>&1; then
97        echo "'xm list' failed: is xend running?"
98        exit 1
99    fi
100
101    # Run a few sample tests to make sure things are working
102    # before we take the plunge
103    echo "Running sanity checks..."
104    make -C tests/_sanity check 2>&1 | grep REASON
105    if [ $? -eq 0 ]; then
106        echo "Sanity checks failed"
107        exit 1
108    fi
109
110}
111
112
113# Get contact info if needed
114get_contact_info() {
115   
116    if [ ! -f contact_info ]; then
117        if [ "$batch" = "yes" ]; then
118            echo "Unable to read contact_info!"
119            echo "Please run me once interactively before using batch mode!"
120            exit 1
121        else
122            echo "Please provide your email address so that we can "
123            echo "contact you if we need further information concerning"
124            echo "your results.  Any information provided will be"
125            echo "kept private.  If you wish to remain anonymous, please"
126            echo "hit [ENTER] now."
127           
128            while ! echo "$EMAIL" | grep -q '@'; do
129                echo
130                echo -n "Your email address: "
131                read EMAIL
132                if [ -z $EMAIL ]; then
133                    EMAIL="anonymous@somewhere.com"
134                fi
135            done
136            echo $EMAIL > contact_info
137        fi
138    fi
139}
140
141# Run the tests
142run_tests() {
143    groupentered=$1
144    output=$2
145    report=$3
146    startfile=${report}.start
147    stopfile=${report}.stop
148
149    date -R > $startfile
150    exec <  grouptest/$groupentered
151    while read casename testlist; do
152       echo Running $casename tests...
153       echo "*** case $casename from group $groupentered" >> $output
154       if [ -z "$testlist" ]; then
155          echo "*** Running tests for case $casename" >> $output
156          (cd tests/$casename && TEST_VERBOSE=1 make -k check) >> $output 2>&1
157       else
158          echo "*** Running tests $testlist from case $casename" >> $output
159          (cd tests/$casename && TEST_VERBOSE=1 make -k check TESTS="$testlist") >> $output 2>&1
160       fi
161
162    done
163    date -R > $stopfile
164
165}
166
167# Generate some plain-text reports
168make_text_reports() {
169    passfail=$1
170    failures=$2
171    output=$3
172    reportfile=$4
173    report=$5
174    summary=summary.tmp
175    startfile=${report}.start
176    stopfile=${report}.stop
177    echo "Making PASS/FAIL report ($passfail)..."
178    cat $OUTPUT | egrep '(REASON|PASS|FAIL|XPASS|XFAIL|SKIP)' | perl -pe 's/^(PASS|FAIL|XPASS|XFAIL)(.+)$/$1$2\n/' > $passfail
179   
180    echo "Making FAIL report ($failures)..."
181    cat $passfail | egrep '(REASON|FAIL)' > $failures
182   
183    NUMPASS=`grep -c PASS $output`
184    NUMFAIL=`grep -c FAIL $output`
185    NUMXPASS=`grep -c XPASS $output`
186    NUMXFAIL=`grep -c XFAIL $output`
187    START=`cat $startfile`
188    STOP=`cat $stopfile`
189    cat > $summary << EOF
190Xm-test timing summary:
191  Run Started : $START
192  Run Stoped  : $STOP
193Xm-test execution summary:
194  PASS:  $NUMPASS
195  FAIL:  $NUMFAIL
196  XPASS: $NUMXPASS
197  XFAIL: $NUMXFAIL
198EOF
199   
200    cat $summary > $reportfile
201   
202    echo -e '\n\nDetails:\n' >> $reportfile
203   
204    ./mkreport $passfail >> $reportfile
205
206    rm $summary
207}
208
209############
210### Main ###
211############
212
213# Defaults
214MAXFAIL=10
215report=yes
216reportserver=${xmtest_repo:-'http://xmtest.dague.org/cgi-bin/report-results'}
217batch=no
218run=yes
219unsafe=no
220GROUPENTERED=default
221
222#Prepare for usage with ACM
223if [ -d /etc/xen/acm-security/policies ]; then
224        cp -f tests/security-acm/xm-test-security_policy.xml \
225              /etc/xen/acm-security/policies
226fi
227
228unset XM_MANAGED_DOMAINS
229
230# Resolve options
231while [ $# -gt 0 ]
232  do
233  case "$1" in
234      -d)
235          echo "(Skipping report submission)"
236          report=no
237          ;;
238      -b)
239          echo "(Batch mode)"
240          batch=yes
241          ;;
242      -e)
243          shift
244          echo $1 > contact_info
245          echo "(Email set to $1)"
246          ;;
247      -g)
248          shift
249          GROUPENTERED=$1
250          if [ ! -f grouptest/$GROUPENTERED ]; then
251             echo "No file for group $GROUPENTERED"
252             exit 1
253          fi
254          ;;
255      -r)
256          shift
257          reportserver=$1
258          ;;
259      -s)
260          run=no
261          ;;
262      -u)
263          echo "(Unsafe mode)"
264          unsafe=yes
265          report=no
266          ;;
267      -md)
268          echo "(use managed domains)"
269          export XM_MANAGED_DOMAINS=1
270          ;;
271      -h|--help)
272          usage
273          exit 0
274          ;;
275      *)
276          REPORT=$1
277          break
278          ;;
279  esac
280  shift
281done
282
283# Usage
284if [ -z $REPORT ]; then
285        usage
286        exit 1
287fi
288
289# Output files
290OSREPORTTEMP=${REPORT}.os.xml
291PROGREPORTTEMP=${REPORT}.prog.xml
292RESULTREPORTTEMP=${REPORT}.result.xml
293XMLREPORT=${REPORT}.xml
294OUTPUT=${REPORT}.output
295SUMMARY=${REPORT}.summary
296PASSFAIL=${REPORT}.passfail
297TXTREPORT=${REPORT}.report
298FAILURES=${REPORT}.failures
299       
300#  Make sure permissions are correct
301chmod a+x lib/XmTestReport/*
302chmod a+x mkreport mergereport
303
304if [ ! -f contact_info ]; then
305    if [ "$batch" = "yes" ]; then
306        echo "Unable to read contact_info"
307        echo "You must run me interactively once!"
308        exit 1
309    else
310        get_contact_info
311    fi
312fi
313
314if [ "$GROUPENTERED" != "default" ]; then
315   report=no;
316fi
317
318if [ "$run" != "no" ]; then
319    if [ "$unsafe" = "no" ]; then
320      runnable_tests
321    fi
322    rm -f $REPORT"*"
323    if [ "$unsafe" = "no" ]; then
324      make_environment_report $OSREPORTTEMP $PROGREPORTTEMP
325    fi
326    run_tests $GROUPENTERED $OUTPUT $REPORT
327    make_text_reports $PASSFAIL $FAILURES $OUTPUT $TXTREPORT $REPORT
328    if [ "$unsafe" = "no" ]; then
329      make_result_report $OUTPUT $RESULTREPORTTEMP
330      cat $OSREPORTTEMP $PROGREPORTTEMP $RESULTREPORTTEMP > $XMLREPORT
331      rm $OSREPORTTEMP $PROGREPORTTEMP $RESULTREPORTTEMP
332    fi
333fi
334
335if [ "$report" = "yes" ]; then
336    if [ ! -f "$XMLREPORT" ]; then
337        echo "No such file: $XMLREPORT"
338        exit 1
339    fi
340    submit_report $XMLREPORT
341fi
Note: See TracBrowser for help on using the repository browser.