1
2# simple path test
3[cases.test_paths_normal]
4code = '''
5    lfs_t lfs;
6    lfs_format(&lfs, cfg) => 0;
7    lfs_mount(&lfs, cfg) => 0;
8    lfs_mkdir(&lfs, "tea") => 0;
9    lfs_mkdir(&lfs, "tea/hottea") => 0;
10    lfs_mkdir(&lfs, "tea/warmtea") => 0;
11    lfs_mkdir(&lfs, "tea/coldtea") => 0;
12
13    struct lfs_info info;
14    lfs_stat(&lfs, "tea/hottea", &info) => 0;
15    assert(strcmp(info.name, "hottea") == 0);
16    lfs_stat(&lfs, "/tea/hottea", &info) => 0;
17    assert(strcmp(info.name, "hottea") == 0);
18
19    lfs_mkdir(&lfs, "/milk") => 0;
20    lfs_stat(&lfs, "/milk", &info) => 0;
21    assert(strcmp(info.name, "milk") == 0);
22    lfs_stat(&lfs, "milk", &info) => 0;
23    assert(strcmp(info.name, "milk") == 0);
24    lfs_unmount(&lfs) => 0;
25'''
26
27# redundant slashes
28[cases.test_paths_redundant_slashes]
29code = '''
30    lfs_t lfs;
31    lfs_format(&lfs, cfg) => 0;
32    lfs_mount(&lfs, cfg) => 0;
33    lfs_mkdir(&lfs, "tea") => 0;
34    lfs_mkdir(&lfs, "tea/hottea") => 0;
35    lfs_mkdir(&lfs, "tea/warmtea") => 0;
36    lfs_mkdir(&lfs, "tea/coldtea") => 0;
37
38    struct lfs_info info;
39    lfs_stat(&lfs, "/tea/hottea", &info) => 0;
40    assert(strcmp(info.name, "hottea") == 0);
41    lfs_stat(&lfs, "//tea//hottea", &info) => 0;
42    assert(strcmp(info.name, "hottea") == 0);
43    lfs_stat(&lfs, "///tea///hottea", &info) => 0;
44    assert(strcmp(info.name, "hottea") == 0);
45
46    lfs_mkdir(&lfs, "////milk") => 0;
47    lfs_stat(&lfs, "////milk", &info) => 0;
48    assert(strcmp(info.name, "milk") == 0);
49    lfs_stat(&lfs, "milk", &info) => 0;
50    assert(strcmp(info.name, "milk") == 0);
51    lfs_unmount(&lfs) => 0;
52'''
53
54# dot path test
55[cases.test_paths_dot]
56code = '''
57    lfs_t lfs;
58    lfs_format(&lfs, cfg) => 0;
59    lfs_mount(&lfs, cfg) => 0;
60    lfs_mkdir(&lfs, "tea") => 0;
61    lfs_mkdir(&lfs, "tea/hottea") => 0;
62    lfs_mkdir(&lfs, "tea/warmtea") => 0;
63    lfs_mkdir(&lfs, "tea/coldtea") => 0;
64
65    struct lfs_info info;
66    lfs_stat(&lfs, "./tea/hottea", &info) => 0;
67    assert(strcmp(info.name, "hottea") == 0);
68    lfs_stat(&lfs, "/./tea/hottea", &info) => 0;
69    assert(strcmp(info.name, "hottea") == 0);
70    lfs_stat(&lfs, "/././tea/hottea", &info) => 0;
71    assert(strcmp(info.name, "hottea") == 0);
72    lfs_stat(&lfs, "/./tea/./hottea", &info) => 0;
73    assert(strcmp(info.name, "hottea") == 0);
74
75    lfs_mkdir(&lfs, "/./milk") => 0;
76    lfs_stat(&lfs, "/./milk", &info) => 0;
77    assert(strcmp(info.name, "milk") == 0);
78    lfs_stat(&lfs, "milk", &info) => 0;
79    assert(strcmp(info.name, "milk") == 0);
80    lfs_unmount(&lfs) => 0;
81'''
82
83# dot dot path test
84[cases.test_paths_dot_dot]
85code = '''
86    lfs_t lfs;
87    lfs_format(&lfs, cfg) => 0;
88    lfs_mount(&lfs, cfg) => 0;
89    lfs_mkdir(&lfs, "tea") => 0;
90    lfs_mkdir(&lfs, "tea/hottea") => 0;
91    lfs_mkdir(&lfs, "tea/warmtea") => 0;
92    lfs_mkdir(&lfs, "tea/coldtea") => 0;
93    lfs_mkdir(&lfs, "coffee") => 0;
94    lfs_mkdir(&lfs, "coffee/hotcoffee") => 0;
95    lfs_mkdir(&lfs, "coffee/warmcoffee") => 0;
96    lfs_mkdir(&lfs, "coffee/coldcoffee") => 0;
97
98    struct lfs_info info;
99    lfs_stat(&lfs, "coffee/../tea/hottea", &info) => 0;
100    assert(strcmp(info.name, "hottea") == 0);
101    lfs_stat(&lfs, "tea/coldtea/../hottea", &info) => 0;
102    assert(strcmp(info.name, "hottea") == 0);
103    lfs_stat(&lfs, "coffee/coldcoffee/../../tea/hottea", &info) => 0;
104    assert(strcmp(info.name, "hottea") == 0);
105    lfs_stat(&lfs, "coffee/../coffee/../tea/hottea", &info) => 0;
106    assert(strcmp(info.name, "hottea") == 0);
107
108    lfs_mkdir(&lfs, "coffee/../milk") => 0;
109    lfs_stat(&lfs, "coffee/../milk", &info) => 0;
110    strcmp(info.name, "milk") => 0;
111    lfs_stat(&lfs, "milk", &info) => 0;
112    strcmp(info.name, "milk") => 0;
113    lfs_unmount(&lfs) => 0;
114'''
115
116# trailing dot path test
117[cases.test_paths_trailing_dot]
118code = '''
119    lfs_t lfs;
120    lfs_format(&lfs, cfg) => 0;
121    lfs_mount(&lfs, cfg) => 0;
122    lfs_mkdir(&lfs, "tea") => 0;
123    lfs_mkdir(&lfs, "tea/hottea") => 0;
124    lfs_mkdir(&lfs, "tea/warmtea") => 0;
125    lfs_mkdir(&lfs, "tea/coldtea") => 0;
126
127    struct lfs_info info;
128    lfs_stat(&lfs, "tea/hottea/", &info) => 0;
129    assert(strcmp(info.name, "hottea") == 0);
130    lfs_stat(&lfs, "tea/hottea/.", &info) => 0;
131    assert(strcmp(info.name, "hottea") == 0);
132    lfs_stat(&lfs, "tea/hottea/./.", &info) => 0;
133    assert(strcmp(info.name, "hottea") == 0);
134    lfs_stat(&lfs, "tea/hottea/..", &info) => 0;
135    assert(strcmp(info.name, "tea") == 0);
136    lfs_stat(&lfs, "tea/hottea/../.", &info) => 0;
137    assert(strcmp(info.name, "tea") == 0);
138    lfs_unmount(&lfs) => 0;
139'''
140
141# leading dot path test
142[cases.test_paths_leading_dot]
143code = '''
144    lfs_t lfs;
145    lfs_format(&lfs, cfg) => 0;
146    lfs_mount(&lfs, cfg) => 0;
147    lfs_mkdir(&lfs, ".milk") => 0;
148    struct lfs_info info;
149    lfs_stat(&lfs, ".milk", &info) => 0;
150    strcmp(info.name, ".milk") => 0;
151    lfs_stat(&lfs, "tea/.././.milk", &info) => 0;
152    strcmp(info.name, ".milk") => 0;
153    lfs_unmount(&lfs) => 0;
154'''
155
156# root dot dot path test
157[cases.test_paths_root_dot_dot]
158code = '''
159    lfs_t lfs;
160    lfs_format(&lfs, cfg) => 0;
161    lfs_mount(&lfs, cfg) => 0;
162    lfs_mkdir(&lfs, "tea") => 0;
163    lfs_mkdir(&lfs, "tea/hottea") => 0;
164    lfs_mkdir(&lfs, "tea/warmtea") => 0;
165    lfs_mkdir(&lfs, "tea/coldtea") => 0;
166    lfs_mkdir(&lfs, "coffee") => 0;
167    lfs_mkdir(&lfs, "coffee/hotcoffee") => 0;
168    lfs_mkdir(&lfs, "coffee/warmcoffee") => 0;
169    lfs_mkdir(&lfs, "coffee/coldcoffee") => 0;
170
171    struct lfs_info info;
172    lfs_stat(&lfs, "coffee/../../../../../../tea/hottea", &info) => 0;
173    strcmp(info.name, "hottea") => 0;
174
175    lfs_mkdir(&lfs, "coffee/../../../../../../milk") => 0;
176    lfs_stat(&lfs, "coffee/../../../../../../milk", &info) => 0;
177    strcmp(info.name, "milk") => 0;
178    lfs_stat(&lfs, "milk", &info) => 0;
179    strcmp(info.name, "milk") => 0;
180    lfs_unmount(&lfs) => 0;
181'''
182
183# invalid path tests
184[cases.test_paths_invalid]
185code = '''
186    lfs_t lfs;
187    lfs_format(&lfs, cfg);
188    lfs_mount(&lfs, cfg) => 0;
189    struct lfs_info info;
190    lfs_stat(&lfs, "dirt", &info) => LFS_ERR_NOENT;
191    lfs_stat(&lfs, "dirt/ground", &info) => LFS_ERR_NOENT;
192    lfs_stat(&lfs, "dirt/ground/earth", &info) => LFS_ERR_NOENT;
193
194    lfs_remove(&lfs, "dirt") => LFS_ERR_NOENT;
195    lfs_remove(&lfs, "dirt/ground") => LFS_ERR_NOENT;
196    lfs_remove(&lfs, "dirt/ground/earth") => LFS_ERR_NOENT;
197
198    lfs_mkdir(&lfs, "dirt/ground") => LFS_ERR_NOENT;
199    lfs_file_t file;
200    lfs_file_open(&lfs, &file, "dirt/ground", LFS_O_WRONLY | LFS_O_CREAT)
201            => LFS_ERR_NOENT;
202    lfs_mkdir(&lfs, "dirt/ground/earth") => LFS_ERR_NOENT;
203    lfs_file_open(&lfs, &file, "dirt/ground/earth", LFS_O_WRONLY | LFS_O_CREAT)
204            => LFS_ERR_NOENT;
205    lfs_unmount(&lfs) => 0;
206'''
207
208# root operations
209[cases.test_paths_root]
210code = '''
211    lfs_t lfs;
212    lfs_format(&lfs, cfg) => 0;
213    lfs_mount(&lfs, cfg) => 0;
214    struct lfs_info info;
215    lfs_stat(&lfs, "/", &info) => 0;
216    assert(strcmp(info.name, "/") == 0);
217    assert(info.type == LFS_TYPE_DIR);
218
219    lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
220    lfs_file_t file;
221    lfs_file_open(&lfs, &file, "/", LFS_O_WRONLY | LFS_O_CREAT)
222            => LFS_ERR_ISDIR;
223
224    lfs_remove(&lfs, "/") => LFS_ERR_INVAL;
225    lfs_unmount(&lfs) => 0;
226'''
227
228# root representations
229[cases.test_paths_root_reprs]
230code = '''
231    lfs_t lfs;
232    lfs_format(&lfs, cfg) => 0;
233    lfs_mount(&lfs, cfg) => 0;
234    struct lfs_info info;
235    lfs_stat(&lfs, "/", &info) => 0;
236    assert(strcmp(info.name, "/") == 0);
237    assert(info.type == LFS_TYPE_DIR);
238    lfs_stat(&lfs, "", &info) => 0;
239    assert(strcmp(info.name, "/") == 0);
240    assert(info.type == LFS_TYPE_DIR);
241    lfs_stat(&lfs, ".", &info) => 0;
242    assert(strcmp(info.name, "/") == 0);
243    assert(info.type == LFS_TYPE_DIR);
244    lfs_stat(&lfs, "..", &info) => 0;
245    assert(strcmp(info.name, "/") == 0);
246    assert(info.type == LFS_TYPE_DIR);
247    lfs_stat(&lfs, "//", &info) => 0;
248    assert(strcmp(info.name, "/") == 0);
249    assert(info.type == LFS_TYPE_DIR);
250    lfs_stat(&lfs, "./", &info) => 0;
251    assert(strcmp(info.name, "/") == 0);
252    assert(info.type == LFS_TYPE_DIR);
253    lfs_unmount(&lfs) => 0;
254'''
255
256# superblock conflict test
257[cases.test_paths_superblock_conflict]
258code = '''
259    lfs_t lfs;
260    lfs_format(&lfs, cfg) => 0;
261    lfs_mount(&lfs, cfg) => 0;
262    struct lfs_info info;
263    lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
264    lfs_remove(&lfs, "littlefs") => LFS_ERR_NOENT;
265
266    lfs_mkdir(&lfs, "littlefs") => 0;
267    lfs_stat(&lfs, "littlefs", &info) => 0;
268    assert(strcmp(info.name, "littlefs") == 0);
269    assert(info.type == LFS_TYPE_DIR);
270    lfs_remove(&lfs, "littlefs") => 0;
271    lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
272    lfs_unmount(&lfs) => 0;
273'''
274
275# max path test
276[cases.test_paths_max]
277code = '''
278    lfs_t lfs;
279    lfs_format(&lfs, cfg) => 0;
280    lfs_mount(&lfs, cfg) => 0;
281    lfs_mkdir(&lfs, "coffee") => 0;
282    lfs_mkdir(&lfs, "coffee/hotcoffee") => 0;
283    lfs_mkdir(&lfs, "coffee/warmcoffee") => 0;
284    lfs_mkdir(&lfs, "coffee/coldcoffee") => 0;
285
286    char path[1024];
287    memset(path, 'w', LFS_NAME_MAX+1);
288    path[LFS_NAME_MAX+1] = '\0';
289    lfs_mkdir(&lfs, path) => LFS_ERR_NAMETOOLONG;
290    lfs_file_t file;
291    lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT)
292            => LFS_ERR_NAMETOOLONG;
293
294    memcpy(path, "coffee/", strlen("coffee/"));
295    memset(path+strlen("coffee/"), 'w', LFS_NAME_MAX+1);
296    path[strlen("coffee/")+LFS_NAME_MAX+1] = '\0';
297    lfs_mkdir(&lfs, path) => LFS_ERR_NAMETOOLONG;
298    lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT)
299            => LFS_ERR_NAMETOOLONG;
300    lfs_unmount(&lfs) => 0;
301'''
302
303# really big path test
304[cases.test_paths_really_big]
305code = '''
306    lfs_t lfs;
307    lfs_format(&lfs, cfg) => 0;
308    lfs_mount(&lfs, cfg) => 0;
309    lfs_mkdir(&lfs, "coffee") => 0;
310    lfs_mkdir(&lfs, "coffee/hotcoffee") => 0;
311    lfs_mkdir(&lfs, "coffee/warmcoffee") => 0;
312    lfs_mkdir(&lfs, "coffee/coldcoffee") => 0;
313
314    char path[1024];
315    memset(path, 'w', LFS_NAME_MAX);
316    path[LFS_NAME_MAX] = '\0';
317    lfs_mkdir(&lfs, path) => 0;
318    lfs_remove(&lfs, path) => 0;
319    lfs_file_t file;
320    lfs_file_open(&lfs, &file, path,
321            LFS_O_WRONLY | LFS_O_CREAT) => 0;
322    lfs_file_close(&lfs, &file) => 0;
323    lfs_remove(&lfs, path) => 0;
324
325    memcpy(path, "coffee/", strlen("coffee/"));
326    memset(path+strlen("coffee/"), 'w', LFS_NAME_MAX);
327    path[strlen("coffee/")+LFS_NAME_MAX] = '\0';
328    lfs_mkdir(&lfs, path) => 0;
329    lfs_remove(&lfs, path) => 0;
330    lfs_file_open(&lfs, &file, path,
331            LFS_O_WRONLY | LFS_O_CREAT) => 0;
332    lfs_file_close(&lfs, &file) => 0;
333    lfs_remove(&lfs, path) => 0;
334    lfs_unmount(&lfs) => 0;
335'''
336
337