1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
14 #ifndef RTE_LIBRTE_POWER
19 printf("Power management library not supported, skipping test\n");
25 #include <rte_power.h>
28 check_function_ptrs(void)
30 enum power_management_env env
= rte_power_get_env();
32 const bool not_null_expected
= !(env
== PM_ENV_NOT_SET
);
34 const char *inject_not_string1
= not_null_expected
? " not" : "";
35 const char *inject_not_string2
= not_null_expected
? "" : " not";
37 if ((rte_power_freqs
== NULL
) == not_null_expected
) {
38 printf("rte_power_freqs should%s be NULL, environment has%s been "
39 "initialised\n", inject_not_string1
,
43 if ((rte_power_get_freq
== NULL
) == not_null_expected
) {
44 printf("rte_power_get_freq should%s be NULL, environment has%s been "
45 "initialised\n", inject_not_string1
,
49 if ((rte_power_set_freq
== NULL
) == not_null_expected
) {
50 printf("rte_power_set_freq should%s be NULL, environment has%s been "
51 "initialised\n", inject_not_string1
,
55 if ((rte_power_freq_up
== NULL
) == not_null_expected
) {
56 printf("rte_power_freq_up should%s be NULL, environment has%s been "
57 "initialised\n", inject_not_string1
,
61 if ((rte_power_freq_down
== NULL
) == not_null_expected
) {
62 printf("rte_power_freq_down should%s be NULL, environment has%s been "
63 "initialised\n", inject_not_string1
,
67 if ((rte_power_freq_max
== NULL
) == not_null_expected
) {
68 printf("rte_power_freq_max should%s be NULL, environment has%s been "
69 "initialised\n", inject_not_string1
,
73 if ((rte_power_freq_min
== NULL
) == not_null_expected
) {
74 printf("rte_power_freq_min should%s be NULL, environment has%s been "
75 "initialised\n", inject_not_string1
,
79 if ((rte_power_turbo_status
== NULL
) == not_null_expected
) {
80 printf("rte_power_turbo_status should%s be NULL, environment has%s been "
81 "initialised\n", inject_not_string1
,
85 if ((rte_power_freq_enable_turbo
== NULL
) == not_null_expected
) {
86 printf("rte_power_freq_enable_turbo should%s be NULL, environment has%s been "
87 "initialised\n", inject_not_string1
,
91 if ((rte_power_freq_disable_turbo
== NULL
) == not_null_expected
) {
92 printf("rte_power_freq_disable_turbo should%s be NULL, environment has%s been "
93 "initialised\n", inject_not_string1
,
97 if ((rte_power_get_capabilities
== NULL
) == not_null_expected
) {
98 printf("rte_power_get_capabilities should%s be NULL, environment has%s been "
99 "initialised\n", inject_not_string1
,
111 enum power_management_env env
;
113 /* Test setting an invalid environment */
114 ret
= rte_power_set_env(PM_ENV_NOT_SET
);
116 printf("Unexpectedly succeeded on setting an invalid environment\n");
120 /* Test that the environment has not been set */
121 env
= rte_power_get_env();
122 if (env
!= PM_ENV_NOT_SET
) {
123 printf("Unexpectedly got a valid environment configuration\n");
127 /* Verify that function pointers are NULL */
128 if (check_function_ptrs() < 0)
131 rte_power_unset_env();
133 /* Perform tests for valid environments.*/
134 const enum power_management_env envs
[] = {PM_ENV_ACPI_CPUFREQ
,
136 PM_ENV_PSTATE_CPUFREQ
};
138 const int envs_size
= sizeof(envs
)/sizeof(enum power_management_env
);
141 for (i
= 0; i
< envs_size
; ++i
) {
143 /* Test setting a valid environment */
144 ret
= rte_power_set_env(envs
[i
]);
146 printf("Unexpectedly unsucceeded on setting a valid environment\n");
150 /* Test that the environment has been set */
151 env
= rte_power_get_env();
152 if (env
!= envs
[i
]) {
153 printf("Not expected environment configuration\n");
157 /* Verify that function pointers are NOT NULL */
158 if (check_function_ptrs() < 0)
161 rte_power_unset_env();
163 /* Verify that function pointers are NULL */
164 if (check_function_ptrs() < 0)
171 rte_power_unset_env();
176 REGISTER_TEST_COMMAND(power_autotest
, test_power
);