LCOV - code coverage report
Current view: top level - app/test - test_power_kvm_vm.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 19 106 17.9 %
Date: 2024-02-14 00:53:57 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 68 16.2 %

           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.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                 :            :         /* verify that function pointers are not NULL */
      51         [ -  + ]:          1 :         if (rte_power_freqs == NULL) {
      52                 :            :                 printf("rte_power_freqs should not be NULL, environment has not been "
      53                 :            :                                 "initialised\n");
      54                 :          0 :                 return -1;
      55                 :            :         }
      56         [ -  + ]:          1 :         if (rte_power_get_freq == NULL) {
      57                 :            :                 printf("rte_power_get_freq should not be NULL, environment has not "
      58                 :            :                                 "been initialised\n");
      59                 :          0 :                 return -1;
      60                 :            :         }
      61         [ -  + ]:          1 :         if (rte_power_set_freq == NULL) {
      62                 :            :                 printf("rte_power_set_freq should not be NULL, environment has not "
      63                 :            :                                 "been initialised\n");
      64                 :          0 :                 return -1;
      65                 :            :         }
      66         [ -  + ]:          1 :         if (rte_power_freq_up == NULL) {
      67                 :            :                 printf("rte_power_freq_up should not be NULL, environment has not "
      68                 :            :                                 "been initialised\n");
      69                 :          0 :                 return -1;
      70                 :            :         }
      71         [ -  + ]:          1 :         if (rte_power_freq_down == NULL) {
      72                 :            :                 printf("rte_power_freq_down should not be NULL, environment has not "
      73                 :            :                                 "been initialised\n");
      74                 :          0 :                 return -1;
      75                 :            :         }
      76         [ -  + ]:          1 :         if (rte_power_freq_max == NULL) {
      77                 :            :                 printf("rte_power_freq_max should not be NULL, environment has not "
      78                 :            :                                 "been initialised\n");
      79                 :          0 :                 return -1;
      80                 :            :         }
      81         [ -  + ]:          1 :         if (rte_power_freq_min == NULL) {
      82                 :            :                 printf("rte_power_freq_min should not be NULL, environment has not "
      83                 :            :                                 "been initialised\n");
      84                 :          0 :                 return -1;
      85                 :            :         }
      86                 :            :         /* Test initialisation of an out of bounds lcore */
      87                 :          1 :         ret = rte_power_init(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
      88         [ -  + ]:          1 :         if (ret != -1) {
      89                 :            :                 printf("rte_power_init unexpectedly succeeded on an invalid lcore %u\n",
      90                 :            :                                 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
      91                 :          0 :                 rte_power_unset_env();
      92                 :          0 :                 return -1;
      93                 :            :         }
      94                 :            : 
      95                 :            :         /* Test initialisation of a valid lcore */
      96                 :          1 :         ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
      97         [ +  - ]:          1 :         if (ret < 0) {
      98                 :            :                 printf("Cannot initialise power management for lcore %u, this "
      99                 :            :                                 "may occur if environment is not configured "
     100                 :            :                                 "correctly(KVM VM) or operating in another valid "
     101                 :            :                                 "Power management environment\n",
     102                 :            :                                 TEST_POWER_VM_LCORE_ID);
     103                 :          1 :                 rte_power_unset_env();
     104                 :          1 :                 return TEST_SKIPPED;
     105                 :            :         }
     106                 :            : 
     107                 :            :         /* Test initialisation of previously initialised lcore */
     108                 :          0 :         ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
     109         [ #  # ]:          0 :         if (ret == 0) {
     110                 :            :                 printf("rte_power_init unexpectedly succeeded on calling init twice on"
     111                 :            :                                 " lcore %u\n", TEST_POWER_VM_LCORE_ID);
     112                 :          0 :                 goto fail_all;
     113                 :            :         }
     114                 :            : 
     115                 :            :         /* Test frequency up of invalid lcore */
     116                 :          0 :         ret = rte_power_freq_up(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     117         [ #  # ]:          0 :         if (ret == 1) {
     118                 :            :                 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
     119                 :            :                                 TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     120                 :          0 :                 goto fail_all;
     121                 :            :         }
     122                 :            : 
     123                 :            :         /* Test frequency down of invalid lcore */
     124                 :          0 :         ret = rte_power_freq_down(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     125         [ #  # ]:          0 :         if (ret == 1) {
     126                 :            :                 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
     127                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     128                 :          0 :                 goto fail_all;
     129                 :            :         }
     130                 :            : 
     131                 :            :         /* Test frequency min of invalid lcore */
     132                 :          0 :         ret = rte_power_freq_min(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     133         [ #  # ]:          0 :         if (ret == 1) {
     134                 :            :                 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
     135                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     136                 :          0 :                 goto fail_all;
     137                 :            :         }
     138                 :            : 
     139                 :            :         /* Test frequency max of invalid lcore */
     140                 :          0 :         ret = rte_power_freq_max(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     141         [ #  # ]:          0 :         if (ret == 1) {
     142                 :            :                 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
     143                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_OUT_OF_BOUNDS);
     144                 :          0 :                 goto fail_all;
     145                 :            :         }
     146                 :            : 
     147                 :            :         /* Test frequency up of valid but uninitialised lcore */
     148                 :          0 :         ret = rte_power_freq_up(TEST_POWER_VM_LCORE_INVALID);
     149         [ #  # ]:          0 :         if (ret == 1) {
     150                 :            :                 printf("rte_power_freq_up unexpectedly succeeded on invalid lcore %u\n",
     151                 :            :                                 TEST_POWER_VM_LCORE_INVALID);
     152                 :          0 :                 goto fail_all;
     153                 :            :         }
     154                 :            : 
     155                 :            :         /* Test frequency down of valid but uninitialised lcore */
     156                 :          0 :         ret = rte_power_freq_down(TEST_POWER_VM_LCORE_INVALID);
     157         [ #  # ]:          0 :         if (ret == 1) {
     158                 :            :                 printf("rte_power_freq_down unexpectedly succeeded on invalid lcore "
     159                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_INVALID);
     160                 :          0 :                 goto fail_all;
     161                 :            :         }
     162                 :            : 
     163                 :            :         /* Test frequency min of valid but uninitialised lcore */
     164                 :          0 :         ret = rte_power_freq_min(TEST_POWER_VM_LCORE_INVALID);
     165         [ #  # ]:          0 :         if (ret == 1) {
     166                 :            :                 printf("rte_power_freq_min unexpectedly succeeded on invalid lcore "
     167                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_INVALID);
     168                 :          0 :                 goto fail_all;
     169                 :            :         }
     170                 :            : 
     171                 :            :         /* Test frequency max of valid but uninitialised lcore */
     172                 :          0 :         ret = rte_power_freq_max(TEST_POWER_VM_LCORE_INVALID);
     173         [ #  # ]:          0 :         if (ret == 1) {
     174                 :            :                 printf("rte_power_freq_max unexpectedly succeeded on invalid lcore "
     175                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_INVALID);
     176                 :          0 :                 goto fail_all;
     177                 :            :         }
     178                 :            : 
     179                 :            :         /* Test KVM_VM Enable Turbo of valid core */
     180                 :          0 :         ret = rte_power_freq_enable_turbo(TEST_POWER_VM_LCORE_ID);
     181         [ #  # ]:          0 :         if (ret == -1) {
     182                 :            :                 printf("rte_power_freq_enable_turbo failed on valid lcore"
     183                 :            :                         "%u\n", TEST_POWER_VM_LCORE_ID);
     184                 :          0 :                 goto fail_all;
     185                 :            :         }
     186                 :            : 
     187                 :            :         /* Test KVM_VM Disable Turbo of valid core */
     188                 :          0 :         ret = rte_power_freq_disable_turbo(TEST_POWER_VM_LCORE_ID);
     189         [ #  # ]:          0 :         if (ret == -1) {
     190                 :            :                 printf("rte_power_freq_disable_turbo failed on valid lcore"
     191                 :            :                 "%u\n", TEST_POWER_VM_LCORE_ID);
     192                 :          0 :                 goto fail_all;
     193                 :            :         }
     194                 :            : 
     195                 :            :         /* Test frequency up of valid lcore */
     196                 :          0 :         ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
     197         [ #  # ]:          0 :         if (ret != 1) {
     198                 :            :                 printf("rte_power_freq_up unexpectedly failed on valid lcore %u\n",
     199                 :            :                                 TEST_POWER_VM_LCORE_ID);
     200                 :          0 :                 goto fail_all;
     201                 :            :         }
     202                 :            : 
     203                 :            :         /* Test frequency down of valid lcore */
     204                 :          0 :         ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
     205         [ #  # ]:          0 :         if (ret != 1) {
     206                 :            :                 printf("rte_power_freq_down unexpectedly failed on valid lcore "
     207                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_ID);
     208                 :          0 :                 goto fail_all;
     209                 :            :         }
     210                 :            : 
     211                 :            :         /* Test frequency min of valid lcore */
     212                 :          0 :         ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
     213         [ #  # ]:          0 :         if (ret != 1) {
     214                 :            :                 printf("rte_power_freq_min unexpectedly failed on valid lcore "
     215                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_ID);
     216                 :          0 :                 goto fail_all;
     217                 :            :         }
     218                 :            : 
     219                 :            :         /* Test frequency max of valid lcore */
     220                 :          0 :         ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
     221         [ #  # ]:          0 :         if (ret != 1) {
     222                 :            :                 printf("rte_power_freq_max unexpectedly failed on valid lcore "
     223                 :            :                                 "%u\n", TEST_POWER_VM_LCORE_ID);
     224                 :          0 :                 goto fail_all;
     225                 :            :         }
     226                 :            : 
     227                 :            :         /* Test unsupported rte_power_freqs */
     228                 :          0 :         ret = rte_power_freqs(TEST_POWER_VM_LCORE_ID, NULL, 0);
     229         [ #  # ]:          0 :         if (ret != -ENOTSUP) {
     230                 :            :                 printf("rte_power_freqs did not return the expected -ENOTSUP(%d) but "
     231                 :            :                                 "returned %d\n", -ENOTSUP, ret);
     232                 :          0 :                 goto fail_all;
     233                 :            :         }
     234                 :            : 
     235                 :            :         /* Test unsupported rte_power_get_freq */
     236                 :          0 :         ret = rte_power_get_freq(TEST_POWER_VM_LCORE_ID);
     237         [ #  # ]:          0 :         if (ret != -ENOTSUP) {
     238                 :            :                 printf("rte_power_get_freq did not return the expected -ENOTSUP(%d) but"
     239                 :            :                                 " returned %d for lcore %u\n",
     240                 :            :                                 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
     241                 :          0 :                 goto fail_all;
     242                 :            :         }
     243                 :            : 
     244                 :            :         /* Test unsupported rte_power_set_freq */
     245                 :          0 :         ret = rte_power_set_freq(TEST_POWER_VM_LCORE_ID, 0);
     246         [ #  # ]:          0 :         if (ret != -ENOTSUP) {
     247                 :            :                 printf("rte_power_set_freq did not return the expected -ENOTSUP(%d) but"
     248                 :            :                                 " returned %d for lcore %u\n",
     249                 :            :                                 -ENOTSUP, ret, TEST_POWER_VM_LCORE_ID);
     250                 :          0 :                 goto fail_all;
     251                 :            :         }
     252                 :            : 
     253                 :            :         /* Test removing of an lcore */
     254                 :          0 :         ret = rte_power_exit(TEST_POWER_VM_LCORE_ID);
     255         [ #  # ]:          0 :         if (ret != 0) {
     256                 :            :                 printf("rte_power_exit unexpectedly failed on valid lcore %u,"
     257                 :            :                                 "please ensure that the environment has been configured "
     258                 :            :                                 "correctly\n", TEST_POWER_VM_LCORE_ID);
     259                 :          0 :                 goto fail_all;
     260                 :            :         }
     261                 :            : 
     262                 :            :         /* Test frequency up of previously removed lcore */
     263                 :          0 :         ret = rte_power_freq_up(TEST_POWER_VM_LCORE_ID);
     264         [ #  # ]:          0 :         if (ret == 0) {
     265                 :            :                 printf("rte_power_freq_up unexpectedly succeeded on a removed "
     266                 :            :                                 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
     267                 :          0 :                 return -1;
     268                 :            :         }
     269                 :            : 
     270                 :            :         /* Test frequency down of previously removed lcore */
     271                 :          0 :         ret = rte_power_freq_down(TEST_POWER_VM_LCORE_ID);
     272         [ #  # ]:          0 :         if (ret == 0) {
     273                 :            :                 printf("rte_power_freq_down unexpectedly succeeded on a removed "
     274                 :            :                                 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
     275                 :          0 :                 return -1;
     276                 :            :         }
     277                 :            : 
     278                 :            :         /* Test frequency min of previously removed lcore */
     279                 :          0 :         ret = rte_power_freq_min(TEST_POWER_VM_LCORE_ID);
     280         [ #  # ]:          0 :         if (ret == 0) {
     281                 :            :                 printf("rte_power_freq_min unexpectedly succeeded on a removed "
     282                 :            :                                 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
     283                 :          0 :                 return -1;
     284                 :            :         }
     285                 :            : 
     286                 :            :         /* Test frequency max of previously removed lcore */
     287                 :          0 :         ret = rte_power_freq_max(TEST_POWER_VM_LCORE_ID);
     288         [ #  # ]:          0 :         if (ret == 0) {
     289                 :            :                 printf("rte_power_freq_max unexpectedly succeeded on a removed "
     290                 :            :                                 "lcore %u\n", TEST_POWER_VM_LCORE_ID);
     291                 :          0 :                 return -1;
     292                 :            :         }
     293                 :          0 :         rte_power_unset_env();
     294                 :          0 :         return 0;
     295                 :          0 : fail_all:
     296                 :          0 :         rte_power_exit(TEST_POWER_VM_LCORE_ID);
     297                 :          0 :         rte_power_unset_env();
     298                 :          0 :         return -1;
     299                 :            : }
     300                 :            : #endif
     301                 :            : 
     302                 :        235 : REGISTER_FAST_TEST(power_kvm_vm_autotest, false, true, test_power_kvm_vm);

Generated by: LCOV version 1.14