Skip to content

Commit b9707d4

Browse files
debox1ij-intel
authored andcommitted
platform/x86/intel/pmt: KUNIT test for PMT Enhanced Discovery API
Adds a KUNIT test for the intel_pmt_get_regions_by_feature() API. Signed-off-by: David E. Box <david.e.box@linux.intel.com> Link: https://lore.kernel.org/r/20250703022832.1302928-16-david.e.box@linux.intel.com Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 42dabe5 commit b9707d4

3 files changed

Lines changed: 132 additions & 0 deletions

File tree

drivers/platform/x86/intel/pmt/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,17 @@ config INTEL_PMT_DISCOVERY
5151

5252
To compile this driver as a module, choose M here: the module
5353
will be called pmt_discovery.
54+
55+
config INTEL_PMT_KUNIT_TEST
56+
tristate "KUnit tests for Intel PMT driver"
57+
depends on INTEL_PMT_DISCOVERY
58+
depends on KUNIT
59+
help
60+
Enable this option to compile and run a suite of KUnit tests for the Intel
61+
Platform Monitoring Technology (PMT) driver. These tests are designed to
62+
validate the driver's functionality, error handling, and overall stability,
63+
helping developers catch regressions and ensure code quality during changes.
64+
65+
This option is intended for development and testing environments. It is
66+
recommended to disable it in production builds. To compile this driver as a
67+
module, choose M here: the module will be called pmt-discovery-kunit.

drivers/platform/x86/intel/pmt/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ obj-$(CONFIG_INTEL_PMT_CRASHLOG) += pmt_crashlog.o
1212
pmt_crashlog-y := crashlog.o
1313
obj-$(CONFIG_INTEL_PMT_DISCOVERY) += pmt_discovery.o
1414
pmt_discovery-y := discovery.o features.o
15+
obj-$(CONFIG_INTEL_PMT_KUNIT_TEST) += pmt-discovery-kunit.o
16+
pmt-discovery-kunit-y := discovery-kunit.o
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Intel Platform Monitory Technology Discovery KUNIT tests
4+
*
5+
* Copyright (c) 2025, Intel Corporation.
6+
* All Rights Reserved.
7+
*/
8+
9+
#include <kunit/test.h>
10+
#include <linux/err.h>
11+
#include <linux/intel_pmt_features.h>
12+
#include <linux/intel_vsec.h>
13+
#include <linux/module.h>
14+
#include <linux/slab.h>
15+
16+
#define PMT_FEATURE_COUNT (FEATURE_MAX + 1)
17+
18+
static void
19+
validate_pmt_regions(struct kunit *test, struct pmt_feature_group *feature_group, int feature_id)
20+
{
21+
int i;
22+
23+
kunit_info(test, "Feature ID %d [%s] has %d regions.\n", feature_id,
24+
pmt_feature_names[feature_id], feature_group->count);
25+
26+
for (i = 0; i < feature_group->count; i++) {
27+
struct telemetry_region *region = &feature_group->regions[i];
28+
29+
kunit_info(test, " - Region %d: cdie_mask=%u, package_id=%u, partition=%u, segment=%u,",
30+
i, region->plat_info.cdie_mask, region->plat_info.package_id,
31+
region->plat_info.partition, region->plat_info.segment);
32+
kunit_info(test, "\t\tbus=%u, device=%u, function=%u, guid=0x%x,",
33+
region->plat_info.bus_number, region->plat_info.device_number,
34+
region->plat_info.function_number, region->guid);
35+
kunit_info(test, "\t\taddr=%p, size=%lu, num_rmids=%u", region->addr, region->size,
36+
region->num_rmids);
37+
38+
39+
KUNIT_ASSERT_GE(test, region->plat_info.cdie_mask, 0);
40+
KUNIT_ASSERT_GE(test, region->plat_info.package_id, 0);
41+
KUNIT_ASSERT_GE(test, region->plat_info.partition, 0);
42+
KUNIT_ASSERT_GE(test, region->plat_info.segment, 0);
43+
KUNIT_ASSERT_GE(test, region->plat_info.bus_number, 0);
44+
KUNIT_ASSERT_GE(test, region->plat_info.device_number, 0);
45+
KUNIT_ASSERT_GE(test, region->plat_info.function_number, 0);
46+
47+
KUNIT_ASSERT_NE(test, region->guid, 0);
48+
49+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, (__force const void *)region->addr);
50+
}
51+
}
52+
53+
static void linebreak(struct kunit *test)
54+
{
55+
kunit_info(test, "*****************************************************************************\n");
56+
}
57+
58+
static void test_intel_pmt_get_regions_by_feature(struct kunit *test)
59+
{
60+
struct pmt_feature_group *feature_group;
61+
int num_available = 0;
62+
int feature_id;
63+
64+
/* Iterate through all possible feature IDs */
65+
for (feature_id = 1; feature_id < PMT_FEATURE_COUNT; feature_id++, linebreak(test)) {
66+
const char *name;
67+
68+
if (!pmt_feature_id_is_valid(feature_id))
69+
continue;
70+
71+
name = pmt_feature_names[feature_id];
72+
73+
feature_group = intel_pmt_get_regions_by_feature(feature_id);
74+
if (IS_ERR(feature_group)) {
75+
if (PTR_ERR(feature_group) == -ENOENT)
76+
kunit_warn(test, "intel_pmt_get_regions_by_feature() reporting feature %d [%s] is not present.\n",
77+
feature_id, name);
78+
else
79+
kunit_warn(test, "intel_pmt_get_regions_by_feature() returned error %ld while attempt to lookup %d [%s].\n",
80+
PTR_ERR(feature_group), feature_id, name);
81+
82+
continue;
83+
}
84+
85+
if (!feature_group) {
86+
kunit_warn(test, "Feature ID %d: %s is not available.\n", feature_id, name);
87+
continue;
88+
}
89+
90+
num_available++;
91+
92+
validate_pmt_regions(test, feature_group, feature_id);
93+
94+
intel_pmt_put_feature_group(feature_group);
95+
}
96+
97+
if (num_available == 0)
98+
kunit_warn(test, "No PMT region groups were available for any feature ID (0-10).\n");
99+
}
100+
101+
static struct kunit_case intel_pmt_discovery_test_cases[] = {
102+
KUNIT_CASE(test_intel_pmt_get_regions_by_feature),
103+
{}
104+
};
105+
106+
static struct kunit_suite intel_pmt_discovery_test_suite = {
107+
.name = "pmt_discovery_test",
108+
.test_cases = intel_pmt_discovery_test_cases,
109+
};
110+
111+
kunit_test_suite(intel_pmt_discovery_test_suite);
112+
113+
MODULE_IMPORT_NS("INTEL_PMT_DISCOVERY");
114+
MODULE_AUTHOR("David E. Box <david.e.box@linux.intel.com>");
115+
MODULE_DESCRIPTION("Intel PMT Discovery KUNIT test driver");
116+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)