From 7142d6f4a36b49ae3710da8decb8bf9288c6f3bb Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 10 Jun 2025 17:42:01 +0800 Subject: [PATCH] componnets: utest: fix case-name matching problem There is a problem with the matching of case names in the original code. Due to original code use memcmp with len, if the input case name and the existing case name have an inclusion relationship, for example, if the actual case name is "gpip_irq", and run `utest_run gpio` will also match successfully, but it's not expected. Modify the logic of exact matching and use strcmp instead. Keep the original wildcard logic, that is, `utest_run gpio*` can match both "gpio_irq" and "gpio". Signed-off-by: Chen Wang --- components/utilities/utest/utest.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 5cb10e1af16..3d44a8b16aa 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -217,8 +217,13 @@ static void utest_do_run(const char *utest_name) if (utest_name[len - 1] == '*') { len -= 1; + if (rt_memcmp(tc_table[i].name, utest_name, len) != 0) + { + i++; + continue; + } } - if (rt_memcmp(tc_table[i].name, utest_name, len) != 0) + else if (rt_strcmp(tc_table[i].name, utest_name) != 0) { i++; continue;