t5300, t5302, t5303: Do not use /dev/zero
We do not have /dev/zero on Windows. This replaces it by data generated with printf, perl, or echo. Most of the cases do not depend on that the data is a stream of zero bytes, so we use something printable; nor is an unlimited stream of data needed, so we produce only as many bytes as the test cases need. Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Johannes Sixt committed
Nov 17, 2008 at 09:21 UTC
b689ccf6c9eecb9811f60ac69a24cadacf84da44
3 files changed
+16
-15
t/t5300-pack-object.sh
+8
-9
@@ -13,11 +13,10 @@ TRASH=`pwd`
13
test_expect_success \
14
'setup' \
15
'rm -f .git/index*
16
- for i in a b c
17
- do
18
- dd if=/dev/zero bs=4k count=1 | perl -pe "y/\\000/$i/" >$i &&
19
- git update-index --add $i || return 1
20
- done &&
16
+ perl -e "print \"a\" x 4096;" > a &&
17
+ perl -e "print \"b\" x 4096;" > b &&
18
+ perl -e "print \"c\" x 4096;" > c &&
19
+ git update-index --add a b c &&
20
cat c >d && echo foo >>d && git update-index --add d &&
21
tree=`git write-tree` &&
22
commit=`git commit-tree $tree </dev/null` && {
@@ -221,7 +220,7 @@ test_expect_success \
220
test_expect_success \
221
'verify-pack catches a corrupted pack signature' \
222
'cat test-1-${packname_1}.pack >test-3.pack &&
224
- dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
223
+ echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
224
if git verify-pack test-3.idx
225
then false
226
else :;
@@ -230,7 +229,7 @@ test_expect_success \
229
test_expect_success \
230
'verify-pack catches a corrupted pack version' \
231
'cat test-1-${packname_1}.pack >test-3.pack &&
233
- dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
232
+ echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
233
if git verify-pack test-3.idx
234
then false
235
else :;
@@ -239,7 +238,7 @@ test_expect_success \
238
test_expect_success \
239
'verify-pack catches a corrupted type/size of the 1st packed object data' \
240
'cat test-1-${packname_1}.pack >test-3.pack &&
242
- dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
241
+ echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
242
if git verify-pack test-3.idx
243
then false
244
else :;
@@ -250,7 +249,7 @@ test_expect_success \
249
'l=`wc -c <test-3.idx` &&
250
l=`expr $l - 20` &&
251
cat test-1-${packname_1}.pack >test-3.pack &&
253
- dd if=/dev/zero of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
252
+ printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
253
if git verify-pack test-3.pack
254
then false
255
else :;
t/t5302-pack-index.sh
+1
-1
@@ -208,7 +208,7 @@ test_expect_success \
208
obj=`git hash-object file_001` &&
209
nr=`index_obj_nr ".git/objects/pack/pack-${pack1}.idx" $obj` &&
210
chmod +w ".git/objects/pack/pack-${pack1}.idx" &&
211
- dd if=/dev/zero of=".git/objects/pack/pack-${pack1}.idx" conv=notrunc \
211
+ printf xxxx | dd of=".git/objects/pack/pack-${pack1}.idx" conv=notrunc \
212
bs=1 count=4 seek=$((8 + 256 * 4 + `wc -l <obj-list` * 20 + $nr * 4)) &&
213
( while read obj
214
do git cat-file -p $obj >/dev/null || exit 1
t/t5303-pack-corruption-resilience.sh
+7
-5
@@ -55,6 +55,8 @@ do_corrupt_object() {
55
test_must_fail git verify-pack ${pack}.pack
56
}
57
58
+printf '\0' > zero
59
+
60
test_expect_success \
61
'initial setup validation' \
62
'create_test_files &&
@@ -66,7 +68,7 @@ test_expect_success \
68
69
test_expect_success \
70
'create corruption in header of first object' \
69
- 'do_corrupt_object $blob_1 0 < /dev/zero &&
71
+ 'do_corrupt_object $blob_1 0 < zero &&
72
test_must_fail git cat-file blob $blob_1 > /dev/null &&
73
test_must_fail git cat-file blob $blob_2 > /dev/null &&
74
test_must_fail git cat-file blob $blob_3 > /dev/null'
@@ -125,7 +127,7 @@ test_expect_success \
127
'create corruption in header of first delta' \
128
'create_new_pack &&
129
git prune-packed &&
128
- do_corrupt_object $blob_2 0 < /dev/zero &&
130
+ do_corrupt_object $blob_2 0 < zero &&
131
git cat-file blob $blob_1 > /dev/null &&
132
test_must_fail git cat-file blob $blob_2 > /dev/null &&
133
test_must_fail git cat-file blob $blob_3 > /dev/null'
@@ -180,7 +182,7 @@ test_expect_success \
182
'corruption in delta base reference of first delta (OBJ_REF_DELTA)' \
183
'create_new_pack &&
184
git prune-packed &&
183
- do_corrupt_object $blob_2 2 < /dev/zero &&
185
+ do_corrupt_object $blob_2 2 < zero &&
186
git cat-file blob $blob_1 > /dev/null &&
187
test_must_fail git cat-file blob $blob_2 > /dev/null &&
188
test_must_fail git cat-file blob $blob_3 > /dev/null'
@@ -207,7 +209,7 @@ test_expect_success \
209
'corruption #0 in delta base reference of first delta (OBJ_OFS_DELTA)' \
210
'create_new_pack --delta-base-offset &&
211
git prune-packed &&
210
- do_corrupt_object $blob_2 2 < /dev/zero &&
212
+ do_corrupt_object $blob_2 2 < zero &&
213
git cat-file blob $blob_1 > /dev/null &&
214
test_must_fail git cat-file blob $blob_2 > /dev/null &&
215
test_must_fail git cat-file blob $blob_3 > /dev/null'
@@ -259,7 +261,7 @@ test_expect_success \
261
262
test_expect_success \
263
'... and a redundant pack allows for full recovery too' \
262
- 'do_corrupt_object $blob_2 2 < /dev/zero &&
264
+ 'do_corrupt_object $blob_2 2 < zero &&
265
git cat-file blob $blob_1 > /dev/null &&
266
test_must_fail git cat-file blob $blob_2 > /dev/null &&
267
test_must_fail git cat-file blob $blob_3 > /dev/null &&