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