summaryrefslogtreecommitdiff
path: root/common/report
blob: 5ca41bc40762b353660f5718f57f1d65450d4c46 (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
#
# Reports generator funcitons lives here
#

# List of xfstests's enviroment variables to include reports
## TODO automate list population inside common/conf
REPORT_ENV_LIST=("SECTION" "FSTYP" "PLATFORM" "MKFS_OPTIONS" "MOUNT_OPTIONS" \
		 "HOST_OPTIONS" "CHECK_OPTIONS" "XFS_MKFS_OPTIONS" \
		 "TIME_FACTOR" "LOAD_FACTOR" "TEST_DIR" "TEST_DEV" \
		 "SCRATCH_DEV" "SCRATCH_MNT" "OVL_UPPER" "OVL_LOWER" "OVL_WORK")

encode_xml()
{
	cat -v | \
	    sed -e 's/&/\&/g' \
		-e 's/>/\>/g' \
		-e 's/</\&lt;/g' \
		-e "s/'/\&apos;/g" \
		-e 's/"/\&quot;/g'
}

#
# Xunit format report functions
_xunit_add_property()
{
	local name="$1"
	local value="${!name}"

	if [ ! -z "$value" ]; then
		echo -e "\t\t<property name=\"$name\" value=\"$value\"/>" >> $REPORT_DIR/result.xml
	fi
}
_xunit_make_section_report()
{
	# xfstest:section ==> xunit:testsuite
	local sect_name="$1"
	local tests_count="$2"
	local bad_count="$3"
	local notrun_count="$4"
	local sect_time="$5"

	if [ $sect_name == '-no-sections-' ]; then
		sect_name='global'
	fi
	local report=$tmp.report.xunit.$sect_name.xml
	# Header
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $REPORT_DIR/result.xml
	if [ -z "$date_time" ]; then
		date_time=$(date +"%F %T")
	fi
	local stats="failures=\"$bad_count\" skipped=\"$notrun_count\" tests=\"$tests_count\" time=\"$sect_time\""
	local hw_info="hostname=\"$HOST\" timestamp=\"${date_time/ /T}\" "
	echo "<testsuite name=\"xfstests\" $stats  $hw_info >" >> $REPORT_DIR/result.xml

	# Properties
	echo -e "\t<properties>" >> $REPORT_DIR/result.xml
	for p in "${REPORT_ENV_LIST[@]}"; do
		_xunit_add_property "$p"
	done
	echo -e "\t</properties>" >> $REPORT_DIR/result.xml
	if [ -f $report ]; then
		cat $report >> $REPORT_DIR/result.xml
	fi
	echo "</testsuite>" >> $REPORT_DIR/result.xml
	echo "Xunit report: $REPORT_DIR/result.xml"
}

_xunit_make_testcase_report()
{
	local sect_name="$1"
	local test_name="$2"
	local test_status="$3"
	local test_time="$4"

	# TODO: other places may also win if no-section mode will be named like 'default/global'
	if [ $sect_name == '-no-sections-' ]; then
		sect_name='global'

	fi
	local report=$tmp.report.xunit.$sect_name.xml

	echo -e "\t<testcase classname=\"xfstests.$sect_name\" name=\"$test_name\" time=\"$test_time\">" >> $report
	case $test_status in
	"pass")
		;;
	"notrun")
		local notrun_file="${REPORT_DIR}/${test_name}.notrun"
		if [ -f "$notrun_file" ]; then
			local msg=`cat "$notrun_file" | encode_xml`
			echo -e "\t\t<skipped message=\"$msg\" />" >> $report
		else
			echo -e "\t\t<skipped/>" >> $report
		fi
		;;
	"list")
		echo -e "\t\t<skipped/>" >> $report
		;;
	"fail")
		local out_src="${SRC_DIR}/${test_name}.out"
		local full_file="${REPORT_DIR}/${test_name}.full"
		local dmesg_file="${REPORT_DIR}/${test_name}.dmesg"
		local outbad_file="${REPORT_DIR}/${test_name}.out.bad"
		if [ -z "$_err_msg" ]; then
			_err_msg="Test $test_name failed, reason unknown"
		fi
		echo -e "\t\t<failure message=\"$_err_msg\" type=\"TestFail\" />" >> $report
		if [ -s "$full_file" ]; then
			echo -e "\t\t<system-out>" >> $report
			printf	'<![CDATA[\n' >>$report
			cat "$full_file" | tr -dc '[:print:][:space:]' | encode_xml >>$report
			printf ']]>\n'	>>$report
			echo -e "\t\t</system-out>" >> $report
		fi
		if [ -f "$dmesg_file" ]; then
			echo -e "\t\t<system-err>" >> $report
			printf	'<![CDATA[\n' >>$report
			cat "$dmesg_file" | tr -dc '[:print:][:space:]' | encode_xml >>$report
			printf ']]>\n'	>>$report
			echo -e "\t\t</system-err>" >> $report
		elif [ -s "$outbad_file" ]; then
			echo -e "\t\t<system-err>" >> $report
			printf	'<![CDATA[\n' >>$report
			$diff "$out_src" "$outbad_file" | encode_xml >>$report
			printf ']]>\n'	>>$report
			echo -e "\t\t</system-err>" >> $report
		fi
		;;
	*)
		echo -e "\t\t<failure message=\"Unknown test_status=$test_status\" type=\"TestFail\"/>" >> $report
		;;
	esac
	echo -e "\t</testcase>" >> $report
}


#
#  Common report generator entry points
_make_section_report()
{
	local sect_name="$1"
	local tests_count="$2"
	local bad_count="$3"
	local notrun_count="$4"
	local sect_time="$5"
	for report in $REPORT_LIST; do
		case "$report" in
		"xunit")
			_xunit_make_section_report "$sect_name" "$tests_count" \
						   "$bad_count" "$notrun_count" \
						   "$sect_time"
			;;
		*)
			_dump_err "format '$report' is not supported"
			;;
		esac
	done
}

_make_testcase_report()
{
	local sect_name="$1"
	local test_seq="$2"
	local test_status="$3"
	local test_time="$4"
	for report in $REPORT_LIST; do
		case "$report" in
		"xunit")
			_xunit_make_testcase_report "$sect_name" "$test_seq" \
						    "$test_status" "$test_time"
			;;
		*)
			_dump_err "report format '$report' is not supported"
			;;
		esac
	done
}

_assert_report_list() {
	for report in $REPORT_LIST; do
		case "$report" in
		"xunit")
			;;
		*)
			_fatal "report format '$report' is not supported"
			;;
		esac
	done
}