+ 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;
+ }
+
+ /* this process will run in default mem mode, so it should not leave any
+ * hugepage files behind.
+ */
+ if (launch_proc(argv4) != 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) != 0) {
+ printf("Error - hugepage files for %s were not deleted!\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;
+ }
+
+ /* this process will run in --in-memory mode, so it should not leave any
+ * hugepage files behind.
+ */
+
+ /* test case to check eal-options with --in-memory mode */
+ if (launch_proc(argv5) != 0) {
+ printf("Error - failed to run with --in-memory mode\n");
+ return -1;
+ }
+
+ /*test case to check eal-options with --in-memory mode with
+ * custom file-prefix.
+ */
+ if (launch_proc(argv6) != 0) {
+ printf("Error - failed to run with --in-memory mode\n");
+ return -1;
+ }
+
+ /* check if hugefiles for memtest1 are present */
+ if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
+ printf("Error - hugepage files for %s were created and not deleted!\n",
+ memtest1);
+ return -1;
+ }
+
+ /* test case to check eal-options with --in-memory mode with
+ * parent file-prefix.
+ */
+ if (launch_proc(argv7) != 0) {
+ printf("Error - failed to run with --file-prefix=%s\n", prefix);
+ return -1;
+ }
+
+ /* this process will run in --single-file-segments mode,
+ * so it should not leave any hugepage files behind.
+ */
+ if (launch_proc(argv8) != 0) {
+ printf("Error - failed to run with --single-file-segments mode\n");
+ 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;
+}
+
+/* This function writes in passed buf pointer a valid --socket-mem= option
+ * for num_sockets then concatenates the provided suffix string.
+ *
+ * Example for num_sockets 4, mem "2", suffix "plop"
+ * --socket-mem=2,2,2,2plop
+ */
+static void
+populate_socket_mem_param(int num_sockets, const char *mem,
+ const char *suffix, char *buf, size_t buf_size)
+{
+ unsigned int offset = 0;
+ int written;
+ int i;
+
+ written = snprintf(&buf[offset], buf_size - offset, "--socket-mem=");
+ if (written < 0 || written + offset >= buf_size)
+ return;
+ offset += written;
+
+ for (i = 0; i < num_sockets - 1; i++) {
+ written = snprintf(&buf[offset], buf_size - offset,
+ "%s,", mem);
+ if (written < 0 || written + offset >= buf_size)
+ return;
+ offset += written;
+ }
+
+ written = snprintf(&buf[offset], buf_size - offset, "%s%s", mem,
+ suffix);
+ if (written < 0 || written + offset >= buf_size)
+ return;
+ offset += written;
+}
+
+/*
+ * Tests for correct handling of -m and --socket-mem flags
+ */
+static int
+test_memory_flags(void)
+{
+#ifdef RTE_EXEC_ENV_FREEBSD
+ /* 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,
+ "-m", DEFAULT_MEM_SIZE};
+
+ /* valid -m flag */
+ const char *argv1[] = {prgname,
+ "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
+
+ /* valid (zero) --socket-mem flag */
+ char arg2_socket_mem[SOCKET_MEM_STRLEN];
+ const char *argv2[] = {prgname,
+ "--file-prefix=" memtest, arg2_socket_mem};
+
+ /* invalid (incomplete) --socket-mem flag */
+ char arg3_socket_mem[SOCKET_MEM_STRLEN];
+ const char *argv3[] = {prgname,
+ "--file-prefix=" memtest, arg3_socket_mem};
+
+ /* invalid (mixed with invalid data) --socket-mem flag */
+ char arg4_socket_mem[SOCKET_MEM_STRLEN];
+ const char *argv4[] = {prgname,
+ "--file-prefix=" memtest, arg4_socket_mem};
+
+ /* invalid (with numeric value as last character) --socket-mem flag */
+ char arg5_socket_mem[SOCKET_MEM_STRLEN];
+ const char *argv5[] = {prgname,
+ "--file-prefix=" memtest, arg5_socket_mem};
+
+ /* invalid (with empty socket) --socket-mem flag */
+ char arg6_socket_mem[SOCKET_MEM_STRLEN];
+ const char *argv6[] = {prgname,
+ "--file-prefix=" memtest, arg6_socket_mem};
+
+ /* invalid (null) --socket-mem flag */
+ const char *argv7[] = {prgname,
+ "--file-prefix=" memtest, "--socket-mem="};
+
+ /* valid --socket-mem specified together with -m flag */
+ char arg8_socket_mem[SOCKET_MEM_STRLEN];
+ const char *argv8[] = {prgname,
+ "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE,
+ arg8_socket_mem};
+
+#ifdef RTE_EXEC_ENV_FREEBSD
+ int num_sockets = 1;
+#else
+ int num_sockets = RTE_MIN(get_number_of_sockets(),
+ RTE_MAX_NUMA_NODES);
+#endif
+
+ if (num_sockets <= 0) {
+ printf("Error - cannot get number of sockets!\n");
+ return -1;
+ }
+
+ /* invalid --socket-mem flag (with extra socket) */
+ char invalid_socket_mem[SOCKET_MEM_STRLEN];
+ const char *argv9[] = {prgname,
+ "--file-prefix=" memtest, invalid_socket_mem};
+
+ /* valid --socket-mem flag */
+ char valid_socket_mem[SOCKET_MEM_STRLEN];
+ const char *argv10[] = {prgname,
+ "--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_FREEBSD
+ /* 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;
+ }
+
+ populate_socket_mem_param(num_sockets, "0", "",
+ arg2_socket_mem, sizeof(arg2_socket_mem));
+ if (launch_proc(argv2) != 0) {
+ printf("Error - process failed with valid (zero) --socket-mem!\n");
+ return -1;
+ }
+
+ if (num_sockets > 1) {
+ populate_socket_mem_param(num_sockets - 1, "2", ",",
+ arg3_socket_mem, sizeof(arg3_socket_mem));
+ if (launch_proc(argv3) == 0) {
+ printf("Error - process run ok with invalid "
+ "(incomplete) --socket-mem!\n");
+ return -1;
+ }
+
+ populate_socket_mem_param(num_sockets - 1, "2", ",Fred",
+ arg4_socket_mem, sizeof(arg4_socket_mem));
+ if (launch_proc(argv4) == 0) {
+ printf("Error - process run ok with invalid "
+ "(mixed with invalid input) --socket-mem!\n");
+ return -1;
+ }
+
+ populate_socket_mem_param(num_sockets - 1, "2", ",Fred0",
+ arg5_socket_mem, sizeof(arg5_socket_mem));
+ if (launch_proc(argv5) == 0) {
+ printf("Error - process run ok with invalid "
+ "(mixed with invalid input with a numeric value as "
+ "last character) --socket-mem!\n");
+ return -1;
+ }
+ }
+
+ if (num_sockets > 2) {
+ populate_socket_mem_param(num_sockets - 2, "2", ",,2",
+ arg6_socket_mem, sizeof(arg6_socket_mem));
+ if (launch_proc(argv6) == 0) {
+ printf("Error - process run ok with invalid "
+ "(with empty socket) --socket-mem!\n");
+ return -1;
+ }
+ }
+
+ if (launch_proc(argv7) == 0) {
+ printf("Error - process run ok with invalid (null) --socket-mem!\n");
+ return -1;
+ }
+
+ populate_socket_mem_param(num_sockets, "2", "",
+ arg8_socket_mem, sizeof(arg8_socket_mem));
+ if (launch_proc(argv8) == 0) {
+ printf("Error - process run ok with --socket-mem and -m specified!\n");