kunit: Handle thread creation error
authorMickaël Salaün <mic@digikod.net>
Mon, 8 Apr 2024 07:46:19 +0000 (09:46 +0200)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 6 May 2024 20:22:02 +0000 (14:22 -0600)
Previously, if a thread creation failed (e.g. -ENOMEM), the function was
called (kunit_catch_run_case or kunit_catch_run_case_cleanup) without
marking the test as failed.  Instead, fill try_result with the error
code returned by kthread_run(), which will mark the test as failed and
print "internal error occurred...".

Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Link: https://lore.kernel.org/r/20240408074625.65017-2-mic@digikod.net
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/kunit/try-catch.c

index f7825991d576ab309267070b4f928c1116449c69..a5cb2ef70a258a998dcb15ad949f3be6756d8c55 100644 (file)
@@ -69,6 +69,7 @@ void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context)
                                  try_catch,
                                  "kunit_try_catch_thread");
        if (IS_ERR(task_struct)) {
+               try_catch->try_result = PTR_ERR(task_struct);
                try_catch->catch(try_catch->context);
                return;
        }