Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * KUnit test of ext4 inode that verify the seconds part of [a/c/m]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * timestamps in ext4 inode structs are decoded correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <kunit/test.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/time64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "ext4.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * For constructing the nonnegative timestamp lower bound value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * binary: 00000000 00000000 00000000 00000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define LOWER_MSB_0 0L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * For constructing the nonnegative timestamp upper bound value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * binary: 01111111 11111111 11111111 11111111
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define UPPER_MSB_0 0x7fffffffL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * For constructing the negative timestamp lower bound value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * binary: 10000000 00000000 00000000 00000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define LOWER_MSB_1 (-(UPPER_MSB_0) - 1L)  /* avoid overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * For constructing the negative timestamp upper bound value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * binary: 11111111 11111111 11111111 11111111
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define UPPER_MSB_1 (-1L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * Upper bound for nanoseconds value supported by the encoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * binary: 00111111 11111111 11111111 11111111
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define MAX_NANOSECONDS ((1L << 30) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define CASE_NAME_FORMAT "%s: msb:%x lower_bound:%x extra_bits: %x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	"1901-12-13 Lower bound of 32bit < 0 timestamp, no extra bits"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define UPPER_BOUND_NEG_NO_EXTRA_BITS_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	"1969-12-31 Upper bound of 32bit < 0 timestamp, no extra bits"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define LOWER_BOUND_NONNEG_NO_EXTRA_BITS_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	"1970-01-01 Lower bound of 32bit >=0 timestamp, no extra bits"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define UPPER_BOUND_NONNEG_NO_EXTRA_BITS_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	"2038-01-19 Upper bound of 32bit >=0 timestamp, no extra bits"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define LOWER_BOUND_NEG_LO_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	"2038-01-19 Lower bound of 32bit <0 timestamp, lo extra sec bit on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define UPPER_BOUND_NEG_LO_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	"2106-02-07 Upper bound of 32bit <0 timestamp, lo extra sec bit on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define LOWER_BOUND_NONNEG_LO_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	"2106-02-07 Lower bound of 32bit >=0 timestamp, lo extra sec bit on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define UPPER_BOUND_NONNEG_LO_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	"2174-02-25 Upper bound of 32bit >=0 timestamp, lo extra sec bit on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define LOWER_BOUND_NEG_HI_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	"2174-02-25 Lower bound of 32bit <0 timestamp, hi extra sec bit on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define UPPER_BOUND_NEG_HI_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	"2242-03-16 Upper bound of 32bit <0 timestamp, hi extra sec bit on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define LOWER_BOUND_NONNEG_HI_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	"2242-03-16 Lower bound of 32bit >=0 timestamp, hi extra sec bit on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define UPPER_BOUND_NONNEG_HI_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	"2310-04-04 Upper bound of 32bit >=0 timestamp, hi extra sec bit on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define UPPER_BOUND_NONNEG_HI_1_NS_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	"2310-04-04 Upper bound of 32bit>=0 timestamp, hi extra sec bit 1. 1 ns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define LOWER_BOUND_NONNEG_HI_1_NS_MAX_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	"2378-04-22 Lower bound of 32bit>= timestamp. Extra sec bits 1. Max ns"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define LOWER_BOUND_NONNEG_EXTRA_BITS_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	"2378-04-22 Lower bound of 32bit >=0 timestamp. All extra sec bits on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	"2446-05-10 Upper bound of 32bit >=0 timestamp. All extra sec bits on"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) struct timestamp_expectation {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	const char *test_case_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct timespec64 expected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	u32 extra_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	bool msb_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	bool lower_bound;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static time64_t get_32bit_time(const struct timestamp_expectation * const test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (test->msb_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		if (test->lower_bound)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			return LOWER_MSB_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return UPPER_MSB_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (test->lower_bound)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		return LOWER_MSB_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	return UPPER_MSB_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *  Test data is derived from the table in the Inode Timestamps section of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  *  Documentation/filesystems/ext4/inodes.rst.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static void inode_test_xtimestamp_decoding(struct kunit *test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	const struct timestamp_expectation test_data[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			.test_case_name = LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			.msb_set = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			.lower_bound = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			.extra_bits = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			.expected = {.tv_sec = -0x80000000LL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			.test_case_name = UPPER_BOUND_NEG_NO_EXTRA_BITS_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			.msb_set = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			.lower_bound = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			.extra_bits = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			.expected = {.tv_sec = -1LL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			.test_case_name = LOWER_BOUND_NONNEG_NO_EXTRA_BITS_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			.lower_bound = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			.extra_bits = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			.expected = {0LL, 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			.test_case_name = UPPER_BOUND_NONNEG_NO_EXTRA_BITS_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			.lower_bound = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			.extra_bits = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			.expected = {.tv_sec = 0x7fffffffLL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			.test_case_name = LOWER_BOUND_NEG_LO_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			.msb_set = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			.lower_bound = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			.extra_bits = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			.expected = {.tv_sec = 0x80000000LL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			.test_case_name = UPPER_BOUND_NEG_LO_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			.msb_set = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			.lower_bound = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			.extra_bits = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			.expected = {.tv_sec = 0xffffffffLL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			.test_case_name = LOWER_BOUND_NONNEG_LO_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			.lower_bound = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			.extra_bits = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			.expected = {.tv_sec = 0x100000000LL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			.test_case_name = UPPER_BOUND_NONNEG_LO_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			.lower_bound = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			.extra_bits = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			.expected = {.tv_sec = 0x17fffffffLL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			.test_case_name = LOWER_BOUND_NEG_HI_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			.msb_set = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			.lower_bound = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			.extra_bits =  2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			.expected = {.tv_sec = 0x180000000LL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			.test_case_name = UPPER_BOUND_NEG_HI_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			.msb_set = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			.lower_bound = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			.extra_bits = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			.expected = {.tv_sec = 0x1ffffffffLL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			.test_case_name = LOWER_BOUND_NONNEG_HI_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			.lower_bound = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			.extra_bits = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			.expected = {.tv_sec = 0x200000000LL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			.test_case_name = UPPER_BOUND_NONNEG_HI_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			.lower_bound = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			.extra_bits = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			.expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			.test_case_name = UPPER_BOUND_NONNEG_HI_1_NS_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			.lower_bound = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			.extra_bits = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			.expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 1L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			.test_case_name = LOWER_BOUND_NONNEG_HI_1_NS_MAX_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			.lower_bound = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			.extra_bits = 0xFFFFFFFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			.expected = {.tv_sec = 0x300000000LL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				     .tv_nsec = MAX_NANOSECONDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			.test_case_name = LOWER_BOUND_NONNEG_EXTRA_BITS_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			.lower_bound = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			.extra_bits = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			.expected = {.tv_sec = 0x300000000LL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			.test_case_name = UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			.msb_set = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			.lower_bound = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			.extra_bits = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			.expected = {.tv_sec = 0x37fffffffLL, .tv_nsec = 0L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct timespec64 timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	for (i = 0; i < ARRAY_SIZE(test_data); ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		timestamp.tv_sec = get_32bit_time(&test_data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		ext4_decode_extra_time(&timestamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				       cpu_to_le32(test_data[i].extra_bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		KUNIT_EXPECT_EQ_MSG(test,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 				    test_data[i].expected.tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				    timestamp.tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				    CASE_NAME_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				    test_data[i].test_case_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 				    test_data[i].msb_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 				    test_data[i].lower_bound,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				    test_data[i].extra_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		KUNIT_EXPECT_EQ_MSG(test,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				    test_data[i].expected.tv_nsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				    timestamp.tv_nsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				    CASE_NAME_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				    test_data[i].test_case_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				    test_data[i].msb_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				    test_data[i].lower_bound,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				    test_data[i].extra_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static struct kunit_case ext4_inode_test_cases[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	KUNIT_CASE(inode_test_xtimestamp_decoding),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static struct kunit_suite ext4_inode_test_suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	.name = "ext4_inode_test",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	.test_cases = ext4_inode_test_cases,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) kunit_test_suites(&ext4_inode_test_suite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) MODULE_LICENSE("GPL v2");