From 786b29255c492ed000957367e9317433ba4bb17b Mon Sep 17 00:00:00 2001 From: Anatoly Burakov Date: Wed, 25 Jul 2018 14:44:26 +0100 Subject: [PATCH] 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 Acked-by: Reshma Pattan --- test/test/process.h | 29 ++++++++++++++++++++++++ test/test/test_eal_flags.c | 42 +++++++++-------------------------- test/test/test_mp_secondary.c | 26 ---------------------- 3 files changed, 39 insertions(+), 58 deletions(-) diff --git a/test/test/process.h b/test/test/process.h index 11986d5c24..ba3a185027 100644 --- a/test/test/process.h +++ b/test/test/process.h @@ -5,6 +5,11 @@ #ifndef _PROCESS_H_ #define _PROCESS_H_ +#include /* PATH_MAX */ +#include /* basename et al */ +#include /* NULL */ +#include /* 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_ */ diff --git a/test/test/test_eal_flags.c b/test/test/test_eal_flags.c index 8d1da2c60a..3a990766d1 100644 --- a/test/test/test_eal_flags.c +++ b/test/test/test_eal_flags.c @@ -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); diff --git a/test/test/test_mp_secondary.c b/test/test/test_mp_secondary.c index cc46cf4def..b597dfcdf1 100644 --- a/test/test/test_mp_secondary.c +++ b/test/test/test_mp_secondary.c @@ -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 -- 2.20.1