Skip to content

Commit 8c32905

Browse files
captain5050namhyung
authored andcommitted
perf test: Add hwmon filename parser test
Filename parsing maps a hwmon filename to constituent parts enum/int parts for the hwmon config value. Add a test case for the parsing. Signed-off-by: Ian Rogers <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Yoshihiro Furudera <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ze Gao <[email protected]> Cc: Changbin Du <[email protected]> Cc: Junhao He <[email protected]> Cc: Weilin Wang <[email protected]> Cc: James Clark <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Athira Jajeev <[email protected]> [namhyung: add #include <linux/string.h> for strlcpy()] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 4810b76 commit 8c32905

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

tools/perf/tests/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ perf-test-y += sigtrap.o
6666
perf-test-y += event_groups.o
6767
perf-test-y += symbols.o
6868
perf-test-y += util.o
69+
perf-test-y += hwmon_pmu.o
6970
perf-test-y += tool_pmu.o
7071

7172
ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc))

tools/perf/tests/builtin-test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static struct test_suite *generic_tests[] = {
7171
&suite__PERF_RECORD,
7272
&suite__pmu,
7373
&suite__pmu_events,
74+
&suite__hwmon_pmu,
7475
&suite__tool_pmu,
7576
&suite__dso_data,
7677
&suite__perf_evsel__roundtrip_name_test,

tools/perf/tests/hwmon_pmu.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2+
#include "debug.h"
3+
#include "hwmon_pmu.h"
4+
#include "tests.h"
5+
#include <linux/compiler.h>
6+
#include <linux/kernel.h>
7+
#include <linux/string.h>
8+
9+
static int test__parse_hwmon_filename(struct test_suite *test __maybe_unused,
10+
int subtest __maybe_unused)
11+
{
12+
const struct hwmon_parse_test {
13+
const char *filename;
14+
enum hwmon_type type;
15+
int number;
16+
enum hwmon_item item;
17+
bool alarm;
18+
bool parse_ok;
19+
} tests[] = {
20+
{
21+
.filename = "cpu0_accuracy",
22+
.type = HWMON_TYPE_CPU,
23+
.number = 0,
24+
.item = HWMON_ITEM_ACCURACY,
25+
.alarm = false,
26+
.parse_ok = true,
27+
},
28+
{
29+
.filename = "temp1_input",
30+
.type = HWMON_TYPE_TEMP,
31+
.number = 1,
32+
.item = HWMON_ITEM_INPUT,
33+
.alarm = false,
34+
.parse_ok = true,
35+
},
36+
{
37+
.filename = "fan2_vid",
38+
.type = HWMON_TYPE_FAN,
39+
.number = 2,
40+
.item = HWMON_ITEM_VID,
41+
.alarm = false,
42+
.parse_ok = true,
43+
},
44+
{
45+
.filename = "power3_crit_alarm",
46+
.type = HWMON_TYPE_POWER,
47+
.number = 3,
48+
.item = HWMON_ITEM_CRIT,
49+
.alarm = true,
50+
.parse_ok = true,
51+
},
52+
{
53+
.filename = "intrusion4_average_interval_min_alarm",
54+
.type = HWMON_TYPE_INTRUSION,
55+
.number = 4,
56+
.item = HWMON_ITEM_AVERAGE_INTERVAL_MIN,
57+
.alarm = true,
58+
.parse_ok = true,
59+
},
60+
{
61+
.filename = "badtype5_baditem",
62+
.type = HWMON_TYPE_NONE,
63+
.number = 5,
64+
.item = HWMON_ITEM_NONE,
65+
.alarm = false,
66+
.parse_ok = false,
67+
},
68+
{
69+
.filename = "humidity6_baditem",
70+
.type = HWMON_TYPE_NONE,
71+
.number = 6,
72+
.item = HWMON_ITEM_NONE,
73+
.alarm = false,
74+
.parse_ok = false,
75+
},
76+
};
77+
78+
for (size_t i = 0; i < ARRAY_SIZE(tests); i++) {
79+
enum hwmon_type type;
80+
int number;
81+
enum hwmon_item item;
82+
bool alarm;
83+
84+
TEST_ASSERT_EQUAL("parse_hwmon_filename",
85+
parse_hwmon_filename(
86+
tests[i].filename,
87+
&type,
88+
&number,
89+
&item,
90+
&alarm),
91+
tests[i].parse_ok
92+
);
93+
if (tests[i].parse_ok) {
94+
TEST_ASSERT_EQUAL("parse_hwmon_filename type", type, tests[i].type);
95+
TEST_ASSERT_EQUAL("parse_hwmon_filename number", number, tests[i].number);
96+
TEST_ASSERT_EQUAL("parse_hwmon_filename item", item, tests[i].item);
97+
TEST_ASSERT_EQUAL("parse_hwmon_filename alarm", alarm, tests[i].alarm);
98+
}
99+
}
100+
return TEST_OK;
101+
}
102+
103+
static struct test_case tests__hwmon_pmu[] = {
104+
TEST_CASE("Basic parsing test", parse_hwmon_filename),
105+
{ .name = NULL, }
106+
};
107+
108+
struct test_suite suite__hwmon_pmu = {
109+
.desc = "Hwmon PMU",
110+
.test_cases = tests__hwmon_pmu,
111+
};

tools/perf/tests/tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ DECLARE_SUITE(perf_evsel__tp_sched_test);
9292
DECLARE_SUITE(syscall_openat_tp_fields);
9393
DECLARE_SUITE(pmu);
9494
DECLARE_SUITE(pmu_events);
95+
DECLARE_SUITE(hwmon_pmu);
9596
DECLARE_SUITE(tool_pmu);
9697
DECLARE_SUITE(attr);
9798
DECLARE_SUITE(dso_data);

0 commit comments

Comments
 (0)