* [PATCH] xfs: convert the dahash test to KUnit
@ 2026-11-12 4:16 Wang Yibo
2026-11-12 19:17 ` kernel test robot
0 siblings, 1 reply; 2+ messages in thread
From: Wang Yibo @ 2026-11-12 4:16 UTC (permalink / raw)
To: arlos Maiolino; +Cc: linux-kernel, linux-xfs
xfs_dahash_test() runs from init_xfs_fs() and only counts mismatches: a
failure prints a single total, which says nothing about which test
vector or which of the two hash functions was wrong, and the test can
only be exercised by building XFS into the kernel and watching the
console at boot.
Report the vectors through KUnit instead. Split them into one case per
hash function so that a failure names both the function and the vector
index, and KUnit prints the expected and actual values next to it. The
results then come out in TAP format, so the suite can be run with
kunit.py or under QEMU without rebooting the machine, and every case is
reported on its own.
Put the test behind CONFIG_XFS_DAHASH_KUNIT_TEST so that it is no
longer built into every kernel, and drop the now unused header. The
vector table and test_buf can no longer live in __initdata, because
KUnit keeps the data around for the lifetime of the suite; mark them
const since nothing writes to them.
No change to the hash functions themselves.
Signed-off-by: Wang Yibo <wangyibo@kylinos.cn>
---
fs/xfs/Kconfig | 14 +++++++++
fs/xfs/Makefile | 2 +-
fs/xfs/xfs_dahash_test.c | 64 ++++++++++++++++++++++++----------------
fs/xfs/xfs_dahash_test.h | 12 --------
fs/xfs/xfs_super.c | 5 ----
5 files changed, 54 insertions(+), 43 deletions(-)
delete mode 100644 fs/xfs/xfs_dahash_test.h
diff --git a/fs/xfs/Kconfig b/fs/xfs/Kconfig
index b99da294e9a3..5b36adea933b 100644
--- a/fs/xfs/Kconfig
+++ b/fs/xfs/Kconfig
@@ -241,3 +241,17 @@ config XFS_ASSERT_FATAL
result in warnings.
This behavior can be modified at runtime via sysfs.
+
+config XFS_DAHASH_KUNIT_TEST
+ bool "KUnit tests for XFS dir/attr name hashes" if !KUNIT_ALL_TESTS
+ depends on XFS_FS && KUNIT
+ default KUNIT_ALL_TESTS
+ help
+ This builds the XFS directory and attribute name hash KUnit test.
+
+ KUnit tests run during boot (or module load) and output the results
+ to the debug log in TAP format (https://testanything.org/). Only
+ useful for kernel devs running the KUnit test harness and are not
+ for inclusion into a production build.
+
+ If unsure, say N.
diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 399a207f2d0e..c95a57c5ca98 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -74,7 +74,6 @@ xfs-y += xfs_aops.o \
xfs_bmap_util.o \
xfs_bio_io.o \
xfs_buf.o \
- xfs_dahash_test.o \
xfs_dir2_readdir.o \
xfs_discard.o \
xfs_error.o \
@@ -160,6 +159,7 @@ xfs-$(CONFIG_XFS_DRAIN_INTENTS) += xfs_drain.o
xfs-$(CONFIG_XFS_LIVE_HOOKS) += xfs_hooks.o
xfs-$(CONFIG_XFS_MEMORY_BUFS) += xfs_buf_mem.o
xfs-$(CONFIG_XFS_BTREE_IN_MEM) += libxfs/xfs_btree_mem.o
+xfs-$(CONFIG_XFS_DAHASH_KUNIT_TEST) += xfs_dahash_test.o
# online scrub/repair
ifeq ($(CONFIG_XFS_ONLINE_SCRUB),y)
diff --git a/fs/xfs/xfs_dahash_test.c b/fs/xfs/xfs_dahash_test.c
index f1ee2643b948..4c7d7e12f1ba 100644
--- a/fs/xfs/xfs_dahash_test.c
+++ b/fs/xfs/xfs_dahash_test.c
@@ -1,8 +1,11 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
+ * KUnit tests for XFS dir/attr name hash functions.
+ *
* Copyright (C) 2023 Oracle. All Rights Reserved.
* Author: Darrick J. Wong <djwong@kernel.org>
*/
+#include <kunit/test.h>
#include "xfs_platform.h"
#include "xfs_fs.h"
#include "xfs_shared.h"
@@ -12,10 +15,9 @@
#include "xfs_trans_resv.h"
#include "xfs_mount.h"
#include "xfs_dir2_priv.h"
-#include "xfs_dahash_test.h"
/* 4096 random bytes */
-static uint8_t __initdata __attribute__((__aligned__(8))) test_buf[] =
+static const uint8_t test_buf[] __aligned(8) =
{
0x5b, 0x85, 0x21, 0xcb, 0x09, 0x68, 0x7d, 0x30,
0xc7, 0x69, 0xd7, 0x30, 0x92, 0xde, 0x59, 0xe4,
@@ -532,12 +534,12 @@ static uint8_t __initdata __attribute__((__aligned__(8))) test_buf[] =
};
/* 100 test cases */
-static struct dahash_test {
+static const struct dahash_test {
uint16_t start; /* random 12 bit offset in buf */
uint16_t length; /* random 8 bit length of test */
xfs_dahash_t dahash; /* expected dahash result */
xfs_dahash_t ascii_ci_dahash; /* expected ascii-ci dahash result */
-} test[] __initdata =
+} dahash_test_vecs[] =
{
{0x0567, 0x0097, 0x96951389, 0xc153aa0d},
{0x0869, 0x0055, 0x6455ab4f, 0xd07f69bf},
@@ -641,33 +643,45 @@ static struct dahash_test {
{0x05b5, 0x00da, 0x8e52f0e2, 0x98531012},
};
-int __init
-xfs_dahash_test(void)
+static void xfs_da_hashname_case(struct kunit *test)
{
unsigned int i;
- unsigned int errors = 0;
- for (i = 0; i < ARRAY_SIZE(test); i++) {
- struct xfs_name xname = { };
- xfs_dahash_t hash;
+ for (i = 0; i < ARRAY_SIZE(dahash_test_vecs); i++) {
+ const struct dahash_test *tv = &dahash_test_vecs[i];
+ xfs_dahash_t hash;
- hash = xfs_da_hashname(test_buf + test[i].start,
- test[i].length);
- if (hash != test[i].dahash)
- errors++;
+ hash = xfs_da_hashname(test_buf + tv->start, tv->length);
+ KUNIT_EXPECT_EQ_MSG(test, hash, tv->dahash, "case %u", i);
+ }
+}
+
+static void xfs_ascii_ci_hashname_case(struct kunit *test)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(dahash_test_vecs); i++) {
+ const struct dahash_test *tv = &dahash_test_vecs[i];
+ struct xfs_name xname = { };
+ xfs_dahash_t hash;
- xname.name = test_buf + test[i].start;
- xname.len = test[i].length;
+ xname.name = test_buf + tv->start;
+ xname.len = tv->length;
hash = xfs_ascii_ci_hashname(&xname);
- if (hash != test[i].ascii_ci_dahash)
- errors++;
+ KUNIT_EXPECT_EQ_MSG(test, hash, tv->ascii_ci_dahash,
+ "case %u", i);
}
+}
- if (errors) {
- printk(KERN_ERR "xfs dir/attr hash test failed %u times!",
- errors);
- return -ERANGE;
- }
+static struct kunit_case xfs_dahash_test_cases[] = {
+ KUNIT_CASE(xfs_da_hashname_case),
+ KUNIT_CASE(xfs_ascii_ci_hashname_case),
+ {}
+};
- return 0;
-}
+static struct kunit_suite xfs_dahash_test_suite = {
+ .name = "xfs_dahash",
+ .test_cases = xfs_dahash_test_cases,
+};
+
+kunit_test_suites(&xfs_dahash_test_suite);
diff --git a/fs/xfs/xfs_dahash_test.h b/fs/xfs/xfs_dahash_test.h
deleted file mode 100644
index 1a05bf4bd9e1..000000000000
--- a/fs/xfs/xfs_dahash_test.h
+++ /dev/null
@@ -1,12 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (C) 2023 Oracle. All Rights Reserved.
- * Author: Darrick J. Wong <djwong@kernel.org>
- */
-#ifndef __XFS_DAHASH_TEST_H__
-#define __XFS_DAHASH_TEST_H__
-
-int xfs_dahash_test(void);
-
-#endif /* __XFS_DAHASH_TEST_H__ */
-
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 5a06132aa384..75bc05801e4a 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -43,7 +43,6 @@
#include "xfs_error.h"
#include "xfs_errortag.h"
#include "xfs_iunlink_item.h"
-#include "xfs_dahash_test.h"
#include "xfs_rtbitmap.h"
#include "xfs_exchmaps_item.h"
#include "xfs_parent.h"
@@ -2647,10 +2646,6 @@ init_xfs_fs(void)
xfs_check_ondisk_structs();
- error = xfs_dahash_test();
- if (error)
- return error;
-
printk(KERN_INFO XFS_VERSION_STRING " with "
XFS_BUILD_OPTIONS " enabled\n");
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] xfs: convert the dahash test to KUnit
2026-11-12 4:16 [PATCH] xfs: convert the dahash test to KUnit Wang Yibo
@ 2026-11-12 19:17 ` kernel test robot
0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2026-11-12 19:17 UTC (permalink / raw)
To: Wang Yibo, arlos Maiolino; +Cc: oe-kbuild-all, linux-kernel, linux-xfs
Hi Wang,
kernel test robot noticed the following build errors:
[auto build test ERROR on xfs-linux/for-next]
[also build test ERROR on linus/master v7.4-rc2 next-20261111]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Wang-Yibo/xfs-convert-the-dahash-test-to-KUnit/20261112-121631
base: https://git.kernel.org/pub/scm/fs/xfs/xfs-linux.git for-next
patch link: https://lore.kernel.org/r/20261112041631.2792545-1-wangyibo%40kylinos.cn
patch subject: [PATCH] xfs: convert the dahash test to KUnit
config: i386-randconfig-1012-20261112 (https://download.01.org/0day-ci/archive/20261113/202611130302.dGXAb4Py-lkp@intel.com/config)
compiler: gcc-13 (Debian 13.3.0-16) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261113/202611130302.dGXAb4Py-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202611130302.dGXAb4Py-lkp@intel.com/
All errors (new ones prefixed by >>):
ld: fs/xfs/xfs_dahash_test.o: in function `xfs_ascii_ci_hashname_case':
>> fs/xfs/xfs_dahash_test.c:671:(.text+0x88): undefined reference to `kunit_binary_assert_format'
>> ld: fs/xfs/xfs_dahash_test.c:671:(.text+0xc0): undefined reference to `__kunit_do_failed_assertion'
ld: fs/xfs/xfs_dahash_test.o: in function `xfs_da_hashname_case':
fs/xfs/xfs_dahash_test.c:655:(.text+0x178): undefined reference to `kunit_binary_assert_format'
ld: fs/xfs/xfs_dahash_test.c:655:(.text+0x1b0): undefined reference to `__kunit_do_failed_assertion'
vim +671 fs/xfs/xfs_dahash_test.c
658
659 static void xfs_ascii_ci_hashname_case(struct kunit *test)
660 {
661 unsigned int i;
662
663 for (i = 0; i < ARRAY_SIZE(dahash_test_vecs); i++) {
664 const struct dahash_test *tv = &dahash_test_vecs[i];
665 struct xfs_name xname = { };
666 xfs_dahash_t hash;
667
668 xname.name = test_buf + tv->start;
669 xname.len = tv->length;
670 hash = xfs_ascii_ci_hashname(&xname);
> 671 KUNIT_EXPECT_EQ_MSG(test, hash, tv->ascii_ci_dahash,
672 "case %u", i);
673 }
674 }
675
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-12 19:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 4:16 [PATCH] xfs: convert the dahash test to KUnit Wang Yibo
2026-11-12 19:17 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox