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, *src_sges_str,
301 : : *dst_sges_str, *use_dma_ops;
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 : : if (is_dma) {
353 : : use_dma_ops =
354 : 0 : rte_cfgfile_get_entry(cfgfile, section_name, "use_enq_deq_ops");
355 : 0 : if (use_dma_ops != NULL && (atoi(use_dma_ops) == 1))
356 : 0 : test_case->use_ops = true;
357 : : else
358 : 0 : test_case->use_ops = false;
359 : : }
360 : :
361 : 0 : test_case->is_dma = is_dma;
362 : 0 : test_case->src_numa_node = (int)atoi(rte_cfgfile_get_entry(cfgfile,
363 : : section_name, "src_numa_node"));
364 : 0 : test_case->dst_numa_node = (int)atoi(rte_cfgfile_get_entry(cfgfile,
365 : : section_name, "dst_numa_node"));
366 : : nb_vp = 0;
367 : 0 : mem_size_str = rte_cfgfile_get_entry(cfgfile, section_name, "mem_size");
368 : 0 : args_nr = parse_entry(mem_size_str, &test_case->mem_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 : : nb_vp++;
375 : :
376 : 0 : buf_size_str = rte_cfgfile_get_entry(cfgfile, section_name, "buf_size");
377 : 0 : args_nr = parse_entry(buf_size_str, &test_case->buf_size);
378 : 0 : if (args_nr < 0) {
379 : : printf("parse error in case %d.\n", i + 1);
380 : 0 : test_case->is_valid = false;
381 : 0 : continue;
382 : 0 : } else if (args_nr == 4)
383 : 0 : nb_vp++;
384 : :
385 : 0 : if (is_dma) {
386 : 0 : ring_size_str = rte_cfgfile_get_entry(cfgfile, section_name,
387 : : "dma_ring_size");
388 : 0 : args_nr = parse_entry(ring_size_str, &test_case->ring_size);
389 : 0 : if (args_nr < 0) {
390 : : printf("parse error in case %d.\n", i + 1);
391 : 0 : test_case->is_valid = false;
392 : 0 : continue;
393 : 0 : } else if (args_nr == 4)
394 : 0 : nb_vp++;
395 : :
396 : 0 : src_sges_str = rte_cfgfile_get_entry(cfgfile, section_name,
397 : : "dma_src_sge");
398 : 0 : if (src_sges_str != NULL) {
399 : 0 : test_case->nb_src_sges = (int)atoi(rte_cfgfile_get_entry(cfgfile,
400 : : section_name, "dma_src_sge"));
401 : : }
402 : :
403 : 0 : dst_sges_str = rte_cfgfile_get_entry(cfgfile, section_name,
404 : : "dma_dst_sge");
405 : 0 : if (dst_sges_str != NULL) {
406 : 0 : test_case->nb_dst_sges = (int)atoi(rte_cfgfile_get_entry(cfgfile,
407 : : section_name, "dma_dst_sge"));
408 : : }
409 : :
410 : 0 : if ((src_sges_str != NULL && dst_sges_str == NULL) ||
411 : : (src_sges_str == NULL && dst_sges_str != NULL)) {
412 : : printf("parse dma_src_sge, dma_dst_sge error in case %d.\n",
413 : : i + 1);
414 : 0 : test_case->is_valid = false;
415 : 0 : continue;
416 : 0 : } else if (src_sges_str != NULL && dst_sges_str != NULL) {
417 : 0 : test_case->is_sg = true;
418 : :
419 : 0 : if (test_case->nb_src_sges == 0 || test_case->nb_dst_sges == 0) {
420 : : printf("dma_src_sge and dma_dst_sge can not be 0 in case %d.\n",
421 : : i + 1);
422 : 0 : test_case->is_valid = false;
423 : 0 : continue;
424 : : }
425 : : } else {
426 : 0 : test_case->is_sg = false;
427 : : }
428 : :
429 : 0 : kick_batch_str = rte_cfgfile_get_entry(cfgfile, section_name, "kick_batch");
430 : 0 : args_nr = parse_entry(kick_batch_str, &test_case->kick_batch);
431 : 0 : if (args_nr < 0) {
432 : : printf("parse error in case %d.\n", i + 1);
433 : 0 : test_case->is_valid = false;
434 : 0 : continue;
435 : 0 : } else if (args_nr == 4)
436 : 0 : nb_vp++;
437 : :
438 : : char lc_dma[RTE_DEV_NAME_MAX_LEN];
439 : : int i = 0;
440 : : while (1) {
441 : 0 : snprintf(lc_dma, RTE_DEV_NAME_MAX_LEN, "lcore_dma%d", i);
442 : 0 : lcore_dma = rte_cfgfile_get_entry(cfgfile, section_name, lc_dma);
443 : 0 : if (lcore_dma == NULL)
444 : : break;
445 : :
446 : 0 : kvlist = rte_kvargs_parse(lcore_dma, NULL);
447 : 0 : if (kvlist == NULL) {
448 : : printf("rte_kvargs_parse() error");
449 : 0 : test_case->is_valid = false;
450 : 0 : break;
451 : : }
452 : :
453 : 0 : if (rte_kvargs_process(kvlist, NULL, populate_dma_dev_config,
454 : 0 : (void *)&test_case->dma_config[i]) < 0) {
455 : : printf("rte_kvargs_process() error\n");
456 : 0 : rte_kvargs_free(kvlist);
457 : 0 : test_case->is_valid = false;
458 : 0 : break;
459 : : }
460 : 0 : i++;
461 : 0 : test_case->num_worker++;
462 : 0 : rte_kvargs_free(kvlist);
463 : : }
464 : :
465 : 0 : if (test_case->num_worker == 0) {
466 : : printf("Error: Parsing %s Failed\n", lc_dma);
467 : 0 : continue;
468 : : }
469 : : } else {
470 : 0 : lcore_dma = rte_cfgfile_get_entry(cfgfile, section_name, "lcore");
471 : 0 : int lcore_ret = parse_lcore(test_case, lcore_dma);
472 : 0 : if (lcore_ret < 0) {
473 : : printf("parse lcore error in case %d.\n", i + 1);
474 : 0 : test_case->is_valid = false;
475 : 0 : continue;
476 : : }
477 : : }
478 : :
479 : 0 : if (nb_vp > 1) {
480 : : printf("Case %d error, each section can only have a single variable parameter.\n",
481 : : i + 1);
482 : 0 : test_case->is_valid = false;
483 : 0 : continue;
484 : : }
485 : :
486 : 0 : test_case->cache_flush =
487 : 0 : (uint8_t)atoi(rte_cfgfile_get_entry(cfgfile, section_name, "cache_flush"));
488 : 0 : test_case->test_secs = (uint16_t)atoi(rte_cfgfile_get_entry(cfgfile,
489 : : section_name, "test_seconds"));
490 : :
491 : 0 : test_case->eal_args = rte_cfgfile_get_entry(cfgfile, section_name, "eal_args");
492 : 0 : test_case->is_valid = true;
493 : : }
494 : :
495 : 0 : rte_cfgfile_close(cfgfile);
496 : : printf("config file parsing complete.\n\n");
497 : 0 : return i;
498 : : }
499 : :
500 : : /* Parse the argument given in the command line of the application */
501 : : static int
502 : 0 : append_eal_args(int argc, char **argv, const char *eal_args, char **new_argv)
503 : : {
504 : : int i;
505 : : char *tokens[MAX_EAL_PARAM_NB];
506 : 0 : char args[MAX_EAL_PARAM_LEN] = {0};
507 : : int token_nb, new_argc = 0;
508 : :
509 : 0 : for (i = 0; i < argc; i++) {
510 : 0 : if ((strcmp(argv[i], CMDLINE_CONFIG_ARG) == 0) ||
511 : 0 : (strcmp(argv[i], CMDLINE_RESULT_ARG) == 0)) {
512 : 0 : i++;
513 : 0 : continue;
514 : : }
515 : 0 : strlcpy(new_argv[new_argc], argv[i], MAX_EAL_PARAM_LEN);
516 : 0 : new_argc++;
517 : : }
518 : :
519 : 0 : if (eal_args) {
520 : : strlcpy(args, eal_args, MAX_EAL_PARAM_LEN);
521 : 0 : token_nb = rte_strsplit(args, strlen(args),
522 : : tokens, MAX_EAL_PARAM_NB, ' ');
523 : 0 : for (i = 0; i < token_nb; i++)
524 : 0 : strlcpy(new_argv[new_argc++], tokens[i], MAX_EAL_PARAM_LEN);
525 : : }
526 : :
527 : 0 : return new_argc;
528 : : }
529 : :
530 : : int
531 : 0 : main(int argc, char *argv[])
532 : : {
533 : : int ret;
534 : : uint16_t case_nb;
535 : : uint32_t i, nb_lcores;
536 : : pid_t cpid, wpid;
537 : : int wstatus;
538 : : char args[MAX_EAL_PARAM_NB][MAX_EAL_PARAM_LEN];
539 : : char *pargs[MAX_EAL_PARAM_NB];
540 : : char *cfg_path_ptr = NULL;
541 : : char *rst_path_ptr = NULL;
542 : : char rst_path[PATH_MAX];
543 : : int new_argc;
544 : :
545 : : memset(args, 0, sizeof(args));
546 : :
547 : 0 : for (i = 0; i < RTE_DIM(pargs); i++)
548 : 0 : pargs[i] = args[i];
549 : :
550 : 0 : for (i = 0; i < (uint32_t)argc; i++) {
551 : 0 : if (strncmp(argv[i], CMDLINE_CONFIG_ARG, MAX_LONG_OPT_SZ) == 0)
552 : 0 : cfg_path_ptr = argv[i + 1];
553 : 0 : if (strncmp(argv[i], CMDLINE_RESULT_ARG, MAX_LONG_OPT_SZ) == 0)
554 : 0 : rst_path_ptr = argv[i + 1];
555 : : }
556 : 0 : if (cfg_path_ptr == NULL) {
557 : : printf("Config file not assigned.\n");
558 : 0 : return -1;
559 : : }
560 : 0 : if (rst_path_ptr == NULL) {
561 : 0 : rte_basename(cfg_path_ptr, rst_path, sizeof(rst_path));
562 : 0 : char *token = strtok(rst_path, ".");
563 : 0 : if (token == NULL) {
564 : : printf("Config file error.\n");
565 : 0 : return -1;
566 : : }
567 : 0 : strlcat(token, "_result.csv", sizeof(rst_path));
568 : : rst_path_ptr = rst_path;
569 : : }
570 : :
571 : 0 : case_nb = load_configs(cfg_path_ptr);
572 : 0 : fd = fopen(rst_path_ptr, "w");
573 : 0 : if (fd == NULL) {
574 : : printf("Open output CSV file error.\n");
575 : 0 : return -1;
576 : : }
577 : 0 : fclose(fd);
578 : :
579 : : printf("Running cases...\n");
580 : 0 : for (i = 0; i < case_nb; i++) {
581 : 0 : if (test_cases[i].is_skip) {
582 : 0 : printf("Test case %d configured to be skipped.\n\n", i + 1);
583 : : snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Skip the test-case %d\n",
584 : : i + 1);
585 : 0 : if (open_output_csv(rst_path_ptr))
586 : : return 0;
587 : 0 : continue;
588 : : }
589 : :
590 : 0 : if (!test_cases[i].is_valid) {
591 : 0 : printf("Invalid test case %d.\n\n", i + 1);
592 : : snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Invalid case %d\n", i + 1);
593 : 0 : if (open_output_csv(rst_path_ptr))
594 : : return 0;
595 : 0 : continue;
596 : : }
597 : :
598 : 0 : cpid = fork();
599 : 0 : if (cpid < 0) {
600 : 0 : printf("Fork case %d failed.\n", i + 1);
601 : 0 : exit(EXIT_FAILURE);
602 : 0 : } else if (cpid == 0) {
603 : 0 : printf("\nRunning case %u\n\n", i + 1);
604 : :
605 : 0 : new_argc = append_eal_args(argc, argv, test_cases[i].eal_args, pargs);
606 : 0 : ret = rte_eal_init(new_argc, pargs);
607 : 0 : if (ret < 0)
608 : 0 : rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
609 : :
610 : : /* Check lcores. */
611 : 0 : nb_lcores = rte_lcore_count();
612 : 0 : if (nb_lcores < 2)
613 : 0 : rte_exit(EXIT_FAILURE,
614 : : "There should be at least 2 worker lcores.\n");
615 : :
616 : 0 : fd = fopen(rst_path_ptr, "a");
617 : 0 : if (!fd) {
618 : : printf("Open output CSV file error.\n");
619 : 0 : return 0;
620 : : }
621 : :
622 : 0 : output_env_info();
623 : :
624 : 0 : run_test(i + 1, &test_cases[i]);
625 : :
626 : : /* clean up the EAL */
627 : 0 : rte_eal_cleanup();
628 : :
629 : 0 : fclose(fd);
630 : :
631 : : printf("\nCase %u completed.\n\n", i + 1);
632 : :
633 : 0 : exit(EXIT_SUCCESS);
634 : : } else {
635 : 0 : wpid = waitpid(cpid, &wstatus, 0);
636 : 0 : if (wpid == -1) {
637 : : printf("waitpid error.\n");
638 : 0 : exit(EXIT_FAILURE);
639 : : }
640 : :
641 : 0 : if (WIFEXITED(wstatus))
642 : 0 : printf("Case process exited. status %d\n\n",
643 : 0 : WEXITSTATUS(wstatus));
644 : 0 : else if (WIFSIGNALED(wstatus))
645 : : printf("Case process killed by signal %d\n\n",
646 : : WTERMSIG(wstatus));
647 : 0 : else if (WIFSTOPPED(wstatus))
648 : 0 : printf("Case process stopped by signal %d\n\n",
649 : 0 : WSTOPSIG(wstatus));
650 : 0 : else if (WIFCONTINUED(wstatus))
651 : : printf("Case process continued.\n\n");
652 : : else
653 : : printf("Case process unknown terminated.\n\n");
654 : : }
655 : : }
656 : :
657 : : printf("Bye...\n");
658 : 0 : return 0;
659 : : }
|