Skip to content

Commit 24cf65a

Browse files
committed
selftests/harness: Share _metadata between forked processes
Unconditionally share _metadata between all forked processes, which enables to actually catch errors which were previously ignored. This is required for a following commit replacing vfork() with clone3() and CLONE_VFORK (i.e. not sharing the full memory) . It should also be useful to share _metadata to extend expectations to test process's forks. For instance, this change identified a wrong expectation in pidfd_setns_test. Because this _metadata is used by the new XFAIL_ADD(), use a global pointer initialized in TEST_F(). This is OK because only XFAIL_ADD() use it, and XFAIL_ADD() already depends on TEST_F(). Cc: Jakub Kicinski <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Will Drewry <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 821bc4a commit 24cf65a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

tools/testing/selftests/kselftest_harness.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,19 @@ static inline pid_t clone3_vfork(void)
430430
kill(getpid(), WTERMSIG(status)); \
431431
__test_check_assert(_metadata); \
432432
} \
433-
static struct __test_metadata \
434-
_##fixture_name##_##test_name##_object = { \
435-
.name = #test_name, \
436-
.fn = &wrapper_##fixture_name##_##test_name, \
437-
.fixture = &_##fixture_name##_fixture_object, \
438-
.termsig = signal, \
439-
.timeout = tmout, \
440-
.teardown_parent = false, \
441-
}; \
433+
static struct __test_metadata *_##fixture_name##_##test_name##_object; \
442434
static void __attribute__((constructor)) \
443435
_register_##fixture_name##_##test_name(void) \
444436
{ \
445-
__register_test(&_##fixture_name##_##test_name##_object); \
437+
struct __test_metadata *object = mmap(NULL, sizeof(*object), \
438+
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); \
439+
object->name = #test_name; \
440+
object->fn = &wrapper_##fixture_name##_##test_name; \
441+
object->fixture = &_##fixture_name##_fixture_object; \
442+
object->termsig = signal; \
443+
object->timeout = tmout; \
444+
_##fixture_name##_##test_name##_object = object; \
445+
__register_test(object); \
446446
} \
447447
static void fixture_name##_##test_name( \
448448
struct __test_metadata __attribute__((unused)) *_metadata, \
@@ -850,11 +850,12 @@ struct __test_xfail {
850850
{ \
851851
.fixture = &_##fixture_name##_fixture_object, \
852852
.variant = &_##fixture_name##_##variant_name##_object, \
853-
.test = &_##fixture_name##_##test_name##_object, \
854853
}; \
855854
static void __attribute__((constructor)) \
856855
_register_##fixture_name##_##variant_name##_##test_name##_xfail(void) \
857856
{ \
857+
_##fixture_name##_##variant_name##_##test_name##_xfail.test = \
858+
_##fixture_name##_##test_name##_object; \
858859
__register_xfail(&_##fixture_name##_##variant_name##_##test_name##_xfail); \
859860
}
860861

@@ -1181,6 +1182,9 @@ void __run_test(struct __fixture_metadata *f,
11811182
/* reset test struct */
11821183
t->exit_code = KSFT_PASS;
11831184
t->trigger = 0;
1185+
t->aborted = false;
1186+
t->setup_completed = false;
1187+
memset(t->env, 0, sizeof(t->env));
11841188
memset(t->results->reason, 0, sizeof(t->results->reason));
11851189

11861190
if (asprintf(&test_name, "%s%s%s.%s", f->name,

0 commit comments

Comments
 (0)