DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: techboard@dpdk.org, Bruce Richardson <bruce.richardson@intel.com>
Subject: [RFC PATCH 39/44] app/test: enable testing init using EAL config lib
Date: Wed, 29 Apr 2026 17:58:31 +0100	[thread overview]
Message-ID: <20260429165845.2136843-40-bruce.richardson@intel.com> (raw)
In-Reply-To: <20260429165845.2136843-1-bruce.richardson@intel.com>

To test the eal_cfg library initialization we need to bypass the regular
rte_eal_init() calls in the test binary, which requires a little bit of
rework to the existing test harness. Make those changes and then add
some very basic init testing using the rte_eal_cfg_init() function.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test/test.c         | 14 +++---
 app/test/test.h         |  1 +
 app/test/test_eal_cfg.c | 99 +++++++++++++++++++++++++++++++----------
 3 files changed, 86 insertions(+), 28 deletions(-)

diff --git a/app/test/test.c b/app/test/test.c
index 58ef52f312..dba3c581a4 100644
--- a/app/test/test.c
+++ b/app/test/test.c
@@ -47,13 +47,11 @@ extern cmdline_parse_ctx_t main_ctx[];
 
 const char *prgname; /* to be set to argv[0] */
 
-static const char *recursive_call; /* used in linux for MP and other tests */
-
 static int
 no_action(void){ return 0; }
 
 static int
