[Concept,6/9] test: ut: Refactor argument processing to use a loop

Message ID 20251229160611.3899708-7-sjg@u-boot.org
State New
Headers
Series test: Various improvements to unit-test infrastructure |

Commit Message

Simon Glass Dec. 29, 2025, 4:06 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

The current argument-parsing logic uses switch (str[1]) which only
processes the second character of each argument. This prevents combining
multiple single-character flags in one argument (e.g., -fm).

Refactor the code to use a for loop that iterates through all characters
in the argument. For flags that take a value (like -r and -I), use goto
to skip the rest of the argument after processing.

This allows combined flags like -fmR instead of requiring -f -m -R.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 test/cmd_ut.c | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)
  

Patch

diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 050f7ee6caf..37144242099 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -267,26 +267,29 @@  static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	while (argc > 0 && *argv[0] == '-') {
 		const char *str = argv[0];
 
-		switch (str[1]) {
-		case 'r':
-			runs_per_text = dectoul(str + 2, NULL);
-			break;
-		case 'f':
-		case 'm':
-			force_run = true;
-			break;
-		case 'I':
-			test_insert = str + 2;
-			if (!strchr(test_insert, ':'))
-				return CMD_RET_USAGE;
-			break;
-		case 'R':
-			keep_record = true;
-			break;
-		case 's':
-			show_suites = true;
-			break;
+		for (str++; *str; str++) {
+			switch (*str) {
+			case 'r':
+				runs_per_text = dectoul(str + 1, NULL);
+				goto next_arg;
+			case 'f':
+			case 'm':
+				force_run = true;
+				break;
+			case 'I':
+				test_insert = str + 1;
+				if (!strchr(test_insert, ':'))
+					return CMD_RET_USAGE;
+				goto next_arg;
+			case 'R':
+				keep_record = true;
+				break;
+			case 's':
+				show_suites = true;
+				break;
+			}
 		}
+next_arg:
 		argv++;
 		argc--;
 	}