Re: [RFC PATCH v4 2/2] sysctl: convert kernel/sysctl-test.c to use CTLTBL_ENTRY_XXX()

From: Joel Granados

Date: Thu Mar 19 2026 - 10:25:19 EST


On Wed, Mar 18, 2026 at 01:36:15AM +0800, wen.yang@xxxxxxxxx wrote:
> From: Wen Yang <wen.yang@xxxxxxxxx>
>
> Convert all struct ctl_table initializations in kernel/sysctl-test.c
> from direct field assignment to indirect initialization via the
> CTLTBL_ENTRY_XXX() macros introduced in the previous patch. This
> demonstrates the macros in real usage and validates their correctness
> against the existing test suite.
>
> The following macro variants are exercised:

...

> + * auto-selected handler (proc_dointvec for int).
> + */
> +static void sysctl_test_api_ctltbl_entry_vnm(struct kunit *test)
> +{
> + int data = 0;
> + struct ctl_table table = CTLTBL_ENTRY_VNM(data, "foo", 0644);
> +
> + KUNIT_EXPECT_STREQ(test, "foo", table.procname);
> + KUNIT_EXPECT_EQ(test, (umode_t)0644, table.mode);
> + KUNIT_EXPECT_PTR_EQ(test, &data, table.data);
> + KUNIT_EXPECT_EQ(test, sizeof(int), table.maxlen);
> + KUNIT_EXPECT_PTR_EQ(test, (proc_handler *)proc_dointvec,
> + table.proc_handler);
> +}
> +
> +/*
> + * Test CTLTBL_ENTRY_VNMH: custom procname, mode and explicit handler.
> + */
> +static void sysctl_test_api_ctltbl_entry_vnmh(struct kunit *test)
> +{
> + int data = 0;
> + struct ctl_table table = CTLTBL_ENTRY_VNMH(data, "foo", 0644,
> + proc_dointvec);
> +
> + KUNIT_EXPECT_STREQ(test, "foo", table.procname);
> + KUNIT_EXPECT_EQ(test, (umode_t)0644, table.mode);
> + KUNIT_EXPECT_PTR_EQ(test, &data, table.data);
> + KUNIT_EXPECT_EQ(test, sizeof(int), table.maxlen);
> + KUNIT_EXPECT_PTR_EQ(test, (proc_handler *)proc_dointvec,
> + table.proc_handler);
> +}
> +

Have you checked if this approach supports u8, bool and char (string).
I see that in all your tests you use an integer as data; Does it make
sense to add a u8, bool and char test case to the list?

> static struct kunit_case sysctl_test_cases[] = {
> KUNIT_CASE(sysctl_test_api_dointvec_null_tbl_data),
> KUNIT_CASE(sysctl_test_api_dointvec_table_maxlen_unset),
> @@ -378,6 +414,12 @@ static struct kunit_case sysctl_test_cases[] = {
> KUNIT_CASE(sysctl_test_dointvec_write_happy_single_negative),
> KUNIT_CASE(sysctl_test_api_dointvec_write_single_less_int_min),
> KUNIT_CASE(sysctl_test_api_dointvec_write_single_greater_int_max),
> + KUNIT_CASE(sysctl_test_api_ctltbl_entry_v),
> + KUNIT_CASE(sysctl_test_api_ctltbl_entry_vm),
> + KUNIT_CASE(sysctl_test_api_ctltbl_entry_vmr),
> + KUNIT_CASE(sysctl_test_api_ctltbl_entry_vn),
> + KUNIT_CASE(sysctl_test_api_ctltbl_entry_vnm),
> + KUNIT_CASE(sysctl_test_api_ctltbl_entry_vnmh),
> {}
> };
>
> --
> 2.25.1
>

--

Joel Granados

Attachment: signature.asc
Description: PGP signature