+ printf("Error - process did not run ok with --syslog flag\n");
+ return -1;
+ }
+ if (launch_proc(argv4) == 0) {
+ printf("Error - process run ok with empty --syslog flag\n");
+ return -1;
+ }
+ if (launch_proc(argv5) == 0) {
+ printf("Error - process run ok with invalid --syslog flag\n");
+ return -1;
+ }
+ if (launch_proc(argv6) != 0) {
+ printf("Error - process did not run ok with --no-shconf flag\n");
+ return -1;
+ }
+#ifdef RTE_EXEC_ENV_BSDAPP
+ return 0;
+#endif
+ if (launch_proc(argv7) != 0) {
+ printf("Error - process did not run ok with --huge-dir flag\n");
+ return -1;
+ }
+ if (launch_proc(argv8) == 0) {
+ printf("Error - process run ok with empty --huge-dir flag\n");
+ return -1;
+ }
+ if (launch_proc(argv9) == 0) {
+ printf("Error - process run ok with invalid --huge-dir flag\n");
+ return -1;
+ }
+ if (launch_proc(argv10) != 0) {
+ printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
+ return -1;
+ }
+ if (launch_proc(argv11) != 0) {
+ printf("Error - process did not run ok with --base-virtaddr parameter\n");
+ return -1;
+ }
+ if (launch_proc(argv12) != 0) {
+ printf("Error - process did not run ok with "
+ "--vfio-intr INTx parameter\n");
+ return -1;
+ }
+ if (launch_proc(argv13) != 0) {
+ printf("Error - process did not run ok with "
+ "--vfio-intr MSI parameter\n");
+ return -1;
+ }
+ if (launch_proc(argv14) != 0) {
+ printf("Error - process did not run ok with "
+ "--vfio-intr MSI-X parameter\n");
+ return -1;
+ }
+ if (launch_proc(argv15) == 0) {
+ printf("Error - process run ok with "
+ "--vfio-intr invalid parameter\n");
+ return -1;
+ }
+ return 0;
+}
+#endif
+
+static int
+test_file_prefix(void)
+{
+ /*
+ * 1. check if current process hugefiles are locked
+ * 2. try to run secondary process without a corresponding primary process
+ * (while failing to run, it will also remove any unused hugepage files)
+ * 3. check if current process hugefiles are still in place and are locked
+ * 4. run a primary process with memtest1 prefix
+ * 5. check if memtest1 hugefiles are created
+ * 6. run a primary process with memtest2 prefix
+ * 7. check that only memtest2 hugefiles are present in the hugedir
+ */
+
+#ifdef RTE_EXEC_ENV_BSDAPP
+ return 0;
+#endif
+
+ /* this should fail unless the test itself is run with "memtest" prefix */
+ const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
+ "--file-prefix=" memtest };
+
+ /* primary process with memtest1 */
+ const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
+ "--file-prefix=" memtest1 };
+
+ /* primary process with memtest2 */
+ const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
+ "--file-prefix=" memtest2 };
+
+ char prefix[32];
+ if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
+ printf("Error - unable to get current prefix!\n");
+ return -1;
+ }
+#ifdef RTE_LIBRTE_XEN_DOM0
+ return 0;
+#endif
+
+ /* check if files for current prefix are present */
+ if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
+ printf("Error - hugepage files for %s were not created!\n", prefix);
+ return -1;
+ }
+
+ /* checks if files for current prefix are locked */
+ if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
+ printf("Error - hugepages for current process aren't locked!\n");
+ return -1;
+ }
+
+ /* check if files for secondary process are present */
+ if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
+ /* check if they are not locked */
+ if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
+ printf("Error - hugepages for current process are locked!\n");
+ return -1;
+ }
+ /* they aren't locked, delete them */
+ else {
+ if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
+ printf("Error - deleting hugepages failed!\n");
+ return -1;
+ }
+ }
+ }
+
+ if (launch_proc(argv0) == 0) {
+ printf("Error - secondary process ran ok without primary process\n");
+ return -1;
+ }
+
+ /* check if files for current prefix are present */
+ if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
+ printf("Error - hugepage files for %s were not created!\n", prefix);
+ return -1;
+ }
+
+ /* checks if files for current prefix are locked */
+ if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
+ printf("Error - hugepages for current process aren't locked!\n");
+ return -1;
+ }
+
+ if (launch_proc(argv1) != 0) {
+ printf("Error - failed to run with --file-prefix=%s\n", memtest);
+ return -1;
+ }
+
+ /* check if memtest1_map0 is present */
+ if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
+ printf("Error - hugepage files for %s were not created!\n", memtest1);
+ return -1;
+ }
+
+ if (launch_proc(argv2) != 0) {
+ printf("Error - failed to run with --file-prefix=%s\n", memtest2);
+ return -1;
+ }
+
+ /* check if hugefiles for memtest2 are present */
+ if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
+ printf("Error - hugepage files for %s were not created!\n", memtest2);
+ return -1;
+ }
+
+ /* check if hugefiles for memtest1 are present */
+ if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
+ printf("Error - hugepage files for %s were not deleted!\n", memtest1);
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Tests for correct handling of -m and --socket-mem flags
+ */
+static int
+test_memory_flags(void)
+{
+#ifdef RTE_EXEC_ENV_BSDAPP
+ /* BSD target doesn't support prefixes at this point */
+ const char * prefix = "";
+#else
+ char prefix[PATH_MAX], tmp[PATH_MAX];
+ if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
+ printf("Error - unable to get current prefix!\n");
+ return -1;
+ }
+ snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
+#endif
+
+ /* valid -m flag and mp flag */
+ const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
+ "-n", "2", "-m", DEFAULT_MEM_SIZE};
+
+ /* valid -m flag */
+ const char *argv1[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
+
+ /* invalid (zero) --socket-mem flag */
+ const char *argv2[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
+
+ /* invalid (incomplete) --socket-mem flag */
+ const char *argv3[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, "--socket-mem=2,2,"};
+
+ /* invalid (mixed with invalid data) --socket-mem flag */
+ const char *argv4[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
+
+ /* invalid (with numeric value as last character) --socket-mem flag */
+ const char *argv5[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
+
+ /* invalid (with empty socket) --socket-mem flag */
+ const char *argv6[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, "--socket-mem=2,,2"};
+
+ /* invalid (null) --socket-mem flag */
+ const char *argv7[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, "--socket-mem="};
+
+ /* valid --socket-mem specified together with -m flag */
+ const char *argv8[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
+
+ /* construct an invalid socket mask with 2 megs on each socket plus
+ * extra 2 megs on socket that doesn't exist on current system */
+ char invalid_socket_mem[SOCKET_MEM_STRLEN];
+ char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
+
+#ifdef RTE_EXEC_ENV_BSDAPP
+ int i, num_sockets = 1;
+#else
+ int i, num_sockets = get_number_of_sockets();
+#endif
+
+ if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
+ printf("Error - cannot get number of sockets!\n");
+ return -1;
+ }
+
+ snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
+
+ /* add one extra socket */
+ for (i = 0; i < num_sockets + 1; i++) {
+ snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
+ snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
+
+ if (num_sockets + 1 - i > 1) {
+ snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
+ snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
+ }
+ }
+
+ /* construct a valid socket mask with 2 megs on each existing socket */
+ char valid_socket_mem[SOCKET_MEM_STRLEN];
+
+ snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
+
+ /* add one extra socket */
+ for (i = 0; i < num_sockets; i++) {
+ snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
+ snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
+
+ if (num_sockets - i > 1) {
+ snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
+ snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
+ }
+ }
+
+ /* invalid --socket-mem flag (with extra socket) */
+ const char *argv9[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, invalid_socket_mem};
+
+ /* valid --socket-mem flag */
+ const char *argv10[] = {prgname, "-c", "10", "-n", "2",
+ "--file-prefix=" memtest, valid_socket_mem};
+
+ if (launch_proc(argv0) != 0) {
+ printf("Error - secondary process failed with valid -m flag !\n");
+ return -1;
+ }
+
+#ifdef RTE_EXEC_ENV_BSDAPP
+ /* no other tests are applicable to BSD */
+ return 0;
+#endif
+
+ if (launch_proc(argv1) != 0) {
+ printf("Error - process failed with valid -m flag!\n");
+ return -1;
+ }
+#ifdef RTE_LIBRTE_XEN_DOM0
+ return 0;
+#endif
+ if (launch_proc(argv2) == 0) {
+ printf("Error - process run ok with invalid (zero) --socket-mem!\n");
+ return -1;
+ }
+
+ if (launch_proc(argv3) == 0) {
+ printf("Error - process run ok with invalid "
+ "(incomplete) --socket-mem!\n");
+ return -1;
+ }
+
+ if (launch_proc(argv4) == 0) {
+ printf("Error - process run ok with invalid "
+ "(mixed with invalid input) --socket-mem!\n");