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
28 #define TEMP_POWER_MANAGER_FILE_PATH "/tmp/testpm"
30 int guest_channel_host_connect(const char *path, unsigned int lcore_id);
33 test_power_kvm_vm(void)
36 enum power_management_env env;
40 ret = rte_power_set_env(PM_ENV_KVM_VM);
42 printf("Failed on setting environment to PM_ENV_KVM_VM\n");
46 /* Test environment configuration */
47 env = rte_power_get_env();
48 if (env != PM_ENV_KVM_VM) {
49 printf("Unexpectedly got a Power Management environment other than "
51 rte_power_unset_env();
55 /* verify that function pointers are not NULL */
56 if (rte_power_freqs == NULL) {
57 printf("rte_power_freqs should not be NULL, environment has not been "
61 if (rte_power_get_freq == NULL) {
62 printf("rte_power_get_freq should not be NULL, environment has not "
63 "been initialised\n");
66 if (rte_power_set_freq == NULL) {
67 printf("rte_power_set_freq should not be NULL, environment has not "
68 "been initialised\n");
71 if (rte_power_freq_up == NULL) {
72 printf("rte_power_freq_up should not be NULL, environment has not "
73 "been initialised\n");
76 if (rte_power_freq_down == NULL) {
77 printf("rte_power_freq_down should not be NULL, environment has not "
78 "been initialised\n");
81 if (rte_power_freq_max == NULL) {
82 printf("rte_power_freq_max should not be NULL, environment has not "
83 "been initialised\n");
86 if (rte_power_freq_min == NULL) {
87 printf("rte_power_freq_min should not be NULL, environment has not "
88 "been initialised\n");
91 /* Test initialisation of an out of bounds lcore */
92 ret = rte_power_init(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
94 printf("rte_power_init unexpectedly succeeded on an invalid lcore %u\n",
95 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
96 rte_power_unset_env();
100 /* Test initialisation of a valid lcore */
101 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
103 printf("rte_power_init failed as expected in host\n");
104 /* This test would be successful when run on VM,
105 * in order to run in Host itself, temporary file path
106 * is created and same is used for further communication
109 snprintf(fPath, PATH_MAX, "%s.%u",
110 TEMP_POWER_MANAGER_FILE_PATH, TEST_POWER_VM_LCORE_ID);
111 fPtr = fopen(fPath, "w");
113 printf(" Unable to create file\n");
114 rte_power_unset_env();
117 ret = guest_channel_host_connect(TEMP_POWER_MANAGER_FILE_PATH,
118 TEST_POWER_VM_LCORE_ID);
120 printf("guest_channel_host_connect successful\n");
122 printf("guest_channel_host_connect failed\n");
123 rte_power_unset_env();
130 /* Test initialisation of previously initialised lcore */
131 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
133 printf("rte_power_init unexpectedly succeeded on calling init twice on"
134 " lcore %u\n", TEST_POWER_VM_LCORE_ID);
138 /* Test frequency up of invalid lcore */
139 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
141 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
142 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
146 /* Test frequency down of invalid lcore */
147 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
149 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
150 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
154 /* Test frequency min of invalid lcore */
155 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
157 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
158 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
162 /* Test frequency max of invalid lcore */
163 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
165 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
166 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
170 /* Test frequency up of valid but uninitialised lcore */
171 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_INVALID);
173 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
174 TEST_POWER_VM_LCORE_INVALID);
178 /* Test frequency down of valid but uninitialised lcore */
179 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_INVALID);
181 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
182 "%u\n", TEST_POWER_VM_LCORE_INVALID);
186 /* Test frequency min of valid but uninitialised lcore */
187 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_INVALID);
189 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
190 "%u\n", TEST_POWER_VM_LCORE_INVALID);
194 /* Test frequency max of valid but uninitialised lcore */
195 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_INVALID);
197 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
198 "%u\n", TEST_POWER_VM_LCORE_INVALID);
202 /* Test KVM_VM Enable Turbo of valid core */
203 ret = rte_power_freq_enable_turbo(TEST_POWER_VM_LCORE_ID);
205 printf("rte_power_freq_enable_turbo failed on valid lcore"
206 "%u\n", TEST_POWER_VM_LCORE_ID);
210 /* Test KVM_VM Disable Turbo of valid core */
211 ret = rte_power_freq_disable_turbo(TEST_POWER_VM_LCORE_ID);
213 printf("rte_power_freq_disable_turbo failed on valid lcore"
214 "%u\n", TEST_POWER_VM_LCORE_ID);
218 /* Test frequency up of valid lcore */
219 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
221 printf("rte_power_freq_up unexpectedly failed on valid lcore %u\n",
222 TEST_POWER_VM_LCORE_ID);
226 /* Test frequency down of valid lcore */
227 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
229 printf("rte_power_freq_down unexpectedly failed on valid lcore "
230 "%u\n", TEST_POWER_VM_LCORE_ID);
234 /* Test frequency min of valid lcore */
235 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
237 printf("rte_power_freq_min unexpectedly failed on valid lcore "
238 "%u\n", TEST_POWER_VM_LCORE_ID);
242 /* Test frequency max of valid lcore */
243 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
245 printf("rte_power_freq_max unexpectedly failed on valid lcore "
246 "%u\n", TEST_POWER_VM_LCORE_ID);
250 /* Test unsupported rte_power_freqs */
251 ret = rte_power_freqs(TEST_POWER_VM_LCORE_ID, NULL, 0);
252 if (ret != -ENOTSUP) {
253 printf("rte_power_freqs did not return the expected -ENOTSUP(%d) but "
254 "returned %d\n", -ENOTSUP, ret);
258 /* Test unsupported rte_power_get_freq */
259 ret = rte_power_get_freq(TEST_POWER_VM_LCORE_ID);
260 if (ret != -ENOTSUP) {
261 printf("rte_power_get_freq did not return the expected -ENOTSUP(%d) but"
262 " returned %d for lcore %u\n",
263 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
267 /* Test unsupported rte_power_set_freq */
268 ret = rte_power_set_freq(TEST_POWER_VM_LCORE_ID, 0);
269 if (ret != -ENOTSUP) {
270 printf("rte_power_set_freq did not return the expected -ENOTSUP(%d) but"
271 " returned %d for lcore %u\n",
272 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
276 /* Test removing of an lcore */
277 ret = rte_power_exit(TEST_POWER_VM_LCORE_ID);
279 printf("rte_power_exit unexpectedly failed on valid lcore %u,"
280 "please ensure that the environment has been configured "
281 "correctly\n", TEST_POWER_VM_LCORE_ID);
285 /* Test frequency up of previously removed lcore */
286 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
288 printf("rte_power_freq_up unexpectedly succeeded on a removed "
289 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
293 /* Test frequency down of previously removed lcore */
294 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
296 printf("rte_power_freq_down unexpectedly succeeded on a removed "
297 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
301 /* Test frequency min of previously removed lcore */
302 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
304 printf("rte_power_freq_min unexpectedly succeeded on a removed "
305 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
309 /* Test frequency max of previously removed lcore */
310 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
312 printf("rte_power_freq_max unexpectedly succeeded on a removed "
313 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
316 rte_power_unset_env();
323 rte_power_exit(TEST_POWER_VM_LCORE_ID);
324 rte_power_unset_env();
333 REGISTER_TEST_COMMAND(power_kvm_vm_autotest, test_power_kvm_vm);