Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 8c0a87b

Browse files
committed
Convert functional test suite to TAP
Automake provides a nice test harness that can parse TAP results, so switch to using that. Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
1 parent 253dcbb commit 8c0a87b

File tree

4 files changed

+74
-42
lines changed

4 files changed

+74
-42
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ stamp-h1
2828
bsdiff-*.tar.xz
2929
test/*.diff
3030
test/*.out
31+
test/*.log
32+
test/*.trs
33+
tap-driver.sh
34+
test-suite.log

Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ install-exec-hook:
104104

105105
TEST_EXTENSIONS = .sh
106106
if ENABLE_TESTS
107+
tap_driver = env AM_TAP_AWK='$(AWK)' $(SHELL) \
108+
$(top_srcdir)/tap-driver.sh
109+
110+
LOG_DRIVER = $(tap_driver)
111+
SH_LOG_DRIVER = $(tap_driver)
107112
TESTS = $(dist_check_SCRIPTS)
108113
dist_check_SCRIPTS = \
109114
test/run.sh

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ AS_IF([test "$enable_tests" != "no"], [
6666
AM_CONDITIONAL([ENABLE_TESTS], [test "$enable_tests" != "no"])
6767

6868
AC_CONFIG_FILES([Makefile data/bsdiff.pc])
69+
AC_REQUIRE_AUX_FILE([tap-driver.sh])
6970
AC_OUTPUT
7071

7172
AC_MSG_RESULT([

test/run.sh

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,84 @@
11
#!/bin/bash
22

3+
# $srcdir variable is set by automake environment
4+
cd $srcdir/test
5+
6+
# number is incremented after running every test
7+
testnum=0
8+
39
sudo rm -f *.diff *.out
410

511
libdir="$(realpath "../.libs")"
612
ldpath="LD_LIBRARY_PATH=$libdir"
713
BSDIFF="sudo $ldpath valgrind -q $libdir/bsdiff"
814
BSPATCH="sudo $ldpath valgrind -q $libdir/bspatch"
915

10-
echo -n "5.."
16+
# If exit status is 0, the test succeeded. Else it failed.
17+
check_success() {
18+
res=$?
19+
[ -n "$1" ] && msg="$1" || msg=""
20+
testnum=$(expr $testnum + 1)
21+
if [ $res -ne 0 ]; then
22+
echo "not ok $testnum - $msg"
23+
else
24+
echo "ok $testnum"
25+
fi
26+
}
27+
28+
# If exit status is 255, the test succeeded. Else it failed.
29+
check_failure() {
30+
res=$?
31+
[ -n "$1" ] && msg="$1" || msg=""
32+
testnum=$(expr $testnum + 1)
33+
if [ $res -ne 255 ]; then
34+
echo "not ok $testnum - $msg"
35+
else
36+
echo "ok $testnum"
37+
fi
38+
}
39+
40+
echo "Running test #5 ..."
1141
$BSPATCH data/5.bspatch.original 5.out data/5.bspatch.diff
12-
echo -n "6.."
42+
check_success
43+
44+
echo "Running test #6 ..."
1345
$BSPATCH data/6.bspatch.original 6.out data/6.bspatch.diff
14-
echo -n "7.."
46+
check_success
47+
48+
echo "Running test #7 ..."
1549
$BSPATCH data/7.bspatch.original 7.out data/7.bspatch.diff
16-
echo -n "8.."
50+
check_success
51+
52+
echo "Running test #8 ..."
1753
$BSPATCH data/8.bspatch.original 8.out data/8.bspatch.diff
18-
echo -n "9.."
54+
check_success
55+
56+
echo "Running test #9 ..."
1957
$BSPATCH data/9.bspatch.original 9.out data/9.bspatch.diff
2058
diff data/9.bspatch.modified 9.out
21-
if [ $? -ne 0 ]
22-
then
23-
echo "bspatch 9 output does not match expected!!"
24-
fi
25-
echo -n "10.."
59+
check_success "output does not match expected!!"
60+
61+
echo "Running test #10 ..."
2662
$BSPATCH data/10.bspatch.original 10.out data/10.bspatch.diff
2763
diff data/10.bspatch.modified 10.out
28-
if [ $? -ne 0 ]
29-
then
30-
echo "bspatch 10 output does not match expected!!"
31-
fi
64+
check_success "output does not match expected!!"
65+
3266
#same as 9 but with zeros encoding
33-
echo -n "11.."
67+
echo "Running test #11 ..."
3468
$BSPATCH data/9.bspatch.original 11.out data/11.bspatch.diff
3569
diff data/9.bspatch.modified 11.out
36-
if [ $? -ne 0 ]
37-
then
38-
echo "bspatch 11 output does not match expected!!"
39-
fi
40-
echo -n "12.."
70+
check_success "output does not match expected!!"
71+
72+
echo "Running test #12 ..."
4173
$BSPATCH data/12.bspatch.original 12.out data/12.bspatch.diff
4274
diff data/12.bspatch.modified 12.out
43-
if [ $? -ne 0 ]
44-
then
45-
echo "bspatch 12 output does not match expected!!"
46-
fi
47-
echo -n "13.."
75+
check_success "output does not match expected!!"
76+
77+
echo "Running test #13 ..."
4878
$BSDIFF data/13.bspatch.original data/13.bspatch.modified 13.diff any
4979
$BSPATCH data/13.bspatch.original 13.out 13.diff
5080
diff data/13.bspatch.modified 13.out
51-
if [ $? -ne 0 ]
52-
then
53-
echo "bspatch 13 output does not match expected!!"
54-
fi
81+
check_success "output does not match expected!!"
5582

5683
# Next a very loooong running test, but one which successfully condenses the 2MB
5784
# original file pair into a 26kB bsdiff. The bsdiff computation alone (ie:
@@ -62,26 +89,21 @@ fi
6289
# used in a regression test run at every check-in of code changes to the bsdiff
6390
# implementation.
6491
#
65-
#echo -n "14.."
92+
#echo "Running test #14 ..."
6693
#$BSDIFF data/14.bspatch.original data/14.bspatch.modified 14.diff any
6794
#$BSPATCH data/14.bspatch.original 14.out 14.diff
6895
#diff data/14.bspatch.modified 14.out
69-
#if [ $? -ne 0 ]
70-
#then
71-
# echo "bspatch 14 output does not match expected!!"
72-
#fi
96+
#check_success "output does not match expected!!"
7397

74-
echo -n "15.."
98+
echo "Running test #15 ..."
7599
$BSDIFF data/15.bspatch.original data/15.bspatch.modified 15.diff any
76100
# expected output: "Failed to create delta (-1)"
77-
if [ $? -ne 255 ]
78-
then
79-
echo "bspatch 15 creation has memory management issue!"
80-
fi
101+
check_failure "patch creation has memory management issue!"
81102

82-
echo -n "16.."
103+
echo "Running test #16 ..."
83104
# any valgrind errors may indicate a buffer overflow
84105
$BSPATCH data/16.bspatch.original 16.out data/16.bspatch.diff
106+
check_success
85107

86-
# add final newline
87-
echo ""
108+
# For TAP support, output the plan
109+
echo "1..${testnum}"

0 commit comments

Comments
 (0)