report: fix summary statistics in xUnit header
[xfstests-dev.git] / common / report
1 #
2 # Reports generator funcitons lives here
3 #
4
5 # List of xfstests's enviroment variables to include reports
6 ## TODO automate list population inside common/conf
7 REPORT_ENV_LIST="$REPORT_ENV_LIST SECTION"
8 REPORT_ENV_LIST="$REPORT_ENV_LIST FSTYP"
9 REPORT_ENV_LIST="$REPORT_ENV_LIST PLATFORM"
10 REPORT_ENV_LIST="$REPORT_ENV_LIST MKFS_OPTIONS"
11 REPORT_ENV_LIST="$REPORT_ENV_LIST MOUNT_OPTIONS"
12
13 REPORT_ENV_LIST="$REPORT_ENV_LIST HOST_OPTIONS"
14 REPORT_ENV_LIST="$REPORT_ENV_LIST CHECK_OPTIONS"
15 REPORT_ENV_LIST="$REPORT_ENV_LIST XFS_MKFS_OPTIONS"
16 REPORT_ENV_LIST="$REPORT_ENV_LIST TIME_FACTOR"
17 REPORT_ENV_LIST="$REPORT_ENV_LIST LOAD_FACTOR"
18
19 REPORT_ENV_LIST="$REPORT_ENV_LIST TEST_DIR"
20 REPORT_ENV_LIST="$REPORT_ENV_LIST TEST_DEV"
21 REPORT_ENV_LIST="$REPORT_ENV_LIST SCRATCH_DEV"
22 REPORT_ENV_LIST="$REPORT_ENV_LIST SCRATCH_MNT"
23
24 REPORT_ENV_LIST="$REPORT_ENV_LIST OVL_UPPER"
25 REPORT_ENV_LIST="$REPORT_ENV_LIST OVL_LOWER"
26 REPORT_ENV_LIST="$REPORT_ENV_LIST OVL_WORK"
27
28 encode_xml()
29 {
30     sed -e 's/&/\&/g' \
31         -e 's/>/\>/g' \
32         -e 's/</\&lt;/g' \
33         -e "s/'/\&apos;/g" \
34         -e 's/"/\&quot;/g'
35 }
36
37 #
38 # Xunit format report functions
39 _xunit_add_property()
40 {
41         local name="$1"
42         local value="${!name}"
43
44         if [ ! -z "$value" ]; then
45                 echo -e "\t\t<property name=\"$name\" value=\"$value\"/>" >> $REPORT_DIR/result.xml
46         fi
47 }
48 _xunit_make_section_report()
49 {
50         # xfstest:section ==> xunit:testsuite
51         local sect_name=$section
52         local sect_time=`expr $sect_stop - $sect_start`
53         local n_total=`expr $n_try + $n_notrun`
54
55         if [ $sect_name == '-no-sections-' ]; then
56                 sect_name='global'
57         fi
58         local report=$tmp.report.xunit.$sect_name.xml
59         # Header
60         echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $REPORT_DIR/result.xml
61         local dtime=`echo $date_time| tr  " " 'T'`
62         local stats="failures=\"$n_bad\" skipped=\"$n_notrun\" tests=\"$n_total\" time=\"$sect_time\""
63         local hw_info="hostname=\"$HOST\" timestamp=\"$dtime\" "
64         echo "<testsuite name=\"xfstests\" $stats  $hw_info >" >> $REPORT_DIR/result.xml
65
66         # Properties
67         echo -e "\t<properties>" >> $REPORT_DIR/result.xml
68         for p in $REPORT_ENV_LIST;do
69                 _xunit_add_property "$p"
70         done
71         echo -e "\t</properties>" >> $REPORT_DIR/result.xml
72         cat $tmp.report.xunit.$sect_name.xml >> $REPORT_DIR/result.xml
73         echo "</testsuite>" >> $REPORT_DIR/result.xml
74         echo "Xunit report: $REPORT_DIR/result.xml"
75 }
76
77 _xunit_make_testcase_report()
78 {
79         local test_status="$1"
80         local test_time=`expr $stop - $start`
81         local strip="$SRC_DIR/"
82         local test_name=${seq#$strip}
83         local sect_name=$section
84
85         # TODO: other places may also win if no-section mode will be named like 'default/global'
86         if [ $sect_name == '-no-sections-' ]; then
87                 sect_name='global'
88
89         fi
90         local report=$tmp.report.xunit.$sect_name.xml
91
92         echo -e "\t<testcase classname=\"xfstests.$sect_name\" name=\"$test_name\" time=\"$test_time\">" >> $report
93         case $test_status in
94         "pass")
95                 ;;
96         "notrun")
97                 if [ -f $seqres.notrun ]; then
98                         local msg=`cat $seqres.notrun | encode_xml`
99                         echo -e "\t\t<skipped message=\"$msg\" />" >> $report
100                 else
101                         echo -e "\t\t<skipped/>" >> $report
102                 fi
103                 ;;
104         "list")
105                 echo -e "\t\t<skipped/>" >> $report
106                 ;;
107         "fail")
108                 if [ -z "$err_msg" ]; then
109                         err_msg="Test $sequm failed, reason unknown"
110                 fi
111                 echo -e "\t\t<failure message=\"$err_msg\" type=\"TestFail\" />" >> $report
112                 if [ -s $seqres.full ]; then
113                         echo -e "\t\t<system-out>" >> $report
114                         printf  '<![CDATA[\n' >>$report
115                         cat $seqres.full | tr -dc '[:print:][:space:]' | encode_xml >>$report
116                         printf ']]>\n'  >>$report
117                         echo -e "\t\t</system-out>" >> $report
118                 fi
119                 if [ -f $seqres.dmesg ]; then
120                         echo -e "\t\t<system-err>" >> $report
121                         printf  '<![CDATA[\n' >>$report
122                         cat $seqres.dmesg | tr -dc '[:print:][:space:]' | encode_xml >>$report
123                         printf ']]>\n'  >>$report
124                         echo -e "\t\t</system-err>" >> $report
125                 elif [ -s $seqres.out.bad ]; then
126                         echo -e "\t\t<system-err>" >> $report
127                         printf  '<![CDATA[\n' >>$report
128                         $diff $seq.out $seqres.out.bad | encode_xml >>$report
129                         printf ']]>\n'  >>$report
130                         echo -e "\t\t</system-err>" >> $report
131                 fi
132                 ;;
133         *)
134                 echo -e "\t\t<failure message=\"Unknown ret_state=$ret_state\" type=\"TestFail\"/>" >> $report
135                 ;;
136         esac
137         echo -e "\t</testcase>" >> $report
138 }
139
140
141 #
142 #  Common report generator entry points
143 _make_section_report()
144 {
145         for report in $REPORT_LIST; do
146                 case "$report" in
147                 "xunit")
148                         _xunit_make_section_report "$test_status"
149                         ;;
150                 *)
151                         _dump_err "format '$report' is not supported"
152                         ;;
153                 esac
154         done
155 }
156
157 _make_testcase_report()
158 {
159         test_status="$1"
160         for report in $REPORT_LIST; do
161                 case "$report" in
162                 "xunit")
163                         _xunit_make_testcase_report "$test_status"
164                         ;;
165                 *)
166                         _dump_err "report format '$report' is not supported"
167                         ;;
168                 esac
169         done
170 }
171
172 _assert_report_list() {
173         for report in $REPORT_LIST; do
174                 case "$report" in
175                 "xunit")
176                         ;;
177                 *)
178                         _fatal "report format '$report' is not supported"
179                         ;;
180                 esac
181         done
182 }