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

test_corrupt.sh « tests - github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1491dac3cd746a0aaeddeb8548a6ad150aa38e78 (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
#!/bin/bash
set -eu

echo "=== Corrupt tests ==="

NAMEMULT=64
FILEMULT=1

lfs_mktree() {
tests/test.py ${1:-} << TEST
    lfs_format(&lfs, &cfg) => 0;

    lfs_mount(&lfs, &cfg) => 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 0; j < $NAMEMULT; j++) {
            buffer[j] = '0'+i;
        }
        buffer[$NAMEMULT] = '\0';
        lfs_mkdir(&lfs, (char*)buffer) => 0;

        buffer[$NAMEMULT] = '/';
        for (int j = 0; j < $NAMEMULT; j++) {
            buffer[j+$NAMEMULT+1] = '0'+i;
        }
        buffer[2*$NAMEMULT+1] = '\0';
        lfs_file_open(&lfs, &file[0], (char*)buffer,
                LFS_O_WRONLY | LFS_O_CREAT) => 0;
        
        size = $NAMEMULT;
        for (int j = 0; j < i*$FILEMULT; j++) {
            lfs_file_write(&lfs, &file[0], buffer, size) => size;
        }

        lfs_file_close(&lfs, &file[0]) => 0;
    }
    lfs_unmount(&lfs) => 0;
TEST
}

lfs_chktree() {
tests/test.py ${1:-} << TEST
    lfs_mount(&lfs, &cfg) => 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 0; j < $NAMEMULT; j++) {
            buffer[j] = '0'+i;
        }
        buffer[$NAMEMULT] = '\0';
        lfs_stat(&lfs, (char*)buffer, &info) => 0;
        info.type => LFS_TYPE_DIR;

        buffer[$NAMEMULT] = '/';
        for (int j = 0; j < $NAMEMULT; j++) {
            buffer[j+$NAMEMULT+1] = '0'+i;
        }
        buffer[2*$NAMEMULT+1] = '\0';
        lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_RDONLY) => 0;
        
        size = $NAMEMULT;
        for (int j = 0; j < i*$FILEMULT; j++) {
            lfs_file_read(&lfs, &file[0], rbuffer, size) => size;
            memcmp(buffer, rbuffer, size) => 0;
        }

        lfs_file_close(&lfs, &file[0]) => 0;
    }
    lfs_unmount(&lfs) => 0;
TEST
}

echo "--- Sanity check ---"
rm -rf blocks
lfs_mktree
lfs_chktree

echo "--- Block corruption ---"
for i in {2..33}
do 
    rm -rf blocks
    mkdir blocks
    ln -s /dev/zero blocks/$(printf '%x' $i)
    lfs_mktree
    lfs_chktree
done

echo "--- Block persistance ---"
for i in {2..33}
do 
    rm -rf blocks
    mkdir blocks
    lfs_mktree
    chmod a-w blocks/$(printf '%x' $i) || true
    lfs_mktree
    lfs_chktree
done

echo "--- Big region corruption ---"
rm -rf blocks
mkdir blocks
for i in {2..255}
do
    ln -s /dev/zero blocks/$(printf '%x' $i)
done
lfs_mktree
lfs_chktree

echo "--- Alternating corruption ---"
rm -rf blocks
mkdir blocks
for i in {2..511..2}
do
    ln -s /dev/zero blocks/$(printf '%x' $i)
done
lfs_mktree
lfs_chktree

echo "--- Results ---"
tests/stats.py