• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2[[case]] # interspersed file test
3define.SIZE = [10, 100]
4define.FILES = [4, 10, 26]
5code = '''
6    lfs_file_t files[FILES];
7    const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
8    lfs_format(&lfs, &cfg) => 0;
9    lfs_mount(&lfs, &cfg) => 0;
10    for (int j = 0; j < FILES; j++) {
11        sprintf(path, "%c", alphas[j]);
12        lfs_file_open(&lfs, &files[j], path,
13                LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
14    }
15
16    for (int i = 0; i < SIZE; i++) {
17        for (int j = 0; j < FILES; j++) {
18            lfs_file_write(&lfs, &files[j], &alphas[j], 1) => 1;
19        }
20    }
21
22    for (int j = 0; j < FILES; j++) {
23        lfs_file_close(&lfs, &files[j]);
24    }
25
26    lfs_dir_open(&lfs, &dir, "/") => 0;
27    lfs_dir_read(&lfs, &dir, &info) => 1;
28    assert(strcmp(info.name, ".") == 0);
29    assert(info.type == LFS_TYPE_DIR);
30    lfs_dir_read(&lfs, &dir, &info) => 1;
31    assert(strcmp(info.name, "..") == 0);
32    assert(info.type == LFS_TYPE_DIR);
33    for (int j = 0; j < FILES; j++) {
34        sprintf(path, "%c", alphas[j]);
35        lfs_dir_read(&lfs, &dir, &info) => 1;
36        assert(strcmp(info.name, path) == 0);
37        assert(info.type == LFS_TYPE_REG);
38        assert(info.size == SIZE);
39    }
40    lfs_dir_read(&lfs, &dir, &info) => 0;
41    lfs_dir_close(&lfs, &dir) => 0;
42
43    for (int j = 0; j < FILES; j++) {
44        sprintf(path, "%c", alphas[j]);
45        lfs_file_open(&lfs, &files[j], path, LFS_O_RDONLY) => 0;
46    }
47
48    for (int i = 0; i < 10; i++) {
49        for (int j = 0; j < FILES; j++) {
50            lfs_file_read(&lfs, &files[j], buffer, 1) => 1;
51            assert(buffer[0] == alphas[j]);
52        }
53    }
54
55    for (int j = 0; j < FILES; j++) {
56        lfs_file_close(&lfs, &files[j]);
57    }
58
59    lfs_unmount(&lfs) => 0;
60'''
61
62[[case]] # interspersed remove file test
63define.SIZE = [10, 100]
64define.FILES = [4, 10, 26]
65code = '''
66    const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
67    lfs_format(&lfs, &cfg) => 0;
68    lfs_mount(&lfs, &cfg) => 0;
69    for (int j = 0; j < FILES; j++) {
70        sprintf(path, "%c", alphas[j]);
71        lfs_file_open(&lfs, &file, path,
72                LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
73        for (int i = 0; i < SIZE; i++) {
74            lfs_file_write(&lfs, &file, &alphas[j], 1) => 1;
75        }
76        lfs_file_close(&lfs, &file);
77    }
78    lfs_unmount(&lfs) => 0;
79
80    lfs_mount(&lfs, &cfg) => 0;
81    lfs_file_open(&lfs, &file, "zzz", LFS_O_WRONLY | LFS_O_CREAT) => 0;
82    for (int j = 0; j < FILES; j++) {
83        lfs_file_write(&lfs, &file, (const void*)"~", 1) => 1;
84        lfs_file_sync(&lfs, &file) => 0;
85
86        sprintf(path, "%c", alphas[j]);
87        lfs_remove(&lfs, path) => 0;
88    }
89    lfs_file_close(&lfs, &file);
90
91    lfs_dir_open(&lfs, &dir, "/") => 0;
92    lfs_dir_read(&lfs, &dir, &info) => 1;
93    assert(strcmp(info.name, ".") == 0);
94    assert(info.type == LFS_TYPE_DIR);
95    lfs_dir_read(&lfs, &dir, &info) => 1;
96    assert(strcmp(info.name, "..") == 0);
97    assert(info.type == LFS_TYPE_DIR);
98    lfs_dir_read(&lfs, &dir, &info) => 1;
99    assert(strcmp(info.name, "zzz") == 0);
100    assert(info.type == LFS_TYPE_REG);
101    assert(info.size == FILES);
102    lfs_dir_read(&lfs, &dir, &info) => 0;
103    lfs_dir_close(&lfs, &dir) => 0;
104
105    lfs_file_open(&lfs, &file, "zzz", LFS_O_RDONLY) => 0;
106    for (int i = 0; i < FILES; i++) {
107        lfs_file_read(&lfs, &file, buffer, 1) => 1;
108        assert(buffer[0] == '~');
109    }
110    lfs_file_close(&lfs, &file);
111
112    lfs_unmount(&lfs) => 0;
113'''
114
115[[case]] # remove inconveniently test
116define.SIZE = [10, 100]
117code = '''
118    lfs_format(&lfs, &cfg) => 0;
119    lfs_mount(&lfs, &cfg) => 0;
120    lfs_file_t files[3];
121    lfs_file_open(&lfs, &files[0], "e", LFS_O_WRONLY | LFS_O_CREAT) => 0;
122    lfs_file_open(&lfs, &files[1], "f", LFS_O_WRONLY | LFS_O_CREAT) => 0;
123    lfs_file_open(&lfs, &files[2], "g", LFS_O_WRONLY | LFS_O_CREAT) => 0;
124
125    for (int i = 0; i < SIZE/2; i++) {
126        lfs_file_write(&lfs, &files[0], (const void*)"e", 1) => 1;
127        lfs_file_write(&lfs, &files[1], (const void*)"f", 1) => 1;
128        lfs_file_write(&lfs, &files[2], (const void*)"g", 1) => 1;
129    }
130
131    lfs_remove(&lfs, "f") => 0;
132
133    for (int i = 0; i < SIZE/2; i++) {
134        lfs_file_write(&lfs, &files[0], (const void*)"e", 1) => 1;
135        lfs_file_write(&lfs, &files[1], (const void*)"f", 1) => 1;
136        lfs_file_write(&lfs, &files[2], (const void*)"g", 1) => 1;
137    }
138
139    lfs_file_close(&lfs, &files[0]);
140    lfs_file_close(&lfs, &files[1]);
141    lfs_file_close(&lfs, &files[2]);
142
143    lfs_dir_open(&lfs, &dir, "/") => 0;
144    lfs_dir_read(&lfs, &dir, &info) => 1;
145    assert(strcmp(info.name, ".") == 0);
146    assert(info.type == LFS_TYPE_DIR);
147    lfs_dir_read(&lfs, &dir, &info) => 1;
148    assert(strcmp(info.name, "..") == 0);
149    assert(info.type == LFS_TYPE_DIR);
150    lfs_dir_read(&lfs, &dir, &info) => 1;
151    assert(strcmp(info.name, "e") == 0);
152    assert(info.type == LFS_TYPE_REG);
153    assert(info.size == SIZE);
154    lfs_dir_read(&lfs, &dir, &info) => 1;
155    assert(strcmp(info.name, "g") == 0);
156    assert(info.type == LFS_TYPE_REG);
157    assert(info.size == SIZE);
158    lfs_dir_read(&lfs, &dir, &info) => 0;
159    lfs_dir_close(&lfs, &dir) => 0;
160
161    lfs_file_open(&lfs, &files[0], "e", LFS_O_RDONLY) => 0;
162    lfs_file_open(&lfs, &files[1], "g", LFS_O_RDONLY) => 0;
163    for (int i = 0; i < SIZE; i++) {
164        lfs_file_read(&lfs, &files[0], buffer, 1) => 1;
165        assert(buffer[0] == 'e');
166        lfs_file_read(&lfs, &files[1], buffer, 1) => 1;
167        assert(buffer[0] == 'g');
168    }
169    lfs_file_close(&lfs, &files[0]);
170    lfs_file_close(&lfs, &files[1]);
171
172    lfs_unmount(&lfs) => 0;
173'''
174
175[[case]] # reentrant interspersed file test
176define.SIZE = [10, 100]
177define.FILES = [4, 10, 26]
178reentrant = true
179code = '''
180    lfs_file_t files[FILES];
181    const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
182
183    err = lfs_mount(&lfs, &cfg);
184    if (err) {
185        lfs_format(&lfs, &cfg) => 0;
186        lfs_mount(&lfs, &cfg) => 0;
187    }
188
189    for (int j = 0; j < FILES; j++) {
190        sprintf(path, "%c", alphas[j]);
191        lfs_file_open(&lfs, &files[j], path,
192                LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
193    }
194
195    for (int i = 0; i < SIZE; i++) {
196        for (int j = 0; j < FILES; j++) {
197            size = lfs_file_size(&lfs, &files[j]);
198            assert((int)size >= 0);
199            if ((int)size <= i) {
200                lfs_file_write(&lfs, &files[j], &alphas[j], 1) => 1;
201                lfs_file_sync(&lfs, &files[j]) => 0;
202            }
203        }
204    }
205
206    for (int j = 0; j < FILES; j++) {
207        lfs_file_close(&lfs, &files[j]);
208    }
209
210    lfs_dir_open(&lfs, &dir, "/") => 0;
211    lfs_dir_read(&lfs, &dir, &info) => 1;
212    assert(strcmp(info.name, ".") == 0);
213    assert(info.type == LFS_TYPE_DIR);
214    lfs_dir_read(&lfs, &dir, &info) => 1;
215    assert(strcmp(info.name, "..") == 0);
216    assert(info.type == LFS_TYPE_DIR);
217    for (int j = 0; j < FILES; j++) {
218        sprintf(path, "%c", alphas[j]);
219        lfs_dir_read(&lfs, &dir, &info) => 1;
220        assert(strcmp(info.name, path) == 0);
221        assert(info.type == LFS_TYPE_REG);
222        assert(info.size == SIZE);
223    }
224    lfs_dir_read(&lfs, &dir, &info) => 0;
225    lfs_dir_close(&lfs, &dir) => 0;
226
227    for (int j = 0; j < FILES; j++) {
228        sprintf(path, "%c", alphas[j]);
229        lfs_file_open(&lfs, &files[j], path, LFS_O_RDONLY) => 0;
230    }
231
232    for (int i = 0; i < 10; i++) {
233        for (int j = 0; j < FILES; j++) {
234            lfs_file_read(&lfs, &files[j], buffer, 1) => 1;
235            assert(buffer[0] == alphas[j]);
236        }
237    }
238
239    for (int j = 0; j < FILES; j++) {
240        lfs_file_close(&lfs, &files[j]);
241    }
242
243    lfs_unmount(&lfs) => 0;
244'''
245