Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | expected_file="$1" |
| 3 | results_file="$2" |
| 4 | |
Harald Welte | 0cdf071 | 2019-06-19 18:15:38 +0200 | [diff] [blame] | 5 | # 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 Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 19 | usage() { |
| 20 | echo " |
| 21 | Usage: |
| 22 | |
| 23 | $(basename "$0") expected_results.junit-log current_results.junit-log [--allow-* [...]] |
| 24 | |
| 25 | Return 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 | |
| 36 | if [ ! -f "$expected_file" ]; then |
| 37 | usage |
| 38 | echo "Expected file not found: '$expected_file'" |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | if [ ! -f "$results_file" ]; then |
| 43 | usage |
| 44 | echo "Current results file not found: '$results_file'" |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | shift |
| 49 | shift |
| 50 | |
| 51 | allow_xpass=0 |
| 52 | allow_skip=0 |
| 53 | allow_new=0 |
| 54 | |
| 55 | while 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 |
| 69 | done |
| 70 | |
| 71 | echo "Comparing expected results $expected_file against results in $results_file |
| 72 | --------------------" |
| 73 | |
| 74 | parse_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 | |
| 85 | pass=0 |
| 86 | xfail=0 |
| 87 | more_failures=0 |
| 88 | more_successes=0 |
| 89 | skipped=0 |
| 90 | new=0 |
| 91 | |
| 92 | while 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 Hofmeyr | a9acec4 | 2018-09-06 14:33:37 +0200 | [diff] [blame] | 129 | done <<< "$(grep "<testcase.*$exp_test_name" "$results_file")" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 130 | |
| 131 | if [ "x$matched" = "x0" ]; then |
| 132 | echo "skipped $exp_suite_name.$exp_test_name" |
| 133 | (( skipped += 1 )) |
| 134 | fi |
| 135 | |
| 136 | done <<< "$(grep "<testcase" "$expected_file")" |
| 137 | |
| 138 | # Also catch all new tests that aren't covered in the expected results |
| 139 | while 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 Hofmeyr | a9acec4 | 2018-09-06 14:33:37 +0200 | [diff] [blame] | 157 | done <<< "$(grep "<testcase.*$test_name" "$expected_file")" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 158 | |
| 159 | if [ "x$matched" = "x0" ]; then |
| 160 | echo "NEW-$got_test_result $got_suite_name.$got_test_name" |
| 161 | (( new += 1 )) |
| 162 | fi |
| 163 | |
| 164 | done <<< "$(grep "<testcase" "$results_file")" |
| 165 | |
| 166 | echo "--------------------" |
| 167 | overall_verdict=0 |
| 168 | |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 169 | ask_update="" |
| 170 | |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 171 | if [ "x$pass" != x0 ]; then |
| 172 | echo "$pass pass" |
| 173 | fi |
| 174 | |
| 175 | if [ "x$xfail" != x0 ]; then |
| 176 | echo "$xfail xfail" |
| 177 | fi |
| 178 | |
| 179 | if [ "x$skipped" != x0 ]; then |
| 180 | echo "$skipped skipped" |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 181 | ask_update="$ask_update removed=$skipped" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 182 | if [ "x$allow_skip" = x0 ]; then |
| 183 | overall_verdict=4 |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 184 | fi |
| 185 | fi |
| 186 | |
| 187 | if [ "x$new" != x0 ]; then |
| 188 | echo "$new new" |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 189 | ask_update="$ask_update new=$new" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 190 | if [ "x$allow_new" = x0 ]; then |
| 191 | overall_verdict=3 |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 192 | fi |
| 193 | fi |
| 194 | |
| 195 | if [ "x$more_successes" != x0 ]; then |
| 196 | echo "$more_successes pass unexpectedly" |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 197 | ask_update="$ask_update xpass=$more_successes" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 198 | if [ "x$allow_xpass" = x0 ]; then |
| 199 | overall_verdict=2 |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 200 | fi |
| 201 | fi |
| 202 | |
| 203 | if [ "x$more_failures" != x0 ]; then |
| 204 | echo "$more_failures FAIL" |
| 205 | overall_verdict=1 |
| 206 | fi |
| 207 | |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 208 | if [ -n "$ask_update" ]; then |
| 209 | echo |
| 210 | echo "(Please update the expected results:$ask_update)" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 211 | fi |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 212 | |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 213 | exit $overall_verdict |