-do_recursive_call(void)
+do_recursive_call(const char *recursive_call)
 {
 	unsigned i;
 	struct {
@@ -117,6 +115,13 @@ main(int argc, char **argv)
 	int i;
 	char *extra_args;
 	int ret;
+	const char *recursive_call = getenv(RECURSIVE_ENV_VAR);
+
+#ifdef RTE_LIB_EAL_CFG
+	/* Pre-EAL-init dispatch: for tests that test EAL init itself. */
+	if (recursive_call != NULL && strcmp(recursive_call, "test_eal_cfg_init") == 0)
+		return test_eal_cfg_init();
+#endif
 
 	extra_args = getenv("DPDK_TEST_PARAMS");
 	if (extra_args != NULL && strlen(extra_args) > 0) {
@@ -174,9 +179,8 @@ main(int argc, char **argv)
 		goto out;
 	}
 
-	recursive_call = getenv(RECURSIVE_ENV_VAR);
 	if (recursive_call != NULL) {
-		ret = do_recursive_call();
+		ret = do_recursive_call(recursive_call);
 		goto out;
 	}
 
diff --git a/app/test/test.h b/app/test/test.h
index 1f12fc5397..b80c818249 100644
--- a/app/test/test.h
+++ b/app/test/test.h
@@ -179,6 +179,7 @@ int test_exit(void);
 int test_mp_secondary(void);
 int test_panic(void);
 int test_timer_secondary(void);
+int test_eal_cfg_init(void);
 
 int test_set_rxtx_conf(cmdline_fixed_string_t mode);
 int test_set_rxtx_anchor(cmdline_fixed_string_t type);
diff --git a/app/test/test_eal_cfg.c b/app/test/test_eal_cfg.c
index 3def760b50..f714be3fd4 100644
--- a/app/test/test_eal_cfg.c
+++ b/app/test/test_eal_cfg.c
@@ -4,12 +4,19 @@
 
 #include <errno.h>
 
+#include <rte_eal.h>
+#include <rte_debug.h>
 #include <rte_errno.h>
 
 #include <rte_eal_cfg.h>
+#include <stdlib.h>
 
 #include "test.h"
 
+#ifndef RTE_EXEC_ENV_WINDOWS
+#include "process.h"
+#endif
+
 /* Test that a config handle can be created and freed without error. */
 static int
 test_eal_cfg_create_free(void)
@@ -29,14 +36,13 @@ test_eal_cfg_create_free(void)
 	return TEST_SUCCESS;
 }
 
-/*
- * Test initialising EAL with a freshly created (empty/default) config.
- * Since the test binary has already initialised EAL, we expect the call to
- * fail with EALREADY rather than succeed — but the function must forward
- * the call through to rte_eal_runtime_init() and return its error correctly.
- */
+#ifdef RTE_EXEC_ENV_WINDOWS
+int
+test_eal_cfg_init(void) { return 0; }
+#else
+/* Test initialising EAL with a freshly created (empty/default) config. */
 static int
-test_eal_cfg_init_empty(void)
+subtest_eal_cfg_init_empty(void)
 {
 	struct rte_eal_cfg *cfg;
 	int ret;
@@ -45,29 +51,21 @@ test_eal_cfg_init_empty(void)
 	TEST_ASSERT_NOT_NULL(cfg, "rte_eal_cfg_create returned NULL");
 
 	ret = rte_eal_init_from_cfg("test_prog", cfg);
-	TEST_ASSERT(ret == -1,
-		"Expected -1 from rte_eal_init_from_cfg (EAL already init), got %d", ret);
-	TEST_ASSERT(rte_errno == EALREADY,
-		"Expected EALREADY, got %d", rte_errno);
+	TEST_ASSERT(ret == 0,
+		"Expected 0 from rte_eal_init_from_cfg, got %d", ret);
 
 	rte_eal_cfg_free(cfg);
+
+	rte_eal_cleanup();
 	return TEST_SUCCESS;
 }
 
-/* Test that passing NULL cfg to rte_eal_init_from_cfg uses default config.
- * Since EAL is already running, we still expect EALREADY.
- */
+/* Test that passing NULL cfg to rte_eal_init_from_cfg uses default config. */
 static int
-test_eal_cfg_init_null(void)
+subtest_eal_cfg_init_null(void)
 {
 	int ret;
 
-	ret = rte_eal_init_from_cfg("test_prog", NULL);
-	TEST_ASSERT(ret == -1,
-		"Expected -1 from rte_eal_init_from_cfg with NULL cfg, got %d", ret);
-	TEST_ASSERT(rte_errno == EALREADY,
-		"Expected EALREADY for NULL cfg, got %d", rte_errno);
-
 	/* NULL progname must be rejected regardless of cfg */
 	ret = rte_eal_init_from_cfg(NULL, NULL);
 	TEST_ASSERT(ret == -1,
@@ -75,17 +73,72 @@ test_eal_cfg_init_null(void)
 	TEST_ASSERT(rte_errno == EINVAL,
 		"Expected EINVAL for NULL progname, got %d", rte_errno);
 
+	ret = rte_eal_init_from_cfg("test_prog", NULL);
+	TEST_ASSERT(ret == 0,
+		"Expected 0 from rte_eal_init_from_cfg with NULL cfg, got %d", ret);
+
+	rte_eal_cleanup();
 	return TEST_SUCCESS;
 }
 
+/*
+ * Test EAL initialisation from a default config in a fresh subprocess.
+ * Called before rte_eal_init() so that it can exercise the very first call
+ * through rte_eal_init_from_cfg(). Returns 0 on success, 1 on failure.
+ */
+int
+test_eal_cfg_init(void)
+{
+#define EAL_CFG_TEST_FN "EAL_CFG_TEST_FN"
+	struct test_fns {
+		const char *name;
+		int (*fn)(void);
+	} test_fns[] = {
+#define TEST_CFG_FN(X) { #X, X }
+		TEST_CFG_FN(subtest_eal_cfg_init_null),
+		TEST_CFG_FN(subtest_eal_cfg_init_empty),
+		{ NULL, NULL }
+	};
+
+	const char *test_fn = getenv(EAL_CFG_TEST_FN);
+	if (test_fn == NULL) {
+		/* This is the parent process: spawn a child to run the test. */
+		const char *argv[] = { prgname, NULL };
+
+		for (size_t i = 0; test_fns[i].name != NULL; i++) {
+			setenv(EAL_CFG_TEST_FN, test_fns[i].name, 1);
+			int ret = process_dup(argv, 1, __func__);
+			if (ret != 0) {
+				printf("Test '%s' failed with return code %d\n",
+					test_fns[i].name, ret);
+				return -1;
+			}
+			printf("Test '%s' passed\n", test_fns[i].name);
+		}
+	} else {
+		/* This is the child process: run the specified test function. */
+		for (size_t i = 0; test_fns[i].name != NULL; i++) {
+			if (strcmp(test_fn, test_fns[i].name) == 0) {
+				printf("Running test '%s'\n", test_fns[i].name);
+				return test_fns[i].fn();
+			}
+		}
+
+		printf("Unknown test function '%s'\n", test_fn);
+		return -1;
+	}
+
+	return 0;
+}
+#endif /* RTE_EXEC_ENV_WINDOWS */
+
 static struct unit_test_suite eal_cfg_testsuite = {
 	.suite_name = "EAL cfg API tests",
 	.setup = NULL,
 	.teardown = NULL,
 	.unit_test_cases = {
 		TEST_CASE(test_eal_cfg_create_free),
-		TEST_CASE(test_eal_cfg_init_empty),
-		TEST_CASE(test_eal_cfg_init_null),
+		TEST_CASE(test_eal_cfg_init),
 		TEST_CASES_END()
 	}
 };
-- 
2.51.0


  parent reply	other threads:[~2026-04-29 17:04 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 16:57 [RFC PATCH 00/44] Allow intitializing EAL without argc/argv Bruce Richardson
2026-04-29 16:57 ` [RFC PATCH 01/44] eal: define new functionally distinct config structs Bruce Richardson
2026-04-29 19:03   ` Stephen Hemminger
2026-04-30  7:56     ` Bruce Richardson
2026-04-29 16:57 ` [RFC PATCH 02/44] eal: move memory request fields to user config Bruce Richardson
2026-04-29 16:57 ` [RFC PATCH 03/44] eal: move NUMA " Bruce Richardson
2026-04-29 16:57 ` [RFC PATCH 04/44] eal: move hugepage policy " Bruce Richardson
2026-04-29 16:57 ` [RFC PATCH 05/44] eal: move process " Bruce Richardson
2026-04-29 16:57 ` [RFC PATCH 06/44] eal: move advanced user config options to user cfg struct Bruce Richardson
2026-04-29 16:57 ` [RFC PATCH 07/44] eal: move hugepage size info to platform info struct Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 08/44] telemetry: make cpuset init parameter const Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 09/44] eal: move runtime state to appropriate structure Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 10/44] eal: record details of all cpus in platform info Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 11/44] eal: use platform info for lcore lookups Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 12/44] eal: add RTE_CPU_FFS macro Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 13/44] eal: store lcore configuration in runtime data Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 14/44] eal: cleanup CPU init function Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 15/44] eal: move numa node information to platform info struct Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 16/44] eal: move lcore role and count to runtime state Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 17/44] eal: make lcore role a field in lcore config struct Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 18/44] eal: move main lcore setting to runtime " Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 19/44] eal: move iova mode and process type to runtime cfg Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 20/44] eal: move memory config pointer to runtime state struct Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 21/44] eal: remove rte_config structure Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 22/44] eal: separate runtime state update from arg parsing Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 23/44] eal: move devopt_list staging list into user_cfg Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 24/44] eal: separate plugin paths from loaded plugin objects Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 25/44] eal: simplify internal driver path iteration APIs Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 26/44] eal: move trace config into user config struct Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 27/44] eal: record service cores in " Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 28/44] eal: store user-provided lcore info " Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 29/44] eal: clarify docs on params taking lcore IDs Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 30/44] eal: remove internal config reset function Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 31/44] eal: move functions setting runtime state Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 32/44] eal: initialize platform info on first use Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 33/44] eal: remove duplicated scan of sysfs for hugepage details Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 34/44] eal: add utilities for working with user config struct Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 35/44] eal: split EAL init into two stages Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 36/44] eal: provide hooks for init with externally supplied config Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 37/44] eal_cfg: add new library to programmatically init DPDK Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 38/44] eal_cfg: configure defaults for easier testing and use Bruce Richardson
2026-04-29 16:58 ` Bruce Richardson [this message]
2026-04-29 16:58 ` [RFC PATCH 40/44] eal_cfg: add basic setters and getters Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 41/44] eal_cfg: add hugepage memory configuration Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 42/44] eal_cfg: support configuring lcores Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 43/44] eal_cfg: support device and driver lists Bruce Richardson
2026-04-29 16:58 ` [RFC PATCH 44/44] eal_cfg: add APIs for configuring remaining init settings Bruce Richardson
2026-04-29 21:40 ` [RFC PATCH 00/44] Allow intitializing EAL without argc/argv Stephen Hemminger
2026-04-29 22:04 ` Stephen Hemminger
2026-04-30  8:00   ` Bruce Richardson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260429165845.2136843-40-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=techboard@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox