summaryrefslogtreecommitdiff
path: root/firmware/test/fat/test16.sh
blob: 5a1c13150c4ec00bdca609526ba045cbccf55061 (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
#!/bin/sh

IMAGE=disk.img
MOUNT=/mnt/dummy
DIR=$MOUNT/q
RESULT=result.txt

fail() {
    echo "!! Test failed $RETVAL. Look in $RESULT for test logs."
    chmod a+rw $RESULT
    exit
}

check() {
    /sbin/dosfsck -r $IMAGE | tee -a $RESULT
    [ $RETVAL -ne 0 ] && fail
}

try() {
    echo COMMAND: fat $1 "$2" "$3"
    echo COMMAND: fat $1 "$2" "$3" >> $RESULT
    ./fat $1 "$2" "$3" 2>> $RESULT
    RETVAL=$?
    [ $RETVAL -ne 0 ] && fail
}

buildimage() {
    /sbin/mkdosfs -F 16 -s $1 $IMAGE > /dev/null;
    mount -o loop,fat=16 $IMAGE $MOUNT;
    echo "Filling it with /etc files";
    mkdir $DIR;
    find /etc -type f -maxdepth 1 -exec cp {} $DIR \;
    for i in `seq 1 120`;
    do
        echo apa > "$DIR/very $i long test filename so we can make sure they.work";
    done;
    umount $MOUNT;
}

runtests() {
    rm $RESULT

    echo ---Test: create a long name directory in the root
    try mkdir "/very long subdir name"
    check
    try mkdir "/very long subdir name/apa.monkey.me.now"
    check

    echo ---Test: create a directory called "dir"
    try mkdir "/dir"
    check

    echo ---Test: create a 10K file
    try mkfile "/really long filenames rock" 10
    check

    try mkfile /dir/apa.monkey.me.now 10
    check
    try chkfile "/really long filenames rock" 10
    try chkfile /dir/apa.monkey.me.now 8

    echo ---Test: create a 1K file
    try mkfile /bpa.rock 1
    check
    try chkfile /bpa.rock 1

    echo ---Test: create a 40K file
    try mkfile /cpa.rock 40
    check
    try chkfile /cpa.rock 40

    echo ---Test: create a 400K file
    try mkfile /dpa.rock 400
    check
    try chkfile /dpa.rock 400

    echo ---Test: create a 1200K file
    try mkfile /epa.rock 1200
    check
    try chkfile /epa.rock 1200

    echo ---Test: rewrite first 20K of a 40K file
    try mkfile /cpa.rock 20
    check
    try chkfile /cpa.rock 20

    echo ---Test: rewrite first sector of 40K file
    try mkfile /cpa.rock 0
    check
    try chkfile /cpa.rock
    try chkfile /bpa.rock

    LOOP=25
    SIZE=700

    try del "/really long filenames rock"

    echo ---Test: create $LOOP $SIZE k files
    for i in `seq 1 $LOOP`;
    do
        echo ---Test: $i/$LOOP ---
        try mkfile "/q/rockbox rocks.$i" $SIZE
        check
        try chkfile "/q/rockbox rocks.$i" $SIZE
        check
        try del "/q/rockbox rocks.$i"
        check
        try mkfile "/q/rockbox rocks.$i" $SIZE
        check
        try ren "/q/rockbox rocks.$i" "/q/$i is a new long filename!"
        check
    done

}

echo "--------------------------------------"
echo "Building test image (4 sector/cluster)"
echo "--------------------------------------"
buildimage 4
runtests

echo "--------------------------------------"
echo "Building test image (8 sectors/cluster)"
echo "--------------------------------------"
buildimage 8
runtests

echo "----------------------------------------"
echo "Building test image (64 sectors/cluster)"
echo "----------------------------------------"
buildimage 64
runtests

echo "== Test completed successfully =="
chmod a+rw $RESULT