[PATCH 4/5] kunit: kfence: Make KFENCE_TEST_REQUIRES macro available for all kunit case

Feng Tang posted 5 patches 2 months, 3 weeks ago
There is a newer version of this series
[PATCH 4/5] kunit: kfence: Make KFENCE_TEST_REQUIRES macro available for all kunit case
Posted by Feng Tang 2 months, 3 weeks ago
KFENCE_TEST_REQUIRES macro is convenient for judging if a prerequisite of a
test case exists. Lift it into kunit/test.h so that all kunit test cases
can benefit from it.

Signed-off-by: Feng Tang <feng.tang@intel.com>
---
 include/kunit/test.h    | 6 ++++++
 mm/kfence/kfence_test.c | 9 ++-------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 5ac237c949a0..8a8027e10b89 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -643,6 +643,12 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
 	WRITE_ONCE(test->last_seen.line, __LINE__);			       \
 } while (0)
 
+#define KUNIT_TEST_REQUIRES(test, cond) do {			\
+	if (!(cond))						\
+		kunit_skip((test), "Test requires: " #cond);	\
+} while (0)
+
+
 /**
  * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
  * @test: The test context object.
diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c
index 00fd17285285..5dbb22c8c44f 100644
--- a/mm/kfence/kfence_test.c
+++ b/mm/kfence/kfence_test.c
@@ -32,11 +32,6 @@
 #define arch_kfence_test_address(addr) (addr)
 #endif
 
-#define KFENCE_TEST_REQUIRES(test, cond) do {			\
-	if (!(cond))						\
-		kunit_skip((test), "Test requires: " #cond);	\
-} while (0)
-
 /* Report as observed from console. */
 static struct {
 	spinlock_t lock;
@@ -561,7 +556,7 @@ static void test_init_on_free(struct kunit *test)
 	};
 	int i;
 
-	KFENCE_TEST_REQUIRES(test, IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON));
+	KUNIT_TEST_REQUIRES(test, IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON));
 	/* Assume it hasn't been disabled on command line. */
 
 	setup_test_cache(test, size, 0, NULL);
@@ -609,7 +604,7 @@ static void test_gfpzero(struct kunit *test)
 	int i;
 
 	/* Skip if we think it'd take too long. */
-	KFENCE_TEST_REQUIRES(test, kfence_sample_interval <= 100);
+	KUNIT_TEST_REQUIRES(test, kfence_sample_interval <= 100);
 
 	setup_test_cache(test, size, 0, NULL);
 	buf1 = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY);
-- 
2.34.1
Re: [PATCH 4/5] kunit: kfence: Make KFENCE_TEST_REQUIRES macro available for all kunit case
Posted by Vlastimil Babka 2 months, 3 weeks ago
On 9/9/24 03:29, Feng Tang wrote:
> KFENCE_TEST_REQUIRES macro is convenient for judging if a prerequisite of a
> test case exists. Lift it into kunit/test.h so that all kunit test cases
> can benefit from it.
> 
> Signed-off-by: Feng Tang <feng.tang@intel.com>

I think you should have Cc'd kunit and kfence maintainers on this one.
But if that's necessary depends on the review for patch 5...

> ---
>  include/kunit/test.h    | 6 ++++++
>  mm/kfence/kfence_test.c | 9 ++-------
>  2 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index 5ac237c949a0..8a8027e10b89 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -643,6 +643,12 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
>  	WRITE_ONCE(test->last_seen.line, __LINE__);			       \
>  } while (0)
>  
> +#define KUNIT_TEST_REQUIRES(test, cond) do {			\
> +	if (!(cond))						\
> +		kunit_skip((test), "Test requires: " #cond);	\
> +} while (0)
> +
> +
>  /**
>   * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
>   * @test: The test context object.
> diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c
> index 00fd17285285..5dbb22c8c44f 100644
> --- a/mm/kfence/kfence_test.c
> +++ b/mm/kfence/kfence_test.c
> @@ -32,11 +32,6 @@
>  #define arch_kfence_test_address(addr) (addr)
>  #endif
>  
> -#define KFENCE_TEST_REQUIRES(test, cond) do {			\
> -	if (!(cond))						\
> -		kunit_skip((test), "Test requires: " #cond);	\
> -} while (0)
> -
>  /* Report as observed from console. */
>  static struct {
>  	spinlock_t lock;
> @@ -561,7 +556,7 @@ static void test_init_on_free(struct kunit *test)
>  	};
>  	int i;
>  
> -	KFENCE_TEST_REQUIRES(test, IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON));
> +	KUNIT_TEST_REQUIRES(test, IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON));
>  	/* Assume it hasn't been disabled on command line. */
>  
>  	setup_test_cache(test, size, 0, NULL);
> @@ -609,7 +604,7 @@ static void test_gfpzero(struct kunit *test)
>  	int i;
>  
>  	/* Skip if we think it'd take too long. */
> -	KFENCE_TEST_REQUIRES(test, kfence_sample_interval <= 100);
> +	KUNIT_TEST_REQUIRES(test, kfence_sample_interval <= 100);
>  
>  	setup_test_cache(test, size, 0, NULL);
>  	buf1 = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY);
Re: [PATCH 4/5] kunit: kfence: Make KFENCE_TEST_REQUIRES macro available for all kunit case
Posted by Feng Tang 2 months, 3 weeks ago
On Tue, Sep 10, 2024 at 03:17:10PM +0200, Vlastimil Babka wrote:
> On 9/9/24 03:29, Feng Tang wrote:
> > KFENCE_TEST_REQUIRES macro is convenient for judging if a prerequisite of a
> > test case exists. Lift it into kunit/test.h so that all kunit test cases
> > can benefit from it.
> > 
> > Signed-off-by: Feng Tang <feng.tang@intel.com>
> 
> I think you should have Cc'd kunit and kfence maintainers on this one.
> But if that's necessary depends on the review for patch 5...

I added Marco Elver, Shuah Khan, David Gow and kasan-dev@googlegroups.com 
for kence and kunit review. That should be incomplete, will add more in
next verion. Thanks for the reminder!

- Feng

> 
> > ---
> >  include/kunit/test.h    | 6 ++++++
> >  mm/kfence/kfence_test.c | 9 ++-------
> >  2 files changed, 8 insertions(+), 7 deletions(-)
> > 
> > diff --git a/include/kunit/test.h b/include/kunit/test.h
> > index 5ac237c949a0..8a8027e10b89 100644
> > --- a/include/kunit/test.h
> > +++ b/include/kunit/test.h
> > @@ -643,6 +643,12 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
> >  	WRITE_ONCE(test->last_seen.line, __LINE__);			       \
> >  } while (0)
> >  
> > +#define KUNIT_TEST_REQUIRES(test, cond) do {			\
> > +	if (!(cond))						\
> > +		kunit_skip((test), "Test requires: " #cond);	\
> > +} while (0)
> > +
> > +
> >  /**
> >   * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
> >   * @test: The test context object.
> > diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c
> > index 00fd17285285..5dbb22c8c44f 100644
> > --- a/mm/kfence/kfence_test.c
> > +++ b/mm/kfence/kfence_test.c
> > @@ -32,11 +32,6 @@
> >  #define arch_kfence_test_address(addr) (addr)
> >  #endif
> >  
> > -#define KFENCE_TEST_REQUIRES(test, cond) do {			\
> > -	if (!(cond))						\
> > -		kunit_skip((test), "Test requires: " #cond);	\
> > -} while (0)
> > -
> >  /* Report as observed from console. */
> >  static struct {
> >  	spinlock_t lock;
> > @@ -561,7 +556,7 @@ static void test_init_on_free(struct kunit *test)
> >  	};
> >  	int i;
> >  
> > -	KFENCE_TEST_REQUIRES(test, IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON));
> > +	KUNIT_TEST_REQUIRES(test, IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON));
> >  	/* Assume it hasn't been disabled on command line. */
> >  
> >  	setup_test_cache(test, size, 0, NULL);
> > @@ -609,7 +604,7 @@ static void test_gfpzero(struct kunit *test)
> >  	int i;
> >  
> >  	/* Skip if we think it'd take too long. */
> > -	KFENCE_TEST_REQUIRES(test, kfence_sample_interval <= 100);
> > +	KUNIT_TEST_REQUIRES(test, kfence_sample_interval <= 100);
> >  
> >  	setup_test_cache(test, size, 0, NULL);
> >  	buf1 = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY);
>
Re: [PATCH 4/5] kunit: kfence: Make KFENCE_TEST_REQUIRES macro available for all kunit case
Posted by Marco Elver 2 months, 3 weeks ago
On Tue, 10 Sept 2024 at 16:14, Feng Tang <feng.tang@intel.com> wrote:
>
> On Tue, Sep 10, 2024 at 03:17:10PM +0200, Vlastimil Babka wrote:
> > On 9/9/24 03:29, Feng Tang wrote:
> > > KFENCE_TEST_REQUIRES macro is convenient for judging if a prerequisite of a
> > > test case exists. Lift it into kunit/test.h so that all kunit test cases
> > > can benefit from it.
> > >
> > > Signed-off-by: Feng Tang <feng.tang@intel.com>
> >
> > I think you should have Cc'd kunit and kfence maintainers on this one.
> > But if that's necessary depends on the review for patch 5...
>
> I added Marco Elver, Shuah Khan, David Gow and kasan-dev@googlegroups.com
> for kence and kunit review. That should be incomplete, will add more in
> next verion. Thanks for the reminder!

Reviewed-by: Marco Elver <elver@google.com>

Glad to see you found this macro generally useful. But do await KUnit
maintainer Ack as well.

Thanks,
-- Marco
Re: [PATCH 4/5] kunit: kfence: Make KFENCE_TEST_REQUIRES macro available for all kunit case
Posted by Alexander Potapenko 2 months, 3 weeks ago
On Tue, Sep 10, 2024 at 4:14 PM Feng Tang <feng.tang@intel.com> wrote:
>
> On Tue, Sep 10, 2024 at 03:17:10PM +0200, Vlastimil Babka wrote:
> > On 9/9/24 03:29, Feng Tang wrote:
> > > KFENCE_TEST_REQUIRES macro is convenient for judging if a prerequisite of a
> > > test case exists. Lift it into kunit/test.h so that all kunit test cases
> > > can benefit from it.
> > >
> > > Signed-off-by: Feng Tang <feng.tang@intel.com>
Reviewed-by: Alexander Potapenko <glider@google.com>

(assuming KUNIT maintainers are fine with the change)