Re: [PATCH v2] hfs: introduce KUnit tests for HFS string operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2025-09-12 at 11:28 +0800, black_desk wrote:
> On Fri, Sep 12, 2025 at 9:10 AM Viacheslav Dubeyko
> <slava@xxxxxxxxxxx> wrote:
> > 
> > This patch implements the initial Kunit based set of
> > unit tests for HFS string operations. It checks
> > functionality of hfs_strcmp(), hfs_hash_dentry(),
> > and hfs_compare_dentry() methods.
> > 
> > ./tools/testing/kunit/kunit.py run --kunitconfig
> > ./fs/hfs/.kunitconfig
> > 
> > [16:04:50] Configuring KUnit Kernel ...
> > Regenerating .config ...
> > Populating config with:
> > $ make ARCH=um O=.kunit olddefconfig
> > [16:04:51] Building KUnit Kernel ...
> > Populating config with:
> > $ make ARCH=um O=.kunit olddefconfig
> > Building with:
> > $ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --
> > jobs=22
> > [16:04:59] Starting KUnit Kernel (1/1)...
> > [16:04:59]
> > ============================================================
> > Running tests with:
> > $ .kunit/linux kunit.enable=1 mem=1G console=tty
> > kunit_shutdown=halt
> > [16:04:59] ================= hfs_string (3 subtests)
> > ==================
> > [16:04:59] [PASSED] hfs_strcmp_test
> > [16:04:59] [PASSED] hfs_hash_dentry_test
> > [16:04:59] [PASSED] hfs_compare_dentry_test
> > [16:04:59] =================== [PASSED] hfs_string
> > ====================
> > [16:04:59]
> > ============================================================
> > [16:04:59] Testing complete. Ran 3 tests: passed: 3
> > [16:04:59] Elapsed time: 9.087s total, 1.310s configuring, 7.611s
> > building, 0.125s running
> > 
> > v2
> > Fix linker error.
> > 
> > Signed-off-by: Viacheslav Dubeyko <slava@xxxxxxxxxxx>
> > cc: John Paul Adrian Glaubitz <glaubitz@xxxxxxxxxxxxxxxxxxx>
> > cc: Yangtao Li <frank.li@xxxxxxxx>
> > cc: linux-fsdevel@xxxxxxxxxxxxxxx
> > ---
> >  fs/hfs/.kunitconfig  |   7 +++
> >  fs/hfs/Kconfig       |  15 +++++
> >  fs/hfs/Makefile      |   2 +
> >  fs/hfs/string.c      |   3 +
> >  fs/hfs/string_test.c | 132
> > +++++++++++++++++++++++++++++++++++++++++++
> >  5 files changed, 159 insertions(+)
> >  create mode 100644 fs/hfs/.kunitconfig
> >  create mode 100644 fs/hfs/string_test.c
> > 
> > diff --git a/fs/hfs/.kunitconfig b/fs/hfs/.kunitconfig
> > new file mode 100644
> > index 000000000000..5caa9af1e3bb
> > --- /dev/null
> > +++ b/fs/hfs/.kunitconfig
> > @@ -0,0 +1,7 @@
> > +CONFIG_KUNIT=y
> > +CONFIG_HFS_FS=y
> > +CONFIG_HFS_KUNIT_TEST=y
> > +CONFIG_BLOCK=y
> > +CONFIG_BUFFER_HEAD=y
> > +CONFIG_NLS=y
> > +CONFIG_LEGACY_DIRECT_IO=y
> > diff --git a/fs/hfs/Kconfig b/fs/hfs/Kconfig
> > index 5ea5cd8ecea9..7f3cbe43b4b7 100644
> > --- a/fs/hfs/Kconfig
> > +++ b/fs/hfs/Kconfig
> > @@ -13,3 +13,18 @@ config HFS_FS
> > 
> >           To compile this file system support as a module, choose M
> > here: the
> >           module will be called hfs.
> > +
> > +config HFS_KUNIT_TEST
> > +       tristate "KUnit tests for HFS filesystem" if
> > !KUNIT_ALL_TESTS
> > +       depends on HFS_FS && KUNIT
> > +       default KUNIT_ALL_TESTS
> > +       help
> > +         This builds KUnit tests for the HFS filesystem.
> > +
> > +         KUnit tests run during boot and output the results to the
> > debug
> > +         log in TAP format (https://testanything.org/). Only
> > useful for
> > +         kernel devs running KUnit test harness and are not for
> > inclusion
> > +         into a production build.
> > +
> > +         For more information on KUnit and unit tests in general
> > please
> > +         refer to the KUnit documentation in Documentation/dev-
> > tools/kunit/.
> > diff --git a/fs/hfs/Makefile b/fs/hfs/Makefile
> > index b65459bf3dc4..a7c9ce6b4609 100644
> > --- a/fs/hfs/Makefile
> > +++ b/fs/hfs/Makefile
> > @@ -9,3 +9,5 @@ hfs-objs := bitmap.o bfind.o bnode.o brec.o btree.o
> > \
> >             catalog.o dir.o extent.o inode.o attr.o mdb.o \
> >              part_tbl.o string.o super.o sysdep.o trans.o
> > 
> > +# KUnit tests
> > +obj-$(CONFIG_HFS_KUNIT_TEST) += string_test.o
> > diff --git a/fs/hfs/string.c b/fs/hfs/string.c
> > index 3912209153a8..b011c1cbdf94 100644
> > --- a/fs/hfs/string.c
> > +++ b/fs/hfs/string.c
> > @@ -65,6 +65,7 @@ int hfs_hash_dentry(const struct dentry *dentry,
> > struct qstr *this)
> >         this->hash = end_name_hash(hash);
> >         return 0;
> >  }
> > +EXPORT_SYMBOL_GPL(hfs_hash_dentry);
> 
> It seems we should use EXPORT_SYMBOL_IF_KUNIT here?
> See
> https://docs.kernel.org/dev-tools/kunit/usage.html#testing-static-functions
> 

Yeah, you are right. I missed this. It will be much better to use
EXPORT_SYMBOL_IF_KUNIT. Let me rework the patch.

Thanks,
Slava.





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux