Skip to content

Commit e3565d1

Browse files
James Morsectmarinas
authored andcommitted
arm_mpam: Add kunit test for bitmap reset
The bitmap reset code has been a source of bugs. Add a unit test. This currently has to be built in, as the rest of the driver is builtin. Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: James Morse <james.morse@arm.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Ben Horgan <ben.horgan@arm.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Hanjun Guo <guohanjun@huawei.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 201d96c commit e3565d1

3 files changed

Lines changed: 82 additions & 0 deletions

File tree

drivers/resctrl/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ config ARM64_MPAM_DRIVER_DEBUG
1212
help
1313
Say yes here to enable debug messages from the MPAM driver.
1414

15+
config MPAM_KUNIT_TEST
16+
bool "KUnit tests for MPAM driver " if !KUNIT_ALL_TESTS
17+
depends on KUNIT=y
18+
default KUNIT_ALL_TESTS
19+
help
20+
Enable this option to run tests in the MPAM driver.
21+
22+
If unsure, say N.
23+
1524
endif

drivers/resctrl/mpam_devices.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,3 +2717,7 @@ static int __init mpam_msc_driver_init(void)
27172717

27182718
/* Must occur after arm64_mpam_register_cpus() from arch_initcall() */
27192719
subsys_initcall(mpam_msc_driver_init);
2720+
2721+
#ifdef CONFIG_MPAM_KUNIT_TEST
2722+
#include "test_mpam_devices.c"
2723+
#endif
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2025 Arm Ltd.
3+
/* This file is intended to be included into mpam_devices.c */
4+
5+
#include <kunit/test.h>
6+
7+
static void test_mpam_reset_msc_bitmap(struct kunit *test)
8+
{
9+
char __iomem *buf = kunit_kzalloc(test, SZ_16K, GFP_KERNEL);
10+
struct mpam_msc fake_msc = {};
11+
u32 *test_result;
12+
13+
if (!buf)
14+
return;
15+
16+
fake_msc.mapped_hwpage = buf;
17+
fake_msc.mapped_hwpage_sz = SZ_16K;
18+
cpumask_copy(&fake_msc.accessibility, cpu_possible_mask);
19+
20+
/* Satisfy lockdep checks */
21+
mutex_init(&fake_msc.part_sel_lock);
22+
mutex_lock(&fake_msc.part_sel_lock);
23+
24+
test_result = (u32 *)(buf + MPAMCFG_CPBM);
25+
26+
mpam_reset_msc_bitmap(&fake_msc, MPAMCFG_CPBM, 0);
27+
KUNIT_EXPECT_EQ(test, test_result[0], 0);
28+
KUNIT_EXPECT_EQ(test, test_result[1], 0);
29+
test_result[0] = 0;
30+
test_result[1] = 0;
31+
32+
mpam_reset_msc_bitmap(&fake_msc, MPAMCFG_CPBM, 1);
33+
KUNIT_EXPECT_EQ(test, test_result[0], 1);
34+
KUNIT_EXPECT_EQ(test, test_result[1], 0);
35+
test_result[0] = 0;
36+
test_result[1] = 0;
37+
38+
mpam_reset_msc_bitmap(&fake_msc, MPAMCFG_CPBM, 16);
39+
KUNIT_EXPECT_EQ(test, test_result[0], 0xffff);
40+
KUNIT_EXPECT_EQ(test, test_result[1], 0);
41+
test_result[0] = 0;
42+
test_result[1] = 0;
43+
44+
mpam_reset_msc_bitmap(&fake_msc, MPAMCFG_CPBM, 32);
45+
KUNIT_EXPECT_EQ(test, test_result[0], 0xffffffff);
46+
KUNIT_EXPECT_EQ(test, test_result[1], 0);
47+
test_result[0] = 0;
48+
test_result[1] = 0;
49+
50+
mpam_reset_msc_bitmap(&fake_msc, MPAMCFG_CPBM, 33);
51+
KUNIT_EXPECT_EQ(test, test_result[0], 0xffffffff);
52+
KUNIT_EXPECT_EQ(test, test_result[1], 1);
53+
test_result[0] = 0;
54+
test_result[1] = 0;
55+
56+
mutex_unlock(&fake_msc.part_sel_lock);
57+
}
58+
59+
static struct kunit_case mpam_devices_test_cases[] = {
60+
KUNIT_CASE(test_mpam_reset_msc_bitmap),
61+
{}
62+
};
63+
64+
static struct kunit_suite mpam_devices_test_suite = {
65+
.name = "mpam_devices_test_suite",
66+
.test_cases = mpam_devices_test_cases,
67+
};
68+
69+
kunit_test_suites(&mpam_devices_test_suite);

0 commit comments

Comments
 (0)