Skip to content

Commit e31f9bf

Browse files
nashifdanieldegrasse
authored andcommitted
ztest: native_sim: fail instead of crashing on wrong arguments
Instead of crashing fail with a message when -test arguments is of wrong format. Fixes #91655 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
1 parent bec789d commit e31f9bf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

subsys/testsuite/ztest/src/ztest_posix.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <zephyr/tc_util.h>
1212
#include <zephyr/ztest_test.h>
1313
#include "nsi_host_trampolines.h"
14+
#include <nsi_tracing.h>
1415

1516
static const char *test_args;
1617
static bool list_tests;
@@ -161,10 +162,18 @@ static bool z_ztest_testargs_contains(const char *suite_name, const char *test_n
161162
suite_arg = strtok_r(suite_test_pair, ":", &last_arg);
162163
test_arg = strtok_r(NULL, ":", &last_arg);
163164

165+
/* Validate format: must be test_suite::* or test_suite::test_case */
166+
if (!suite_arg || !test_arg || strtok_r(NULL, ":", &last_arg) != NULL) {
167+
/* Invalid format, report error and exit */
168+
nsi_print_error_and_exit(
169+
"Invalid test argument format '%s'. Expected a set of pairs like"
170+
"'suite::test' or 'suite::*', got instead '%s'.\n",
171+
test_args, suite_test_pair);
172+
}
173+
164174
found = !strcmp(suite_arg, suite_name);
165175
if (test_name) {
166-
found &= !strcmp(test_arg, "*") ||
167-
!strcmp(test_arg, test_name);
176+
found &= (!strcmp(test_arg, "*") || !strcmp(test_arg, test_name));
168177
}
169178

170179
suite_test_pair = strtok_r(NULL, ",", &last_suite_test_pair);

0 commit comments

Comments
 (0)