4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <rte_power.h>
43 #include <rte_config.h>
45 #define TEST_POWER_VM_LCORE_ID 0U
46 #define TEST_POWER_VM_LCORE_OUT_OF_BOUNDS (RTE_MAX_LCORE+1)
47 #define TEST_POWER_VM_LCORE_INVALID 1U
50 test_power_kvm_vm(void)
53 enum power_management_env env;
55 ret = rte_power_set_env(PM_ENV_KVM_VM);
57 printf("Failed on setting environment to PM_ENV_KVM_VM\n");
61 /* Test environment configuration */
62 env = rte_power_get_env();
63 if (env != PM_ENV_KVM_VM) {
64 printf("Unexpectedly got a Power Management environment other than "
66 rte_power_unset_env();
70 /* verify that function pointers are not NULL */
71 if (rte_power_freqs == NULL) {
72 printf("rte_power_freqs should not be NULL, environment has not been "
76 if (rte_power_get_freq == NULL) {
77 printf("rte_power_get_freq should not be NULL, environment has not "
78 "been initialised\n");
81 if (rte_power_set_freq == NULL) {
82 printf("rte_power_set_freq should not be NULL, environment has not "
83 "been initialised\n");
86 if (rte_power_freq_up == NULL) {
87 printf("rte_power_freq_up should not be NULL, environment has not "
88 "been initialised\n");
91 if (rte_power_freq_down == NULL) {
92 printf("rte_power_freq_down should not be NULL, environment has not "
93 "been initialised\n");
96 if (rte_power_freq_max == NULL) {
97 printf("rte_power_freq_max should not be NULL, environment has not "
98 "been initialised\n");
101 if (rte_power_freq_min == NULL) {
102 printf("rte_power_freq_min should not be NULL, environment has not "
103 "been initialised\n");
106 /* Test initialisation of an out of bounds lcore */
107 ret = rte_power_init(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
109 printf("rte_power_init unexpectedly succeeded on an invalid lcore %u\n",
110 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
111 rte_power_unset_env();
115 /* Test initialisation of a valid lcore */
116 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
118 printf("Cannot initialise power management for lcore %u, this "
119 "may occur if environment is not configured "
120 "correctly(KVM VM) or operating in another valid "
121 "Power management environment\n", TEST_POWER_VM_LCORE_ID);
122 rte_power_unset_env();
126 /* Test initialisation of previously initialised lcore */
127 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
129 printf("rte_power_init unexpectedly succeeded on calling init twice on"
130 " lcore %u\n", TEST_POWER_VM_LCORE_ID);
134 /* Test frequency up of invalid lcore */
135 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
137 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
138 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
142 /* Test frequency down of invalid lcore */
143 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
145 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
146 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
150 /* Test frequency min of invalid lcore */
151 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
153 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
154 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
158 /* Test frequency max of invalid lcore */
159 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
161 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
162 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
166 /* Test frequency up of valid but uninitialised lcore */
167 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_INVALID);
169 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
170 TEST_POWER_VM_LCORE_INVALID);
174 /* Test frequency down of valid but uninitialised lcore */
175 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_INVALID);
177 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
178 "%u\n", TEST_POWER_VM_LCORE_INVALID);
182 /* Test frequency min of valid but uninitialised lcore */
183 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_INVALID);
185 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
186 "%u\n", TEST_POWER_VM_LCORE_INVALID);
190 /* Test frequency max of valid but uninitialised lcore */
191 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_INVALID);
193 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
194 "%u\n", TEST_POWER_VM_LCORE_INVALID);
198 /* Test frequency up of valid lcore */
199 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
201 printf("rte_power_freq_up unexpectedly failed on valid lcore %u\n",
202 TEST_POWER_VM_LCORE_ID);
206 /* Test frequency down of valid lcore */
207 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
209 printf("rte_power_freq_down unexpectedly failed on valid lcore "
210 "%u\n", TEST_POWER_VM_LCORE_ID);
214 /* Test frequency min of valid lcore */
215 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
217 printf("rte_power_freq_min unexpectedly failed on valid lcore "
218 "%u\n", TEST_POWER_VM_LCORE_ID);
222 /* Test frequency max of valid lcore */
223 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
225 printf("rte_power_freq_max unexpectedly failed on valid lcore "
226 "%u\n", TEST_POWER_VM_LCORE_ID);
230 /* Test unsupported rte_power_freqs */
231 ret = rte_power_freqs(TEST_POWER_VM_LCORE_ID, NULL, 0);
232 if (ret != -ENOTSUP) {
233 printf("rte_power_freqs did not return the expected -ENOTSUP(%d) but "
234 "returned %d\n", -ENOTSUP, ret);
238 /* Test unsupported rte_power_get_freq */
239 ret = rte_power_get_freq(TEST_POWER_VM_LCORE_ID);
240 if (ret != -ENOTSUP) {
241 printf("rte_power_get_freq did not return the expected -ENOTSUP(%d) but"
242 " returned %d for lcore %u\n",
243 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
247 /* Test unsupported rte_power_set_freq */
248 ret = rte_power_set_freq(TEST_POWER_VM_LCORE_ID, 0);
249 if (ret != -ENOTSUP) {
250 printf("rte_power_set_freq did not return the expected -ENOTSUP(%d) but"
251 " returned %d for lcore %u\n",
252 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
256 /* Test removing of an lcore */
257 ret = rte_power_exit(TEST_POWER_VM_LCORE_ID);
259 printf("rte_power_exit unexpectedly failed on valid lcore %u,"
260 "please ensure that the environment has been configured "
261 "correctly\n", TEST_POWER_VM_LCORE_ID);
265 /* Test frequency up of previously removed lcore */
266 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
268 printf("rte_power_freq_up unexpectedly succeeded on a removed "
269 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
273 /* Test frequency down of previously removed lcore */
274 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
276 printf("rte_power_freq_down unexpectedly succeeded on a removed "
277 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
281 /* Test frequency min of previously removed lcore */
282 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
284 printf("rte_power_freq_min unexpectedly succeeded on a removed "
285 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
289 /* Test frequency max of previously removed lcore */
290 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
292 printf("rte_power_freq_max unexpectedly succeeded on a removed "
293 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
296 rte_power_unset_env();
299 rte_power_exit(TEST_POWER_VM_LCORE_ID);
300 rte_power_unset_env();
304 static struct test_command power_kvm_vm_cmd = {
305 .command = "power_kvm_vm_autotest",
306 .callback = test_power_kvm_vm,
308 REGISTER_TEST_COMMAND(power_kvm_vm_cmd);