From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 71F7245B37; Mon, 14 Oct 2024 12:23:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5F3E1402EF; Mon, 14 Oct 2024 12:23:13 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by mails.dpdk.org (Postfix) with ESMTP id 98B39402D9; Mon, 14 Oct 2024 12:23:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728901391; x=1760437391; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+OiaN2S3wjsWXM1E12CFffzibuFc4YbuSLPyXIYfUlc=; b=YHfwZXxc/gxNtr04RgNx7lDBBZfVY3y1hHQ/xrs2/gg1kN0LH8hZDe6E dOM4kyY2tFOonFQIaha0z3Dk6l5xRgrxmc04Jx2dmMwljAOzWSkRUCdOZ /ENyjJJ/MR3zpFnct7BLOC/Y9+N6BPlLqiRTPzIqW09ihXA1AMzBROqf6 zQXZ2IbT4gzfTrJHcUIVANZLgR14rSrmpRwxhJnY6CimSeAMan0YRa75s k0O3cY0dIcwV8Kku2dolL2vCiLfmFV+0Rcpc0IL1SyoEzXyI+pwL0WRKr MvBgVTvl2l+DmP5/QcLMdzAOFt0q3poHEVjqrgoAccEs58MGg2Fm6BNnI w==; X-CSE-ConnectionGUID: 4g9n9iBWQm61JMzJm5QVYA== X-CSE-MsgGUID: j80UHpuBRqagYsKfEOOhMA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="28336317" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="28336317" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2024 03:23:10 -0700 X-CSE-ConnectionGUID: ZHSHhZF9TymE2ng1Zyo0Wg== X-CSE-MsgGUID: BKIyRTQRRzCVB54IvrRyHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="82313440" Received: from unknown (HELO localhost.localdomain) ([10.239.252.253]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2024 03:23:08 -0700 From: Mingjin Ye To: dev@dpdk.org Cc: Mingjin Ye , stable@dpdk.org Subject: [PATCH v3] test: fix option devices Date: Mon, 14 Oct 2024 10:00:26 +0000 Message-Id: <20241014100026.1517769-1-mingjinx.ye@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241012093519.1500942-1-mingjinx.ye@intel.com> References: <20241012093519.1500942-1-mingjinx.ye@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Without using allow (-a) or block (-b), EAL loads all devices by default. Unexpected devices may be loaded when running test cases in sub-processes. This patch fixes the issue by copying the parameters of the master process if the allow (-a) or block (-b) option is not used when starting the child process. Also, EAL does not allow the options allow (-a) and block (-b) to be used at the same time. Fixes: b3ce7891ad38 ("test: fix probing in secondary process") Cc: stable@dpdk.org Signed-off-by: Mingjin Ye --- v2: The long form of the fix option is "--block". --- v3: new scheme. --- app/test/process.h | 58 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/app/test/process.h b/app/test/process.h index 9fb2bf481c..665abae9dc 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -36,6 +36,7 @@ extern uint16_t flag_for_send_pkts; #endif #define PREFIX_ALLOW "--allow=" +#define PREFIX_BLOCK "--block=" static int add_parameter_allow(char **argv, int max_capacity) @@ -44,7 +45,7 @@ add_parameter_allow(char **argv, int max_capacity) int count = 0; RTE_EAL_DEVARGS_FOREACH(NULL, devargs) { - if (strlen(devargs->name) == 0) + if (strlen(devargs->name) == 0 || devargs->type != RTE_DEVTYPE_ALLOWED) continue; if (devargs->data == NULL || strlen(devargs->data) == 0) { @@ -63,6 +64,32 @@ add_parameter_allow(char **argv, int max_capacity) return count; } +static int +add_parameter_block(char **argv, int max_capacity) +{ + struct rte_devargs *devargs; + int count = 0; + + RTE_EAL_DEVARGS_FOREACH(NULL, devargs) { + if (strlen(devargs->name) == 0 || devargs->type != RTE_DEVTYPE_BLOCKED) + continue; + + if (devargs->data == NULL || strlen(devargs->data) == 0) { + if (asprintf(&argv[count], PREFIX_BLOCK"%s", devargs->name) < 0) + break; + } else { + if (asprintf(&argv[count], PREFIX_BLOCK"%s,%s", + devargs->name, devargs->data) < 0) + break; + } + + if (++count == max_capacity) + break; + } + + return count; +} + /* * launches a second copy of the test process using the given argv parameters, * which should include argv[0] as the process name. To identify in the @@ -74,7 +101,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) { int num = 0; char **argv_cpy; - int allow_num; + int allow_num, block_num; int argv_num; int i, status; char path[32]; @@ -89,8 +116,27 @@ process_dup(const char *const argv[], int numargs, const char *env_value) if (pid < 0) return -1; else if (pid == 0) { - allow_num = rte_devargs_type_count(RTE_DEVTYPE_ALLOWED); - argv_num = numargs + allow_num + 1; + allow_num = 0; + block_num = 0; + + for (i = 0; i < numargs; i++) { + if (strcmp(argv[i], "-b") == 0 || + strcmp(argv[i], "--block") == 0) + block_num++; + if (strcmp(argv[i], "-a") == 0 || + strcmp(argv[i], "--allow") == 0) + allow_num++; + } + /* If block (-b) and allow (-a) are present, they will not be added. */ + if (!block_num && !allow_num) { + allow_num = rte_devargs_type_count(RTE_DEVTYPE_ALLOWED); + block_num = rte_devargs_type_count(RTE_DEVTYPE_BLOCKED); + } else { + allow_num = 0; + block_num = 0; + } + + argv_num = numargs + allow_num + block_num + 1; argv_cpy = calloc(argv_num, sizeof(char *)); if (!argv_cpy) rte_panic("Memory allocation failed\n"); @@ -101,8 +147,12 @@ process_dup(const char *const argv[], int numargs, const char *env_value) if (argv_cpy[i] == NULL) rte_panic("Error dup args\n"); } + + /* EAL limits block (-b) and allow (-a) to not exist at the same time. */ if (allow_num > 0) num = add_parameter_allow(&argv_cpy[i], allow_num); + else if (block_num > 0) + num = add_parameter_block(&argv_cpy[i], block_num); num += numargs; #ifdef RTE_EXEC_ENV_LINUX -- 2.25.1