LCOV - code coverage report
Current view: top level - app/test - test_meter.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 238 337 70.6 %
Date: 2024-12-01 18:57:19 Functions: 14 14 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 113 226 50.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 <stdlib.h>
       6                 :            : #include <stdio.h>
       7                 :            : #include <string.h>
       8                 :            : #include <stdint.h>
       9                 :            : #include <unistd.h>
      10                 :            : 
      11                 :            : #include "test.h"
      12                 :            : 
      13                 :            : #include <rte_cycles.h>
      14                 :            : #include <rte_meter.h>
      15                 :            : 
      16                 :            : #define mlog(format, ...) do{\
      17                 :            :                 printf("Line %d:",__LINE__);\
      18                 :            :                 printf(format, ##__VA_ARGS__);\
      19                 :            :                 printf("\n");\
      20                 :            :         }while(0);
      21                 :            : 
      22                 :            : #define melog(format, ...) do{\
      23                 :            :                 printf("Line %d:",__LINE__);\
      24                 :            :                 printf(format, ##__VA_ARGS__);\
      25                 :            :                 printf(" failed!\n");\
      26                 :            :                 return -1;\
      27                 :            :         }while(0);
      28                 :            : 
      29                 :            : #define TM_TEST_SRTCM_CIR_DF 46000000
      30                 :            : #define TM_TEST_SRTCM_CBS_DF 2048
      31                 :            : #define TM_TEST_SRTCM_EBS_DF 4096
      32                 :            : 
      33                 :            : #define TM_TEST_TRTCM_CIR_DF 46000000
      34                 :            : #define TM_TEST_TRTCM_PIR_DF 69000000
      35                 :            : #define TM_TEST_TRTCM_EIR_DF 69000000
      36                 :            : #define TM_TEST_TRTCM_CBS_DF 2048
      37                 :            : #define TM_TEST_TRTCM_PBS_DF 4096
      38                 :            : #define TM_TEST_TRTCM_EBS_DF 4096
      39                 :            : 
      40                 :            : static struct rte_meter_srtcm_params sparams =
      41                 :            :                                 {.cir = TM_TEST_SRTCM_CIR_DF,
      42                 :            :                                  .cbs = TM_TEST_SRTCM_CBS_DF,
      43                 :            :                                  .ebs = TM_TEST_SRTCM_EBS_DF,};
      44                 :            : 
      45                 :            : static struct   rte_meter_trtcm_params tparams=
      46                 :            :                                 {.cir = TM_TEST_TRTCM_CIR_DF,
      47                 :            :                                  .pir = TM_TEST_TRTCM_PIR_DF,
      48                 :            :                                  .cbs = TM_TEST_TRTCM_CBS_DF,
      49                 :            :                                  .pbs = TM_TEST_TRTCM_PBS_DF,};
      50                 :            : 
      51                 :            : static struct rte_meter_trtcm_rfc4115_params rfc4115params =
      52                 :            :                                 {.cir = TM_TEST_TRTCM_CIR_DF,
      53                 :            :                                  .eir = TM_TEST_TRTCM_EIR_DF,
      54                 :            :                                  .cbs = TM_TEST_TRTCM_CBS_DF,
      55                 :            :                                  .ebs = TM_TEST_TRTCM_EBS_DF,};
      56                 :            : 
      57                 :            : /**
      58                 :            :  * functional test for rte_meter_srtcm_config
      59                 :            :  */
      60                 :            : static inline int
      61                 :          1 : tm_test_srtcm_config(void)
      62                 :            : {
      63                 :            : #define SRTCM_CFG_MSG "srtcm_config"
      64                 :            :         struct rte_meter_srtcm_profile sp;
      65                 :            :         struct  rte_meter_srtcm_params sparams1;
      66                 :            : 
      67                 :            :         /* invalid parameter test */
      68         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(NULL, NULL) == 0)
      69                 :          0 :                 melog(SRTCM_CFG_MSG);
      70         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, NULL) == 0)
      71                 :          0 :                 melog(SRTCM_CFG_MSG);
      72         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(NULL, &sparams) == 0)
      73                 :          0 :                 melog(SRTCM_CFG_MSG);
      74                 :            : 
      75                 :            :         /* cbs and ebs can't both be zero */
      76                 :          1 :         sparams1 = sparams;
      77                 :          1 :         sparams1.cbs = 0;
      78                 :          1 :         sparams1.ebs = 0;
      79         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, &sparams1) == 0)
      80                 :          0 :                 melog(SRTCM_CFG_MSG);
      81                 :            : 
      82                 :            :         /* cir should never be 0 */
      83                 :          1 :         sparams1 = sparams;
      84                 :          1 :         sparams1.cir = 0;
      85         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, &sparams1) == 0)
      86                 :          0 :                 melog(SRTCM_CFG_MSG);
      87                 :            : 
      88                 :            :         /* one of ebs and cbs can be zero, should be successful */
      89                 :          1 :         sparams1 = sparams;
      90                 :          1 :         sparams1.ebs = 0;
      91         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, &sparams1) != 0)
      92                 :          0 :                 melog(SRTCM_CFG_MSG);
      93                 :            : 
      94                 :          1 :         sparams1 = sparams;
      95                 :          1 :         sparams1.cbs = 0;
      96         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, &sparams1) != 0)
      97                 :          0 :                 melog(SRTCM_CFG_MSG);
      98                 :            : 
      99                 :            :         /* usual parameter, should be successful */
     100         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
     101                 :          0 :                 melog(SRTCM_CFG_MSG);
     102                 :            : 
     103                 :            :         return 0;
     104                 :            : 
     105                 :            : }
     106                 :            : 
     107                 :            : /**
     108                 :            :  * functional test for rte_meter_trtcm_config
     109                 :            :  */
     110                 :            : static inline int
     111                 :          1 : tm_test_trtcm_config(void)
     112                 :            : {
     113                 :            :         struct rte_meter_trtcm_profile tp;
     114                 :            :         struct  rte_meter_trtcm_params tparams1;
     115                 :            : #define TRTCM_CFG_MSG "trtcm_config"
     116                 :            : 
     117                 :            :         /* invalid parameter test */
     118         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(NULL, NULL) == 0)
     119                 :          0 :                 melog(TRTCM_CFG_MSG);
     120         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, NULL) == 0)
     121                 :          0 :                 melog(TRTCM_CFG_MSG);
     122         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(NULL, &tparams) == 0)
     123                 :          0 :                 melog(TRTCM_CFG_MSG);
     124                 :            : 
     125                 :            :         /* cir, cbs, pir and pbs never be zero */
     126                 :          1 :         tparams1 = tparams;
     127                 :          1 :         tparams1.cir = 0;
     128         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
     129                 :          0 :                 melog(TRTCM_CFG_MSG);
     130                 :            : 
     131                 :          1 :         tparams1 = tparams;
     132                 :          1 :         tparams1.cbs = 0;
     133         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
     134                 :          0 :                 melog(TRTCM_CFG_MSG);
     135                 :            : 
     136                 :          1 :         tparams1 = tparams;
     137                 :          1 :         tparams1.pbs = 0;
     138         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
     139                 :          0 :                 melog(TRTCM_CFG_MSG);
     140                 :            : 
     141                 :          1 :         tparams1 = tparams;
     142                 :          1 :         tparams1.pir = 0;
     143         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
     144                 :          0 :                 melog(TRTCM_CFG_MSG);
     145                 :            : 
     146                 :            :         /* pir should be greater or equal to cir */
     147                 :          1 :         tparams1 = tparams;
     148                 :          1 :         tparams1.pir = tparams1.cir - 1;
     149         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
     150                 :          0 :                 melog(TRTCM_CFG_MSG" pir < cir test");
     151                 :            : 
     152                 :            :         /* usual parameter, should be successful */
     153         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
     154                 :          0 :                 melog(TRTCM_CFG_MSG);
     155                 :            : 
     156                 :            :         return 0;
     157                 :            : }
     158                 :            : 
     159                 :            : /**
     160                 :            :  * functional test for rte_meter_trtcm_rfc4115_config
     161                 :            :  */
     162                 :            : static inline int
     163                 :          1 : tm_test_trtcm_rfc4115_config(void)
     164                 :            : {
     165                 :            :         struct rte_meter_trtcm_rfc4115_profile tp;
     166                 :            :         struct  rte_meter_trtcm_rfc4115_params rfc4115params1;
     167                 :            : #define TRTCM_RFC4115_CFG_MSG "trtcm_rfc4115_config"
     168                 :            : 
     169                 :            :         /* invalid parameter test */
     170         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(NULL, NULL) == 0)
     171                 :          0 :                 melog(TRTCM_RFC4115_CFG_MSG);
     172         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, NULL) == 0)
     173                 :          0 :                 melog(TRTCM_RFC4115_CFG_MSG);
     174         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(NULL, &rfc4115params) == 0)
     175                 :          0 :                 melog(TRTCM_RFC4115_CFG_MSG);
     176                 :            : 
     177                 :            :         /*
     178                 :            :          * cbs and pbs should be none-zero if cir and eir are none-zero
     179                 :            :          * respectively
     180                 :            :          */
     181                 :          1 :         rfc4115params1 = rfc4115params;
     182                 :          1 :         rfc4115params1.cbs = 0;
     183         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params1) == 0)
     184                 :          0 :                 melog(TRTCM_RFC4115_CFG_MSG);
     185                 :            : 
     186                 :          1 :         rfc4115params1 = rfc4115params;
     187                 :          1 :         rfc4115params1.ebs = 0;
     188         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params1) == 0)
     189                 :          0 :                 melog(TRTCM_RFC4115_CFG_MSG);
     190                 :            : 
     191                 :            :         /* usual parameter, should be successful */
     192         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
     193                 :          0 :                 melog(TRTCM_RFC4115_CFG_MSG);
     194                 :            : 
     195                 :            :         return 0;
     196                 :            : }
     197                 :            : 
     198                 :            : /**
     199                 :            :  * functional test for rte_meter_srtcm_color_blind_check
     200                 :            :  */
     201                 :            : static inline int
     202                 :          1 : tm_test_srtcm_color_blind_check(void)
     203                 :            : {
     204                 :            : #define SRTCM_BLIND_CHECK_MSG "srtcm_blind_check"
     205                 :            :         struct rte_meter_srtcm_profile sp;
     206                 :            :         struct rte_meter_srtcm sm;
     207                 :            :         uint64_t time;
     208                 :          1 :         uint64_t hz = rte_get_tsc_hz();
     209                 :            : 
     210                 :            :         /* Test green */
     211         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
     212                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG);
     213         [ -  + ]:          1 :         if (rte_meter_srtcm_config(&sm, &sp) != 0)
     214                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG);
     215                 :          1 :         time = rte_get_tsc_cycles() + hz;
     216         [ -  + ]:          1 :         if (rte_meter_srtcm_color_blind_check(
     217                 :            :                 &sm, &sp, time, TM_TEST_SRTCM_CBS_DF - 1)
     218                 :            :                 != RTE_COLOR_GREEN)
     219                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG" GREEN");
     220                 :            : 
     221                 :            :         /* Test yellow */
     222         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
     223                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG);
     224         [ -  + ]:          1 :         if (rte_meter_srtcm_config(&sm, &sp) != 0)
     225                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG);
     226                 :          1 :         time = rte_get_tsc_cycles() + hz;
     227         [ -  + ]:          1 :         if (rte_meter_srtcm_color_blind_check(
     228                 :            :                 &sm, &sp, time, TM_TEST_SRTCM_CBS_DF + 1)
     229                 :            :                 != RTE_COLOR_YELLOW)
     230                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
     231                 :            : 
     232         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
     233                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG);
     234         [ -  + ]:          1 :         if (rte_meter_srtcm_config(&sm, &sp) != 0)
     235                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG);
     236                 :          1 :         time = rte_get_tsc_cycles() + hz;
     237         [ -  + ]:          1 :         if (rte_meter_srtcm_color_blind_check(
     238                 :          1 :                 &sm, &sp, time, (uint32_t)sp.ebs - 1) != RTE_COLOR_YELLOW)
     239                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
     240                 :            : 
     241                 :            :         /* Test red */
     242         [ -  + ]:          1 :         if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
     243                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG);
     244         [ -  + ]:          1 :         if (rte_meter_srtcm_config(&sm, &sp) != 0)
     245                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG);
     246                 :          1 :         time = rte_get_tsc_cycles() + hz;
     247         [ -  + ]:          1 :         if (rte_meter_srtcm_color_blind_check(
     248                 :            :                 &sm, &sp, time, TM_TEST_SRTCM_EBS_DF + 1)
     249                 :            :                 != RTE_COLOR_RED)
     250                 :          0 :                 melog(SRTCM_BLIND_CHECK_MSG" RED");
     251                 :            : 
     252                 :            :         return 0;
     253                 :            : 
     254                 :            : }
     255                 :            : 
     256                 :            : /**
     257                 :            :  * functional test for rte_meter_trtcm_color_blind_check
     258                 :            :  */
     259                 :            : static inline int
     260                 :          1 : tm_test_trtcm_color_blind_check(void)
     261                 :            : {
     262                 :            : #define TRTCM_BLIND_CHECK_MSG "trtcm_blind_check"
     263                 :            : 
     264                 :            :         uint64_t time;
     265                 :            :         struct rte_meter_trtcm_profile tp;
     266                 :            :         struct rte_meter_trtcm tm;
     267                 :          1 :         uint64_t hz = rte_get_tsc_hz();
     268                 :            : 
     269                 :            :         /* Test green */
     270         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
     271                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG);
     272         [ -  + ]:          1 :         if (rte_meter_trtcm_config(&tm, &tp) != 0)
     273                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG);
     274                 :          1 :         time = rte_get_tsc_cycles() + hz;
     275         [ -  + ]:          1 :         if (rte_meter_trtcm_color_blind_check(
     276                 :            :                 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1)
     277                 :            :                 != RTE_COLOR_GREEN)
     278                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG" GREEN");
     279                 :            : 
     280                 :            :         /* Test yellow */
     281         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
     282                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG);
     283         [ -  + ]:          1 :         if (rte_meter_trtcm_config(&tm, &tp) != 0)
     284                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG);
     285                 :          1 :         time = rte_get_tsc_cycles() + hz;
     286         [ -  + ]:          1 :         if (rte_meter_trtcm_color_blind_check(
     287                 :            :                 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1)
     288                 :            :                 != RTE_COLOR_YELLOW)
     289                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
     290                 :            : 
     291         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
     292                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG);
     293         [ -  + ]:          1 :         if (rte_meter_trtcm_config(&tm, &tp) != 0)
     294                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG);
     295                 :          1 :         time = rte_get_tsc_cycles() + hz;
     296         [ -  + ]:          1 :         if (rte_meter_trtcm_color_blind_check(
     297                 :            :                 &tm, &tp, time, TM_TEST_TRTCM_PBS_DF - 1)
     298                 :            :                 != RTE_COLOR_YELLOW)
     299                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
     300                 :            : 
     301                 :            :         /* Test red */
     302         [ -  + ]:          1 :         if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
     303                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG);
     304         [ -  + ]:          1 :         if (rte_meter_trtcm_config(&tm, &tp) != 0)
     305                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG);
     306                 :          1 :         time = rte_get_tsc_cycles() + hz;
     307         [ -  + ]:          1 :         if (rte_meter_trtcm_color_blind_check(
     308                 :            :                 &tm, &tp, time, TM_TEST_TRTCM_PBS_DF + 1)
     309                 :            :                 != RTE_COLOR_RED)
     310                 :          0 :                 melog(TRTCM_BLIND_CHECK_MSG" RED");
     311                 :            : 
     312                 :            :         return 0;
     313                 :            : }
     314                 :            : 
     315                 :            : /**
     316                 :            :  * functional test for rte_meter_trtcm_rfc4115_color_blind_check
     317                 :            :  */
     318                 :            : static inline int
     319                 :          1 : tm_test_trtcm_rfc4115_color_blind_check(void)
     320                 :            : {
     321                 :            : #define TRTCM_RFC4115_BLIND_CHECK_MSG "trtcm_rfc4115_blind_check"
     322                 :            : 
     323                 :            :         uint64_t time;
     324                 :            :         struct rte_meter_trtcm_rfc4115_profile tp;
     325                 :            :         struct rte_meter_trtcm_rfc4115 tm;
     326                 :          1 :         uint64_t hz = rte_get_tsc_hz();
     327                 :            : 
     328                 :            :         /* Test green */
     329         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
     330                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
     331         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
     332                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
     333                 :          1 :         time = rte_get_tsc_cycles() + hz;
     334         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_color_blind_check(
     335                 :            :                 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1)
     336                 :            :                 != RTE_COLOR_GREEN)
     337                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG" GREEN");
     338                 :            : 
     339                 :            :         /* Test yellow */
     340         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
     341                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
     342         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
     343                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
     344                 :          1 :         time = rte_get_tsc_cycles() + hz;
     345         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_color_blind_check(
     346                 :            :                 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1)
     347                 :            :                 != RTE_COLOR_YELLOW)
     348                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG" YELLOW");
     349                 :            : 
     350         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
     351                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
     352         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
     353                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
     354                 :          1 :         time = rte_get_tsc_cycles() + hz;
     355         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_color_blind_check(
     356                 :            :                 &tm, &tp, time, TM_TEST_TRTCM_EBS_DF - 1)
     357                 :            :                 != RTE_COLOR_YELLOW)
     358                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG" YELLOW");
     359                 :            : 
     360                 :            :         /* Test red */
     361         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
     362                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
     363         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
     364                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
     365                 :          1 :         time = rte_get_tsc_cycles() + hz;
     366         [ -  + ]:          1 :         if (rte_meter_trtcm_rfc4115_color_blind_check(
     367                 :            :                 &tm, &tp, time, TM_TEST_TRTCM_EBS_DF + 1)
     368                 :            :                 != RTE_COLOR_RED)
     369                 :          0 :                 melog(TRTCM_RFC4115_BLIND_CHECK_MSG" RED");
     370                 :            : 
     371                 :            :         return 0;
     372                 :            : }
     373                 :            : 
     374                 :            : 
     375                 :            : /**
     376                 :            :  * @in[4] : the flags packets carries.
     377                 :            :  * @in[4] : the flags function expect to return.
     378                 :            :  * It will do blind check at the time of 1 second from beginning.
     379                 :            :  * At the time, it will use packets length of cbs -1, cbs + 1,
     380                 :            :  * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
     381                 :            :  * aware check, expect flag out[0], out[1], out[2] and out[3]
     382                 :            :  */
     383                 :            : 
     384                 :            : static inline int
     385                 :          3 : tm_test_srtcm_aware_check
     386                 :            : (enum rte_color in[4], enum rte_color out[4])
     387                 :            : {
     388                 :            : #define SRTCM_AWARE_CHECK_MSG "srtcm_aware_check"
     389                 :            :         struct rte_meter_srtcm_profile sp;
     390                 :            :         struct rte_meter_srtcm sm;
     391                 :            :         uint64_t time;
     392                 :          3 :         uint64_t hz = rte_get_tsc_hz();
     393                 :            : 
     394         [ -  + ]:          3 :         if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
     395                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG);
     396         [ -  + ]:          3 :         if (rte_meter_srtcm_config(&sm, &sp) != 0)
     397                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG);
     398                 :          3 :         time = rte_get_tsc_cycles() + hz;
     399                 :          3 :         if (rte_meter_srtcm_color_aware_check(
     400         [ -  + ]:          3 :                 &sm, &sp, time, TM_TEST_SRTCM_CBS_DF - 1, in[0]) != out[0])
     401                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
     402                 :            : 
     403         [ -  + ]:          3 :         if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
     404                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG);
     405         [ -  + ]:          3 :         if (rte_meter_srtcm_config(&sm, &sp) != 0)
     406                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG);
     407                 :          3 :         time = rte_get_tsc_cycles() + hz;
     408                 :          3 :         if (rte_meter_srtcm_color_aware_check(
     409         [ -  + ]:          3 :                 &sm, &sp, time, TM_TEST_SRTCM_CBS_DF + 1, in[1]) != out[1])
     410                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
     411                 :            : 
     412         [ -  + ]:          3 :         if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
     413                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG);
     414         [ -  + ]:          3 :         if (rte_meter_srtcm_config(&sm, &sp) != 0)
     415                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG);
     416                 :          3 :         time = rte_get_tsc_cycles() + hz;
     417                 :          3 :         if (rte_meter_srtcm_color_aware_check(
     418         [ -  + ]:          3 :                 &sm, &sp, time, TM_TEST_SRTCM_EBS_DF - 1, in[2]) != out[2])
     419                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
     420                 :            : 
     421         [ -  + ]:          3 :         if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
     422                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG);
     423         [ -  + ]:          3 :         if (rte_meter_srtcm_config(&sm, &sp) != 0)
     424                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG);
     425                 :          3 :         time = rte_get_tsc_cycles() + hz;
     426                 :          3 :         if (rte_meter_srtcm_color_aware_check(
     427         [ -  + ]:          3 :                 &sm, &sp, time, TM_TEST_SRTCM_EBS_DF + 1, in[3]) != out[3])
     428                 :          0 :                 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
     429                 :            : 
     430                 :            :         return 0;
     431                 :            : }
     432                 :            : 
     433                 :            : 
     434                 :            : /**
     435                 :            :  * functional test for rte_meter_srtcm_color_aware_check
     436                 :            :  */
     437                 :            : static inline int
     438                 :          1 : tm_test_srtcm_color_aware_check(void)
     439                 :            : {
     440                 :            :         enum rte_color in[4], out[4];
     441                 :            : 
     442                 :            :         /**
     443                 :            :           * test 4 points that will produce green, yellow, yellow, red flag
     444                 :            :           * if using blind check
     445                 :            :           */
     446                 :            : 
     447                 :            :         /* previously have a green, test points should keep unchanged */
     448                 :          1 :         in[0] = in[1] = in[2] = in[3] = RTE_COLOR_GREEN;
     449                 :          1 :         out[0] = RTE_COLOR_GREEN;
     450                 :          1 :         out[1] = RTE_COLOR_YELLOW;
     451                 :          1 :         out[2] = RTE_COLOR_YELLOW;
     452                 :          1 :         out[3] = RTE_COLOR_RED;
     453         [ +  - ]:          1 :         if (tm_test_srtcm_aware_check(in, out) != 0)
     454                 :            :                 return -1;
     455                 :            : 
     456                 :            :         /**
     457                 :            :           * previously have a yellow, green & yellow = yellow
     458                 :            :           * yellow & red = red
     459                 :            :           */
     460                 :          1 :         in[0] = in[1] = in[2] = in[3] = RTE_COLOR_YELLOW;
     461                 :          1 :         out[0] = RTE_COLOR_YELLOW;
     462                 :          1 :         out[1] = RTE_COLOR_YELLOW;
     463                 :          1 :         out[2] = RTE_COLOR_YELLOW;
     464                 :          1 :         out[3] = RTE_COLOR_RED;
     465         [ +  - ]:          1 :         if (tm_test_srtcm_aware_check(in, out) != 0)
     466                 :            :                 return -1;
     467                 :            : 
     468                 :            :         /**
     469                 :            :           * previously have a red, red & green = red
     470                 :            :           * red & yellow = red
     471                 :            :           */
     472                 :          1 :         in[0] = in[1] = in[2] = in[3] = RTE_COLOR_RED;
     473                 :          1 :         out[0] = RTE_COLOR_RED;
     474                 :          1 :         out[1] = RTE_COLOR_RED;
     475                 :          1 :         out[2] = RTE_COLOR_RED;
     476                 :          1 :         out[3] = RTE_COLOR_RED;
     477         [ -  + ]:          1 :         if (tm_test_srtcm_aware_check(in, out) != 0)
     478                 :          0 :                 return -1;
     479                 :            : 
     480                 :            :         return 0;
     481                 :            : }
     482                 :            : 
     483                 :            : /**
     484                 :            :  * @in[4] : the flags packets carries.
     485                 :            :  * @in[4] : the flags function expect to return.
     486                 :            :  * It will do blind check at the time of 1 second from beginning.
     487                 :            :  * At the time, it will use packets length of cbs -1, cbs + 1,
     488                 :            :  * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
     489                 :            :  * aware check, expect flag out[0], out[1], out[2] and out[3]
     490                 :            :  */
     491                 :            : static inline int
     492                 :          3 : tm_test_trtcm_aware_check
     493                 :            : (enum rte_color in[4], enum rte_color out[4])
     494                 :            : {
     495                 :            : #define TRTCM_AWARE_CHECK_MSG "trtcm_aware_check"
     496                 :            :         struct rte_meter_trtcm_profile tp;
     497                 :            :         struct rte_meter_trtcm tm;
     498                 :            :         uint64_t time;
     499                 :          3 :         uint64_t hz = rte_get_tsc_hz();
     500                 :            : 
     501         [ -  + ]:          3 :         if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
     502                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG);
     503         [ -  + ]:          3 :         if (rte_meter_trtcm_config(&tm, &tp) != 0)
     504                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG);
     505                 :          3 :         time = rte_get_tsc_cycles() + hz;
     506                 :          3 :         if (rte_meter_trtcm_color_aware_check(
     507         [ -  + ]:          3 :                 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1, in[0]) != out[0])
     508                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
     509                 :            : 
     510         [ -  + ]:          3 :         if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
     511                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG);
     512         [ -  + ]:          3 :         if (rte_meter_trtcm_config(&tm, &tp) != 0)
     513                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG);
     514                 :          3 :         time = rte_get_tsc_cycles() + hz;
     515                 :          3 :         if (rte_meter_trtcm_color_aware_check(
     516         [ -  + ]:          3 :                 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1, in[1]) != out[1])
     517                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
     518                 :            : 
     519         [ -  + ]:          3 :         if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
     520                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG);
     521         [ -  + ]:          3 :         if (rte_meter_trtcm_config(&tm, &tp) != 0)
     522                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG);
     523                 :          3 :         time = rte_get_tsc_cycles() + hz;
     524                 :          3 :         if (rte_meter_trtcm_color_aware_check(
     525         [ -  + ]:          3 :                 &tm, &tp, time, TM_TEST_TRTCM_PBS_DF - 1, in[2]) != out[2])
     526                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
     527                 :            : 
     528         [ -  + ]:          3 :         if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
     529                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG);
     530         [ -  + ]:          3 :         if (rte_meter_trtcm_config(&tm, &tp) != 0)
     531                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG);
     532                 :          3 :         time = rte_get_tsc_cycles() + hz;
     533                 :          3 :         if (rte_meter_trtcm_color_aware_check(
     534         [ -  + ]:          3 :                 &tm, &tp, time, TM_TEST_TRTCM_PBS_DF + 1, in[3]) != out[3])
     535                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
     536                 :            : 
     537                 :            :         return 0;
     538                 :            : }
     539                 :            : 
     540                 :            : 
     541                 :            : /**
     542                 :            :  * functional test for rte_meter_trtcm_color_aware_check
     543                 :            :  */
     544                 :            : 
     545                 :            : static inline int
     546                 :          1 : tm_test_trtcm_color_aware_check(void)
     547                 :            : {
     548                 :            :         enum rte_color in[4], out[4];
     549                 :            :         /**
     550                 :            :           * test 4 points that will produce green, yellow, yellow, red flag
     551                 :            :           * if using blind check
     552                 :            :           */
     553                 :            : 
     554                 :            :         /* previously have a green, test points should keep unchanged */
     555                 :          1 :         in[0] = in[1] = in[2] = in[3] = RTE_COLOR_GREEN;
     556                 :          1 :         out[0] = RTE_COLOR_GREEN;
     557                 :          1 :         out[1] = RTE_COLOR_YELLOW;
     558                 :          1 :         out[2] = RTE_COLOR_YELLOW;
     559                 :          1 :         out[3] = RTE_COLOR_RED;
     560         [ +  - ]:          1 :         if (tm_test_trtcm_aware_check(in, out) != 0)
     561                 :            :                 return -1;
     562                 :            : 
     563                 :          1 :         in[0] = in[1] = in[2] = in[3] = RTE_COLOR_YELLOW;
     564                 :          1 :         out[0] = RTE_COLOR_YELLOW;
     565                 :          1 :         out[1] = RTE_COLOR_YELLOW;
     566                 :          1 :         out[2] = RTE_COLOR_YELLOW;
     567                 :          1 :         out[3] = RTE_COLOR_RED;
     568         [ +  - ]:          1 :         if (tm_test_trtcm_aware_check(in, out) != 0)
     569                 :            :                 return -1;
     570                 :            : 
     571                 :          1 :         in[0] = in[1] = in[2] = in[3] = RTE_COLOR_RED;
     572                 :          1 :         out[0] = RTE_COLOR_RED;
     573                 :          1 :         out[1] = RTE_COLOR_RED;
     574                 :          1 :         out[2] = RTE_COLOR_RED;
     575                 :          1 :         out[3] = RTE_COLOR_RED;
     576         [ -  + ]:          1 :         if (tm_test_trtcm_aware_check(in, out) != 0)
     577                 :          0 :                 return -1;
     578                 :            : 
     579                 :            :         return 0;
     580                 :            : }
     581                 :            : 
     582                 :            : /**
     583                 :            :  * @in[4] : the flags packets carries.
     584                 :            :  * @in[4] : the flags function expect to return.
     585                 :            :  * It will do blind check at the time of 1 second from beginning.
     586                 :            :  * At the time, it will use packets length of cbs -1, cbs + 1,
     587                 :            :  * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
     588                 :            :  * aware check, expect flag out[0], out[1], out[2] and out[3]
     589                 :            :  */
     590                 :            : static inline int
     591                 :          3 : tm_test_trtcm_rfc4115_aware_check
     592                 :            : (enum rte_color in[4], enum rte_color out[4])
     593                 :            : {
     594                 :            : #define TRTCM_RFC4115_AWARE_CHECK_MSG "trtcm_rfc4115_aware_check"
     595                 :            :         struct rte_meter_trtcm_rfc4115_profile tp;
     596                 :            :         struct rte_meter_trtcm_rfc4115 tm;
     597                 :            :         uint64_t time;
     598                 :          3 :         uint64_t hz = rte_get_tsc_hz();
     599                 :            : 
     600         [ -  + ]:          3 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
     601                 :          0 :                 melog(TRTCM_AWARE_CHECK_MSG);
     602         [ -  + ]:          3 :         if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
     603                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
     604                 :          3 :         time = rte_get_tsc_cycles() + hz;
     605                 :          3 :         if (rte_meter_trtcm_rfc4115_color_aware_check(
     606         [ -  + ]:          3 :                 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1, in[0]) != out[0])
     607                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
     608                 :            : 
     609         [ -  + ]:          3 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
     610                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
     611         [ -  + ]:          3 :         if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
     612                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
     613                 :          3 :         time = rte_get_tsc_cycles() + hz;
     614                 :          3 :         if (rte_meter_trtcm_rfc4115_color_aware_check(
     615         [ -  + ]:          3 :                 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1, in[1]) != out[1])
     616                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
     617                 :            : 
     618         [ -  + ]:          3 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
     619                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
     620         [ -  + ]:          3 :         if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
     621                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
     622                 :          3 :         time = rte_get_tsc_cycles() + hz;
     623                 :          3 :         if (rte_meter_trtcm_rfc4115_color_aware_check(
     624         [ -  + ]:          3 :                 &tm, &tp, time, TM_TEST_TRTCM_EBS_DF - 1, in[2]) != out[2])
     625                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
     626                 :            : 
     627         [ -  + ]:          3 :         if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
     628                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
     629         [ -  + ]:          3 :         if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
     630                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
     631                 :          3 :         time = rte_get_tsc_cycles() + hz;
     632                 :          3 :         if (rte_meter_trtcm_rfc4115_color_aware_check(
     633         [ -  + ]:          3 :                 &tm, &tp, time, TM_TEST_TRTCM_EBS_DF + 1, in[3]) != out[3])
     634                 :          0 :                 melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
     635                 :            : 
     636                 :            :         return 0;
     637                 :            : }
     638                 :            : 
     639                 :            : /**
     640                 :            :  * functional test for rte_meter_trtcm_rfc4115_color_aware_check
     641                 :            :  */
     642                 :            : static inline int
     643                 :          1 : tm_test_trtcm_rfc4115_color_aware_check(void)
     644                 :            : {
     645                 :            :         enum rte_color in[4], out[4];
     646                 :            :         /**
     647                 :            :           * test 4 points that will produce green, yellow, yellow, red flag
     648                 :            :           * if using blind check
     649                 :            :           */
     650                 :            : 
     651                 :            :         /* previously have a green, test points should keep unchanged */
     652                 :          1 :         in[0] = in[1] = in[2] = in[3] = RTE_COLOR_GREEN;
     653                 :          1 :         out[0] = RTE_COLOR_GREEN;
     654                 :          1 :         out[1] = RTE_COLOR_YELLOW;
     655                 :          1 :         out[2] = RTE_COLOR_YELLOW;
     656                 :          1 :         out[3] = RTE_COLOR_RED;
     657         [ +  - ]:          1 :         if (tm_test_trtcm_rfc4115_aware_check(in, out) != 0)
     658                 :            :                 return -1;
     659                 :            : 
     660                 :          1 :         in[0] = in[1] = in[2] = in[3] = RTE_COLOR_YELLOW;
     661                 :          1 :         out[0] = RTE_COLOR_YELLOW;
     662                 :          1 :         out[1] = RTE_COLOR_YELLOW;
     663                 :          1 :         out[2] = RTE_COLOR_YELLOW;
     664                 :          1 :         out[3] = RTE_COLOR_RED;
     665         [ +  - ]:          1 :         if (tm_test_trtcm_rfc4115_aware_check(in, out) != 0)
     666                 :            :                 return -1;
     667                 :            : 
     668                 :          1 :         in[0] = in[1] = in[2] = in[3] = RTE_COLOR_RED;
     669                 :          1 :         out[0] = RTE_COLOR_RED;
     670                 :          1 :         out[1] = RTE_COLOR_RED;
     671                 :          1 :         out[2] = RTE_COLOR_RED;
     672                 :          1 :         out[3] = RTE_COLOR_RED;
     673         [ -  + ]:          1 :         if (tm_test_trtcm_rfc4115_aware_check(in, out) != 0)
     674                 :          0 :                 return -1;
     675                 :            : 
     676                 :            :         return 0;
     677                 :            : }
     678                 :            : 
     679                 :            : /**
     680                 :            :  * test main entrance for library meter
     681                 :            :  */
     682                 :            : static int
     683                 :          1 : test_meter(void)
     684                 :            : {
     685         [ +  - ]:          1 :         if (tm_test_srtcm_config() != 0)
     686                 :            :                 return -1;
     687                 :            : 
     688         [ +  - ]:          1 :         if (tm_test_trtcm_config() != 0)
     689                 :            :                 return -1;
     690                 :            : 
     691         [ +  - ]:          1 :         if (tm_test_trtcm_rfc4115_config() != 0)
     692                 :            :                 return -1;
     693                 :            : 
     694         [ +  - ]:          1 :         if (tm_test_srtcm_color_blind_check() != 0)
     695                 :            :                 return -1;
     696                 :            : 
     697         [ +  - ]:          1 :         if (tm_test_trtcm_color_blind_check() != 0)
     698                 :            :                 return -1;
     699                 :            : 
     700         [ +  - ]:          1 :         if (tm_test_trtcm_rfc4115_color_blind_check() != 0)
     701                 :            :                 return -1;
     702                 :            : 
     703         [ +  - ]:          1 :         if (tm_test_srtcm_color_aware_check() != 0)
     704                 :            :                 return -1;
     705                 :            : 
     706         [ +  - ]:          1 :         if (tm_test_trtcm_color_aware_check() != 0)
     707                 :            :                 return -1;
     708                 :            : 
     709         [ -  + ]:          1 :         if (tm_test_trtcm_rfc4115_color_aware_check() != 0)
     710                 :          0 :                 return -1;
     711                 :            : 
     712                 :            :         return 0;
     713                 :            : 
     714                 :            : }
     715                 :            : 
     716                 :        251 : REGISTER_FAST_TEST(meter_autotest, true, true, test_meter);

Generated by: LCOV version 1.14