Skip to content

Commit 9abb16b

Browse files
committed
Merge tag 'linux-kselftest-fixes-5.18-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest fixes from Shuah Khan: "Build and run-times fixes to tests: - header dependencies - missing tear-downs to release allocated resources in assert paths - missing error messages when build fails - coccicheck and unused variable warnings" * tag 'linux-kselftest-fixes-5.18-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests/harness: Pass variant to teardown selftests/harness: Run TEARDOWN for ASSERT failures selftests: fix an unused variable warning in pidfd selftest selftests: fix header dependency for pid_namespace selftests selftests: x86: add 32bit build warnings for SUSE selftests/proc: fix array_size.cocci warning selftests/vDSO: fix array_size.cocci warning
2 parents 911b2b9 + 79ee8aa commit 9abb16b

File tree

6 files changed

+54
-31
lines changed

6 files changed

+54
-31
lines changed

tools/testing/selftests/kselftest_harness.h

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include <sys/types.h>
6565
#include <sys/wait.h>
6666
#include <unistd.h>
67+
#include <setjmp.h>
6768

6869
#include "kselftest.h"
6970

@@ -183,7 +184,10 @@
183184
struct __test_metadata *_metadata, \
184185
struct __fixture_variant_metadata *variant) \
185186
{ \
186-
test_name(_metadata); \
187+
_metadata->setup_completed = true; \
188+
if (setjmp(_metadata->env) == 0) \
189+
test_name(_metadata); \
190+
__test_check_assert(_metadata); \
187191
} \
188192
static struct __test_metadata _##test_name##_object = \
189193
{ .name = #test_name, \
@@ -287,7 +291,9 @@
287291
#define FIXTURE_TEARDOWN(fixture_name) \
288292
void fixture_name##_teardown( \
289293
struct __test_metadata __attribute__((unused)) *_metadata, \
290-
FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
294+
FIXTURE_DATA(fixture_name) __attribute__((unused)) *self, \
295+
const FIXTURE_VARIANT(fixture_name) \
296+
__attribute__((unused)) *variant)
291297

292298
/**
293299
* FIXTURE_VARIANT() - Optionally called once per fixture
@@ -302,9 +308,9 @@
302308
* ...
303309
* };
304310
*
305-
* Defines type of constant parameters provided to FIXTURE_SETUP() and TEST_F()
306-
* as *variant*. Variants allow the same tests to be run with different
307-
* arguments.
311+
* Defines type of constant parameters provided to FIXTURE_SETUP(), TEST_F() and
312+
* FIXTURE_TEARDOWN as *variant*. Variants allow the same tests to be run with
313+
* different arguments.
308314
*/
309315
#define FIXTURE_VARIANT(fixture_name) struct _fixture_variant_##fixture_name
310316

@@ -356,10 +362,7 @@
356362
* Defines a test that depends on a fixture (e.g., is part of a test case).
357363
* Very similar to TEST() except that *self* is the setup instance of fixture's
358364
* datatype exposed for use by the implementation.
359-
*
360-
* Warning: use of ASSERT_* here will skip TEARDOWN.
361365
*/
362-
/* TODO(wad) register fixtures on dedicated test lists. */
363366
#define TEST_F(fixture_name, test_name) \
364367
__TEST_F_IMPL(fixture_name, test_name, -1, TEST_TIMEOUT_DEFAULT)
365368

@@ -381,12 +384,17 @@
381384
/* fixture data is alloced, setup, and torn down per call. */ \
382385
FIXTURE_DATA(fixture_name) self; \
383386
memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \
384-
fixture_name##_setup(_metadata, &self, variant->data); \
385-
/* Let setup failure terminate early. */ \
386-
if (!_metadata->passed) \
387-
return; \
388-
fixture_name##_##test_name(_metadata, &self, variant->data); \
389-
fixture_name##_teardown(_metadata, &self); \
387+
if (setjmp(_metadata->env) == 0) { \
388+
fixture_name##_setup(_metadata, &self, variant->data); \
389+
/* Let setup failure terminate early. */ \
390+
if (!_metadata->passed) \
391+
return; \
392+
_metadata->setup_completed = true; \
393+
fixture_name##_##test_name(_metadata, &self, variant->data); \
394+
} \
395+
if (_metadata->setup_completed) \
396+
fixture_name##_teardown(_metadata, &self, variant->data); \
397+
__test_check_assert(_metadata); \
390398
} \
391399
static struct __test_metadata \
392400
_##fixture_name##_##test_name##_object = { \
@@ -683,7 +691,7 @@
683691
*/
684692
#define OPTIONAL_HANDLER(_assert) \
685693
for (; _metadata->trigger; _metadata->trigger = \
686-
__bail(_assert, _metadata->no_print, _metadata->step))
694+
__bail(_assert, _metadata))
687695

