ext4: add kunit test for decoding extended timestamps
Subsystems (2)
PATCH v4 1/1 ext4: add kunit test for decoding extended timestamps
KUnit tests for decoding extended 64 bit timestamps
that verify the seconds part of [a/c/m]
timestamps in ext4 inode structs are decoded correctly. KUnit tests, which run on boot and output
the results to the debug log in TAP format (http://testanything.org/).
are only useful for kernel devs running KUnit test harness. Not for inclusion into a production build.
Test data is derive from the table under Documentation/filesystems/ext4/inodes.rst Inode Timestamps.
--- fs/ext4/Kconfig | 14 +++ fs/ext4/Makefile | 1 + fs/ext4/inode-test.c | 239 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 fs/ext4/inode-test.c
fs/ext4/Kconfig +14 -0
@@ -106,3 +106,17 @@ config EXT4_DEBUG If you select Y here, then you will be able to turn on debugging with a command such as: echo 1 > /sys/module/ext4/parameters/mballoc_debug + +config EXT4_KUNIT_TESTS + bool "KUnit tests for ext4" + select EXT4_FS + depends on KUNIT + help + This builds the ext4 KUnit tests, which run on boot and output + the results to the debug log in TAP format (http://testanything.org/). + Only useful for kernel devs running KUnit test harness. 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/. + + If unsure, say N.
fs/ext4/Makefile +1 -0
@@ -13,4 +13,5 @@ ext4-y := balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \ ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o +ext4-$(CONFIG_EXT4_KUNIT_TESTS) += inode-test.o ext4-$(CONFIG_FS_VERITY) += verity.o
fs/ext4/inode-test.c new file +239 -0
239 lines not on this page · raw message
--
2.23.0.700.g56cf767bdb-goog
Quoted 8 lines · Iurii Zaikin
KUnit tests for decoding extended 64 bit timestamps
that verify the seconds part of [a/c/m]
timestamps in ext4 inode structs are decoded correctly. KUnit tests, which run on boot and output
the results to the debug log in TAP format (http://testanything.org/).
are only useful for kernel devs running KUnit test harness. Not for inclusion into a production build.
Test data is derive from the table under
nit: ^ Should be: derived from ...
Quoted 3 lines
Documentation/filesystems/ext4/inodes.rstInode Timestamps.Signed-off-by Iurii Zaikin <[email protected]>
Quoted 7 lines
--- fs/ext4/Kconfig | 14 +++ fs/ext4/Makefile | 1 + fs/ext4/inode-test.c | 239 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 fs/ext4/inode-test.c
[...]
Quoted 54 lines
fs/ext4/inode-test.c new file +48
-0@@ -0,0 +1,239 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* KUnit test of ext4 inode that verify the seconds part of [a/c/m] +* timestamps in ext4 inode structs are decoded correctly. +*/ + +#include <kunit/test.h> +#include <linux/kernel.h> +#include <linux/time64.h> + +#include "ext4.h" + +/* binary: 00000000 00000000 00000000 00000000 */ +#define LOWER_MSB_0 0L +/* binary: 01111111 11111111 11111111 11111111 */ +#define UPPER_MSB_0 0x7fffffffL +/* binary: 10000000 00000000 00000000 00000000 */ +#define LOWER_MSB_1 (-0x80000000L) +/* binary: 11111111 11111111 11111111 11111111 */ +#define UPPER_MSB_1 (-1L) +/* binary: 00111111 11111111 11111111 11111111 */ +#define MAX_NANOSECONDS ((1L << 30) - 1) + +#define CASE_NAME_FORMAT "%s: msb:%x lower_bound:%x extra_bits: %x" + +struct timestamp_expectation { +const char *test_case_name; +struct timespec64 expected; +u32 extra_bits; +bool msb_set; +bool lower_bound; +}; + +static time64_t get_32bit_time (const struct timestamp_expectation *const test) +{ +if (test->msb_set) { +if (test->lower_bound) +return LOWER_MSB_1 ; + +return UPPER_MSB_1 ; + } + +if (test->lower_bound) +return LOWER_MSB_0 ; +return UPPER_MSB_0 ; +} + +
fs/ext4/inode-test.c line 58
Quoted 10 lines
fs/ext4/inode-test.c new file +10
-0+/* +* These tests are derived from the table under +* Documentation/filesystems/ext4/inodes.rst Inode Timestamps +*/ +static void inode_test_xtimestamp_decoding (struct kunit *test) +{ +const struct timestamp_expectation test_data[] = { + { + .test_case_name = +"1901-12-13 Lower bound of 32bit < 0 timestamp, no extra bits." ,
nit: Maybe drop the period at the end (here and elsewhere)? Otherwise if the test fails you have a period right next to a colon and it looks a bit off.
fs/ext4/inode-test.c line 63
Quoted 5 lines
fs/ext4/inode-test.c new file +5
-0+ .msb_set = true, + .lower_bound = true, + .extra_bits = 0, + .expected = {.tv_sec = -0x80000000LL, .tv_nsec = 0L}, + },
Feel free to ignore my nits if you don't need to send another version. Also note that Ted has given a Reviewed-by on an earlier revision.
Thanks!
Quoted 10 lines · Brendan Higgins
Quoted 8 lines · Iurii Zaikin
KUnit tests for decoding extended 64 bit timestamps
that verify the seconds part of [a/c/m]
timestamps in ext4 inode structs are decoded correctly. KUnit tests, which run on boot and output
the results to the debug log in TAP format (http://testanything.org/).
are only useful for kernel devs running KUnit test harness. Not for inclusion into a production build.
Test data is derive from the table under
Quoted 3 lines
nit: ^ Should be: derived from ...
Oops. Done.
Quoted 75 lines
Quoted 3 lines
Documentation/filesystems/ext4/inodes.rstInode Timestamps.Signed-off-by Iurii Zaikin <[email protected]>Reviewed-by Brendan Higgins <[email protected]>Tested-by Brendan Higgins <[email protected]>Quoted 7 lines
--- fs/ext4/Kconfig | 14 +++ fs/ext4/Makefile | 1 + fs/ext4/inode-test.c | 239 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 fs/ext4/inode-test.c[...]
Quoted 60 lines
fs/ext4/inode-test.c new file +54
-0@@ -0,0 +1,239 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* KUnit test of ext4 inode that verify the seconds part of [a/c/m] +* timestamps in ext4 inode structs are decoded correctly. +*/ + +#include <kunit/test.h> +#include <linux/kernel.h> +#include <linux/time64.h> + +#include "ext4.h" + +/* binary: 00000000 00000000 00000000 00000000 */ +#define LOWER_MSB_0 0L +/* binary: 01111111 11111111 11111111 11111111 */ +#define UPPER_MSB_0 0x7fffffffL +/* binary: 10000000 00000000 00000000 00000000 */ +#define LOWER_MSB_1 (-0x80000000L) +/* binary: 11111111 11111111 11111111 11111111 */ +#define UPPER_MSB_1 (-1L) +/* binary: 00111111 11111111 11111111 11111111 */ +#define MAX_NANOSECONDS ((1L << 30) - 1) + +#define CASE_NAME_FORMAT "%s: msb:%x lower_bound:%x extra_bits: %x" + +struct timestamp_expectation { +const char *test_case_name; +struct timespec64 expected; +u32 extra_bits; +bool msb_set; +bool lower_bound; +}; + +static time64_t get_32bit_time (const struct timestamp_expectation *const test) +{ +if (test->msb_set) { +if (test->lower_bound) +return LOWER_MSB_1 ; + +return UPPER_MSB_1 ; + } + +if (test->lower_bound) +return LOWER_MSB_0 ; +return UPPER_MSB_0 ; +} + + +/* +* These tests are derived from the table under +* Documentation/filesystems/ext4/inodes.rst Inode Timestamps +*/ +static void inode_test_xtimestamp_decoding (struct kunit *test) +{
Quoted 9 lines
fs/ext4/inode-test.c line 58
Quoted 4 lines
fs/ext4/inode-test.c new file +4
-0+const struct timestamp_expectation test_data[] = { + { + .test_case_name = +"1901-12-13 Lower bound of 32bit < 0 timestamp, no extra bits." ,nit: Maybe drop the period at the end (here and elsewhere)? Otherwise if the test fails you have a period right next to a colon and it looks a bit off.
Done
Quoted 10 lines
fs/ext4/inode-test.c line 63
Quoted 5 lines
fs/ext4/inode-test.c new file +5
-0+ .msb_set = true, + .lower_bound = true, + .extra_bits = 0, + .expected = {.tv_sec = -0x80000000LL, .tv_nsec = 0L}, + },Feel free to ignore my nits if you don't need to send another version. Also note that Ted has given a Reviewed-by on an earlier revision.
Thanks!