test: ut: Refactor argument processing to use a loop

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>
This commit is contained in:
Simon Glass
2025-12-29 08:00:49 -07:00
committed by Simon Glass
parent 9844bfd977
commit 58b6eaef82

View File

@@ -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--;
}