Skip to contentSkip to conversation

fat: Add KUnit tests for checksums and timestamps

PATCH Superseded David Gow 2 participants 2 messages Oct 21, 2020 – Oct 22, 2020

Subsystems (2)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH v3 1/1 fat: Add KUnit tests for checksums and timestamps

Add some basic sanity-check tests for the fat_checksum() function and the fat_time_unix2fat() and fat_time_fat2unix() functions. These unit tests verify these functions return correct output for a number of test inputs.

These tests were inspored by -- and serve a similar purpose to -- the timestamp parsing KUnit tests in ext4[1].

Note that, unlike fat_time_unix2fat, fat_time_fat2unix wasn't previously exported, so this patch exports it as well. This is required for the case where we're building the fat and fat_test as modules.

[1]:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/ext4/inode-test.c

---

Changes since v2:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Comment that the export for fat_time_fat2unix() function is for KUnit tests.

Changes since v1:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Now export fat_time_fat2unix() so that the test can access it when built as a module.

Cheers,
-- David

 fs/fat/Kconfig    |  13 +++
 fs/fat/Makefile   |   2 +
 fs/fat/fat_test.c | 196 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fat/misc.c     |   2 +
 4 files changed, 213 insertions(+)
 create mode 100644 fs/fat/fat_test.c
fs/fat/Kconfig +13 -0
index 66532a71e8fd..fdef03b79c69 100644
@@ -115,3 +115,16 @@ config FAT_DEFAULT_UTF8
 	  Say Y if you use UTF-8 encoding for file names, N otherwise.
 
 	  See <file:Documentation/filesystems/vfat.rst> for more information.
+
+config FAT_KUNIT_TEST
+	tristate "Unit Tests for FAT filesystems" if !KUNIT_ALL_TESTS
+	select FAT_FS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the FAT KUnit tests
+
+	  For more information on KUnit and unit tests in general, please refer
+	  to the KUnit documentation in Documentation/dev-tools/kunit
+
+	  If unsure, say N
fs/fat/Makefile +2 -0
index 70645ce2f7fc..2b034112690d 100644
@@ -10,3 +10,5 @@ obj-$(CONFIG_MSDOS_FS) += msdos.o
 fat-y := cache.o dir.o fatent.o file.o inode.o misc.o nfs.o
 vfat-y := namei_vfat.o
 msdos-y := namei_msdos.o
+
+obj-$(CONFIG_FAT_KUNIT_TEST) += fat_test.o
fs/fat/fat_test.c new file +196 -0

196 lines not on this page · raw message

fs/fat/misc.c +2 -0
index f1b2a1fc2a6a..3eabd07b38e2 100644
@@ -229,6 +229,8 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
 		ts->tv_nsec = 0;
 	}
 }
+/* Export fat_time_fat2unix() for the fat_test KUnit tests. */
+EXPORT_SYMBOL_GPL(fat_time_fat2unix);
 
 /* Convert linear UNIX date to a FAT time/date pair. */
 void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,

base-commit: c4d6fe7311762f2e03b3c27ad38df7c40c80cc93

Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
#1 lore raw
I love your patch! Yet something to improve:

Hi David,

I love your patch! Yet something to improve:

[auto build test ERROR on c4d6fe7311762f2e03b3c27ad38df7c40c80cc93]

url:    https://github.com/0day-ci/linux/commits/David-Gow/fat-Add-KUnit-tests-for-checksums-and-timestamps/20201021-141819
base:    c4d6fe7311762f2e03b3c27ad38df7c40c80cc93
config: sparc64-randconfig-r034-20201022 (attached as .config)
compiler: sparc64-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/2395aa690e74265a3d09190ff5fc3628dcac9f09
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review David-Gow/fat-Add-KUnit-tests-for-checksums-and-timestamps/20201021-141819 git checkout 2395aa690e74265a3d09190ff5fc3628dcac9f09
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sparc64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> fs/fat/inode.c:64:35: error: 'CONFIG_FAT_DEFAULT_CODEPAGE' undeclared here (not in a function); did you mean 'CONFIG_FAT_DEFAULT_IOCHARSET'?
      64 | static int fat_default_codepage = CONFIG_FAT_DEFAULT_CODEPAGE;
         |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                   CONFIG_FAT_DEFAULT_IOCHARSET

vim +64 fs/fat/inode.c

190a8843ded231 Conrad Meyer 2014-06-06 63
^1da177e4c3f41 Linus Torvalds 2005-04-16 @64 static int fat_default_codepage = CONFIG_FAT_DEFAULT_CODEPAGE; ^1da177e4c3f41 Linus Torvalds 2005-04-16 65 static char fat_default_iocharset[] = CONFIG_FAT_DEFAULT_IOCHARSET; ^1da177e4c3f41 Linus Torvalds 2005-04-16 66

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org