1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation. 3 * Copyright(c) 2014 6WIND S.A. 4 */ 5 6 #include <stdio.h> 7 8 #include "test.h" 9 10 #include <string.h> 11 #include <stdarg.h> 12 #include <libgen.h> 13 #include <stdlib.h> 14 #include <errno.h> 15 #include <unistd.h> 16 #include <dirent.h> 17 #include <sys/wait.h> 18 #include <sys/file.h> 19 #include <limits.h> 20 21 #include <rte_per_lcore.h> 22 #include <rte_debug.h> 23 #include <rte_string_fns.h> 24 25 #include "process.h" 26 27 #define DEFAULT_MEM_SIZE "18" 28 #define mp_flag "--proc-type=secondary" 29 #define no_hpet "--no-hpet" 30 #define no_huge "--no-huge" 31 #define no_shconf "--no-shconf" 32 #define pci_whitelist "--pci-whitelist" 33 #define vdev "--vdev" 34 #define memtest "memtest" 35 #define memtest1 "memtest1" 36 #define memtest2 "memtest2" 37 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20) 38 #define launch_proc(ARGV) process_dup(ARGV, \ 39 sizeof(ARGV)/(sizeof(ARGV[0])), __func__) 40 41 enum hugepage_action { 42 HUGEPAGE_CHECK_EXISTS = 0, 43 HUGEPAGE_CHECK_LOCKED, 44 HUGEPAGE_DELETE, 45 HUGEPAGE_INVALID 46 }; 47 48 /* if string contains a hugepage path */ 49 static int 50 get_hugepage_path(char * src, int src_len, char * dst, int dst_len) 51 { 52 #define NUM_TOKENS 4 53 char *tokens[NUM_TOKENS]; 54 55 /* if we couldn't properly split the string */ 56 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS) 57 return 0; 58 59 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) { 60 snprintf(dst, dst_len, "%s", tokens[1]); 61 return 1; 62 } 63 return 0; 64 } 65 66 /* 67 * Cycles through hugepage directories and looks for hugepage 68 * files associated with a given prefix. Depending on value of 69 * action, the hugepages are checked if they exist, checked if 70 * they can be locked, or are simply deleted. 71 * 72 * Returns 1 if it finds at least one hugepage matching the action 73 * Returns 0 if no matching hugepages were found 74 * Returns -1 if it encounters an error 75 */ 76 static int 77 process_hugefiles(const char * prefix, enum hugepage_action action) 78 { 79 FILE * hugedir_handle = NULL; 80 DIR * hugepage_dir = NULL; 81 struct dirent *dirent = NULL; 82 83 char hugefile_prefix[PATH_MAX] = {0}; 84 char hugedir[PATH_MAX] = {0}; 85 char line[PATH_MAX] = {0}; 86 87 int fd, lck_result, result = 0; 88 89 const int prefix_len = snprintf(hugefile_prefix, 90 sizeof(hugefile_prefix), "%smap_", prefix); 91 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix) 92 || prefix_len >= (int)sizeof(dirent->d_name)) { 93 printf("Error creating hugefile filename prefix\n"); 94 return -1; 95 } 96 97 /* get hugetlbfs mountpoints from /proc/mounts */ 98 hugedir_handle = fopen("/proc/mounts", "r"); 99 100 if (hugedir_handle == NULL) { 101 printf("Error parsing /proc/mounts!\n"); 102 return -1; 103 } 104 105 /* read and parse script output */ 106 while (fgets(line, sizeof(line), hugedir_handle) != NULL) { 107 108 /* check if we have a hugepage filesystem path */ 109 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir))) 110 continue; 111 112 /* check if directory exists */ 113 if ((hugepage_dir = opendir(hugedir)) == NULL) { 114 fclose(hugedir_handle); 115 printf("Error reading %s: %s\n", hugedir, strerror(errno)); 116 return -1; 117 } 118 119 while ((dirent = readdir(hugepage_dir)) != NULL) { 120 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0) 121 continue; 122 123 switch (action) { 124 case HUGEPAGE_CHECK_EXISTS: 125 { 126 /* file exists, return */ 127 result = 1; 128 goto end; 129 } 130 break; 131 case HUGEPAGE_DELETE: 132 { 133 char file_path[PATH_MAX] = {0}; 134 135 snprintf(file_path, sizeof(file_path), 136 "%s/%s", hugedir, dirent->d_name); 137 138 /* remove file */ 139 if (remove(file_path) < 0) { 140 printf("Error deleting %s - %s!\n", 141 dirent->d_name, strerror(errno)); 142 closedir(hugepage_dir); 143 result = -1; 144 goto end; 145 } 146 result = 1; 147 } 148 break; 149 case HUGEPAGE_CHECK_LOCKED: 150 { 151 /* try and lock the file */ 152 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY); 153 154 /* this shouldn't happen */ 155 if (fd == -1) { 156 printf("Error opening %s - %s!\n", 157 dirent->d_name, strerror(errno)); 158 closedir(hugepage_dir); 159 result = -1; 160 goto end; 161 } 162 163 /* non-blocking lock */ 164 lck_result = flock(fd, LOCK_EX | LOCK_NB); 165 166 /* if lock succeeds, there's something wrong */ 167 if (lck_result != -1) { 168 result = 0; 169 170 /* unlock the resulting lock */ 171 flock(fd, LOCK_UN); 172 close(fd); 173 closedir(hugepage_dir); 174 goto end; 175 } 176 result = 1; 177 close(fd); 178 } 179 break; 180 /* shouldn't happen */ 181 default: 182 goto end; 183 } /* switch */ 184 185 } /* read hugepage directory */ 186 closedir(hugepage_dir); 187 } /* read /proc/mounts */ 188 end: 189 fclose(hugedir_handle); 190 return result; 191 } 192 193 #ifdef RTE_EXEC_ENV_LINUX 194 /* 195 * count the number of "node*" files in /sys/devices/system/node/ 196 */ 197 static int 198 get_number_of_sockets(void) 199 { 200 struct dirent *dirent = NULL; 201 const char * nodedir = "/sys/devices/system/node/"; 202 DIR * dir = NULL; 203 int result = 0; 204 205 /* check if directory exists */ 206 if ((dir = opendir(nodedir)) == NULL) { 207 /* if errno==ENOENT this means we don't have NUMA support */ 208 if (errno == ENOENT) { 209 printf("No NUMA nodes detected: assuming 1 available socket\n"); 210 return 1; 211 } 212 printf("Error opening %s: %s\n", nodedir, strerror(errno)); 213 return -1; 214 } 215 216 while ((dirent = readdir(dir)) != NULL) 217 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0) 218 result++; 219 220 closedir(dir); 221 return result; 222 } 223 #endif 224 225 /* 226 * Test that the app doesn't run with invalid whitelist option. 227 * Final tests ensures it does run with valid options as sanity check (one 228 * test for with Domain+BDF, second for just with BDF) 229 */ 230 static int 231 test_whitelist_flag(void) 232 { 233 unsigned i; 234 #ifdef RTE_EXEC_ENV_FREEBSD 235 /* BSD target doesn't support prefixes at this point */ 236 const char * prefix = ""; 237 #else 238 char prefix[PATH_MAX], tmp[PATH_MAX]; 239 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { 240 printf("Error - unable to get current prefix!\n"); 241 return -1; 242 } 243 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 244 #endif 245 246 const char *wlinval[][11] = { 247 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", 248 pci_whitelist, "error", "", ""}, 249 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", 250 pci_whitelist, "0:0:0", "", ""}, 251 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", 252 pci_whitelist, "0:error:0.1", "", ""}, 253 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", 254 pci_whitelist, "0:0:0.1error", "", ""}, 255 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", 256 pci_whitelist, "error0:0:0.1", "", ""}, 257 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", 258 pci_whitelist, "0:0:0.1.2", "", ""}, 259 }; 260 /* Test with valid whitelist option */ 261 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", 262 pci_whitelist, "00FF:09:0B.3"}; 263 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", 264 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"}; 265 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", 266 pci_whitelist, "09:0B.3,type=test", 267 pci_whitelist, "08:00.1,type=normal", 268 }; 269 270 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) { 271 if (launch_proc(wlinval[i]) == 0) { 272 printf("Error - process did run ok with invalid " 273 "whitelist parameter\n"); 274 return -1; 275 } 276 } 277 if (launch_proc(wlval1) != 0 ) { 278 printf("Error - process did not run ok with valid whitelist\n"); 279 return -1; 280 } 281 if (launch_proc(wlval2) != 0 ) { 282 printf("Error - process did not run ok with valid whitelist value set\n"); 283 return -1; 284 } 285 if (launch_proc(wlval3) != 0 ) { 286 printf("Error - process did not run ok with valid whitelist + args\n"); 287 return -1; 288 } 289 290 return 0; 291 } 292 293 /* 294 * Test that the app doesn't run with invalid blacklist option. 295 * Final test ensures it does run with valid options as sanity check 296 */ 297 static int 298 test_invalid_b_flag(void) 299 { 300 #ifdef RTE_EXEC_ENV_FREEBSD 301 /* BSD target doesn't support prefixes at this point */ 302 const char * prefix = ""; 303 #else 304 char prefix[PATH_MAX], tmp[PATH_MAX]; 305 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { 306 printf("Error - unable to get current prefix!\n"); 307 return -1; 308 } 309 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 310 #endif 311 312 const char *blinval[][9] = { 313 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"}, 314 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"}, 315 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"}, 316 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"}, 317 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"}, 318 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"}, 319 }; 320 /* Test with valid blacklist option */ 321 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"}; 322 323 int i; 324 325 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) { 326 if (launch_proc(blinval[i]) == 0) { 327 printf("Error - process did run ok with invalid " 328 "blacklist parameter\n"); 329 return -1; 330 } 331 } 332 if (launch_proc(blval) != 0) { 333 printf("Error - process did not run ok with valid blacklist value\n"); 334 return -1; 335 } 336 return 0; 337 } 338 339 /* 340 * Test that the app doesn't run with invalid vdev option. 341 * Final test ensures it does run with valid options as sanity check 342 */ 343 #ifdef RTE_LIBRTE_PMD_RING 344 static int 345 test_invalid_vdev_flag(void) 346 { 347 #ifdef RTE_EXEC_ENV_FREEBSD 348 /* BSD target doesn't support prefixes at this point, and we also need to 349 * run another primary process here */ 350 const char * prefix = no_shconf; 351 #else 352 const char * prefix = "--file-prefix=vdev"; 353 #endif 354 355 /* Test with invalid vdev option */ 356 const char *vdevinval[] = {prgname, prefix, no_huge, "-n", "1", 357 "-c", "1", vdev, "eth_dummy"}; 358 359 /* Test with valid vdev option */ 360 const char *vdevval1[] = {prgname, prefix, no_huge, "-n", "1", 361 "-c", "1", vdev, "net_ring0"}; 362 363 const char *vdevval2[] = {prgname, prefix, no_huge, "-n", "1", 364 "-c", "1", vdev, "net_ring0,args=test"}; 365 366 const char *vdevval3[] = {prgname, prefix, no_huge, "-n", "1", 367 "-c", "1", vdev, "net_ring0,nodeaction=r1:0:CREATE"}; 368 369 if (launch_proc(vdevinval) == 0) { 370 printf("Error - process did run ok with invalid " 371 "vdev parameter\n"); 372 return -1; 373 } 374 375 if (launch_proc(vdevval1) != 0) { 376 printf("Error - process did not run ok with valid vdev value\n"); 377 return -1; 378 } 379 380 if (launch_proc(vdevval2) != 0) { 381 printf("Error - process did not run ok with valid vdev value," 382 "with dummy args\n"); 383 return -1; 384 } 385 386 if (launch_proc(vdevval3) != 0) { 387 printf("Error - process did not run ok with valid vdev value," 388 "with valid args\n"); 389 return -1; 390 } 391 return 0; 392 } 393 #endif 394 395 /* 396 * Test that the app doesn't run with invalid -r option. 397 */ 398 static int 399 test_invalid_r_flag(void) 400 { 401 #ifdef RTE_EXEC_ENV_FREEBSD 402 /* BSD target doesn't support prefixes at this point */ 403 const char * prefix = ""; 404 #else 405 char prefix[PATH_MAX], tmp[PATH_MAX]; 406 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { 407 printf("Error - unable to get current prefix!\n"); 408 return -1; 409 } 410 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 411 #endif 412 413 const char *rinval[][9] = { 414 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"}, 415 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"}, 416 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"}, 417 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"}, 418 }; 419 /* Test with valid blacklist option */ 420 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"}; 421 422 int i; 423 424 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) { 425 if (launch_proc(rinval[i]) == 0) { 426 printf("Error - process did run ok with invalid " 427 "-r (rank) parameter\n"); 428 return -1; 429 } 430 } 431 if (launch_proc(rval) != 0) { 432 printf("Error - process did not run ok with valid -r (rank) value\n"); 433 return -1; 434 } 435 return 0; 436 } 437 438 /* 439 * Test that the app doesn't run without the coremask/corelist flags. In all cases 440 * should give an error and fail to run 441 */ 442 static int 443 test_missing_c_flag(void) 444 { 445 #ifdef RTE_EXEC_ENV_FREEBSD 446 /* BSD target doesn't support prefixes at this point */ 447 const char * prefix = ""; 448 #else 449 char prefix[PATH_MAX], tmp[PATH_MAX]; 450 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { 451 printf("Error - unable to get current prefix!\n"); 452 return -1; 453 } 454 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 455 #endif 456 457 /* -c flag but no coremask value */ 458 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"}; 459 /* No -c, -l or --lcores flag at all */ 460 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"}; 461 /* bad coremask value */ 462 const char *argv3[] = { prgname, prefix, mp_flag, 463 "-n", "3", "-c", "error" }; 464 /* sanity check of tests - valid coremask value */ 465 const char *argv4[] = { prgname, prefix, mp_flag, 466 "-n", "3", "-c", "1" }; 467 /* -l flag but no corelist value */ 468 const char *argv5[] = { prgname, prefix, mp_flag, 469 "-n", "3", "-l"}; 470 const char *argv6[] = { prgname, prefix, mp_flag, 471 "-n", "3", "-l", " " }; 472 /* bad corelist values */ 473 const char *argv7[] = { prgname, prefix, mp_flag, 474 "-n", "3", "-l", "error" }; 475 const char *argv8[] = { prgname, prefix, mp_flag, 476 "-n", "3", "-l", "1-" }; 477 const char *argv9[] = { prgname, prefix, mp_flag, 478 "-n", "3", "-l", "1," }; 479 const char *argv10[] = { prgname, prefix, mp_flag, 480 "-n", "3", "-l", "1#2" }; 481 /* core number is negative value */ 482 const char * const argv11[] = { prgname, prefix, mp_flag, 483 "-n", "3", "-l", "-5" }; 484 const char * const argv12[] = { prgname, prefix, mp_flag, 485 "-n", "3", "-l", "-5-7" }; 486 /* core number is maximum value */ 487 const char * const argv13[] = { prgname, prefix, mp_flag, 488 "-n", "3", "-l", RTE_STR(RTE_MAX_LCORE) }; 489 const char * const argv14[] = { prgname, prefix, mp_flag, 490 "-n", "3", "-l", "1-"RTE_STR(RTE_MAX_LCORE) }; 491 /* sanity check test - valid corelist value */ 492 const char * const argv15[] = { prgname, prefix, mp_flag, 493 "-n", "3", "-l", "1-2,3" }; 494 495 /* --lcores flag but no lcores value */ 496 const char * const argv16[] = { prgname, prefix, mp_flag, 497 "-n", "3", "--lcores" }; 498 const char * const argv17[] = { prgname, prefix, mp_flag, 499 "-n", "3", "--lcores", " " }; 500 /* bad lcores value */ 501 const char * const argv18[] = { prgname, prefix, mp_flag, 502 "-n", "3", "--lcores", "1-3-5" }; 503 const char * const argv19[] = { prgname, prefix, mp_flag, 504 "-n", "3", "--lcores", "0-1,,2" }; 505 const char * const argv20[] = { prgname, prefix, mp_flag, 506 "-n", "3", "--lcores", "0-,1" }; 507 const char * const argv21[] = { prgname, prefix, mp_flag, 508 "-n", "3", "--lcores", "(0-,2-4)" }; 509 const char * const argv22[] = { prgname, prefix, mp_flag, 510 "-n", "3", "--lcores", "(-1,2)" }; 511 const char * const argv23[] = { prgname, prefix, mp_flag, 512 "-n", "3", "--lcores", "(2-4)@(2-4-6)" }; 513 const char * const argv24[] = { prgname, prefix, mp_flag, 514 "-n", "3", "--lcores", "(a,2)" }; 515 const char * const argv25[] = { prgname, prefix, mp_flag, 516 "-n", "3", "--lcores", "1-3@(1,3)" }; 517 const char * const argv26[] = { prgname, prefix, mp_flag, 518 "-n", "3", "--lcores", "3@((1,3)" }; 519 const char * const argv27[] = { prgname, prefix, mp_flag, 520 "-n", "3", "--lcores", "(4-7)=(1,3)" }; 521 const char * const argv28[] = { prgname, prefix, mp_flag, 522 "-n", "3", "--lcores", "[4-7]@(1,3)" }; 523 /* sanity check of tests - valid lcores value */ 524 const char * const argv29[] = { prgname, prefix, mp_flag, 525 "-n", "3", "--lcores", 526 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"}; 527 528 if (launch_proc(argv2) != 0) { 529 printf("Error - " 530 "process did not run ok when missing -c flag\n"); 531 return -1; 532 } 533 534 if (launch_proc(argv1) == 0 535 || launch_proc(argv3) == 0) { 536 printf("Error - " 537 "process ran without error with invalid -c flag\n"); 538 return -1; 539 } 540 if (launch_proc(argv4) != 0) { 541 printf("Error - " 542 "process did not run ok with valid coremask value\n"); 543 return -1; 544 } 545 546 /* start -l test */ 547 if (launch_proc(argv5) == 0 548 || launch_proc(argv6) == 0 549 || launch_proc(argv7) == 0 550 || launch_proc(argv8) == 0 551 || launch_proc(argv9) == 0 552 || launch_proc(argv10) == 0 553 || launch_proc(argv11) == 0 554 || launch_proc(argv12) == 0 555 || launch_proc(argv13) == 0 556 || launch_proc(argv14) == 0) { 557 printf("Error - " 558 "process ran without error with invalid -l flag\n"); 559 return -1; 560 } 561 if (launch_proc(argv15) != 0) { 562 printf("Error - " 563 "process did not run ok with valid corelist value\n"); 564 return -1; 565 } 566 567 /* start --lcores tests */ 568 if (launch_proc(argv16) == 0 || launch_proc(argv17) == 0 || 569 launch_proc(argv18) == 0 || launch_proc(argv19) == 0 || 570 launch_proc(argv20) == 0 || launch_proc(argv21) == 0 || 571 launch_proc(argv22) == 0 || launch_proc(argv23) == 0 || 572 launch_proc(argv24) == 0 || launch_proc(argv25) == 0 || 573 launch_proc(argv26) == 0 || launch_proc(argv27) == 0 || 574 launch_proc(argv28) == 0) { 575 printf("Error - " 576 "process ran without error with invalid --lcore flag\n"); 577 return -1; 578 } 579 580 if (launch_proc(argv29) != 0) { 581 printf("Error - " 582 "process did not run ok with valid corelist value\n"); 583 return -1; 584 } 585 586 return 0; 587 } 588 589 /* 590 * Test --master-lcore option with matching coremask 591 */ 592 static int 593 test_master_lcore_flag(void) 594 { 595 #ifdef RTE_EXEC_ENV_FREEBSD 596 /* BSD target doesn't support prefixes at this point */ 597 const char *prefix = ""; 598 #else 599 char prefix[PATH_MAX], tmp[PATH_MAX]; 600 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { 601 printf("Error - unable to get current prefix!\n"); 602 return -1; 603 } 604 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 605 #endif 606 607 /* --master-lcore flag but no value */ 608 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"}; 609 /* --master-lcore flag with invalid value */ 610 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"}; 611 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"}; 612 /* master lcore not in coremask */ 613 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"}; 614 /* valid value */ 615 const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"}; 616 /* valid value set before coremask */ 617 const char *argv6[] = { prgname, prefix, mp_flag, "-n", "1", "--master-lcore", "1", "-c", "3"}; 618 619 if (launch_proc(argv1) == 0 620 || launch_proc(argv2) == 0 621 || launch_proc(argv3) == 0 622 || launch_proc(argv4) == 0) { 623 printf("Error - process ran without error with wrong --master-lcore\n"); 624 return -1; 625 } 626 if (launch_proc(argv5) != 0 627 || launch_proc(argv6) != 0) { 628 printf("Error - process did not run ok with valid --master-lcore\n"); 629 return -1; 630 } 631 return 0; 632 } 633 634 /* 635 * Test that the app doesn't run with invalid -n flag option. 636 * Final test ensures it does run with valid options as sanity check 637 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf 638 * flags. 639 */ 640 static int 641 test_invalid_n_flag(void) 642 { 643 #ifdef RTE_EXEC_ENV_FREEBSD 644 /* BSD target doesn't support prefixes at this point */ 645 const char * prefix = ""; 646 #else 647 char prefix[PATH_MAX], tmp[PATH_MAX]; 648 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { 649 printf("Error - unable to get current prefix!\n"); 650 return -1; 651 } 652 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 653 #endif 654 655 /* -n flag but no value */ 656 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"}; 657 /* bad numeric value */ 658 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" }; 659 /* zero is invalid */ 660 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "0" }; 661 /* sanity test - check with good value */ 662 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" }; 663 /* sanity test - check with no -n flag */ 664 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"}; 665 666 if (launch_proc(argv1) == 0 667 || launch_proc(argv2) == 0 668 || launch_proc(argv3) == 0) { 669 printf("Error - process ran without error when" 670 "invalid -n flag\n"); 671 return -1; 672 } 673 if (launch_proc(argv4) != 0) { 674 printf("Error - process did not run ok with valid num-channel value\n"); 675 return -1; 676 } 677 if (launch_proc(argv5) != 0) { 678 printf("Error - process did not run ok without -n flag\n"); 679 return -1; 680 } 681 682 return 0; 683 } 684 685 /* 686 * Test that the app runs with HPET, and without HPET 687 */ 688 static int 689 test_no_hpet_flag(void) 690 { 691 char prefix[PATH_MAX] = ""; 692 693 #ifdef RTE_EXEC_ENV_FREEBSD 694 return 0; 695 #else 696 char tmp[PATH_MAX]; 697 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { 698 printf("Error - unable to get current prefix!\n"); 699 return -1; 700 } 701 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 702 #endif 703 704 /* With --no-hpet */ 705 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"}; 706 /* Without --no-hpet */ 707 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"}; 708 709 if (launch_proc(argv1) != 0) { 710 printf("Error - process did not run ok with --no-hpet flag\n"); 711 return -1; 712 } 713 if (launch_proc(argv2) != 0) { 714 printf("Error - process did not run ok without --no-hpet flag\n"); 715 return -1; 716 } 717 return 0; 718 } 719 720 /* 721 * Test that the app runs with --no-huge and doesn't run when --socket-mem are 722 * specified with --no-huge. 723 */ 724 static int 725 test_no_huge_flag(void) 726 { 727 #ifdef RTE_EXEC_ENV_FREEBSD 728 /* BSD target doesn't support prefixes at this point, and we also need to 729 * run another primary process here */ 730 const char * prefix = no_shconf; 731 #else 732 const char * prefix = "--file-prefix=nohuge"; 733 #endif 734 735 /* With --no-huge */ 736 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"}; 737 /* With --no-huge and -m */ 738 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", 739 "-m", DEFAULT_MEM_SIZE}; 740 741 /* With --no-huge and --socket-mem */ 742 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", 743 "--socket-mem=" DEFAULT_MEM_SIZE}; 744 /* With --no-huge, -m and --socket-mem */ 745 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", 746 "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE}; 747 if (launch_proc(argv1) != 0) { 748 printf("Error - process did not run ok with --no-huge flag\n"); 749 return -1; 750 } 751 if (launch_proc(argv2) != 0) { 752 printf("Error - process did not run ok with --no-huge and -m flags\n"); 753 return -1; 754 } 755 #ifdef RTE_EXEC_ENV_FREEBSD 756 /* BSD target does not support NUMA, hence no --socket-mem tests */ 757 return 0; 758 #endif 759 760 if (launch_proc(argv3) == 0) { 761 printf("Error - process run ok with --no-huge and --socket-mem " 762 "flags\n"); 763 return -1; 764 } 765 if (launch_proc(argv4) == 0) { 766 printf("Error - process run ok with --no-huge, -m and " 767 "--socket-mem flags\n"); 768 return -1; 769 } 770 return 0; 771 } 772 773 static int 774 test_misc_flags(void) 775 { 776 char hugepath[PATH_MAX] = {0}; 777 #ifdef RTE_EXEC_ENV_FREEBSD 778 /* BSD target doesn't support prefixes at this point */ 779 const char * prefix = ""; 780 const char * nosh_prefix = ""; 781 #else 782 char prefix[PATH_MAX], tmp[PATH_MAX]; 783 const char * nosh_prefix = "--file-prefix=noshconf"; 784 FILE * hugedir_handle = NULL; 785 char line[PATH_MAX] = {0}; 786 unsigned i, isempty = 1; 787 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { 788 printf("Error - unable to get current prefix!\n"); 789 return -1; 790 } 791 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 792 793 /* 794 * get first valid hugepage path 795 */ 796 797 /* get hugetlbfs mountpoints from /proc/mounts */ 798 hugedir_handle = fopen("/proc/mounts", "r"); 799 800 if (hugedir_handle == NULL) { 801 printf("Error opening /proc/mounts!\n"); 802 return -1; 803 } 804 805 /* read /proc/mounts */ 806 while (fgets(line, sizeof(line), hugedir_handle) != NULL) { 807 808 /* find first valid hugepath */ 809 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath))) 810 break; 811 } 812 813 fclose(hugedir_handle); 814 815 /* check if path is not empty */ 816 for (i = 0; i < sizeof(hugepath); i++) 817 if (hugepath[i] != '\0') 818 isempty = 0; 819 820 if (isempty) { 821 printf("No mounted hugepage dir found!\n"); 822 return -1; 823 } 824 #endif 825 826 827 /* check that some general flags don't prevent things from working. 828 * All cases, apart from the first, app should run. 829 * No further testing of output done. 830 */ 831 /* sanity check - failure with invalid option */ 832 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"}; 833 834 /* With --no-pci */ 835 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"}; 836 /* With -v */ 837 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"}; 838 /* With valid --syslog */ 839 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1", 840 "--syslog", "syslog"}; 841 /* With empty --syslog (should fail) */ 842 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"}; 843 /* With invalid --syslog */ 844 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"}; 845 /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */ 846 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE, 847 no_shconf, nosh_prefix, no_huge}; 848 849 /* With --huge-dir */ 850 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE, 851 "--file-prefix=hugedir", "--huge-dir", hugepath}; 852 /* With empty --huge-dir (should fail) */ 853 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE, 854 "--file-prefix=hugedir", "--huge-dir"}; 855 /* With invalid --huge-dir */ 856 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE, 857 "--file-prefix=hugedir", "--huge-dir", "invalid"}; 858 /* Secondary process with invalid --huge-dir (should run as flag has no 859 * effect on secondary processes) */ 860 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"}; 861 862 /* try running with base-virtaddr param */ 863 const char *argv11[] = {prgname, "--file-prefix=virtaddr", 864 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"}; 865 866 /* try running with --vfio-intr INTx flag */ 867 const char *argv12[] = {prgname, "--file-prefix=intr", 868 "-c", "1", "-n", "2", "--vfio-intr=legacy"}; 869 870 /* try running with --vfio-intr MSI flag */ 871 const char *argv13[] = {prgname, "--file-prefix=intr", 872 "-c", "1", "-n", "2", "--vfio-intr=msi"}; 873 874 /* try running with --vfio-intr MSI-X flag */ 875 const char *argv14[] = {prgname, "--file-prefix=intr", 876 "-c", "1", "-n", "2", "--vfio-intr=msix"}; 877 878 /* try running with --vfio-intr invalid flag */ 879 const char *argv15[] = {prgname, "--file-prefix=intr", 880 "-c", "1", "-n", "2", "--vfio-intr=invalid"}; 881 882 /* run all tests also applicable to FreeBSD first */ 883 884 if (launch_proc(argv0) == 0) { 885 printf("Error - process ran ok with invalid flag\n"); 886 return -1; 887 } 888 if (launch_proc(argv1) != 0) { 889 printf("Error - process did not run ok with --no-pci flag\n"); 890 return -1; 891 } 892 if (launch_proc(argv2) != 0) { 893 printf("Error - process did not run ok with -v flag\n"); 894 return -1; 895 } 896 if (launch_proc(argv6) != 0) { 897 printf("Error - process did not run ok with --no-shconf flag\n"); 898 return -1; 899 } 900 901 #ifdef RTE_EXEC_ENV_FREEBSD 902 /* no more tests to be done on FreeBSD */ 903 return 0; 904 #endif 905 906 if (launch_proc(argv3) != 0) { 907 printf("Error - process did not run ok with --syslog flag\n"); 908 return -1; 909 } 910 if (launch_proc(argv4) == 0) { 911 printf("Error - process run ok with empty --syslog flag\n"); 912 return -1; 913 } 914 if (launch_proc(argv5) == 0) { 915 printf("Error - process run ok with invalid --syslog flag\n"); 916 return -1; 917 } 918 if (launch_proc(argv7) != 0) { 919 printf("Error - process did not run ok with --huge-dir flag\n"); 920 return -1; 921 } 922 if (launch_proc(argv8) == 0) { 923 printf("Error - process run ok with empty --huge-dir flag\n"); 924 return -1; 925 } 926 if (launch_proc(argv9) == 0) { 927 printf("Error - process run ok with invalid --huge-dir flag\n"); 928 return -1; 929 } 930 if (launch_proc(argv10) != 0) { 931 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n"); 932 return -1; 933 } 934 if (launch_proc(argv11) != 0) { 935 printf("Error - process did not run ok with --base-virtaddr parameter\n"); 936 return -1; 937 } 938 if (launch_proc(argv12) != 0) { 939 printf("Error - process did not run ok with " 940 "--vfio-intr INTx parameter\n"); 941 return -1; 942 } 943 if (launch_proc(argv13) != 0) { 944 printf("Error - process did not run ok with " 945 "--vfio-intr MSI parameter\n"); 946 return -1; 947 } 948 if (launch_proc(argv14) != 0) { 949 printf("Error - process did not run ok with " 950 "--vfio-intr MSI-X parameter\n"); 951 return -1; 952 } 953 if (launch_proc(argv15) == 0) { 954 printf("Error - process run ok with " 955 "--vfio-intr invalid parameter\n"); 956 return -1; 957 } 958 return 0; 959 } 960 961 static int 962 test_file_prefix(void) 963 { 964 /* 965 * 1. check if current process hugefiles are locked 966 * 2. try to run secondary process without a corresponding primary process 967 * (while failing to run, it will also remove any unused hugepage files) 968 * 3. check if current process hugefiles are still in place and are locked 969 * 4. run a primary process with memtest1 prefix in default and legacy 970 * mem mode 971 * 5. check if memtest1 hugefiles are created in case of legacy mem 972 * mode, and deleted in case of default mem mode 973 * 6. run a primary process with memtest2 prefix in default and legacy 974 * mem modes 975 * 7. check that memtest2 hugefiles are present in the hugedir after a 976 * run in legacy mode, and not present at all after run in default 977 * mem mode 978 */ 979 char prefix[PATH_MAX] = ""; 980 981 #ifdef RTE_EXEC_ENV_FREEBSD 982 return 0; 983 #else 984 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) { 985 printf("Error - unable to get current prefix!\n"); 986 return -1; 987 } 988 #endif 989 990 /* this should fail unless the test itself is run with "memtest" prefix */ 991 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE, 992 "--file-prefix=" memtest }; 993 994 /* primary process with memtest1 and default mem mode */ 995 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", 996 DEFAULT_MEM_SIZE, "--file-prefix=" memtest1 }; 997 998 /* primary process with memtest1 and legacy mem mode */ 999 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", 1000 DEFAULT_MEM_SIZE, "--file-prefix=" memtest1, 1001 "--legacy-mem" }; 1002 1003 /* primary process with memtest2 and legacy mem mode */ 1004 const char *argv3[] = {prgname, "-c", "1", "-n", "2", "-m", 1005 DEFAULT_MEM_SIZE, "--file-prefix=" memtest2, 1006 "--legacy-mem" }; 1007 1008 /* primary process with memtest2 and default mem mode */ 1009 const char *argv4[] = {prgname, "-c", "1", "-n", "2", "-m", 1010 DEFAULT_MEM_SIZE, "--file-prefix=" memtest2 }; 1011 1012 /* check if files for current prefix are present */ 1013 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) { 1014 printf("Error - hugepage files for %s were not created!\n", prefix); 1015 return -1; 1016 } 1017 1018 /* checks if files for current prefix are locked */ 1019 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) { 1020 printf("Error - hugepages for current process aren't locked!\n"); 1021 return -1; 1022 } 1023 1024 /* check if files for secondary process are present */ 1025 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) { 1026 /* check if they are not locked */ 1027 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) { 1028 printf("Error - hugepages for current process are locked!\n"); 1029 return -1; 1030 } 1031 /* they aren't locked, delete them */ 1032 else { 1033 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) { 1034 printf("Error - deleting hugepages failed!\n"); 1035 return -1; 1036 } 1037 } 1038 } 1039 1040 if (launch_proc(argv0) == 0) { 1041 printf("Error - secondary process ran ok without primary process\n"); 1042 return -1; 1043 } 1044 1045 /* check if files for current prefix are present */ 1046 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) { 1047 printf("Error - hugepage files for %s were not created!\n", prefix); 1048 return -1; 1049 } 1050 1051 /* checks if files for current prefix are locked */ 1052 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) { 1053 printf("Error - hugepages for current process aren't locked!\n"); 1054 return -1; 1055 } 1056 1057 /* we're running this process in default memory mode, which means it 1058 * should clean up after itself on exit and leave no hugepages behind. 1059 */ 1060 if (launch_proc(argv1) != 0) { 1061 printf("Error - failed to run with --file-prefix=%s\n", 1062 memtest1); 1063 return -1; 1064 } 1065 1066 /* check if memtest1_map0 is present */ 1067 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) { 1068 printf("Error - hugepage files for %s were not deleted!\n", 1069 memtest1); 1070 return -1; 1071 } 1072 1073 /* now, we're running a process under the same prefix, but with legacy 1074 * mem mode - this should leave behind hugepage files. 1075 */ 1076 if (launch_proc(argv2) != 0) { 1077 printf("Error - failed to run with --file-prefix=%s\n", 1078 memtest1); 1079 return -1; 1080 } 1081 1082 /* check if memtest1_map0 is present */ 1083 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) { 1084 printf("Error - hugepage files for %s were not created!\n", 1085 memtest1); 1086 return -1; 1087 } 1088 1089 if (launch_proc(argv3) != 0) { 1090 printf("Error - failed to run with --file-prefix=%s\n", 1091 memtest2); 1092 return -1; 1093 } 1094 1095 /* check if hugefiles for memtest2 are present */ 1096 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) { 1097 printf("Error - hugepage files for %s were not created!\n", 1098 memtest2); 1099 return -1; 1100 } 1101 1102 /* check if hugefiles for memtest1 are present */ 1103 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) { 1104 printf("Error - hugepage files for %s were not deleted!\n", 1105 memtest1); 1106 return -1; 1107 } 1108 1109 /* this process will run in default mem mode, so it should not leave any 1110 * hugepage files behind. 1111 */ 1112 if (launch_proc(argv4) != 0) { 1113 printf("Error - failed to run with --file-prefix=%s\n", 1114 memtest2); 1115 return -1; 1116 } 1117 1118 /* check if hugefiles for memtest2 are present */ 1119 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 0) { 1120 printf("Error - hugepage files for %s were not deleted!\n", 1121 memtest2); 1122 return -1; 1123 } 1124 1125 /* check if hugefiles for memtest1 are present */ 1126 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) { 1127 printf("Error - hugepage files for %s were not deleted!\n", 1128 memtest1); 1129 return -1; 1130 } 1131 1132 return 0; 1133 } 1134 1135 /* 1136 * Tests for correct handling of -m and --socket-mem flags 1137 */ 1138 static int 1139 test_memory_flags(void) 1140 { 1141 #ifdef RTE_EXEC_ENV_FREEBSD 1142 /* BSD target doesn't support prefixes at this point */ 1143 const char * prefix = ""; 1144 #else 1145 char prefix[PATH_MAX], tmp[PATH_MAX]; 1146 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { 1147 printf("Error - unable to get current prefix!\n"); 1148 return -1; 1149 } 1150 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 1151 #endif 1152 1153 /* valid -m flag and mp flag */ 1154 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10", 1155 "-n", "2", "-m", DEFAULT_MEM_SIZE}; 1156 1157 /* valid -m flag */ 1158 const char *argv1[] = {prgname, "-c", "10", "-n", "2", 1159 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE}; 1160 1161 /* valid (zero) --socket-mem flag */ 1162 const char *argv2[] = {prgname, "-c", "10", "-n", "2", 1163 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"}; 1164 1165 /* invalid (incomplete) --socket-mem flag */ 1166 const char *argv3[] = {prgname, "-c", "10", "-n", "2", 1167 "--file-prefix=" memtest, "--socket-mem=2,2,"}; 1168 1169 /* invalid (mixed with invalid data) --socket-mem flag */ 1170 const char *argv4[] = {prgname, "-c", "10", "-n", "2", 1171 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"}; 1172 1173 /* invalid (with numeric value as last character) --socket-mem flag */ 1174 const char *argv5[] = {prgname, "-c", "10", "-n", "2", 1175 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"}; 1176 1177 /* invalid (with empty socket) --socket-mem flag */ 1178 const char *argv6[] = {prgname, "-c", "10", "-n", "2", 1179 "--file-prefix=" memtest, "--socket-mem=2,,2"}; 1180 1181 /* invalid (null) --socket-mem flag */ 1182 const char *argv7[] = {prgname, "-c", "10", "-n", "2", 1183 "--file-prefix=" memtest, "--socket-mem="}; 1184 1185 /* valid --socket-mem specified together with -m flag */ 1186 const char *argv8[] = {prgname, "-c", "10", "-n", "2", 1187 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"}; 1188 1189 /* construct an invalid socket mask with 2 megs on each socket plus 1190 * extra 2 megs on socket that doesn't exist on current system */ 1191 char invalid_socket_mem[SOCKET_MEM_STRLEN]; 1192 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */ 1193 1194 #ifdef RTE_EXEC_ENV_FREEBSD 1195 int i, num_sockets = 1; 1196 #else 1197 int i, num_sockets = RTE_MIN(get_number_of_sockets(), 1198 RTE_MAX_NUMA_NODES); 1199 #endif 1200 1201 if (num_sockets <= 0) { 1202 printf("Error - cannot get number of sockets!\n"); 1203 return -1; 1204 } 1205 1206 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem="); 1207 1208 /* add one extra socket */ 1209 for (i = 0; i < num_sockets + 1; i++) { 1210 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE); 1211 strlcpy(invalid_socket_mem, buf, sizeof(invalid_socket_mem)); 1212 1213 if (num_sockets + 1 - i > 1) { 1214 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem); 1215 strlcpy(invalid_socket_mem, buf, 1216 sizeof(invalid_socket_mem)); 1217 } 1218 } 1219 1220 /* construct a valid socket mask with 2 megs on each existing socket */ 1221 char valid_socket_mem[SOCKET_MEM_STRLEN]; 1222 1223 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem="); 1224 1225 /* add one extra socket */ 1226 for (i = 0; i < num_sockets; i++) { 1227 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE); 1228 strlcpy(valid_socket_mem, buf, sizeof(valid_socket_mem)); 1229 1230 if (num_sockets - i > 1) { 1231 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem); 1232 strlcpy(valid_socket_mem, buf, 1233 sizeof(valid_socket_mem)); 1234 } 1235 } 1236 1237 /* invalid --socket-mem flag (with extra socket) */ 1238 const char *argv9[] = {prgname, "-c", "10", "-n", "2", 1239 "--file-prefix=" memtest, invalid_socket_mem}; 1240 1241 /* valid --socket-mem flag */ 1242 const char *argv10[] = {prgname, "-c", "10", "-n", "2", 1243 "--file-prefix=" memtest, valid_socket_mem}; 1244 1245 if (launch_proc(argv0) != 0) { 1246 printf("Error - secondary process failed with valid -m flag !\n"); 1247 return -1; 1248 } 1249 1250 #ifdef RTE_EXEC_ENV_FREEBSD 1251 /* no other tests are applicable to BSD */ 1252 return 0; 1253 #endif 1254 1255 if (launch_proc(argv1) != 0) { 1256 printf("Error - process failed with valid -m flag!\n"); 1257 return -1; 1258 } 1259 if (launch_proc(argv2) != 0) { 1260 printf("Error - process failed with valid (zero) --socket-mem!\n"); 1261 return -1; 1262 } 1263 1264 if (launch_proc(argv3) == 0) { 1265 printf("Error - process run ok with invalid " 1266 "(incomplete) --socket-mem!\n"); 1267 return -1; 1268 } 1269 1270 if (launch_proc(argv4) == 0) { 1271 printf("Error - process run ok with invalid " 1272 "(mixed with invalid input) --socket-mem!\n"); 1273 return -1; 1274 } 1275 1276 if (launch_proc(argv5) == 0) { 1277 printf("Error - process run ok with invalid " 1278 "(mixed with invalid input with a numeric value as " 1279 "last character) --socket-mem!\n"); 1280 return -1; 1281 } 1282 1283 if (launch_proc(argv6) == 0) { 1284 printf("Error - process run ok with invalid " 1285 "(with empty socket) --socket-mem!\n"); 1286 return -1; 1287 } 1288 1289 if (launch_proc(argv7) == 0) { 1290 printf("Error - process run ok with invalid (null) --socket-mem!\n"); 1291 return -1; 1292 } 1293 1294 if (launch_proc(argv8) == 0) { 1295 printf("Error - process run ok with --socket-mem and -m specified!\n"); 1296 return -1; 1297 } 1298 1299 if (launch_proc(argv9) == 0) { 1300 printf("Error - process run ok with extra socket in --socket-mem!\n"); 1301 return -1; 1302 } 1303 1304 if (launch_proc(argv10) != 0) { 1305 printf("Error - process failed with valid --socket-mem!\n"); 1306 return -1; 1307 } 1308 1309 return 0; 1310 } 1311 1312 static int 1313 test_eal_flags(void) 1314 { 1315 int ret = 0; 1316 1317 ret = test_missing_c_flag(); 1318 if (ret < 0) { 1319 printf("Error in test_missing_c_flag()\n"); 1320 return ret; 1321 } 1322 1323 ret = test_master_lcore_flag(); 1324 if (ret < 0) { 1325 printf("Error in test_master_lcore_flag()\n"); 1326 return ret; 1327 } 1328 1329 ret = test_invalid_n_flag(); 1330 if (ret < 0) { 1331 printf("Error in test_invalid_n_flag()\n"); 1332 return ret; 1333 } 1334 1335 ret = test_no_hpet_flag(); 1336 if (ret < 0) { 1337 printf("Error in test_no_hpet_flag()\n"); 1338 return ret; 1339 } 1340 1341 ret = test_no_huge_flag(); 1342 if (ret < 0) { 1343 printf("Error in test_no_huge_flag()\n"); 1344 return ret; 1345 } 1346 1347 ret = test_whitelist_flag(); 1348 if (ret < 0) { 1349 printf("Error in test_invalid_whitelist_flag()\n"); 1350 return ret; 1351 } 1352 1353 ret = test_invalid_b_flag(); 1354 if (ret < 0) { 1355 printf("Error in test_invalid_b_flag()\n"); 1356 return ret; 1357 } 1358 1359 #ifdef RTE_LIBRTE_PMD_RING 1360 ret = test_invalid_vdev_flag(); 1361 if (ret < 0) { 1362 printf("Error in test_invalid_vdev_flag()\n"); 1363 return ret; 1364 } 1365 #endif 1366 ret = test_invalid_r_flag(); 1367 if (ret < 0) { 1368 printf("Error in test_invalid_r_flag()\n"); 1369 return ret; 1370 } 1371 1372 ret = test_memory_flags(); 1373 if (ret < 0) { 1374 printf("Error in test_memory_flags()\n"); 1375 return ret; 1376 } 1377 1378 ret = test_file_prefix(); 1379 if (ret < 0) { 1380 printf("Error in test_file_prefix()\n"); 1381 return ret; 1382 } 1383 1384 ret = test_misc_flags(); 1385 if (ret < 0) { 1386 printf("Error in test_misc_flags()"); 1387 return ret; 1388 } 1389 1390 return ret; 1391 } 1392 1393 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags); 1394