From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id B4B872BAC for ; Wed, 25 Jul 2018 15:44:44 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2018 06:44:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,401,1526367600"; d="scan'208";a="59367819" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga007.jf.intel.com with ESMTP; 25 Jul 2018 06:44:27 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w6PDiQnM002666; Wed, 25 Jul 2018 14:44:26 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w6PDiQ3K028199; Wed, 25 Jul 2018 14:44:26 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w6PDiQKh028195; Wed, 25 Jul 2018 14:44:26 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: reshma.pattan@intel.com Date: Wed, 25 Jul 2018 14:44:26 +0100 Message-Id: <7c3d473da9d4de99086c87424369e3b4d5081547.1532526128.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2] test: fix prefix discovery X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Jul 2018 13:44:45 -0000 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 11986d5c2..ba3a18502 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 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