Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #208 from darrenldl/dev
Browse files Browse the repository at this point in the history
Coverage test suite update
  • Loading branch information
darrenldl authored Jun 9, 2019
2 parents 5dd8198 + 6aca8c1 commit ba002d9
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ if [[ $? != 0 ]]; then
fi
cd ..

echo ""
echo "========================================"
echo ""
echo "Merging all code coverage reports"
echo ""
echo "========================================"
rm -rf target/cov/total
mkdir -p target/cov/total
Expand Down
123 changes: 123 additions & 0 deletions cov_tests/burst_corruption_tests_decode_stdout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash

source kcov_blkar_fun.sh

exit_code=0

VERSIONS=(17)

source functions.sh

file_size=$(ls -l dummy | awk '{ print $5 }')

# generate test data
dd if=/dev/urandom of=dummy bs=$file_size count=1 &>/dev/null

for ver in ${VERSIONS[*]}; do
for (( i=0; i < 1; i++ )); do
if [[ $ver == 17 ]]; then
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
burst=$((1 + RANDOM % 10))
elif [[ $ver == 18 ]]; then
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
burst=$((1 + RANDOM % 10))
else
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
burst=$((1 + RANDOM % 10))
fi

container_name=burst_$data_shards\_$parity_shards\_$burst\_$ver.sbx

echo -n "Encoding"
output=$(./../blkar encode --json --sbx-version $ver -f dummy $container_name \
--hash sha1 \
--rs-data $data_shards --rs-parity $parity_shards \
--burst $burst)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.sbxVersion") == "$ver" ]]; then
echo -n " ==> Okay"
else
echo -n " ==> NOT okay"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.hash" | awk '{ print $1 }') == "SHA1" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

echo -n "Checking burst error resistance level"
output=$(./../blkar show --json --guess-burst $container_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".bestGuessForBurstErrorResistanceLevel") == $burst ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

if [[ $ver == 17 ]]; then
block_size=512
elif [[ $ver == 18 ]]; then
block_size=128
else
block_size=4096
fi

echo "Corrupting at $parity_shards random positions, burst error size is $burst"
for (( p=0; p < $parity_shards; p++ )); do
pos=$(( (RANDOM % $file_size) / $block_size ))
# echo "#$p corruption, corrupting byte at position : $pos"
corrupt $pos $block_size $burst $container_name
done

echo -n "Repairing"
output=$(./../blkar repair --json --verbose $container_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.sbxVersion") == "$ver" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

output_name=dummy_$data_shards\_$parity_shards

echo -n "Decoding"
output=$(./../blkar decode --json -f $container_name - 2>&1 > $output_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.sbxVersion") == "$ver" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

echo -n "Comparing decoded data to original"
cmp dummy $output_name
if [[ $? == 0 ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi
done
done

echo $exit_code > exit_code
98 changes: 98 additions & 0 deletions cov_tests/corruption_tests_decode_stdout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash

source kcov_blkar_fun.sh

exit_code=0

VERSIONS=(17)

source functions.sh

file_size=$(ls -l dummy | awk '{ print $5 }')

# generate test data
dd if=/dev/urandom of=dummy bs=$file_size count=1 &>/dev/null

for ver in ${VERSIONS[*]}; do
for (( i=0; i < 1; i++ )); do
if [[ $ver == 17 ]]; then
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
elif [[ $ver == 18 ]]; then
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
else
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
fi

container_name=corrupt_$data_shards\_$parity_shards\_$ver.sbx

echo -n "Encoding in version $ver, data = $data_shards, parity = $parity_shards"
output=$(./../blkar encode --json --sbx-version $ver -f dummy $container_name \
--hash sha1 \
--rs-data $data_shards --rs-parity $parity_shards)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.sbxVersion") == "$ver" ]]; then
echo -n " ==> Okay"
else
echo -n " ==> NOT okay"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.hash" | awk '{ print $1 }') == "SHA1" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

echo "Corrupting at $parity_shards random positions"
for (( p=0; p < $parity_shards; p++ )); do
pos=$((RANDOM % $file_size))
# echo "#$p corruption, corrupting byte at position : $pos"
corrupt $pos $container_name
done

echo -n "Repairing"
output=$(./../blkar repair --json --verbose $container_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.sbxVersion") == "$ver" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

output_name=dummy_$data_shards\_$parity_shards

echo -n "Decoding"
output=$(./../blkar decode --json -f $container_name - 2>&1 > $output_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.sbxVersion") == "$ver" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

echo -n "Comparing decoded data to original"
cmp dummy $output_name
if [[ $? == 0 ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi
done
done

echo $exit_code > exit_code
5 changes: 3 additions & 2 deletions cov_tests/hash_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ source kcov_blkar_fun.sh

exit_code=0

HASHES=("sha1")
HASHES=("sha1" "sha256" "sha512" "blake2b-256" "blake2b-512")

# Record the hashes
a[0]=$(sha1sum dummy | awk '{print $1}')
a[1]=$(sha256sum dummy | awk '{print $1}')
a[2]=$(sha512sum dummy | awk '{print $1}')
if [[ $(command -v b2sum) != "" ]]; then
a[3]=$(b2sum dummy | awk '{print $1}')
a[3]=$(b2sum -l 256 dummy | awk '{print $1}')
a[4]=$(b2sum dummy | awk '{print $1}')
fi

# Encode in all 4 hashes
Expand Down

0 comments on commit ba002d9

Please sign in to comment.