Skip to content

Commit e91ec6e

Browse files
committed
tests: Minor test improvements
1. Ensure that a keyboard interrupt signal terminates a test run 2. Check required Perl modules before running tests Signed-off-by: Peter Oberparleiter <[email protected]>
1 parent bee8ae7 commit e91ec6e

File tree

4 files changed

+83
-3
lines changed

4 files changed

+83
-3
lines changed

tests/bin/checkdeps

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env perl
2+
#
3+
# Copyright IBM Corp. 2020
4+
#
5+
# Usage: checkdeps <perl-file1> [<perl-file2> ...]
6+
#
7+
# Check if all Perl modules required by the Perl programs specified on the
8+
# command line are available. Note that this is a simple check that will only
9+
# catch straight-forward use directives.
10+
#
11+
# Example:
12+
# $ checkdeps file.pl file2.pl
13+
#
14+
15+
use strict;
16+
use warnings;
17+
18+
my $verbose = 0;
19+
20+
sub check_file($)
21+
{
22+
my ($file) = @_;
23+
my $fd;
24+
my $line;
25+
my $rc = 0;
26+
27+
open($fd, "<", $file) or die("Could not open $file: $!\n");
28+
$line = <$fd>;
29+
30+
if ($line =~ /^#.*perl/) {
31+
while ($line = <$fd>) {
32+
my $module;
33+
34+
# Look for ...use...module...;
35+
next if ($line !~ /^\s*use\s+(\S+).*;\s*$/);
36+
37+
$module = $1;
38+
print("Checking for $module\n") if ($verbose);
39+
if (!eval("require $module")) {
40+
warn("Error: Missing Perl module '$module' ".
41+
"required by $file\n");
42+
$rc = 1;
43+
}
44+
}
45+
}
46+
47+
close($fd);
48+
49+
return $rc;
50+
}
51+
52+
sub main()
53+
{
54+
my $rc = 0;
55+
56+
for my $file (@ARGV) {
57+
$rc = 1 if (check_file($file));
58+
}
59+
60+
return $rc;
61+
}
62+
63+
exit(main());

tests/bin/runtests

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ if [[ -z "${_TESTS_RUNNING}" ]] ; then
1515

1616
testsuite_init
1717
trap testsuite_exit exit
18+
# Suppress test results on keyboard interrupt
19+
trap "trap exit ; exit 1" SIGINT
1820
fi
1921

2022
for TEST in ${TESTS} ; do
2123
if [[ -d "${TEST}" ]] ; then
2224
# Enter sub-directory
23-
${MAKE} -C "${TEST}" check
25+
${MAKE} -C "${TEST}" check || exit 1
2426
else
2527
# Enter test
2628
ABS_TEST="$PWD/$TEST"
2729
REL_TEST="${ABS_TEST##$TOPDIR}"
28-
test_run "${REL_TEST}" "${ABS_TEST}" </dev/null
30+
test_run "${REL_TEST}" "${ABS_TEST}" </dev/null || exit 1
2931
fi
3032
done
3133

tests/bin/test_run

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# test log file. Must be run after testsuite_init.
99
#
1010

11+
trap 'echo ; exit 1' SIGINT
12+
1113
TOPDIR=$(realpath $(dirname $0)/..) && source "$TOPDIR/bin/common"
1214
EXCERPTLEN=10
1315
TESTNAME="$1"

tests/common.mak

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,28 @@ endif
4343
# make TESTS=subdir
4444
MAKEOVERRIDES := $(filter-out TESTS=%,$(MAKEOVERRIDES))
4545

46-
check: prepare
46+
# Default target
47+
check:
4748
runtests "$(MAKE)" $(TESTS)
4849

50+
ifeq ($(_ONCE),)
51+
52+
# Do these only once during initialization
53+
export _ONCE := 1
54+
55+
check: checkdeps prepare
56+
57+
checkdeps:
58+
checkdeps $(TOPDIR)/../bin/* $(TOPDIR)/bin/*
59+
4960
prepare: $(INFOFILES) $(COUNTFILES)
5061

5162
# Create artificial info files as test data
5263
$(INFOFILES) $(COUNTFILES):
5364
cd $(TOPDIR) && mkinfo profiles/$(SIZE) -o src/
5465

66+
endif
67+
5568
clean: clean_echo clean_subdirs
5669

5770
clean_echo:

0 commit comments

Comments
 (0)