Skip to content

Commit 3d6e3ab

Browse files
committed
Add new pdsh testsuite
Add a new pdsh testsuite based on test-lib.sh from the Git tests. See tests/README for more information.
1 parent 4ded388 commit 3d6e3ab

19 files changed

+2024
-1
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
2010-10-19 Mark Grondona <mgrondona@llnl.gov>
22

3+
* Makefile.am, configure.ac, tests/* :
4+
Add new pdsh testsuite based on the test-lib.sh from Git.
5+
See tests/README for more information.
6+
37
* src/pdsh/main.c :
48
Allow PDSH_MODULE_DIR to override pdsh_module_dir iff pdsh
59
is not running as root and isn't running setuid. This will be

Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include $(top_srcdir)/config/Make-inc.mk
99
ACLOCAL_AMFLAGS = -I config
1010
AUTOMAKE_OPTIONS = foreign dist-bzip2
1111
CONFIG_STATUS_DEPENDENCIES = META
12-
SUBDIRS = src doc etc scripts config
12+
SUBDIRS = src tests doc etc scripts config
1313

1414
maintainer-clean-local:
1515
-(cd $(top_srcdir) && rm -rf autom4te.cache)

configure.ac

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ AC_CONFIG_FILES([
319319
doc/Makefile
320320
etc/Makefile
321321
scripts/Makefile
322+
tests/Makefile
323+
tests/test-modules/Makefile
322324
doc/pdcp.1
323325
doc/pdsh.1
324326
]

tests/Makefile.am

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
SUBDIRS = test-modules
3+
CPPFLAGS = \
4+
-I $(top_srcdir)
5+
6+
T = $(wildcard $(srcdir)/t[0-9]*.sh)
7+
8+
TESTS = $(T)
9+
10+
EXTRA_DIST = \
11+
test-lib.sh \
12+
aggregate-results.sh \
13+
$(T)
14+
15+
clean-local:
16+
rm -fr trash-directory.* test-results .prove
17+
18+

tests/README

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Pdsh Tests
2+
----------
3+
4+
This directory contains many basic test scripts for pdsh
5+
and its modules. The test framework is borrowed from the
6+
core Git testsuite, and thus shares many of the Git
7+
test features, including output in the Test Anything
8+
Protocol (TAP, testanything.org) format.
9+
10+
Running Tests
11+
-------------
12+
13+
Tests may be run in 3 different ways, the easiest of which
14+
is by issuing "make check" from this directory or the top
15+
level pdsh build directory. The tests may also all be
16+
invoked via ./runtests.sh. Finally, since the tests output
17+
TAP, the tests may be run with any TAP harness, most
18+
notably the prove(1) command, e.g.
19+
20+
prove --timer -j 4 t[0-9]*.sh
21+
[15:47:54] t0002-internal.sh ........ ok 79 ms
22+
[15:47:54] t0101-dshgroup.sh ........ ok 263 ms
23+
[15:47:54] t1000-dshbak.sh .......... ok 365 ms
24+
[15:47:54] t0004-module-loading.sh .. ok 329 ms
25+
[15:47:54] t0003-wcoll.sh ........... ok 569 ms
26+
[15:47:54] t0001-basic.sh ........... ok 676 ms
27+
[15:47:54]
28+
All tests successful.
29+
Files=8, Tests=55, 1 wallclock secs ( 0.13 usr 0.05 sys + 0.75 cusr 1.64 csys = 2.57 CPU)
30+
Result: PASS
31+
32+
33+
Test scripts may be run individually as well, e.g.
34+
35+
./t0003-wcoll.sh
36+
ok 1 - hostname range expansion works
37+
ok 2 - host range expansion does not strip leading zeros
38+
ok 3 - host range expansion handles mixed size suffixes
39+
...
40+
ok 11 - WCOLL environment variable works
41+
ok 12 - ranges can be embedded in wcoll files
42+
# passed all 12 test(s)
43+
1..12
44+
45+
Tests also support a standard set of options:
46+
47+
-v, --verbose Print commands being run and their output
48+
-d, --debug Enable any test debugging
49+
-i, --immediate Fail immediately on first failed test
50+
-l, --long-tests Run additional long-running tests
51+
--tee Also write test output to test-results/$TEST_NAME.out
52+
--root=dir Create 'trash' directories under "dir"
53+
54+
Skipping Tests
55+
--------------
56+
57+
The environment variable PDSH_SKIP_TESTS is a space separated list
58+
of patterns that tells which tests to skip, and can either match
59+
the test number t[0-9]{4} to skip an entire test script, or
60+
have an appended .$number to skip a particular test in a test script.
61+
62+
Test Naming
63+
-------------
64+
65+
The test files are by convention named
66+
67+
tNNNN-<name>.sh
68+
69+
where N is a decimal digit. For pdsh, only the first digit has meaning,
70+
where so far the only digits used are:
71+
72+
0 - basic pdsh functionality tests
73+
1 - pdsh module tests
74+
5 - other tools tests (e.g. dshbak)
75+
76+
Obviously, tests are run in numerical order, so if one test depends on
77+
another it should be numbered higher.
78+

tests/aggregate-results.sh

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/sh
2+
3+
fixed=0
4+
success=0
5+
failed=0
6+
broken=0
7+
total=0
8+
9+
for file
10+
do
11+
while read type value
12+
do
13+
case $type in
14+
'')
15+
continue ;;
16+
fixed)
17+
fixed=$(($fixed + $value)) ;;
18+
success)
19+
success=$(($success + $value)) ;;
20+
failed)
21+
failed=$(($failed + $value)) ;;
22+
broken)
23+
broken=$(($broken + $value)) ;;
24+
total)
25+
total=$(($total + $value)) ;;
26+
esac
27+
done <"$file"
28+
done
29+
30+
pluralize () {
31+
case $2 in
32+
1)
33+
case $1 in
34+
test)
35+
echo test ;;
36+
failure)
37+
echo failure ;;
38+
esac
39+
;;
40+
*)
41+
case $1 in
42+
test)
43+
echo tests ;;
44+
failure)
45+
echo failures ;;
46+
esac
47+
;;
48+
esac
49+
}
50+
51+
echo "pdsh test suite complete."
52+
if [ "$fixed" = "0" ] && [ "$failed" = "0" ]; then
53+
tests=$(pluralize "test" $total)
54+
printf "All $total $tests "
55+
if [ "$broken" = "0" ]; then
56+
echo "passed."
57+
else
58+
failures=$(pluralize "failure" $broken)
59+
echo "behaved as expected ($broken expected $failures)."
60+
fi;
61+
else
62+
echo "$success/$total tests passed."
63+
if [ "$broken" != "0" ]; then
64+
tests=$(pluralize "test" $broken)
65+
echo "$broken broken $tests failed as expected."
66+
fi
67+
if [ "$fixed" != "0" ]; then
68+
tests=$(pluralize "test" $fixed)
69+
echo "$fixed broken $tests now fixed."
70+
fi
71+
if [ "$failed" != "0" ]; then
72+
tests=$(pluralize "test" $failed)
73+
echo "$failed $tests failed."
74+
fi
75+
fi
76+
77+
skipped=$(($total - $fixed - $success - $failed - $broken))
78+
if [ "$skipped" != "0" ]; then
79+
tests=$(pluralize "test" $skipped)
80+
echo "$skipped $tests skipped."
81+
fi

tests/runtests.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
rm -rf test-results trash-directory*
3+
4+
for test in t[0-9]*.sh; do
5+
echo "*** $test ***"
6+
./$test
7+
done
8+
9+
./aggregate-results.sh test-results/*

tests/t0001-basic.sh

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/sh
2+
3+
test_description='test framework and pdsh basics'
4+
5+
if ! test -x ../src/pdsh/pdsh; then
6+
echo >&2 'Failed to find pdsh binary. Please run make.'
7+
exit 1
8+
fi
9+
10+
. ${srcdir:-.}/test-lib.sh
11+
12+
###########################################################################
13+
#
14+
# Tests of the framework. From git teststuite:
15+
#
16+
test_expect_success 'working success' '/bin/true'
17+
18+
test_set_prereq HAVEIT
19+
haveit=no
20+
test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
21+
test_have_prereq HAVEIT &&
22+
haveit=yes
23+
'
24+
25+
clean=no
26+
test_expect_success 'tests clean up after themselves' '
27+
test_when_finished clean=yes
28+
'
29+
30+
cleaner=no
31+
test_expect_code 1 'tests clean up even after a failure' '
32+
test_when_finished cleaner=yes &&
33+
(exit 1)
34+
'
35+
36+
if test $clean$cleaner != yesyes
37+
then
38+
say "bug in test framework: cleanup commands do not work reliably"
39+
exit 1
40+
fi
41+
42+
test_expect_code 2 'failure to clean up causes the test to fail' '
43+
test_when_finished "(exit 2)"
44+
'
45+
46+
###########################################################################
47+
#
48+
# Basic pdsh functionality
49+
#
50+
test_expect_success 'pdsh runs' '
51+
pdsh -w foo -q | tail -1 | grep foo
52+
'
53+
test_expect_success 'pdsh -V works' '
54+
pdsh -V 2>&1 | grep -q ^pdsh
55+
'
56+
test_expect_success 'pdsh -L works' '
57+
pdsh -L 2>&1 | grep -q ^Module:
58+
'
59+
test_expect_success 'pdsh -h works' '
60+
pdsh -h 2>&1 | grep Usage:
61+
'
62+
test_expect_success 'rcmd/exec module is built' '
63+
test_have_prereq MOD_RCMD_EXEC && havit=yes
64+
'
65+
test_expect_success 'pdsh -N option works' '
66+
O1=$(pdsh -Rexec -w foo0 echo foo | sed "s/foo0: //")
67+
O2=$(pdsh -NRexec -w foo0 echo foo)
68+
if ! test "$O1" = "$O2"; then
69+
say_color error "Error: -N output \"$O1\" != \"$O2\""
70+
false
71+
fi
72+
'
73+
74+
run_timeout() {
75+
perl -e 'alarm shift @ARGV; exec @ARGV' "$@"
76+
}
77+
test_expect_success LONGTESTS '-u option is functional' '
78+
run_timeout 5 pdsh -wfoo -Rexec -u 1 sleep 10 2>&1 \
79+
| grep -i "command timeout"
80+
'
81+
82+
check_pdsh_option() {
83+
flag=$1; name=$2; value=$3;
84+
flagval=$value
85+
if test "$value" = "Yes" -o "$value" = "No"; then
86+
flagval=""
87+
fi
88+
echo "flag=$flag name='$name' value=$value flagval=$flagval"
89+
pdsh -$flag$flagval -w foo -q | grep -q "$name[ ]*$value$"
90+
}
91+
92+
test_expect_success '-f sets fanout' '
93+
check_pdsh_option f Fanout 8
94+
'
95+
test_expect_success '-l sets remote username' '
96+
check_pdsh_option l "Remote username" foouser
97+
'
98+
test_expect_success '-t sets connect timeout' '
99+
check_pdsh_option t "Connect timeout (secs)" 33
100+
'
101+
test_expect_success '-u sets command timeout' '
102+
check_pdsh_option u "Command timeout (secs)" 22
103+
'
104+
test_expect_success 'command timeout 0 by default' '
105+
pdsh -w foo -q | grep -q "Command timeout (secs)[ ]*0$"
106+
'
107+
test_expect_success '-b enables batch mode' '
108+
check_pdsh_option b "one \^C will kill pdsh" Yes
109+
'
110+
test_expect_success 'pdsh -N option works' '
111+
O1=$(pdsh -Rexec -w foo0 echo foo | sed "s/foo0: //")
112+
O2=$(pdsh -NRexec -w foo0 echo foo)
113+
if ! test "$O1" = "$O2"; then
114+
say_color error "Error: -N output \"$O1\" != \"$O2\""
115+
false
116+
fi
117+
'
118+
test_done

tests/t0002-internal.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
test_description='pdsh internal testcases
4+
5+
Run pdsh internal testsuite'
6+
7+
. ${srcdir:-.}/test-lib.sh
8+
9+
test_expect_success 'working xstrerrorcat' '
10+
pdsh -T0
11+
'
12+
test_expect_success 'working pipecmd' '
13+
pdsh -T1
14+
'
15+
test_done

0 commit comments

Comments
 (0)