Skip to content

Commit 3e39e68

Browse files
committed
cpufreq/amd-pstate-ut: Add test case for mode switches
There is a state machine in the amd-pstate driver utilized for switches for all modes. To make sure that cleanup and setup works properly for each mode add a unit test case that tries all combinations. Reviewed-by: Perry Yuan <[email protected]> Signed-off-by: Mario Limonciello <[email protected]>
1 parent 8d91681 commit 3e39e68

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

drivers/cpufreq/amd-pstate-ut.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ static void amd_pstate_ut_acpi_cpc_valid(u32 index);
5454
static void amd_pstate_ut_check_enabled(u32 index);
5555
static void amd_pstate_ut_check_perf(u32 index);
5656
static void amd_pstate_ut_check_freq(u32 index);
57+
static void amd_pstate_ut_check_driver(u32 index);
5758

5859
static struct amd_pstate_ut_struct amd_pstate_ut_cases[] = {
5960
{"amd_pstate_ut_acpi_cpc_valid", amd_pstate_ut_acpi_cpc_valid },
6061
{"amd_pstate_ut_check_enabled", amd_pstate_ut_check_enabled },
6162
{"amd_pstate_ut_check_perf", amd_pstate_ut_check_perf },
62-
{"amd_pstate_ut_check_freq", amd_pstate_ut_check_freq }
63+
{"amd_pstate_ut_check_freq", amd_pstate_ut_check_freq },
64+
{"amd_pstate_ut_check_driver", amd_pstate_ut_check_driver }
6365
};
6466

6567
static bool get_shared_mem(void)
@@ -254,6 +256,43 @@ static void amd_pstate_ut_check_freq(u32 index)
254256
cpufreq_cpu_put(policy);
255257
}
256258

259+
static int amd_pstate_set_mode(enum amd_pstate_mode mode)
260+
{
261+
const char *mode_str = amd_pstate_get_mode_string(mode);
262+
263+
pr_debug("->setting mode to %s\n", mode_str);
264+
265+
return amd_pstate_update_status(mode_str, strlen(mode_str));
266+
}
267+
268+
static void amd_pstate_ut_check_driver(u32 index)
269+
{
270+
enum amd_pstate_mode mode1, mode2;
271+
int ret;
272+
273+
for (mode1 = AMD_PSTATE_DISABLE; mode1 < AMD_PSTATE_MAX; mode1++) {
274+
ret = amd_pstate_set_mode(mode1);
275+
if (ret)
276+
goto out;
277+
for (mode2 = AMD_PSTATE_DISABLE; mode2 < AMD_PSTATE_MAX; mode2++) {
278+
if (mode1 == mode2)
279+
continue;
280+
ret = amd_pstate_set_mode(mode2);
281+
if (ret)
282+
goto out;
283+
}
284+
}
285+
out:
286+
if (ret)
287+
pr_warn("%s: failed to update status for %s->%s: %d\n", __func__,
288+
amd_pstate_get_mode_string(mode1),
289+
amd_pstate_get_mode_string(mode2), ret);
290+
291+
amd_pstate_ut_cases[index].result = ret ?
292+
AMD_PSTATE_UT_RESULT_FAIL :
293+
AMD_PSTATE_UT_RESULT_PASS;
294+
}
295+
257296
static int __init amd_pstate_ut_init(void)
258297
{
259298
u32 i = 0, arr_size = ARRAY_SIZE(amd_pstate_ut_cases);

0 commit comments

Comments
 (0)