~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/fat/fat_test.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/fat/fat_test.c (Version linux-6.12-rc7) and /fs/fat/fat_test.c (Version linux-6.0.19)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  * KUnit tests for FAT filesystems.                 3  * KUnit tests for FAT filesystems.
  4  *                                                  4  *
  5  * Copyright (C) 2020 Google LLC.                   5  * Copyright (C) 2020 Google LLC.
  6  * Author: David Gow <davidgow@google.com>          6  * Author: David Gow <davidgow@google.com>
  7  */                                                 7  */
  8                                                     8 
  9 #include <kunit/test.h>                             9 #include <kunit/test.h>
 10                                                    10 
 11 #include "fat.h"                                   11 #include "fat.h"
 12                                                    12 
 13 static void fat_checksum_test(struct kunit *te     13 static void fat_checksum_test(struct kunit *test)
 14 {                                                  14 {
 15         /* With no extension. */                   15         /* With no extension. */
 16         KUNIT_EXPECT_EQ(test, fat_checksum("VM     16         KUNIT_EXPECT_EQ(test, fat_checksum("VMLINUX    "), (u8)44);
 17         /* With 3-letter extension. */             17         /* With 3-letter extension. */
 18         KUNIT_EXPECT_EQ(test, fat_checksum("RE     18         KUNIT_EXPECT_EQ(test, fat_checksum("README  TXT"), (u8)115);
 19         /* With short (1-letter) extension. */     19         /* With short (1-letter) extension. */
 20         KUNIT_EXPECT_EQ(test, fat_checksum("AB     20         KUNIT_EXPECT_EQ(test, fat_checksum("ABCDEFGHA  "), (u8)98);
 21 }                                                  21 }
 22                                                    22 
 23 struct fat_timestamp_testcase {                    23 struct fat_timestamp_testcase {
 24         const char *name;                          24         const char *name;
 25         struct timespec64 ts;                      25         struct timespec64 ts;
 26         __le16 time;                               26         __le16 time;
 27         __le16 date;                               27         __le16 date;
 28         u8 cs;                                     28         u8 cs;
 29         int time_offset;                           29         int time_offset;
 30 };                                                 30 };
 31                                                    31 
 32 static struct fat_timestamp_testcase time_test     32 static struct fat_timestamp_testcase time_test_cases[] = {
 33         {                                          33         {
 34                 .name = "Earliest possible UTC     34                 .name = "Earliest possible UTC (1980-01-01 00:00:00)",
 35                 .ts = {.tv_sec = 315532800LL,      35                 .ts = {.tv_sec = 315532800LL, .tv_nsec = 0L},
 36                 .time = cpu_to_le16(0),            36                 .time = cpu_to_le16(0),
 37                 .date = cpu_to_le16(33),           37                 .date = cpu_to_le16(33),
 38                 .cs = 0,                           38                 .cs = 0,
 39                 .time_offset = 0,                  39                 .time_offset = 0,
 40         },                                         40         },
 41         {                                          41         {
 42                 .name = "Latest possible UTC (     42                 .name = "Latest possible UTC (2107-12-31 23:59:58)",
 43                 .ts = {.tv_sec = 4354819198LL,     43                 .ts = {.tv_sec = 4354819198LL, .tv_nsec = 0L},
 44                 .time = cpu_to_le16(49021),        44                 .time = cpu_to_le16(49021),
 45                 .date = cpu_to_le16(65439),        45                 .date = cpu_to_le16(65439),
 46                 .cs = 0,                           46                 .cs = 0,
 47                 .time_offset = 0,                  47                 .time_offset = 0,
 48         },                                         48         },
 49         {                                          49         {
 50                 .name = "Earliest possible (UT     50                 .name = "Earliest possible (UTC-11) (== 1979-12-31 13:00:00 UTC)",
 51                 .ts = {.tv_sec = 315493200LL,      51                 .ts = {.tv_sec = 315493200LL, .tv_nsec = 0L},
 52                 .time = cpu_to_le16(0),            52                 .time = cpu_to_le16(0),
 53                 .date = cpu_to_le16(33),           53                 .date = cpu_to_le16(33),
 54                 .cs = 0,                           54                 .cs = 0,
 55                 .time_offset = 11 * 60,            55                 .time_offset = 11 * 60,
 56         },                                         56         },
 57         {                                          57         {
 58                 .name = "Latest possible (UTC+     58                 .name = "Latest possible (UTC+11) (== 2108-01-01 10:59:58 UTC)",
 59                 .ts = {.tv_sec = 4354858798LL,     59                 .ts = {.tv_sec = 4354858798LL, .tv_nsec = 0L},
 60                 .time = cpu_to_le16(49021),        60                 .time = cpu_to_le16(49021),
 61                 .date = cpu_to_le16(65439),        61                 .date = cpu_to_le16(65439),
 62                 .cs = 0,                           62                 .cs = 0,
 63                 .time_offset = -11 * 60,           63                 .time_offset = -11 * 60,
 64         },                                         64         },
 65         {                                          65         {
 66                 .name = "Leap Day / Year (1996     66                 .name = "Leap Day / Year (1996-02-29 00:00:00)",
 67                 .ts = {.tv_sec = 825552000LL,      67                 .ts = {.tv_sec = 825552000LL, .tv_nsec = 0L},
 68                 .time = cpu_to_le16(0),            68                 .time = cpu_to_le16(0),
 69                 .date = cpu_to_le16(8285),         69                 .date = cpu_to_le16(8285),
 70                 .cs = 0,                           70                 .cs = 0,
 71                 .time_offset = 0,                  71                 .time_offset = 0,
 72         },                                         72         },
 73         {                                          73         {
 74                 .name = "Year 2000 is leap yea     74                 .name = "Year 2000 is leap year (2000-02-29 00:00:00)",
 75                 .ts = {.tv_sec = 951782400LL,      75                 .ts = {.tv_sec = 951782400LL, .tv_nsec = 0L},
 76                 .time = cpu_to_le16(0),            76                 .time = cpu_to_le16(0),
 77                 .date = cpu_to_le16(10333),        77                 .date = cpu_to_le16(10333),
 78                 .cs = 0,                           78                 .cs = 0,
 79                 .time_offset = 0,                  79                 .time_offset = 0,
 80         },                                         80         },
 81         {                                          81         {
 82                 .name = "Year 2100 not leap ye     82                 .name = "Year 2100 not leap year (2100-03-01 00:00:00)",
 83                 .ts = {.tv_sec = 4107542400LL,     83                 .ts = {.tv_sec = 4107542400LL, .tv_nsec = 0L},
 84                 .time = cpu_to_le16(0),            84                 .time = cpu_to_le16(0),
 85                 .date = cpu_to_le16(61537),        85                 .date = cpu_to_le16(61537),
 86                 .cs = 0,                           86                 .cs = 0,
 87                 .time_offset = 0,                  87                 .time_offset = 0,
 88         },                                         88         },
 89         {                                          89         {
 90                 .name = "Leap year + timezone      90                 .name = "Leap year + timezone UTC+1 (== 2004-02-29 00:30:00 UTC)",
 91                 .ts = {.tv_sec = 1078014600LL,     91                 .ts = {.tv_sec = 1078014600LL, .tv_nsec = 0L},
 92                 .time = cpu_to_le16(48064),        92                 .time = cpu_to_le16(48064),
 93                 .date = cpu_to_le16(12380),        93                 .date = cpu_to_le16(12380),
 94                 .cs = 0,                           94                 .cs = 0,
 95                 .time_offset = -60,                95                 .time_offset = -60,
 96         },                                         96         },
 97         {                                          97         {
 98                 .name = "Leap year + timezone      98                 .name = "Leap year + timezone UTC-1 (== 2004-02-29 23:30:00 UTC)",
 99                 .ts = {.tv_sec = 1078097400LL,     99                 .ts = {.tv_sec = 1078097400LL, .tv_nsec = 0L},
100                 .time = cpu_to_le16(960),         100                 .time = cpu_to_le16(960),
101                 .date = cpu_to_le16(12385),       101                 .date = cpu_to_le16(12385),
102                 .cs = 0,                          102                 .cs = 0,
103                 .time_offset = 60,                103                 .time_offset = 60,
104         },                                        104         },
105         {                                         105         {
106                 .name = "VFAT odd-second resol    106                 .name = "VFAT odd-second resolution (1999-12-31 23:59:59)",
107                 .ts = {.tv_sec = 946684799LL,     107                 .ts = {.tv_sec = 946684799LL, .tv_nsec = 0L},
108                 .time = cpu_to_le16(49021),       108                 .time = cpu_to_le16(49021),
109                 .date = cpu_to_le16(10143),       109                 .date = cpu_to_le16(10143),
110                 .cs = 100,                        110                 .cs = 100,
111                 .time_offset = 0,                 111                 .time_offset = 0,
112         },                                        112         },
113         {                                         113         {
114                 .name = "VFAT 10ms resolution     114                 .name = "VFAT 10ms resolution (1980-01-01 00:00:00:0010)",
115                 .ts = {.tv_sec = 315532800LL,     115                 .ts = {.tv_sec = 315532800LL, .tv_nsec = 10000000L},
116                 .time = cpu_to_le16(0),           116                 .time = cpu_to_le16(0),
117                 .date = cpu_to_le16(33),          117                 .date = cpu_to_le16(33),
118                 .cs = 1,                          118                 .cs = 1,
119                 .time_offset = 0,                 119                 .time_offset = 0,
120         },                                        120         },
121 };                                                121 };
122                                                   122 
123 static void time_testcase_desc(struct fat_time    123 static void time_testcase_desc(struct fat_timestamp_testcase *t,
124                                char *desc)        124                                char *desc)
125 {                                                 125 {
126         strscpy(desc, t->name, KUNIT_PARAM_DES    126         strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
127 }                                                 127 }
128                                                   128 
129 KUNIT_ARRAY_PARAM(fat_time, time_test_cases, t    129 KUNIT_ARRAY_PARAM(fat_time, time_test_cases, time_testcase_desc);
130                                                   130 
131 static void fat_time_fat2unix_test(struct kuni    131 static void fat_time_fat2unix_test(struct kunit *test)
132 {                                                 132 {
133         static struct msdos_sb_info fake_sb;      133         static struct msdos_sb_info fake_sb;
134         struct timespec64 ts;                     134         struct timespec64 ts;
135         struct fat_timestamp_testcase *testcas    135         struct fat_timestamp_testcase *testcase =
136                 (struct fat_timestamp_testcase    136                 (struct fat_timestamp_testcase *)test->param_value;
137                                                   137 
138         fake_sb.options.tz_set = 1;               138         fake_sb.options.tz_set = 1;
139         fake_sb.options.time_offset = testcase    139         fake_sb.options.time_offset = testcase->time_offset;
140                                                   140 
141         fat_time_fat2unix(&fake_sb, &ts,          141         fat_time_fat2unix(&fake_sb, &ts,
142                           testcase->time,         142                           testcase->time,
143                           testcase->date,         143                           testcase->date,
144                           testcase->cs);          144                           testcase->cs);
145         KUNIT_EXPECT_EQ_MSG(test,                 145         KUNIT_EXPECT_EQ_MSG(test,
146                             testcase->ts.tv_se    146                             testcase->ts.tv_sec,
147                             ts.tv_sec,            147                             ts.tv_sec,
148                             "Timestamp mismatc    148                             "Timestamp mismatch (seconds)\n");
149         KUNIT_EXPECT_EQ_MSG(test,                 149         KUNIT_EXPECT_EQ_MSG(test,
150                             testcase->ts.tv_ns    150                             testcase->ts.tv_nsec,
151                             ts.tv_nsec,           151                             ts.tv_nsec,
152                             "Timestamp mismatc    152                             "Timestamp mismatch (nanoseconds)\n");
153 }                                                 153 }
154                                                   154 
155 static void fat_time_unix2fat_test(struct kuni    155 static void fat_time_unix2fat_test(struct kunit *test)
156 {                                                 156 {
157         static struct msdos_sb_info fake_sb;      157         static struct msdos_sb_info fake_sb;
158         __le16 date, time;                        158         __le16 date, time;
159         u8 cs;                                    159         u8 cs;
160         struct fat_timestamp_testcase *testcas    160         struct fat_timestamp_testcase *testcase =
161                 (struct fat_timestamp_testcase    161                 (struct fat_timestamp_testcase *)test->param_value;
162                                                   162 
163         fake_sb.options.tz_set = 1;               163         fake_sb.options.tz_set = 1;
164         fake_sb.options.time_offset = testcase    164         fake_sb.options.time_offset = testcase->time_offset;
165                                                   165 
166         fat_time_unix2fat(&fake_sb, &testcase-    166         fat_time_unix2fat(&fake_sb, &testcase->ts,
167                           &time, &date, &cs);     167                           &time, &date, &cs);
168         KUNIT_EXPECT_EQ_MSG(test,                 168         KUNIT_EXPECT_EQ_MSG(test,
169                             le16_to_cpu(testca    169                             le16_to_cpu(testcase->time),
170                             le16_to_cpu(time),    170                             le16_to_cpu(time),
171                             "Time mismatch\n")    171                             "Time mismatch\n");
172         KUNIT_EXPECT_EQ_MSG(test,                 172         KUNIT_EXPECT_EQ_MSG(test,
173                             le16_to_cpu(testca    173                             le16_to_cpu(testcase->date),
174                             le16_to_cpu(date),    174                             le16_to_cpu(date),
175                             "Date mismatch\n")    175                             "Date mismatch\n");
176         KUNIT_EXPECT_EQ_MSG(test,                 176         KUNIT_EXPECT_EQ_MSG(test,
177                             testcase->cs,         177                             testcase->cs,
178                             cs,                   178                             cs,
179                             "Centisecond misma    179                             "Centisecond mismatch\n");
180 }                                                 180 }
181                                                   181 
182 static struct kunit_case fat_test_cases[] = {     182 static struct kunit_case fat_test_cases[] = {
183         KUNIT_CASE(fat_checksum_test),            183         KUNIT_CASE(fat_checksum_test),
184         KUNIT_CASE_PARAM(fat_time_fat2unix_tes    184         KUNIT_CASE_PARAM(fat_time_fat2unix_test, fat_time_gen_params),
185         KUNIT_CASE_PARAM(fat_time_unix2fat_tes    185         KUNIT_CASE_PARAM(fat_time_unix2fat_test, fat_time_gen_params),
186         {},                                       186         {},
187 };                                                187 };
188                                                   188 
189 static struct kunit_suite fat_test_suite = {      189 static struct kunit_suite fat_test_suite = {
190         .name = "fat_test",                       190         .name = "fat_test",
191         .test_cases = fat_test_cases,             191         .test_cases = fat_test_cases,
192 };                                                192 };
193                                                   193 
194 kunit_test_suites(&fat_test_suite);               194 kunit_test_suites(&fat_test_suite);
195                                                   195 
196 MODULE_DESCRIPTION("KUnit tests for FAT filesy << 
197 MODULE_LICENSE("GPL v2");                         196 MODULE_LICENSE("GPL v2");
198                                                   197 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php