improve index-pack tests
Commit9441b61dc5
introduced serious bugs in index-pack which are described and fixed by commitce3f6dc655
. However, despite the boldness of those bugs, the test suite still passed. This improves t5302-pack-index.sh so to ensure a much better code path coverage. With commitce3f6dc655
reverted, 17 of the 26 tests do fail now. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
ce3f6dc655
commit
2b5c208f5b
@ -11,13 +11,18 @@ test_expect_success \
|
|||||||
'rm -rf .git
|
'rm -rf .git
|
||||||
git init &&
|
git init &&
|
||||||
i=1 &&
|
i=1 &&
|
||||||
while test $i -le 100
|
while test $i -le 100
|
||||||
do
|
do
|
||||||
i=`printf '%03i' $i`
|
iii=`printf '%03i' $i`
|
||||||
echo $i >file_$i &&
|
test-genrandom "bar" 200 > wide_delta_$iii &&
|
||||||
test-genrandom "$i" 8192 >>file_$i &&
|
test-genrandom "baz $iii" 50 >> wide_delta_$iii &&
|
||||||
git update-index --add file_$i &&
|
test-genrandom "foo"$i 100 > deep_delta_$iii &&
|
||||||
i=`expr $i + 1` || return 1
|
test-genrandom "foo"`expr $i + 1` 100 >> deep_delta_$iii &&
|
||||||
|
test-genrandom "foo"`expr $i + 2` 100 >> deep_delta_$iii &&
|
||||||
|
echo $iii >file_$iii &&
|
||||||
|
test-genrandom "$iii" 8192 >>file_$iii &&
|
||||||
|
git update-index --add file_$iii deep_delta_$iii wide_delta_$iii &&
|
||||||
|
i=`expr $i + 1` || return 1
|
||||||
done &&
|
done &&
|
||||||
{ echo 101 && test-genrandom 100 8192; } >file_101 &&
|
{ echo 101 && test-genrandom 100 8192; } >file_101 &&
|
||||||
git update-index --add file_101 &&
|
git update-index --add file_101 &&
|
||||||
@ -92,6 +97,31 @@ test_expect_success \
|
|||||||
'64-bit offsets: index-pack result should match pack-objects one' \
|
'64-bit offsets: index-pack result should match pack-objects one' \
|
||||||
'cmp "test-3-${pack3}.idx" "3.idx"'
|
'cmp "test-3-${pack3}.idx" "3.idx"'
|
||||||
|
|
||||||
|
# returns the object number for given object in given pack index
|
||||||
|
index_obj_nr()
|
||||||
|
{
|
||||||
|
idx_file=$1
|
||||||
|
object_sha1=$2
|
||||||
|
nr=0
|
||||||
|
git show-index < $idx_file |
|
||||||
|
while read offs sha1 extra
|
||||||
|
do
|
||||||
|
nr=$(($nr + 1))
|
||||||
|
test "$sha1" = "$object_sha1" || continue
|
||||||
|
echo "$(($nr - 1))"
|
||||||
|
break
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# returns the pack offset for given object as found in given pack index
|
||||||
|
index_obj_offset()
|
||||||
|
{
|
||||||
|
idx_file=$1
|
||||||
|
object_sha1=$2
|
||||||
|
git show-index < $idx_file | grep $object_sha1 |
|
||||||
|
( read offs extra && echo "$offs" )
|
||||||
|
}
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'[index v1] 1) stream pack to repository' \
|
'[index v1] 1) stream pack to repository' \
|
||||||
'git index-pack --index-version=1 --stdin < "test-1-${pack1}.pack" &&
|
'git index-pack --index-version=1 --stdin < "test-1-${pack1}.pack" &&
|
||||||
@ -102,19 +132,22 @@ test_expect_success \
|
|||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'[index v1] 2) create a stealth corruption in a delta base reference' \
|
'[index v1] 2) create a stealth corruption in a delta base reference' \
|
||||||
'# this test assumes a delta smaller than 16 bytes at the end of the pack
|
'# This test assumes file_101 is a delta smaller than 16 bytes.
|
||||||
git show-index <1.idx | sort -n | sed -ne \$p | (
|
# It should be against file_100 but we substitute its base for file_099
|
||||||
read delta_offs delta_sha1 &&
|
sha1_101=`git hash-object file_101` &&
|
||||||
git cat-file blob "$delta_sha1" > blob_1 &&
|
sha1_099=`git hash-object file_099` &&
|
||||||
chmod +w ".git/objects/pack/pack-${pack1}.pack" &&
|
offs_101=`index_obj_offset 1.idx $sha1_101` &&
|
||||||
dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($delta_offs + 1)) \
|
nr_099=`index_obj_nr 1.idx $sha1_099` &&
|
||||||
if=".git/objects/pack/pack-${pack1}.idx" skip=$((256 * 4 + 4)) \
|
chmod +w ".git/objects/pack/pack-${pack1}.pack" &&
|
||||||
bs=1 count=20 conv=notrunc &&
|
dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \
|
||||||
git cat-file blob "$delta_sha1" > blob_2 )'
|
if=".git/objects/pack/pack-${pack1}.idx" \
|
||||||
|
skip=$((4 + 256 * 4 + $nr_099 * 24)) \
|
||||||
|
bs=1 count=20 conv=notrunc &&
|
||||||
|
git cat-file blob $sha1_101 > file_101_foo1'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'[index v1] 3) corrupted delta happily returned wrong data' \
|
'[index v1] 3) corrupted delta happily returned wrong data' \
|
||||||
'! cmp blob_1 blob_2'
|
'test -f file_101_foo1 && ! cmp file_101 file_101_foo1'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'[index v1] 4) confirm that the pack is actually corrupted' \
|
'[index v1] 4) confirm that the pack is actually corrupted' \
|
||||||
@ -140,19 +173,22 @@ test_expect_success \
|
|||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'[index v2] 2) create a stealth corruption in a delta base reference' \
|
'[index v2] 2) create a stealth corruption in a delta base reference' \
|
||||||
'# this test assumes a delta smaller than 16 bytes at the end of the pack
|
'# This test assumes file_101 is a delta smaller than 16 bytes.
|
||||||
git show-index <1.idx | sort -n | sed -ne \$p | (
|
# It should be against file_100 but we substitute its base for file_099
|
||||||
read delta_offs delta_sha1 delta_crc &&
|
sha1_101=`git hash-object file_101` &&
|
||||||
git cat-file blob "$delta_sha1" > blob_3 &&
|
sha1_099=`git hash-object file_099` &&
|
||||||
chmod +w ".git/objects/pack/pack-${pack1}.pack" &&
|
offs_101=`index_obj_offset 1.idx $sha1_101` &&
|
||||||
dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($delta_offs + 1)) \
|
nr_099=`index_obj_nr 1.idx $sha1_099` &&
|
||||||
if=".git/objects/pack/pack-${pack1}.idx" skip=$((8 + 256 * 4)) \
|
chmod +w ".git/objects/pack/pack-${pack1}.pack" &&
|
||||||
bs=1 count=20 conv=notrunc &&
|
dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \
|
||||||
git cat-file blob "$delta_sha1" > blob_4 )'
|
if=".git/objects/pack/pack-${pack1}.idx" \
|
||||||
|
skip=$((8 + 256 * 4 + $nr_099 * 20)) \
|
||||||
|
bs=1 count=20 conv=notrunc &&
|
||||||
|
git cat-file blob $sha1_101 > file_101_foo2'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'[index v2] 3) corrupted delta happily returned wrong data' \
|
'[index v2] 3) corrupted delta happily returned wrong data' \
|
||||||
'! cmp blob_3 blob_4'
|
'test -f file_101_foo2 && ! cmp file_101 file_101_foo2'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'[index v2] 4) confirm that the pack is actually corrupted' \
|
'[index v2] 4) confirm that the pack is actually corrupted' \
|
||||||
@ -167,9 +203,11 @@ test_expect_success \
|
|||||||
'rm -f .git/objects/pack/* &&
|
'rm -f .git/objects/pack/* &&
|
||||||
git index-pack --index-version=2 --stdin < "test-1-${pack1}.pack" &&
|
git index-pack --index-version=2 --stdin < "test-1-${pack1}.pack" &&
|
||||||
git verify-pack ".git/objects/pack/pack-${pack1}.pack" &&
|
git verify-pack ".git/objects/pack/pack-${pack1}.pack" &&
|
||||||
|
obj=`git hash-object file_001` &&
|
||||||
|
nr=`index_obj_nr ".git/objects/pack/pack-${pack1}.idx" $obj` &&
|
||||||
chmod +w ".git/objects/pack/pack-${pack1}.idx" &&
|
chmod +w ".git/objects/pack/pack-${pack1}.idx" &&
|
||||||
dd if=/dev/zero of=".git/objects/pack/pack-${pack1}.idx" conv=notrunc \
|
dd if=/dev/zero of=".git/objects/pack/pack-${pack1}.idx" conv=notrunc \
|
||||||
bs=1 count=4 seek=$((8 + 256 * 4 + `wc -l <obj-list` * 20 + 0)) &&
|
bs=1 count=4 seek=$((8 + 256 * 4 + `wc -l <obj-list` * 20 + $nr * 4)) &&
|
||||||
( while read obj
|
( while read obj
|
||||||
do git cat-file -p $obj >/dev/null || exit 1
|
do git cat-file -p $obj >/dev/null || exit 1
|
||||||
done <obj-list ) &&
|
done <obj-list ) &&
|
||||||
|
Reference in New Issue
Block a user