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