diff --git a/tests/run_sender_receiver.sh b/tests/run_sender_receiver.sh index f0ebe4b7344b6e986d8f3aed75be6028200a655d..a90061273ff88a7b5350e8aee99d7755d7a516ac 100755 --- a/tests/run_sender_receiver.sh +++ b/tests/run_sender_receiver.sh @@ -41,7 +41,7 @@ if [ ! -d "${name_type_of_test}" ]; then mkdir "${name_type_of_test}" 2>/dev/null fi # Checking for an optional 11 argument for a sub directory name -if [ "$#" -ne 10 ]; then +if [ "$#" -eq 11 ]; then if [ ! -d "${name_type_of_test}${11}/" ]; then mkdir "${name_type_of_test}${11}/" 2>/dev/null fi @@ -116,10 +116,8 @@ sender_logs="${DIR}${sender_name}.log" ##### Launching the receiver and capturinig its output ##### valgrind --leak-check=full --log-file=${receiver_valgrind} \ - ./${receiver} ::1 $port1 \ - -s ${receiver_stats} \ - 1> ${output_file} \ - 2> ${receiver_logs} & receiver_pid=$! + ./${receiver} ::1 $port1 -s ${receiver_stats} 1> ${output_file} \ + 2> ${receiver_logs} & receiver_pid=$! cleanup() { @@ -168,9 +166,11 @@ else # We check the return value of the receiver fi fi -# Stop the link simulator -kill -9 $link_pid -wait $link_pid 2>/dev/null +# Stop the link simulator if there is one +if [ "$#" -gt 6 ]; then + kill -9 $link_pid + wait $link_pid 2>/dev/null +fi if [ $err -ne 1 ]; then # We verify that the transfer ran through properly diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 4714bd3f763e59ffa508479aeb674f35868cf661..a8da3e677a04d9cf45d28c8403956ea82c270cf4 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -14,12 +14,14 @@ TEST_FILES_DIR=./tests_files/ if [ ! -d ./tests_logs/ ]; then mkdir ./tests_logs fi -# Remove everything -rm -rf ./tests_logs/* -if [ -d ./unwanted_logs/ ]; then - rm -rdf ./unwanted_logs -fi + + +##### SIMPLE TESTS ##### +dir="tests_logs/simple_tests/" +rm -rf $dir/* + +mode='without_FEC' simple_test_files=( 'tests_files/greeting.txt' @@ -28,40 +30,47 @@ simple_test_files=( 'tests_files/thumbs-up-nod.gif' ) -advanced_test_files=( - 'tests_files/greeting.txt' - 'tests_files/long_message.txt' - 'tests_files/noice.gif' -) -# echo -e "\nStarting simple tests ...\n" -# i=1 -# for FILENAME in "${simple_test_files[@]}"; do -# FILESIZE=$(stat -c%s "$FILENAME") -# echo -e "${BROWN}($i/${#simple_test_files[@]}) Sending \"$FILENAME\" \t[$FILESIZE bytes] with Valgrind${NC}" -# ./tests/simple_test.sh $FILENAME +echo -e "\nStarting simple tests ...\n" +i=1 +for file in "${simple_test_files[@]}"; do + filesize=$(stat -c%s "$file") + echo -e "\n${BROWN}($i/${#simple_test_files[@]}) Sending \"$file\" \t[$filesize bytes] with Valgrind${NC}" + + ./tests/run_sender_receiver.sh $my_sender $my_receiver $file $dir $mode + if [ $? -ne 0 ]; then + echo "Tests terminated cause of a failed test" + exit 0 + fi + let i++ + +done +echo -e "Finished Simple tests." -# if [ $? -ne 0 ]; then -# echo "Tests terminated cause of a failed test" -# exit 0 -# fi -# let i++ -# done -# echo -e "Finished Simple tests." +##### ADVANCED TESTS ##### +dir="tests_logs/advanced_tests/" +rm -rf $dir/* modes=( 'with_FEC' 'without_FEC' ) + +advanced_test_files=( + 'tests_files/greeting.txt' + 'tests_files/long_message.txt' + 'tests_files/noice.gif' +) + + ERROR_RATE=5 CUT_RATE=5 DELAY=100 JITTER=100 LOSS_RATE=1 -dir="tests_logs/advanced_tests/" if [ -d linksimulator/ ]; then echo -e "\nStarting advanced tests ...\n" diff --git a/tests/simple_test.sh b/tests/simple_test.sh deleted file mode 100755 index 1f1b9f37147eba67254f642fcff45c31890447a2..0000000000000000000000000000000000000000 --- a/tests/simple_test.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash - -if [ -z "$1" ]; then - echo "Not given the file to send" - exit 1 -fi - -FILENAME=$1 -BASENAME=$(basename $FILENAME) -BSN_PRE="${BASENAME%.*}" -BSN_EXT="${BASENAME##*.}" -TEST_OUTPUT_FILES="tests_logs/simple_tests/${BSN_PRE}" -GREEN='\033[0;32m' -NC='\033[0m' - -# If the directory does not exist, we create it -if [ ! -d "tests_logs/simple_tests/" ]; then - mkdir 'tests_logs/simple_tests/' 2>/dev/null -fi -mkdir "${TEST_OUTPUT_FILES}/" 2>/dev/null - -touch "${TEST_OUTPUT_FILES}/${BSN_PRE}_received_file.${BSN_EXT}" \ - "${TEST_OUTPUT_FILES}/valgrind_${BSN_PRE}_receiver.log" \ - "${TEST_OUTPUT_FILES}/valgrind_${BSN_PRE}_sender.log" \ - "${TEST_OUTPUT_FILES}/${BSN_PRE}_sender.log" \ - "${TEST_OUTPUT_FILES}/${BSN_PRE}_receiver.log" - - -# The next line come from: https://unix.stackexchange.com/questions/55913/whats-the-easiest-way-to-find-an-unused-local-port -# We use this to be sure we're using unused port -port=$(comm -23 <(seq 65000 65200 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1) - -# We launch the receiver and capture its output -valgrind --leak-check=full --log-file=${TEST_OUTPUT_FILES}/valgrind_${BSN_PRE}_receiver.log \ - ./receiver ::1 $port -s ${TEST_OUTPUT_FILES}/${BSN_PRE}_receiver_stats.csv 1> ${TEST_OUTPUT_FILES}/${BSN_PRE}_received_file.${BSN_EXT} \ - 2> ${TEST_OUTPUT_FILES}/${BSN_PRE}_receiver.log & receiver_pid=$! - -cleanup() -{ - kill -9 $receiver_pid - kill -9 $link_pid - exit 0 -} -trap cleanup SIGINT # Kill the background procces in case of ^-C - -# We start the transfer -if ! valgrind --leak-check=full --log-file=${TEST_OUTPUT_FILES}/valgrind_${BSN_PRE}_sender.log \ - ./sender -f ${FILENAME} ::1 $port -s ${TEST_OUTPUT_FILES}/${BSN_PRE}_sender_stats.csv 2> ${TEST_OUTPUT_FILES}/${BSN_PRE}_sender.log ; then - echo "The sender crashed!" - cat ${TEST_OUTPUT_FILES}/${BSN_PRE}_sender.log - err=1 # We record the error -fi - -sleep 5 # We wait 5s for the receiver to finish up - -if kill -0 $receiver_pid &> /dev/null ; then - echo "The receiver didn't stop at the end of the transfer!" - kill -9 $receiver_pid - err=1 -else # We check the return value of the receiver - if ! wait $receiver_pid ; then - echo "The receiver crashed!" - cat ${TEST_OUTPUT_FILES}/${BSN_PRE}_receiver.log - err=1 - fi -fi - -# We check that the transfer ran through properly -if [[ "$(md5sum ${FILENAME} | awk '{print $1}')" != "$(md5sum ${TEST_OUTPUT_FILES}/${BSN_PRE}_received_file.${BSN_EXT} | awk '{print $1}')" ]]; then - echo "The transfer has corrupted the file!" - echo "Binary difference between the 2 files: (expected vs actual)" - diff -C 9 <(od -Ax -t x1z ${FILENAME}) <(od -Ax -t x1z ${TEST_OUTPUT_FILES}/${BSN_PRE}_received_file.${BSN_EXT}) - exit 1 -else - echo -e "${GREEN}The transfer has succeeded!${NC}" - exit ${err:-0} # In case of error, we send back the error code. -fi \ No newline at end of file