bbc0002.sh
4.78 KB
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
#!/bin/bash
#
# test script to test
# BBCFormat functions
# with read DBE
#
TESTID=BBC0002
TESTFILE=testfile.$$
OUTPUT=/dev/null
echo creating test file $TESTFILE ...
./mkcart > $TESTFILE
. ./testlib.sh
#
# Format the cartridge and install SKSA
#
export BBC_BAD_BLKS=
export BBC_READ_DBE_BLKS=
export BBC_WRITE_ERR_BLKS=
#
# Test 1: 1 DBE SKSA area
#
dbe0=$(($RANDOM % BB_SYS_BLK_NUM))
export BBC_READ_DBE_BLKS=$dbe0
cp ./$TESTFILE bkup.$$
echo " Test (1): Format with DBE @ $dbe0"
emsh << END_OF_FILE >out1.$$ 2>err1_f.$$
u ./$TESTFILE
B
F
C
Q
q
END_OF_FILE
sed -e s/"\(blk \)$dbe0\( reads with DBE\)"/"\1Expexted\2/" err1_f.$$ | sed -e s/"blk $dbe0 read DBE (ok)"/"expected blk read DBE (ok)"/ > err1.$$
rm -rf err1_f.$$
#### Check for log file and image data #####
check_log 1 out
check_log 1 err
check_unchange bkup.$$ ./$TESTFILE 0 $BB_BLK_NUM_B4_FAT "input" "result"
check_fat ./$TESTFILE 0 16 Golden/Init_FAT
#
# Test 2: 2 DBE in SKSA area
#
dbe0=$(($RANDOM % BB_SYS_BLK_NUM))
dbe1=$(($RANDOM % BB_SYS_BLK_NUM))
while [ $dbe0 -eq $dbe1 ]; do
dbe1=$(($RANDOM % BB_SYS_BLK_NUM))
done
echo " Test (2): Format with DBE @ $dbe0 $dbe1"
export BBC_READ_DBE_BLKS="$dbe0,$dbe1"
emsh << END_OF_FILE >out2.$$ 2>err2_f.$$
u ./$TESTFILE
B
F
C
Q
q
END_OF_FILE
filter_DBE_ERR_OUT err2_f.$$ "$dbe0,$dbe1" err2.$$
rm -rf err2_f.$$
#### check result ###
check_log 2 out
check_log 2 err
check_unchange bkup.$$ ./$TESTFILE 0 $BB_BLK_NUM_B4_FAT "input" "result"
check_fat ./$TESTFILE 0 16 Golden/Init_FAT
#
# Test 3: more than 2 DBE in SKSA area
#
num=$(($RANDOM % 16))
BBC_READ_DBE_BLKS=`create_random 0 64 $(($num + 3))`
echo " Test (3): Format with DBE @ $BBC_READ_DBE_BLKS"
export BBC_READ_DBE_BLKS
emsh << END_OF_FILE >out3.$$ 2>err3_f.$$
u ./$TESTFILE
B
F
C
Q
q
END_OF_FILE
filter_DBE_ERR_OUT err3_f.$$ $BBC_READ_DBE_BLKS err3.$$
check_log 3 out
check_log 3 err
check_unchange bkup.$$ ./$TESTFILE 0 $BB_BLK_NUM_B4_FAT "input" "result"
check_fat ./$TESTFILE 0 16 Golden/Init_FAT
rm -rf err3_f.$$
#
# Random DBE in FAT area
#
num=$(($RANDOM % 8))
num=$((num + 1))
BBC_READ_DBE_BLKS=`create_random 4080 16 $num`
echo " Test (4): Format with DBE @ $BBC_READ_DBE_BLKS in Fat area"
export BBC_READ_DBE_BLKS
##### Trash exisiting FAT ######
cp -f bkup.$$ ./$TESTFILE
emsh << END_OF_FILE >out4.$$ 2>err4_f.$$
u ./$TESTFILE
B
F
C
Q
q
END_OF_FILE
err_num=`grep "ERROR read_fat_blk: read_blocks failed" err4_f.$$ | wc -l`
if [ $err_num -eq $num ]; then
echo "Got expect $num FAT DBE"
else
echo "Failed: expect $num DBE but got $err_num DBE"
fi
filter_DBE_ERR_OUT err4_f.$$ $BBC_READ_DBE_BLKS err4.$$
check_log 4 out
check_log 4 err
check_unchange bkup.$$ ./$TESTFILE 0 $BB_BLK_NUM_B4_FAT "input" "result"
check_fat ./$TESTFILE 0 16 Golden/Init_FAT
rm -rf err4_f.$$
#
# Random DBE in Application area
#
num=$(($RANDOM % 32))
num=$((num + 1))
BBC_READ_DBE_BLKS=`create_random 64 4016 $num`
echo " Test (5): Format with DBE @ $BBC_READ_DBE_BLKS in Application area"
export BBC_READ_DBE_BLKS
##### Trash exisiting FAT ######
emsh << END_OF_FILE >out5.$$ 2>err5_f.$$
u ./$TESTFILE
B
F
C
Q
q
END_OF_FILE
filter_DBE_ERR_OUT err5_f.$$ $BBC_READ_DBE_BLKS err5.$$
check_log 5 out
check_log 5 err
check_unchange bkup.$$ ./$TESTFILE 0 $BB_BLK_NUM_B4_FAT "input" "result"
check_fat ./$TESTFILE 0 16 Golden/Init_FAT
rm -rf err5_f.$$
#
# Random DBE in SYSTEM and Application area
#
num_sys=$(($RANDOM % 8))
num_sys=$(($num_sys + 1))
num_app=$(($RANDOM % 32))
num_app=$(($num_app + 1))
blk_list1=`create_random 0 64 $num_sys`
blk_list2=`create_random 64 4016 $num_app`
export BBC_READ_DBE_BLKS="$blk_list1,$blk_list2"
echo " Test (6): Format with DBE @ $BBC_READ_DBE_BLKS"
emsh << END_OF_FILE >out6.$$ 2>err6_f.$$
u ./$TESTFILE
B
F
C
Q
q
END_OF_FILE
filter_DBE_ERR_OUT err6_f.$$ $BBC_READ_DBE_BLKS err6.$$
check_log 6 out
check_log 6 err
check_unchange bkup.$$ ./$TESTFILE 0 $BB_BLK_NUM_B4_FAT "input" "result"
check_fat ./$TESTFILE 0 16 Golden/Init_FAT
rm -rf err6_f.$$
#
# Random DBE
#
num_sys=$(($RANDOM % 2))
blk_list1=`create_random 0 64 $num_sys`
num_app=$(($RANDOM % 8))
blk_list2=`create_random 64 4016 $num_app`
[ "$blk_list2" = "" ] || {
[ "$blk_list1" = "" ] && {
blk_list1="$blk_list2"
} || {
blk_list1="$blk_list1,$blk_list2"
}
}
num_fat=$(($RANDOM % 4))
num_fat=$(($num_fat + 1))
blk_list2=`create_random 4080 16 $num_fat`
[ "$blk_list1" = "" ] && {
blk_list1="$blk_list2"
} || {
blk_list1="$blk_list1,$blk_list2"
}
export BBC_READ_DBE_BLKS="$blk_list1"
echo " Test (7): Format with DBE @ $BBC_READ_DBE_BLKS"
emsh << END_OF_FILE >out7.$$ 2>err7_f.$$
u ./$TESTFILE
B
F
C
Q
q
END_OF_FILE
filter_DBE_ERR_OUT err7_f.$$ $BBC_READ_DBE_BLKS err7.$$
check_log 7 out
check_log 7 err
check_unchange bkup.$$ ./$TESTFILE 0 $BB_BLK_NUM_B4_FAT "input" "result"
check_fat ./$TESTFILE 0 16 Golden/Init_FAT
rm -rf err7_f.$$
rm -rf ./$TESTFILE bkup.$$
exit 0