Re: [PATCH 12/53] selftests/mm: khugepaged: group tests in an array

Donet Tom
2026-04-15T05:40:02Z

On 4/14/26 9:29 PM, Mike Rapoport wrote:
> Hi Donet,
>
> On Tue, Apr 14, 2026 at 12:32:48PM +0530, Donet Tom wrote:
>> Hi Mike
>>
>> On 4/6/26 7:46 PM, Mike Rapoport wrote:
>> get_finfo(argv[1]);
>> }
>>
>> +typedef void (*test_fn)(struct collapse_context *c, struct mem_ops *ops);
>> +
>> +struct test_case {
>> + struct collapse_context *ctx;
>> + struct mem_ops *ops;
>> + const char *desc;
>> + test_fn fn;
>> +};
>> +
>> +#define MAX_TEST_CASES 45
>>
>> I see 48 tests in khugepaged.c, and running khugepaged all:all results in the
>> error below. Should MAX_TEST_CASES be updated to 48 instead?
> I'm going to bump it to 64 to accommodate potential future tests.
>
>> ./khugepaged all:all .
>> TAP version 13
>> # Save THP and khugepaged settings... OK
>> Bail out! MAX_ADD_CASES is too small
>> # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
>> # Restore THP and khugepaged settings... OK
>> # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
>>
>>
>> +static struct test_case test_cases[MAX_TEST_CASES];
>> +static int nr_test_cases;
>> +
>> +#define TEST(t, c, o) do { \
>> + if (c && o) { \
>> + if (nr_test_cases >= MAX_TEST_CASES) { \
>>
>>
>> I had a small question—since the number of tests is fixed, would this check
>> still be necessary?
>
> If we add too much tests without updating the maximum we get a nice "Bail
> out" rather than SIGSEGV :)

Thanks for the clarification. It’s good to include this change.

>
>> + printf("MAX_ADD_CASES is too small\n"); \
>> + exit(EXIT_FAILURE); \
>> + } \
>> + test_cases[nr_test_cases++] = (struct test_case){ \
>> + .ctx = c, \
>> + .ops = o, \
>> + .desc = #t, \
>> + .fn = t, \
>> + }; \
>> + } \
>> + } while (0)
>> +
>> int main(int argc, char **argv)
>> {
>> int hpage_pmd_order;
>> @@ -1216,13 +1244,6 @@ int main(int argc, char **argv)
>>
>> alloc_at_fault();
>>
>> -#define TEST(t, c, o) do { \
>> - if (c && o) { \
>> - printf("\nRun test: " #t " (%s:%s)\n", c->name, o->name); \
>> - t(c, o); \
>> - } \
>> - } while (0)
>> -
>> TEST(collapse_full, khugepaged_context, anon_ops);
>> TEST(collapse_full, khugepaged_context, file_ops);
>> TEST(collapse_full, khugepaged_context, shmem_ops);
>> @@ -1284,5 +1305,13 @@ int main(int argc, char **argv)
>> TEST(madvise_retracted_page_tables, madvise_context, file_ops);
>> TEST(madvise_retracted_page_tables, madvise_context, shmem_ops);
>>
>> + for (int i = 0; i < nr_test_cases; i++) {
>> + struct test_case *t = &test_cases[i];
>> +
>> + exit_status = KSFT_PASS;
>> + printf("\nRun test: %s: (%s:%s)\n", t->desc, t->ctx->name, t->ops->name);
>> + t->fn(t->ctx, t->ops);
>> + }
>> +
>> restore_settings(0);
>> }
>>
>>
>> -Donet
>>