{"id":2222489,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2222489/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20260412111958.943933-2-sjg@chromium.org/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/1.2/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260412111958.943933-2-sjg@chromium.org>","list_archive_url":null,"date":"2026-04-12T11:19:38","name":"[v2,01/12] test: Add ut_asserteq_regex() for regex pattern matching","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"3e803f1173705f6f5e61726e01de974c093fffad","submitter":{"id":6170,"url":"http://patchwork.ozlabs.org/api/1.2/people/6170/?format=json","name":"Simon Glass","email":"sjg@chromium.org"},"delegate":{"id":3651,"url":"http://patchwork.ozlabs.org/api/1.2/users/3651/?format=json","username":"trini","first_name":"Tom","last_name":"Rini","email":"trini@ti.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20260412111958.943933-2-sjg@chromium.org/mbox/","series":[{"id":499596,"url":"http://patchwork.ozlabs.org/api/1.2/series/499596/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=499596","date":"2026-04-12T11:19:37","name":"test: Add support for passing arguments to C unit tests","version":2,"mbox":"http://patchwork.ozlabs.org/series/499596/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2222489/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2222489/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256\n header.s=google header.b=XHV8P9CC;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=85.214.62.61; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=chromium.org","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=chromium.org header.i=@chromium.org\n header.b=\"XHV8P9CC\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=chromium.org","phobos.denx.de;\n spf=pass smtp.mailfrom=sjg@chromium.org"],"Received":["from phobos.denx.de (phobos.denx.de [85.214.62.61])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4ftp8R5hlXz1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 12 Apr 2026 21:24:07 +1000 (AEST)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 1F5B4839D5;\n\tSun, 12 Apr 2026 13:24:04 +0200 (CEST)","by phobos.denx.de (Postfix, from userid 109)\n id E967E840D8; Sun, 12 Apr 2026 13:24:03 +0200 (CEST)","from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com\n [IPv6:2001:4860:4864:20::2e])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 53E438341A\n for <u-boot@lists.denx.de>; Sun, 12 Apr 2026 13:24:01 +0200 (CEST)","by mail-oa1-x2e.google.com with SMTP id\n 586e51a60fabf-4138136f02eso2249951fac.2\n for <u-boot@lists.denx.de>; Sun, 12 Apr 2026 04:24:01 -0700 (PDT)","from chromium.org ([73.34.74.121]) by smtp.gmail.com with ESMTPSA id\n 586e51a60fabf-423dd395606sm6622071fac.1.2026.04.12.04.23.56\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Sun, 12 Apr 2026 04:23:57 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,\n DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,\n RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham\n autolearn_force=no version=3.4.2","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=chromium.org; s=google; t=1775993039; x=1776597839; darn=lists.denx.de;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=vJU8VpiUrK7UsUpBNsC+ecw18CCcPk4W41lFeryMrJQ=;\n b=XHV8P9CCo40UpNi7YxEjAEBXx9x6dpGCOUpsjHQhz7M2DQs4UGxdRCY00Aqsl37SCg\n I01y0+A717WXhCA1oNqPXIk2jdzq2Mc8YhyX/SDeRk3x7nzmhw0hM3AJy1DWM4caslWh\n giKsyAcRTrUHdDiYkO345bQGyFM6m7lYehLb4=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775993039; x=1776597839;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=vJU8VpiUrK7UsUpBNsC+ecw18CCcPk4W41lFeryMrJQ=;\n b=HEe/LBOcXXfpKgfNzvrQe6IuA7Cf5UVG4A/UQFkxU0afqtwMnGHSTFQ7OsPTh57/8W\n Ts4ihaOHvaGyx+aGQvvH1Z/eWPtyYfykobLVBl/CWj54gtggbynFdAUxMLl/J8Guhhls\n pbWixeF280u+/ym0DwE9opV+4X99sXEoVFrlrXlNLtiCAo+1jGKvV2JWb4USgp/+qGDm\n /7YSLrf5Eh1SvOAiveTZBOBZQnEpq4Q9VSwsWdCKxoWQt25/aAR/B8gx05cc526yNj4X\n S7P0xGeF1WV+9jujmklRLVq03JA96Q/RcFY9MUcNxp0mY4aN0a0U17eotIMpDSFrrKCy\n 4iBw==","X-Gm-Message-State":"AOJu0YzRdqFxrRomJNkbcDlSX4Uy63RQJKeKwWivx0W5uPqp5Q3jUqGH\n Y+bKSmlAqv4eHvVgitM/0ecuyg9Nn8sN/UqvwHFQ1mGI44OIQJw2yGxg//zHGZQySz2dve0vW2I\n CWDfgIA==","X-Gm-Gg":"AeBDietrA4SFj85H0M+3ctuhprDdtwF2+Iy3eGJ7T2uMCKIl7O6ht4Qdrhx9uDOaqko\n l8/kNNf8sa5/BtQAPAzpX2c4yUwYpS1xPBYIxrKHTnc8vhAVTA+nY7DdPEqyDqK+JuPUujhLgdH\n gtH1fE4uZPITW7m2TMUucCcuwFVWdow5wehPZiPG/9vibGgqZBF3uKjAqC/HyThH204tLgNlJL0\n SXSICt2K/wUEWOYap1xqxX7b3fdeCRt6fuv9swi/r96ltDvvgWXGE6iglooiQX1h75ADHmVFhw4\n xdS0zOnm7jEVhZBxh2bow5MrbT8rTdNqOZqDSIftGYPudPSSTqvRe159QO3IFZo67/TK052P8m6\n 0x5DpOWXXo4PkIDP9tKXJAAQBgIIzJGD6pIaEI8v6DpquVo5wn6xg/87J75mjzhvoDN/U5HwB74\n 3cotg/c7bvRsoJPJ9AaQ==","X-Received":"by 2002:a05:6870:a787:b0:409:a4d3:a30e with SMTP id\n 586e51a60fabf-423e0db9f67mr5366971fac.2.1775993039430;\n Sun, 12 Apr 2026 04:23:59 -0700 (PDT)","From":"Simon Glass <sjg@chromium.org>","To":"u-boot@lists.denx.de","Cc":"Tom Rini <trini@konsulko.com>, Heinrich Schuchardt <xypron.glpk@gmx.de>,\n Simon Glass <sjg@chromium.org>","Subject":"[PATCH v2 01/12] test: Add ut_asserteq_regex() for regex pattern\n matching","Date":"Sun, 12 Apr 2026 05:19:38 -0600","Message-ID":"<20260412111958.943933-2-sjg@chromium.org>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260412111958.943933-1-sjg@chromium.org>","References":"<20260412111958.943933-1-sjg@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"},"content":"Add a new assertion macro ut_asserteq_regex() that checks if a string\nmatches a regular expression pattern using the SLRE library.\n\nThis is useful for tests where exact string-matching is difficult, such\nas when output contains line numbers or other variable content.\n\nUse a helper function ut_check_regex() to avoid including slre.h in the\nheader.\n\nSigned-off-by: Simon Glass <sjg@chromium.org>\n---\n\n(no changes since v1)\n\n include/test/ut.h | 36 +++++++++++++++++++++++++++++-------\n test/ut.c         | 30 ++++++++++++++++++++++++++++++\n 2 files changed, 59 insertions(+), 7 deletions(-)","diff":"diff --git a/include/test/ut.h b/include/test/ut.h\nindex 6510c35997f..cda15f3a7a9 100644\n--- a/include/test/ut.h\n+++ b/include/test/ut.h\n@@ -13,6 +13,9 @@\n #include <linux/err.h>\n #include <test/test.h>\n \n+/* Size of error buffer for ut_check_regex() */\n+#define UT_REGEX_ERR_SIZE\t256\n+\n struct unit_test_state;\n \n /**\n@@ -41,6 +44,16 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,\n \t      const char *func, const char *cond, const char *fmt, ...)\n \t\t\t__attribute__ ((format (__printf__, 6, 7)));\n \n+/**\n+ * ut_check_regex() - Check if a string matches a regex pattern\n+ *\n+ * @pattern: Regular expression pattern\n+ * @str: String to match against\n+ * @err: Buffer to hold error message on failure (UT_REGEX_ERR_SIZE bytes)\n+ * Return: 0 if match, -EINVAL if pattern is invalid, -ENOENT if no match\n+ */\n+int ut_check_regex(const char *pattern, const char *str, char *err);\n+\n /**\n  * ut_check_console_line() - Check the next console line against expectations\n  *\n@@ -264,13 +277,22 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);\n \t__ret;\t\t\t\t\t\t\t\t\\\n })\n \n-/**\n- * ut_asserteq_mem() - Assert that two memory areas are equal\n- *\n- * @expr1:\texpected value\n- * @expr2:\tactual value\n- * @len:\tlength of the memory areas\n- */\n+/* Assert that a string matches a regex pattern */\n+#define ut_asserteq_regex(pattern, str) ({\t\t\t\t\\\n+\tconst char *_pattern = (pattern), *_str = (str);\t\t\\\n+\tchar _err[UT_REGEX_ERR_SIZE];\t\t\t\t\t\\\n+\tint __ret = 0;\t\t\t\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n+\t__ret = ut_check_regex(_pattern, _str, _err);\t\t\t\\\n+\tif (__ret) {\t\t\t\t\t\t\t\\\n+\t\tut_failf(uts, __FILE__, __LINE__, __func__,\t\t\\\n+\t\t\t #pattern \" matches \" #str, \"%s\", _err);\t\\\n+\t\treturn CMD_RET_FAILURE;\t\t\t\t\t\\\n+\t}\t\t\t\t\t\t\t\t\\\n+\t__ret;\t\t\t\t\t\t\t\t\\\n+})\n+\n+/* Assert that two memory areas are equal */\n #define ut_asserteq_mem(expr1, expr2, len) ({\t\t\t\t\\\n \tconst u8 *_val1 = (u8 *)(expr1), *_val2 = (u8 *)(expr2);\t\\\n \tconst uint __len = len;\t\t\t\t\t\t\\\ndiff --git a/test/ut.c b/test/ut.c\nindex a16fdfb3a93..b4f2a8bf40f 100644\n--- a/test/ut.c\n+++ b/test/ut.c\n@@ -6,7 +6,10 @@\n  */\n \n #include <console.h>\n+#include <errno.h>\n #include <malloc.h>\n+#include <slre.h>\n+#include <vsprintf.h>\n #ifdef CONFIG_SANDBOX\n #include <asm/state.h>\n #endif\n@@ -38,6 +41,33 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,\n \tuts->cur.fail_count++;\n }\n \n+int ut_check_regex(const char *pattern, const char *str, char *err)\n+{\n+\tstruct slre slre;\n+\n+\tif (!pattern || !str) {\n+\t\tsnprintf(err, UT_REGEX_ERR_SIZE,\n+\t\t\t \"NULL value: pattern=%s, str=%s\",\n+\t\t\t pattern ? pattern : \"(null)\",\n+\t\t\t str ? str : \"(null)\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!slre_compile(&slre, pattern)) {\n+\t\tsnprintf(err, UT_REGEX_ERR_SIZE,\n+\t\t\t \"Invalid regex '%s': %s\", pattern, slre.err_str);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!slre_match(&slre, str, strlen(str), NULL)) {\n+\t\tsnprintf(err, UT_REGEX_ERR_SIZE,\n+\t\t\t \"No match: pattern '%s', str '%s'\", pattern, str);\n+\t\treturn -ENOENT;\n+\t}\n+\n+\treturn 0;\n+}\n+\n ulong ut_check_free(void)\n {\n \tstruct mallinfo info = mallinfo();\n","prefixes":["v2","01/12"]}