On Mon, May 17, 2021 at 08:49:10 +0200, Michal Privoznik wrote:
Sometimes a test has a wrapper over main() (e.g. because it's
preloading some mock libraries). In such case, the main() is
renamed to something else (usually mymain()), and main() is
generated by calling one of VIR_TEST_MAIN() or
VIR_TEST_MAIN_PRELOAD() macros.
AFAIK it's not just sometimes but always in our testsuite.
This has a neat side effect - if mymain() returns an error a
short summary is printed, e.g.:
Some tests failed. Run them using:
VIR_TEST_DEBUG=1 VIR_TEST_RANGE=5-6 ./virtest
However, this detection only works if EXIT_FAILURE is returned by
mymain(). Document and enforce this limitation.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tests/testutils.c | 13 +++++++++++++
tests/testutils.h | 4 ++++
2 files changed, 17 insertions(+)
diff --git a/tests/testutils.c b/tests/testutils.c
index 870a3b081a..b57b44fab5 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -838,6 +838,19 @@ int virTestMain(int argc,
fprintf(stderr, "%*s", 40 - (int)(testCounter % 40),
"");
fprintf(stderr, " %-3zu %s\n", testCounter, ret == 0 ? "OK"
: "FAIL");
}
+
+ switch (ret) {
+ case EXIT_FAILURE:
+ case EXIT_SUCCESS:
+ case EXIT_AM_SKIP:
+ case EXIT_AM_HARDFAIL:
+ break;
+ default:
+ fprintf(stderr, "Test callback did returned invalid value: %d\n",
ret);
s/did//
+ ret = EXIT_AM_HARDFAIL;
+ break;
+ }