From nobody Thu Apr 9 11:49:27 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 531D437C939; Sun, 15 Mar 2026 21:18:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609509; cv=pass; b=AmXAeMEbfyqU8UrvFqkVMbfRbDfT1ev3jN1CTWhdmvVIOrTM9rcvJetbc/0UgC9E7w3Z2AGKvpJ9CRjFa/f7vVbT5c/HECwcza9bodHmwId8kXxJJQMwxwbprZ9cC0O3/BAjQSOkWJj7ciaJfsPJeUxP1u1HPgyaeP1s3HCzyo0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609509; c=relaxed/simple; bh=MrFEroHwYorqSWGBoY5ocHzyEC+JzAla+WphZ3zVa6Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LRZICogfvNLf1GFC3TClZpgp5NqmGx4+QqyFA2OzvsELloAaqM1XDV2hj3m29qVs5reCqbIo7mZSuEzIDKEBXWHuQg/h2yJuq/V0FgzHQMoRSqqYDM86DyOhdUGzycN2PVEte1GWdrB0GdspgVq7NPLfcsHnb4DNBHt9quHt6ck= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=A+FHKzaP; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="A+FHKzaP" ARC-Seal: i=1; a=rsa-sha256; t=1773609495; cv=none; d=zohomail.eu; s=zohoarc; b=LXSDq398A/5aYtmwFr9ymG457T2fs4BtNeoVAHjTSTGXLXoerCemQBfbHzO+szA68X90e5Pag6HeZw0XixX006ACXt/2G16Uu8i3wStz1J4DWvIUzL/UUEqw86Omo82FrnOt6l/YnZwQGF7KW3ZAX+6BhHItWw19UPVq6o2thT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773609495; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=/JtZCIPsgGracX5Mx/4hRAMi9BpwqYEGpkwpzrg8Moo=; b=KgYMNTVWGBUuNBvafXnBM/3JGglA6WgPf47qHGbvQkB6PGBFK8ScqyQu3pmA2oyY+5G8pXuNiO0wntjk8a8MwWA7ifx3zsM9hkNfCLxD2/NIUbWUtTQy9CWS4PSEoQwXQ1hoZJitruBGCDZ7PdaAHiBeDzHlE1XTWdUCWOQsih8= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773609495; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=/JtZCIPsgGracX5Mx/4hRAMi9BpwqYEGpkwpzrg8Moo=; b=A+FHKzaPzrOgjPIsz+y/T/qBtA74zcKllis6BmVDGC5pl8qKrZ9FScgo8lStt+GC 6EjJ8PKHE7FsFANWeStpPD1VaWHmTbcCPvnrjjA9p8W6xrVrc59fLwKPP8E8zgPbLGT ff8jUSakjLMfLzLyJMhDRQNXr83jDTMXQCRbyvAc= Received: by mx.zoho.eu with SMTPS id 1773609494489924.6100757135223; Sun, 15 Mar 2026 22:18:14 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Josh Law 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 Message-Id: <20260315211807.411173-8-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315211807.411173-1-objecting@objecting.org> References: <20260315211807.411173-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" 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 --- 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); } =20 +/* Case-insensitive matching tests */ +static const struct glob_test_case glob_nocase_test_cases[] =3D { + { .pat =3D "abc", .str =3D "ABC", .expected =3D true }, + { .pat =3D "ABC", .str =3D "abc", .expected =3D true }, + { .pat =3D "aBc", .str =3D "AbC", .expected =3D true }, + { .pat =3D "a*c", .str =3D "ABC", .expected =3D true }, + { .pat =3D "A?C", .str =3D "abc", .expected =3D true }, + { .pat =3D "[A-Z]", .str =3D "m", .expected =3D true }, + { .pat =3D "[a-z]", .str =3D "M", .expected =3D true }, + { .pat =3D "abc", .str =3D "abd", .expected =3D false }, + { .pat =3D "ABC", .str =3D "ABD", .expected =3D false }, + { .pat =3D "a*z", .str =3D "ABZ", .expected =3D true }, + { .pat =3D "\\A", .str =3D "a", .expected =3D 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 =3D 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[] =3D { + { .pat =3D "abc", .expected =3D true }, + { .pat =3D "*", .expected =3D true }, + { .pat =3D "?", .expected =3D true }, + { .pat =3D "[abc]", .expected =3D true }, + { .pat =3D "[!abc]", .expected =3D true }, + { .pat =3D "[^abc]", .expected =3D true }, + { .pat =3D "[a-z]", .expected =3D true }, + { .pat =3D "[]abc]", .expected =3D true }, + { .pat =3D "\\*", .expected =3D true }, + { .pat =3D "\\\\", .expected =3D true }, + { .pat =3D "", .expected =3D true }, + /* Invalid patterns */ + { .pat =3D "[", .expected =3D false }, + { .pat =3D "[abc", .expected =3D false }, + { .pat =3D "[!abc", .expected =3D false }, + { .pat =3D "abc\\", .expected =3D false }, + { .pat =3D "\\", .expected =3D false }, + { .pat =3D "abc[def", .expected =3D 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 =3D 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[] =3D { 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), {} }; =20 --=20 2.34.1