diff options
author | Dominik Karol Piatkowski <dominik.karol.piatkowski@intel.com> | 2023-06-14 12:58:06 +0200 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@kernel.org> | 2023-06-14 15:16:45 +0200 |
commit | c5ca214cacf8a779c7e5ea083d3f18accc442e9a (patch) | |
tree | eefd0baa7a44da03cdc5209cb328c6f317b95429 /lib/igt_kmod.c | |
parent | 980bbff965831a29386c66f33dde643523bc6937 (diff) |
Change logic of ktap parser to run on a thread
The ktap parser should be listening and parsing messages as the tests
are executed, and not after the end of module load.
v1 -> v2:
- fix coding style
- remove usleep
- add error check logic
- follow the structure of igt_kselftests more closely
v2 -> v3:
- fixed sublevel issues by rewriting tap parser flow
v3 -> v4:
- fixed delimiter
- squashed lib/igt_kmod: fix nesting igt_fixture in igt_subtest
Fix the following issue:
$ ./build/tests/drm_buddy
Starting subtest: all-tests
nesting igt_fixture in igt_subtest is invalid
please refer to lib/igt_core documentation
- squashed lib/igt_kmod: place KUnit tests on a subtest
There's a hidden bug at KUnit implementation: as it doesn't
place tests inside a subtest, trying to use it with igt_main
causes a crash:
$ ./build/tests/drm_mm --list
skipping is allowed only in fixtures, subtests or igt_simple_main
please refer to lib/igt_core documentation
drm_mm: ../lib/igt_core.c:437: internal_assert: Assertion `0' failed.
Received signal SIGABRT.
Stack trace:
#0 [fatal_sig_handler+0x17b]
#1 [__sigaction+0x50]
#2 [__pthread_kill_implementation+0x114]
#3 [gsignal+0x1e]
#4 [abort+0xdf]
#5 [__assert_fail_base.cold+0xe]
#6 [__assert_fail+0x47]
#7 [internal_assert+0xe5]
#8 [igt_skip+0x169]
#9 [__igt_skip_check+0x1bb]
#10 [igt_ktest_begin+0xa6]
#11 [igt_kunit+0x70]
#12 [main+0x2a]
#13 [__libc_start_call_main+0x7a]
#14 [__libc_start_main+0x8b]
#15 [_start+0x25]
Fix it by using igt_subtests() before actually implememnting
KUnit logic.
After the patch, it should now report subtests:
$ ./build/tests/drm_mm --list
all-tests
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Dominik Karol PiÄ…tkowski <dominik.karol.piatkowski@intel.com>
Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Diffstat (limited to 'lib/igt_kmod.c')
-rw-r--r-- | lib/igt_kmod.c | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 21e801bde..73478f75e 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -754,14 +754,15 @@ void igt_kselftest_get_tests(struct kmod_module *kmod, * * Returns: IGT default codes */ -int igt_kunit(const char *module_name, const char *opts) +static int __igt_kunit(const char *module_name, const char *opts) { struct igt_ktest tst; struct kmod_module *kunit_kmod; - char record[BUF_LEN + 1]; FILE *f; bool is_builtin; int ret; + struct ktap_test_results *results; + struct ktap_test_results_element *temp; ret = IGT_EXIT_INVALID; @@ -804,25 +805,63 @@ int igt_kunit(const char *module_name, const char *opts) is_builtin = kmod_module_get_initstate(kunit_kmod) == KMOD_MODULE_BUILTIN; + results = ktap_parser_start(f, is_builtin); + if (igt_kmod_load(module_name, opts) != 0) { igt_warn("Unable to load %s module\n", module_name); + ret = ktap_parser_stop(); igt_fail(IGT_EXIT_FAILURE); } - ret = igt_ktap_parser(f, record, is_builtin); - if (ret != 0) - ret = IGT_EXIT_ABORT; + while (READ_ONCE(results->still_running) || READ_ONCE(results->head) != NULL) + { + if (READ_ONCE(results->head) != NULL) { + pthread_mutex_lock(&results->mutex); + + igt_dynamic(results->head->test_name) { + if (READ_ONCE(results->head->passed)) + igt_success(); + else + igt_fail(IGT_EXIT_FAILURE); + } + + temp = results->head; + results->head = results->head->next; + free(temp); + + pthread_mutex_unlock(&results->mutex); + } + } + unload: igt_ktest_end(&tst); igt_ktest_fini(&tst); + ret = ktap_parser_stop(); + + if (ret != 0) + ret = IGT_EXIT_ABORT; + if (ret == 0) igt_success(); - return ret; } +int igt_kunit(const char *module_name, const char *opts) +{ + /* + * We need to use igt_subtest here, as otherwise it may crash with: + * skipping is allowed only in fixtures, subtests or igt_simple_main + * if used on igt_main. This is also needed in order to provide + * proper namespace for dynamic subtests, with is required for CI + * and for documentation. + */ + igt_subtest_with_dynamic("all-tests") + return __igt_kunit(module_name, opts); + return 0; +} + static int open_parameters(const char *module_name) { char path[256]; |