From 2ee0a8743942e7080eb6d5610de66a0fa8f40379 Mon Sep 17 00:00:00 2001 From: John Jones Date: Thu, 5 Oct 2017 11:20:12 -0500 Subject: [PATCH] Adjusting test scripts to make it easier to spot failures. --- test/scripts/run_test.sh | 15 ++++++++--- test/scripts/run_tests.sh | 34 +++++++++++++++++++------ test/scripts/test_1.sh | 17 +++++++------ test/scripts/test_2.sh | 6 ++--- test/scripts/test_3.sh | 6 ++--- test/scripts/test_4.sh | 8 +++--- test/scripts/test_5.sh | 8 +++--- test/scripts/test_6.sh | 6 ++--- test/scripts/test_7.sh | 8 +++--- test/scripts/test_8.sh | 49 ++++++++++++++++++++++++++++++++++++ test/scripts/test_9.sh | 45 +++++++++++++++++++++++++++++++++ test/scripts/test_helpers.sh | 31 +++++++++++++++++++++-- 12 files changed, 191 insertions(+), 42 deletions(-) create mode 100755 test/scripts/test_8.sh create mode 100755 test/scripts/test_9.sh diff --git a/test/scripts/run_test.sh b/test/scripts/run_test.sh index 79ea10b..7b0635a 100755 --- a/test/scripts/run_test.sh +++ b/test/scripts/run_test.sh @@ -1,10 +1,17 @@ #!/bin/bash -TEST_FILE=$1 +TEST_FILE=test_$1.sh + +test_success=0 source ./$TEST_FILE -pre -body -post +function do_it() { + pre + body + post + return $? +} +do_it +exit $test_success diff --git a/test/scripts/run_tests.sh b/test/scripts/run_tests.sh index fd64437..20affc7 100755 --- a/test/scripts/run_tests.sh +++ b/test/scripts/run_tests.sh @@ -1,9 +1,29 @@ #!/bin/bash -./run_test.sh test_1.sh -./run_test.sh test_2.sh -./run_test.sh test_3.sh -./run_test.sh test_4.sh -./run_test.sh test_5.sh -./run_test.sh test_6.sh -./run_test.sh test_7.sh +#source ./test_helpers.sh + +rm testlog.txt + +num_tests=9 +tests_passed=0 +tests_failed=0 +i=1 +while [ $i -le $num_tests ]; do + echo *Running test number $i + echo *Running test number $i >> testlog.txt + ./run_test.sh $i >>testlog.txt 2>&1 + retVal=$? + if [ $retVal -ne 0 ]; then + echo *Test number $i failed + echo *Test number $i failed >> testlog.txt + let tests_failed++ + else + echo *Test number $i passed + echo *Test number $i passed >> testlog.txt + let tests_passed++ + fi + let i++ +done +echo Of $num_tests tests, $tests_passed passed and $tests_failed failed. +echo Of $num_tests tests, $tests_passed passed and $tests_failed failed. >> testlog.txt +echo Results are in testlog.txt diff --git a/test/scripts/test_1.sh b/test/scripts/test_1.sh index bbe35aa..97d890a 100755 --- a/test/scripts/test_1.sh +++ b/test/scripts/test_1.sh @@ -1,7 +1,7 @@ #!/bin/bash #### -# Attempt to retrieve binary file from running daemon +# Attempt to retrieve large binary file from running daemon # #### @@ -12,7 +12,7 @@ IPFS="../../main/ipfs --config /tmp/ipfs_1" function pre { rm -Rf /tmp/ipfs_1 eval "$IPFS" init; - check_failure "pre" $? + check_failure_with_exit "pre" $? cp ../config.test1.wo_journal /tmp/ipfs_1/config } @@ -23,22 +23,23 @@ function post { } function body { - create_binary_file; + create_binary_file 512; eval "$IPFS" add hello.bin - check_failure "add hello.bin" $? + check_failure_with_exit "add hello.bin" $? #start the daemon eval "../../main/ipfs --config /tmp/ipfs_1 daemon &" daemon_id=$! sleep 5 - eval "$IPFS" cat QmX4zpwaE7CSgZZsULgoB3gXYC6hh7RN19bEfWxw7sL8Xx > hello2.bin - check_failure "cat" $? + eval "$IPFS" cat QmVGA3bXDJ41xoT621xQNzQgtBMQHj2AYxaunLBJtSoNgg > hello2.bin + check_failure_with_exit "cat" $? - # file size should be 256 + # file size should be 512 actualsize=$(wc -c < hello2.bin) - if [ $actualsize -ne 256 ]; then + if [ $actualsize -ne 512 ]; then echo '*** Failure *** file size incorrect' + exit 1 fi kill -9 $daemon_id diff --git a/test/scripts/test_2.sh b/test/scripts/test_2.sh index cdd4033..2b27615 100755 --- a/test/scripts/test_2.sh +++ b/test/scripts/test_2.sh @@ -7,7 +7,7 @@ IPFS="../../main/ipfs --config /tmp/ipfs_1" function pre { post eval "$IPFS" init; - check_failure "pre" $? + check_failure_with_exit "pre" $? } function post { @@ -18,10 +18,10 @@ function post { function body { create_hello_world; eval "$IPFS" add hello.txt - check_failure "add hello.txt" $? + check_failure_with_exit "add hello.txt" $? eval "$IPFS" cat QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH - check_failure "cat hello.txt" $? + check_failure_with_exit "cat hello.txt" $? } diff --git a/test/scripts/test_3.sh b/test/scripts/test_3.sh index 283ea48..c564139 100755 --- a/test/scripts/test_3.sh +++ b/test/scripts/test_3.sh @@ -12,7 +12,7 @@ IPFS="../../main/ipfs --config /tmp/ipfs_1" function pre { post eval "$IPFS" init; - check_failure "pre" $? + check_failure_with_exit "pre" $? } function post { @@ -23,7 +23,7 @@ function post { function body { create_hello_world; eval "$IPFS" add hello.txt - check_failure "add hello.txt" $? + check_failure_with_exit "add hello.txt" $? #start the daemon eval "../../main/ipfs --config /tmp/ipfs_1 daemon &" @@ -31,7 +31,7 @@ function body { sleep 5 eval "$IPFS" cat QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH - check_failure "cat hello.txt" $? + check_failure_with_exit "cat hello.txt" $? kill -9 $daemon_id } diff --git a/test/scripts/test_4.sh b/test/scripts/test_4.sh index 3e93cfc..2bef821 100755 --- a/test/scripts/test_4.sh +++ b/test/scripts/test_4.sh @@ -12,7 +12,7 @@ IPFS="../../main/ipfs --config /tmp/ipfs_1" function pre { post eval "$IPFS" init; - check_failure "pre" $? + check_failure_with_exit "pre" $? cp ../config.test1.wo_journal /tmp/ipfs_1/config } @@ -24,7 +24,7 @@ function post { function body { create_hello_world; eval "$IPFS" add hello.txt - check_failure "add hello.txt" $? + check_failure_with_exit "add hello.txt" $? #start the daemon eval "../../main/ipfs --config /tmp/ipfs_1 daemon &" @@ -32,10 +32,10 @@ function body { sleep 5 eval "$IPFS" name publish QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH - check_failure "name publish" $? + check_failure_with_exit "name publish" $? eval "$IPFS" name resolve /ipns/QmZVoAZGFfinB7MQQiDzB84kWaDPQ95GLuXdemJFM2r9b4 - check_failure "name resolve" $? + check_failure_with_exit "name resolve" $? kill -9 $daemon_id } diff --git a/test/scripts/test_5.sh b/test/scripts/test_5.sh index 291d3f3..09373f3 100755 --- a/test/scripts/test_5.sh +++ b/test/scripts/test_5.sh @@ -12,11 +12,11 @@ IPFS2="../../main/ipfs --config /tmp/ipfs_2" function pre { post eval "$IPFS1" init; - check_failure "pre" $? + check_failure_with_exit "pre" $? cp ../config.test1.wo_journal /tmp/ipfs_1/config eval "$IPFS2" init; - check_failure "pre ipfs2" $? + check_failure_with_exit "pre ipfs2" $? cp ../config.test2.wo_journal /tmp/ipfs_2/config } @@ -29,7 +29,7 @@ function post { function body { create_hello_world; eval "$IPFS1" add hello.txt - check_failure "add hello.txt" $? + check_failure_with_exit "add hello.txt" $? #start the daemons eval "../../main/ipfs --config /tmp/ipfs_1 daemon &" @@ -40,7 +40,7 @@ function body { #A client of server 2 wants the file at server 1 eval "$IPFS2" cat QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH - check_failure "cat" $? + check_failure_with_exit "cat" $? kill -9 $daemon_id_1 kill -9 $daemon_id_2 diff --git a/test/scripts/test_6.sh b/test/scripts/test_6.sh index cd2e06e..16115c3 100755 --- a/test/scripts/test_6.sh +++ b/test/scripts/test_6.sh @@ -12,7 +12,7 @@ IPFS="../../main/ipfs --config /tmp/ipfs_1" function pre { post eval "$IPFS" init; - check_failure "pre" $? + check_failure_with_exit "pre" $? cp ../config.test1.wo_journal /tmp/ipfs_1/config } @@ -24,7 +24,7 @@ function post { function body { create_hello_world; eval "$IPFS" add hello.txt - check_failure "add hello.txt" $? + check_failure_with_exit "add hello.txt" $? #start the daemon eval "../../main/ipfs --config /tmp/ipfs_1 daemon &" @@ -32,7 +32,7 @@ function body { sleep 5 eval "$IPFS" name publish QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH - check_failure "name publish" $? + check_failure_with_exit "name publish" $? kill -9 $daemon_id } diff --git a/test/scripts/test_7.sh b/test/scripts/test_7.sh index 376e6f0..a066062 100755 --- a/test/scripts/test_7.sh +++ b/test/scripts/test_7.sh @@ -12,7 +12,7 @@ IPFS="../../main/ipfs --config /tmp/ipfs_1" function pre { rm -Rf /tmp/ipfs_1 eval "$IPFS" init; - check_failure "pre" $? + check_failure_with_exit "pre" $? cp ../config.test1.wo_journal /tmp/ipfs_1/config } @@ -23,7 +23,7 @@ function post { } function body { - create_binary_file; + create_binary_file 256; #start the daemon eval "../../main/ipfs --config /tmp/ipfs_1 daemon &" @@ -32,12 +32,12 @@ function body { # add file eval "$IPFS" add hello.bin - check_failure "add hello.bin" $? + check_failure_with_exit "add hello.bin" $? sleep 5 # retrieve file eval "$IPFS" cat QmX4zpwaE7CSgZZsULgoB3gXYC6hh7RN19bEfWxw7sL8Xx > hello2.bin - check_failure "cat" $? + check_failure_with_exit "cat" $? # file size should be 256 actualsize=$(wc -c < hello2.bin) diff --git a/test/scripts/test_8.sh b/test/scripts/test_8.sh new file mode 100755 index 0000000..a066062 --- /dev/null +++ b/test/scripts/test_8.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +#### +# Attempt to add and retrieve binary file from running daemon +# +#### + +source ./test_helpers.sh + +IPFS="../../main/ipfs --config /tmp/ipfs_1" + +function pre { + rm -Rf /tmp/ipfs_1 + eval "$IPFS" init; + check_failure_with_exit "pre" $? + cp ../config.test1.wo_journal /tmp/ipfs_1/config +} + +function post { + rm -Rf /tmp/ipfs_1; + rm hello.bin; + rm hello2.bin; +} + +function body { + create_binary_file 256; + + #start the daemon + eval "../../main/ipfs --config /tmp/ipfs_1 daemon &" + daemon_id=$! + sleep 5 + + # add file + eval "$IPFS" add hello.bin + check_failure_with_exit "add hello.bin" $? + sleep 5 + + # retrieve file + eval "$IPFS" cat QmX4zpwaE7CSgZZsULgoB3gXYC6hh7RN19bEfWxw7sL8Xx > hello2.bin + check_failure_with_exit "cat" $? + + # file size should be 256 + actualsize=$(wc -c < hello2.bin) + if [ $actualsize -ne 256 ]; then + echo '*** Failure *** file size incorrect' + fi + + kill -9 $daemon_id +} diff --git a/test/scripts/test_9.sh b/test/scripts/test_9.sh new file mode 100755 index 0000000..de8e39a --- /dev/null +++ b/test/scripts/test_9.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +#### +# Attempt to retrieve binary file from running daemon +# +#### + +source ./test_helpers.sh + +IPFS="../../main/ipfs --config /tmp/ipfs_1" + +function pre { + rm -Rf /tmp/ipfs_1 + eval "$IPFS" init; + check_failure_with_exit "pre" $? + cp ../config.test1.wo_journal /tmp/ipfs_1/config +} + +function post { + rm -Rf /tmp/ipfs_1; + rm hello.bin; + rm hello2.bin; +} + +function body { + create_binary_file 256; + eval "$IPFS" add hello.bin + check_failure_with_exit "add hello.bin" $? + + #start the daemon + eval "../../main/ipfs --config /tmp/ipfs_1 daemon &" + daemon_id=$! + sleep 5 + + eval "$IPFS" cat QmX4zpwaE7CSgZZsULgoB3gXYC6hh7RN19bEfWxw7sL8Xx > hello2.bin + check_failure_with_exit "cat" $? + + # file size should be 256 + actualsize=$(wc -c < hello2.bin) + if [ $actualsize -ne 256 ]; then + echo '*** Failure *** file size incorrect' + fi + + kill -9 $daemon_id +} diff --git a/test/scripts/test_helpers.sh b/test/scripts/test_helpers.sh index 8259958..e747e16 100755 --- a/test/scripts/test_helpers.sh +++ b/test/scripts/test_helpers.sh @@ -1,5 +1,10 @@ #!/bin/bash +##### +# global to keep track of failures +##### +failure_count=0 + ##### # Functions to help with test scripts ##### @@ -16,9 +21,15 @@ function create_hello_world { ### function create_binary_file { rm hello.bin - for byte in `seq 0 255`; + num_bytes=$1 + if [ $num_bytes -eq 0 ]; then + num_bytes=255; + fi + let num_bytes-- + for byte in `seq 0 $num_bytes`; do - printf "\\$(printf "%o" $byte)" >> hello.bin + remainder=($byte % 255) + printf "\\$(printf "%o" $remainder)" >> hello.bin done } @@ -33,4 +44,20 @@ function check_failure() { if [ $RESULT -ne 0 ]; then echo "***Failure*** in $FUNC. The return value was $RESULT"; fi + return $RESULT +} + +#### +# Checks the return code and displays message if return code is not 0 +# Param $1 name of function +# Param $2 return code +#### +function check_failure_with_exit() { + FUNC=$1; + RESULT=$2; + if [ $RESULT -ne 0 ]; then + echo "***Failure*** in $FUNC. The return value was $RESULT"; + exit $RESULT + fi + return $RESULT }