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

test_superblocks.toml « tests - github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a99a5a47b0524797c5db602335ffff98085f3b41 (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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# simple formatting test
[cases.test_superblocks_format]
code = '''
    lfs_t lfs;
    lfs_format(&lfs, cfg) => 0;
'''

# mount/unmount
[cases.test_superblocks_mount]
code = '''
    lfs_t lfs;
    lfs_format(&lfs, cfg) => 0;
    lfs_mount(&lfs, cfg) => 0;
    lfs_unmount(&lfs) => 0;
'''

# mount/unmount from interpretting a previous superblock block_count
[cases.test_superblocks_mount_unknown_block_count]
code = '''
    lfs_t lfs;
    lfs_format(&lfs, cfg) => 0;

    memset(&lfs, 0, sizeof(lfs));
    struct lfs_config tweaked_cfg = *cfg;
    tweaked_cfg.block_count = 0;
    lfs_mount(&lfs, &tweaked_cfg) => 0;
    assert(lfs.block_count == cfg->block_count);
    lfs_unmount(&lfs) => 0;
'''


# reentrant format
[cases.test_superblocks_reentrant_format]
reentrant = true
code = '''
    lfs_t lfs;
    int err = lfs_mount(&lfs, cfg);
    if (err) {
        lfs_format(&lfs, cfg) => 0;
        lfs_mount(&lfs, cfg) => 0;
    }
    lfs_unmount(&lfs) => 0;
'''

# invalid mount
[cases.test_superblocks_invalid_mount]
code = '''
    lfs_t lfs;
    lfs_mount(&lfs, cfg) => LFS_ERR_CORRUPT;
'''

# test we can read superblock info through lfs_fs_stat
[cases.test_superblocks_stat]
if = 'DISK_VERSION == 0'
code = '''
    lfs_t lfs;
    lfs_format(&lfs, cfg) => 0;

    // test we can mount and read fsinfo
    lfs_mount(&lfs, cfg) => 0;

    struct lfs_fsinfo fsinfo;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.disk_version == LFS_DISK_VERSION);
    assert(fsinfo.name_max == LFS_NAME_MAX);
    assert(fsinfo.file_max == LFS_FILE_MAX);
    assert(fsinfo.attr_max == LFS_ATTR_MAX);

    lfs_unmount(&lfs) => 0;
'''

[cases.test_superblocks_stat_tweaked]
if = 'DISK_VERSION == 0'
defines.TWEAKED_NAME_MAX = 63
defines.TWEAKED_FILE_MAX = '(1 << 16)-1'
defines.TWEAKED_ATTR_MAX = 512
code = '''
    // create filesystem with tweaked params
    struct lfs_config tweaked_cfg = *cfg;
    tweaked_cfg.name_max = TWEAKED_NAME_MAX;
    tweaked_cfg.file_max = TWEAKED_FILE_MAX;
    tweaked_cfg.attr_max = TWEAKED_ATTR_MAX;

    lfs_t lfs;
    lfs_format(&lfs, &tweaked_cfg) => 0;

    // test we can mount and read these params with the original config
    lfs_mount(&lfs, cfg) => 0;

    struct lfs_fsinfo fsinfo;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.disk_version == LFS_DISK_VERSION);
    assert(fsinfo.name_max == TWEAKED_NAME_MAX);
    assert(fsinfo.file_max == TWEAKED_FILE_MAX);
    assert(fsinfo.attr_max == TWEAKED_ATTR_MAX);

    lfs_unmount(&lfs) => 0;
'''

# expanding superblock
[cases.test_superblocks_expand]
defines.BLOCK_CYCLES = [32, 33, 1]
defines.N = [10, 100, 1000]
code = '''
    lfs_t lfs;
    lfs_format(&lfs, cfg) => 0;
    lfs_mount(&lfs, cfg) => 0;
    for (int i = 0; i < N; i++) {
        lfs_file_t file;
        lfs_file_open(&lfs, &file, "dummy",
                LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
        lfs_file_close(&lfs, &file) => 0;
        struct lfs_info info;
        lfs_stat(&lfs, "dummy", &info) => 0;
        assert(strcmp(info.name, "dummy") == 0);
        assert(info.type == LFS_TYPE_REG);
        lfs_remove(&lfs, "dummy") => 0;
    }
    lfs_unmount(&lfs) => 0;

    // one last check after power-cycle
    lfs_mount(&lfs, cfg) => 0;
    lfs_file_t file;
    lfs_file_open(&lfs, &file, "dummy",
            LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
    lfs_file_close(&lfs, &file) => 0;
    struct lfs_info info;
    lfs_stat(&lfs, "dummy", &info) => 0;
    assert(strcmp(info.name, "dummy") == 0);
    assert(info.type == LFS_TYPE_REG);
    lfs_unmount(&lfs) => 0;
'''

# expanding superblock with power cycle
[cases.test_superblocks_expand_power_cycle]
defines.BLOCK_CYCLES = [32, 33, 1]
defines.N = [10, 100, 1000]
code = '''
    lfs_t lfs;
    lfs_format(&lfs, cfg) => 0;
    for (int i = 0; i < N; i++) {
        lfs_mount(&lfs, cfg) => 0;
        // remove lingering dummy?
        struct lfs_info info;
        int err = lfs_stat(&lfs, "dummy", &info);
        assert(err == 0 || (err == LFS_ERR_NOENT && i == 0));
        if (!err) {
            assert(strcmp(info.name, "dummy") == 0);
            assert(info.type == LFS_TYPE_REG);
            lfs_remove(&lfs, "dummy") => 0;
        }

        lfs_file_t file;
        lfs_file_open(&lfs, &file, "dummy",
                LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
        lfs_file_close(&lfs, &file) => 0;
        lfs_stat(&lfs, "dummy", &info) => 0;
        assert(strcmp(info.name, "dummy") == 0);
        assert(info.type == LFS_TYPE_REG);
        lfs_unmount(&lfs) => 0;
    }

    // one last check after power-cycle
    lfs_mount(&lfs, cfg) => 0;
    struct lfs_info info;
    lfs_stat(&lfs, "dummy", &info) => 0;
    assert(strcmp(info.name, "dummy") == 0);
    assert(info.type == LFS_TYPE_REG);
    lfs_unmount(&lfs) => 0;
'''

# reentrant expanding superblock
[cases.test_superblocks_reentrant_expand]
defines.BLOCK_CYCLES = [2, 1]
defines.N = 24
reentrant = true
code = '''
    lfs_t lfs;
    int err = lfs_mount(&lfs, cfg);
    if (err) {
        lfs_format(&lfs, cfg) => 0;
        lfs_mount(&lfs, cfg) => 0;
    }

    for (int i = 0; i < N; i++) {
        // remove lingering dummy?
        struct lfs_info info;
        err = lfs_stat(&lfs, "dummy", &info);
        assert(err == 0 || (err == LFS_ERR_NOENT && i == 0));
        if (!err) {
            assert(strcmp(info.name, "dummy") == 0);
            assert(info.type == LFS_TYPE_REG);
            lfs_remove(&lfs, "dummy") => 0;
        }

        lfs_file_t file;
        lfs_file_open(&lfs, &file, "dummy",
                LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
        lfs_file_close(&lfs, &file) => 0;
        lfs_stat(&lfs, "dummy", &info) => 0;
        assert(strcmp(info.name, "dummy") == 0);
        assert(info.type == LFS_TYPE_REG);
    }

    lfs_unmount(&lfs) => 0;

    // one last check after power-cycle
    lfs_mount(&lfs, cfg) => 0;
    struct lfs_info info;
    lfs_stat(&lfs, "dummy", &info) => 0;
    assert(strcmp(info.name, "dummy") == 0);
    assert(info.type == LFS_TYPE_REG);
    lfs_unmount(&lfs) => 0;
'''

# mount with unknown block_count
[cases.test_superblocks_unknown_blocks]
code = '''
    lfs_t lfs;
    lfs_format(&lfs, cfg) => 0;

    // known block_size/block_count
    cfg->block_size = BLOCK_SIZE;
    cfg->block_count = BLOCK_COUNT;
    lfs_mount(&lfs, cfg) => 0;
    struct lfs_fsinfo fsinfo;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.block_size == BLOCK_SIZE);
    assert(fsinfo.block_count == BLOCK_COUNT);
    lfs_unmount(&lfs) => 0;

    // unknown block_count
    cfg->block_size = BLOCK_SIZE;
    cfg->block_count = 0;
    lfs_mount(&lfs, cfg) => 0;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.block_size == BLOCK_SIZE);
    assert(fsinfo.block_count == BLOCK_COUNT);
    lfs_unmount(&lfs) => 0;

    // do some work
    lfs_mount(&lfs, cfg) => 0;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.block_size == BLOCK_SIZE);
    assert(fsinfo.block_count == BLOCK_COUNT);
    lfs_file_t file;
    lfs_file_open(&lfs, &file, "test",
            LFS_O_CREAT | LFS_O_EXCL | LFS_O_WRONLY) => 0;
    lfs_file_write(&lfs, &file, "hello!", 6) => 6;
    lfs_file_close(&lfs, &file) => 0;
    lfs_unmount(&lfs) => 0;

    lfs_mount(&lfs, cfg) => 0;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.block_size == BLOCK_SIZE);
    assert(fsinfo.block_count == BLOCK_COUNT);
    lfs_file_open(&lfs, &file, "test", LFS_O_RDONLY) => 0;
    uint8_t buffer[256];
    lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => 6;
    lfs_file_close(&lfs, &file) => 0;
    assert(memcmp(buffer, "hello!", 6) == 0);
    lfs_unmount(&lfs) => 0;
'''

# mount with blocks fewer than the erase_count
[cases.test_superblocks_fewer_blocks]
defines.BLOCK_COUNT = ['ERASE_COUNT/2', 'ERASE_COUNT/4', '2']
code = '''
    lfs_t lfs;
    lfs_format(&lfs, cfg) => 0;

    // known block_size/block_count
    cfg->block_size = BLOCK_SIZE;
    cfg->block_count = BLOCK_COUNT;
    lfs_mount(&lfs, cfg) => 0;
    struct lfs_fsinfo fsinfo;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.block_size == BLOCK_SIZE);
    assert(fsinfo.block_count == BLOCK_COUNT);
    lfs_unmount(&lfs) => 0;

    // incorrect block_count
    cfg->block_size = BLOCK_SIZE;
    cfg->block_count = ERASE_COUNT;
    lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;

    // unknown block_count
    cfg->block_size = BLOCK_SIZE;
    cfg->block_count = 0;
    lfs_mount(&lfs, cfg) => 0;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.block_size == BLOCK_SIZE);
    assert(fsinfo.block_count == BLOCK_COUNT);
    lfs_unmount(&lfs) => 0;

    // do some work
    lfs_mount(&lfs, cfg) => 0;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.block_size == BLOCK_SIZE);
    assert(fsinfo.block_count == BLOCK_COUNT);
    lfs_file_t file;
    lfs_file_open(&lfs, &file, "test",
            LFS_O_CREAT | LFS_O_EXCL | LFS_O_WRONLY) => 0;
    lfs_file_write(&lfs, &file, "hello!", 6) => 6;
    lfs_file_close(&lfs, &file) => 0;
    lfs_unmount(&lfs) => 0;

    lfs_mount(&lfs, cfg) => 0;
    lfs_fs_stat(&lfs, &fsinfo) => 0;
    assert(fsinfo.block_size == BLOCK_SIZE);
    assert(fsinfo.block_count == BLOCK_COUNT);
    lfs_file_open(&lfs, &file, "test", LFS_O_RDONLY) => 0;
    uint8_t buffer[256];
    lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => 6;
    lfs_file_close(&lfs, &file) => 0;
    assert(memcmp(buffer, "hello!", 6) == 0);
    lfs_unmount(&lfs) => 0;
'''

# mount with more blocks than the erase_count
[cases.test_superblocks_more_blocks]
defines.FORMAT_BLOCK_COUNT = '2*ERASE_COUNT'
in = 'lfs.c'
code = '''
    lfs_t lfs;
    lfs_init(&lfs, cfg) => 0;
    lfs.block_count = BLOCK_COUNT;

    lfs_mdir_t root = {
        .pair = {0, 0}, // make sure this goes into block 0
        .rev = 0,
        .off = sizeof(uint32_t),
        .etag = 0xffffffff,
        .count = 0,
        .tail = {LFS_BLOCK_NULL, LFS_BLOCK_NULL},
        .erased = false,
        .split = false,
    };

    lfs_superblock_t superblock = {
        .version     = LFS_DISK_VERSION,
        .block_size  = BLOCK_SIZE,
        .block_count = FORMAT_BLOCK_COUNT,
        .name_max    = LFS_NAME_MAX,
        .file_max    = LFS_FILE_MAX,
        .attr_max    = LFS_ATTR_MAX,
    };

    lfs_superblock_tole32(&superblock);
    lfs_dir_commit(&lfs, &root, LFS_MKATTRS(
            {LFS_MKTAG(LFS_TYPE_CREATE, 0, 0), NULL},
            {LFS_MKTAG(LFS_TYPE_SUPERBLOCK, 0, 8), "littlefs"},
            {LFS_MKTAG(LFS_TYPE_INLINESTRUCT, 0, sizeof(superblock)),
                &superblock})) => 0;
    lfs_deinit(&lfs) => 0;

    // known block_size/block_count
    cfg->block_size = BLOCK_SIZE;
    cfg->block_count = BLOCK_COUNT;
    lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;
'''