From: Gabriel Krisman Bertazi <krisman@suse.de>
To: Gabriela Bittencourt <gbittencourt@lkcamp.dev>
Cc: Gabriel Krisman Bertazi <krisman@kernel.org>,
David Gow <davidgow@google.com>,
Shuah Khan <skhan@linuxfoundation.org>,
linux-fsdevel@vger.kernel.org, ~lkcamp/patches@lists.sr.ht,
linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
porlando@lkcamp.dev, dpereira@lkcamp.dev
Subject: Re: [PATCH 1/2] unicode: kunit: refactor selftest to kunit tests
Date: Mon, 23 Sep 2024 15:39:05 -0400 [thread overview]
Message-ID: <87r09axiqu.fsf@mailhost.krisman.be> (raw)
In-Reply-To: <20240923173454.264852-2-gbittencourt@lkcamp.dev> (Gabriela Bittencourt's message of "Mon, 23 Sep 2024 14:34:53 -0300")
Gabriela Bittencourt <gbittencourt@lkcamp.dev> writes:
>
> -static ssize_t utf8len(const struct unicode_map *um, enum utf8_normalization n,
> - const char *s)
> +static ssize_t utf8len(const struct unicode_map *um, enum utf8_normalization n, const char *s)
> {
Please, do not make indentation-only changes, specially as part of a larger
change. It makes the patch much harder to review.
> return utf8nlen(um, n, s, (size_t)-1);
> }
>
> static int utf8cursor(struct utf8cursor *u8c, const struct unicode_map *um,
> - enum utf8_normalization n, const char *s)
> + enum utf8_normalization n, const char *s)
likewise.
> {
> return utf8ncursor(u8c, um, n, s, (unsigned int)-1);
> }
>
> -static void check_utf8_nfdi(struct unicode_map *um)
> +static void check_utf8_nfdi(struct kunit *test)
> {
> int i;
> struct utf8cursor u8c;
> + struct unicode_map *um = test->priv;
>
> for (i = 0; i < ARRAY_SIZE(nfdi_test_data); i++) {
> int len = strlen(nfdi_test_data[i].str);
> @@ -181,28 +161,29 @@ static void check_utf8_nfdi(struct unicode_map *um)
> int j = 0;
> unsigned char c;
>
> - test((utf8len(um, UTF8_NFDI, nfdi_test_data[i].str) == nlen));
> - test((utf8nlen(um, UTF8_NFDI, nfdi_test_data[i].str, len) ==
> - nlen));
> + KUNIT_EXPECT_EQ(test, utf8len(um, UTF8_NFDI, nfdi_test_data[i].str), nlen);
> + KUNIT_EXPECT_EQ(test, utf8nlen(um, UTF8_NFDI, nfdi_test_data[i].str, len),
> + nlen);
> - if (utf8cursor(&u8c, um, UTF8_NFDI, nfdi_test_data[i].str) < 0)
> - pr_err("can't create cursor\n");
> + KUNIT_EXPECT_GE_MSG(test, utf8cursor(&u8c, um, UTF8_NFDI, nfdi_test_data[i].str),
> + 0, "Can't create cursor\n");
These KUNIT_ macros are way less readable than the existing code,
IMO. the old macro makes it obvious what we are checking, without having
to dig into the definition. But, meh, I can live with it.
>
> while ((c = utf8byte(&u8c)) > 0) {
> - test_f((c == nfdi_test_data[i].dec[j]),
> - "Unexpected byte 0x%x should be 0x%x\n",
> - c, nfdi_test_data[i].dec[j]);
> + KUNIT_EXPECT_EQ_MSG(test, c, nfdi_test_data[i].dec[j],
> + "Unexpected byte 0x%x should be 0x%x\n",
> + c, nfdi_test_data[i].dec[j]);
> j++;
> }
>
> - test((j == nlen));
> + KUNIT_EXPECT_EQ(test, j, nlen);
> }
> }
>
> -static void check_utf8_nfdicf(struct unicode_map *um)
> +static void check_utf8_nfdicf(struct kunit *test)
> {
> int i;
> struct utf8cursor u8c;
> + struct unicode_map *um = test->priv;
>
> for (i = 0; i < ARRAY_SIZE(nfdicf_test_data); i++) {
> int len = strlen(nfdicf_test_data[i].str);
> @@ -210,29 +191,30 @@ static void check_utf8_nfdicf(struct unicode_map *um)
> int j = 0;
> unsigned char c;
>
> - test((utf8len(um, UTF8_NFDICF, nfdicf_test_data[i].str) ==
> - nlen));
> - test((utf8nlen(um, UTF8_NFDICF, nfdicf_test_data[i].str, len) ==
> - nlen));
> + KUNIT_EXPECT_EQ(test, utf8len(um, UTF8_NFDICF, nfdicf_test_data[i].str),
> + nlen);
> + KUNIT_EXPECT_EQ(test, utf8nlen(um, UTF8_NFDICF, nfdicf_test_data[i].str, len),
> + nlen);
>
> - if (utf8cursor(&u8c, um, UTF8_NFDICF,
> - nfdicf_test_data[i].str) < 0)
> - pr_err("can't create cursor\n");
> + KUNIT_EXPECT_GE_MSG(test,
> + utf8cursor(&u8c, um, UTF8_NFDICF, nfdicf_test_data[i].str),
> + 0, "Can't create cursor\n");
>
> while ((c = utf8byte(&u8c)) > 0) {
> - test_f((c == nfdicf_test_data[i].ncf[j]),
> - "Unexpected byte 0x%x should be 0x%x\n",
> - c, nfdicf_test_data[i].ncf[j]);
> + KUNIT_EXPECT_EQ_MSG(test, c, nfdicf_test_data[i].ncf[j],
> + "Unexpected byte 0x%x should be 0x%x\n",
> + c, nfdicf_test_data[i].ncf[j]);
> j++;
> }
>
> - test((j == nlen));
> + KUNIT_EXPECT_EQ(test, j, nlen);
> }
> }
>
> -static void check_utf8_comparisons(struct unicode_map *table)
> +static void check_utf8_comparisons(struct kunit *test)
> {
> int i;
> + struct unicode_map *um = test->priv;
>
> for (i = 0; i < ARRAY_SIZE(nfdi_test_data); i++) {
> const struct qstr s1 = {.name = nfdi_test_data[i].str,
> @@ -240,8 +222,9 @@ static void check_utf8_comparisons(struct unicode_map *table)
> const struct qstr s2 = {.name = nfdi_test_data[i].dec,
> .len = sizeof(nfdi_test_data[i].dec)};
>
> - test_f(!utf8_strncmp(table, &s1, &s2),
> - "%s %s comparison mismatch\n", s1.name, s2.name);
> + // strncmp returns 0 when strings are equal
We don't do comments with // in the kernel (aside from SPDX). Please, use /* */.
> + KUNIT_EXPECT_EQ_MSG(test, utf8_strncmp(um, &s1, &s2), 0,
> + "%s %s comparison mismatch\n", s1.name, s2.name);
Yuck. This is even less readable. Is there a kunit macro that receives
an expression, similar to WARN_ON/BUG_ON? It would be way more readable.
Something like this.
KUNIT_BLA(test, utf8_strncmp(um, &s1,&s2) == 0, "BAD TEST!")
--
Gabriel Krisman Bertazi
next prev parent reply other threads:[~2024-09-23 19:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-23 17:34 [PATCH 0/2] unicode: kunit: refactor selftest to kunit tests Gabriela Bittencourt
2024-09-23 17:34 ` [PATCH 1/2] " Gabriela Bittencourt
2024-09-23 19:18 ` Shuah Khan
2024-09-23 19:39 ` Gabriel Krisman Bertazi [this message]
2024-09-24 21:30 ` André Almeida
2024-09-24 21:40 ` Gabriel Krisman Bertazi
2024-09-24 22:16 ` André Almeida
2024-09-23 17:34 ` [PATCH 2/2] unicode: kunit: change tests filename and path Gabriela Bittencourt
2024-09-23 19:19 ` Shuah Khan
-- strict thread matches above, loose matches on Subject: below --
2024-09-22 20:16 [PATCH 0/2] unicode: kunit: refactor selftest to kunit tests Gabriela Bittencourt
2024-09-22 20:16 ` [PATCH 1/2] " Gabriela Bittencourt
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=87r09axiqu.fsf@mailhost.krisman.be \
--to=krisman@suse.de \
--cc=davidgow@google.com \
--cc=dpereira@lkcamp.dev \
--cc=gbittencourt@lkcamp.dev \
--cc=krisman@kernel.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=porlando@lkcamp.dev \
--cc=skhan@linuxfoundation.org \
--cc=~lkcamp/patches@lists.sr.ht \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox