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