Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_relocations.toml « tests - github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad267b51c10d96218c77205011adf01375ebf198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# specific corner cases worth explicitly testing for
[[case]] # dangling split dir test
define.ITERATIONS = 20
define.COUNT = 10
define.LFS_BLOCK_CYCLES = [8, 1]
code = '''
    lfs_format(&lfs, &cfg) => 0;
    // fill up filesystem so only ~16 blocks are left
    lfs_mount(&lfs, &cfg) => 0;
    lfs_file_open(&lfs, &file, "padding", LFS_O_CREAT | LFS_O_WRONLY) => 0;
    memset(buffer, 0, 512);
    while (LFS_BLOCK_COUNT - lfs_fs_size(&lfs) > 16) {
        lfs_file_write(&lfs, &file, buffer, 512) => 512;
    }
    lfs_file_close(&lfs, &file) => 0;
    // make a child dir to use in bounded space
    lfs_mkdir(&lfs, "child") => 0;
    lfs_unmount(&lfs) => 0;

    lfs_mount(&lfs, &cfg) => 0;
    for (int j = 0; j < ITERATIONS; j++) {
        for (int i = 0; i < COUNT; i++) {
            sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
            lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
            lfs_file_close(&lfs, &file) => 0;
        }

        lfs_dir_open(&lfs, &dir, "child") => 0;
        lfs_dir_read(&lfs, &dir, &info) => 1;
        lfs_dir_read(&lfs, &dir, &info) => 1;
        for (int i = 0; i < COUNT; i++) {
            sprintf(path, "test%03d_loooooooooooooooooong_name", i);
            lfs_dir_read(&lfs, &dir, &info) => 1;
            strcmp(info.name, path) => 0;
        }
        lfs_dir_read(&lfs, &dir, &info) => 0;
        lfs_dir_close(&lfs, &dir) => 0;

        if (j == ITERATIONS-1) {
            break;
        }

        for (int i = 0; i < COUNT; i++) {
            sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
            lfs_remove(&lfs, path) => 0;
        }
    }
    lfs_unmount(&lfs) => 0;

    lfs_mount(&lfs, &cfg) => 0;
    lfs_dir_open(&lfs, &dir, "child") => 0;
    lfs_dir_read(&lfs, &dir, &info) => 1;
    lfs_dir_read(&lfs, &dir, &info) => 1;
    for (int i = 0; i < COUNT; i++) {
        sprintf(path, "test%03d_loooooooooooooooooong_name", i);
        lfs_dir_read(&lfs, &dir, &info) => 1;
        strcmp(info.name, path) => 0;
    }
    lfs_dir_read(&lfs, &dir, &info) => 0;
    lfs_dir_close(&lfs, &dir) => 0;
    for (int i = 0; i < COUNT; i++) {
        sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
        lfs_remove(&lfs, path) => 0;
    }
    lfs_unmount(&lfs) => 0;
'''

