diff options
author | Andreas Hasenack <andreas@canonical.com> | 2020-04-27 17:09:27 -0300 |
---|---|---|
committer | Andreas Hasenack <andreas@canonical.com> | 2020-04-27 17:38:15 -0300 |
commit | 6bd7c73e6075656083b0e523ac605bce9c638db6 (patch) | |
tree | 63ce78520ad51bed7261fa1e2ecfe2a5ce259258 | |
parent | 175264ca17ec8838adfb570d72cabcf5cf2a560f (diff) |
* d/rules, d/run-regression-tests.sh: run regression tests with
a script
-rwxr-xr-x | debian/rules | 21 | ||||
-rwxr-xr-x | debian/run-regression-tests.sh | 60 |
2 files changed, 61 insertions, 20 deletions
diff --git a/debian/rules b/debian/rules index aa20f30..e51a8cc 100755 --- a/debian/rules +++ b/debian/rules | |||
@@ -16,23 +16,4 @@ override_dh_makeshlibs: | |||
16 | dh_makeshlibs -- -c4 | 16 | dh_makeshlibs -- -c4 |
17 | 17 | ||
18 | override_dh_auto_test: | 18 | override_dh_auto_test: |
19 | # regress/ tests are only included when the build type is set to Debug, so | 19 | debian/run-regression-tests.sh |
20 | # we build it again in a separate directory as we don't want a Debug build | ||
21 | # in the shipped packages | ||
22 | mkdir good-case | ||
23 | echo "Running regression tests" | ||
24 | cd good-case; cmake -DCMAKE_BUILD_TYPE=Debug ..; make | ||
25 | echo "SUCCESS: regression tests passed" | ||
26 | # the way the tests are run, by just calling the built binary in a | ||
27 | # post-build hook, makes them super silent. The fact that a binary is even | ||
28 | # being called after the build is not shown. To be sure we really ran the | ||
29 | # tests, let's do it one more time but with an injected failure | ||
30 | echo "Injecting a failure and running regression tests again" | ||
31 | sed -r -i 's,exit\(0\);,assert(1 == 0); exit(0); /* force failure */,' regress/cred.c | ||
32 | # if the next grep fails, then the sed above didn't make any changes, and | ||
33 | # we should bail as the "force failure" case isn't valid anymore | ||
34 | grep "force failure" -q regress/cred.c | ||
35 | mkdir bad-case | ||
36 | cd bad-case; cmake -DCMAKE_BUILD_TYPE=Debug ..; \ | ||
37 | make && { echo "ERROR: Expected regression test failure did not happen"; exit 1; } \ | ||
38 | || echo "SUCCESS: the expected failure happened" | ||
diff --git a/debian/run-regression-tests.sh b/debian/run-regression-tests.sh new file mode 100755 index 0000000..2271e5e --- /dev/null +++ b/debian/run-regression-tests.sh | |||
@@ -0,0 +1,60 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | set -e | ||
4 | |||
5 | saved_dir=$(pwd) | ||
6 | regression_test_dir="debian/regression-test-output" | ||
7 | |||
8 | cleanup() { | ||
9 | cd ${saved_dir} | ||
10 | rm -rf ${regression_test_dir} | ||
11 | if [ -f regress/cred.c.bak ]; then | ||
12 | mv -f regress/cred.c.bak regress/cred.c | ||
13 | fi | ||
14 | } | ||
15 | |||
16 | trap cleanup 0 INT QUIT ABRT PIPE TERM | ||
17 | |||
18 | # regress/ tests are only included when the build type is set to Debug, so | ||
19 | # we build it again in a separate directory as we don't want a Debug build | ||
20 | # in the shipped packages | ||
21 | rm -rf ${regression_test_dir} | ||
22 | mkdir ${regression_test_dir} | ||
23 | echo "Running regression tests" | ||
24 | cd ${regression_test_dir} | ||
25 | cmake -DCMAKE_BUILD_TYPE=Debug ../../ | ||
26 | make | ||
27 | echo "SUCCESS: regression tests passed" | ||
28 | |||
29 | # the way the tests are run, by just calling the built binary in a | ||
30 | # post-build hook, makes them super silent. The fact that a binary is even | ||
31 | # being called after the build is not shown. To be sure we really ran the | ||
32 | # tests, let's do it one more time but with an injected failure | ||
33 | cd ${saved_dir} | ||
34 | echo "Injecting a failure and running regression tests again" | ||
35 | sed -r -i.bak 's,exit\(0\);,assert(1 == 0); exit(0); /* force failure */,' regress/cred.c | ||
36 | # if the next grep fails, then the sed above didn't make any changes, and | ||
37 | # we should bail as the "force failure" case isn't valid anymore | ||
38 | result=0 | ||
39 | grep "force failure" -q regress/cred.c || result=$? | ||
40 | if [ "$result" -ne 0 ]; then | ||
41 | echo "ERROR: failure was not injected correctly into regress/cred.c" | ||
42 | exit $result | ||
43 | fi | ||
44 | rm -rf ${regression_test_dir} | ||
45 | mkdir ${regression_test_dir} | ||
46 | cd ${regression_test_dir} | ||
47 | cmake -DCMAKE_BUILD_TYPE=Debug ../../ | ||
48 | result=0 | ||
49 | make || result=$? | ||
50 | if [ "$result" -ne 0 ]; then | ||
51 | echo "SUCCESS: the expected failure happened" | ||
52 | result=0 | ||
53 | else | ||
54 | echo "ERROR: Expected regression test failure did not happen" | ||
55 | result=1 | ||
56 | fi | ||
57 | cd ${saved_dir} | ||
58 | rm -rf ${regression_test_dir} | ||
59 | mv -f regress/cred.c.bak regress/cred.c | ||
60 | exit $result | ||