Skip to content

Commit

Permalink
Verify fork() support
Browse files Browse the repository at this point in the history
The tests will not pass if libcheck is compiled with CF_FORK=no
because they have been written assuming CF_FORK=yes. Each test
inherits a pristine copy of global state in the forked child process.
Mutations of global state by the child process are not propagated
forward to the next test.

This commit exposes the implicit assumption of CF_FORK=yes as
an explicit test.

Signed-off-by: Earl Chew <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
earlchew authored and jan-kiszka committed Jul 24, 2023
1 parent a621bd9 commit 9758b28
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tools/tests/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,29 @@
*/

#include <stdlib.h>
#include <stdio.h>
#include <check.h>
#include <fff.h>

extern Suite *ebg_test_suite(void);

int main(void)
{
int number_failed;
int number_failed = 1;

Suite *s;
SRunner *sr;

s = ebg_test_suite();
sr = srunner_create(s);

srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
if (srunner_fork_status(sr) != CK_FORK) {
fprintf(stderr, "Tests assume fork() support");
} else {
srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
}

return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

0 comments on commit 9758b28

Please sign in to comment.