[[case]] # outdated head test
define.ITERATIONS = 20
define.COUNT = 10
define.LFS_BLOCK_CYCLES = [8, 1]
code = '''
    lfs_format(&lfs, &cfg) => 0;
    // fill up filesystem so only ~16 blocks are left
    lfs_mount(&lfs, &cfg) => 0;
    lfs_file_open(&lfs, &file, "padding", LFS_O_CREAT | LFS_O_WRONLY) => 0;
    memset(buffer, 0, 512);
    while (LFS_BLOCK_COUNT - lfs_fs_size(&lfs) > 16) {
        lfs_file_write(&lfs, &file, buffer, 512) => 512;
    }
    lfs_file_close(&lfs, &file) => 0;
    // make a child dir to use in bounded space
    lfs_mkdir(&lfs, "child") => 0;
    lfs_unmount(&lfs) => 0;

    lfs_mount(&lfs, &cfg) => 0;
    for (int j = 0; j < ITERATIONS; j++) {
        for (int i = 0; i < COUNT; i++) {
            sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
            lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
            lfs_file_close(&lfs, &file) => 0;
        }

        lfs_dir_open(&lfs, &dir, "child") => 0;
        lfs_dir_read(&lfs, &dir, &info) => 1;
        lfs_dir_read(&lfs, &dir, &info) => 1;
        for (int i = 0; i < COUNT; i++) {
            sprintf(path, "test%03d_loooooooooooooooooong_name", i);
            lfs_dir_read(&lfs, &dir, &info) => 1;
            strcmp(info.name, path) => 0;
            info.size => 0;

            sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
            lfs_file_open(&lfs, &file, path, LFS_O_WRONLY) => 0;
            lfs_file_write(&lfs, &file, "hi", 2) => 2;
            lfs_file_close(&lfs, &file) => 0;
        }
        lfs_dir_read(&lfs, &dir, &info) => 0;

        lfs_dir_rewind(&lfs, &dir) => 0;
        lfs_dir_read(&lfs, &dir, &info) => 1;
        lfs_dir_read(&lfs, &dir, &info) => 1;
        for (int i = 0; i < COUNT; i++) {
            sprintf(path, "test%03d_loooooooooooooooooong_name", i);
            lfs_dir_read(&lfs, &dir, &info) => 1;
            strcmp(info.name, path) => 0;
            info.size => 2;

            sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
            lfs_file_open(&lfs, &file, path, LFS_O_WRONLY) => 0;
            lfs_file_write(&lfs, &file, "hi", 2) => 2;
            lfs_file_close(&lfs, &file) => 0;
        }
        lfs_dir_read(&lfs, &dir, &info) => 0;

        lfs_dir_rewind(&lfs, &dir) => 0;
        lfs_dir_read(&lfs, &dir, &info) => 1;
        lfs_dir_read(&lfs, &dir, &info) => 1;
        for (int i = 0; i < COUNT; i++) {
            sprintf(path, "test%03d_loooooooooooooooooong_name", i);
            lfs_dir_read(&lfs, &dir, &info) => 1;
            strcmp(info.name, path) => 0;
            info.size => 2;
        }
        lfs_dir_read(&lfs, &dir, &info) => 0;
        lfs_dir_close(&lfs, &dir) => 0;

        for (int i = 0; i < COUNT; i++) {
            sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
            lfs_remove(&lfs, path) => 0;
        }
    }
    lfs_unmount(&lfs) => 0;
'''

[[case]] # reentrant testing for relocations, this is the same as the
         # orphan testing, except here we also set block_cycles so that
         # almost every tree operation needs a relocation
reentrant = true
define = [
    {FILES=6,  DEPTH=1, CYCLES=50, LFS_BLOCK_CYCLES=1},
    {FILES=26, DEPTH=1, CYCLES=50, LFS_BLOCK_CYCLES=1},
    {FILES=3,  DEPTH=3, CYCLES=50, LFS_BLOCK_CYCLES=1},
]
code = '''
    err = lfs_mount(&lfs, &cfg);
    if (err) {
        lfs_format(&lfs, &cfg) => 0;
        lfs_mount(&lfs, &cfg) => 0;
    }

    srand(1);
    const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
    for (int i = 0; i < CYCLES; i++) {
        // create random path
        char full_path[256];
        for (int d = 0; d < DEPTH; d++) {
            sprintf(&full_path[2*d], "/%c", alpha[rand() % FILES]);
        }

        // if it does not exist, we create it, else we destroy
        int res = lfs_stat(&lfs, full_path, &info);
        if (res == LFS_ERR_NOENT) {
            // create each directory in turn, ignore if dir already exists
            for (int d = 0; d < DEPTH; d++) {
                strcpy(path, full_path);
                path[2*d+2] = '\0';
                err = lfs_mkdir(&lfs, path);
                assert(!err || err == LFS_ERR_EXIST);
            }

            for (int d = 0; d < DEPTH; d++) {
                strcpy(path, full_path);
                path[2*d+2] = '\0';
                lfs_stat(&lfs, path, &info) => 0;
                assert(strcmp(info.name, &path[2*d+1]) == 0);
                assert(info.type == LFS_TYPE_DIR);
            }
        } else {
            // is valid dir?
            assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
            assert(info.type == LFS_TYPE_DIR);

            // try to delete path in reverse order, ignore if dir is not empty
            for (int d = DEPTH-1; d >= 0; d--) {
                strcpy(path, full_path);
                path[2*d+2] = '\0';
                err = lfs_remove(&lfs, path);
                assert(!err || err == LFS_ERR_NOTEMPTY);
            }

            lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
        }
    }
    lfs_unmount(&lfs) => 0;
'''

