1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <rte_power.h>
15 #define TEST_POWER_VM_LCORE_ID 0U
16 #define TEST_POWER_VM_LCORE_OUT_OF_BOUNDS (RTE_MAX_LCORE+1)
17 #define TEST_POWER_VM_LCORE_INVALID 1U
20 test_power_kvm_vm(void)
23 enum power_management_env env;
25 ret = rte_power_set_env(PM_ENV_KVM_VM);
27 printf("Failed on setting environment to PM_ENV_KVM_VM\n");
31 /* Test environment configuration */
32 env = rte_power_get_env();
33 if (env != PM_ENV_KVM_VM) {
34 printf("Unexpectedly got a Power Management environment other than "
36 rte_power_unset_env();
40 /* verify that function pointers are not NULL */
41 if (rte_power_freqs == NULL) {
42 printf("rte_power_freqs should not be NULL, environment has not been "
46 if (rte_power_get_freq == NULL) {
47 printf("rte_power_get_freq should not be NULL, environment has not "
48 "been initialised\n");
51 if (rte_power_set_freq == NULL) {
52 printf("rte_power_set_freq should not be NULL, environment has not "
53 "been initialised\n");
56 if (rte_power_freq_up == NULL) {
57 printf("rte_power_freq_up should not be NULL, environment has not "
58 "been initialised\n");
61 if (rte_power_freq_down == NULL) {
62 printf("rte_power_freq_down should not be NULL, environment has not "
63 "been initialised\n");
66 if (rte_power_freq_max == NULL) {
67 printf("rte_power_freq_max should not be NULL, environment has not "
68 "been initialised\n");
71 if (rte_power_freq_min == NULL) {
72 printf("rte_power_freq_min should not be NULL, environment has not "
73 "been initialised\n");
76 /* Test initialisation of an out of bounds lcore */
77 ret = rte_power_init(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
79 printf("rte_power_init unexpectedly succeeded on an invalid lcore %u\n",
80 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
81 rte_power_unset_env();
85 /* Test initialisation of a valid lcore */
86 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
88 printf("Cannot initialise power management for lcore %u, this "
89 "may occur if environment is not configured "
90 "correctly(KVM VM) or operating in another valid "
91 "Power management environment\n", TEST_POWER_VM_LCORE_ID);
92 rte_power_unset_env();
96 /* Test initialisation of previously initialised lcore */
97 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
99 printf("rte_power_init unexpectedly succeeded on calling init twice on"
100 " lcore %u\n", TEST_POWER_VM_LCORE_ID);
104 /* Test frequency up of invalid lcore */
105 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
107 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
108 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
112 /* Test frequency down of invalid lcore */
113 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
115 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
116 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
120 /* Test frequency min of invalid lcore */
121 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
123 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
124 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
128 /* Test frequency max of invalid lcore */
129 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
131 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
132 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
136 /* Test frequency up of valid but uninitialised lcore */
137 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_INVALID);
139 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
140 TEST_POWER_VM_LCORE_INVALID);
144 /* Test frequency down of valid but uninitialised lcore */
145 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_INVALID);
147 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
148 "%u\n", TEST_POWER_VM_LCORE_INVALID);
152 /* Test frequency min of valid but uninitialised lcore */
153 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_INVALID);
155 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
156 "%u\n", TEST_POWER_VM_LCORE_INVALID);
160 /* Test frequency max of valid but uninitialised lcore */
161 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_INVALID);
163 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
164 "%u\n", TEST_POWER_VM_LCORE_INVALID);
168 /* Test frequency up of valid lcore */
169 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
171 printf("rte_power_freq_up unexpectedly failed on valid lcore %u\n",
172 TEST_POWER_VM_LCORE_ID);
176 /* Test frequency down of valid lcore */
177 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
179 printf("rte_power_freq_down unexpectedly failed on valid lcore "
180 "%u\n", TEST_POWER_VM_LCORE_ID);
184 /* Test frequency min of valid lcore */
185 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
187 printf("rte_power_freq_min unexpectedly failed on valid lcore "
188 "%u\n", TEST_POWER_VM_LCORE_ID);
192 /* Test frequency max of valid lcore */
193 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
195 printf("rte_power_freq_max unexpectedly failed on valid lcore "
196 "%u\n", TEST_POWER_VM_LCORE_ID);
200 /* Test unsupported rte_power_freqs */
201 ret = rte_power_freqs(TEST_POWER_VM_LCORE_ID, NULL, 0);
202 if (ret != -ENOTSUP) {
203 printf("rte_power_freqs did not return the expected -ENOTSUP(%d) but "
204 "returned %d\n", -ENOTSUP, ret);
208 /* Test unsupported rte_power_get_freq */
209 ret = rte_power_get_freq(TEST_POWER_VM_LCORE_ID);
210 if (ret != -ENOTSUP) {
211 printf("rte_power_get_freq did not return the expected -ENOTSUP(%d) but"
212 " returned %d for lcore %u\n",
213 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
217 /* Test unsupported rte_power_set_freq */
218 ret = rte_power_set_freq(TEST_POWER_VM_LCORE_ID, 0);
219 if (ret != -ENOTSUP) {
220 printf("rte_power_set_freq did not return the expected -ENOTSUP(%d) but"
221 " returned %d for lcore %u\n",
222 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
226 /* Test removing of an lcore */
227 ret = rte_power_exit(TEST_POWER_VM_LCORE_ID);
229 printf("rte_power_exit unexpectedly failed on valid lcore %u,"
230 "please ensure that the environment has been configured "
231 "correctly\n", TEST_POWER_VM_LCORE_ID);
235 /* Test frequency up of previously removed lcore */
236 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
238 printf("rte_power_freq_up unexpectedly succeeded on a removed "
239 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
243 /* Test frequency down of previously removed lcore */
244 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
246 printf("rte_power_freq_down unexpectedly succeeded on a removed "
247 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
251 /* Test frequency min of previously removed lcore */
252 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
254 printf("rte_power_freq_min unexpectedly succeeded on a removed "
255 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
259 /* Test frequency max of previously removed lcore */
260 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
262 printf("rte_power_freq_max unexpectedly succeeded on a removed "
263 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
266 rte_power_unset_env();
269 rte_power_exit(TEST_POWER_VM_LCORE_ID);
270 rte_power_unset_env();
274 REGISTER_TEST_COMMAND(power_kvm_vm_autotest, test_power_kvm_vm);