688696
#define __INC_STEP(_metadata) \
689697
/* Keep "step" below 255 (which is used for "SKIP" reporting). */ \
@@ -830,6 +838,9 @@ struct __test_metadata {
830838
bool timed_out; /* did this test timeout instead of exiting? */
831839
__u8 step;
832840
bool no_print; /* manual trigger when TH_LOG_STREAM is not available */
841+
bool aborted; /* stopped test due to failed ASSERT */
842+
bool setup_completed; /* did setup finish? */
843+
jmp_buf env; /* for exiting out of test early */
833844
struct __test_results *results;
834845
struct __test_metadata *prev, *next;
835846
};
@@ -848,16 +859,26 @@ static inline void __register_test(struct __test_metadata *t)
848859
__LIST_APPEND(t->fixture->tests, t);
849860
}
850861

851-
static inline int __bail(int for_realz, bool no_print, __u8 step)
862+
static inline int __bail(int for_realz, struct __test_metadata *t)
852863
{
864+
/* if this is ASSERT, return immediately. */
853865
if (for_realz) {
854-
if (no_print)
855-
_exit(step);
856-
abort();
866+
t->aborted = true;
867+
longjmp(t->env, 1);
857868
}
869+
/* otherwise, end the for loop and continue. */
858870
return 0;
859871
}
860872

873+
static inline void __test_check_assert(struct __test_metadata *t)
874+
{
875+
if (t->aborted) {
876+
if (t->no_print)
877+
_exit(t->step);
878+
abort();
879+
}
880+
}
881+
861882
struct __test_metadata *__active_test;
862883
static void __timeout_handler(int sig, siginfo_t *info, void *ucontext)
863884
{
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# SPDX-License-Identifier: GPL-2.0
22
CFLAGS += -g -I../../../../usr/include/
33

4-
TEST_GEN_PROGS := regression_enomem
4+
TEST_GEN_PROGS = regression_enomem
55

6-
include ../lib.mk
6+
LOCAL_HDRS += $(selfdir)/pidfd/pidfd.h
77

8-
$(OUTPUT)/regression_enomem: regression_enomem.c ../pidfd/pidfd.h
8+
include ../lib.mk

tools/testing/selftests/pidfd/pidfd_wait.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ TEST(wait_states)
9595
.flags = CLONE_PIDFD | CLONE_PARENT_SETTID,
9696
.exit_signal = SIGCHLD,
9797
};
98-
int ret;
9998
pid_t pid;
10099
siginfo_t info = {
101100
.si_signo = 0,

tools/testing/selftests/proc/proc-pid-vm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
#include <sys/time.h>
4747
#include <sys/resource.h>
4848

49+
#include "../kselftest.h"
50+
4951
static inline long sys_execveat(int dirfd, const char *pathname, char **argv, char **envp, int flags)
5052
{
5153
return syscall(SYS_execveat, dirfd, pathname, argv, envp, flags);
@@ -368,7 +370,7 @@ int main(void)
368370
};
369371
int i;
370372

371-
for (i = 0; i < sizeof(S)/sizeof(S[0]); i++) {
373+
for (i = 0; i < ARRAY_SIZE(S); i++) {
372374
assert(memmem(buf, rv, S[i], strlen(S[i])));
373375
}
374376

@@ -417,7 +419,7 @@ int main(void)
417419
};
418420
int i;
419421

420-
for (i = 0; i < sizeof(S)/sizeof(S[0]); i++) {
422+
for (i = 0; i < ARRAY_SIZE(S); i++) {
421423
assert(memmem(buf, rv, S[i], strlen(S[i])));
422424
}
423425
}

tools/testing/selftests/vDSO/vdso_test_correctness.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <limits.h>
2121

2222
#include "vdso_config.h"
23+
#include "../kselftest.h"
2324

2425
static const char **name;
2526

@@ -306,10 +307,8 @@ static void test_clock_gettime(void)
306307
return;
307308
}
308309

309-
for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]);
310-
clock++) {
310+
for (int clock = 0; clock < ARRAY_SIZE(clocknames); clock++)
311311
test_one_clock_gettime(clock, clocknames[clock]);
312-
}
313312

314313
/* Also test some invalid clock ids */
315314
test_one_clock_gettime(-1, "invalid");
@@ -370,10 +369,8 @@ static void test_clock_gettime64(void)
370369
return;
371370
}
372371

373-
for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]);
374-
clock++) {
372+
for (int clock = 0; clock < ARRAY_SIZE(clocknames); clock++)
375373
test_one_clock_gettime64(clock, clocknames[clock]);
376-
}
377374

378375
/* Also test some invalid clock ids */
379376
test_one_clock_gettime64(-1, "invalid");

tools/testing/selftests/x86/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ warn_32bit_failure:
9292
echo "If you are using a Fedora-like distribution, try:"; \
9393
echo ""; \
9494
echo " yum install glibc-devel.*i686"; \
95+
echo ""; \
96+
echo "If you are using a SUSE-like distribution, try:"; \
97+
echo ""; \
98+
echo " zypper install gcc-32bit glibc-devel-static-32bit"; \
9599
exit 0;
96100
endif
97101

0 commit comments

Comments
 (0)