LCOV - code coverage report
Current view: top level - app/test - test_power.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 14 18 77.8 %
Date: 2025-02-01 18:54:23 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 10 60.0 %

           Branch data     Line data    Source code
       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                 :          1 : test_power(void)
      29                 :            : {
      30                 :            :         int ret = -1;
      31                 :            :         enum power_management_env env;
      32                 :            : 
      33                 :            :         /* Test setting an invalid environment */
      34                 :          1 :         ret = rte_power_set_env(PM_ENV_NOT_SET);
      35         [ -  + ]:          1 :         if (ret == 0) {
      36                 :            :                 printf("Unexpectedly succeeded on setting an invalid environment\n");
      37                 :          0 :                 return -1;
      38                 :            :         }
      39                 :            : 
      40                 :            :         /* Test that the environment has not been set */
      41                 :          1 :         env = rte_power_get_env();
      42         [ -  + ]:          1 :         if (env != PM_ENV_NOT_SET) {
      43                 :            :                 printf("Unexpectedly got a valid environment configuration\n");
      44                 :          0 :                 return -1;
      45                 :            :         }
      46                 :            : 
      47                 :          1 :         rte_power_unset_env();
      48                 :            : 
      49                 :            :         /* Perform tests for valid environments.*/
      50                 :          1 :         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         [ +  + ]:          6 :         for (i = 0; i < RTE_DIM(envs); ++i) {
      58                 :            : 
      59                 :            :                 /* Test setting a valid environment */
      60                 :          5 :                 ret = rte_power_set_env(envs[i]);
      61         [ -  + ]:          5 :                 if (ret != 0) {
      62                 :            :                         printf("Unexpectedly unsuccessful on setting a valid environment\n");
      63                 :          0 :                         return -1;
      64                 :            :                 }
      65                 :            : 
      66                 :            :                 /* Test that the environment has been set */
      67                 :          5 :                 env = rte_power_get_env();
      68         [ -  + ]:          5 :                 if (env != envs[i]) {
      69                 :            :                         printf("Not expected environment configuration\n");
      70                 :          0 :                         return -1;
      71                 :            :                 }
      72                 :            : 
      73                 :          5 :                 rte_power_unset_env();
      74                 :            : 
      75                 :            :         }
      76                 :            : 
      77                 :            :         return 0;
      78                 :            : }
      79                 :            : #endif
      80                 :            : 
      81                 :        252 : REGISTER_FAST_TEST(power_autotest, true, true, test_power);

Generated by: LCOV version 1.14