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