Skip to contentSkip to conversation

fat: Add KUnit tests for checksums and timestamps

PATCH Superseded David Gow 2 participants 2 messages Oct 28, 2020 – Nov 4, 2020

Subsystems (2)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH v7 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 v6:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Make CONFIG_FAT_DEFAULT_CODEPAGE depend on FAT_FS, rather than either VFAT_FS or MSDOS_FS.
- This means that FAT_KUNIT_TEST can now also just depend of FAT_FS
- Fix a few warnings that KUnit tool was eating:
- KUnit's type checking needs a specific cast for the fat_checksum() expected results.
- The time test cases shouldn't be 'const'
- The fake superblock is now static, as otherwise it increased the stack size too much.

Changes since v4/5:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Fix a typo introduced in the Kconfig. It builds now.

Changes since v3:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Update the Kconfig entry to use "depends on" rather than "select", as discussed in [2].
- Depend on "MSDOS_FS || VFAT_FS", rather than "FAT_FS", as we need the CONFIG_FAT_DEFAULT_CODEPAGE symbol to be defined.

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.

[2]:
https://lore.kernel.org/linux-ext4/[email protected]/T/#t

 fs/fat/Kconfig    |  14 +++-
 fs/fat/Makefile   |   2 +
 fs/fat/fat_test.c | 196 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fat/misc.c     |   2 +
 4 files changed, 213 insertions(+), 1 deletion(-)
 create mode 100644 fs/fat/fat_test.c
fs/fat/Kconfig +13 -1
index 66532a71e8fd..238cc55f84c4 100644
@@ -77,7 +77,7 @@ config VFAT_FS
 
 config FAT_DEFAULT_CODEPAGE
 	int "Default codepage for FAT"
-	depends on MSDOS_FS || VFAT_FS
+	depends on FAT_FS
 	default 437
 	help
 	  This option should be set to the codepage of your FAT filesystems.
@@ -115,3 +115,15 @@ 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
+	depends on KUNIT && FAT_FS
+	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,
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
#1 lore raw
I love your patch! Perhaps something to improve:

Hi David,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.10-rc2 next-20201104]
[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]

url:    https://github.com/0day-ci/linux/commits/David-Gow/fat-Add-KUnit-tests-for-checksums-and-timestamps/20201029-062211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 23859ae44402f4d935b9ee548135dd1e65e2cbf4
config: parisc-randconfig-s031-20201104 (attached as .config)
compiler: hppa-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-76-gf680124b-dirty
# https://github.com/0day-ci/linux/commit/2703274109bdea879973719332569f6754dce440
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/20201029-062211 git checkout 2703274109bdea879973719332569f6754dce440
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=parisc

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

"sparse warnings: (new ones prefixed by >>)"
fs/fat/fat_test.c:38:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:38:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:38:25: sparse: got int
fs/fat/fat_test.c:45:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] time @@ got int @@
fs/fat/fat_test.c:45:25: sparse: expected restricted __le16 [usertype] time
fs/fat/fat_test.c:45:25: sparse: got int
fs/fat/fat_test.c:46:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:46:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:46:25: sparse: got int
fs/fat/fat_test.c:54:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:54:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:54:25: sparse: got int
fs/fat/fat_test.c:61:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] time @@ got int @@
fs/fat/fat_test.c:61:25: sparse: expected restricted __le16 [usertype] time
fs/fat/fat_test.c:61:25: sparse: got int
fs/fat/fat_test.c:62:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:62:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:62:25: sparse: got int
fs/fat/fat_test.c:70:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:70:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:70:25: sparse: got int
fs/fat/fat_test.c:78:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:78:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:78:25: sparse: got int
fs/fat/fat_test.c:86:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:86:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:86:25: sparse: got int
fs/fat/fat_test.c:93:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] time @@ got int @@
fs/fat/fat_test.c:93:25: sparse: expected restricted __le16 [usertype] time
fs/fat/fat_test.c:93:25: sparse: got int
fs/fat/fat_test.c:94:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:94:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:94:25: sparse: got int
fs/fat/fat_test.c:101:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] time @@ got int @@
fs/fat/fat_test.c:101:25: sparse: expected restricted __le16 [usertype] time
fs/fat/fat_test.c:101:25: sparse: got int
fs/fat/fat_test.c:102:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:102:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:102:25: sparse: got int
fs/fat/fat_test.c:109:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] time @@ got int @@
fs/fat/fat_test.c:109:25: sparse: expected restricted __le16 [usertype] time
fs/fat/fat_test.c:109:25: sparse: got int
fs/fat/fat_test.c:110:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:110:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:110:25: sparse: got int
fs/fat/fat_test.c:118:25: sparse: sparse: incorrect type in initializer (different base types) @@ expected restricted __le16 [usertype] date @@ got int @@
fs/fat/fat_test.c:118:25: sparse: expected restricted __le16 [usertype] date
fs/fat/fat_test.c:118:25: sparse: got int

>> fs/fat/fat_test.c:164:17: sparse: sparse: incorrect type in initializer (different base types) @@     expected long long left_value @@     got restricted __le16 __left @@
   fs/fat/fat_test.c:164:17: sparse:     expected long long left_value
>> fs/fat/fat_test.c:164:17: sparse:     got restricted __le16 __left

fs/fat/fat_test.c:164:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected long long right_value @@ got restricted __le16 __right @@
fs/fat/fat_test.c:164:17: sparse: expected long long right_value
fs/fat/fat_test.c:164:17: sparse: got restricted __le16 __right
fs/fat/fat_test.c:169:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected long long left_value @@ got restricted __le16 __left @@
fs/fat/fat_test.c:169:17: sparse: expected long long left_value
fs/fat/fat_test.c:169:17: sparse: got restricted __le16 __left
fs/fat/fat_test.c:169:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected long long right_value @@ got restricted __le16 __right @@
fs/fat/fat_test.c:169:17: sparse: expected long long right_value
fs/fat/fat_test.c:169:17: sparse: got restricted __le16 __right

vim +164 fs/fat/fat_test.c

150
151 static void fat_time_unix2fat_test(struct kunit *test)
152 {
153 static struct msdos_sb_info fake_sb;
154 int i;
155 __le16 date, time;
156 u8 cs;
157
158 for (i = 0; i < ARRAY_SIZE(time_test_cases); ++i) {
159 fake_sb.options.tz_set = 1;
160 fake_sb.options.time_offset = time_test_cases[i].time_offset;
161
162 fat_time_unix2fat(&fake_sb, &time_test_cases[i].ts,
163 &time, &date, &cs);

 > 164			KUNIT_EXPECT_EQ_MSG(test,
   165					    time_test_cases[i].time,
   166					    time,
   167					    "Time mismatch in case \"%s\"\n",
   168					    time_test_cases[i].name);
   169			KUNIT_EXPECT_EQ_MSG(test,
   170					    time_test_cases[i].date,
   171					    date,
   172					    "Date mismatch in case \"%s\"\n",
   173					    time_test_cases[i].name);
   174			KUNIT_EXPECT_EQ_MSG(test,
   175					    time_test_cases[i].cs,
   176					    cs,
   177					    "Centisecond mismatch in case \"%s\"\n",
   178					    time_test_cases[i].name);

179 }
180 }
181

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