Commit 9abb16ba authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-fixes-5.18-rc2' of...

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
parents 911b2b95 79ee8aa3
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <setjmp.h>
#include "kselftest.h" #include "kselftest.h"
...@@ -183,7 +184,10 @@ ...@@ -183,7 +184,10 @@
struct __test_metadata *_metadata, \ struct __test_metadata *_metadata, \
struct __fixture_variant_metadata *variant) \ struct __fixture_variant_metadata *variant) \
{ \ { \
test_name(_metadata); \ _metadata->setup_completed = true; \
if (setjmp(_metadata->env) == 0) \
test_name(_metadata); \
__test_check_assert(_metadata); \
} \ } \
static struct __test_metadata _##test_name##_object = \ static struct __test_metadata _##test_name##_object = \
{ .name = #test_name, \ { .name = #test_name, \
...@@ -287,7 +291,9 @@ ...@@ -287,7 +291,9 @@
#define FIXTURE_TEARDOWN(fixture_name) \ #define FIXTURE_TEARDOWN(fixture_name) \
void fixture_name##_teardown( \ void fixture_name##_teardown( \
struct __test_metadata __attribute__((unused)) *_metadata, \ struct __test_metadata __attribute__((unused)) *_metadata, \
FIXTURE_DATA(fixture_name) __attribute__((unused)) *self) FIXTURE_DATA(fixture_name) __attribute__((unused)) *self, \
const FIXTURE_VARIANT(fixture_name) \
__attribute__((unused)) *variant)
/** /**
* FIXTURE_VARIANT() - Optionally called once per fixture * FIXTURE_VARIANT() - Optionally called once per fixture
...@@ -302,9 +308,9 @@ ...@@ -302,9 +308,9 @@
* ... * ...
* }; * };
* *
* Defines type of constant parameters provided to FIXTURE_SETUP() and TEST_F() * Defines type of constant parameters provided to FIXTURE_SETUP(), TEST_F() and
* as *variant*. Variants allow the same tests to be run with different * FIXTURE_TEARDOWN as *variant*. Variants allow the same tests to be run with
* arguments. * different arguments.
*/ */
#define FIXTURE_VARIANT(fixture_name) struct _fixture_variant_##fixture_name #define FIXTURE_VARIANT(fixture_name) struct _fixture_variant_##fixture_name
...@@ -356,10 +362,7 @@ ...@@ -356,10 +362,7 @@
* Defines a test that depends on a fixture (e.g., is part of a test case). * Defines a test that depends on a fixture (e.g., is part of a test case).
* Very similar to TEST() except that *self* is the setup instance of fixture's * Very similar to TEST() except that *self* is the setup instance of fixture's
* datatype exposed for use by the implementation. * datatype exposed for use by the implementation.
*
* Warning: use of ASSERT_* here will skip TEARDOWN.
*/ */
/* TODO(wad) register fixtures on dedicated test lists. */
#define TEST_F(fixture_name, test_name) \ #define TEST_F(fixture_name, test_name) \
__TEST_F_IMPL(fixture_name, test_name, -1, TEST_TIMEOUT_DEFAULT) __TEST_F_IMPL(fixture_name, test_name, -1, TEST_TIMEOUT_DEFAULT)
...@@ -381,12 +384,17 @@ ...@@ -381,12 +384,17 @@
/* fixture data is alloced, setup, and torn down per call. */ \ /* fixture data is alloced, setup, and torn down per call. */ \
FIXTURE_DATA(fixture_name) self; \ FIXTURE_DATA(fixture_name) self; \
memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \ memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \
fixture_name##_setup(_metadata, &self, variant->data); \ if (setjmp(_metadata->env) == 0) { \
/* Let setup failure terminate early. */ \ fixture_name##_setup(_metadata, &self, variant->data); \
if (!_metadata->passed) \ /* Let setup failure terminate early. */ \
return; \ if (!_metadata->passed) \
fixture_name##_##test_name(_metadata, &self, variant->data); \ return; \
fixture_name##_teardown(_metadata, &self); \ _metadata->setup_completed = true; \
fixture_name##_##test_name(_metadata, &self, variant->data); \
} \
if (_metadata->setup_completed) \
fixture_name##_teardown(_metadata, &self, variant->data); \
__test_check_assert(_metadata); \
} \ } \
static struct __test_metadata \ static struct __test_metadata \
_##fixture_name##_##test_name##_object = { \ _##fixture_name##_##test_name##_object = { \
...@@ -683,7 +691,7 @@ ...@@ -683,7 +691,7 @@
*/ */
#define OPTIONAL_HANDLER(_assert) \ #define OPTIONAL_HANDLER(_assert) \
for (; _metadata->trigger; _metadata->trigger = \ for (; _metadata->trigger; _metadata->trigger = \
__bail(_assert, _metadata->no_print, _metadata->step)) __bail(_assert, _metadata))
#define __INC_STEP(_metadata) \ #define __INC_STEP(_metadata) \
/* Keep "step" below 255 (which is used for "SKIP" reporting). */ \ /* Keep "step" below 255 (which is used for "SKIP" reporting). */ \
...@@ -830,6 +838,9 @@ struct __test_metadata { ...@@ -830,6 +838,9 @@ struct __test_metadata {
bool timed_out; /* did this test timeout instead of exiting? */ bool timed_out; /* did this test timeout instead of exiting? */
__u8 step; __u8 step;
bool no_print; /* manual trigger when TH_LOG_STREAM is not available */ bool no_print; /* manual trigger when TH_LOG_STREAM is not available */
bool aborted; /* stopped test due to failed ASSERT */
bool setup_completed; /* did setup finish? */
jmp_buf env; /* for exiting out of test early */
struct __test_results *results; struct __test_results *results;
struct __test_metadata *prev, *next; struct __test_metadata *prev, *next;
}; };
...@@ -848,16 +859,26 @@ static inline void __register_test(struct __test_metadata *t) ...@@ -848,16 +859,26 @@ static inline void __register_test(struct __test_metadata *t)
__LIST_APPEND(t->fixture->tests, t); __LIST_APPEND(t->fixture->tests, t);
} }
static inline int __bail(int for_realz, bool no_print, __u8 step) static inline int __bail(int for_realz, struct __test_metadata *t)
{ {
/* if this is ASSERT, return immediately. */
if (for_realz) { if (for_realz) {
if (no_print) t->aborted = true;
_exit(step); longjmp(t->env, 1);
abort();
} }
/* otherwise, end the for loop and continue. */
return 0; return 0;
} }
static inline void __test_check_assert(struct __test_metadata *t)
{
if (t->aborted) {
if (t->no_print)
_exit(t->step);
abort();
}
}
struct __test_metadata *__active_test; struct __test_metadata *__active_test;
static void __timeout_handler(int sig, siginfo_t *info, void *ucontext) static void __timeout_handler(int sig, siginfo_t *info, void *ucontext)
{ {
......
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
CFLAGS += -g -I../../../../usr/include/ CFLAGS += -g -I../../../../usr/include/
TEST_GEN_PROGS := regression_enomem TEST_GEN_PROGS = regression_enomem
include ../lib.mk LOCAL_HDRS += $(selfdir)/pidfd/pidfd.h
$(OUTPUT)/regression_enomem: regression_enomem.c ../pidfd/pidfd.h include ../lib.mk
...@@ -95,7 +95,6 @@ TEST(wait_states) ...@@ -95,7 +95,6 @@ TEST(wait_states)
.flags = CLONE_PIDFD | CLONE_PARENT_SETTID, .flags = CLONE_PIDFD | CLONE_PARENT_SETTID,
.exit_signal = SIGCHLD, .exit_signal = SIGCHLD,
}; };
int ret;
pid_t pid; pid_t pid;
siginfo_t info = { siginfo_t info = {
.si_signo = 0, .si_signo = 0,
......
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#include "../kselftest.h"
static inline long sys_execveat(int dirfd, const char *pathname, char **argv, char **envp, int flags) static inline long sys_execveat(int dirfd, const char *pathname, char **argv, char **envp, int flags)
{ {
return syscall(SYS_execveat, dirfd, pathname, argv, envp, flags); return syscall(SYS_execveat, dirfd, pathname, argv, envp, flags);
...@@ -368,7 +370,7 @@ int main(void) ...@@ -368,7 +370,7 @@ int main(void)
}; };
int i; int i;
for (i = 0; i < sizeof(S)/sizeof(S[0]); i++) { for (i = 0; i < ARRAY_SIZE(S); i++) {
assert(memmem(buf, rv, S[i], strlen(S[i]))); assert(memmem(buf, rv, S[i], strlen(S[i])));
} }
...@@ -417,7 +419,7 @@ int main(void) ...@@ -417,7 +419,7 @@ int main(void)
}; };
int i; int i;
for (i = 0; i < sizeof(S)/sizeof(S[0]); i++) { for (i = 0; i < ARRAY_SIZE(S); i++) {
assert(memmem(buf, rv, S[i], strlen(S[i]))); assert(memmem(buf, rv, S[i], strlen(S[i])));
} }
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <limits.h> #include <limits.h>
#include "vdso_config.h" #include "vdso_config.h"
#include "../kselftest.h"
static const char **name; static const char **name;
...@@ -306,10 +307,8 @@ static void test_clock_gettime(void) ...@@ -306,10 +307,8 @@ static void test_clock_gettime(void)
return; return;
} }
for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]); for (int clock = 0; clock < ARRAY_SIZE(clocknames); clock++)
clock++) {
test_one_clock_gettime(clock, clocknames[clock]); test_one_clock_gettime(clock, clocknames[clock]);
}
/* Also test some invalid clock ids */ /* Also test some invalid clock ids */
test_one_clock_gettime(-1, "invalid"); test_one_clock_gettime(-1, "invalid");
...@@ -370,10 +369,8 @@ static void test_clock_gettime64(void) ...@@ -370,10 +369,8 @@ static void test_clock_gettime64(void)
return; return;
} }
for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]); for (int clock = 0; clock < ARRAY_SIZE(clocknames); clock++)
clock++) {
test_one_clock_gettime64(clock, clocknames[clock]); test_one_clock_gettime64(clock, clocknames[clock]);
}
/* Also test some invalid clock ids */ /* Also test some invalid clock ids */
test_one_clock_gettime64(-1, "invalid"); test_one_clock_gettime64(-1, "invalid");
......
...@@ -92,6 +92,10 @@ warn_32bit_failure: ...@@ -92,6 +92,10 @@ warn_32bit_failure:
echo "If you are using a Fedora-like distribution, try:"; \ echo "If you are using a Fedora-like distribution, try:"; \
echo ""; \ echo ""; \
echo " yum install glibc-devel.*i686"; \ echo " yum install glibc-devel.*i686"; \
echo ""; \
echo "If you are using a SUSE-like distribution, try:"; \
echo ""; \
echo " zypper install gcc-32bit glibc-devel-static-32bit"; \
exit 0; exit 0;
endif endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment