diff mbox series

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

Message ID 20240909012958.913438-5-feng.tang@intel.com (mailing list archive)
State New
Headers show
Series mm/slub: Improve data handling of krealloc() when orig_size is enabled | expand

Commit Message

Feng Tang Sept. 9, 2024, 1:29 a.m. UTC
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(-)

Comments

Vlastimil Babka Sept. 10, 2024, 1:17 p.m. UTC | #1
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);
Feng Tang Sept. 10, 2024, 2:14 p.m. UTC | #2
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);
>
Alexander Potapenko Sept. 10, 2024, 2:19 p.m. UTC | #3
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)
Marco Elver Sept. 10, 2024, 4:04 p.m. UTC | #4
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
diff mbox series

Patch

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);