test: fix file prefix discovery

Config file has moved, but the tests weren't updated to point to
its new location. Update the code to find current prefix.

Also, this function is duplicated across multiple tests, so move it
into process.h and force compile failures for any attempts to use
it on platforms other than Linux.

Fixes: adf1d867361c ("eal: move runtime config file to new location")

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Reshma Pattan <reshma.pattan@intel.com>
This commit is contained in:
Anatoly Burakov 2018-07-25 14:44:26 +01:00 committed by Thomas Monjalon
parent b5d878e6db
commit 786b29255c
3 changed files with 39 additions and 58 deletions

View File

@ -5,6 +5,11 @@
#ifndef _PROCESS_H_
#define _PROCESS_H_
#include <limits.h> /* PATH_MAX */
#include <libgen.h> /* basename et al */
#include <stdlib.h> /* NULL */
#include <unistd.h> /* readlink */
#ifdef RTE_EXEC_ENV_BSDAPP
#define self "curproc"
#define exe "file"
@ -61,4 +66,28 @@ process_dup(const char *const argv[], int numargs, const char *env_value)
return status;
}
/* FreeBSD doesn't support file prefixes, so force compile failures for any
* tests attempting to use this function on FreeBSD.
*/
#ifdef RTE_EXEC_ENV_LINUXAPP
static char *
get_current_prefix(char *prefix, int size)
{
char path[PATH_MAX] = {0};
char buf[PATH_MAX] = {0};
/* get file for config (fd is always 3) */
snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
/* return NULL on error */
if (readlink(path, buf, sizeof(buf)) == -1)
return NULL;
/* get the prefix */
snprintf(prefix, size, "%s", basename(dirname(buf)));
return prefix;
}
#endif
#endif /* _PROCESS_H_ */

View File

@ -221,30 +221,6 @@ get_number_of_sockets(void)
}
#endif
static char*
get_current_prefix(char * prefix, int size)
{
char path[PATH_MAX] = {0};
char buf[PATH_MAX] = {0};
/* get file for config (fd is always 3) */
snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
/* return NULL on error */
if (readlink(path, buf, sizeof(buf)) == -1)
return NULL;
/* get the basename */
snprintf(buf, sizeof(buf), "%s", basename(buf));
/* copy string all the way from second char up to start of _config */
snprintf(prefix, size, "%.*s",
(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
&buf[1]);
return prefix;
}
/*
* Test that the app doesn't run with invalid whitelist option.
* Final tests ensures it does run with valid options as sanity check (one
@ -697,16 +673,18 @@ test_invalid_n_flag(void)
static int
test_no_hpet_flag(void)
{
char prefix[PATH_MAX], tmp[PATH_MAX];
char prefix[PATH_MAX] = "";
#ifdef RTE_EXEC_ENV_BSDAPP
return 0;
#endif
#else
char 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
/* With --no-hpet */
const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
@ -978,9 +956,15 @@ test_file_prefix(void)
* 6. run a primary process with memtest2 prefix
* 7. check that only memtest2 hugefiles are present in the hugedir
*/
char prefix[PATH_MAX] = "";
#ifdef RTE_EXEC_ENV_BSDAPP
return 0;
#else
if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
printf("Error - unable to get current prefix!\n");
return -1;
}
#endif
/* this should fail unless the test itself is run with "memtest" prefix */
@ -995,12 +979,6 @@ test_file_prefix(void)
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;
}
/* 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);

View File

@ -50,32 +50,6 @@
#define launch_proc(ARGV) process_dup(ARGV, \
sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
#ifdef RTE_EXEC_ENV_LINUXAPP
static char*
get_current_prefix(char * prefix, int size)
{
char path[PATH_MAX] = {0};
char buf[PATH_MAX] = {0};
/* get file for config (fd is always 3) */
snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
/* return NULL on error */
if (readlink(path, buf, sizeof(buf)) == -1)
return NULL;
/* get the basename */
snprintf(buf, sizeof(buf), "%s", basename(buf));
/* copy string all the way from second char up to start of _config */
snprintf(prefix, size, "%.*s",
(int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
&buf[1]);
return prefix;
}
#endif
/*
* This function is called in the primary i.e. main test, to spawn off secondary
* processes to run actual mp tests. Uses fork() and exec pair