From: Shuah Khan <skhan@linuxfoundation.org>
To: Gabriela Bittencourt <gbittencourt@lkcamp.dev>,
Gabriel Krisman Bertazi <krisman@kernel.org>,
David Gow <davidgow@google.com>,
linux-fsdevel@vger.kernel.org, ~lkcamp/patches@lists.sr.ht
Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
porlando@lkcamp.dev, dpereira@lkcamp.dev,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH 1/2] unicode: kunit: refactor selftest to kunit tests
Date: Mon, 23 Sep 2024 13:18:05 -0600 [thread overview]
Message-ID: <06f56247-d2fb-4038-9593-7717a4e7796b@linuxfoundation.org> (raw)
In-Reply-To: <20240923173454.264852-2-gbittencourt@lkcamp.dev>
On 9/23/24 11:34, Gabriela Bittencourt wrote:
> Instead of creating 'test' functions, use kunit functions to test
> utf-8 support in unicode subsystem.
Can you elaborate on the reefactoring changes. This will help
others who would want to take on such refactoring in the future.
>
> Co-developed-by: Pedro Orlando <porlando@lkcamp.dev>
> Signed-off-by: Pedro Orlando <porlando@lkcamp.dev>
> Co-developed-by: Danilo Pereira <dpereira@lkcamp.dev>
> Signed-off-by: Danilo Pereira <dpereira@lkcamp.dev>
> Signed-off-by: Gabriela Bittencourt <gbittencourt@lkcamp.dev>
> ---
> fs/unicode/.kunitconfig | 3 +
> fs/unicode/Kconfig | 5 +-
> fs/unicode/Makefile | 2 +-
> fs/unicode/utf8-selftest.c | 152 +++++++++++++++++--------------------
> 4 files changed, 76 insertions(+), 86 deletions(-)
> create mode 100644 fs/unicode/.kunitconfig
>
> diff --git a/fs/unicode/.kunitconfig b/fs/unicode/.kunitconfig
> new file mode 100644
> index 000000000000..62dd5c171f9c
> --- /dev/null
> +++ b/fs/unicode/.kunitconfig
> @@ -0,0 +1,3 @@
> +CONFIG_KUNIT=y
> +CONFIG_UNICODE=y
> +CONFIG_UNICODE_NORMALIZATION_KUNIT_TEST=y
> diff --git a/fs/unicode/Kconfig b/fs/unicode/Kconfig
> index da786a687fdc..4ad2c36550f1 100644
> --- a/fs/unicode/Kconfig
> +++ b/fs/unicode/Kconfig
> @@ -10,6 +10,7 @@ config UNICODE
> be a separate loadable module that gets requested only when a file
> system actually use it.
>
> -config UNICODE_NORMALIZATION_SELFTEST
> +config UNICODE_NORMALIZATION_KUNIT_TEST
> tristate "Test UTF-8 normalization support"
> - depends on UNICODE
> + depends on UNICODE && KUNIT
> + default KUNIT_ALL_TESTS
> diff --git a/fs/unicode/Makefile b/fs/unicode/Makefile
> index e309afe2b2bb..37bbcbc628a1 100644
> --- a/fs/unicode/Makefile
> +++ b/fs/unicode/Makefile
> @@ -4,7 +4,7 @@ ifneq ($(CONFIG_UNICODE),)
> obj-y += unicode.o
> endif
> obj-$(CONFIG_UNICODE) += utf8data.o
> -obj-$(CONFIG_UNICODE_NORMALIZATION_SELFTEST) += utf8-selftest.o
> +obj-$(CONFIG_UNICODE_NORMALIZATION_KUNIT_TEST) += utf8-selftest.o
>
> unicode-y := utf8-norm.o utf8-core.o
>
> diff --git a/fs/unicode/utf8-selftest.c b/fs/unicode/utf8-selftest.c
> index 600e15efe9ed..54ded8db6b1c 100644
> --- a/fs/unicode/utf8-selftest.c
> +++ b/fs/unicode/utf8-selftest.c
> @@ -1,38 +1,18 @@
> // SPDX-License-Identifier: GPL-2.0-only
> /*
> - * Kernel module for testing utf-8 support.
> + * KUnit tests for utf-8 support
> *
> * Copyright 2017 Collabora Ltd.
> */
>
> -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> -
> -#include <linux/module.h>
> -#include <linux/printk.h>
> #include <linux/unicode.h>
> -#include <linux/dcache.h>
> +#include <kunit/test.h>
>
> #include "utf8n.h"
>
> -static unsigned int failed_tests;
> -static unsigned int total_tests;
> -
> /* Tests will be based on this version. */
> #define UTF8_LATEST UNICODE_AGE(12, 1, 0)
>
> -#define _test(cond, func, line, fmt, ...) do { \
> - total_tests++; \
> - if (!cond) { \
> - failed_tests++; \
> - pr_err("test %s:%d Failed: %s%s", \
> - func, line, #cond, (fmt?":":".")); \
> - if (fmt) \
> - pr_err(fmt, ##__VA_ARGS__); \
> - } \
> - } while (0)
> -#define test_f(cond, fmt, ...) _test(cond, __func__, __LINE__, fmt, ##__VA_ARGS__)
> -#define test(cond) _test(cond, __func__, __LINE__, "")
> -
> static const struct {
> /* UTF-8 strings in this vector _must_ be NULL-terminated. */
> unsigned char str[10];
> @@ -158,22 +138,22 @@ static const struct {
> }
> };
>
> -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)
Keep "const char *s" on the second line.
> {
> return utf8nlen(um, n, s, (size_t)-1);
> }
>
Rest looks good to me.
thanks,
-- Shuah
next prev parent reply other threads:[~2024-09-23 19:18 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 [this message]
2024-09-23 19:39 ` Gabriel Krisman Bertazi
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=06f56247-d2fb-4038-9593-7717a4e7796b@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--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=~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