From nobody Tue Apr 7 07:08:24 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 605ED3750BE for ; Sun, 15 Mar 2026 17:11:15 +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=1773594677; cv=pass; b=TryfbxrBdF1iKrx4Wa+UxLAmy635de5iUgzOylY3wa9QGzsRghmBGrLmMv4nd1w0yf4hroUYKkcWnBcKLC2p2vj8xeMyEgQKyNBdviRsFmsjXgTPSvpKGPPSRilVc54y7EHCvqFnbDrYfayqaUqYiXwuMFipMaeJwVVr/e56Ruc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594677; c=relaxed/simple; bh=MrFEroHwYorqSWGBoY5ocHzyEC+JzAla+WphZ3zVa6Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=prDgHCwLB8DSAaLt1B5zA+EY3GTur1fVpSsIwtWcj/Z4w0U8ycecRaIZU/KIw0xf+bXjnwtYdCLM8Wy2OFhUTYkfo2594/HwCos0iL213ZHPhT42QotpcWz78neu18J2EkrRKMsuNbeJr0fK6K3q1jyHpxPsAHnRbK+sHX9y18M= 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=X9x8/EQK; 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="X9x8/EQK" ARC-Seal: i=1; a=rsa-sha256; t=1773594671; cv=none; d=zohomail.eu; s=zohoarc; b=WQswHqsEbA1vx3QolzeQYrgNTOfCE5kh/NdlnQ3daohdBFCNY0fjOPXoTH0yzfP4heV6ekJKj9dZkGLuwfgmt4nKC/P7/OOFhGKBZu/V3cjHdTUZoGZZyDObGv77q27AcBMwqtQ2Fg/A9lIVITGiMTdcZPyeAitz5Mxz+S8VkGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773594671; 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=i+GtGcZZv6+dgVIl7/ytk8bAAq+uq7VIXWuSBgqGV5k+GVj1Jnefe4P2MGHVtQufWjSI7IHOriY2rs5pRZHOiV9aoeRX+WpGeKhL3iG/iOUwZELkEQK5lF6KipD/ATGZSSwaDOjAW1QVtu4Q/1y6+E0CmejqKQmqldVeDzEM0kQ= 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=1773594671; 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=X9x8/EQKiVDc/gAvQil7HX1mpUYCw0l6XvyOX3pRaxnfnYWfvK+1T5wjlKFKX00o OyeB4+Nc5LsIcP0FhBzHhQ6u/MGNjmDNaTdXGhduxo2QXfQx0optzsCARh+sqK2n4mN AiLAEaH96ozcjxUC1ZQaa+5q9NSysZim3OzOryAo= Received: by mx.zoho.eu with SMTPS id 1773594669572303.50176239745804; Sun, 15 Mar 2026 18:11:09 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 7/7] lib/tests: add kunit tests for glob_match_nocase() and glob_validate() Date: Sun, 15 Mar 2026 17:11:04 +0000 Message-Id: <20260315171104.268944-8-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315171104.268944-1-objecting@objecting.org> References: <20260315171104.268944-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