blob: 6037174dbc1a55e00e657e8ee9208ed04f110a68 [file] [log] [blame]
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +02001#!/usr/bin/env bash
2expected_file="$1"
3results_file="$2"
4
Harald Welte0cdf0712019-06-19 18:15:38 +02005# Copyright 2018 sysmocom - s.f.m.c. GmbH
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +020019usage() {
20 echo "
21Usage:
22
23 $(basename "$0") expected_results.junit-log current_results.junit-log [--allow-* [...]]
24
25Return 0 if the expected results match the current results exactly.
26
27 --allow-skip Allow runnning less tests than are listed in the expected file.
28 Default is to return failure on any skipped tests.
29 --allow-new Allow more test results than found in the expected file.
30 Default is to return failure on any unknown tests.
31 --allow-xpass If a test was expected to fail but passed, return success.
32 Default is to return failure on any mismatch.
33"
34}
35
36if [ ! -f "$expected_file" ]; then
37 usage
38 echo "Expected file not found: '$expected_file'"
39 exit 1
40fi
41
42if [ ! -f "$results_file" ]; then
43 usage
44 echo "Current results file not found: '$results_file'"
45 exit 1
46fi
47
48shift
49shift
50
51allow_xpass=0
52allow_skip=0
53allow_new=0
54
55while test -n "$1"; do
56 arg="$1"
57 if [ "x$arg" = "x--allow-xpass" ]; then
58 allow_xpass=1
59 elif [ "x$arg" = "x--allow-skip" ]; then
60 allow_skip=1
61 elif [ "x$arg" = "x--allow-new" ]; then
62 allow_new=1
63 else
64 usage
65 echo "Unknown argument: '$arg'"
66 exit 1
67 fi
68 shift
69done
70
71echo "Comparing expected results $expected_file against results in $results_file
72--------------------"
73
74parse_testcase() {
75 line="$1"
76 suite_name="$(echo "$line" | sed 's,.*classname='"'"'\([^'"'"']*\)'"'"'.*,\1,')"
77 test_name="$(echo "$line" | sed 's,.*\<name='"'"'\([^'"'"']*\)'"'"'.*,\1,')"
78 if [ -n "$(echo "$line" | grep '/>$')" ]; then
79 test_result="pass"
80 else
81 test_result="FAIL"
82 fi
83}
84
85pass=0
86xfail=0
87more_failures=0
88more_successes=0
89skipped=0
90new=0
91
92while read line; do
93 parse_testcase "$line"
94 exp_suite_name="$suite_name"
95 exp_test_name="$test_name"
96 exp_test_result="$test_result"
97 matched="0"
98
99 while read line; do
100 parse_testcase "$line"
101 if [ "x$exp_suite_name" != "x$suite_name" ]; then
102 continue
103 fi
104 if [ "x$exp_test_name" != "x$test_name" ]; then
105 continue
106 fi
107
108 if [ "x$exp_test_result" = "x$test_result" ]; then
109 if [ "x$exp_test_result" = "xFAIL" ]; then
110 exp_test_result="xfail"
111 (( xfail += 1 ))
112 else
113 (( pass += 1 ))
114 fi
115 echo "$exp_test_result $suite_name.$test_name"
116 else
117 if [ "x$exp_test_result" = "xFAIL" ]; then
118 exp_test_result="xfail"
119 fi
120 echo "$exp_test_result->$test_result $suite_name.$test_name"
121 if [ "x$test_result" = "xFAIL" ]; then
122 (( more_failures += 1 ))
123 else
124 (( more_successes += 1 ))
125 fi
126 fi
127 matched="1"
128 break
Neels Hofmeyra9acec42018-09-06 14:33:37 +0200129 done <<< "$(grep "<testcase.*$exp_test_name" "$results_file")"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200130
131 if [ "x$matched" = "x0" ]; then
132 echo "skipped $exp_suite_name.$exp_test_name"
133 (( skipped += 1 ))
134 fi
135
136done <<< "$(grep "<testcase" "$expected_file")"
137
138# Also catch all new tests that aren't covered in the expected results
139while read line; do
140 parse_testcase "$line"
141 got_suite_name="$suite_name"
142 got_test_name="$test_name"
143 got_test_result="$test_result"
144 matched="0"
145
146 while read line; do
147 parse_testcase "$line"
148 if [ "x$got_suite_name" != "x$suite_name" ]; then
149 continue
150 fi
151 if [ "x$got_test_name" != "x$test_name" ]; then
152 continue
153 fi
154
155 matched="1"
156 break
Neels Hofmeyra9acec42018-09-06 14:33:37 +0200157 done <<< "$(grep "<testcase.*$test_name" "$expected_file")"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200158
159 if [ "x$matched" = "x0" ]; then
160 echo "NEW-$got_test_result $got_suite_name.$got_test_name"
161 (( new += 1 ))
162 fi
163
164done <<< "$(grep "<testcase" "$results_file")"
165
166echo "--------------------"
167overall_verdict=0
168
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200169ask_update=""
170
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200171if [ "x$pass" != x0 ]; then
172 echo "$pass pass"
173fi
174
175if [ "x$xfail" != x0 ]; then
176 echo "$xfail xfail"
177fi
178
179if [ "x$skipped" != x0 ]; then
180 echo "$skipped skipped"
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200181 ask_update="$ask_update removed=$skipped"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200182 if [ "x$allow_skip" = x0 ]; then
183 overall_verdict=4
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200184 fi
185fi
186
187if [ "x$new" != x0 ]; then
188 echo "$new new"
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200189 ask_update="$ask_update new=$new"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200190 if [ "x$allow_new" = x0 ]; then
191 overall_verdict=3
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200192 fi
193fi
194
195if [ "x$more_successes" != x0 ]; then
196 echo "$more_successes pass unexpectedly"
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200197 ask_update="$ask_update xpass=$more_successes"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200198 if [ "x$allow_xpass" = x0 ]; then
199 overall_verdict=2
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200200 fi
201fi
202
203if [ "x$more_failures" != x0 ]; then
204 echo "$more_failures FAIL"
205 overall_verdict=1
206fi
207
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200208if [ -n "$ask_update" ]; then
209 echo
210 echo "(Please update the expected results:$ask_update)"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200211fi
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200212
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200213exit $overall_verdict