LCOV - code coverage report
Current view: top level - app/test-dma-perf - main.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 280 0.0 %
Date: 2024-01-22 16:13:49 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2023 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <stdlib.h>
       7                 :            : #include <getopt.h>
       8                 :            : #include <signal.h>
       9                 :            : #include <stdbool.h>
      10                 :            : #include <unistd.h>
      11                 :            : #include <sys/wait.h>
      12                 :            : #include <inttypes.h>
      13                 :            : #include <libgen.h>
      14                 :            : 
      15                 :            : #include <rte_eal.h>
      16                 :            : #include <rte_cfgfile.h>
      17                 :            : #include <rte_string_fns.h>
      18                 :            : #include <rte_lcore.h>
      19                 :            : 
      20                 :            : #include "main.h"
      21                 :            : 
      22                 :            : #define CSV_HDR_FMT "Case %u : %s,lcore,DMA,DMA ring size,kick batch size,buffer size(B),number of buffers,memory(MB),average cycle,bandwidth(Gbps),MOps\n"
      23                 :            : 
      24                 :            : #define MAX_EAL_PARAM_NB 100
      25                 :            : #define MAX_EAL_PARAM_LEN 1024
      26                 :            : 
      27                 :            : #define DMA_MEM_COPY "DMA_MEM_COPY"
      28                 :            : #define CPU_MEM_COPY "CPU_MEM_COPY"
      29                 :            : 
      30                 :            : #define CMDLINE_CONFIG_ARG "--config"
      31                 :            : #define CMDLINE_RESULT_ARG "--result"
      32                 :            : 
      33                 :            : #define MAX_PARAMS_PER_ENTRY 4
      34                 :            : 
      35                 :            : #define MAX_LONG_OPT_SZ 64
      36                 :            : 
      37                 :            : enum {
      38                 :            :         TEST_TYPE_NONE = 0,
      39                 :            :         TEST_TYPE_DMA_MEM_COPY,
      40                 :            :         TEST_TYPE_CPU_MEM_COPY
      41                 :            : };
      42                 :            : 
      43                 :            : #define MAX_TEST_CASES 16
      44                 :            : static struct test_configure test_cases[MAX_TEST_CASES];
      45                 :            : 
      46                 :            : char output_str[MAX_WORKER_NB + 1][MAX_OUTPUT_STR_LEN];
      47                 :            : 
      48                 :            : static FILE *fd;
      49                 :            : 
      50                 :            : static void
      51                 :          0 : output_csv(bool need_blankline)
      52                 :            : {
      53                 :            :         uint32_t i;
      54                 :            : 
      55                 :          0 :         if (need_blankline) {
      56                 :          0 :                 fprintf(fd, ",,,,,,,,\n");
      57                 :          0 :                 fprintf(fd, ",,,,,,,,\n");
      58                 :            :         }
      59                 :            : 
      60                 :          0 :         for (i = 0; i < RTE_DIM(output_str); i++) {
      61                 :          0 :                 if (output_str[i][0]) {
      62                 :          0 :                         fprintf(fd, "%s", output_str[i]);
      63                 :          0 :                         output_str[i][0] = '\0';
      64                 :            :                 }
      65                 :            :         }
      66                 :            : 
      67                 :          0 :         fflush(fd);
      68                 :          0 : }
      69                 :            : 
      70                 :            : static void
      71                 :          0 : output_env_info(void)
      72                 :            : {
      73                 :            :         snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Test Environment:\n");
      74                 :          0 :         snprintf(output_str[1], MAX_OUTPUT_STR_LEN, "CPU frequency,%.3lf Ghz",
      75                 :            :                         rte_get_timer_hz() / 1000000000.0);
      76                 :            : 
      77                 :          0 :         output_csv(true);
      78                 :          0 : }
      79                 :            : 
      80                 :            : static void
      81                 :          0 : output_header(uint32_t case_id, struct test_configure *case_cfg)
      82                 :            : {
      83                 :          0 :         snprintf(output_str[0], MAX_OUTPUT_STR_LEN,
      84                 :            :                         CSV_HDR_FMT, case_id, case_cfg->test_type_str);
      85                 :            : 
      86                 :          0 :         output_csv(true);
      87                 :          0 : }
      88                 :            : 
      89                 :            : static void
      90                 :          0 : run_test_case(struct test_configure *case_cfg)
      91                 :            : {
      92                 :          0 :         switch (case_cfg->test_type) {
      93                 :          0 :         case TEST_TYPE_DMA_MEM_COPY:
      94                 :          0 :                 mem_copy_benchmark(case_cfg, true);
      95                 :          0 :                 break;
      96                 :          0 :         case TEST_TYPE_CPU_MEM_COPY:
      97                 :          0 :                 mem_copy_benchmark(case_cfg, false);
      98                 :          0 :                 break;
      99                 :          0 :         default:
     100                 :          0 :                 printf("Unknown test type. %s\n", case_cfg->test_type_str);
     101                 :            :                 break;
     102                 :            :         }
     103                 :          0 : }
     104                 :            : 
     105                 :            : static void
     106                 :          0 : run_test(uint32_t case_id, struct test_configure *case_cfg)
     107                 :            : {
     108                 :            :         uint32_t i;
     109                 :          0 :         uint32_t nb_lcores = rte_lcore_count();
     110                 :          0 :         struct test_configure_entry *mem_size = &case_cfg->mem_size;
     111                 :          0 :         struct test_configure_entry *buf_size = &case_cfg->buf_size;
     112                 :          0 :         struct test_configure_entry *ring_size = &case_cfg->ring_size;
     113                 :          0 :         struct test_configure_entry *kick_batch = &case_cfg->kick_batch;
     114                 :          0 :         struct test_configure_entry dummy = { 0 };
     115                 :            :         struct test_configure_entry *var_entry = &dummy;
     116                 :            : 
     117                 :          0 :         for (i = 0; i < RTE_DIM(output_str); i++)
     118                 :          0 :                 memset(output_str[i], 0, MAX_OUTPUT_STR_LEN);
     119                 :            : 
     120                 :          0 :         if (nb_lcores <= case_cfg->lcore_dma_map.cnt) {
     121                 :            :                 printf("Case %u: Not enough lcores.\n", case_id);
     122                 :          0 :                 return;
     123                 :            :         }
     124                 :            : 
     125                 :            :         printf("Number of used lcores: %u.\n", nb_lcores);
     126                 :            : 
     127                 :          0 :         if (mem_size->incr != 0)
     128                 :            :                 var_entry = mem_size;
     129                 :            : 
     130                 :          0 :         if (buf_size->incr != 0)
     131                 :            :                 var_entry = buf_size;
     132                 :            : 
     133                 :          0 :         if (ring_size->incr != 0)
     134                 :            :                 var_entry = ring_size;
     135                 :            : 
     136                 :          0 :         if (kick_batch->incr != 0)
     137                 :            :                 var_entry = kick_batch;
     138                 :            : 
     139                 :          0 :         case_cfg->scenario_id = 0;
     140                 :            : 
     141                 :          0 :         output_header(case_id, case_cfg);
     142                 :            : 
     143                 :          0 :         for (var_entry->cur = var_entry->first; var_entry->cur <= var_entry->last;) {
     144                 :          0 :                 case_cfg->scenario_id++;
     145                 :          0 :                 printf("\nRunning scenario %d\n", case_cfg->scenario_id);
     146                 :            : 
     147                 :          0 :                 run_test_case(case_cfg);
     148                 :          0 :                 output_csv(false);
     149                 :            : 
     150                 :          0 :                 if (var_entry->op == OP_ADD)
     151                 :          0 :                         var_entry->cur += var_entry->incr;
     152                 :          0 :                 else if (var_entry->op == OP_MUL)
     153                 :          0 :                         var_entry->cur *= var_entry->incr;
     154                 :            :                 else {
     155                 :            :                         printf("No proper operation for variable entry.\n");
     156                 :            :                         break;
     157                 :            :                 }
     158                 :            :         }
     159                 :            : }
     160                 :            : 
     161                 :            : static int
     162                 :          0 : parse_lcore(struct test_configure *test_case, const char *value)
     163                 :            : {
     164                 :            :         uint16_t len;
     165                 :            :         char *input;
     166                 :            :         struct lcore_dma_map_t *lcore_dma_map;
     167                 :            : 
     168                 :          0 :         if (test_case == NULL || value == NULL)
     169                 :            :                 return -1;
     170                 :            : 
     171                 :          0 :         len = strlen(value);
     172                 :          0 :         input = (char *)malloc((len + 1) * sizeof(char));
     173                 :            :         strlcpy(input, value, len + 1);
     174                 :          0 :         lcore_dma_map = &(test_case->lcore_dma_map);
     175                 :            : 
     176                 :            :         memset(lcore_dma_map, 0, sizeof(struct lcore_dma_map_t));
     177                 :            : 
     178                 :          0 :         char *token = strtok(input, ", ");
     179                 :          0 :         while (token != NULL) {
     180                 :          0 :                 if (lcore_dma_map->cnt >= MAX_WORKER_NB) {
     181                 :          0 :                         free(input);
     182                 :          0 :                         return -1;
     183                 :            :                 }
     184                 :            : 
     185                 :          0 :                 uint16_t lcore_id = atoi(token);
     186                 :          0 :                 lcore_dma_map->lcores[lcore_dma_map->cnt++] = lcore_id;
     187                 :            : 
     188                 :          0 :                 token = strtok(NULL, ", ");
     189                 :            :         }
     190                 :            : 
     191                 :          0 :         free(input);
     192                 :          0 :         return 0;
     193                 :            : }
     194                 :            : 
     195                 :            : static int
     196                 :          0 : parse_lcore_dma(struct test_configure *test_case, const char *value)
     197                 :            : {
     198                 :            :         struct lcore_dma_map_t *lcore_dma_map;
     199                 :            :         char *input, *addrs;
     200                 :            :         char *ptrs[2];
     201                 :            :         char *start, *end, *substr;
     202                 :            :         uint16_t lcore_id;
     203                 :            :         int ret = 0;
     204                 :            : 
     205                 :          0 :         if (test_case == NULL || value == NULL)
     206                 :            :                 return -1;
     207                 :            : 
     208                 :          0 :         input = strndup(value, strlen(value) + 1);
     209                 :            :         addrs = input;
     210                 :            : 
     211                 :          0 :         while (*addrs == '\0')
     212                 :          0 :                 addrs++;
     213                 :            :         if (*addrs == '\0') {
     214                 :            :                 fprintf(stderr, "No input DMA addresses\n");
     215                 :            :                 ret = -1;
     216                 :            :                 goto out;
     217                 :            :         }
     218                 :            : 
     219                 :          0 :         substr = strtok(addrs, ",");
     220                 :          0 :         if (substr == NULL) {
     221                 :          0 :                 fprintf(stderr, "No input DMA address\n");
     222                 :            :                 ret = -1;
     223                 :          0 :                 goto out;
     224                 :            :         }
     225                 :            : 
     226                 :          0 :         memset(&test_case->lcore_dma_map, 0, sizeof(struct lcore_dma_map_t));
     227                 :            : 
     228                 :            :         do {
     229                 :          0 :                 if (rte_strsplit(substr, strlen(substr), ptrs, 2, '@') < 0) {
     230                 :          0 :                         fprintf(stderr, "Illegal DMA address\n");
     231                 :            :                         ret = -1;
     232                 :          0 :                         break;
     233                 :            :                 }
     234                 :            : 
     235                 :          0 :                 start = strstr(ptrs[0], "lcore");
     236                 :          0 :                 if (start == NULL) {
     237                 :          0 :                         fprintf(stderr, "Illegal lcore\n");
     238                 :            :                         ret = -1;
     239                 :          0 :                         break;
     240                 :            :                 }
     241                 :            : 
     242                 :          0 :                 start += 5;
     243                 :          0 :                 lcore_id = strtol(start, &end, 0);
     244                 :          0 :                 if (end == start) {
     245                 :          0 :                         fprintf(stderr, "No input lcore ID or ID %d is wrong\n", lcore_id);
     246                 :            :                         ret = -1;
     247                 :          0 :                         break;
     248                 :            :                 }
     249                 :            : 
     250                 :            :                 lcore_dma_map = &test_case->lcore_dma_map;
     251                 :          0 :                 if (lcore_dma_map->cnt >= MAX_WORKER_NB) {
     252                 :          0 :                         fprintf(stderr, "lcores count error\n");
     253                 :            :                         ret = -1;
     254                 :          0 :                         break;
     255                 :            :                 }
     256                 :            : 
     257                 :          0 :                 lcore_dma_map->lcores[lcore_dma_map->cnt] = lcore_id;
     258                 :          0 :                 strlcpy(lcore_dma_map->dma_names[lcore_dma_map->cnt], ptrs[1],
     259                 :            :                                 RTE_DEV_NAME_MAX_LEN);
     260                 :          0 :                 lcore_dma_map->cnt++;
     261                 :          0 :                 substr = strtok(NULL, ",");
     262                 :          0 :         } while (substr != NULL);
     263                 :            : 
     264                 :          0 : out:
     265                 :          0 :         free(input);
     266                 :          0 :         return ret;
     267                 :            : }
     268                 :            : 
     269                 :            : static int
     270                 :          0 : parse_entry(const char *value, struct test_configure_entry *entry)
     271                 :            : {
     272                 :          0 :         char input[255] = {0};
     273                 :            :         char *args[MAX_PARAMS_PER_ENTRY];
     274                 :            :         int args_nr = -1;
     275                 :            :         int ret;
     276                 :            : 
     277                 :          0 :         if (value == NULL || entry == NULL)
     278                 :          0 :                 goto out;
     279                 :            : 
     280                 :            :         strncpy(input, value, 254);
     281                 :          0 :         if (*input == '\0')
     282                 :          0 :                 goto out;
     283                 :            : 
     284                 :          0 :         ret = rte_strsplit(input, strlen(input), args, MAX_PARAMS_PER_ENTRY, ',');
     285                 :          0 :         if (ret != 1 && ret != 4)
     286                 :          0 :                 goto out;
     287                 :            : 
     288                 :          0 :         entry->cur = entry->first = (uint32_t)atoi(args[0]);
     289                 :            : 
     290                 :          0 :         if (ret == 4) {
     291                 :            :                 args_nr = 4;
     292                 :          0 :                 entry->last = (uint32_t)atoi(args[1]);
     293                 :          0 :                 entry->incr = (uint32_t)atoi(args[2]);
     294                 :          0 :                 if (!strcmp(args[3], "MUL"))
     295                 :          0 :                         entry->op = OP_MUL;
     296                 :          0 :                 else if (!strcmp(args[3], "ADD"))
     297                 :          0 :                         entry->op = OP_ADD;
     298                 :            :                 else {
     299                 :            :                         args_nr = -1;
     300                 :            :                         printf("Invalid op %s.\n", args[3]);
     301                 :            :                 }
     302                 :            : 
     303                 :            :         } else {
     304                 :            :                 args_nr = 1;
     305                 :          0 :                 entry->op = OP_NONE;
     306                 :          0 :                 entry->last = 0;
     307                 :          0 :                 entry->incr = 0;
     308                 :            :         }
     309                 :          0 : out:
     310                 :          0 :         return args_nr;
     311                 :            : }
     312                 :            : 
     313                 :            : static uint16_t
     314                 :          0 : load_configs(const char *path)
     315                 :            : {
     316                 :            :         struct rte_cfgfile *cfgfile;
     317                 :            :         int nb_sections, i;
     318                 :            :         struct test_configure *test_case;
     319                 :            :         char section_name[CFG_NAME_LEN];
     320                 :            :         const char *case_type;
     321                 :            :         const char *lcore_dma;
     322                 :            :         const char *mem_size_str, *buf_size_str, *ring_size_str, *kick_batch_str;
     323                 :            :         int args_nr, nb_vp;
     324                 :            :         bool is_dma;
     325                 :            : 
     326                 :            :         printf("config file parsing...\n");
     327                 :          0 :         cfgfile = rte_cfgfile_load(path, 0);
     328                 :          0 :         if (!cfgfile) {
     329                 :            :                 printf("Open configure file error.\n");
     330                 :          0 :                 exit(1);
     331                 :            :         }
     332                 :            : 
     333                 :          0 :         nb_sections = rte_cfgfile_num_sections(cfgfile, NULL, 0);
     334                 :          0 :         if (nb_sections > MAX_TEST_CASES) {
     335                 :            :                 printf("Error: The maximum number of cases is %d.\n", MAX_TEST_CASES);
     336                 :          0 :                 exit(1);
     337                 :            :         }
     338                 :            : 
     339                 :          0 :         for (i = 0; i < nb_sections; i++) {
     340                 :          0 :                 snprintf(section_name, CFG_NAME_LEN, "case%d", i + 1);
     341                 :          0 :                 test_case = &test_cases[i];
     342                 :          0 :                 case_type = rte_cfgfile_get_entry(cfgfile, section_name, "type");
     343                 :          0 :                 if (case_type == NULL) {
     344                 :            :                         printf("Error: No case type in case %d, the test will be finished here.\n",
     345                 :            :                                 i + 1);
     346                 :          0 :                         test_case->is_valid = false;
     347                 :          0 :                         continue;
     348                 :            :                 }
     349                 :            : 
     350                 :          0 :                 if (strcmp(case_type, DMA_MEM_COPY) == 0) {
     351                 :          0 :                         test_case->test_type = TEST_TYPE_DMA_MEM_COPY;
     352                 :          0 :                         test_case->test_type_str = DMA_MEM_COPY;
     353                 :            :                         is_dma = true;
     354                 :          0 :                 } else if (strcmp(case_type, CPU_MEM_COPY) == 0) {
     355                 :          0 :                         test_case->test_type = TEST_TYPE_CPU_MEM_COPY;
     356                 :          0 :                         test_case->test_type_str = CPU_MEM_COPY;
     357                 :            :                         is_dma = false;
     358                 :            :                 } else {
     359                 :            :                         printf("Error: Wrong test case type %s in case%d.\n", case_type, i + 1);
     360                 :          0 :                         test_case->is_valid = false;
     361                 :          0 :                         continue;
     362                 :            :                 }
     363                 :            : 
     364                 :          0 :                 test_case->src_numa_node = (int)atoi(rte_cfgfile_get_entry(cfgfile,
     365                 :            :                                                                 section_name, "src_numa_node"));
     366                 :          0 :                 test_case->dst_numa_node = (int)atoi(rte_cfgfile_get_entry(cfgfile,
     367                 :            :                                                                 section_name, "dst_numa_node"));
     368                 :            :                 nb_vp = 0;
     369                 :          0 :                 mem_size_str = rte_cfgfile_get_entry(cfgfile, section_name, "mem_size");
     370                 :          0 :                 args_nr = parse_entry(mem_size_str, &test_case->mem_size);
     371                 :          0 :                 if (args_nr < 0) {
     372                 :            :                         printf("parse error in case %d.\n", i + 1);
     373                 :          0 :                         test_case->is_valid = false;
     374                 :          0 :                         continue;
     375                 :          0 :                 } else if (args_nr == 4)
     376                 :            :                         nb_vp++;
     377                 :            : 
     378                 :          0 :                 buf_size_str = rte_cfgfile_get_entry(cfgfile, section_name, "buf_size");
     379                 :          0 :                 args_nr = parse_entry(buf_size_str, &test_case->buf_size);
     380                 :          0 :                 if (args_nr < 0) {
     381                 :            :                         printf("parse error in case %d.\n", i + 1);
     382                 :          0 :                         test_case->is_valid = false;
     383                 :          0 :                         continue;
     384                 :          0 :                 } else if (args_nr == 4)
     385                 :          0 :                         nb_vp++;
     386                 :            : 
     387                 :          0 :                 if (is_dma) {
     388                 :          0 :                         ring_size_str = rte_cfgfile_get_entry(cfgfile, section_name,
     389                 :            :                                                                 "dma_ring_size");
     390                 :          0 :                         args_nr = parse_entry(ring_size_str, &test_case->ring_size);
     391                 :          0 :                         if (args_nr < 0) {
     392                 :            :                                 printf("parse error in case %d.\n", i + 1);
     393                 :          0 :                                 test_case->is_valid = false;
     394                 :          0 :                                 continue;
     395                 :          0 :                         } else if (args_nr == 4)
     396                 :          0 :                                 nb_vp++;
     397                 :            : 
     398                 :          0 :                         kick_batch_str = rte_cfgfile_get_entry(cfgfile, section_name, "kick_batch");
     399                 :          0 :                         args_nr = parse_entry(kick_batch_str, &test_case->kick_batch);
     400                 :          0 :                         if (args_nr < 0) {
     401                 :            :                                 printf("parse error in case %d.\n", i + 1);
     402                 :          0 :                                 test_case->is_valid = false;
     403                 :          0 :                                 continue;
     404                 :          0 :                         } else if (args_nr == 4)
     405                 :          0 :                                 nb_vp++;
     406                 :            : 
     407                 :          0 :                         lcore_dma = rte_cfgfile_get_entry(cfgfile, section_name, "lcore_dma");
     408                 :          0 :                         int lcore_ret = parse_lcore_dma(test_case, lcore_dma);
     409                 :          0 :                         if (lcore_ret < 0) {
     410                 :            :                                 printf("parse lcore dma error in case %d.\n", i + 1);
     411                 :          0 :                                 test_case->is_valid = false;
     412                 :          0 :                                 continue;
     413                 :            :                         }
     414                 :            :                 } else {
     415                 :          0 :                         lcore_dma = rte_cfgfile_get_entry(cfgfile, section_name, "lcore");
     416                 :          0 :                         int lcore_ret = parse_lcore(test_case, lcore_dma);
     417                 :          0 :                         if (lcore_ret < 0) {
     418                 :            :                                 printf("parse lcore error in case %d.\n", i + 1);
     419                 :          0 :                                 test_case->is_valid = false;
     420                 :          0 :                                 continue;
     421                 :            :                         }
     422                 :            :                 }
     423                 :            : 
     424                 :          0 :                 if (nb_vp > 1) {
     425                 :            :                         printf("Case %d error, each section can only have a single variable parameter.\n",
     426                 :            :                                         i + 1);
     427                 :          0 :                         test_case->is_valid = false;
     428                 :          0 :                         continue;
     429                 :            :                 }
     430                 :            : 
     431                 :          0 :                 test_case->cache_flush =
     432                 :          0 :                         (uint8_t)atoi(rte_cfgfile_get_entry(cfgfile, section_name, "cache_flush"));
     433                 :          0 :                 test_case->test_secs = (uint16_t)atoi(rte_cfgfile_get_entry(cfgfile,
     434                 :            :                                         section_name, "test_seconds"));
     435                 :            : 
     436                 :          0 :                 test_case->eal_args = rte_cfgfile_get_entry(cfgfile, section_name, "eal_args");
     437                 :          0 :                 test_case->is_valid = true;
     438                 :            :         }
     439                 :            : 
     440                 :          0 :         rte_cfgfile_close(cfgfile);
     441                 :            :         printf("config file parsing complete.\n\n");
     442                 :          0 :         return i;
     443                 :            : }
     444                 :            : 
     445                 :            : /* Parse the argument given in the command line of the application */
     446                 :            : static int
     447                 :          0 : append_eal_args(int argc, char **argv, const char *eal_args, char **new_argv)
     448                 :            : {
     449                 :            :         int i;
     450                 :            :         char *tokens[MAX_EAL_PARAM_NB];
     451                 :          0 :         char args[MAX_EAL_PARAM_LEN] = {0};
     452                 :            :         int token_nb, new_argc = 0;
     453                 :            : 
     454                 :          0 :         for (i = 0; i < argc; i++) {
     455                 :          0 :                 if ((strcmp(argv[i], CMDLINE_CONFIG_ARG) == 0) ||
     456                 :          0 :                                 (strcmp(argv[i], CMDLINE_RESULT_ARG) == 0)) {
     457                 :          0 :                         i++;
     458                 :          0 :                         continue;
     459                 :            :                 }
     460                 :          0 :                 strlcpy(new_argv[new_argc], argv[i], MAX_EAL_PARAM_LEN);
     461                 :          0 :                 new_argc++;
     462                 :            :         }
     463                 :            : 
     464                 :          0 :         if (eal_args) {
     465                 :            :                 strlcpy(args, eal_args, MAX_EAL_PARAM_LEN);
     466                 :          0 :                 token_nb = rte_strsplit(args, strlen(args),
     467                 :            :                                         tokens, MAX_EAL_PARAM_NB, ' ');
     468                 :          0 :                 for (i = 0; i < token_nb; i++)
     469                 :          0 :                         strlcpy(new_argv[new_argc++], tokens[i], MAX_EAL_PARAM_LEN);
     470                 :            :         }
     471                 :            : 
     472                 :          0 :         return new_argc;
     473                 :            : }
     474                 :            : 
     475                 :            : int
     476                 :          0 : main(int argc, char *argv[])
     477                 :            : {
     478                 :            :         int ret;
     479                 :            :         uint16_t case_nb;
     480                 :            :         uint32_t i, nb_lcores;
     481                 :            :         pid_t cpid, wpid;
     482                 :            :         int wstatus;
     483                 :            :         char args[MAX_EAL_PARAM_NB][MAX_EAL_PARAM_LEN];
     484                 :            :         char *pargs[MAX_EAL_PARAM_NB];
     485                 :            :         char *cfg_path_ptr = NULL;
     486                 :            :         char *rst_path_ptr = NULL;
     487                 :            :         char rst_path[PATH_MAX];
     488                 :            :         int new_argc;
     489                 :            : 
     490                 :            :         memset(args, 0, sizeof(args));
     491                 :            : 
     492                 :          0 :         for (i = 0; i < RTE_DIM(pargs); i++)
     493                 :          0 :                 pargs[i] = args[i];
     494                 :            : 
     495                 :          0 :         for (i = 0; i < (uint32_t)argc; i++) {
     496                 :          0 :                 if (strncmp(argv[i], CMDLINE_CONFIG_ARG, MAX_LONG_OPT_SZ) == 0)
     497                 :          0 :                         cfg_path_ptr = argv[i + 1];
     498                 :          0 :                 if (strncmp(argv[i], CMDLINE_RESULT_ARG, MAX_LONG_OPT_SZ) == 0)
     499                 :          0 :                         rst_path_ptr = argv[i + 1];
     500                 :            :         }
     501                 :          0 :         if (cfg_path_ptr == NULL) {
     502                 :            :                 printf("Config file not assigned.\n");
     503                 :          0 :                 return -1;
     504                 :            :         }
     505                 :          0 :         if (rst_path_ptr == NULL) {
     506                 :            :                 strlcpy(rst_path, cfg_path_ptr, PATH_MAX);
     507                 :          0 :                 char *token = strtok(basename(rst_path), ".");
     508                 :          0 :                 if (token == NULL) {
     509                 :            :                         printf("Config file error.\n");
     510                 :          0 :                         return -1;
     511                 :            :                 }
     512                 :            :                 strcat(token, "_result.csv");
     513                 :            :                 rst_path_ptr = rst_path;
     514                 :            :         }
     515                 :            : 
     516                 :          0 :         case_nb = load_configs(cfg_path_ptr);
     517                 :          0 :         fd = fopen(rst_path_ptr, "w");
     518                 :          0 :         if (fd == NULL) {
     519                 :            :                 printf("Open output CSV file error.\n");
     520                 :          0 :                 return -1;
     521                 :            :         }
     522                 :          0 :         fclose(fd);
     523                 :            : 
     524                 :            :         printf("Running cases...\n");
     525                 :          0 :         for (i = 0; i < case_nb; i++) {
     526                 :          0 :                 if (!test_cases[i].is_valid) {
     527                 :          0 :                         printf("Invalid test case %d.\n\n", i + 1);
     528                 :            :                         snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Invalid case %d\n", i + 1);
     529                 :            : 
     530                 :          0 :                         fd = fopen(rst_path_ptr, "a");
     531                 :          0 :                         if (!fd) {
     532                 :            :                                 printf("Open output CSV file error.\n");
     533                 :          0 :                                 return 0;
     534                 :            :                         }
     535                 :          0 :                         output_csv(true);
     536                 :          0 :                         fclose(fd);
     537                 :          0 :                         continue;
     538                 :            :                 }
     539                 :            : 
     540                 :          0 :                 if (test_cases[i].test_type == TEST_TYPE_NONE) {
     541                 :          0 :                         printf("No valid test type in test case %d.\n\n", i + 1);
     542                 :            :                         snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Invalid case %d\n", i + 1);
     543                 :            : 
     544                 :          0 :                         fd = fopen(rst_path_ptr, "a");
     545                 :          0 :                         if (!fd) {
     546                 :            :                                 printf("Open output CSV file error.\n");
     547                 :          0 :                                 return 0;
     548                 :            :                         }
     549                 :          0 :                         output_csv(true);
     550                 :          0 :                         fclose(fd);
     551                 :          0 :                         continue;
     552                 :            :                 }
     553                 :            : 
     554                 :          0 :                 cpid = fork();
     555                 :          0 :                 if (cpid < 0) {
     556                 :          0 :                         printf("Fork case %d failed.\n", i + 1);
     557                 :          0 :                         exit(EXIT_FAILURE);
     558                 :          0 :                 } else if (cpid == 0) {
     559                 :          0 :                         printf("\nRunning case %u\n\n", i + 1);
     560                 :            : 
     561                 :          0 :                         new_argc = append_eal_args(argc, argv, test_cases[i].eal_args, pargs);
     562                 :          0 :                         ret = rte_eal_init(new_argc, pargs);
     563                 :          0 :                         if (ret < 0)
     564                 :          0 :                                 rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
     565                 :            : 
     566                 :            :                         /* Check lcores. */
     567                 :          0 :                         nb_lcores = rte_lcore_count();
     568                 :          0 :                         if (nb_lcores < 2)
     569                 :          0 :                                 rte_exit(EXIT_FAILURE,
     570                 :            :                                         "There should be at least 2 worker lcores.\n");
     571                 :            : 
     572                 :          0 :                         fd = fopen(rst_path_ptr, "a");
     573                 :          0 :                         if (!fd) {
     574                 :            :                                 printf("Open output CSV file error.\n");
     575                 :          0 :                                 return 0;
     576                 :            :                         }
     577                 :            : 
     578                 :          0 :                         output_env_info();
     579                 :            : 
     580                 :          0 :                         run_test(i + 1, &test_cases[i]);
     581                 :            : 
     582                 :            :                         /* clean up the EAL */
     583                 :          0 :                         rte_eal_cleanup();
     584                 :            : 
     585                 :          0 :                         fclose(fd);
     586                 :            : 
     587                 :            :                         printf("\nCase %u completed.\n\n", i + 1);
     588                 :            : 
     589                 :          0 :                         exit(EXIT_SUCCESS);
     590                 :            :                 } else {
     591                 :          0 :                         wpid = waitpid(cpid, &wstatus, 0);
     592                 :          0 :                         if (wpid == -1) {
     593                 :            :                                 printf("waitpid error.\n");
     594                 :          0 :                                 exit(EXIT_FAILURE);
     595                 :            :                         }
     596                 :            : 
     597                 :          0 :                         if (WIFEXITED(wstatus))
     598                 :          0 :                                 printf("Case process exited. status %d\n\n",
     599                 :          0 :                                         WEXITSTATUS(wstatus));
     600                 :          0 :                         else if (WIFSIGNALED(wstatus))
     601                 :            :                                 printf("Case process killed by signal %d\n\n",
     602                 :            :                                         WTERMSIG(wstatus));
     603                 :          0 :                         else if (WIFSTOPPED(wstatus))
     604                 :          0 :                                 printf("Case process stopped by signal %d\n\n",
     605                 :          0 :                                         WSTOPSIG(wstatus));
     606                 :          0 :                         else if (WIFCONTINUED(wstatus))
     607                 :            :                                 printf("Case process continued.\n\n");
     608                 :            :                         else
     609                 :            :                                 printf("Case process unknown terminated.\n\n");
     610                 :            :                 }
     611                 :            :         }
     612                 :            : 
     613                 :            :         printf("Bye...\n");
     614                 :          0 :         return 0;
     615                 :            : }

Generated by: LCOV version 1.14