Skip to contentSkip to conversation

fat: Add KUnit tests for checksums and timestamps

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

Subsystems (2)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH v2 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 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.

 fs/fat/Kconfig    |  13 +++
 fs/fat/Makefile   |   2 +
 fs/fat/fat_test.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fat/misc.c     |   1 +
 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 +197 -0

197 lines not on this page · raw message

fs/fat/misc.c +1 -0
index f1b2a1fc2a6a..445ad3542e74 100644
@@ -229,6 +229,7 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
 		ts->tv_nsec = 0;
 	}
 }
+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,
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
maintainer
#1 lore raw

fs/fat/misc.c void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts, · line 232

Quoted 9 lines · David Gow
fs/fat/misc.c +1 -0
index f1b2a1fc2a6a..445ad3542e74 100644
@@ -229,6 +229,7 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
 		ts->tv_nsec = 0;
 	}
 }
+EXPORT_SYMBOL_GPL(fat_time_fat2unix);

Hm, can this export only if FAT_KUNIT_TEST is builtin or module (maybe #if IS_ENABLED(...))? And #if will also be worked as the comment too.

Quoted 3 lines
fs/fat/misc.c +0 -0
 /* Convert linear UNIX date to a FAT time/date pair. */
 void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,
Signature · 1 line
OGAWA Hirofumi <[email protected]>
author
#2 lore raw
Quoted 16 lines · OGAWA Hirofumi

fs/fat/misc.c void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts, · line 232

Quoted 9 lines · David Gow
fs/fat/misc.c +1 -0
index f1b2a1fc2a6a..445ad3542e74 100644
@@ -229,6 +229,7 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
              ts->tv_nsec = 0;
      }
 }
+EXPORT_SYMBOL_GPL(fat_time_fat2unix);

Hm, can this export only if FAT_KUNIT_TEST is builtin or module (maybe #if IS_ENABLED(...))? And #if will also be worked as the comment too.

That's possible, but I'd prefer to export it unconditionally for two reasons:
1. It'd make it possible to build the fat_test module without having to rebuild the whole kernel/fat.
2. It'd be consistent with fat_time_unix2fat(), which is exported for use in vfat/msdos anyway.

Neither of those are dealbreakers, though, so if you'd still prefer this to be behind an ifdef, I'll change it.

-- David

maintainer
#3 lore raw
Quoted 4 lines · David Gow
Quoted 3 lines

Hm, can this export only if FAT_KUNIT_TEST is builtin or module (maybe #if IS_ENABLED(...))? And #if will also be worked as the comment too.

Quoted 8 lines

That's possible, but I'd prefer to export it unconditionally for two reasons:
1. It'd make it possible to build the fat_test module without having to rebuild the whole kernel/fat.
2. It'd be consistent with fat_time_unix2fat(), which is exported for use in vfat/msdos anyway.

Neither of those are dealbreakers, though, so if you'd still prefer this to be behind an ifdef, I'll change it.

OK. If nobody complain, let's export. However, then, can you add the comment instead of ifdef to mark for kunit?

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>