From: Josh Law <objecting@objecting.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>,
David Gow <david@davidgow.net>, Rae Moar <raemoar63@gmail.com>,
linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
linux-kernel@vger.kernel.org, Josh Law <objecting@objecting.org>
Subject: [PATCH v4 7/8] lib/tests: add kunit tests for glob_match_nocase() and glob_validate()
Date: Sun, 15 Mar 2026 21:18:06 +0000 [thread overview]
Message-ID: <20260315211807.411173-8-objecting@objecting.org> (raw)
In-Reply-To: <20260315211807.411173-1-objecting@objecting.org>
Add parameterized test cases for the new glob API functions:
glob_match_nocase() tests verify case-insensitive matching for
literal characters, wildcards, character class ranges, and
backslash escapes -- e.g., pattern "a*c" matches string "ABC",
and range [A-Z] matches lowercase 'm'.
glob_validate() tests verify detection of malformed patterns:
well-formed patterns (character classes, escapes, wildcards) return
true, while unclosed brackets ("[abc") and trailing backslashes
("abc\") return false.
Signed-off-by: Josh Law <objecting@objecting.org>
---
lib/tests/glob_kunit.c | 77 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/lib/tests/glob_kunit.c b/lib/tests/glob_kunit.c
index 9b53060e7c8e..711cb44d1fc8 100644
--- a/lib/tests/glob_kunit.c
+++ b/lib/tests/glob_kunit.c
@@ -157,8 +157,85 @@ static void glob_test_match(struct kunit *test)
params->pat, params->str, params->expected);
}
+/* Case-insensitive matching tests */
+static const struct glob_test_case glob_nocase_test_cases[] = {
+ { .pat = "abc", .str = "ABC", .expected = true },
+ { .pat = "ABC", .str = "abc", .expected = true },
+ { .pat = "aBc", .str = "AbC", .expected = true },
+ { .pat = "a*c", .str = "ABC", .expected = true },
+ { .pat = "A?C", .str = "abc", .expected = true },
+ { .pat = "[A-Z]", .str = "m", .expected = true },
+ { .pat = "[a-z]", .str = "M", .expected = true },
+ { .pat = "abc", .str = "abd", .expected = false },
+ { .pat = "ABC", .str = "ABD", .expected = false },
+ { .pat = "a*z", .str = "ABZ", .expected = true },
+ { .pat = "\\A", .str = "a", .expected = true },
+};
+
+KUNIT_ARRAY_PARAM(glob_nocase, glob_nocase_test_cases, glob_case_to_desc);
+
+static void glob_test_match_nocase(struct kunit *test)
+{
+ const struct glob_test_case *params = test->param_value;
+
+ KUNIT_EXPECT_EQ_MSG(test,
+ glob_match_nocase(params->pat, params->str),
+ params->expected,
+ "nocase Pattern: \"%s\", String: \"%s\", Expected: %d",
+ params->pat, params->str, params->expected);
+}
+
+/* Pattern validation tests */
+struct glob_validate_case {
+ const char *pat;
+ bool expected;
+};
+
+static const struct glob_validate_case glob_validate_test_cases[] = {
+ { .pat = "abc", .expected = true },
+ { .pat = "*", .expected = true },
+ { .pat = "?", .expected = true },
+ { .pat = "[abc]", .expected = true },
+ { .pat = "[!abc]", .expected = true },
+ { .pat = "[^abc]", .expected = true },
+ { .pat = "[a-z]", .expected = true },
+ { .pat = "[]abc]", .expected = true },
+ { .pat = "\\*", .expected = true },
+ { .pat = "\\\\", .expected = true },
+ { .pat = "", .expected = true },
+ /* Invalid patterns */
+ { .pat = "[", .expected = false },
+ { .pat = "[abc", .expected = false },
+ { .pat = "[!abc", .expected = false },
+ { .pat = "abc\\", .expected = false },
+ { .pat = "\\", .expected = false },
+ { .pat = "abc[def", .expected = false },
+};
+
+static void glob_validate_case_to_desc(const struct glob_validate_case *t,
+ char *desc)
+{
+ snprintf(desc, KUNIT_PARAM_DESC_SIZE, "pat:\"%s\"", t->pat);
+}
+
+KUNIT_ARRAY_PARAM(glob_validate, glob_validate_test_cases,
+ glob_validate_case_to_desc);
+
+static void glob_test_validate(struct kunit *test)
+{
+ const struct glob_validate_case *params = test->param_value;
+
+ KUNIT_EXPECT_EQ_MSG(test,
+ glob_validate(params->pat),
+ params->expected,
+ "validate Pattern: \"%s\", Expected: %d",
+ params->pat, params->expected);
+}
+
static struct kunit_case glob_kunit_test_cases[] = {
KUNIT_CASE_PARAM(glob_test_match, glob_gen_params),
+ KUNIT_CASE_PARAM(glob_test_match_nocase, glob_nocase_gen_params),
+ KUNIT_CASE_PARAM(glob_test_validate, glob_validate_gen_params),
{}
};
--
2.34.1
next prev parent reply other threads:[~2026-03-15 21:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 21:17 [PATCH v4 0/8] lib/glob: bug fixes, new features, and tests Josh Law
2026-03-15 21:18 ` [PATCH v4 1/8] lib/glob: normalize inverted character class ranges Josh Law
2026-03-15 21:18 ` [PATCH v4 2/8] lib/glob: treat trailing backslash as literal character Josh Law
2026-03-15 21:18 ` [PATCH v4 3/8] lib/glob: accept [^...] as character class negation syntax Josh Law
2026-03-15 21:18 ` [PATCH v4 4/8] lib/glob: add case-insensitive glob_match_nocase() Josh Law
2026-03-15 21:18 ` [PATCH v4 5/8] lib/glob: add glob_validate() for pattern syntax checking Josh Law
2026-03-15 21:18 ` [PATCH v4 6/8] lib/tests: add glob test cases for escapes, edge cases, and new features Josh Law
2026-03-15 21:18 ` Josh Law [this message]
2026-03-15 21:18 ` [PATCH v4 8/8] kunit: validate glob filter patterns before use Josh Law
2026-03-17 7:19 ` [PATCH v4 0/8] lib/glob: bug fixes, new features, and tests David Gow
2026-03-17 7:30 ` Josh Law
2026-03-17 16:32 ` Josh Law
2026-03-18 7:19 ` David Gow
2026-03-18 15:54 ` Josh Law
2026-03-19 22:23 ` Josh Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260315211807.411173-8-objecting@objecting.org \
--to=objecting@objecting.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.higgins@linux.dev \
--cc=david@davidgow.net \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=raemoar63@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.