[PATCH 04/12] test: Add argument-type definitions
Simon Glass
sjg at chromium.org
Sun Apr 12 03:34:32 CEST 2026
From: Simon Glass <simon.glass at canonical.com>
Add types for declaring and storing unit test arguments:
- enum ut_arg_type: INT, BOOL, STR types
- enum ut_arg_flags: OPTIONAL flag for non-required args
- struct ut_arg_def: declares expected args with defaults
- struct ut_arg: holds parsed argument values
This prepares for passing key=value arguments to tests via the 'ut'
command instead of needing to use environment variables.
Signed-off-by: Simon Glass <simon.glass at canonical.com>
Signed-off-by: Simon Glass <sjg at chromium.org>
---
include/test/test.h | 65 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/include/test/test.h b/include/test/test.h
index f8a80a88959..c9b56c66eae 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -29,6 +29,40 @@ struct ut_stats {
ulong duration_ms;
};
+/**
+ * enum ut_arg_type - Type of a unit test argument
+ *
+ * @UT_ARG_INT: Integer argument (hex with 0x prefix, or decimal) -> vint
+ * @UT_ARG_BOOL: Boolean argument (0 or 1) -> vbool
+ * @UT_ARG_STR: String argument -> vstr
+ */
+enum ut_arg_type {
+ UT_ARG_INT,
+ UT_ARG_BOOL,
+ UT_ARG_STR,
+};
+
+/**
+ * struct ut_arg - Parsed unit test argument value
+ *
+ * Holds the parsed value of an argument after command-line processing.
+ *
+ * @name: Name of the argument (points to ut_arg_def.name)
+ * @type: Type of the argument
+ * @vint: Integer value (when type is UT_ARG_INT)
+ * @vbool: Boolean value (when type is UT_ARG_BOOL)
+ * @vstr: String value (when type is UT_ARG_STR, points into argv)
+ */
+struct ut_arg {
+ const char *name;
+ enum ut_arg_type type;
+ union {
+ long vint;
+ bool vbool;
+ const char *vstr;
+ };
+};
+
/*
* struct unit_test_state - Entire state of test system
*
@@ -108,6 +142,37 @@ enum ut_flags {
UTF_UNINIT = BIT(13), /* test uninits a suite */
};
+/**
+ * enum ut_arg_flags - Flags for unit test arguments
+ *
+ * @UT_ARGF_OPTIONAL: Argument is optional; use default value if not provided
+ */
+enum ut_arg_flags {
+ UT_ARGF_OPTIONAL = BIT(0),
+};
+
+/**
+ * struct ut_arg_def - Definition of a unit test argument
+ *
+ * Declares an expected argument for a test, including its name, type,
+ * whether it is optional, and its default value.
+ *
+ * @name: Name of the argument (used in key=value matching)
+ * @type: Type of the argument (int, bool, or string)
+ * @flags: Argument flags (e.g., UT_ARGF_OPTIONAL)
+ * @def: Default value (used when argument is optional and not provided)
+ */
+struct ut_arg_def {
+ const char *name;
+ enum ut_arg_type type;
+ int flags;
+ union {
+ long vint;
+ bool vbool;
+ const char *vstr;
+ } def;
+};
+
/**
* struct unit_test - Information about a unit test
*
--
2.43.0
More information about the U-Boot
mailing list