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 #204 from darrenldl/dev
Browse files Browse the repository at this point in the history
Test suite overhaul
  • Loading branch information
darrenldl committed May 26, 2019
2 parents 0c597e0 + 646925a commit 072687d
Show file tree
Hide file tree
Showing 39 changed files with 2,120 additions and 503 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -51,9 +51,8 @@ script:
- bash ci/script.sh
- rm -rf target/cov
- bash install_kcov.sh
- bash cov.sh
- bash tests/dev_tests.sh
- bash cov_tests/dev_tests.sh
- bash cov.sh

addons:
apt:
Expand Down
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -3,7 +3,6 @@
[![Build Status](https://travis-ci.org/darrenldl/blockyarchive.svg?branch=master)](https://travis-ci.org/darrenldl/blockyarchive)
[![Build status](https://ci.appveyor.com/api/projects/status/i4dxpldp4t312gtv?svg=true)](https://ci.appveyor.com/project/darrenldl/blockyarchive)
[![codecov](https://codecov.io/gh/darrenldl/blockyarchive/branch/master/graph/badge.svg)](https://codecov.io/gh/darrenldl/blockyarchive)
[![Coverage Status](https://coveralls.io/repos/github/darrenldl/blockyarchive/badge.svg?branch=master)](https://coveralls.io/github/darrenldl/blockyarchive?branch=master)
[![Crates](https://img.shields.io/crates/v/blkar.svg)](https://crates.io/crates/blkar)
[![dependency status](https://deps.rs/repo/github/darrenldl/blockyarchive/status.svg)](https://deps.rs/repo/github/darrenldl/blockyarchive)
[![Gitter chat](https://badges.gitter.im/blockyarchive/gitter.png)](https://gitter.im/blockyarchive/community)
Expand Down
39 changes: 29 additions & 10 deletions cov.sh
Expand Up @@ -7,23 +7,42 @@ if [[ $TRAVIS == true ]]; then
fi

if [[ $TRAVIS == true ]]; then
TARGET=$HOME/kcov
export PATH=$TARGET/bin:$PATH
export PATH=$HOME/kcov/bin:$PATH
fi

# export RUSTFLAGS="-C link-dead-code"

echo "Running cargo tests"
echo "========================================"
rm -rf target/debug/
cargo build --tests
if [[ $? != 0 ]]; then
exit 1
exit 1
fi

files=(target/debug/blkar)
COV_DIR="target/cov/cargo-tests"
for file in target/debug/blkar_lib-*; do
if [[ $file == *.d ]]; then
continue
fi

#for file in target/debug/blkar-*[^\.d]; do
# for file in ${files[@]}; do
for file in target/debug/blkar_lib-*; do if [[ $file == *.d ]]; then continue; fi
# mkdir -p "target/cov/$(basename $file)"
mkdir -p "target/cov/blkar"
kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/blkar" "$file"
mkdir -p $COV_DIR
kcov --exclude-pattern=/.cargo,/usr/lib --verify $COV_DIR "$file"
done

echo ""
echo "Running binary tests"
echo "========================================"
cd cov_tests/
./dev_tests.sh
if [[ $? != 0 ]]; then
exit 1
fi
cd ..

echo ""
echo "Merging all code coverage reports"
echo "========================================"
rm -rf target/cov/total
mkdir -p target/cov/total
kcov --merge target/cov/total $COV_DIR target/cov/bin-tests
34 changes: 16 additions & 18 deletions cov_tests/burst_corruption_tests.sh
Expand Up @@ -6,38 +6,36 @@ exit_code=0

VERSIONS=(17)

corrupt() {
dd if=/dev/zero of=$4 bs=$2 count=$3 seek=$1 conv=notrunc &>/dev/null
}
source functions.sh

file_size=$[1024 * 2]
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 % 5))
parity_shards=$((1 + RANDOM % 5))
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
burst=$((1 + RANDOM % 10))
elif [[ $ver == 18 ]]; then
data_shards=$((1 + RANDOM % 5))
parity_shards=$((1 + RANDOM % 5))
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
burst=$((1 + RANDOM % 10))
else
data_shards=$((1 + RANDOM % 5))
parity_shards=$((1 + RANDOM % 5))
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=$(kcov_blkar encode --json --sbx-version $ver -f dummy $container_name \
--hash sha1 \
--rs-data $data_shards --rs-parity $parity_shards \
--burst $burst)
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
Expand All @@ -56,7 +54,7 @@ for ver in ${VERSIONS[*]}; do
fi

echo -n "Checking burst error resistance level"
output=$(kcov_blkar show --json --guess-burst $container_name)
output=$(blkar show --json --guess-burst $container_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
Expand Down Expand Up @@ -84,7 +82,7 @@ for ver in ${VERSIONS[*]}; do
done

echo -n "Repairing"
output=$(kcov_blkar repair --json --verbose $container_name)
output=$(blkar repair --json --verbose $container_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
Expand All @@ -99,7 +97,7 @@ for ver in ${VERSIONS[*]}; do
output_name=dummy_$data_shards\_$parity_shards

echo -n "Decoding"
output=$(kcov_blkar decode --json -f $container_name $output_name)
output=$(blkar decode --json -f $container_name $output_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
Expand All @@ -122,4 +120,4 @@ for ver in ${VERSIONS[*]}; do
done
done

exit $exit_code
echo $exit_code > exit_code
87 changes: 87 additions & 0 deletions cov_tests/check_hash_tests.sh
@@ -0,0 +1,87 @@
#!/bin/bash

source kcov_blkar_fun.sh

exit_code=0

VERSIONS=(1 17)

source functions.sh

# Encode in all 6 versions
for ver in ${VERSIONS[*]}; do
for c in 0 1; do
echo -n "Generating container of version $ver, copy #$c"
corrupt 1000 dummy
output=$(blkar encode --uid DEADBEEF0123 --json --sbx-version $ver -f dummy dummy$ver.$c.sbx \
--rs-data 10 --rs-parity 2)
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
done
done

# Check hash of all containers
for ver in ${VERSIONS[*]}; do
if [[ $ver == 1 || $ver == 17 ]]; then
block_size=512
elif [[ $ver == 2 || $ver == 18 ]]; then
block_size=128
elif [[ $ver == 3 || $ver == 19 ]]; then
block_size=4096
fi

echo -n "Checking container version $ver, copy #0"
output=$(blkar check --hash --json --pv 2 --verbose dummy$ver.0.sbx 2>/dev/null)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.numberOfBlocksFailedCheck") == 0 ]]; then
echo -n " ==> Okay"
else
echo -n " ==> NOT okay"
exit_code=1
fi
recorded_hash=$(echo $output | jq -r ".stats.recordedHash" | awk '{ print $3 }')
stored_data_hash=$(echo $output | jq -r ".stats.hashOfStoredData" | awk '{ print $3 }')
if [[ $recorded_hash == $stored_data_hash ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

echo "Overwriting first block of copy #0 with copy #1"
dd if=dummy$ver.1.sbx of=dummy$ver.0.sbx bs=$block_size count=1 conv=notrunc &>/dev/null

echo -n "Checking container version $ver, copy #0 after overwrite"
output=$(blkar check --hash --json --pv 2 --verbose dummy$ver.0.sbx 2>/dev/null)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.numberOfBlocksFailedCheck") == 0 ]]; then
echo -n " ==> Okay"
else
echo -n " ==> NOT okay"
exit_code=1
fi
recorded_hash=$(echo $output | jq -r ".stats.recordedHash" | awk '{ print $3 }')
stored_data_hash=$(echo $output | jq -r ".stats.hashOfStoredData" | awk '{ print $3 }')
if [[ $recorded_hash != $stored_data_hash ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi
done

echo $exit_code > exit_code
51 changes: 42 additions & 9 deletions cov_tests/clean.sh
@@ -1,19 +1,52 @@
#!/bin/bash

if [[ $PWD != */cov_tests ]]; then
cd cov_tests
if [[ $PWD != */blockyarchive/cov_tests ]]; then
echo "Please invoke clean.sh in the cov_tests directory"
exit 1
fi

rm dummy* &>/dev/null
source test_list.sh

rm *.sbx &>/dev/null
rm -f dummy*

rm rescued_data/* &>/dev/null
rm -f *.sbx

rm rescued_data2/* &>/dev/null
rm -f *.ecsbx

rm rescue_log &>/dev/null
rm -f rescued_data/*

rm filler* &>/dev/null
rm -f rescued_data2/*

rm out_test/* &>/dev/null
rm -f rescue_log

rm -f filler*

rm -f out_test/*

rm -f sort_*.sbx.*

rm -f sort_*.ecsbx.*

rm -f exit_code

rm -f ../blkar

rm -f data_chunk

rm -f data_chunk_orig

rm -f chunk_*

rm -f decode*.sbx.*

rm -f decode*.ecsbx.*

find . -regextype sed -regex "./sort_[0-9]*_[0-9]*_[0-9]*" -delete

find . -regextype sed -regex "./decode_[0-9]*_[0-9]*_[0-9]*" -delete

for t in ${tests[@]}; do
if [[ "$t" != "" ]]; then
rm -rf $t
fi
done
1 change: 0 additions & 1 deletion cov_tests/copy.sh
Expand Up @@ -7,4 +7,3 @@ cargo build

echo "Copying blkar binary over"
cp target/debug/blkar ./cov_tests/blkar
cd cov_tests
30 changes: 14 additions & 16 deletions cov_tests/corruption_tests.sh
Expand Up @@ -6,34 +6,32 @@ exit_code=0

VERSIONS=(17)

corrupt() {
dd if=/dev/zero of=$2 bs=1 count=1 seek=$1 conv=notrunc &>/dev/null
}
source functions.sh

file_size=$[1024 * 2]
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 % 5))
parity_shards=$((1 + RANDOM % 5))
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
elif [[ $ver == 18 ]]; then
data_shards=$((1 + RANDOM % 5))
parity_shards=$((1 + RANDOM % 5))
data_shards=$((1 + RANDOM % 128))
parity_shards=$((1 + RANDOM % 128))
else
data_shards=$((1 + RANDOM % 5))
parity_shards=$((1 + RANDOM % 5))
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=$(kcov_blkar encode --json --sbx-version $ver -f dummy $container_name \
--hash sha1 \
--rs-data $data_shards --rs-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
Expand All @@ -59,7 +57,7 @@ for ver in ${VERSIONS[*]}; do
done

echo -n "Repairing"
output=$(kcov_blkar repair --json --verbose $container_name)
output=$(blkar repair --json --verbose $container_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
Expand All @@ -74,7 +72,7 @@ for ver in ${VERSIONS[*]}; do
output_name=dummy_$data_shards\_$parity_shards

echo -n "Decoding"
output=$(kcov_blkar decode --json -f $container_name $output_name)
output=$(blkar decode --json -f $container_name $output_name)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
Expand All @@ -97,4 +95,4 @@ for ver in ${VERSIONS[*]}; do
done
done

exit $exit_code
echo $exit_code > exit_code

0 comments on commit 072687d

Please sign in to comment.