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>
44 #define TEST_POWER_VM_LCORE_ID 0U
45 #define TEST_POWER_VM_LCORE_OUT_OF_BOUNDS (RTE_MAX_LCORE+1)
46 #define TEST_POWER_VM_LCORE_INVALID 1U
49 test_power_kvm_vm(void)
52 enum power_management_env env;
54 ret = rte_power_set_env(PM_ENV_KVM_VM);
56 printf("Failed on setting environment to PM_ENV_KVM_VM\n");
60 /* Test environment configuration */
61 env = rte_power_get_env();
62 if (env != PM_ENV_KVM_VM) {
63 printf("Unexpectedly got a Power Management environment other than "
65 rte_power_unset_env();
69 /* verify that function pointers are not NULL */
70 if (rte_power_freqs == NULL) {
71 printf("rte_power_freqs should not be NULL, environment has not been "
75 if (rte_power_get_freq == NULL) {
76 printf("rte_power_get_freq should not be NULL, environment has not "
77 "been initialised\n");
80 if (rte_power_set_freq == NULL) {
81 printf("rte_power_set_freq should not be NULL, environment has not "
82 "been initialised\n");
85 if (rte_power_freq_up == NULL) {
86 printf("rte_power_freq_up should not be NULL, environment has not "
87 "been initialised\n");
90 if (rte_power_freq_down == NULL) {
91 printf("rte_power_freq_down should not be NULL, environment has not "
92 "been initialised\n");
95 if (rte_power_freq_max == NULL) {
96 printf("rte_power_freq_max should not be NULL, environment has not "
97 "been initialised\n");
100 if (rte_power_freq_min == NULL) {
101 printf("rte_power_freq_min should not be NULL, environment has not "
102 "been initialised\n");
105 /* Test initialisation of an out of bounds lcore */
106 ret = rte_power_init(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
108 printf("rte_power_init unexpectedly succeeded on an invalid lcore %u\n",
109 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
110 rte_power_unset_env();
114 /* Test initialisation of a valid lcore */
115 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
117 printf("Cannot initialise power management for lcore %u, this "
118 "may occur if environment is not configured "
119 "correctly(KVM VM) or operating in another valid "
120 "Power management environment\n", TEST_POWER_VM_LCORE_ID);
121 rte_power_unset_env();
125 /* Test initialisation of previously initialised lcore */
126 ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
128 printf("rte_power_init unexpectedly succeeded on calling init twice on"
129 " lcore %u\n", TEST_POWER_VM_LCORE_ID);
133 /* Test frequency up of invalid lcore */
134 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
136 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
137 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
141 /* Test frequency down of invalid lcore */
142 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
144 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
145 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
149 /* Test frequency min of invalid lcore */
150 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
152 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
153 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
157 /* Test frequency max of invalid lcore */
158 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
160 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
161 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
165 /* Test frequency up of valid but uninitialised lcore */
166 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_INVALID);
168 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
169 TEST_POWER_VM_LCORE_INVALID);
173 /* Test frequency down of valid but uninitialised lcore */
174 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_INVALID);
176 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
177 "%u\n", TEST_POWER_VM_LCORE_INVALID);
181 /* Test frequency min of valid but uninitialised lcore */
182 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_INVALID);
184 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
185 "%u\n", TEST_POWER_VM_LCORE_INVALID);
189 /* Test frequency max of valid but uninitialised lcore */
190 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_INVALID);
192 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
193 "%u\n", TEST_POWER_VM_LCORE_INVALID);
197 /* Test frequency up of valid lcore */
198 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
200 printf("rte_power_freq_up unexpectedly failed on valid lcore %u\n",
201 TEST_POWER_VM_LCORE_ID);
205 /* Test frequency down of valid lcore */
206 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
208 printf("rte_power_freq_down unexpectedly failed on valid lcore "
209 "%u\n", TEST_POWER_VM_LCORE_ID);
213 /* Test frequency min of valid lcore */
214 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
216 printf("rte_power_freq_min unexpectedly failed on valid lcore "
217 "%u\n", TEST_POWER_VM_LCORE_ID);
221 /* Test frequency max of valid lcore */
222 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
224 printf("rte_power_freq_max unexpectedly failed on valid lcore "
225 "%u\n", TEST_POWER_VM_LCORE_ID);
229 /* Test unsupported rte_power_freqs */
230 ret = rte_power_freqs(TEST_POWER_VM_LCORE_ID, NULL, 0);
231 if (ret != -ENOTSUP) {
232 printf("rte_power_freqs did not return the expected -ENOTSUP(%d) but "
233 "returned %d\n", -ENOTSUP, ret);
237 /* Test unsupported rte_power_get_freq */
238 ret = rte_power_get_freq(TEST_POWER_VM_LCORE_ID);
239 if (ret != -ENOTSUP) {
240 printf("rte_power_get_freq did not return the expected -ENOTSUP(%d) but"
241 " returned %d for lcore %u\n",
242 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
246 /* Test unsupported rte_power_set_freq */
247 ret = rte_power_set_freq(TEST_POWER_VM_LCORE_ID, 0);
248 if (ret != -ENOTSUP) {
249 printf("rte_power_set_freq did not return the expected -ENOTSUP(%d) but"
250 " returned %d for lcore %u\n",
251 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
255 /* Test removing of an lcore */
256 ret = rte_power_exit(TEST_POWER_VM_LCORE_ID);
258 printf("rte_power_exit unexpectedly failed on valid lcore %u,"
259 "please ensure that the environment has been configured "
260 "correctly\n", TEST_POWER_VM_LCORE_ID);
264 /* Test frequency up of previously removed lcore */
265 ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
267 printf("rte_power_freq_up unexpectedly succeeded on a removed "
268 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
272 /* Test frequency down of previously removed lcore */
273 ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
275 printf("rte_power_freq_down unexpectedly succeeded on a removed "
276 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
280 /* Test frequency min of previously removed lcore */
281 ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
283 printf("rte_power_freq_min unexpectedly succeeded on a removed "
284 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
288 /* Test frequency max of previously removed lcore */
289 ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
291 printf("rte_power_freq_max unexpectedly succeeded on a removed "
292 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
295 rte_power_unset_env();
298 rte_power_exit(TEST_POWER_VM_LCORE_ID);
299 rte_power_unset_env();
303 REGISTER_TEST_COMMAND(power_kvm_vm_autotest, test_power_kvm_vm);