LCOV - code coverage report
Current view: top level - app/test - test_power.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 33 54 61.1 %
Date: 2024-01-22 16:26:08 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 42 57.1 %

           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.h>
      26                 :            : 
      27                 :            : static int
      28                 :         11 : check_function_ptrs(void)
      29                 :            : {
      30                 :         11 :         enum power_management_env env = rte_power_get_env();
      31                 :            : 
      32                 :         11 :         const bool not_null_expected = !(env == PM_ENV_NOT_SET);
      33                 :            : 
      34         [ +  + ]:         11 :         const char *inject_not_string1 = not_null_expected ? " not" : "";
      35         [ +  + ]:         11 :         const char *inject_not_string2 = not_null_expected ? "" : " not";
      36                 :            : 
      37         [ -  + ]:         11 :         if ((rte_power_freqs == NULL) == not_null_expected) {
      38                 :            :                 printf("rte_power_freqs should%s be NULL, environment has%s been "
      39                 :            :                                 "initialised\n", inject_not_string1,
      40                 :            :                                         inject_not_string2);
      41                 :          0 :                 return -1;
      42                 :            :         }
      43         [ -  + ]:         11 :         if ((rte_power_get_freq == NULL) == not_null_expected) {
      44                 :            :                 printf("rte_power_get_freq should%s be NULL, environment has%s been "
      45                 :            :                                 "initialised\n", inject_not_string1,
      46                 :            :                                         inject_not_string2);
      47                 :          0 :                 return -1;
      48                 :            :         }
      49         [ -  + ]:         11 :         if ((rte_power_set_freq == NULL) == not_null_expected) {
      50                 :            :                 printf("rte_power_set_freq should%s be NULL, environment has%s been "
      51                 :            :                                 "initialised\n", inject_not_string1,
      52                 :            :                                 inject_not_string2);
      53                 :          0 :                 return -1;
      54                 :            :         }
      55         [ -  + ]:         11 :         if ((rte_power_freq_up == NULL) == not_null_expected) {
      56                 :            :                 printf("rte_power_freq_up should%s be NULL, environment has%s been "
      57                 :            :                                 "initialised\n", inject_not_string1,
      58                 :            :                                 inject_not_string2);
      59                 :          0 :                 return -1;
      60                 :            :         }
      61         [ -  + ]:         11 :         if ((rte_power_freq_down == NULL) == not_null_expected) {
      62                 :            :                 printf("rte_power_freq_down should%s be NULL, environment has%s been "
      63                 :            :                                 "initialised\n", inject_not_string1,
      64                 :            :                                 inject_not_string2);
      65                 :          0 :                 return -1;
      66                 :            :         }
      67         [ -  + ]:         11 :         if ((rte_power_freq_max == NULL) == not_null_expected) {
      68                 :            :                 printf("rte_power_freq_max should%s be NULL, environment has%s been "
      69                 :            :                                 "initialised\n", inject_not_string1,
      70                 :            :                                 inject_not_string2);
      71                 :          0 :                 return -1;
      72                 :            :         }
      73         [ -  + ]:         11 :         if ((rte_power_freq_min == NULL) == not_null_expected) {
      74                 :            :                 printf("rte_power_freq_min should%s be NULL, environment has%s been "
      75                 :            :                                 "initialised\n", inject_not_string1,
      76                 :            :                                 inject_not_string2);
      77                 :          0 :                 return -1;
      78                 :            :         }
      79         [ -  + ]:         11 :         if ((rte_power_turbo_status == NULL) == not_null_expected) {
      80                 :            :                 printf("rte_power_turbo_status should%s be NULL, environment has%s been "
      81                 :            :                                 "initialised\n", inject_not_string1,
      82                 :            :                                 inject_not_string2);
      83                 :          0 :                 return -1;
      84                 :            :         }
      85         [ -  + ]:         11 :         if ((rte_power_freq_enable_turbo == NULL) == not_null_expected) {
      86                 :            :                 printf("rte_power_freq_enable_turbo should%s be NULL, environment has%s been "
      87                 :            :                                 "initialised\n", inject_not_string1,
      88                 :            :                                 inject_not_string2);
      89                 :          0 :                 return -1;
      90                 :            :         }
      91         [ -  + ]:         11 :         if ((rte_power_freq_disable_turbo == NULL) == not_null_expected) {
      92                 :            :                 printf("rte_power_freq_disable_turbo should%s be NULL, environment has%s been "
      93                 :            :                                 "initialised\n", inject_not_string1,
      94                 :            :                                 inject_not_string2);
      95                 :          0 :                 return -1;
      96                 :            :         }
      97         [ -  + ]:         11 :         if ((rte_power_get_capabilities == NULL) == not_null_expected) {
      98                 :            :                 printf("rte_power_get_capabilities should%s be NULL, environment has%s been "
      99                 :            :                                 "initialised\n", inject_not_string1,
     100                 :            :                                 inject_not_string2);
     101                 :          0 :                 return -1;
     102                 :            :         }
     103                 :            : 
     104                 :            :         return 0;
     105                 :            : }
     106                 :            : 
     107                 :            : static int
     108                 :          1 : test_power(void)
     109                 :            : {
     110                 :            :         int ret = -1;
     111                 :            :         enum power_management_env env;
     112                 :            : 
     113                 :            :         /* Test setting an invalid environment */
     114                 :          1 :         ret = rte_power_set_env(PM_ENV_NOT_SET);
     115         [ -  + ]:          1 :         if (ret == 0) {
     116                 :            :                 printf("Unexpectedly succeeded on setting an invalid environment\n");
     117                 :          0 :                 return -1;
     118                 :            :         }
     119                 :            : 
     120                 :            :         /* Test that the environment has not been set */
     121                 :          1 :         env = rte_power_get_env();
     122         [ -  + ]:          1 :         if (env != PM_ENV_NOT_SET) {
     123                 :            :                 printf("Unexpectedly got a valid environment configuration\n");
     124                 :          0 :                 return -1;
     125                 :            :         }
     126                 :            : 
     127                 :            :         /* Verify that function pointers are NULL */
     128         [ -  + ]:          1 :         if (check_function_ptrs() < 0)
     129                 :          0 :                 goto fail_all;
     130                 :            : 
     131                 :          1 :         rte_power_unset_env();
     132                 :            : 
     133                 :            :         /* Perform tests for valid environments.*/
     134                 :          1 :         const enum power_management_env envs[] = {PM_ENV_ACPI_CPUFREQ,
     135                 :            :                         PM_ENV_KVM_VM,
     136                 :            :                         PM_ENV_PSTATE_CPUFREQ,
     137                 :            :                         PM_ENV_AMD_PSTATE_CPUFREQ,
     138                 :            :                         PM_ENV_CPPC_CPUFREQ};
     139                 :            : 
     140                 :            :         unsigned int i;
     141         [ +  + ]:          6 :         for (i = 0; i < RTE_DIM(envs); ++i) {
     142                 :            : 
     143                 :            :                 /* Test setting a valid environment */
     144                 :          5 :                 ret = rte_power_set_env(envs[i]);
     145         [ -  + ]:          5 :                 if (ret != 0) {
     146                 :            :                         printf("Unexpectedly unsucceeded on setting a valid environment\n");
     147                 :          0 :                         return -1;
     148                 :            :                 }
     149                 :            : 
     150                 :            :                 /* Test that the environment has been set */
     151                 :          5 :                 env = rte_power_get_env();
     152         [ -  + ]:          5 :                 if (env != envs[i]) {
     153                 :            :                         printf("Not expected environment configuration\n");
     154                 :          0 :                         return -1;
     155                 :            :                 }
     156                 :            : 
     157                 :            :                 /* Verify that function pointers are NOT NULL */
     158         [ -  + ]:          5 :                 if (check_function_ptrs() < 0)
     159                 :          0 :                         goto fail_all;
     160                 :            : 
     161                 :          5 :                 rte_power_unset_env();
     162                 :            : 
     163                 :            :                 /* Verify that function pointers are NULL */
     164         [ -  + ]:          5 :                 if (check_function_ptrs() < 0)
     165                 :          0 :                         goto fail_all;
     166                 :            : 
     167                 :            :         }
     168                 :            : 
     169                 :            :         return 0;
     170                 :          0 : fail_all:
     171                 :          0 :         rte_power_unset_env();
     172                 :          0 :         return -1;
     173                 :            : }
     174                 :            : #endif
     175                 :            : 
     176                 :        235 : REGISTER_FAST_TEST(power_autotest, true, true, test_power);

Generated by: LCOV version 1.14