[[case]] # reentrant testing for relocations, but now with random renames!
reentrant = true
define = [
    {FILES=6,  DEPTH=1, CYCLES=50, LFS_BLOCK_CYCLES=1},
    {FILES=26, DEPTH=1, CYCLES=50, LFS_BLOCK_CYCLES=1},
    {FILES=3,  DEPTH=3, CYCLES=50, LFS_BLOCK_CYCLES=1},
]
code = '''
    err = lfs_mount(&lfs, &cfg);
    if (err) {
        lfs_format(&lfs, &cfg) => 0;
        lfs_mount(&lfs, &cfg) => 0;
    }

    srand(1);
    const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
    for (int i = 0; i < CYCLES; i++) {
        // create random path
        char full_path[256];
        for (int d = 0; d < DEPTH; d++) {
            sprintf(&full_path[2*d], "/%c", alpha[rand() % FILES]);
        }

        // if it does not exist, we create it, else we destroy
        int res = lfs_stat(&lfs, full_path, &info);
        assert(!res || res == LFS_ERR_NOENT);
        if (res == LFS_ERR_NOENT) {
            // create each directory in turn, ignore if dir already exists
            for (int d = 0; d < DEPTH; d++) {
                strcpy(path, full_path);
                path[2*d+2] = '\0';
                err = lfs_mkdir(&lfs, path);
                assert(!err || err == LFS_ERR_EXIST);
            }

            for (int d = 0; d < DEPTH; d++) {
                strcpy(path, full_path);
                path[2*d+2] = '\0';
                lfs_stat(&lfs, path, &info) => 0;
                assert(strcmp(info.name, &path[2*d+1]) == 0);
                assert(info.type == LFS_TYPE_DIR);
            }
        } else {
            assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
            assert(info.type == LFS_TYPE_DIR);

            // create new random path
            char new_path[256];
            for (int d = 0; d < DEPTH; d++) {
                sprintf(&new_path[2*d], "/%c", alpha[rand() % FILES]);
            }

            // if new path does not exist, rename, otherwise destroy
            res = lfs_stat(&lfs, new_path, &info);
            assert(!res || res == LFS_ERR_NOENT);
            if (res == LFS_ERR_NOENT) {
                // stop once some dir is renamed
                for (int d = 0; d < DEPTH; d++) {
                    strcpy(&path[2*d], &full_path[2*d]);
                    path[2*d+2] = '\0';
                    strcpy(&path[128+2*d], &new_path[2*d]);
                    path[128+2*d+2] = '\0';
                    err = lfs_rename(&lfs, path, path+128);
                    assert(!err || err == LFS_ERR_NOTEMPTY);
                    if (!err) {
                        strcpy(path, path+128);
                    }
                }

                for (int d = 0; d < DEPTH; d++) {
                    strcpy(path, new_path);
                    path[2*d+2] = '\0';
                    lfs_stat(&lfs, path, &info) => 0;
                    assert(strcmp(info.name, &path[2*d+1]) == 0);
                    assert(info.type == LFS_TYPE_DIR);
                }
                
                lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
            } else {
                // try to delete path in reverse order,
                // ignore if dir is not empty
                for (int d = DEPTH-1; d >= 0; d--) {
                    strcpy(path, full_path);
                    path[2*d+2] = '\0';
                    err = lfs_remove(&lfs, path);
                    assert(!err || err == LFS_ERR_NOTEMPTY);
                }

                lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
            }
        }
    }
    lfs_unmount(&lfs) => 0;
'''