aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xm-test/runtest.sh
blob: c259fca4510f0c3bacda7ca38450bcfb2656c4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/sh

usage() {
    echo "Usage: $0 [opts] <logfile>"
    echo "  Where opts are:"
    echo "  -d         : do not submit a report for this run"
    echo "  -b         : do not ask any questions (batch mode)"
    echo "  -e <email> : set email address for report"
}
##
## Test driver script
##

#
# Defaults
#
MAXFAIL=10
report=yes
batch=no

#
# Resolve options
#
while [ $# -gt 0 ]
do
    case "$1" in
    -d)
        echo "(Skipping report submission)"
        report=no
        ;;
    -b)
        echo "(Batch mode)"
        batch=yes
        ;;
    -e)
        shift
        echo $1 > contact_info
        echo "(Email set to $1)"
        ;;
    *)
        LOGFILE=$1
        break
        ;;
    esac
    shift
done

#
# Usage
#
if [ -z $LOGFILE ]; then
	usage
	exit 1
fi

#
# Output files
#
OSREPORTTEMP=${LOGFILE}.os.xml
PROGREPORTTEMP=${LOGFILE}.prog.xml
RESULTREPORTTEMP=${LOGFILE}.result.xml
OUTPUT=${LOGFILE}.output
SUMMARY=${LOGFILE}.summary
PASSFAIL=${LOGFILE}.passfail
REPORT=${LOGFILE}.report
FAILURES=${LOGFILE}.failures
		
#
# Make sure we're root
#
uid=$(id -u)
if [ $uid != 0 ]; then 
    echo "ERROR: I must be run as root!"
    exit 1
fi

#
# See if the ramdisk has been built
#
rdsize=$(stat -c %s ramdisk/initrd.img 2>/dev/null)
if [ -z "$rdsize" ] || [ $rdsize -le 16384 ]; then
    echo "Cannot find a valid ramdisk.  You need to run \"make\" or"
    echo "copy in a previously-built ramdisk to the ramdisk/ directory"
    exit 1
fi

#
# See if xend is running
#
if ! xm list >/dev/null 2>&1; then
    echo "'xm list' failed: is xend running?"
    exit 1
fi

#
#  Make sure permissions are correct
#
chmod a+x lib/XmTestReport/*
chmod a+x mkreport mergereport

#
# Get contact info if needed
#
if [ ! -f contact_info ]; then
    if [ "$batch" = "yes" ]; then
	echo "Unable to read contact_info!"
	echo "Please run me once interactively before using batch mode!"
	exit 1
    else
	echo "Please provide your email address so that we can "
	echo "contact you if we need further information concerning"
	echo "your results.  Any information provided will be"
	echo "kept private.  If you wish to remain anonymous, please"
	echo "hit [ENTER] now."
	
	while ! echo "$EMAIL" | grep -q '@'; do
	    echo
	    echo -n "Your email address: "
	    read EMAIL
	    if [ -z $EMAIL ]; then
		EMAIL="anonymous@somewhere.com"
	    fi
	done
	echo $EMAIL > contact_info
    fi
fi

#
# Collect environment information for XML report
#
if ! ./lib/XmTestReport/OSReport.py > $OSREPORTTEMP; then
    echo "Unable to generate clean OSReport"
    echo "Take a look at $OSREPORTTEMP"
    exit 1
fi
if ! ./lib/XmTestReport/ProgReport.py > $PROGREPORTTEMP; then
    echo "Unable to generate clean ProgReport"
    echo "Take a look at $PROGREPORTTEMP"
    exit 1
fi

#
# Run the tests
#
export TEST_VERBOSE=1
echo Running tests...
make -k check > $OUTPUT 2>&1

#
# Generate some plain-text reports
#
echo "Making PASS/FAIL report ($PASSFAIL)..."
cat $OUTPUT | egrep '(REASON|PASS|FAIL|XPASS|XFAIL|SKIP)' | perl -pe 's/^(PASS|FAIL|XPASS|XFAIL)(.+)$/$1$2\n/' > $PASSFAIL

echo "Making FAIL report ($FAILURES)..."
cat $PASSFAIL | egrep '(REASON|FAIL)' > $FAILURES

NUMPASS=`grep -c PASS $OUTPUT`
NUMFAIL=`grep -c FAIL $OUTPUT`
NUMXPASS=`grep -c XPASS $OUTPUT`
NUMXFAIL=`grep -c XFAIL $OUTPUT`
cat > $SUMMARY << EOF
Xm-test execution summary:
  PASS:  $NUMPASS
  FAIL:  $NUMFAIL
  XPASS: $NUMXPASS
  XFAIL: $NUMXFAIL
EOF

cat $SUMMARY > $REPORT

echo -e '\n\nDetails:\n' >> $REPORT
 
./mkreport $PASSFAIL >> $REPORT

#
# Check to see if it's worth reporting these results
#
#if  [ "$batch"  =   "no" ] && 
#    [ "$report" =   "yes" ] && 
#    [ $NUMFAIL  -gt $MAXFAIL ]; then
#    echo "NOTE: $NUMFAIL tests failed, which may be erroneous.  It may"
#    echo "be a good idea to review the report before sending.  If you"
#    echo "choose not to submit the report, it will be saved for your review"
#    echo "and later submission."
#    echo
#    echo -n "Submit anyway? [y/n] "
#    read ANSWER
#    if [ "$ANSWER" = "n" ]; then
#	report=no
#    fi
#fi

#
# Generate the XML result report
#
if ! ./lib/XmTestReport/ResultReport.py $OUTPUT > $RESULTREPORTTEMP; then
    echo "Unable to generate clean ResultReport"
    echo "Take a look at $RESULTREPORTTEMP"
    exit 1
fi

#
# Maybe submit report and save the combined XML file
#
if [ "$report" = "yes" ]; then
    echo "Sending report..."
    ./lib/XmTestReport/Report.py -D $OSREPORTTEMP $PROGREPORTTEMP \
                                    $RESULTREPORTTEMP > $1.xml
    echo "Report also saved in $1.xml"
else
    echo "Saving report to $1.xml..."
    ./lib/XmTestReport/Report.py -d $OSREPORTTEMP $PROGREPORTTEMP \
                                    $RESULTREPORTTEMP > $1.xml
fi