197f17497SC.J. Collier/*-
297f17497SC.J. Collier *   BSD LICENSE
397f17497SC.J. Collier *
497f17497SC.J. Collier *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
597f17497SC.J. Collier *   Copyright(c) 2014 6WIND S.A.
697f17497SC.J. Collier *   All rights reserved.
797f17497SC.J. Collier *
897f17497SC.J. Collier *   Redistribution and use in source and binary forms, with or without
997f17497SC.J. Collier *   modification, are permitted provided that the following conditions
1097f17497SC.J. Collier *   are met:
1197f17497SC.J. Collier *
1297f17497SC.J. Collier *     * Redistributions of source code must retain the above copyright
1397f17497SC.J. Collier *       notice, this list of conditions and the following disclaimer.
1497f17497SC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
1597f17497SC.J. Collier *       notice, this list of conditions and the following disclaimer in
1697f17497SC.J. Collier *       the documentation and/or other materials provided with the
1797f17497SC.J. Collier *       distribution.
1897f17497SC.J. Collier *     * Neither the name of Intel Corporation nor the names of its
1997f17497SC.J. Collier *       contributors may be used to endorse or promote products derived
2097f17497SC.J. Collier *       from this software without specific prior written permission.
2197f17497SC.J. Collier *
2297f17497SC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2397f17497SC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2497f17497SC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2597f17497SC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2697f17497SC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2797f17497SC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2897f17497SC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2997f17497SC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3097f17497SC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3197f17497SC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3297f17497SC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3397f17497SC.J. Collier */
3497f17497SC.J. Collier#include <stdio.h>
3597f17497SC.J. Collier
3697f17497SC.J. Collier#include "test.h"
3797f17497SC.J. Collier
3897f17497SC.J. Collier#include <string.h>
3997f17497SC.J. Collier#include <stdarg.h>
4097f17497SC.J. Collier#include <libgen.h>
4197f17497SC.J. Collier#include <stdio.h>
4297f17497SC.J. Collier#include <stdlib.h>
4397f17497SC.J. Collier#include <errno.h>
4497f17497SC.J. Collier#include <unistd.h>
4597f17497SC.J. Collier#include <dirent.h>
4697f17497SC.J. Collier#include <sys/wait.h>
4797f17497SC.J. Collier#include <sys/file.h>
4897f17497SC.J. Collier#include <limits.h>
4997f17497SC.J. Collier
5097f17497SC.J. Collier#include <rte_debug.h>
5197f17497SC.J. Collier#include <rte_string_fns.h>
5297f17497SC.J. Collier
5397f17497SC.J. Collier#include "process.h"
5497f17497SC.J. Collier
5597f17497SC.J. Collier#ifdef RTE_LIBRTE_XEN_DOM0
5697f17497SC.J. Collier#define DEFAULT_MEM_SIZE "30"
5797f17497SC.J. Collier#else
5897f17497SC.J. Collier#define DEFAULT_MEM_SIZE "18"
5997f17497SC.J. Collier#endif
6097f17497SC.J. Collier#define mp_flag "--proc-type=secondary"
6197f17497SC.J. Collier#define no_hpet "--no-hpet"
6297f17497SC.J. Collier#define no_huge "--no-huge"
6397f17497SC.J. Collier#define no_shconf "--no-shconf"
6497f17497SC.J. Collier#define pci_whitelist "--pci-whitelist"
6597f17497SC.J. Collier#define vdev "--vdev"
6697f17497SC.J. Collier#define memtest "memtest"
6797f17497SC.J. Collier#define memtest1 "memtest1"
6897f17497SC.J. Collier#define memtest2 "memtest2"
6943192222SLuca Boccassi#define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
7097f17497SC.J. Collier#define launch_proc(ARGV) process_dup(ARGV, \
7197f17497SC.J. Collier		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
7297f17497SC.J. Collier
7397f17497SC.J. Collierenum hugepage_action {
7497f17497SC.J. Collier	HUGEPAGE_CHECK_EXISTS = 0,
7597f17497SC.J. Collier	HUGEPAGE_CHECK_LOCKED,
7697f17497SC.J. Collier	HUGEPAGE_DELETE,
7797f17497SC.J. Collier	HUGEPAGE_INVALID
7897f17497SC.J. Collier};
7997f17497SC.J. Collier
8097f17497SC.J. Collier/* if string contains a hugepage path */
8197f17497SC.J. Collierstatic int
8297f17497SC.J. Collierget_hugepage_path(char * src, int src_len, char * dst, int dst_len)
8397f17497SC.J. Collier{
8497f17497SC.J. Collier#define NUM_TOKENS 4
8597f17497SC.J. Collier	char *tokens[NUM_TOKENS];
8697f17497SC.J. Collier
8797f17497SC.J. Collier	/* if we couldn't properly split the string */
8897f17497SC.J. Collier	if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
8997f17497SC.J. Collier		return 0;
9097f17497SC.J. Collier
9197f17497SC.J. Collier	if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
9297f17497SC.J. Collier		snprintf(dst, dst_len, "%s", tokens[1]);
9397f17497SC.J. Collier		return 1;
9497f17497SC.J. Collier	}
9597f17497SC.J. Collier	return 0;
9697f17497SC.J. Collier}
9797f17497SC.J. Collier
9897f17497SC.J. Collier/*
9997f17497SC.J. Collier * Cycles through hugepage directories and looks for hugepage
10097f17497SC.J. Collier * files associated with a given prefix. Depending on value of
10197f17497SC.J. Collier * action, the hugepages are checked if they exist, checked if
10297f17497SC.J. Collier * they can be locked, or are simply deleted.
10397f17497SC.J. Collier *
10497f17497SC.J. Collier * Returns 1 if it finds at least one hugepage matching the action
10597f17497SC.J. Collier * Returns 0 if no matching hugepages were found
10697f17497SC.J. Collier * Returns -1 if it encounters an error
10797f17497SC.J. Collier */
10897f17497SC.J. Collierstatic int
10997f17497SC.J. Collierprocess_hugefiles(const char * prefix, enum hugepage_action action)
11097f17497SC.J. Collier{
11197f17497SC.J. Collier	FILE * hugedir_handle = NULL;
11297f17497SC.J. Collier	DIR * hugepage_dir = NULL;
11397f17497SC.J. Collier	struct dirent *dirent = NULL;
11497f17497SC.J. Collier
11597f17497SC.J. Collier	char hugefile_prefix[PATH_MAX] = {0};
11697f17497SC.J. Collier	char hugedir[PATH_MAX] = {0};
11797f17497SC.J. Collier	char line[PATH_MAX] = {0};
11897f17497SC.J. Collier
11997f17497SC.J. Collier	int fd, lck_result, result = 0;
12097f17497SC.J. Collier
12197f17497SC.J. Collier	const int prefix_len = snprintf(hugefile_prefix,
12297f17497SC.J. Collier			sizeof(hugefile_prefix), "%smap_", prefix);
12397f17497SC.J. Collier	if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
12497f17497SC.J. Collier			|| prefix_len >= (int)sizeof(dirent->d_name)) {
12597f17497SC.J. Collier		printf("Error creating hugefile filename prefix\n");
12697f17497SC.J. Collier		return -1;
12797f17497SC.J. Collier	}
12897f17497SC.J. Collier
12997f17497SC.J. Collier	/* get hugetlbfs mountpoints from /proc/mounts */
13097f17497SC.J. Collier	hugedir_handle = fopen("/proc/mounts", "r");
13197f17497SC.J. Collier
13297f17497SC.J. Collier	if (hugedir_handle == NULL) {
13397f17497SC.J. Collier		printf("Error parsing /proc/mounts!\n");
13497f17497SC.J. Collier		return -1;
13597f17497SC.J. Collier	}
13697f17497SC.J. Collier
13797f17497SC.J. Collier	/* read and parse script output */
13897f17497SC.J. Collier	while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
13997f17497SC.J. Collier
14097f17497SC.J. Collier		/* check if we have a hugepage filesystem path */
14197f17497SC.J. Collier		if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
14297f17497SC.J. Collier			continue;
14397f17497SC.J. Collier
14497f17497SC.J. Collier		/* check if directory exists */
14597f17497SC.J. Collier		if ((hugepage_dir = opendir(hugedir)) == NULL) {
14697f17497SC.J. Collier			fclose(hugedir_handle);
14797f17497SC.J. Collier			printf("Error reading %s: %s\n", hugedir, strerror(errno));
14897f17497SC.J. Collier			return -1;
14997f17497SC.J. Collier		}
15097f17497SC.J. Collier
15197f17497SC.J. Collier		while ((dirent = readdir(hugepage_dir)) != NULL) {
15297f17497SC.J. Collier			if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
15397f17497SC.J. Collier				continue;
15497f17497SC.J. Collier
15597f17497SC.J. Collier			switch (action) {
15697f17497SC.J. Collier			case HUGEPAGE_CHECK_EXISTS:
15797f17497SC.J. Collier				{
15897f17497SC.J. Collier					/* file exists, return */
15997f17497SC.J. Collier					result = 1;
16097f17497SC.J. Collier					goto end;
16197f17497SC.J. Collier				}
16297f17497SC.J. Collier				break;
16397f17497SC.J. Collier			case HUGEPAGE_DELETE:
16497f17497SC.J. Collier				{
16597f17497SC.J. Collier					char file_path[PATH_MAX] = {0};
16697f17497SC.J. Collier
16797f17497SC.J. Collier					snprintf(file_path, sizeof(file_path),
16897f17497SC.J. Collier						"%s/%s", hugedir, dirent->d_name);
16997f17497SC.J. Collier
17097f17497SC.J. Collier					/* remove file */
17197f17497SC.J. Collier					if (remove(file_path) < 0) {
17297f17497SC.J. Collier						printf("Error deleting %s - %s!\n",
17397f17497SC.J. Collier								dirent->d_name, strerror(errno));
17497f17497SC.J. Collier						closedir(hugepage_dir);
17597f17497SC.J. Collier						result = -1;
17697f17497SC.J. Collier						goto end;
17797f17497SC.J. Collier					}
17897f17497SC.J. Collier					result = 1;
17997f17497SC.J. Collier				}
18097f17497SC.J. Collier				break;
18197f17497SC.J. Collier			case HUGEPAGE_CHECK_LOCKED:
18297f17497SC.J. Collier				{
18397f17497SC.J. Collier					/* try and lock the file */
18497f17497SC.J. Collier					fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
18597f17497SC.J. Collier
18697f17497SC.J. Collier					/* this shouldn't happen */
18797f17497SC.J. Collier					if (fd == -1) {
18897f17497SC.J. Collier						printf("Error opening %s - %s!\n",
18997f17497SC.J. Collier								dirent->d_name, strerror(errno));
19097f17497SC.J. Collier						closedir(hugepage_dir);
19197f17497SC.J. Collier						result = -1;
19297f17497SC.J. Collier						goto end;
19397f17497SC.J. Collier					}
19497f17497SC.J. Collier
19597f17497SC.J. Collier					/* non-blocking lock */
19697f17497SC.J. Collier					lck_result = flock(fd, LOCK_EX | LOCK_NB);
19797f17497SC.J. Collier
19897f17497SC.J. Collier					/* if lock succeeds, there's something wrong */
19997f17497SC.J. Collier					if (lck_result != -1) {
20097f17497SC.J. Collier						result = 0;
20197f17497SC.J. Collier
20297f17497SC.J. Collier						/* unlock the resulting lock */
20397f17497SC.J. Collier						flock(fd, LOCK_UN);
20497f17497SC.J. Collier						close(fd);
20597f17497SC.J. Collier						closedir(hugepage_dir);
20697f17497SC.J. Collier						goto end;
20797f17497SC.J. Collier					}
20897f17497SC.J. Collier					result = 1;
20997f17497SC.J. Collier					close(fd);
21097f17497SC.J. Collier				}
21197f17497SC.J. Collier				break;
21297f17497SC.J. Collier				/* shouldn't happen */
21397f17497SC.J. Collier			default:
21497f17497SC.J. Collier				goto end;
21597f17497SC.J. Collier			} /* switch */
21697f17497SC.J. Collier
21797f17497SC.J. Collier		} /* read hugepage directory */
21897f17497SC.J. Collier		closedir(hugepage_dir);
21997f17497SC.J. Collier	} /* read /proc/mounts */
22097f17497SC.J. Collierend:
22197f17497SC.J. Collier	fclose(hugedir_handle);
22297f17497SC.J. Collier	return result;
22397f17497SC.J. Collier}
22497f17497SC.J. Collier
22597f17497SC.J. Collier#ifdef RTE_EXEC_ENV_LINUXAPP
22697f17497SC.J. Collier/*
22797f17497SC.J. Collier * count the number of "node*" files in /sys/devices/system/node/
22897f17497SC.J. Collier */
22997f17497SC.J. Collierstatic int
23097f17497SC.J. Collierget_number_of_sockets(void)
23197f17497SC.J. Collier{
23297f17497SC.J. Collier	struct dirent *dirent = NULL;
23397f17497SC.J. Collier	const char * nodedir = "/sys/devices/system/node/";
23497f17497SC.J. Collier	DIR * dir = NULL;
23597f17497SC.J. Collier	int result = 0;
23697f17497SC.J. Collier
23797f17497SC.J. Collier	/* check if directory exists */
23897f17497SC.J. Collier	if ((dir = opendir(nodedir)) == NULL) {
23997f17497SC.J. Collier		/* if errno==ENOENT this means we don't have NUMA support */
24097f17497SC.J. Collier		if (errno == ENOENT) {
24197f17497SC.J. Collier			printf("No NUMA nodes detected: assuming 1 available socket\n");
24297f17497SC.J. Collier			return 1;
24397f17497SC.J. Collier		}
24497f17497SC.J. Collier		printf("Error opening %s: %s\n", nodedir, strerror(errno));
24597f17497SC.J. Collier		return -1;
24697f17497SC.J. Collier	}
24797f17497SC.J. Collier
24897f17497SC.J. Collier	while ((dirent = readdir(dir)) != NULL)
24997f17497SC.J. Collier		if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
25097f17497SC.J. Collier			result++;
25197f17497SC.J. Collier
25297f17497SC.J. Collier	closedir(dir);
25397f17497SC.J. Collier	return result;
25497f17497SC.J. Collier}
25597f17497SC.J. Collier#endif
25697f17497SC.J. Collier
25797f17497SC.J. Collierstatic char*
25897f17497SC.J. Collierget_current_prefix(char * prefix, int size)
25997f17497SC.J. Collier{
26097f17497SC.J. Collier	char path[PATH_MAX] = {0};
26197f17497SC.J. Collier	char buf[PATH_MAX] = {0};
26297f17497SC.J. Collier
26397f17497SC.J. Collier	/* get file for config (fd is always 3) */
26497f17497SC.J. Collier	snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
26597f17497SC.J. Collier
26697f17497SC.J. Collier	/* return NULL on error */
26797f17497SC.J. Collier	if (readlink(path, buf, sizeof(buf)) == -1)
26897f17497SC.J. Collier		return NULL;
26997f17497SC.J. Collier
27097f17497SC.J. Collier	/* get the basename */
27197f17497SC.J. Collier	snprintf(buf, sizeof(buf), "%s", basename(buf));
27297f17497SC.J. Collier
27397f17497SC.J. Collier	/* copy string all the way from second char up to start of _config */
27497f17497SC.J. Collier	snprintf(prefix, size, "%.*s",
27597f17497SC.J. Collier			(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
27697f17497SC.J. Collier			&buf[1]);
27797f17497SC.J. Collier
27897f17497SC.J. Collier	return prefix;
27997f17497SC.J. Collier}
28097f17497SC.J. Collier
28197f17497SC.J. Collier/*
28297f17497SC.J. Collier * Test that the app doesn't run with invalid whitelist option.
28397f17497SC.J. Collier * Final tests ensures it does run with valid options as sanity check (one
28497f17497SC.J. Collier * test for with Domain+BDF, second for just with BDF)
28597f17497SC.J. Collier */
28697f17497SC.J. Collierstatic int
28797f17497SC.J. Colliertest_whitelist_flag(void)
28897f17497SC.J. Collier{
28997f17497SC.J. Collier	unsigned i;
29097f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
29197f17497SC.J. Collier	/* BSD target doesn't support prefixes at this point */
29297f17497SC.J. Collier	const char * prefix = "";
29397f17497SC.J. Collier#else
29497f17497SC.J. Collier	char prefix[PATH_MAX], tmp[PATH_MAX];
29597f17497SC.J. Collier	if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
29697f17497SC.J. Collier		printf("Error - unable to get current prefix!\n");
29797f17497SC.J. Collier		return -1;
29897f17497SC.J. Collier	}
29997f17497SC.J. Collier	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
30097f17497SC.J. Collier#endif
30197f17497SC.J. Collier
30297f17497SC.J. Collier	const char *wlinval[][11] = {
30397f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1",
30497f17497SC.J. Collier				pci_whitelist, "error", "", ""},
30597f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1",
30697f17497SC.J. Collier				pci_whitelist, "0:0:0", "", ""},
30797f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1",
30897f17497SC.J. Collier				pci_whitelist, "0:error:0.1", "", ""},
30997f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1",
31097f17497SC.J. Collier				pci_whitelist, "0:0:0.1error", "", ""},
31197f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1",
31297f17497SC.J. Collier				pci_whitelist, "error0:0:0.1", "", ""},
31397f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1",
31497f17497SC.J. Collier				pci_whitelist, "0:0:0.1.2", "", ""},
31597f17497SC.J. Collier	};
31697f17497SC.J. Collier	/* Test with valid whitelist option */
31797f17497SC.J. Collier	const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
31897f17497SC.J. Collier			pci_whitelist, "00FF:09:0B.3"};
31997f17497SC.J. Collier	const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
32097f17497SC.J. Collier			pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
32197f17497SC.J. Collier	const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
32297f17497SC.J. Collier			pci_whitelist, "09:0B.3,type=test",
32397f17497SC.J. Collier			pci_whitelist, "08:00.1,type=normal",
32497f17497SC.J. Collier	};
32597f17497SC.J. Collier
32697f17497SC.J. Collier	for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
32797f17497SC.J. Collier		if (launch_proc(wlinval[i]) == 0) {
32897f17497SC.J. Collier			printf("Error - process did run ok with invalid "
32997f17497SC.J. Collier			    "whitelist parameter\n");
33097f17497SC.J. Collier			return -1;
33197f17497SC.J. Collier		}
33297f17497SC.J. Collier	}
33397f17497SC.J. Collier	if (launch_proc(wlval1) != 0 ) {
33497f17497SC.J. Collier		printf("Error - process did not run ok with valid whitelist\n");
33597f17497SC.J. Collier		return -1;
33697f17497SC.J. Collier	}
33797f17497SC.J. Collier	if (launch_proc(wlval2) != 0 ) {
33897f17497SC.J. Collier		printf("Error - process did not run ok with valid whitelist value set\n");
33997f17497SC.J. Collier		return -1;
34097f17497SC.J. Collier	}
34197f17497SC.J. Collier	if (launch_proc(wlval3) != 0 ) {
34297f17497SC.J. Collier		printf("Error - process did not run ok with valid whitelist + args\n");
34397f17497SC.J. Collier		return -1;
34497f17497SC.J. Collier	}
34597f17497SC.J. Collier
34697f17497SC.J. Collier	return 0;
34797f17497SC.J. Collier}
34897f17497SC.J. Collier
34997f17497SC.J. Collier/*
35097f17497SC.J. Collier * Test that the app doesn't run with invalid blacklist option.
35197f17497SC.J. Collier * Final test ensures it does run with valid options as sanity check
35297f17497SC.J. Collier */
35397f17497SC.J. Collierstatic int
35497f17497SC.J. Colliertest_invalid_b_flag(void)
35597f17497SC.J. Collier{
35697f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
35797f17497SC.J. Collier	/* BSD target doesn't support prefixes at this point */
35897f17497SC.J. Collier	const char * prefix = "";
35997f17497SC.J. Collier#else
36097f17497SC.J. Collier	char prefix[PATH_MAX], tmp[PATH_MAX];
36197f17497SC.J. Collier	if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
36297f17497SC.J. Collier		printf("Error - unable to get current prefix!\n");
36397f17497SC.J. Collier		return -1;
36497f17497SC.J. Collier	}
36597f17497SC.J. Collier	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
36697f17497SC.J. Collier#endif
36797f17497SC.J. Collier
36897f17497SC.J. Collier	const char *blinval[][9] = {
36997f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
37097f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
37197f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
37297f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
37397f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
37497f17497SC.J. Collier		{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
37597f17497SC.J. Collier	};
37697f17497SC.J. Collier	/* Test with valid blacklist option */
37797f17497SC.J. Collier	const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
37897f17497SC.J. Collier
37997f17497SC.J. Collier	int i;
38097f17497SC.J. Collier
38197f17497SC.J. Collier	for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
38297f17497SC.J. Collier		if (launch_proc(blinval[i]) == 0) {
38397f17497SC.J. Collier			printf("Error - process did run ok with invalid "
38497f17497SC.J. Collier			    "blacklist parameter\n");
38597f17497SC.J. Collier			return -1;
38697f17497SC.J. Collier		}
38797f17497SC.J. Collier	}
38897f17497SC.J. Collier	if (launch_proc(blval) != 0) {
38997f17497SC.J. Collier		printf("Error - process did not run ok with valid blacklist value\n");
39097f17497SC.J. Collier		return -1;
39197f17497SC.J. Collier	}
39297f17497SC.J. Collier	return 0;
39397f17497SC.J. Collier}
39497f17497SC.J. Collier
39597f17497SC.J. Collier/*
39697f17497SC.J. Collier *  Test that the app doesn't run with invalid vdev option.
39797f17497SC.J. Collier *  Final test ensures it does run with valid options as sanity check
39897f17497SC.J. Collier */
39997f17497SC.J. Collier#ifdef RTE_LIBRTE_PMD_RING
40097f17497SC.J. Collierstatic int
40197f17497SC.J. Colliertest_invalid_vdev_flag(void)
40297f17497SC.J. Collier{
40397f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
40497f17497SC.J. Collier	/* BSD target doesn't support prefixes at this point, and we also need to
40597f17497SC.J. Collier	 * run another primary process here */
40697f17497SC.J. Collier	const char * prefix = no_shconf;
40797f17497SC.J. Collier#else
40897f17497SC.J. Collier	const char * prefix = "--file-prefix=vdev";
40997f17497SC.J. Collier#endif
41097f17497SC.J. Collier
41197f17497SC.J. Collier	/* Test with invalid vdev option */
4128e6d9d11SLuca Boccassi	const char *vdevinval[] = {prgname, prefix, no_huge, "-n", "1",
41397f17497SC.J. Collier				"-c", "1", vdev, "eth_dummy"};
41497f17497SC.J. Collier
41597f17497SC.J. Collier	/* Test with valid vdev option */
4168e6d9d11SLuca Boccassi	const char *vdevval1[] = {prgname, prefix, no_huge, "-n", "1",
4176b3e017eSChristian Ehrhardt	"-c", "1", vdev, "net_ring0"};
41897f17497SC.J. Collier
4198e6d9d11SLuca Boccassi	const char *vdevval2[] = {prgname, prefix, no_huge, "-n", "1",
4206b3e017eSChristian Ehrhardt	"-c", "1", vdev, "net_ring0,args=test"};
42197f17497SC.J. Collier
4228e6d9d11SLuca Boccassi	const char *vdevval3[] = {prgname, prefix, no_huge, "-n", "1",
4236b3e017eSChristian Ehrhardt	"-c", "1", vdev, "net_ring0,nodeaction=r1:0:CREATE"};
42497f17497SC.J. Collier
42597f17497SC.J. Collier	if (launch_proc(vdevinval) == 0) {
42697f17497SC.J. Collier		printf("Error - process did run ok with invalid "
42797f17497SC.J. Collier			"vdev parameter\n");
42897f17497SC.J. Collier		return -1;
42997f17497SC.J. Collier	}
43097f17497SC.J. Collier
43197f17497SC.J. Collier	if (launch_proc(vdevval1) != 0) {
43297f17497SC.J. Collier		printf("Error - process did not run ok with valid vdev value\n");
43397f17497SC.J. Collier		return -1;
43497f17497SC.J. Collier	}
43597f17497SC.J. Collier
43697f17497SC.J. Collier	if (launch_proc(vdevval2) != 0) {
43797f17497SC.J. Collier		printf("Error - process did not run ok with valid vdev value,"
43897f17497SC.J. Collier			"with dummy args\n");
43997f17497SC.J. Collier		return -1;
44097f17497SC.J. Collier	}
44197f17497SC.J. Collier
44297f17497SC.J. Collier	if (launch_proc(vdevval3) != 0) {
44397f17497SC.J. Collier		printf("Error - process did not run ok with valid vdev value,"
44497f17497SC.J. Collier			"with valid args\n");
44597f17497SC.J. Collier		return -1;
44697f17497SC.J. Collier	}
44797f17497SC.J. Collier	return 0;
44897f17497SC.J. Collier}
44997f17497SC.J. Collier#endif
45097f17497SC.J. Collier
45197f17497SC.J. Collier/*
45297f17497SC.J. Collier * Test that the app doesn't run with invalid -r option.
45397f17497SC.J. Collier */
45497f17497SC.J. Collierstatic int
45597f17497SC.J. Colliertest_invalid_r_flag(void)
45697f17497SC.J. Collier{
45797f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
45897f17497SC.J. Collier	/* BSD target doesn't support prefixes at this point */
45997f17497SC.J. Collier	const char * prefix = "";
46097f17497SC.J. Collier#else
46197f17497SC.J. Collier	char prefix[PATH_MAX], tmp[PATH_MAX];
46297f17497SC.J. Collier	if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
46397f17497SC.J. Collier		printf("Error - unable to get current prefix!\n");
46497f17497SC.J. Collier		return -1;
46597f17497SC.J. Collier	}
46697f17497SC.J. Collier	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
46797f17497SC.J. Collier#endif
46897f17497SC.J. Collier
46997f17497SC.J. Collier	const char *rinval[][9] = {
47097f17497SC.J. Collier			{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
47197f17497SC.J. Collier			{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
47297f17497SC.J. Collier			{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
47397f17497SC.J. Collier			{prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
47497f17497SC.J. Collier	};
47597f17497SC.J. Collier	/* Test with valid blacklist option */
47697f17497SC.J. Collier	const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
47797f17497SC.J. Collier
47897f17497SC.J. Collier	int i;
47997f17497SC.J. Collier
48097f17497SC.J. Collier	for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
48197f17497SC.J. Collier		if (launch_proc(rinval[i]) == 0) {
48297f17497SC.J. Collier			printf("Error - process did run ok with invalid "
48397f17497SC.J. Collier			    "-r (rank) parameter\n");
48497f17497SC.J. Collier			return -1;
48597f17497SC.J. Collier		}
48697f17497SC.J. Collier	}
48797f17497SC.J. Collier	if (launch_proc(rval) != 0) {
48897f17497SC.J. Collier		printf("Error - process did not run ok with valid -r (rank) value\n");
48997f17497SC.J. Collier		return -1;
49097f17497SC.J. Collier	}
49197f17497SC.J. Collier	return 0;
49297f17497SC.J. Collier}
49397f17497SC.J. Collier
49497f17497SC.J. Collier/*
49597f17497SC.J. Collier * Test that the app doesn't run without the coremask/corelist flags. In all cases
49697f17497SC.J. Collier * should give an error and fail to run
49797f17497SC.J. Collier */
49897f17497SC.J. Collierstatic int
49997f17497SC.J. Colliertest_missing_c_flag(void)
50097f17497SC.J. Collier{
50197f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
50297f17497SC.J. Collier	/* BSD target doesn't support prefixes at this point */
50397f17497SC.J. Collier	const char * prefix = "";
50497f17497SC.J. Collier#else
50597f17497SC.J. Collier	char prefix[PATH_MAX], tmp[PATH_MAX];
50697f17497SC.J. Collier	if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
50797f17497SC.J. Collier		printf("Error - unable to get current prefix!\n");
50897f17497SC.J. Collier		return -1;
50997f17497SC.J. Collier	}
51097f17497SC.J. Collier	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
51197f17497SC.J. Collier#endif
51297f17497SC.J. Collier
51397f17497SC.J. Collier	/* -c flag but no coremask value */
51497f17497SC.J. Collier	const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
51597f17497SC.J. Collier	/* No -c, -l or --lcores flag at all */
51697f17497SC.J. Collier	const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
51797f17497SC.J. Collier	/* bad coremask value */
51897f17497SC.J. Collier	const char *argv3[] = { prgname, prefix, mp_flag,
51997f17497SC.J. Collier				"-n", "3", "-c", "error" };
52097f17497SC.J. Collier	/* sanity check of tests - valid coremask value */
52197f17497SC.J. Collier	const char *argv4[] = { prgname, prefix, mp_flag,
52297f17497SC.J. Collier				"-n", "3", "-c", "1" };
52397f17497SC.J. Collier	/* -l flag but no corelist value */
52497f17497SC.J. Collier	const char *argv5[] = { prgname, prefix, mp_flag,
52597f17497SC.J. Collier				"-n", "3", "-l"};
52697f17497SC.J. Collier	const char *argv6[] = { prgname, prefix, mp_flag,
52797f17497SC.J. Collier				"-n", "3", "-l", " " };
52897f17497SC.J. Collier	/* bad corelist values */
52997f17497SC.J. Collier	const char *argv7[] = { prgname, prefix, mp_flag,
53097f17497SC.J. Collier				"-n", "3", "-l", "error" };
53197f17497SC.J. Collier	const char *argv8[] = { prgname, prefix, mp_flag,
53297f17497SC.J. Collier				"-n", "3", "-l", "1-" };
53397f17497SC.J. Collier	const char *argv9[] = { prgname, prefix, mp_flag,
53497f17497SC.J. Collier				"-n", "3", "-l", "1," };
53597f17497SC.J. Collier	const char *argv10[] = { prgname, prefix, mp_flag,
53697f17497SC.J. Collier				 "-n", "3", "-l", "1#2" };
53797f17497SC.J. Collier	/* sanity check test - valid corelist value */
53897f17497SC.J. Collier	const char *argv11[] = { prgname, prefix, mp_flag,
53997f17497SC.J. Collier				 "-n", "3", "-l", "1-2,3" };
54097f17497SC.J. Collier
54197f17497SC.J. Collier	/* --lcores flag but no lcores value */
54297f17497SC.J. Collier	const char *argv12[] = { prgname, prefix, mp_flag,
54397f17497SC.J. Collier				 "-n", "3", "--lcores" };
54497f17497SC.J. Collier	const char *argv13[] = { prgname, prefix, mp_flag,
54597f17497SC.J. Collier				 "-n", "3", "--lcores", " " };
54697f17497SC.J. Collier	/* bad lcores value */
54797f17497SC.J. Collier	const char *argv14[] = { prgname, prefix, mp_flag,
54897f17497SC.J. Collier				 "-n", "3", "--lcores", "1-3-5" };
54997f17497SC.J. Collier	const char *argv15[] = { prgname, prefix, mp_flag,
55097f17497SC.J. Collier				 "-n", "3", "--lcores", "0-1,,2" };
55197f17497SC.J. Collier	const char *argv16[] = { prgname, prefix, mp_flag,
55297f17497SC.J. Collier				 "-n", "3", "--lcores", "0-,1" };
55397f17497SC.J. Collier	const char *argv17[] = { prgname, prefix, mp_flag,
55497f17497SC.J. Collier				 "-n", "3", "--lcores", "(0-,2-4)" };
55597f17497SC.J. Collier	const char *argv18[] = { prgname, prefix, mp_flag,
55697f17497SC.J. Collier				 "-n", "3", "--lcores", "(-1,2)" };
55797f17497SC.J. Collier	const char *argv19[] = { prgname, prefix, mp_flag,
55897f17497SC.J. Collier				 "-n", "3", "--lcores", "(2-4)@(2-4-6)" };
55997f17497SC.J. Collier	const char *argv20[] = { prgname, prefix, mp_flag,
56097f17497SC.J. Collier				 "-n", "3", "--lcores", "(a,2)" };
56197f17497SC.J. Collier	const char *argv21[] = { prgname, prefix, mp_flag,
56297f17497SC.J. Collier				 "-n", "3", "--lcores", "1-3@(1,3)" };
56397f17497SC.J. Collier	const char *argv22[] = { prgname, prefix, mp_flag,
56497f17497SC.J. Collier				 "-n", "3", "--lcores", "3@((1,3)" };
56597f17497SC.J. Collier	const char *argv23[] = { prgname, prefix, mp_flag,
56697f17497SC.J. Collier				 "-n", "3", "--lcores", "(4-7)=(1,3)" };
56797f17497SC.J. Collier	const char *argv24[] = { prgname, prefix, mp_flag,
56897f17497SC.J. Collier				 "-n", "3", "--lcores", "[4-7]@(1,3)" };
56997f17497SC.J. Collier	/* sanity check of tests - valid lcores value */
57097f17497SC.J. Collier	const char *argv25[] = { prgname, prefix, mp_flag,
57197f17497SC.J. Collier				 "-n", "3", "--lcores",
57297f17497SC.J. Collier				 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
57397f17497SC.J. Collier
57497f17497SC.J. Collier	if (launch_proc(argv2) != 0) {
57597f17497SC.J. Collier		printf("Error - "
57697f17497SC.J. Collier		       "process did not run ok when missing -c flag\n");
57797f17497SC.J. Collier		return -1;
57897f17497SC.J. Collier	}
57997f17497SC.J. Collier
58097f17497SC.J. Collier	if (launch_proc(argv1) == 0
58197f17497SC.J. Collier			|| launch_proc(argv3) == 0) {
58297f17497SC.J. Collier		printf("Error - "
58397f17497SC.J. Collier		       "process ran without error with invalid -c flag\n");
58497f17497SC.J. Collier		return -1;
58597f17497SC.J. Collier	}
58697f17497SC.J. Collier	if (launch_proc(argv4) != 0) {
58797f17497SC.J. Collier		printf("Error - "
58897f17497SC.J. Collier		       "process did not run ok with valid coremask value\n");
58997f17497SC.J. Collier		return -1;
59097f17497SC.J. Collier	}
59197f17497SC.J. Collier
59297f17497SC.J. Collier	/* start -l test */
59397f17497SC.J. Collier	if (launch_proc(argv5) == 0
59497f17497SC.J. Collier			|| launch_proc(argv6) == 0
59597f17497SC.J. Collier			|| launch_proc(argv7) == 0
59697f17497SC.J. Collier			|| launch_proc(argv8) == 0
59797f17497SC.J. Collier			|| launch_proc(argv9) == 0
59897f17497SC.J. Collier			|| launch_proc(argv10) == 0) {
59997f17497SC.J. Collier		printf("Error - "
60097f17497SC.J. Collier		       "process ran without error with invalid -l flag\n");
60197f17497SC.J. Collier		return -1;
60297f17497SC.J. Collier	}
60397f17497SC.J. Collier	if (launch_proc(argv11) != 0) {
60497f17497SC.J. Collier		printf("Error - "
60597f17497SC.J. Collier		       "process did not run ok with valid corelist value\n");
60697f17497SC.J. Collier		return -1;
60797f17497SC.J. Collier	}
60897f17497SC.J. Collier
60997f17497SC.J. Collier	/* start --lcores tests */
61097f17497SC.J. Collier	if (launch_proc(argv12) == 0 || launch_proc(argv13) == 0 ||
61197f17497SC.J. Collier	    launch_proc(argv14) == 0 || launch_proc(argv15) == 0 ||
61297f17497SC.J. Collier	    launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
61397f17497SC.J. Collier	    launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
61497f17497SC.J. Collier	    launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
61597f17497SC.J. Collier	    launch_proc(argv21) == 0 || launch_proc(argv22) == 0 ||
61697f17497SC.J. Collier	    launch_proc(argv23) == 0 || launch_proc(argv24) == 0) {
61797f17497SC.J. Collier		printf("Error - "
61897f17497SC.J. Collier		       "process ran without error with invalid --lcore flag\n");
61997f17497SC.J. Collier		return -1;
62097f17497SC.J. Collier	}
62197f17497SC.J. Collier
62297f17497SC.J. Collier	if (launch_proc(argv25) != 0) {
62397f17497SC.J. Collier		printf("Error - "
62497f17497SC.J. Collier		       "process did not run ok with valid corelist value\n");
62597f17497SC.J. Collier		return -1;
62697f17497SC.J. Collier	}
62797f17497SC.J. Collier
62897f17497SC.J. Collier	return 0;
62997f17497SC.J. Collier}
63097f17497SC.J. Collier
63197f17497SC.J. Collier/*
63297f17497SC.J. Collier * Test --master-lcore option with matching coremask
63397f17497SC.J. Collier */
63497f17497SC.J. Collierstatic int
63597f17497SC.J. Colliertest_master_lcore_flag(void)
63697f17497SC.J. Collier{
63797f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
63897f17497SC.J. Collier	/* BSD target doesn't support prefixes at this point */
63997f17497SC.J. Collier	const char *prefix = "";
64097f17497SC.J. Collier#else
64197f17497SC.J. Collier	char prefix[PATH_MAX], tmp[PATH_MAX];
64297f17497SC.J. Collier	if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
64397f17497SC.J. Collier		printf("Error - unable to get current prefix!\n");
64497f17497SC.J. Collier		return -1;
64597f17497SC.J. Collier	}
64697f17497SC.J. Collier	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
64797f17497SC.J. Collier#endif
64897f17497SC.J. Collier
64997f17497SC.J. Collier	/* --master-lcore flag but no value */
65097f17497SC.J. Collier	const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"};
65197f17497SC.J. Collier	/* --master-lcore flag with invalid value */
65297f17497SC.J. Collier	const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"};
65397f17497SC.J. Collier	const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"};
65497f17497SC.J. Collier	/* master lcore not in coremask */
65597f17497SC.J. Collier	const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"};
65697f17497SC.J. Collier	/* valid value */
65797f17497SC.J. Collier	const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"};
65897f17497SC.J. Collier	/* valid value set before coremask */
65997f17497SC.J. Collier	const char *argv6[] = { prgname, prefix, mp_flag, "-n", "1", "--master-lcore", "1", "-c", "3"};
66097f17497SC.J. Collier
66197f17497SC.J. Collier	if (launch_proc(argv1) == 0
66297f17497SC.J. Collier			|| launch_proc(argv2) == 0
66397f17497SC.J. Collier			|| launch_proc(argv3) == 0
66497f17497SC.J. Collier			|| launch_proc(argv4) == 0) {
66597f17497SC.J. Collier		printf("Error - process ran without error with wrong --master-lcore\n");
66697f17497SC.J. Collier		return -1;
66797f17497SC.J. Collier	}
66897f17497SC.J. Collier	if (launch_proc(argv5) != 0
66997f17497SC.J. Collier			|| launch_proc(argv6) != 0) {
67097f17497SC.J. Collier		printf("Error - process did not run ok with valid --master-lcore\n");
67197f17497SC.J. Collier		return -1;
67297f17497SC.J. Collier	}
67397f17497SC.J. Collier	return 0;
67497f17497SC.J. Collier}
67597f17497SC.J. Collier
67697f17497SC.J. Collier/*
67797f17497SC.J. Collier * Test that the app doesn't run with invalid -n flag option.
67897f17497SC.J. Collier * Final test ensures it does run with valid options as sanity check
67997f17497SC.J. Collier * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
68097f17497SC.J. Collier * flags.
68197f17497SC.J. Collier */
68297f17497SC.J. Collierstatic int
68397f17497SC.J. Colliertest_invalid_n_flag(void)
68497f17497SC.J. Collier{
68597f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
68697f17497SC.J. Collier	/* BSD target doesn't support prefixes at this point */
68797f17497SC.J. Collier	const char * prefix = "";
68897f17497SC.J. Collier#else
68997f17497SC.J. Collier	char prefix[PATH_MAX], tmp[PATH_MAX];
69097f17497SC.J. Collier	if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
69197f17497SC.J. Collier		printf("Error - unable to get current prefix!\n");
69297f17497SC.J. Collier		return -1;
69397f17497SC.J. Collier	}
69497f17497SC.J. Collier	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
69597f17497SC.J. Collier#endif
69697f17497SC.J. Collier
69797f17497SC.J. Collier	/* -n flag but no value */
69897f17497SC.J. Collier	const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
69997f17497SC.J. Collier	/* bad numeric value */
70097f17497SC.J. Collier	const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
70197f17497SC.J. Collier	/* zero is invalid */
70297f17497SC.J. Collier	const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "0" };
70397f17497SC.J. Collier	/* sanity test - check with good value */
70497f17497SC.J. Collier	const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
70597f17497SC.J. Collier	/* sanity test - check with no -n flag */
70697f17497SC.J. Collier	const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
70797f17497SC.J. Collier
70897f17497SC.J. Collier	if (launch_proc(argv1) == 0
70997f17497SC.J. Collier			|| launch_proc(argv2) == 0
71097f17497SC.J. Collier			|| launch_proc(argv3) == 0) {
71197f17497SC.J. Collier		printf("Error - process ran without error when"
71297f17497SC.J. Collier		       "invalid -n flag\n");
71397f17497SC.J. Collier		return -1;
71497f17497SC.J. Collier	}
71597f17497SC.J. Collier	if (launch_proc(argv4) != 0) {
71697f17497SC.J. Collier		printf("Error - process did not run ok with valid num-channel value\n");
71797f17497SC.J. Collier		return -1;
71897f17497SC.J. Collier	}
71997f17497SC.J. Collier	if (launch_proc(argv5) != 0) {
72097f17497SC.J. Collier		printf("Error - process did not run ok without -n flag\n");
72197f17497SC.J. Collier		return -1;
72297f17497SC.J. Collier	}
72397f17497SC.J. Collier
72497f17497SC.J. Collier	return 0;
72597f17497SC.J. Collier}
72697f17497SC.J. Collier
72797f17497SC.J. Collier/*
72897f17497SC.J. Collier * Test that the app runs with HPET, and without HPET
72997f17497SC.J. Collier */
73097f17497SC.J. Collierstatic int
73197f17497SC.J. Colliertest_no_hpet_flag(void)
73297f17497SC.J. Collier{
73397f17497SC.J. Collier	char prefix[PATH_MAX], tmp[PATH_MAX];
73497f17497SC.J. Collier
73597f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
73697f17497SC.J. Collier	return 0;
73797f17497SC.J. Collier#endif
73897f17497SC.J. Collier	if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
73997f17497SC.J. Collier		printf("Error - unable to get current prefix!\n");
74097f17497SC.J. Collier		return -1;
74197f17497SC.J. Collier	}
74297f17497SC.J. Collier	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
74397f17497SC.J. Collier
74497f17497SC.J. Collier	/* With --no-hpet */
74597f17497SC.J. Collier	const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
74697f17497SC.J. Collier	/* Without --no-hpet */
74797f17497SC.J. Collier	const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
74897f17497SC.J. Collier
74997f17497SC.J. Collier	if (launch_proc(argv1) != 0) {
75097f17497SC.J. Collier		printf("Error - process did not run ok with --no-hpet flag\n");
75197f17497SC.J. Collier		return -1;
75297f17497SC.J. Collier	}
75397f17497SC.J. Collier	if (launch_proc(argv2) != 0) {
75497f17497SC.J. Collier		printf("Error - process did not run ok without --no-hpet flag\n");
75597f17497SC.J. Collier		return -1;
75697f17497SC.J. Collier	}
75797f17497SC.J. Collier	return 0;
75897f17497SC.J. Collier}
75997f17497SC.J. Collier
76097f17497SC.J. Collier/*
76197f17497SC.J. Collier * Test that the app runs with --no-huge and doesn't run when --socket-mem are
76297f17497SC.J. Collier * specified with --no-huge.
76397f17497SC.J. Collier */
76497f17497SC.J. Collierstatic int
76597f17497SC.J. Colliertest_no_huge_flag(void)
76697f17497SC.J. Collier{
76797f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
76897f17497SC.J. Collier	/* BSD target doesn't support prefixes at this point, and we also need to
76997f17497SC.J. Collier	 * run another primary process here */
77097f17497SC.J. Collier	const char * prefix = no_shconf;
77197f17497SC.J. Collier#else
77297f17497SC.J. Collier	const char * prefix = "--file-prefix=nohuge";
77397f17497SC.J. Collier#endif
77497f17497SC.J. Collier
77597f17497SC.J. Collier	/* With --no-huge */
77697f17497SC.J. Collier	const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
77797f17497SC.J. Collier	/* With --no-huge and -m */
77897f17497SC.J. Collier	const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
77997f17497SC.J. Collier			"-m", DEFAULT_MEM_SIZE};
78097f17497SC.J. Collier
78197f17497SC.J. Collier	/* With --no-huge and --socket-mem */
78297f17497SC.J. Collier	const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
78397f17497SC.J. Collier			"--socket-mem=" DEFAULT_MEM_SIZE};
78497f17497SC.J. Collier	/* With --no-huge, -m and --socket-mem */
78597f17497SC.J. Collier	const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
78697f17497SC.J. Collier			"-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
78797f17497SC.J. Collier	if (launch_proc(argv1) != 0) {
78897f17497SC.J. Collier		printf("Error - process did not run ok with --no-huge flag\n");
78997f17497SC.J. Collier		return -1;
79097f17497SC.J. Collier	}
79197f17497SC.J. Collier	if (launch_proc(argv2) != 0) {
79297f17497SC.J. Collier		printf("Error - process did not run ok with --no-huge and -m flags\n");
79397f17497SC.J. Collier		return -1;
79497f17497SC.J. Collier	}
79597f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
79697f17497SC.J. Collier	/* BSD target does not support NUMA, hence no --socket-mem tests */
79797f17497SC.J. Collier	return 0;
79897f17497SC.J. Collier#endif
79997f17497SC.J. Collier
80097f17497SC.J. Collier	if (launch_proc(argv3) == 0) {
80197f17497SC.J. Collier		printf("Error - process run ok with --no-huge and --socket-mem "
80297f17497SC.J. Collier				"flags\n");
80397f17497SC.J. Collier		return -1;
80497f17497SC.J. Collier	}
80597f17497SC.J. Collier	if (launch_proc(argv4) == 0) {
80697f17497SC.J. Collier		printf("Error - process run ok with --no-huge, -m and "
80797f17497SC.J. Collier				"--socket-mem flags\n");
80897f17497SC.J. Collier		return -1;
80997f17497SC.J. Collier	}
81097f17497SC.J. Collier	return 0;
81197f17497SC.J. Collier}
81297f17497SC.J. Collier
81397f17497SC.J. Collier#ifdef RTE_LIBRTE_XEN_DOM0
81497f17497SC.J. Collierstatic int
81597f17497SC.J. Colliertest_dom0_misc_flags(void)
81697f17497SC.J. Collier{
81797f17497SC.J. Collier	char prefix[PATH_MAX], tmp[PATH_MAX];
81897f17497SC.J. Collier
81997f17497SC.J. Collier	if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
82097f17497SC.J. Collier		printf("Error - unable to get current prefix!\n");
82197f17497SC.J. Collier		return -1;
82297f17497SC.J. Collier	}
82397f17497SC.J. Collier	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
82497f17497SC.J. Collier
82597f17497SC.J. Collier	/* check that some general flags don't prevent things from working.
82697f17497SC.J. Collier	 * All cases, apart from the first, app should run.
82797f17497SC.J. Collier	 * No futher testing of output done.
82897f17497SC.J. Collier	 */
82997f17497SC.J. Collier	/* sanity check - failure with invalid option */
83097f17497SC.J. Collier	const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
83197f17497SC.J. Collier
83297f17497SC.J. Collier	/* With --no-pci */
83397f17497SC.J. Collier	const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
83497f17497SC.J. Collier	/* With -v */
83597f17497SC.J. Collier	const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
83697f17497SC.J. Collier	/* With valid --syslog */
83797f17497SC.J. Collier	const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
83897f17497SC.J. Collier			"--syslog", "syslog"};
83997f17497SC.J. Collier	/* With empty --syslog (should fail) */
84097f17497SC.J. Collier	const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
84197f17497SC.J. Collier	/* With invalid --syslog */
84297f17497SC.J. Collier	const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
84397f17497SC.J. Collier	/* With no-sh-conf */
84497f17497SC.J. Collier	const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
84597f17497SC.J. Collier			"--no-shconf", "--file-prefix=noshconf" };
84697f17497SC.J. Collier
84797f17497SC.J. Collier	if (launch_proc(argv0) == 0) {
84897f17497SC.J. Collier		printf("Error - process ran ok with invalid flag\n");
84997f17497SC.J. Collier		return -1;
85097f17497SC.J. Collier	}
85197f17497SC.J. Collier	if (launch_proc(argv1) != 0) {
85297f17497SC.J. Collier		printf("Error - process did not run ok with --no-pci flag\n");
85397f17497SC.J. Collier		return -1;
85497f17497SC.J. Collier	}
85597f17497SC.J. Collier	if (launch_proc(argv2) != 0) {
85697f17497SC.J. Collier		printf("Error - process did not run ok with -v flag\n");
85797f17497SC.J. Collier		return -1;
85897f17497SC.J. Collier	}
85997f17497SC.J. Collier	if (launch_proc(argv3) != 0) {
86097f17497SC.J. Collier		printf("Error - process did not run ok with --syslog flag\n");
86197f17497SC.J. Collier		return -1;
86297f17497SC.J. Collier	}
86397f17497SC.J. Collier	if (launch_proc(argv4) == 0) {
86497f17497SC.J. Collier		printf("Error - process run ok with empty --syslog flag\n");
86597f17497SC.J. Collier		return -1;
86697f17497SC.J. Collier	}
86797f17497SC.J. Collier	if (launch_proc(argv5) == 0) {
86897f17497SC.J. Collier		printf("Error - process run ok with invalid --syslog flag\n");
86997f17497SC.J. Collier		return -1;
87097f17497SC.J. Collier	}
87197f17497SC.J. Collier	if (launch_proc(argv6) != 0) {
87297f17497SC.J. Collier		printf("Error - process did not run ok with --no-shconf flag\n");
87397f17497SC.J. Collier		return -1;
87497f17497SC.J. Collier	}
87597f17497SC.J. Collier
87697f17497SC.J. Collier	return 0;
87797f17497SC.J. Collier}
87897f17497SC.J. Collier#else
87997f17497SC.J. Collierstatic int
88097f17497SC.J. Colliertest_misc_flags(void)
88197f17497SC.J. Collier{
88297f17497SC.J. Collier	char hugepath[PATH_MAX] = {0};
88397f17497SC.J. Collier#ifdef RTE_EXEC_ENV_BSDAPP
88497f17497SC.J. Collier	/* BSD target doesn't support prefixes at this point */
88597f17497SC.J. Collier	const char * prefix = "";
88697f17497SC.J. Collier	const char * nosh_prefix = "";
88797f17497SC.J. Collier#else
88897f17497SC.J. Collier	char prefix[PATH_MAX], tmp[PATH_MAX];
88997f17497SC.J. Collier	const char * nosh_prefix = "--file-prefix=noshconf";
89097f17497SC.J. Collier	FILE * hugedir_handle = NULL;
89197f17497SC.J. Collier	char line[PATH_MAX] = {0};
89297f17497SC.J. Collier	unsigned i, isempty = 1;
89397f17497SC.J. Collier	if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
89497f17497SC.J. Collier		printf("Error - unable to get current prefix!\n");
89597f17497SC.J. Collier		return -1;
89697f17497SC.J. Collier	}
89797f17497SC.J. Collier	snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
89897f17497SC.J. Collier
89997f17497SC.J. Collier	/*
90097f17497SC.J. Collier	 * get first valid hugepage path
90197f17497SC.J. Collier	 */
90297f17497SC.J. Collier
90397f17497SC.J. Collier	/* get hugetlbfs mountpoints from /proc/mounts */
90497f17497SC.J. Collier	hugedir_handle = fopen("/proc/mounts", "r");
90597f17497SC.J. Collier
90697f17497SC.J. Collier	if (hugedir_handle == NULL) {
90797f17497SC.J. Collier		printf("Error opening /proc/mounts!\n");
90897f17497SC.J. Collier		return -1;
90997f17497SC.J. Collier	}
91097f17497SC.J. Collier
91197f17497SC.J. Collier	/* read /proc/mounts */
91297f17497SC.J. Collier	while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
91397f17497SC.J. Collier
91497f17497SC.J. Collier		/* find first valid hugepath */
91597f17497SC.J. Collier		if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
91697f17497SC.J. Collier			break;
91797f17497SC.J. Collier	}
91897f17497SC.J. Collier
91997f17497SC.J. Collier	fclose(hugedir_handle);
92097f17497SC.J. Collier
92197f17497SC.J. Collier	/* check if path is not empty */
92297f17497SC.J. Collier	for (i = 0; i < sizeof(hugepath); i++)
92397f17497SC.J. Collier		if (hugepath[i] != '\0')
92497f17497SC.J. Collier			isempty = 0;
92597f17497SC.J. Collier
92697f17497SC.J. Collier	if (isempty) {
92797f17497SC.J. Collier		printf("No mounted hugepage dir found!\n");
92897f17497SC.J. Collier		return -1;
92997f17497SC.J. Collier	}
93097f17497SC.J. Collier#endif
93197f17497SC.J. Collier
93297f17497SC.J. Collier
93397f17497SC.J. Collier	/* check that some general flags don't prevent things from working.
93497f17497SC.J. Collier	 * All cases, apart from the first, app should run.
93597f17497SC.J. Collier	 * No futher testing of output done.
93697f17497SC.J. Collier	 */
93797f17497SC.J. Collier	/* sanity check - failure with invalid option */
93897f17497SC.J. Collier	const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
93997f17497SC.J. Collier
94097f17497SC.J. Collier	/* With --no-pci */
94197f17497SC.J. Collier	const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
94297f17497SC.J. Collier	/* With -v */
94397f17497SC.J. Collier	const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
94497f17497SC.J. Collier	/* With valid --syslog */
94597f17497SC.J. Collier	const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
94697f17497SC.J. Collier			"--syslog", "syslog"};
94797f17497SC.J. Collier	/* With empty --syslog (should fail) */
94897f17497SC.J. Collier	const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
94997f17497SC.J. Collier	/* With invalid --syslog */
95097f17497SC.J. Collier	const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
9518e6d9d11SLuca Boccassi	/* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
95297f17497SC.J. Collier	const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
9538e6d9d11SLuca Boccassi			no_shconf, nosh_prefix, no_huge};
95497f17497SC.J. Collier
95597f17497SC.J. Collier	/* With --huge-dir */
95697f17497SC.J. Collier	const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
95797f17497SC.J. Collier			"--file-prefix=hugedir", "--huge-dir", hugepath};
95897f17497SC.J. Collier	/* With empty --huge-dir (should fail) */
95997f17497SC.J. Collier	const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
96097f17497SC.J. Collier			"--file-prefix=hugedir", "--huge-dir"};
96197f17497SC.J. Collier	/* With invalid --huge-dir */
96297f17497SC.J. Collier	const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
96397f17497SC.J. Collier			"--file-prefix=hugedir", "--huge-dir", "invalid"};
96497f17497SC.J. Collier	/* Secondary process with invalid --huge-dir (should run as flag has no
96597f17497SC.J. Collier	 * effect on secondary processes) */
96697f17497SC.J. Collier	const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
96797f17497SC.J. Collier
96897f17497SC.J. Collier	/* try running with base-virtaddr param */
96997f17497SC.J. Collier	const char *argv11[] = {prgname, "--file-prefix=virtaddr",
97097f17497SC.J. Collier			"-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
97197f17497SC.J. Collier
97297f17497SC.J. Collier	/* try running with --vfio-intr INTx flag */
97397f17497SC.J. Collier	const char *argv12[] = {prgname, "--file-prefix=intr",
97497f17497SC.J. Collier			"-c", "1", "-n", "2", "--vfio-intr=legacy"};
97597f17497SC.J. Collier
97697f17497SC.J. Collier	/* try running with --vfio-intr MSI flag */
97797f17497SC.J. Collier	const char *argv13[] = {prgname, "--file-prefix=intr",
97897f17497SC.J. Collier			"-c", "1", "-n", "2", "--vfio-intr=msi"};
97997f17497SC.J. Collier
98097f17497SC.J. Collier	/* try running with --vfio-intr MSI-X flag */
98197f17497SC.J. Collier	const char *argv14[] = {prgname, "--file-prefix=intr",
98297f17497SC.J. Collier			"-c", "1", "-n", "2", "--vfio-intr=msix"};
98397f17497SC.J. Collier
98497f17497SC.J. Collier	/* try running with --vfio-intr invalid flag */
98597f17497SC.J. Collier	const char *argv15[] = {prgname, "--file-prefix=intr",
98697f17497SC.J. Collier			"-c", "1", "-n", "2", "--vfio-intr=invalid"};
98797f17497SC.J. Collier
9888e6d9d11SLuca Boccassi	/* run all tests also applicable to FreeBSD first */
98997f17497SC.J. Collier
99097f17497SC.J. Collier	if (launch_proc(argv0) == 0) {
99197f17497SC.J. Collier		printf("Error - process ran ok with invalid flag\n");
99297f17497SC.J. Collier		return -1;
99397f17497SC.J. Collier	}
99497f17497SC.J. Collier	if (launch_proc(argv1) != 0) {
99597f17497SC.J. Collier		printf("Error - process did not run ok with --no-pci flag\n");
99697f17497SC.J. Collier		return -1;
99797f17497SC.J. Collier	}
99897f17497SC.J. Collier	if (launch_proc(argv2) != 0) {
99997f17497SC.J. Collier		printf("Error - process did not run ok with -v flag\n");
100097f17497SC.J. Collier		return -1;
100197f17497SC.J. Collier	}
10028e6d9d11SLuca Boccassi	if (launch_proc(argv6) != 0) {
10038e6d9d11SLuca Boccassi		printf("Error - process did not run ok with --no-shconf flag\n");
10048e6d9d11SLuca Boccassi		return -1;
10058e6d9d11SLuca Boccassi	}
10068e6d9d11SLuca Boccassi
10078e6d9d11SLuca Boccassi#ifdef RTE_EXEC_ENV_BSDAPP
10088e6d9d11SLuca Boccassi	/* no more tests to be done on FreeBSD */
10098e6d9d11SLuca Boccassi	return 0;
10108e6d9d11SLuca Boccassi#endif
10118e6d9d11SLuca Boccassi
101297f17497SC.J. Collier	if (launch_proc(argv3) != 0) {
101397f17497SC.J. Collier		printf("Error - process did not run ok with --syslog flag\n");
101497f17497SC.J. Collier		return -1;
101597f17497SC.J. Collier	}
101697f17497SC.J. Collier	if (launch_proc(argv4) == 0) {
101797f17497SC.J. Collier		printf("Error - process run ok with empty --syslog flag\n");
101897f17497SC.J. Collier		return -1;
101997f17497SC.J. Collier	}
102097f17497SC.J. Collier	if (launch_proc(argv5) == 0) {
102197f17497SC.J. Collier		printf("Error - process run ok with invalid --syslog flag\n");
102297f17497SC.J. Collier		return -1;
102397f17497SC.J. Collier	}
102497f17497SC.J. Collier	if (launch_proc(argv7) != 0) {
102597f17497SC.J. Collier		printf("Error - process did not run ok with --huge-dir flag\n");
102697f17497SC.J. Collier		return -1;
102797f17497SC.J. Collier	}
102897f17497SC.J. Collier	if (launch_proc(argv8) == 0) {
102997f17497SC.J. Collier		printf("Error - process run ok with empty --huge-dir flag\n");
103097f17497SC.J. Collier		return -1;
103197f17497SC.J. Collier	}
103297f17497SC.J. Collier	if (launch_proc(argv9) == 0) {
103397f17497SC.J. Collier		printf("Error - process run ok with invalid --huge-dir flag\n");
103497f17497SC.J. Collier		return -1;
103597f17497SC.J. Collier	}
103697f17497SC.J. Collier	if (launch_proc(argv10) != 0) {
103797f17497SC.J. Collier		printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
103897f17497SC.J. Collier		return -1;
103997f17497SC.J. Collier	}
104097f17497SC.J. Collier	if (launch_proc(argv11) != 0) {
104197f17497SC.J. Collier		printf("Error - process did not run ok with --base-virtaddr parameter\n");
104297f17497SC.J. Collier		return -1;
104397f17497SC.J. Collier	}
104497f17497SC.J. Collier	if (launch_proc(argv12) != 0) {
104597f17497SC.J. Collier		printf("Error - process did not run ok with "
104697f17497SC.J. Collier				"--vfio-intr INTx parameter\n");
104797f17497SC.J. Collier		return -1;
104897f17497SC.J. Collier	}
104997f17497SC.J. Collier	if (launch_proc(argv13) != 0) {
105097f17497SC.J. Collier		printf("Error - process did not run ok with "
105197f17497SC.J. Collier				"--vfio-intr MSI parameter\n");
105297f17497SC.J. Collier		return -1;
105397f17497SC.J. Collier	}
105497f17497SC.J. Collier	if (launch_proc(argv14) != 0) {
105597f17497SC.J. Collier		printf("Error - process did not run ok with "
105697f17497SC.J. Collier				"--vfio-intr MSI-X parameter\n");
1057