[igt-dev] [PATCH i-g-t v2 3/4] lib/kselftests: Skip kselftest when opening kmsg fails
Petri Latvala
petri.latvala at intel.com
Mon Aug 15 09:40:37 UTC 2022
On Fri, Aug 12, 2022 at 01:18:25PM -0300, Tales Aparecida wrote:
> Check for errors in igt_kselftest_begin() during open("/dev/kmsg")
> and fail appropriately, removing the always-zero return of the function.
>
> Signed-off-by: Tales Aparecida <tales.aparecida at gmail.com>
> ---
>
> Notes:
> v1 -> v2: Removed return from igt_kselftest_begin and added assertion instead
>
> lib/igt_kmod.c | 7 +++----
> lib/igt_kmod.h | 2 +-
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
> index bde0461a..6356a3e9 100644
> --- a/lib/igt_kmod.c
> +++ b/lib/igt_kmod.c
> @@ -922,7 +922,7 @@ int igt_kselftest_init(struct igt_kselftest *tst,
> return 0;
> }
>
> -int igt_kselftest_begin(struct igt_kselftest *tst)
> +void igt_kselftest_begin(struct igt_kselftest *tst)
> {
> int err;
>
> @@ -933,8 +933,7 @@ int igt_kselftest_begin(struct igt_kselftest *tst)
> igt_require(err == 0 || err == -ENOENT);
>
> tst->kmsg = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
> -
> - return 0;
> + igt_assert_fd(tst->kmsg);
Asserting on the open failure leaves the test result as 'FAIL',
indicating a kernel bug. Opening failure rather means there's an
incorrect setup and the test cannot be executed, meaning the correct
result would be 'SKIP'.
In other words, make this an igt_require_fd instead.
--
Petri Latvala
> }
>
> int igt_kselftest_execute(struct igt_kselftest *tst,
> @@ -1012,7 +1011,7 @@ void igt_kselftests(const char *module_name,
> return;
>
> igt_fixture
> - igt_require(igt_kselftest_begin(&tst) == 0);
> + igt_kselftest_begin(&tst);
>
> igt_kselftest_get_tests(tst.kmod, filter, &tests);
> igt_subtest_with_dynamic(filter ?: "all") {
> diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
> index f98dd29f..0d80451b 100644
> --- a/lib/igt_kmod.h
> +++ b/lib/igt_kmod.h
> @@ -65,7 +65,7 @@ struct igt_kselftest_list {
>
> int igt_kselftest_init(struct igt_kselftest *tst,
> const char *module_name);
> -int igt_kselftest_begin(struct igt_kselftest *tst);
> +void igt_kselftest_begin(struct igt_kselftest *tst);
>
> void igt_kselftest_get_tests(struct kmod_module *kmod,
> const char *filter,
> --
> 2.37.1
>
More information about the igt-dev
mailing list