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