vhost: fix sprintf with snprintf
[dpdk.git] / test / test / test_power_acpi_cpufreq.c
index ad948fb..61b1da0 100644 (file)
@@ -7,9 +7,27 @@
 #include <unistd.h>
 #include <limits.h>
 #include <string.h>
+#include <inttypes.h>
 
 #include "test.h"
 
+#ifndef RTE_LIBRTE_POWER
+
+static int
+test_power_acpi_cpufreq(void)
+{
+       printf("Power management library not supported, skipping test\n");
+       return TEST_SKIPPED;
+}
+
+static int
+test_power_acpi_caps(void)
+{
+       printf("Power management library not supported, skipping test\n");
+       return TEST_SKIPPED;
+}
+
+#else
 #include <rte_power.h>
 
 #define TEST_POWER_LCORE_ID      2U
@@ -17,7 +35,7 @@
 #define TEST_POWER_FREQS_NUM_MAX ((unsigned)RTE_MAX_LCORE_FREQS)
 
 #define TEST_POWER_SYSFILE_CUR_FREQ \
-       "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq"
+       "/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_cur_freq"
 
 static uint32_t total_freq_num;
 static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX];
@@ -354,18 +372,22 @@ test_power_acpi_cpufreq(void)
        int ret = -1;
        enum power_management_env env;
 
-       ret = rte_power_set_env(PM_ENV_ACPI_CPUFREQ);
-       if (ret != 0) {
-               printf("Failed on setting environment to PM_ENV_ACPI_CPUFREQ, this "
-                               "may occur if environment is not configured correctly or "
-                               " operating in another valid Power management environment\n");
-               return -1;
+       /* Test initialisation of a valid lcore */
+       ret = rte_power_init(TEST_POWER_LCORE_ID);
+       if (ret < 0) {
+               printf("Cannot initialise power management for lcore %u, this "
+                               "may occur if environment is not configured "
+                               "correctly(APCI cpufreq) or operating in another valid "
+                               "Power management environment\n",
+                               TEST_POWER_LCORE_ID);
+               rte_power_unset_env();
+               return TEST_SKIPPED;
        }
 
        /* Test environment configuration */
        env = rte_power_get_env();
-       if (env != PM_ENV_ACPI_CPUFREQ) {
-               printf("Unexpectedly got an environment other than ACPI cpufreq\n");
+       if ((env != PM_ENV_ACPI_CPUFREQ) && (env != PM_ENV_PSTATE_CPUFREQ)) {
+               printf("Unexpectedly got an environment other than ACPI/PSTATE\n");
                goto fail_all;
        }
 
@@ -406,6 +428,14 @@ test_power_acpi_cpufreq(void)
                goto fail_all;
        }
 
+       ret = rte_power_exit(TEST_POWER_LCORE_ID);
+       if (ret < 0) {
+               printf("Cannot exit power management for lcore %u\n",
+                                               TEST_POWER_LCORE_ID);
+               rte_power_unset_env();
+               return -1;
+       }
+
        /* test of init power management for an invalid lcore */
        ret = rte_power_init(TEST_POWER_LCORE_INVALID);
        if (ret == 0) {
@@ -423,7 +453,7 @@ test_power_acpi_cpufreq(void)
                                "correctly(APCI cpufreq) or operating in another valid "
                                "Power management environment\n", TEST_POWER_LCORE_ID);
                rte_power_unset_env();
-               return -1;
+               return TEST_SKIPPED;
        }
 
        /**
@@ -508,4 +538,35 @@ fail_all:
        return -1;
 }
 
+static int
+test_power_acpi_caps(void)
+{
+       struct rte_power_core_capabilities caps;
+       int ret;
+
+       ret = rte_power_init(TEST_POWER_LCORE_ID);
+       if (ret < 0) {
+               printf("Cannot initialise power management for lcore %u, this "
+                       "may occur if environment is not configured "
+                       "correctly(APCI cpufreq) or operating in another valid "
+                       "Power management environment\n", TEST_POWER_LCORE_ID);
+               rte_power_unset_env();
+               return -1;
+       }
+
+       ret = rte_power_get_capabilities(TEST_POWER_LCORE_ID, &caps);
+       if (ret) {
+               printf("POWER: Error getting capabilities\n");
+               return -1;
+       }
+
+       printf("POWER: Capabilities %"PRIx64"\n", caps.capabilities);
+
+       rte_power_unset_env();
+       return 0;
+}
+
+#endif
+
 REGISTER_TEST_COMMAND(power_acpi_cpufreq_autotest, test_power_acpi_cpufreq);
+REGISTER_TEST_COMMAND(power_acpi_caps_autotest, test_power_acpi_caps);