|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 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 | + |
3 | 9 | sudo rm -f *.diff *.out |
4 | 10 |
|
5 | 11 | libdir="$(realpath "../.libs")" |
6 | 12 | ldpath="LD_LIBRARY_PATH=$libdir" |
7 | 13 | BSDIFF="sudo $ldpath valgrind -q $libdir/bsdiff" |
8 | 14 | BSPATCH="sudo $ldpath valgrind -q $libdir/bspatch" |
9 | 15 |
|
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 ..." |
11 | 41 | $BSPATCH data/5.bspatch.original 5.out data/5.bspatch.diff |
12 | | -echo -n "6.." |
| 42 | +check_success |
| 43 | + |
| 44 | +echo "Running test #6 ..." |
13 | 45 | $BSPATCH data/6.bspatch.original 6.out data/6.bspatch.diff |
14 | | -echo -n "7.." |
| 46 | +check_success |
| 47 | + |
| 48 | +echo "Running test #7 ..." |
15 | 49 | $BSPATCH data/7.bspatch.original 7.out data/7.bspatch.diff |
16 | | -echo -n "8.." |
| 50 | +check_success |
| 51 | + |
| 52 | +echo "Running test #8 ..." |
17 | 53 | $BSPATCH data/8.bspatch.original 8.out data/8.bspatch.diff |
18 | | -echo -n "9.." |
| 54 | +check_success |
| 55 | + |
| 56 | +echo "Running test #9 ..." |
19 | 57 | $BSPATCH data/9.bspatch.original 9.out data/9.bspatch.diff |
20 | 58 | 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 ..." |
26 | 62 | $BSPATCH data/10.bspatch.original 10.out data/10.bspatch.diff |
27 | 63 | 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 | + |
32 | 66 | #same as 9 but with zeros encoding |
33 | | -echo -n "11.." |
| 67 | +echo "Running test #11 ..." |
34 | 68 | $BSPATCH data/9.bspatch.original 11.out data/11.bspatch.diff |
35 | 69 | 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 ..." |
41 | 73 | $BSPATCH data/12.bspatch.original 12.out data/12.bspatch.diff |
42 | 74 | 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 ..." |
48 | 78 | $BSDIFF data/13.bspatch.original data/13.bspatch.modified 13.diff any |
49 | 79 | $BSPATCH data/13.bspatch.original 13.out 13.diff |
50 | 80 | 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!!" |
55 | 82 |
|
56 | 83 | # Next a very loooong running test, but one which successfully condenses the 2MB |
57 | 84 | # original file pair into a 26kB bsdiff. The bsdiff computation alone (ie: |
|
62 | 89 | # used in a regression test run at every check-in of code changes to the bsdiff |
63 | 90 | # implementation. |
64 | 91 | # |
65 | | -#echo -n "14.." |
| 92 | +#echo "Running test #14 ..." |
66 | 93 | #$BSDIFF data/14.bspatch.original data/14.bspatch.modified 14.diff any |
67 | 94 | #$BSPATCH data/14.bspatch.original 14.out 14.diff |
68 | 95 | #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!!" |
73 | 97 |
|
74 | | -echo -n "15.." |
| 98 | +echo "Running test #15 ..." |
75 | 99 | $BSDIFF data/15.bspatch.original data/15.bspatch.modified 15.diff any |
76 | 100 | # 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!" |
81 | 102 |
|
82 | | -echo -n "16.." |
| 103 | +echo "Running test #16 ..." |
83 | 104 | # any valgrind errors may indicate a buffer overflow |
84 | 105 | $BSPATCH data/16.bspatch.original 16.out data/16.bspatch.diff |
| 106 | +check_success |
85 | 107 |
|
86 | | -# add final newline |
87 | | -echo "" |
| 108 | +# For TAP support, output the plan |
| 109 | +echo "1..${testnum}" |
0 commit comments