1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #include <stdio.h> 6 #include <stdint.h> 7 #include <unistd.h> 8 #include <limits.h> 9 #include <string.h> 10 #include <stdbool.h> 11 12 #include "test.h" 13 14 #ifndef RTE_LIB_POWER 15 16 static int 17 test_power(void) 18 { 19 printf("Power management library not supported, skipping test\n"); 20 return TEST_SKIPPED; 21 } 22 23 #else 24 25 #include <rte_power_cpufreq.h> 26 27 static int 28 test_power(void) 29 { 30 int ret = -1; 31 enum power_management_env env; 32 33 /* Test setting an invalid environment */ 34 ret = rte_power_set_env(PM_ENV_NOT_SET); 35 if (ret == 0) { 36 printf("Unexpectedly succeeded on setting an invalid environment\n"); 37 return -1; 38 } 39 40 /* Test that the environment has not been set */ 41 env = rte_power_get_env(); 42 if (env != PM_ENV_NOT_SET) { 43 printf("Unexpectedly got a valid environment configuration\n"); 44 return -1; 45 } 46 47 rte_power_unset_env(); 48 49 /* Perform tests for valid environments.*/ 50 const enum power_management_env envs[] = {PM_ENV_ACPI_CPUFREQ, 51 PM_ENV_KVM_VM, 52 PM_ENV_PSTATE_CPUFREQ, 53 PM_ENV_AMD_PSTATE_CPUFREQ, 54 PM_ENV_CPPC_CPUFREQ}; 55 56 unsigned int i; 57 for (i = 0; i < RTE_DIM(envs); ++i) { 58 59 /* Test setting a valid environment */ 60 ret = rte_power_set_env(envs[i]); 61 if (ret != 0) { 62 printf("Unexpectedly unsuccessful on setting a valid environment\n"); 63 return -1; 64 } 65 66 /* Test that the environment has been set */ 67 env = rte_power_get_env(); 68 if (env != envs[i]) { 69 printf("Not expected environment configuration\n"); 70 return -1; 71 } 72 73 rte_power_unset_env(); 74 75 } 76 77 return 0; 78 } 79 #endif 80 81 REGISTER_FAST_TEST(power_autotest, true, true, test_power); 82