-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntest.sh
executable file
·1610 lines (1374 loc) · 56 KB
/
runtest.sh
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# runtest.sh -- A dtrace tester and regression tester.
#
# Runs a bunch of .d scripts and tests their results.
# If more than one dtrace build directory is available,
# runs them each in turn, comparing their output
# and generated intermediate representation.
#
# Oracle Linux DTrace.
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
# Sanitize the shell and get configuration info.
shopt -s nullglob extglob
unset CDPATH
unset POSIXLY_CORRECT # Interferes with 'wait'
export LC_COLLATE="C"
arch="$(uname -m)"
[[ -f ./runtest.conf ]] && . ./runtest.conf
load_modules()
{
# If running as root, pull in appropriate modules
if [[ "x$(id -u)" = "x0" ]]; then
cat test/modules | xargs -rn 1 modprobe 2>/dev/null
fi
}
#
# Utility function to ensure a given provider is present.
# Uses the providers list written out at start time.
#
check_provider()
{
grep -q "^$1\$" $tmpdir/providers
}
export -f check_provider
# get_dir_name
#
# Pick a unique temporary directory name to stick things in.
# Returns results via `echo'; must be called via substitution.
#
# Respect TMPDIR if set, as POSIX requires.
get_dir_name()
{
local tmpname; # A subdir name being tested for uniqueness
false; # Starting state - reset $?
while [[ $? -ne 0 ]]; do
tmpname=${TMPDIR:-/tmp}/runtest.${RANDOM}
mkdir $tmpname # Test-and-set it
done
echo $tmpname # Name is unique, return it
}
# find_next_numeric_dir DIR
#
# Create and return the first empty numerically-named directory under DIR.
find_next_numeric_dir()
{
local i;
mkdir -p $1
for ((i=0; ; i++)); do
if [[ ! -e $1/$i ]]; then
mkdir -p $1/$i
chattr +D $1/$i 2>/dev/null
rm -f $1/current
ln -s $i $1/current
echo $1/$i
return
fi
done
}
declare -a ZAPTHESE=
# run_with_timeout TIMEOUT CMD [ARGS ...]
#
# Run command CMD with argument ARGS, with the specified timeout.
# Return the exitcode of the command, or $TIMEOUTRET if a timeout occurred.
# Also send a KILL signal if the command is still running TIMEOUTKIL seconds
# after the initial signal is sent, but start with TIMEOUTSIG so that DTrace
# can perform an orderly shutdown, if possible.
TIMEOUTSIG=TERM
TIMEOUTRET=124
TIMEOUTKIL=5
run_with_timeout()
{
log "Running timeout --signal=$TIMEOUTSIG $@ ${explicit_arg:+"$explicit_arg"}\n"
timeout --signal=$TIMEOUTSIG --kill-after=$TIMEOUTKIL $@ ${explicit_arg:+"$explicit_arg"}
local status=$?
# short wait to allow any coredump to trickle out to disk.
[[ $status -ne 0 ]] && sleep 1
# status 128+9 indicates timeout via KILL(=9)
if [[ $status -eq 137 ]]; then
status=$TIMEOUTRET
fi
return $status
}
# exist_options NAME FILE
#
# Return 0 iff a set of runtest options named NAME exists in FILE,
# or in the test.options file in its directory or in any parent
# up to test/.
#
# The options have the form @@NAME.
exist_options()
{
local retval=1
local path=$2
local file=$2
while [[ $retval -ne 0 ]]; do
if [[ -e "$file" ]]; then
grep -Eq "@@"$1 $file
retval=$?
fi
path="$(dirname $path)"
file="$path/test.options"
if [[ -e "$path/test.$arch.options" ]]; then
file="$path/test.$arch.options"
fi
# Halt at top level.
if [[ -e $path/Makecheck ]]; then
break
fi
done
return $retval
}
# extract_options NAME FILE EXPAND ACCUMULATE
#
# Extract the options named NAME from FILE, or in the test.options file in its
# directory or any parent up to test/, and return them on stdout.
#
# If EXPAND is set, do a round of shell evaluation on them first.
#
# If ACCUMULATE is set, return the concatenated values of all options named
# NAME up to test/.
extract_options()
{
local retval=1
local path=$2
local file=$2
local expand=$3
local accumulate=$4
local val=
while :; do
# This horrible sequence of patterns catches @@foo, @@foo: bar, and @@foo */,
# while not catching @@foo-bar or @@foo-bar: baz. */
if [[ -f $file ]] && grep -Eq -e "@@"$1' *:' -e "@@"$1" " -e "@@"$1'$' $file; then
local val="$val$(grep -E -e "@@"$1' *:' -e "@@"$1" " -e "@@"$1'$' $file | sed 's,.*@@'$1' *: ,,; s,\*/$,,; s, *$,,')"
if [[ -n $accumulate ]]; then
val="$val "
fi
fi
path="$(dirname $path)"
file="$path/test.options"
if [[ -e "$path/test.$arch.options" ]]; then
file="$path/test.$arch.options"
fi
# Halt when we have any tags if not accumulating, or at top level anyway.
if { [[ -z $accumulate ]] && [[ -n $val ]]; } || [[ -e $path/Makecheck ]]; then
# Force the $_pid to expand to itself.
_pid='$_pid'
# This trick is because printf with a straight eval ends up called
# with more args than format string items and squashes out spaces,
# echo -e -e foo prints 'foo', and bash's builtin echo -e -- "foo"
# prints "-- foo". coreutils echo does the right thing, but is more
# expensive than the builtin printf, so use it only when needed.
if [[ -n $val ]]; then
if [[ -n $expand ]]; then
eval printf "%s" \""$val"\"
else
printf "%s" ''"$val"
fi
fi
return
fi
done
}
# is_interpreter_file FILE
is_interpreter_file()
{
if [[ ! -e $1 ]]; then
return 1
fi
if [[ $(awk '{print $1; exit}' $1) != "#!dtrace" ]]; then
return 1
fi
# At this point, perhaps we can also check that the file is executable.
# But we will copy it anyhow. So do not bother.
return 0
}
DEFAULT_TIMEOUT=41
usage()
{
cat <<EOF
$0 -- testsuite engine for DTrace
Usage: runtest options [TEST ...]
Options:
--timeout=TIME: Time out test runs after TIME seconds (default
$DEFAULT_TIMEOUT). (May cause many test failures if lowered.)
--skip-longer[=TIME]: Skip all tests with expected timeouts longer than
TIME (if not specified, $DEFAULT_TIMEOUT or whatever is
specified by --timeout, whichever is longer).
--ignore-timeouts: Treat all timeouts as not being failures. (For use when
testing under load.)
--testsuites=SUITES: Which testsuites (directories under test/) to run,
as a comma-separated list.
--[no-]execute: Execute probes with associated triggers.
--[no-]comparison: (Do not) compare results against expected results.
If result comparison is suppressed, XPASSes are
silently converted to PASSes (catering for expected
failures which are shown only via a miscomparison).
--[no-]capture-expected: Record results of tests that exit successfully
or with a timeout, but have no expected results,
as the expected results. (Only useful if
--no-comparison is not specified.)
--[no-]baddof: Run corrupt-DOF tests.
--[no-]use-installed: Use an installed dtrace rather than a copy in the
source tree.
--quiet: Only show unexpected output (FAILs and XPASSes).
--verbose: The opposite of --quiet (and the default).
--[no-]tag=TAG: Run only tests with[out] TAG.
Multiple such options are ANDed together.
--help: This message.
If one or more TESTs is provided, they must be the name of .d files existing
under the test/ directory. If none is provided, all available tests are run.
EOF
exit 0
}
# Parameters.
CAPTURE_EXPECTED=${DTRACE_TEST_CAPTURE_EXPECTED:+t}
OVERWRITE_RESULTS=
NOEXEC=${DTRACE_TEST_NO_EXECUTE:+t}
NOBADDOF=${DTRACE_TEST_BADDOF:-t}
USE_INSTALLED=${DTRACE_TEST_USE_INSTALLED:+t}
VALGRIND=${DTRACE_TEST_VALGRIND:+t}
COMPARISON=t
SKIP_LONGER=
if [[ -n $DTRACE_TEST_TESTSUITES ]]; then
TESTSUITES="${DTRACE_TEST_TESTSUITES}"
else
TESTSUITES="unittest internals stress demo"
fi
ONLY_TESTS=
TESTS=
QUIET=
USER_TAGS=
if [[ -n $DTRACE_TEST_TIMEOUT ]]; then
TIMEOUT="$DTRACE_TEST_TIMEOUT"
else
TIMEOUT=$DEFAULT_TIMEOUT
fi
IGNORE_TIMEOUTS=${DTRACE_TEST_IGNORE_TIMEOUTS:+t}
ERRORS=
while [[ $# -gt 0 ]]; do
case $1 in
--capture-expected) CAPTURE_EXPECTED=t;;
--no-capture-expected) CAPTURE_EXPECTED=;;
--execute) NOEXEC=;;
--no-execute) NOEXEC=t;;
--comparison) COMPARISON=t;;
--no-comparison) COMPARISON=;;
--valgrind) VALGRIND=t;;
--no-valgrind) VALGRIND=;;
--baddof) NOBADDOF=;;
--no-baddof) NOBADDOF=t;;
--use-installed) USE_INSTALLED=t;;
--no-use-installed) USE_INSTALLED=;;
--timeout=*) TIMEOUT="$(printf -- $1 | cut -d= -f2-)";;
--ignore-timeouts) IGNORE_TIMEOUTS=t;;
--skip-longer) SKIP_LONGER=$TIMEOUT;;
--skip-longer=*) SKIP_LONGER="$(printf -- $1 | cut -d= -f2-)";;
--testsuites=*) TESTSUITES="$(printf -- $1 | cut -d= -f2- | tr "," " ")";;
--quiet) QUIET=t;;
--verbose) QUIET=;;
--tag=*) USER_TAGS="$USER_TAGS $(printf -- $1 | cut -d= -f2-)";;
--no-tag=*) USER_TAGS="$USER_TAGS !$(printf -- $1 | cut -d= -f2-)";;
--help|--*) usage;;
*) ONLY_TESTS=t
OVERWRITE_RESULTS=t
if [[ -f $1 ]]; then
TESTS="$TESTS $1"
else
echo "Test $1 not found, ignored." >&2
fi;;
esac
shift
done
# Store test results in a directory with an incrementing name.
# We arbitrarily assume that we are being run from ~: since
# this is what 'make check' does, that's a reasonable
# assumption.
cd $(dirname $0)
logdir=$(find_next_numeric_dir test/log)
LOGFILE=$logdir/runtest.log
SUMFILE=$logdir/runtest.sum
# Set a locked-memory limit that should be big enough for the test suite.
ulimit -l $((256 * 1024 * 1024))
# If running as root, remember and turn off core_pattern, and set the
# coredumpsize to a biggish value.
orig_core_pattern=
orig_core_uses_pid=
if [[ "x$(id -u)" = "x0" ]]; then
orig_core_pattern="$(cat /proc/sys/kernel/core_pattern)"
orig_core_uses_pid="$(cat /proc/sys/kernel/core_uses_pid)"
echo core > /proc/sys/kernel/core_pattern
echo 0 > /proc/sys/kernel/core_uses_pid
ulimit -c 1000000
fi
# Make a temporary directory for intermediate result storage.
# Make a binary directory within it, for wrapper scripts.
export tmpdir="$(get_dir_name)"
mkdir $tmpdir/bin
export PATH=$tmpdir/bin:$PATH
# Log and failure functions.
out()
{
if [[ -z $QUIET ]]; then
printf "%s" "$*" | sed 's,%,%%,g' | xargs -0n 1 printf
fi
sum "$@"
}
force_out_only()
{
printf "%s" "$*" | sed 's,%,%%,g' | xargs -0n 1 printf
}
force_out()
{
force_out_only "$@"
sum "$@"
}
sum()
{
printf "%s" "$*" | sed 's,%,%%,g' | xargs -0n 1 printf >> $SUMFILE
log "$@"
}
log()
{
printf "%s" "$*" | sed 's,%,%%,g' | xargs -0n 1 printf >> $LOGFILE
}
# At shutdown, delete this directory, kill requested processes, and restore
# core_pattern. When this is specifically an interruption, report as much in
# the log.
closedown()
{
for pid in ${ZAPTHESE[@]}; do
kill -9 -- $pid
done
if [[ -z $orig_core_pattern ]]; then
echo $orig_core_pattern > /proc/sys/kernel/core_pattern
echo $orig_core_uses_pid > /proc/sys/kernel/core_uses_pid
fi
declare -ga ZAPTHESE=
}
trap 'rm -rf ${tmpdir}; closedown; exit' EXIT
trap 'force_out "Test interrupted.\n"; closedown' INT HUP QUIT TERM
# fail XFAIL XFAILMSG FAILMSG
#
# Report a test failure, whether expected or otherwise, with the given
# message. If XFAIL is unset, XFAILMSG is ignored. If FAILMSG
# would be printed but is unset, $testmsg is used instead.
fail()
{
local xfail="$1"
local xfailmsg="$2"
# In quiet mode, we may need to print out the test name too.
[[ -n $QUIET ]] && [[ -z $xfail ]] && force_out_only "$_test: "
shift 2
local failmsg="$(echo ''"$@" | sed 's,^ *,,; s, $,,;')"
if [[ -z $failmsg ]]; then
failmsg="$testmsg"
fi
if [[ -n "$xfail" ]] && [[ -n "$xfailmsg" ]]; then
out "XFAIL: $@ ($xfailmsg).\n"
elif [[ -n "$xfail" ]]; then
out "XFAIL: $@.\n"
elif [[ -n $failmsg ]]; then
ERRORS=t
force_out "FAIL: $failmsg.\n"
else
ERRORS=t
force_out "FAIL.\n"
fi
}
# pass XFAIL MSG
#
# Report a test pass, possibly unexpected. The output format is subtly
# different from failures, to emphasise that the message is less important
# than the fact of passing. If MSG would be printed but is unset, $testmsg
# is used instead.
pass()
{
local xpass="$1"
local xout=out
# In quiet mode, we may need to print out the test name, and will
# want to print out the PASS message if and only if this was an
# XPASS.
if [[ -n $xpass ]] && [[ -n $COMPARISON ]]; then
[[ -n $QUIET ]] && force_out_only "$_test: "
force_out "X"
xout=force_out
fi
shift
local msg="$(echo ''"$@" | sed 's,^ *,,; s, $,,; s,^# *,,')"
if [[ -z $msg ]]; then
msg="$testmsg"
fi
if [[ $# -gt 0 ]] && [[ -n "$msg" ]]; then
$xout "PASS ($msg).\n"
else
$xout "PASS.\n"
fi
}
# postprocess POSTPROCESSOR OUTPUT FINAL
#
# Run postprocessing over some test OUTPUT, yielding a file named
# FINAL. Possibly run the POSTPROCESSOR first.
postprocess()
{
local postprocessor=$1
local output=$2
local final=$3
local retval=0
cp -f $output $tmpdir/pp.out
# Postprocess the output, if need be.
if [[ -x $postprocessor ]]; then
if $postprocessor < $output > $tmpdir/output.post; then
mv -f $tmpdir/output.post $tmpdir/pp.out
else
retval=$?
cp -f $output $tmpdir/pp.out
fi
fi
# Transform any printed hex strings into a fixed string, excepting
# only valgrind errors.
# TODO: may need adjustment or making optional if scripts emit hex
# values which are not continuously variable.
sed -e '/^==[0-9][0-9]*== /!s,0x[0-9a-f][0-9a-f]*,{ptr},g' \
-e 's,at BPF pc [1-9][0-9]*,at BPF pc NNN,' < $tmpdir/pp.out > $final
return $retval
}
# Log results. (Purely to reduce duplication further down.)
# The single argument indicates whether to write to the sumfile:
# writes to the logfile due to reinvocations should not go to the sumfile,
# since that is just noise and throws off results counting.
resultslog()
{
want_sum=$1
# Always log the unpostprocessed test output.
cat $testout >> $LOGFILE
rm -f $testout
if [[ -n $want_sum ]]; then
if [[ -n $want_all_output ]]; then
cat $tmpdir/test.out >> $SUMFILE
elif [[ -n $want_expected_diff ]]; then
log "Diff against expected:\n"
diff -au $rfile $tmpdir/test.out | tee -a $LOGFILE >> $SUMFILE
fi
fi
# Finally, write the debugging output, if any, to the logfile.
if [[ -s $testdebug ]]; then
echo "-- @@debug --" >> $LOGFILE
cat $testdebug >> $LOGFILE
fi
rm -f $testdebug
}
if [[ -z $USE_INSTALLED ]]; then
dtrace="$(pwd)/build*/dtrace"
test_libdir="$(pwd)/build/dlibs"
test_ldflags="-L$(pwd)/build"
test_incflags="-Iinclude -Iuts/common -Ibuild -Ilibdtrace -DARCH_$arch"
helper_device="dtrace/test-$$"
dtprobed_flags="-n $helper_device -F"
export DTRACE_DOF_INIT_DEVNAME="/dev/$helper_device"
if [[ -z $(eval echo $dtrace) ]]; then
echo "No dtraces available." >&2
exit 1
fi
build/dtprobed $dtprobed_flags &
dtprobed_pid=$!
ZAPTHESE+=($dtprobed_pid)
else
dtrace="/usr/sbin/dtrace"
test_libdir="installed"
test_ldflags=""
test_incflags="-DARCH_$arch"
if [[ ! -x $dtrace ]]; then
echo "$dtrace not available." >&2
exit 1
fi
fi
export dtrace
# Flip a few env vars to tell dtrace to produce reproducible output.
export _DTRACE_TESTING=t
export LANGUAGE=C
# Figure out if the preprocessor supports -fno-diagnostics-show-option: if it
# does, add a bunch of options designed to make GCC output look like it used
# to.
# Regardless, turn off display of column numbers, if possible: they vary
# between GCC releases.
test_cppflags=
if ! /usr/bin/cpp -x c -fno-diagnostics-show-caret - /dev/null < /dev/null 2>&1 | \
grep -q 'unrecognized command line option'; then
export DTRACE_OPT_CPPARGS="-fno-diagnostics-show-caret -fdiagnostics-color=never -fno-diagnostics-show-option -fno-show-column"
elif ! /usr/bin/cpp -x c -fno-show-column - /dev/null < /dev/null 2>&1 | \
grep -q 'unrecognized command line option'; then
export DTRACE_OPT_CPPARGS="-fno-show-column"
fi
# More than one dtrace tree -> run tests for all dtraces, and verify identical
# intermediate code is produced by each dtrace.
regression=
first_dtest_dir=
if [[ $(echo $dtrace | wc -w) -gt 1 ]]; then
regression=t
fi
# If not testing an installed dtrace, we must look for our system .d files
# in the right place.
if [[ "x$test_libdir" != "xinstalled" ]]; then
export DTRACE_OPT_SYSLIBDIR="$test_libdir"
fi
# Determine the list of available providers
for dt in $dtrace; do
# Look for our shared libraries in the right place.
if [[ "x$test_libdir" != "xinstalled" ]]; then
export LD_LIBRARY_PATH="$(dirname $dt)"
fi
# Write out a list of loaded providers.
DTRACE_DEBUG= $dt -l | tail -n +2 | awk '{print $2;}' | sort -u > $tmpdir/providers
unset LD_LIBRARY_PATH
break
done
# Initialize test coverage.
if [[ -n $NOBADDOF ]]; then
for name in build*; do
if [[ -n "$(echo $name/*.gcno)" ]]; then
rm -rf $logdir/coverage
mkdir -p $logdir/coverage
lcov --zerocounters --directory $name --quiet
lcov --capture --base-directory . --directory $name --initial \
--quiet -o $logdir/coverage/initial.lcov 2>/dev/null
fi
done
if [[ -n $KERNEL_BUILD_DIR ]] && [[ -d $KERNEL_BUILD_DIR ]] &&
[[ -d /sys/kernel/debug/gcov/$KERNEL_BUILD_DIR/kernel/dtrace ]]; then
rm -rf $KERNEL_BUILD_DIR/coverage
mkdir -p $KERNEL_BUILD_DIR/coverage
lcov --zerocounters --quiet
lcov --capture --base-directory $KERNEL_BUILD_DIR --initial \
--quiet -o $KERNEL_BUILD_DIR/coverage/initial.lcov 2>/dev/null
fi
fi
load_modules
if [[ -z $NOBADDOF ]]; then
# Run DOF-corruption tests instead.
test/utils/badioctl > /dev/null 2> $tmpdir/badioctl.err &
declare ioctlpid=$!
ZAPTHESE+=($ioctlpid)
for _test in $(if [[ $ONLY_TESTS ]]; then
echo $TESTS | sed 's,\.r$,\.d,g; s,\.r ,.d ,g'
else
for name in $TESTSUITES; do
find test/$name -name "*.d" | sort -u
done
fi); do
if ! run_with_timeout $TIMEOUT test/utils/baddof $_test > /dev/null 2> $tmpdir/baddof.err; then
out "$_test: FAIL (bad DOF)"
fi
if [[ -s $tmpdir/baddof.err ]]; then
sum "baddof stderr:"
tee -a < $tmpdir/baddof.err $LOGFILE >> $SUMFILE
fi
done
if [[ "$(ps -p $ioctlpid -o ppid=)" -eq $BASHPID ]]; then
kill -$TIMEOUTSIG -- $ioctlpid >/dev/null 2>&1
fi
if [[ -s $tmpdir/badioctl.err ]]; then
sum "badioctl stderr:"
tee -a < $tmpdir/badioctl.err $LOGFILE >> $SUMFILE
fi
# equivalent of unset "ZAPTHESE[-1]" on bash < 4.3
unset "ZAPTHESE[$((${#ZAPTHESE[@]}-1))]"
exit 0
fi
# Export some variables so triggers and .sh scripts can get at them.
export _test _pid dt_flags
# Arrange to do (relatively expensive) mutex debugging.
export DTRACE_OPT_DEBUGASSERT="mutexes"
# If running DTrace inside valgrind, make sure valgrind works, and multiply
# the timeout by ten.
if [[ -n $VALGRIND ]]; then
if ! valgrind -q /bin/true >/dev/null 2>&1; then
echo "valgrind does not work: cannot run in --valgrind mode." >&2
exit 1
fi
TIMEOUT=$((TIMEOUT * 10))
fi
# Close unexpectedly open FDs.
for fd in /proc/$$/fd/*; do
fd="${fd##*/}"
case $fd in
0|1|2|255) continue;;
*) exec {fd}>&-;;
esac
done
# Mark the log and sumfiles as fsynced always.
touch $LOGFILE
touch $SUMFILE
chattr +S $LOGFILE $SUMFILE 2>/dev/null
# Form run and skip files from multiple sources of user-specified tags:
# - default-tag file (test/tags.default)
# - per-arch default-tag file (test/tags.$arch.default
# - environment variable (TEST_TAGS)
# - command-line options (--[no-]tag=)
USER_TAGS="$(cat test/tags.default test/tags.$arch.default 2>/dev/null) $TEST_TAGS $USER_TAGS"
rm -f $tmpdir/run.tags > /dev/null 2>&1
rm -f $tmpdir/skip.tags > /dev/null 2>&1
printf "%s\n" $USER_TAGS | grep -v '^!' | sort -u > $tmpdir/run.tags
printf "%s\n" $USER_TAGS | grep '^!' | sed 's/^!//' | sort -u > $tmpdir/skip.tags
# Free ourselves of the hassles of empty (but existing) files.
for name in $tmpdir/run.tags $tmpdir/skip.tags; do
if [[ `cat $name | wc -w` -eq 0 ]]; then
rm $name
fi
done
# Loop over each test in turn, or the specified subset if test names were passed
# on the command line.
# Tests are .d files, representing D programs passed to dtrace, or .sh files,
# representing shell scripts which invoke dtrace and analyze the results.
for dt in $dtrace; do
if [[ -n $regression ]]; then
force_out "\nTest of $dt:\n"
fi
# Look for our shared libraries in the right place.
if [[ "x$test_libdir" != "xinstalled" ]]; then
export LD_LIBRARY_PATH="$(dirname $dt)"
fi
# Log versions.
DTRACE_DEBUG= $dt -vV | tee -a $LOGFILE >> $SUMFILE
uname -a | tee -a $LOGFILE >> $SUMFILE
if [[ -f .git-version ]]; then
sum "testsuite version-control ID: $(cat .git-version)\n\n"
elif [[ -f .git-archive-version ]]; then
sum "Testsuite version-control ID: $(cat .git-archive-version)\n\n"
fi
# If we are running valgrind, invoke dtrace via a wrapper.
if [[ -n $VALGRIND ]]; then
cat >> $tmpdir/bin/$(basename $dt) <<-EOT
#!/bin/bash
# Wrap DTrace calls inside valgrind.
valgrind -q $dt "\$@"
EOT
dt="$tmpdir/bin/$(basename $dt)"
vg="valgrind -q "
chmod a+x $tmpdir/bin/$(basename $dt)
else
vg=""
fi
for _test in $(if [[ $ONLY_TESTS ]]; then
echo $TESTS | sed 's,\.r$,\.d,g; s,\.r ,.d ,g'
else
for name in $TESTSUITES; do
find test/$name \( -name "*.d" -o -name "*.sh" -o -name "*.c" \) | sort -u
done
fi); do
base=${_test%.d}
base=${base%.sh}
base=${base%.c}
testonly="$(basename $_test)"
export timeout="$TIMEOUT"
# Hidden files and editor backup files are not tests.
if [[ $_test =~ /\. ]] || [[ $test =~ ~$ ]]; then
continue
fi
if [[ ! -e $_test ]]; then
force_out "$_test: Not found.\n"
continue
fi
# Various options can be set in the test .d script, usually embedded in
# comments. In addition, any options listed in a file test.options in
# any directory from test/ on down will automatically be imposed on
# any tests in that directory tree which do not themselves impose a
# value for that option. If a file named test.$(uname -m).options
# exists at a given level, it is consulted instead of test.options at
# that level.
#
# @@runtest-opts: A set of options to be added to the default set
# (normally -S -e -s, where the -S and -e may not
# necessarily be provided.) Subjected to shell
# expansion.
#
# @@timeout: The timeout to use for this test. Overrides the --timeout
# parameter, iff the @@timeout is greater.
#
# @@skip: If true, the test is skipped.
#
# @@tags: Tag test case with specified tags, separated by spaces.
# Tags named after all subdirectories below 'test' are
# automatically added. (e.g. all tests in test/unittest/proc
# will gain the tags test/unittest/proc and test/unittest.)
#
# @@xfail: A single line containing a reason for this test's expected
# failure. (If the test passes unexpectedly, this message is
# not printed.) See '.x'.
#
# @@no-xfail: If present, this means that a test is *not* expected to
# fail, even though a test.options in a directory above
# this test says otherwise.
#
# @@timeout-success: If present, this means that a timeout is
# considered a test pass, not a test failure.
#
# @@deadman-success: If present, this means that a deadman timer
# firing is considered a test pass, not a test
# failure.
#
# @@reinvoke-failure: If present, this is an integer indicating the
# number of times to reinvoke failed tests: only
# if they fail every time will they be considered
# a FAIL rather than a PASS.
#
# @@trigger: A single line containing the name of a program in
# test/triggers which is executed after dtrace is started.
# When this program exits, dtrace will be killed. If the
# timeout expires, both programs are killed. Arguments may
# be provided as normal, and are subjected to shell
# expansion. For the sake of reproducible testcases, only
# tests with a trigger, or that explicitly declare that they
# can produce reproducible output via /* @@trigger: none */
# are ever executed against the kernel. Triggers should not
# emit anything to stdout or stderr, as their output is not
# currently trapped and it will spoil the screen display.
# See '.trigger'.
#
# @@trigger-timing: A single line containing 'before', 'after',
# 'synchro', or a number. If 'synchro' (the
# default), the trigger will be passed to dtrace via
# -c and left for dtrace to invoke. If 'after', the
# trigger will be exec()ed (from a pre-existing PID)
# after DTrace has started. If 'before', the trigger
# will already be running when DTrace starts. If a
# number, it is a count in seconds to delay trigger
# execution (to wait for DTrace to start).
#
# @@link: A library to link .c programs against (see below). -ldtrace
# by default.
#
# @@nosort: If present, this means do not sort before comparing results
# with a .r file. Results are sorted by default, since many
# test results do not have a well-defined order -- notably,
# when generated on different CPUs. Some tests, however,
# care about strict ordering.
#
# Certain filenames of test .d script are treated specially:
#
# tst.*.d: These are assumed to have /* @@trigger: none */ by default.
#
# err.*.d: As with tst.*.d, only these are additionally expected to
# return 1. (This is not the same as an XFAIL, which suggests
# that this test is known to be not passing: this indicates
# that this test is marked PASS if it returns 1, which would
# normally indicate failure.)
#
# err.D_*.d: As with err.*.d, only run with -xerrtags.
#
# drp.*.d: As with tst.*.d, only run -xdroptags.
# Various other files can exist with the same basename as the test.
# Many of these serve the same purpose as embedded comments: both exist
# to permit identical D scripts to be symlinked together while still
# permitting e.g. different triggering programs to be used.
#
# The full list of suffxes is as follows:
#
# .d: The D program itself.
#
# .sh: If executable, a shell script that is run instead of dtrace with
# a single argument, the path to dtrace. All other features are still
# provided, including timeouts. The script is run as if with
# /* @@trigger: none */. Arguments specified by @@runtest-opts, and
# a minimal set without which no tests will work, are passed in
# the environment variable dt_flags. An exit code of 67 will cause
# the test to be considered an expected failure.
#
# .c: A C program that is linked against the libraries listed in @@link,
# or -ldtrace by default, then run.
#
# .r: Expected results, after postprocessing. If not present,
# no expected-result comparison is done (the results are
# merely dumped into the logfile, and the test is deemed to
# pass as long as dtrace exits with a zero exitcode or
# times out). If any output is expected on standard error, it
# should be appended to this file, after a single line reading
# only "-- @@stderr --". Expected-result comparison can also
# be suppressed with the --no-expected command-line parameter.
#
# Files suffixed $(uname -m).r serve to override the results for a
# particular architecture.
#
# .r.p: Expected-results postprocessor: a filter run before various
# hardwired pointer-value-replacement preprocessors which
# transform all 0x[a-f]* strings into the string {ptr} and edit
# out CPU and probe IDs.
# Receives one argument, the name of the testcase.
#
# .x: If executable, a program which when executed indicates whether
# the test is expected to succeed or not in this environment.
# 0 indicates expected success, 1 expected failure, or 2 that the
# test is unreliable and should be skipped; in the latter two cases
# it can emit to standard output a one-line message describing the
# reason for failure or skipping. This permits tests to inspect
# their environment and determine whether failure is expected, or
# whether they can safely run at all. See '@@xfail' and '@@skip'.
# If both .x and @@xfail exist, only the .x is respected.
#
# Files suffixed $(uname -m).x allow xfails or skips for a
# particular architecture.
#
# As with test.options, executable files named test.x and
# test.$(uname -m).x can exist at any level in the hierarchy:
# the one that is 'most faily' wins (so any SKIP overrides any
# XFAIL, which overrides any PASS, no matter what level of the
# hierarchy it is found at).
#
# .t: If executable, serves the same purpose as the '@@trigger'
# option above. If both .t and @@trigger exist, only the .t is
# respected.
_exit="${NOEXEC:+-e}"
# Optionally skip this test.
if exist_options skip $_test; then
sum "$_test: SKIP: $(extract_options skip $_test)\n"
continue
fi
# Check if the user specified any tags.
if [[ -n "$USER_TAGS" ]]; then
# Extract tags from test, and add tags derived from the test's containing
# directory.
rm -f $tmpdir/test.tags >/dev/null 2>&1
test_tags="$(extract_options tags $_test "" t)"
test_tags="$test_tags $(shrinktest=$_test
while :; do
shrinktest="${shrinktest%/*}"
[[ "$shrinktest" =~ / ]] || break
printf "%s " "$shrinktest"
done)"
printf "%s\n" $test_tags | sort -u > $tmpdir/test.tags
# If user specified run tags, check for them.
if [[ -e $tmpdir/run.tags ]]; then
if [[ -n "$(comm -23 $tmpdir/run.tags $tmpdir/test.tags)" ]]; then
# Some user-specified run tags are not in test. Skip test.
tagdiff=$(comm -23 $tmpdir/run.tags $tmpdir/test.tags | xargs)
sum "$_test: SKIP: test lacks requested tags: $tagdiff\n"
continue
fi
fi
# If user specified skip tags, check for them.
if [[ -e $tmpdir/skip.tags && -n $test_tags ]]; then
if [[ -n "$(comm -12 $tmpdir/skip.tags $tmpdir/test.tags)" ]]; then
# Some user-specified skip tags are in test. Skip test.
tagdiff=$(comm -12 $tmpdir/skip.tags $tmpdir/test.tags | xargs)
sum "$_test: SKIP: test has excluded tags: $tagdiff\n"
continue
fi