* [dpdk-dev] [PATCH v2] test: fix prefix discovery
2018-07-16 13:57 [dpdk-dev] [PATCH] test: fix prefix discovery Anatoly Burakov
2018-07-16 15:21 ` Pattan, Reshma
@ 2018-07-25 13:44 ` Anatoly Burakov
2018-07-26 19:33 ` Thomas Monjalon
1 sibling, 1 reply; 4+ messages in thread
From: Anatoly Burakov @ 2018-07-25 13:44 UTC (permalink / raw)
To: dev; +Cc: reshma.pattan
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>
---
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 11986d5c2..ba3a18502 100644
--- a/test/test/process.h
+++ b/test/test/process.h
@@ -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_ */
diff --git a/test/test/test_eal_flags.c b/test/test/test_eal_flags.c
index f840ca50b..c9a1d3a12 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"};
@@ -977,9 +955,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 */
@@ -994,12 +978,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 cc46cf4de..b597dfcdf 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.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread