Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+54 -31
+40 -19
tools/testing/selftests/kselftest_harness.h
··· 64 64 #include <sys/types.h> 65 65 #include <sys/wait.h> 66 66 #include <unistd.h> 67 + #include <setjmp.h> 67 68 68 69 #include "kselftest.h" 69 70 ··· 184 183 struct __test_metadata *_metadata, \ 185 184 struct __fixture_variant_metadata *variant) \ 186 185 { \ 187 - test_name(_metadata); \ 186 + _metadata->setup_completed = true; \ 187 + if (setjmp(_metadata->env) == 0) \ 188 + test_name(_metadata); \ 189 + __test_check_assert(_metadata); \ 188 190 } \ 189 191 static struct __test_metadata _##test_name##_object = \ 190 192 { .name = #test_name, \ ··· 291 287 #define FIXTURE_TEARDOWN(fixture_name) \ 292 288 void fixture_name##_teardown( \ 293 289 struct __test_metadata __attribute__((unused)) *_metadata, \ 294 - FIXTURE_DATA(fixture_name) __attribute__((unused)) *self) 290 + FIXTURE_DATA(fixture_name) __attribute__((unused)) *self, \ 291 + const FIXTURE_VARIANT(fixture_name) \ 292 + __attribute__((unused)) *variant) 295 293 296 294 /** 297 295 * FIXTURE_VARIANT() - Optionally called once per fixture ··· 308 302 * ... 309 303 * }; 310 304 * 311 - * Defines type of constant parameters provided to FIXTURE_SETUP() and TEST_F() 312 - * as *variant*. Variants allow the same tests to be run with different 313 - * arguments. 305 + * Defines type of constant parameters provided to FIXTURE_SETUP(), TEST_F() and 306 + * FIXTURE_TEARDOWN as *variant*. Variants allow the same tests to be run with 307 + * different arguments. 314 308 */ 315 309 #define FIXTURE_VARIANT(fixture_name) struct _fixture_variant_##fixture_name 316 310 ··· 362 356 * Defines a test that depends on a fixture (e.g., is part of a test case). 363 357 * Very similar to TEST() except that *self* is the setup instance of fixture's 364 358 * datatype exposed for use by the implementation. 365 - * 366 - * Warning: use of ASSERT_* here will skip TEARDOWN. 367 359 */ 368 - /* TODO(wad) register fixtures on dedicated test lists. */ 369 360 #define TEST_F(fixture_name, test_name) \ 370 361 __TEST_F_IMPL(fixture_name, test_name, -1, TEST_TIMEOUT_DEFAULT) 371 362 ··· 384 381 /* fixture data is alloced, setup, and torn down per call. */ \ 385 382 FIXTURE_DATA(fixture_name) self; \ 386 383 memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \ 387 - fixture_name##_setup(_metadata, &self, variant->data); \ 388 - /* Let setup failure terminate early. */ \ 389 - if (!_metadata->passed) \ 390 - return; \ 391 - fixture_name##_##test_name(_metadata, &self, variant->data); \ 392 - fixture_name##_teardown(_metadata, &self); \ 384 + if (setjmp(_metadata->env) == 0) { \ 385 + fixture_name##_setup(_metadata, &self, variant->data); \ 386 + /* Let setup failure terminate early. */ \ 387 + if (!_metadata->passed) \ 388 + return; \ 389 + _metadata->setup_completed = true; \ 390 + fixture_name##_##test_name(_metadata, &self, variant->data); \ 391 + } \ 392 + if (_metadata->setup_completed) \ 393 + fixture_name##_teardown(_metadata, &self, variant->data); \ 394 + __test_check_assert(_metadata); \ 393 395 } \ 394 396 static struct __test_metadata \ 395 397 _##fixture_name##_##test_name##_object = { \ ··· 691 683 */ 692 684 #define OPTIONAL_HANDLER(_assert) \ 693 685 for (; _metadata->trigger; _metadata->trigger = \ 694 - __bail(_assert, _metadata->no_print, _metadata->step)) 686 + __bail(_assert, _metadata)) 695 687 696 688 #define __INC_STEP(_metadata) \ 697 689 /* Keep "step" below 255 (which is used for "SKIP" reporting). */ \ ··· 838 830 bool timed_out; /* did this test timeout instead of exiting? */ 839 831 __u8 step; 840 832 bool no_print; /* manual trigger when TH_LOG_STREAM is not available */ 833 + bool aborted; /* stopped test due to failed ASSERT */ 834 + bool setup_completed; /* did setup finish? */ 835 + jmp_buf env; /* for exiting out of test early */ 841 836 struct __test_results *results; 842 837 struct __test_metadata *prev, *next; 843 838 }; ··· 859 848 __LIST_APPEND(t->fixture->tests, t); 860 849 } 861 850 862 - static inline int __bail(int for_realz, bool no_print, __u8 step) 851 + static inline int __bail(int for_realz, struct __test_metadata *t) 863 852 { 853 + /* if this is ASSERT, return immediately. */ 864 854 if (for_realz) { 865 - if (no_print) 866 - _exit(step); 855 + t->aborted = true; 856 + longjmp(t->env, 1); 857 + } 858 + /* otherwise, end the for loop and continue. */ 859 + return 0; 860 + } 861 + 862 + static inline void __test_check_assert(struct __test_metadata *t) 863 + { 864 + if (t->aborted) { 865 + if (t->no_print) 866 + _exit(t->step); 867 867 abort(); 868 868 } 869 - return 0; 870 869 } 871 870 872 871 struct __test_metadata *__active_test;
+3 -3
tools/testing/selftests/pid_namespace/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 CFLAGS += -g -I../../../../usr/include/ 3 3 4 - TEST_GEN_PROGS := regression_enomem 4 + TEST_GEN_PROGS = regression_enomem 5 + 6 + LOCAL_HDRS += $(selfdir)/pidfd/pidfd.h 5 7 6 8 include ../lib.mk 7 - 8 - $(OUTPUT)/regression_enomem: regression_enomem.c ../pidfd/pidfd.h
-1
tools/testing/selftests/pidfd/pidfd_wait.c
··· 95 95 .flags = CLONE_PIDFD | CLONE_PARENT_SETTID, 96 96 .exit_signal = SIGCHLD, 97 97 }; 98 - int ret; 99 98 pid_t pid; 100 99 siginfo_t info = { 101 100 .si_signo = 0,
+4 -2
tools/testing/selftests/proc/proc-pid-vm.c
··· 46 46 #include <sys/time.h> 47 47 #include <sys/resource.h> 48 48 49 + #include "../kselftest.h" 50 + 49 51 static inline long sys_execveat(int dirfd, const char *pathname, char **argv, char **envp, int flags) 50 52 { 51 53 return syscall(SYS_execveat, dirfd, pathname, argv, envp, flags); ··· 370 368 }; 371 369 int i; 372 370 373 - for (i = 0; i < sizeof(S)/sizeof(S[0]); i++) { 371 + for (i = 0; i < ARRAY_SIZE(S); i++) { 374 372 assert(memmem(buf, rv, S[i], strlen(S[i]))); 375 373 } 376 374 ··· 419 417 }; 420 418 int i; 421 419 422 - for (i = 0; i < sizeof(S)/sizeof(S[0]); i++) { 420 + for (i = 0; i < ARRAY_SIZE(S); i++) { 423 421 assert(memmem(buf, rv, S[i], strlen(S[i]))); 424 422 } 425 423 }
+3 -6
tools/testing/selftests/vDSO/vdso_test_correctness.c
··· 20 20 #include <limits.h> 21 21 22 22 #include "vdso_config.h" 23 + #include "../kselftest.h" 23 24 24 25 static const char **name; 25 26 ··· 307 306 return; 308 307 } 309 308 310 - for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]); 311 - clock++) { 309 + for (int clock = 0; clock < ARRAY_SIZE(clocknames); clock++) 312 310 test_one_clock_gettime(clock, clocknames[clock]); 313 - } 314 311 315 312 /* Also test some invalid clock ids */ 316 313 test_one_clock_gettime(-1, "invalid"); ··· 369 370 return; 370 371 } 371 372 372 - for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]); 373 - clock++) { 373 + for (int clock = 0; clock < ARRAY_SIZE(clocknames); clock++) 374 374 test_one_clock_gettime64(clock, clocknames[clock]); 375 - } 376 375 377 376 /* Also test some invalid clock ids */ 378 377 test_one_clock_gettime64(-1, "invalid");
+4
tools/testing/selftests/x86/Makefile
··· 92 92 echo "If you are using a Fedora-like distribution, try:"; \ 93 93 echo ""; \ 94 94 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"; \ 95 99 exit 0; 96 100 endif 97 101