Re: [PATCH v3 25/47] arm_mpam: resctrl: Add kunit test for rmid idx conversions

Jonathan Cameron
2026-01-13T15:00:01Z

On Mon, 12 Jan 2026 16:58:52 +0000
Ben Horgan <ben.horgan@arm.com> wrote:

> As MPAM's pmg are scoped by partid and RDT's rmid are global the
> rescrl mapping to an index needs to differ.
>
> Add some tests for the MPAM rmid mapping.
>
> Signed-off-by: Ben Horgan <ben.horgan@arm.com>
I'm not sure this particular test brings a massive amount of value, but
I'm not one to object to more tests!

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>

> ---
> drivers/resctrl/test_mpam_resctrl.c | 49 +++++++++++++++++++++++++++++
> 1 file changed, 49 insertions(+)
>
> diff --git a/drivers/resctrl/test_mpam_resctrl.c b/drivers/resctrl/test_mpam_resctrl.c
> index b93d6ad87e43..a20da161d965 100644
> --- a/drivers/resctrl/test_mpam_resctrl.c
> +++ b/drivers/resctrl/test_mpam_resctrl.c
> @@ -296,6 +296,54 @@ static void test_percent_to_max_rounding(struct kunit *test)
> KUNIT_EXPECT_LE(test, 4 * num_rounded_up, 3 * total);
> }
>
> +struct rmid_idx_case {
> + u32 max_partid;
> + u32 max_pmg;
> +};
> +
> +static const struct rmid_idx_case rmid_idx_cases[] = {
> + {0, 0}, {1, 4}, {3, 1}, {5, 9}, {4, 4}, {100, 11}, {0xFFFF, 0xFF},
> +};
> +
> +static void test_rmid_idx_desc(const struct rmid_idx_case *param, char *desc)
> +{
> + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "max_partid=%d, max_pmg=%d\n",
> + param->max_partid, param->max_pmg);
> +}
> +
> +KUNIT_ARRAY_PARAM(test_rmid_idx, rmid_idx_cases, test_rmid_idx_desc);
> +
> +static void test_rmid_idx_encoding(struct kunit *test)
> +{
> + u32 orig_mpam_partid_max = mpam_partid_max;
> + u32 orig_mpam_pmg_max = mpam_pmg_max;
> + const struct rmid_idx_case *param = test->param_value;
> + u32 idx, num_idx, count = 0;
> +
> + mpam_partid_max = param->max_partid;
> + mpam_pmg_max = param->max_pmg;
> +
> + for (u32 partid = 0; partid <= mpam_partid_max; partid++) {
> + for (u32 pmg = 0; pmg <= mpam_pmg_max; pmg++) {
> + u32 partid_out, pmg_out;
> +
> + idx = resctrl_arch_rmid_idx_encode(partid, pmg);
> + /* Confirm there are no holes in the rmid idx range */
> + KUNIT_EXPECT_EQ(test, count, idx);
> + count++;
> + resctrl_arch_rmid_idx_decode(idx, &partid_out, &pmg_out);
> + KUNIT_EXPECT_EQ(test, pmg, pmg_out);
> + KUNIT_EXPECT_EQ(test, partid, partid_out);
> + }
> + }
> + num_idx = resctrl_arch_system_num_rmid_idx();
> + KUNIT_EXPECT_EQ(test, idx + 1, num_idx);
> +
> + /* Restore global variables that were messed with */
> + mpam_partid_max = orig_mpam_partid_max;
> + mpam_pmg_max = orig_mpam_pmg_max;
> +}