|
67 | 67 | #include <sys/types.h>
|
68 | 68 | #include <sys/wait.h>
|
69 | 69 | #include <unistd.h>
|
70 |
| -#include <setjmp.h> |
71 | 70 |
|
72 | 71 | #include "kselftest.h"
|
73 | 72 |
|
|
178 | 177 | struct __test_metadata *_metadata, \
|
179 | 178 | struct __fixture_variant_metadata __attribute__((unused)) *variant) \
|
180 | 179 | { \
|
181 |
| - if (setjmp(_metadata->env) == 0) \ |
182 |
| - test_name(_metadata); \ |
183 |
| - __test_check_assert(_metadata); \ |
| 180 | + test_name(_metadata); \ |
184 | 181 | } \
|
185 | 182 | static struct __test_metadata _##test_name##_object = \
|
186 | 183 | { .name = #test_name, \
|
|
425 | 422 | } \
|
426 | 423 | _metadata->variant = variant->data; \
|
427 | 424 | _metadata->self = self; \
|
428 |
| - if (setjmp(_metadata->env) == 0) { \ |
429 |
| - /* _metadata and potentially self are shared with all forks. */ \ |
430 |
| - child = fork(); \ |
431 |
| - if (child == 0) { \ |
432 |
| - fixture_name##_setup(_metadata, self, variant->data); \ |
433 |
| - /* Let setup failure terminate early. */ \ |
434 |
| - if (_metadata->exit_code) \ |
435 |
| - _exit(0); \ |
436 |
| - *_metadata->no_teardown = false; \ |
437 |
| - fixture_name##_##test_name(_metadata, self, variant->data); \ |
438 |
| - } else if (child < 0 || child != waitpid(child, &status, 0)) { \ |
439 |
| - ksft_print_msg("ERROR SPAWNING TEST GRANDCHILD\n"); \ |
440 |
| - _metadata->exit_code = KSFT_FAIL; \ |
441 |
| - } \ |
442 |
| - } \ |
| 425 | + /* _metadata and potentially self are shared with all forks. */ \ |
| 426 | + child = fork(); \ |
443 | 427 | if (child == 0) { \
|
| 428 | + fixture_name##_setup(_metadata, self, variant->data); \ |
| 429 | + /* Let setup failure terminate early. */ \ |
| 430 | + if (_metadata->exit_code) \ |
| 431 | + _exit(0); \ |
| 432 | + *_metadata->no_teardown = false; \ |
| 433 | + fixture_name##_##test_name(_metadata, self, variant->data); \ |
444 | 434 | _metadata->teardown_fn(false, _metadata, self, variant->data); \
|
445 | 435 | _exit(0); \
|
| 436 | + } else if (child < 0 || child != waitpid(child, &status, 0)) { \ |
| 437 | + ksft_print_msg("ERROR SPAWNING TEST GRANDCHILD\n"); \ |
| 438 | + _metadata->exit_code = KSFT_FAIL; \ |
446 | 439 | } \
|
447 | 440 | _metadata->teardown_fn(true, _metadata, self, variant->data); \
|
448 | 441 | munmap(_metadata->no_teardown, sizeof(*_metadata->no_teardown)); \
|
|
456 | 449 | /* Forward signal to __wait_for_test(). */ \
|
457 | 450 | kill(getpid(), WTERMSIG(status)); \
|
458 | 451 | } \
|
459 |
| - __test_check_assert(_metadata); \ |
460 | 452 | } \
|
461 | 453 | static void wrapper_##fixture_name##_##test_name##_teardown( \
|
462 | 454 | bool in_parent, struct __test_metadata *_metadata, \
|
@@ -927,7 +919,6 @@ struct __test_metadata {
|
927 | 919 | int timeout; /* seconds to wait for test timeout */
|
928 | 920 | bool aborted; /* stopped test due to failed ASSERT */
|
929 | 921 | bool *no_teardown; /* fixture needs teardown */
|
930 |
| - jmp_buf env; /* for exiting out of test early */ |
931 | 922 | void *self;
|
932 | 923 | const void *variant;
|
933 | 924 | struct __test_results *results;
|
@@ -963,19 +954,14 @@ static inline int __bail(int for_realz, struct __test_metadata *t)
|
963 | 954 | {
|
964 | 955 | /* if this is ASSERT, return immediately. */
|
965 | 956 | if (for_realz) {
|
966 |
| - t->aborted = true; |
967 |
| - longjmp(t->env, 1); |
| 957 | + if (t->teardown_fn) |
| 958 | + t->teardown_fn(false, t, t->self, t->variant); |
| 959 | + abort(); |
968 | 960 | }
|
969 | 961 | /* otherwise, end the for loop and continue. */
|
970 | 962 | return 0;
|
971 | 963 | }
|
972 | 964 |
|
973 |
| -static inline void __test_check_assert(struct __test_metadata *t) |
974 |
| -{ |
975 |
| - if (t->aborted) |
976 |
| - abort(); |
977 |
| -} |
978 |
| - |
979 | 965 | static void __wait_for_test(struct __test_metadata *t)
|
980 | 966 | {
|
981 | 967 | /*
|
@@ -1208,7 +1194,6 @@ static void __run_test(struct __fixture_metadata *f,
|
1208 | 1194 | t->trigger = 0;
|
1209 | 1195 | t->aborted = false;
|
1210 | 1196 | t->no_teardown = NULL;
|
1211 |
| - memset(t->env, 0, sizeof(t->env)); |
1212 | 1197 | memset(t->results->reason, 0, sizeof(t->results->reason));
|
1213 | 1198 |
|
1214 | 1199 | snprintf(test_name, sizeof(test_name), "%s%s%s.%s",
|
|
0 commit comments