| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
type=float |
| 4 |
abi=0 |
| 5 |
name= |
| 6 |
srcdir="$(cd "${0%/*}" && pwd)/tests" |
| 7 |
sim="$GCC_TEST_SIMULATOR" |
| 8 |
|
| 9 |
# output_mode values: |
| 10 |
# print only failures with minimal context |
| 11 |
readonly really_quiet=0 |
| 12 |
# as above plus same-line output of last successful test |
| 13 |
readonly same_line=1 |
| 14 |
# as above plus percentage |
| 15 |
readonly percentage=2 |
| 16 |
# print one line per finished test with minimal context on failure |
| 17 |
readonly verbose=3 |
| 18 |
# print one line per finished test with full output of the compiler and test |
| 19 |
readonly really_verbose=4 |
| 20 |
|
| 21 |
output_mode=$really_quiet |
| 22 |
[ -t 1 ] && output_mode=$same_line |
| 23 |
|
| 24 |
timeout=180 |
| 25 |
run_expensive=false |
| 26 |
if [ -n "$GCC_TEST_RUN_EXPENSIVE" ]; then |
| 27 |
run_expensive=true |
| 28 |
fi |
| 29 |
keep_failed=false |
| 30 |
only= |
| 31 |
|
| 32 |
usage() { |
| 33 |
cat <<EOF |
| 34 |
Usage: $0 [Options] <g++ invocation> |
| 35 |
|
| 36 |
Options: |
| 37 |
-h, --help Print this message and exit. |
| 38 |
-q, --quiet Disable same-line progress output (default if stdout is |
| 39 |
not a tty). |
| 40 |
-p, --percentage Add percentage to default same-line progress output. |
| 41 |
-v, --verbose Print one line per test and minimal extra information on |
| 42 |
failure. |
| 43 |
-vv Print all compiler and test output. |
| 44 |
-t <type>, --type <type> |
| 45 |
The value_type to test (default: $type). |
| 46 |
-a [0-9], --abi [0-9] |
| 47 |
The ABI tag subset to test (default: $abi). |
| 48 |
-n <name>, --name <name> |
| 49 |
The name of the test (required). |
| 50 |
-k, --keep-failed Keep executables of failed tests. |
| 51 |
--srcdir <path> The source directory of the tests (default: $srcdir). |
| 52 |
--sim <executable> Path to an executable that is prepended to the test |
| 53 |
execution binary (default: the value of |
| 54 |
GCC_TEST_SIMULATOR). |
| 55 |
--timeout-factor <x> |
| 56 |
Multiply the default timeout with x. |
| 57 |
-x, --run-expensive Compile and run tests marked as expensive (default: |
| 58 |
true if GCC_TEST_RUN_EXPENSIVE is set, false otherwise). |
| 59 |
-o <pattern>, --only <pattern> |
| 60 |
Compile and run only tests matching the given pattern. |
| 61 |
EOF |
| 62 |
} |
| 63 |
|
| 64 |
while [ $# -gt 0 ]; do |
| 65 |
case "$1" in |
| 66 |
-h|--help) |
| 67 |
usage |
| 68 |
exit |
| 69 |
;; |
| 70 |
-q|--quiet) |
| 71 |
output_mode=$really_quiet |
| 72 |
;; |
| 73 |
-p|--percentage) |
| 74 |
output_mode=$percentage |
| 75 |
;; |
| 76 |
-v|--verbose) |
| 77 |
if [ $output_mode -lt $verbose ]; then |
| 78 |
output_mode=$verbose |
| 79 |
else |
| 80 |
output_mode=$really_verbose |
| 81 |
fi |
| 82 |
;; |
| 83 |
-x|--run-expensive) |
| 84 |
run_expensive=true |
| 85 |
;; |
| 86 |
-k|--keep-failed) |
| 87 |
keep_failed=true |
| 88 |
;; |
| 89 |
-o|--only) |
| 90 |
only="$2" |
| 91 |
shift |
| 92 |
;; |
| 93 |
-t|--type) |
| 94 |
type="$2" |
| 95 |
shift |
| 96 |
;; |
| 97 |
-a|--abi) |
| 98 |
abi="$2" |
| 99 |
shift |
| 100 |
;; |
| 101 |
-n|--name) |
| 102 |
name="$2" |
| 103 |
shift |
| 104 |
;; |
| 105 |
--srcdir) |
| 106 |
srcdir="$2" |
| 107 |
shift |
| 108 |
;; |
| 109 |
--sim) |
| 110 |
sim="$2" |
| 111 |
shift |
| 112 |
;; |
| 113 |
--timeout-factor) |
| 114 |
timeout=$(awk "BEGIN { print int($timeout * $2) }") |
| 115 |
shift |
| 116 |
;; |
| 117 |
--) |
| 118 |
shift |
| 119 |
break |
| 120 |
;; |
| 121 |
--*=*) |
| 122 |
opt="$1" |
| 123 |
shift |
| 124 |
value=${opt#*=} |
| 125 |
set -- ${opt%=$value} "$value" ${1+"$@"} |
| 126 |
continue |
| 127 |
;; |
| 128 |
-[ahknopqtvx][ahknopqtvx]*) |
| 129 |
opt="$1" |
| 130 |
shift |
| 131 |
next=${opt#??} |
| 132 |
set -- ${opt%$next} "-$next" ${1+"$@"} |
| 133 |
continue |
| 134 |
;; |
| 135 |
-*) |
| 136 |
echo "Error: Unrecognized option '$1'" >&2 |
| 137 |
exit 1 |
| 138 |
;; |
| 139 |
*) |
| 140 |
break |
| 141 |
;; |
| 142 |
esac |
| 143 |
shift |
| 144 |
done |
| 145 |
|
| 146 |
if [ $output_mode = $percentage ]; then |
| 147 |
inc_progress() { |
| 148 |
{ |
| 149 |
flock -n 9 |
| 150 |
n=$(($(cat .progress) + 1)) |
| 151 |
echo $n >&9 |
| 152 |
echo $n |
| 153 |
} 9<>.progress |
| 154 |
} |
| 155 |
fi |
| 156 |
|
| 157 |
CXX="$1" |
| 158 |
shift |
| 159 |
CXXFLAGS="$@" |
| 160 |
src="${srcdir}/${name}.cc" |
| 161 |
shorttype=$(echo $type|sed -e 's/long /l/' -e 's/unsigned /u/' -e 's/signed /s/') |
| 162 |
testname="${name}-${shorttype}-${abi}" |
| 163 |
exe="${testname}.exe" |
| 164 |
log="${testname}.log" |
| 165 |
sum="${testname}.sum" |
| 166 |
if [ -n "$only" ]; then |
| 167 |
if echo "$testname"|awk "{ exit /$only/ }"; then |
| 168 |
touch "$log" "$sum" |
| 169 |
[ $output_mode = $percentage ] && inc_progress >/dev/null |
| 170 |
exit 0 |
| 171 |
fi |
| 172 |
fi |
| 173 |
|
| 174 |
if [ $abi -eq 0 ]; then |
| 175 |
abiflag="" |
| 176 |
elif [ $abi -gt 0 -a $abi -lt 10 ]; then |
| 177 |
abiflag="-DEXTENDEDTESTS=$((abi-1))" |
| 178 |
else |
| 179 |
echo "Error: The -a argument must be a value between 0 and 9 (inclusive)." >&2 |
| 180 |
exit 1 |
| 181 |
fi |
| 182 |
|
| 183 |
if [ $output_mode = $percentage ]; then |
| 184 |
show_progress() { |
| 185 |
n=$(inc_progress) |
| 186 |
read total < .progress_total |
| 187 |
total=${total}0 |
| 188 |
printf "\e[1G\e[K[%3d %%] ${src##*/} $type $abiflag" \ |
| 189 |
$((n * 1005 / total)) |
| 190 |
} |
| 191 |
trap 'show_progress' EXIT |
| 192 |
prefix="\e[1G\e[K" |
| 193 |
elif [ $output_mode = $same_line ]; then |
| 194 |
show_progress() { |
| 195 |
printf "\e[1G\e[K${src##*/} $type $abiflag" |
| 196 |
} |
| 197 |
trap 'show_progress' EXIT |
| 198 |
prefix="\e[1G\e[K" |
| 199 |
else |
| 200 |
prefix="" |
| 201 |
fi |
| 202 |
|
| 203 |
fail() { |
| 204 |
printf "$prefix" |
| 205 |
echo "FAIL: $src $type $abiflag ($*)" | tee -a "$sum" "$log" |
| 206 |
} |
| 207 |
|
| 208 |
xpass() { |
| 209 |
printf "$prefix" |
| 210 |
echo "XPASS: $src $type $abiflag ($*)" | tee -a "$sum" "$log" |
| 211 |
} |
| 212 |
|
| 213 |
xfail() { |
| 214 |
[ $output_mode -ge $verbose ] && echo "XFAIL: $src $type $abiflag ($*)" |
| 215 |
echo "XFAIL: $src $type $abiflag ($*)" >> "$sum" |
| 216 |
echo "XFAIL: $src $type $abiflag ($*)" >> "$log" |
| 217 |
} |
| 218 |
|
| 219 |
pass() { |
| 220 |
[ $output_mode -ge $verbose ] && echo "PASS: $src $type $abiflag ($*)" |
| 221 |
echo "PASS: $src $type $abiflag ($*)" >> "$sum" |
| 222 |
echo "PASS: $src $type $abiflag ($*)" >> "$log" |
| 223 |
} |
| 224 |
|
| 225 |
unsupported() { |
| 226 |
test |
| 227 |
[ $output_mode -ge $verbose ] && echo "UNSUPPORTED: $src $type $abiflag ($*)" |
| 228 |
echo "UNSUPPORTED: $src $type $abiflag ($*)" >> "$sum" |
| 229 |
echo "UNSUPPORTED: $src $type $abiflag ($*)" >> "$log" |
| 230 |
} |
| 231 |
|
| 232 |
write_log_and_verbose() { |
| 233 |
echo "$*" >> "$log" |
| 234 |
if [ $output_mode = $really_verbose ]; then |
| 235 |
if [ -z "$COLUMNS" ] || ! type fmt>/dev/null; then |
| 236 |
echo "$*" |
| 237 |
else |
| 238 |
echo "$*" | fmt -w $COLUMNS -s - || cat |
| 239 |
fi |
| 240 |
fi |
| 241 |
} |
| 242 |
|
| 243 |
matches() { |
| 244 |
eval "case '$1' in |
| 245 |
$2) return 0;; esac" |
| 246 |
return 1 |
| 247 |
} |
| 248 |
|
| 249 |
test_selector() { |
| 250 |
string="$1" |
| 251 |
pat_type="${string%% *}" |
| 252 |
if matches "$shorttype" "$pat_type"; then |
| 253 |
string="${string#* }" |
| 254 |
pat_abi="${string%% *}" |
| 255 |
if matches "$abi" "$pat_abi"; then |
| 256 |
string="${string#* }" |
| 257 |
pat_triplet="${string%% *}" |
| 258 |
[ -z "$target_triplet" ] && target_triplet=$($CXX -dumpmachine) |
| 259 |
if matches "$target_triplet" "$pat_triplet"; then |
| 260 |
pat_flags="${string#* }" |
| 261 |
if matches "$CXXFLAGS" "*$pat_flags*"; then |
| 262 |
return 0 |
| 263 |
fi |
| 264 |
fi |
| 265 |
fi |
| 266 |
fi |
| 267 |
return 1 |
| 268 |
} |
| 269 |
|
| 270 |
trap "rm -f '$log' '$sum' $exe; exit" INT |
| 271 |
rm -f "$log" "$sum" |
| 272 |
touch "$log" "$sum" |
| 273 |
|
| 274 |
read_src_option() { |
| 275 |
local key tmp var |
| 276 |
key="$1" |
| 277 |
var="$2" |
| 278 |
[ -z "$var" ] && var="$1" |
| 279 |
local tmp="$(head -n25 "$src" | grep "^//\\s*${key}: ")" |
| 280 |
if [ -n "$tmp" ]; then |
| 281 |
tmp="$(echo "${tmp#//*${key}: }" | sed -e 's/ \+/ /g' -e 's/^ //' -e 's/$//')" |
| 282 |
eval "$var=\"$tmp\"" |
| 283 |
else |
| 284 |
return 1 |
| 285 |
fi |
| 286 |
} |
| 287 |
|
| 288 |
if read_src_option skip; then |
| 289 |
if test_selector "$skip"; then |
| 290 |
# silently skip this test |
| 291 |
exit 0 |
| 292 |
fi |
| 293 |
fi |
| 294 |
if read_src_option only; then |
| 295 |
if ! test_selector "$only"; then |
| 296 |
# silently skip this test |
| 297 |
exit 0 |
| 298 |
fi |
| 299 |
fi |
| 300 |
|
| 301 |
if ! $run_expensive; then |
| 302 |
if read_src_option expensive; then |
| 303 |
if test_selector "$expensive"; then |
| 304 |
unsupported "skip expensive tests" |
| 305 |
exit 0 |
| 306 |
fi |
| 307 |
fi |
| 308 |
fi |
| 309 |
|
| 310 |
if read_src_option xfail; then |
| 311 |
if test_selector "${xfail#* }"; then |
| 312 |
xfail="${xfail%% *}" |
| 313 |
else |
| 314 |
unset xfail |
| 315 |
fi |
| 316 |
fi |
| 317 |
|
| 318 |
read_src_option timeout |
| 319 |
|
| 320 |
if read_src_option timeout-factor factor; then |
| 321 |
timeout=$(awk "BEGIN { print int($timeout * $factor) }") |
| 322 |
fi |
| 323 |
|
| 324 |
log_output() { |
| 325 |
if [ $output_mode = $really_verbose ]; then |
| 326 |
maxcol=${1:-1024} |
| 327 |
awk " |
| 328 |
BEGIN { count = 0 } |
| 329 |
/^###exitstatus### [0-9]+$/ { exit \$2 } |
| 330 |
{ |
| 331 |
print >> \"$log\" |
| 332 |
if (count >= 1000) { |
| 333 |
print \"Aborting: too much output\" >> \"$log\" |
| 334 |
print \"Aborting: too much output\" |
| 335 |
exit 125 |
| 336 |
} |
| 337 |
++count |
| 338 |
if (length(\$0) > $maxcol) { |
| 339 |
i = 1 |
| 340 |
while (i + $maxcol <= length(\$0)) { |
| 341 |
len = $maxcol |
| 342 |
line = substr(\$0, i, len) |
| 343 |
len = match(line, / [^ ]*$/) |
| 344 |
if (len <= 0) { |
| 345 |
len = match(substr(\$0, i), / [^ ]/) |
| 346 |
if (len <= 0) len = $maxcol |
| 347 |
} |
| 348 |
print substr(\$0, i, len) |
| 349 |
i += len |
| 350 |
} |
| 351 |
print substr(\$0, i) |
| 352 |
} else { |
| 353 |
print |
| 354 |
} |
| 355 |
} |
| 356 |
END { close(\"$log\") } |
| 357 |
" |
| 358 |
else |
| 359 |
awk " |
| 360 |
BEGIN { count = 0 } |
| 361 |
/^###exitstatus### [0-9]+$/ { exit \$2 } |
| 362 |
{ |
| 363 |
print >> \"$log\" |
| 364 |
if (count >= 1000) { |
| 365 |
print \"Aborting: too much output\" >> \"$log\" |
| 366 |
print \"Aborting: too much output\" |
| 367 |
exit 125 |
| 368 |
} |
| 369 |
++count |
| 370 |
} |
| 371 |
END { close(\"$log\") } |
| 372 |
" |
| 373 |
fi |
| 374 |
} |
| 375 |
|
| 376 |
verify_compilation() { |
| 377 |
log_output $COLUMNS |
| 378 |
exitstatus=$? |
| 379 |
if [ $exitstatus -eq 0 ]; then |
| 380 |
warnings=$(grep -ic 'warning:' "$log") |
| 381 |
if [ $warnings -gt 0 ]; then |
| 382 |
fail "excess warnings:" $warnings |
| 383 |
if [ $output_mode = $verbose ]; then |
| 384 |
grep -i 'warning:' "$log" | head -n5 |
| 385 |
fi |
| 386 |
elif [ "$xfail" = "compile" ]; then |
| 387 |
xpass "test for excess errors" |
| 388 |
else |
| 389 |
pass "test for excess errors" |
| 390 |
fi |
| 391 |
return 0 |
| 392 |
else |
| 393 |
if [ $exitstatus -eq 124 ]; then |
| 394 |
fail "timeout: test for excess errors" |
| 395 |
else |
| 396 |
errors=$(grep -ic 'error:' "$log") |
| 397 |
if [ "$xfail" = "compile" ]; then |
| 398 |
xfail "excess errors:" $errors |
| 399 |
exit 0 |
| 400 |
else |
| 401 |
fail "excess errors:" $errors |
| 402 |
fi |
| 403 |
fi |
| 404 |
if [ $output_mode = $verbose ]; then |
| 405 |
grep -i 'error:' "$log" | head -n5 |
| 406 |
fi |
| 407 |
return 1 |
| 408 |
fi |
| 409 |
} |
| 410 |
|
| 411 |
verify_test() { |
| 412 |
log_output $COLUMNS |
| 413 |
exitstatus=$? |
| 414 |
if [ $exitstatus -eq 0 ]; then |
| 415 |
if [ "$xfail" = "run" ]; then |
| 416 |
$keep_failed || rm "$exe" |
| 417 |
xpass "execution test" |
| 418 |
else |
| 419 |
rm "$exe" |
| 420 |
pass "execution test" |
| 421 |
fi |
| 422 |
return 0 |
| 423 |
else |
| 424 |
$keep_failed || rm "$exe" |
| 425 |
if [ $output_mode = $verbose ]; then |
| 426 |
grep -i fail "$log" | head -n5 |
| 427 |
fi |
| 428 |
if [ $exitstatus -eq 124 ]; then |
| 429 |
fail "timeout: execution test" |
| 430 |
elif [ "$xfail" = "run" ]; then |
| 431 |
xfail "execution test" |
| 432 |
else |
| 433 |
fail "execution test" |
| 434 |
fi |
| 435 |
return 1 |
| 436 |
fi |
| 437 |
} |
| 438 |
|
| 439 |
write_log_and_verbose "$CXX $src $@ -D_GLIBCXX_SIMD_TESTTYPE=$type $abiflag -o $exe" |
| 440 |
{ |
| 441 |
timeout --foreground $timeout "$CXX" "$src" "$@" "-D_GLIBCXX_SIMD_TESTTYPE=$type" $abiflag -o "$exe" 2>&1 <&- |
| 442 |
printf "###exitstatus### %d\n" $? |
| 443 |
} | verify_compilation || exit 0 |
| 444 |
if [ -n "$sim" ]; then |
| 445 |
write_log_and_verbose "$sim ./$exe" |
| 446 |
else |
| 447 |
write_log_and_verbose "./$exe" |
| 448 |
timeout=$(awk "BEGIN { print int($timeout / 2) }") |
| 449 |
fi |
| 450 |
{ |
| 451 |
timeout --foreground $timeout $sim "./$exe" 2>&1 <&- |
| 452 |
printf "###exitstatus### %d\n" $? |
| 453 |
} | verify_test || exit 0 |
| 454 |
|
| 455 |
# vim: sw=2 et cc=81 si |