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};
139 for (i = 0; i < RTE_DIM(envs); ++i) {
141 /* Test setting a valid environment */
142 ret = rte_power_set_env(envs[i]);
144 printf("Unexpectedly unsucceeded on setting a valid environment\n");
148 /* Test that the environment has been set */
149 env = rte_power_get_env();
150 if (env != envs[i]) {
151 printf("Not expected environment configuration\n");
155 /* Verify that function pointers are NOT NULL */
156 if (check_function_ptrs() < 0)
159 rte_power_unset_env();
161 /* Verify that function pointers are NULL */
162 if (check_function_ptrs() < 0)
169 rte_power_unset_env();
174 REGISTER_TEST_COMMAND(power_autotest, test_power);