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