linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: Uriel Guajardo <urielguajardojr@gmail.com>, brendanhiggins@google.com
Cc: urielguajardo@google.com, akpm@linux-foundation.org,
	keescook@chromium.org, rdunlap@infradead.org,
	herbert@gondor.apana.org.au, christian.brauner@ubuntu.com,
	peterz@infradead.org, ardb@kernel.og, arnd@arndb.de,
	julien.grall@arm.com, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH 1/2] kunit: support failure from dynamic analysis tools
Date: Mon, 31 Aug 2020 15:29:13 -0600	[thread overview]
Message-ID: <ae0e6555-5c10-4133-a975-3c28dca01d2f@linuxfoundation.org> (raw)
In-Reply-To: <20200813205722.1384108-1-urielguajardojr@gmail.com>

On 8/13/20 2:57 PM, Uriel Guajardo wrote:
> Adds an API to allow dynamic analysis tools to fail the currently
> running KUnit test case.
> 
> - Always places the kunit test in the task_struct to allow other tools
> to access the currently running KUnit test.
> 
> - Creates a new header file to avoid circular dependencies that could be
> created from the test.h file.
> 
> Requires KASAN-KUnit integration patch to access the kunit test from
> task_struct:
> https://lore.kernel.org/linux-kselftest/20200606040349.246780-2-davidgow@google.com/
> 
> Signed-off-by: Uriel Guajardo <urielguajardo@google.com>
> ---
>   include/kunit/test-bug.h | 24 ++++++++++++++++++++++++
>   include/kunit/test.h     |  1 +
>   lib/kunit/test.c         | 10 ++++++----
>   3 files changed, 31 insertions(+), 4 deletions(-)
>   create mode 100644 include/kunit/test-bug.h
> 
> diff --git a/include/kunit/test-bug.h b/include/kunit/test-bug.h
> new file mode 100644
> index 000000000000..283c19ec328f
> --- /dev/null
> +++ b/include/kunit/test-bug.h
> @@ -0,0 +1,24 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * KUnit API allowing dynamic analysis tools to interact with KUnit tests
> + *
> + * Copyright (C) 2020, Google LLC.
> + * Author: Uriel Guajardo <urielguajardo@google.com>
> + */
> +
> +#ifndef _KUNIT_TEST_BUG_H
> +#define _KUNIT_TEST_BUG_H
> +
> +#if IS_ENABLED(CONFIG_KUNIT)
> +
> +extern void kunit_fail_current_test(void);
> +
> +#else
> +
> +static inline void kunit_fail_current_test(void)
> +{
> +}
> +
> +#endif
> +
> +#endif /* _KUNIT_TEST_BUG_H */
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index 3391f38389f8..81bf43a1abda 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -11,6 +11,7 @@
>   
>   #include <kunit/assert.h>
>   #include <kunit/try-catch.h>
> +#include <kunit/test-bug.h>
>   #include <linux/kernel.h>
>   #include <linux/module.h>
>   #include <linux/slab.h>
> diff --git a/lib/kunit/test.c b/lib/kunit/test.c
> index dcc35fd30d95..d8189d827368 100644
> --- a/lib/kunit/test.c
> +++ b/lib/kunit/test.c
> @@ -16,6 +16,12 @@
>   #include "string-stream.h"
>   #include "try-catch-impl.h"
>   
> +void kunit_fail_current_test(void)
> +{
> +	if (current->kunit_test)
> +		kunit_set_failure(current->kunit_test);
> +}
> +
>   static void kunit_print_tap_version(void)
>   {
>   	static bool kunit_has_printed_tap_version;
> @@ -284,9 +290,7 @@ static void kunit_try_run_case(void *data)
>   	struct kunit_suite *suite = ctx->suite;
>   	struct kunit_case *test_case = ctx->test_case;
>   
> -#if (IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT))
>   	current->kunit_test = test;
> -#endif /* IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT) */
>   
>   	/*
>   	 * kunit_run_case_internal may encounter a fatal error; if it does,
> @@ -602,9 +606,7 @@ void kunit_cleanup(struct kunit *test)
>   		spin_unlock(&test->lock);
>   		kunit_remove_resource(test, res);
>   	}
> -#if (IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT))
>   	current->kunit_test = NULL;
> -#endif /* IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT)*/
>   }
>   EXPORT_SYMBOL_GPL(kunit_cleanup);
>   
> 

Is this patch still needed. Doesn't apply on top of Linux 5.9. From
q quick review, doesn't looks like it is needed. Not seeing any
CONFIG_KASAN's in lib/kunit/test.c

Here is the .rej

--- lib/kunit/test.c
+++ lib/kunit/test.c
@@ -290,9 +296,7 @@ static void kunit_try_run_case(void *data)
         struct kunit_suite *suite = ctx->suite;
         struct kunit_case *test_case = ctx->test_case;

-#if (IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT))
         current->kunit_test = test;
-#endif /* IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT) */

         /*
          * kunit_run_case_internal may encounter a fatal error; if it does,
@@ -608,9 +612,7 @@ void kunit_cleanup(struct kunit *test)
                 spin_unlock(&test->lock);
                 kunit_remove_resource(test, res);
         }
-#if (IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT))
         current->kunit_test = NULL;
-#endif /* IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT)*/
  }
  EXPORT_SYMBOL_GPL(kunit_cleanup);

If this is still needed, please send me rebased patch.

thanks,
-- Shuah


  parent reply	other threads:[~2020-08-31 21:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-13 20:57 [PATCH 1/2] kunit: support failure from dynamic analysis tools Uriel Guajardo
2020-08-13 20:57 ` [PATCH 2/2] kunit: ubsan integration Uriel Guajardo
2020-08-31 21:29   ` Shuah Khan
2020-08-31 21:29 ` Shuah Khan [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-08-06 17:43 [PATCH 1/2] kunit: support failure from dynamic analysis tools Uriel Guajardo
2020-08-07 14:15 ` Alan Maguire
2020-08-07 22:40   ` Uriel Guajardo
2020-08-10 20:37 ` Brendan Higgins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ae0e6555-5c10-4133-a975-3c28dca01d2f@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.og \
    --cc=arnd@arndb.de \
    --cc=brendanhiggins@google.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=julien.grall@arm.com \
    --cc=keescook@chromium.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=urielguajardo@google.com \
    --cc=urielguajardojr@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).