LCOV - code coverage report
Current view: top level - app/test - test_power_kvm_vm.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 12 92 13.0 %
Date: 2024-12-01 18:57:19 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 54 7.4 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2018 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                 :            : 
      11                 :            : #include "test.h"
      12                 :            : 
      13                 :            : #ifndef RTE_LIB_POWER
      14                 :            : 
      15                 :            : static int
      16                 :            : test_power_kvm_vm(void)
      17                 :            : {
      18                 :            :         printf("Power management library not supported, skipping test\n");
      19                 :            :         return TEST_SKIPPED;
      20                 :            : }
      21                 :            : 
      22                 :            : #else
      23                 :            : #include <rte_power_cpufreq.h>
      24                 :            : 
      25                 :            : #define TEST_POWER_VM_LCORE_ID            0U
      26                 :            : #define TEST_POWER_VM_LCORE_OUT_OF_BOUNDS (RTE_MAX_LCORE+1)
      27                 :            : #define TEST_POWER_VM_LCORE_INVALID       1U
      28                 :            : 
      29                 :            : static int
      30                 :          1 : test_power_kvm_vm(void)
      31                 :            : {
      32                 :            :         int ret;
      33                 :            :         enum power_management_env env;
      34                 :            : 
      35                 :          1 :         ret = rte_power_set_env(PM_ENV_KVM_VM);
      36         [ -  + ]:          1 :         if (ret != 0) {
      37                 :            :                 printf("Failed on setting environment to PM_ENV_KVM_VM\n");
      38                 :          0 :                 return -1;
      39                 :            :         }
      40                 :            : 
      41                 :            :         /* Test environment configuration */
      42                 :          1 :         env = rte_power_get_env();
      43         [ -  + ]:          1 :         if (env != PM_ENV_KVM_VM) {
      44                 :            :                 printf("Unexpectedly got a Power Management environment other than "
      45                 :            :                                 "KVM VM\n");
      46                 :          0 :                 rte_power_unset_env();
      47                 :          0 :                 return -1;
      48                 :            :         }
      49                 :            : 
      50                 :            :         /* Test initialisation of an out of bounds lcore */
      51                 :          1 :         ret = rte_power_init(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
      52         [ -  + ]:          1 :         if (ret != -1) {
      53                 :            :                 printf("rte_power_init unexpectedly succeeded on an invalid lcore %u\n",
      54                 :            :                                 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
      55                 :          0 :                 rte_power_unset_env();
      56                 :          0 :                 return -1;
      57                 :            :         }
      58                 :            : 
      59                 :            :         /* Test initialisation of a valid lcore */
      60                 :          1 :         ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
      61         [ +  - ]:          1 :         if (ret < 0) {
      62                 :            :                 printf("Cannot initialise power management for lcore %u, this "
      63                 :            :                                 "may occur if environment is not configured "
      64                 :            :                                 "correctly(KVM VM) or operating in another valid "
      65                 :            :                                 "Power management environment\n",
      66                 :            :                                 TEST_POWER_VM_LCORE_ID);
      67                 :          1 :                 rte_power_unset_env();
      68                 :          1 :                 return TEST_SKIPPED;
      69                 :            :         }
      70                 :            : 
      71                 :            :         /* Test initialisation of previously initialised lcore */
      72                 :          0 :         ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
      73         [ #  # ]:          0 :         if (ret == 0) {
      74                 :            :                 printf("rte_power_init unexpectedly succeeded on calling init twice on"
      75                 :            :                                 " lcore %u\n", TEST_POWER_VM_LCORE_ID);
      76                 :          0 :                 goto fail_all;
      77                 :            :         }
      78                 :            : 
      79                 :            :         /* Test frequency up of invalid lcore */
      80                 :          0 :         ret = rte_power_freq_up(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
      81         [ #  # ]:          0 :         if (ret == 1) {
      82                 :            :                 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
      83                 :            :                                 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
      84                 :          0 :                 goto fail_all;
      85                 :            :         }
      86                 :            : 
      87                 :            :         /* Test frequency down of invalid lcore */
      88                 :          0 :         ret = rte_power_freq_down(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
      89         [ #  # ]:          0 :         if (ret == 1) {
      90                 :            :                 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
      91                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
      92                 :          0 :                 goto fail_all;
      93                 :            :         }
      94                 :            : 
      95                 :            :         /* Test frequency min of invalid lcore */
      96                 :          0 :         ret = rte_power_freq_min(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
      97         [ #  # ]:          0 :         if (ret == 1) {
      98                 :            :                 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
      99                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     100                 :          0 :                 goto fail_all;
     101                 :            :         }
     102                 :            : 
     103                 :            :         /* Test frequency max of invalid lcore */
     104                 :          0 :         ret = rte_power_freq_max(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     105         [ #  # ]:          0 :         if (ret == 1) {
     106                 :            :                 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
     107                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     108                 :          0 :                 goto fail_all;
     109                 :            :         }
     110                 :            : 
     111                 :            :         /* Test frequency up of valid but uninitialised lcore */
     112                 :          0 :         ret = rte_power_freq_up(TEST_POWER_VM_LCORE_INVALID);
     113         [ #  # ]:          0 :         if (ret == 1) {
     114                 :            :                 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
     115                 :            :                                 TEST_POWER_VM_LCORE_INVALID);
     116                 :          0 :                 goto fail_all;
     117                 :            :         }
     118                 :            : 
     119                 :            :         /* Test frequency down of valid but uninitialised lcore */
     120                 :          0 :         ret = rte_power_freq_down(TEST_POWER_VM_LCORE_INVALID);
     121         [ #  # ]:          0 :         if (ret == 1) {
     122                 :            :                 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
     123                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_INVALID);
     124                 :          0 :                 goto fail_all;
     125                 :            :         }
     126                 :            : 
     127                 :            :         /* Test frequency min of valid but uninitialised lcore */
     128                 :          0 :         ret = rte_power_freq_min(TEST_POWER_VM_LCORE_INVALID);
     129         [ #  # ]:          0 :         if (ret == 1) {
     130                 :            :                 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
     131                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_INVALID);
     132                 :          0 :                 goto fail_all;
     133                 :            :         }
     134                 :            : 
     135                 :            :         /* Test frequency max of valid but uninitialised lcore */
     136                 :          0 :         ret = rte_power_freq_max(TEST_POWER_VM_LCORE_INVALID);
     137         [ #  # ]:          0 :         if (ret == 1) {
     138                 :            :                 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
     139                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_INVALID);
     140                 :          0 :                 goto fail_all;
     141                 :            :         }
     142                 :            : 
     143                 :            :         /* Test KVM_VM Enable Turbo of valid core */
     144                 :          0 :         ret = rte_power_freq_enable_turbo(TEST_POWER_VM_LCORE_ID);
     145         [ #  # ]:          0 :         if (ret == -1) {
     146                 :            :                 printf("rte_power_freq_enable_turbo failed on valid lcore"
     147                 :            :                         "%u\n", TEST_POWER_VM_LCORE_ID);
     148                 :          0 :                 goto fail_all;
     149                 :            :         }
     150                 :            : 
     151                 :            :         /* Test KVM_VM Disable Turbo of valid core */
     152                 :          0 :         ret = rte_power_freq_disable_turbo(TEST_POWER_VM_LCORE_ID);
     153         [ #  # ]:          0 :         if (ret == -1) {
     154                 :            :                 printf("rte_power_freq_disable_turbo failed on valid lcore"
     155                 :            :                 "%u\n", TEST_POWER_VM_LCORE_ID);
     156                 :          0 :                 goto fail_all;
     157                 :            :         }
     158                 :            : 
     159                 :            :         /* Test frequency up of valid lcore */
     160                 :          0 :         ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
     161         [ #  # ]:          0 :         if (ret != 1) {
     162                 :            :                 printf("rte_power_freq_up unexpectedly failed on valid lcore %u\n",
     163                 :            :                                 TEST_POWER_VM_LCORE_ID);
     164                 :          0 :                 goto fail_all;
     165                 :            :         }
     166                 :            : 
     167                 :            :         /* Test frequency down of valid lcore */
     168                 :          0 :         ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
     169         [ #  # ]:          0 :         if (ret != 1) {
     170                 :            :                 printf("rte_power_freq_down unexpectedly failed on valid lcore "
     171                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_ID);
     172                 :          0 :                 goto fail_all;
     173                 :            :         }
     174                 :            : 
     175                 :            :         /* Test frequency min of valid lcore */
     176                 :          0 :         ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
     177         [ #  # ]:          0 :         if (ret != 1) {
     178                 :            :                 printf("rte_power_freq_min unexpectedly failed on valid lcore "
     179                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_ID);
     180                 :          0 :                 goto fail_all;
     181                 :            :         }
     182                 :            : 
     183                 :            :         /* Test frequency max of valid lcore */
     184                 :          0 :         ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
     185         [ #  # ]:          0 :         if (ret != 1) {
     186                 :            :                 printf("rte_power_freq_max unexpectedly failed on valid lcore "
     187                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_ID);
     188                 :          0 :                 goto fail_all;
     189                 :            :         }
     190                 :            : 
     191                 :            :         /* Test unsupported rte_power_freqs */
     192                 :          0 :         ret = rte_power_freqs(TEST_POWER_VM_LCORE_ID, NULL, 0);
     193         [ #  # ]:          0 :         if (ret != -ENOTSUP) {
     194                 :            :                 printf("rte_power_freqs did not return the expected -ENOTSUP(%d) but "
     195                 :            :                                 "returned %d\n", -ENOTSUP, ret);
     196                 :          0 :                 goto fail_all;
     197                 :            :         }
     198                 :            : 
     199                 :            :         /* Test unsupported rte_power_get_freq */
     200                 :          0 :         ret = rte_power_get_freq(TEST_POWER_VM_LCORE_ID);
     201         [ #  # ]:          0 :         if (ret != -ENOTSUP) {
     202                 :            :                 printf("rte_power_get_freq did not return the expected -ENOTSUP(%d) but"
     203                 :            :                                 " returned %d for lcore %u\n",
     204                 :            :                                 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
     205                 :          0 :                 goto fail_all;
     206                 :            :         }
     207                 :            : 
     208                 :            :         /* Test unsupported rte_power_set_freq */
     209                 :          0 :         ret = rte_power_set_freq(TEST_POWER_VM_LCORE_ID, 0);
     210         [ #  # ]:          0 :         if (ret != -ENOTSUP) {
     211                 :            :                 printf("rte_power_set_freq did not return the expected -ENOTSUP(%d) but"
     212                 :            :                                 " returned %d for lcore %u\n",
     213                 :            :                                 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
     214                 :          0 :                 goto fail_all;
     215                 :            :         }
     216                 :            : 
     217                 :            :         /* Test removing of an lcore */
     218                 :          0 :         ret = rte_power_exit(TEST_POWER_VM_LCORE_ID);
     219         [ #  # ]:          0 :         if (ret != 0) {
     220                 :            :                 printf("rte_power_exit unexpectedly failed on valid lcore %u,"
     221                 :            :                                 "please ensure that the environment has been configured "
     222                 :            :                                 "correctly\n", TEST_POWER_VM_LCORE_ID);
     223                 :          0 :                 goto fail_all;
     224                 :            :         }
     225                 :            : 
     226                 :            :         /* Test frequency up of previously removed lcore */
     227                 :          0 :         ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
     228         [ #  # ]:          0 :         if (ret == 0) {
     229                 :            :                 printf("rte_power_freq_up unexpectedly succeeded on a removed "
     230                 :            :                                 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
     231                 :          0 :                 return -1;
     232                 :            :         }
     233                 :            : 
     234                 :            :         /* Test frequency down of previously removed lcore */
     235                 :          0 :         ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
     236         [ #  # ]:          0 :         if (ret == 0) {
     237                 :            :                 printf("rte_power_freq_down unexpectedly succeeded on a removed "
     238                 :            :                                 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
     239                 :          0 :                 return -1;
     240                 :            :         }
     241                 :            : 
     242                 :            :         /* Test frequency min of previously removed lcore */
     243                 :          0 :         ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
     244         [ #  # ]:          0 :         if (ret == 0) {
     245                 :            :                 printf("rte_power_freq_min unexpectedly succeeded on a removed "
     246                 :            :                                 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
     247                 :          0 :                 return -1;
     248                 :            :         }
     249                 :            : 
     250                 :            :         /* Test frequency max of previously removed lcore */
     251                 :          0 :         ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
     252         [ #  # ]:          0 :         if (ret == 0) {
     253                 :            :                 printf("rte_power_freq_max unexpectedly succeeded on a removed "
     254                 :            :                                 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
     255                 :          0 :                 return -1;
     256                 :            :         }
     257                 :          0 :         rte_power_unset_env();
     258                 :          0 :         return 0;
     259                 :          0 : fail_all:
     260                 :          0 :         rte_power_exit(TEST_POWER_VM_LCORE_ID);
     261                 :          0 :         rte_power_unset_env();
     262                 :          0 :         return -1;
     263                 :            : }
     264                 :            : #endif
     265                 :            : 
     266                 :        251 : REGISTER_FAST_TEST(power_kvm_vm_autotest, false, true, test_power_kvm_vm);

Generated by: LCOV version 1.14