1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
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",
102 TEST_POWER_VM_LCORE_ID);
103 rte_power_unset_env();
107 /* Test initialisation of previously initialised lcore */
108 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
110 printf("rte_power_init unexpectedly succeeded on calling init twice on"
111 " lcore %u\n", TEST_POWER_VM_LCORE_ID);
115 /* Test frequency up of invalid lcore */
116 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
118 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
119 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
123 /* Test frequency down of invalid lcore */
124 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
126 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
127 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
131 /* Test frequency min of invalid lcore */
132 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
134 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
135 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
139 /* Test frequency max of invalid lcore */
140 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
142 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
143 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
147 /* Test frequency up of valid but uninitialised lcore */
148 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_INVALID);
150 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
151 TEST_POWER_VM_LCORE_INVALID);
155 /* Test frequency down of valid but uninitialised lcore */
156 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_INVALID);
158 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
159 "%u\n", TEST_POWER_VM_LCORE_INVALID);
163 /* Test frequency min of valid but uninitialised lcore */
164 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_INVALID);
166 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
167 "%u\n", TEST_POWER_VM_LCORE_INVALID);
171 /* Test frequency max of valid but uninitialised lcore */
172 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_INVALID);
174 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
175 "%u\n", TEST_POWER_VM_LCORE_INVALID);
179 /* Test KVM_VM Enable Turbo of valid core */
180 ret = rte_power_freq_enable_turbo(TEST_POWER_VM_LCORE_ID);
182 printf("rte_power_freq_enable_turbo failed on valid lcore"
183 "%u\n", TEST_POWER_VM_LCORE_ID);
187 /* Test KVM_VM Disable Turbo of valid core */
188 ret = rte_power_freq_disable_turbo(TEST_POWER_VM_LCORE_ID);
190 printf("rte_power_freq_disable_turbo failed on valid lcore"
191 "%u\n", TEST_POWER_VM_LCORE_ID);
195 /* Test frequency up of valid lcore */
196 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
198 printf("rte_power_freq_up unexpectedly failed on valid lcore %u\n",
199 TEST_POWER_VM_LCORE_ID);
203 /* Test frequency down of valid lcore */
204 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
206 printf("rte_power_freq_down unexpectedly failed on valid lcore "
207 "%u\n", TEST_POWER_VM_LCORE_ID);
211 /* Test frequency min of valid lcore */
212 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
214 printf("rte_power_freq_min unexpectedly failed on valid lcore "
215 "%u\n", TEST_POWER_VM_LCORE_ID);
219 /* Test frequency max of valid lcore */
220 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
222 printf("rte_power_freq_max unexpectedly failed on valid lcore "
223 "%u\n", TEST_POWER_VM_LCORE_ID);
227 /* Test unsupported rte_power_freqs */
228 ret = rte_power_freqs(TEST_POWER_VM_LCORE_ID, NULL, 0);
229 if (ret != -ENOTSUP) {
230 printf("rte_power_freqs did not return the expected -ENOTSUP(%d) but "
231 "returned %d\n", -ENOTSUP, ret);
235 /* Test unsupported rte_power_get_freq */
236 ret = rte_power_get_freq(TEST_POWER_VM_LCORE_ID);
237 if (ret != -ENOTSUP) {
238 printf("rte_power_get_freq did not return the expected -ENOTSUP(%d) but"
239 " returned %d for lcore %u\n",
240 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
244 /* Test unsupported rte_power_set_freq */
245 ret = rte_power_set_freq(TEST_POWER_VM_LCORE_ID, 0);
246 if (ret != -ENOTSUP) {
247 printf("rte_power_set_freq did not return the expected -ENOTSUP(%d) but"
248 " returned %d for lcore %u\n",
249 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
253 /* Test removing of an lcore */
254 ret = rte_power_exit(TEST_POWER_VM_LCORE_ID);
256 printf("rte_power_exit unexpectedly failed on valid lcore %u,"
257 "please ensure that the environment has been configured "
258 "correctly\n", TEST_POWER_VM_LCORE_ID);
262 /* Test frequency up of previously removed lcore */
263 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
265 printf("rte_power_freq_up unexpectedly succeeded on a removed "
266 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
270 /* Test frequency down of previously removed lcore */
271 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
273 printf("rte_power_freq_down unexpectedly succeeded on a removed "
274 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
278 /* Test frequency min of previously removed lcore */
279 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
281 printf("rte_power_freq_min unexpectedly succeeded on a removed "
282 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
286 /* Test frequency max of previously removed lcore */
287 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
289 printf("rte_power_freq_max unexpectedly succeeded on a removed "
290 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
293 rte_power_unset_env();
296 rte_power_exit(TEST_POWER_VM_LCORE_ID);
297 rte_power_unset_env();
302 REGISTER_TEST_COMMAND(power_kvm_vm_autotest, test_power_kvm_vm);