1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #ifndef RTE_LIBRTE_POWER
16 test_power_kvm_vm(void)
18 printf("Power management library not supported, skipping test\n");
23 #include <rte_power.h>
25 #define TEST_POWER_VM_LCORE_ID 0U
26 #define TEST_POWER_VM_LCORE_OUT_OF_BOUNDS (RTE_MAX_LCORE+1)
27 #define TEST_POWER_VM_LCORE_INVALID 1U
30 test_power_kvm_vm(void)
33 enum power_management_env env;
35 ret = rte_power_set_env(PM_ENV_KVM_VM);
37 printf("Failed on setting environment to PM_ENV_KVM_VM\n");
41 /* Test environment configuration */
42 env = rte_power_get_env();
43 if (env != PM_ENV_KVM_VM) {
44 printf("Unexpectedly got a Power Management environment other than "
46 rte_power_unset_env();
50 /* verify that function pointers are not NULL */
51 if (rte_power_freqs == NULL) {
52 printf("rte_power_freqs should not be NULL, environment has not been "
56 if (rte_power_get_freq == NULL) {
57 printf("rte_power_get_freq should not be NULL, environment has not "
58 "been initialised\n");
61 if (rte_power_set_freq == NULL) {
62 printf("rte_power_set_freq should not be NULL, environment has not "
63 "been initialised\n");
66 if (rte_power_freq_up == NULL) {
67 printf("rte_power_freq_up should not be NULL, environment has not "
68 "been initialised\n");
71 if (rte_power_freq_down == NULL) {
72 printf("rte_power_freq_down should not be NULL, environment has not "
73 "been initialised\n");
76 if (rte_power_freq_max == NULL) {
77 printf("rte_power_freq_max should not be NULL, environment has not "
78 "been initialised\n");
81 if (rte_power_freq_min == NULL) {
82 printf("rte_power_freq_min should not be NULL, environment has not "
83 "been initialised\n");
86 /* Test initialisation of an out of bounds lcore */
87 ret = rte_power_init(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
89 printf("rte_power_init unexpectedly succeeded on an invalid lcore %u\n",
90 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
91 rte_power_unset_env();
95 /* Test initialisation of a valid lcore */
96 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
98 printf("Cannot initialise power management for lcore %u, this "
99 "may occur if environment is not configured "
100 "correctly(KVM VM) or operating in another valid "
101 "Power management environment\n", TEST_POWER_VM_LCORE_ID);
102 rte_power_unset_env();
106 /* Test initialisation of previously initialised lcore */
107 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
109 printf("rte_power_init unexpectedly succeeded on calling init twice on"
110 " lcore %u\n", TEST_POWER_VM_LCORE_ID);
114 /* Test frequency up of invalid lcore */
115 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
117 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
118 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
122 /* Test frequency down of invalid lcore */
123 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
125 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
126 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
130 /* Test frequency min of invalid lcore */
131 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
133 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
134 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
138 /* Test frequency max of invalid lcore */
139 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
141 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
142 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
146 /* Test frequency up of valid but uninitialised lcore */
147 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_INVALID);
149 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
150 TEST_POWER_VM_LCORE_INVALID);
154 /* Test frequency down of valid but uninitialised lcore */
155 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_INVALID);
157 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
158 "%u\n", TEST_POWER_VM_LCORE_INVALID);
162 /* Test frequency min of valid but uninitialised lcore */
163 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_INVALID);
165 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
166 "%u\n", TEST_POWER_VM_LCORE_INVALID);
170 /* Test frequency max of valid but uninitialised lcore */
171 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_INVALID);
173 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
174 "%u\n", TEST_POWER_VM_LCORE_INVALID);
178 /* Test frequency up of valid lcore */
179 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
181 printf("rte_power_freq_up unexpectedly failed on valid lcore %u\n",
182 TEST_POWER_VM_LCORE_ID);
186 /* Test frequency down of valid lcore */
187 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
189 printf("rte_power_freq_down unexpectedly failed on valid lcore "
190 "%u\n", TEST_POWER_VM_LCORE_ID);
194 /* Test frequency min of valid lcore */
195 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
197 printf("rte_power_freq_min unexpectedly failed on valid lcore "
198 "%u\n", TEST_POWER_VM_LCORE_ID);
202 /* Test frequency max of valid lcore */
203 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
205 printf("rte_power_freq_max unexpectedly failed on valid lcore "
206 "%u\n", TEST_POWER_VM_LCORE_ID);
210 /* Test unsupported rte_power_freqs */
211 ret = rte_power_freqs(TEST_POWER_VM_LCORE_ID, NULL, 0);
212 if (ret != -ENOTSUP) {
213 printf("rte_power_freqs did not return the expected -ENOTSUP(%d) but "
214 "returned %d\n", -ENOTSUP, ret);
218 /* Test unsupported rte_power_get_freq */
219 ret = rte_power_get_freq(TEST_POWER_VM_LCORE_ID);
220 if (ret != -ENOTSUP) {
221 printf("rte_power_get_freq did not return the expected -ENOTSUP(%d) but"
222 " returned %d for lcore %u\n",
223 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
227 /* Test unsupported rte_power_set_freq */
228 ret = rte_power_set_freq(TEST_POWER_VM_LCORE_ID, 0);
229 if (ret != -ENOTSUP) {
230 printf("rte_power_set_freq did not return the expected -ENOTSUP(%d) but"
231 " returned %d for lcore %u\n",
232 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
236 /* Test removing of an lcore */
237 ret = rte_power_exit(TEST_POWER_VM_LCORE_ID);
239 printf("rte_power_exit unexpectedly failed on valid lcore %u,"
240 "please ensure that the environment has been configured "
241 "correctly\n", TEST_POWER_VM_LCORE_ID);
245 /* Test frequency up of previously removed lcore */
246 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
248 printf("rte_power_freq_up unexpectedly succeeded on a removed "
249 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
253 /* Test frequency down of previously removed lcore */
254 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
256 printf("rte_power_freq_down unexpectedly succeeded on a removed "
257 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
261 /* Test frequency min of previously removed lcore */
262 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
264 printf("rte_power_freq_min unexpectedly succeeded on a removed "
265 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
269 /* Test frequency max of previously removed lcore */
270 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
272 printf("rte_power_freq_max unexpectedly succeeded on a removed "
273 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
276 rte_power_unset_env();
279 rte_power_exit(TEST_POWER_VM_LCORE_ID);
280 rte_power_unset_env();
285 REGISTER_TEST_COMMAND(power_kvm_vm_autotest, test_power_kvm_vm);