From bed9cb7ee096fbd3981de37972c86bce00840022 Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Testillano Date: Mon, 16 Mar 2015 23:40:21 +0100 Subject: [PATCH] 2 Experiment for FT in shell script --- example/diameter/launcher/main.cpp | 16 +- .../tests/{ => experiment1}/case_1.sh | 8 +- .../tests/{ => experiment1}/common.sh | 10 +- .../ProtocolErrors/BadAARtoServer/aar-bad.hex | 1 + .../ProtocolErrors/BadAARtoServer/case_1.tc | 9 + .../ft-client/tests/experiment2/go.sh | 179 ++++++++++++++++++ 6 files changed, 203 insertions(+), 20 deletions(-) rename example/diameter/launcher/resources/ft-client/tests/{ => experiment1}/case_1.sh (86%) rename example/diameter/launcher/resources/ft-client/tests/{ => experiment1}/common.sh (90%) create mode 120000 example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/aar-bad.hex create mode 100644 example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/case_1.tc create mode 100755 example/diameter/launcher/resources/ft-client/tests/experiment2/go.sh diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 416acce..c0d4d37 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -1748,7 +1748,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else if (opType == "decode") { // Get DataBlock from file with hex content: if (!getDataBlockFromHexFile(param1, db_aux)) - throw anna::RuntimeException("Cannot interpret hexadecimal content from file provided", ANNA_FILE_LOCATION); + throw anna::RuntimeException("Error reading hex file provided", ANNA_FILE_LOCATION); // Decode try { G_codecMsg.decode(db_aux); } catch (anna::RuntimeException &ex) { ex.trace(); } @@ -1802,7 +1802,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons else { // Get DataBlock from file with hex content: if (!getDataBlockFromHexFile(param1, db_aux)) - throw anna::RuntimeException("Cannot interpret hexadecimal content from file provided", ANNA_FILE_LOCATION); + throw anna::RuntimeException("Error reading hex file provided", ANNA_FILE_LOCATION); G_commMsgSent2e.setBody(db_aux); } @@ -1919,7 +1919,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Wrong body content format on HTTP Request for 'burst' operation (unexpected action parameter). See help", ANNA_FILE_LOCATION); } - } else if ((opType == "sendxml2c")||(opType == "sendhex2c")) { + } else if ((opType == "sendxml2c") || (opType == "sendhex2c")) { anna::diameter::comm::LocalServer *localServer = getDiameterLocalServer(); if (!localServer) throw anna::RuntimeException("No local server configured to send the message", ANNA_FILE_LOCATION); @@ -1932,7 +1932,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons else { // Get DataBlock from file with hex content: if (!getDataBlockFromHexFile(param1, db_aux)) - throw anna::RuntimeException("Cannot interpret hexadecimal content from file provided", ANNA_FILE_LOCATION); + throw anna::RuntimeException("Error reading hex file provided", ANNA_FILE_LOCATION); G_commMsgSent2c.setBody(db_aux); } @@ -1958,7 +1958,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons startDiameterServer(diameterServerSessions); else getDiameterLocalServer()->setMaxConnections(diameterServerSessions); - } else if ((opType == "answerxml") || (opType == "answerxml2c")) { + } else if ((opType == "answerxml") || (opType == "answerxml2c") || (opType == "answerhex") || (opType == "answerhex2c")) { anna::diameter::comm::LocalServer *localServer = getDiameterLocalServer(); if (!localServer) @@ -1989,7 +1989,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons response_content = "Programmed answers dumped on stdout\n"; return; } - } else if ((opType == "answerxml2e")) { + } else if ((opType == "answerxml2e") || (opType == "answerhex2e")) { anna::diameter::comm::Entity *entity = getEntity(); if (!entity) @@ -2074,12 +2074,12 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons response_content += param1; response_content += "' loaded."; response_content += "\n"; - } else if ((opType == "answerxml") || (opType == "answerxml2c")) { + } else if ((opType == "answerxml") || (opType == "answerxml2c") || (opType == "answerhex") || (opType == "answerhex2c")) { response_content += "Answer to client '"; response_content += param1; response_content += "' programmed."; response_content += "\n"; - } else if ((opType == "answerxml2e")) { + } else if ((opType == "answerxml2e") || (opType == "answerhex2e")) { response_content += "Answer to entity '"; response_content += param1; response_content += "' programmed."; diff --git a/example/diameter/launcher/resources/ft-client/tests/case_1.sh b/example/diameter/launcher/resources/ft-client/tests/experiment1/case_1.sh similarity index 86% rename from example/diameter/launcher/resources/ft-client/tests/case_1.sh rename to example/diameter/launcher/resources/ft-client/tests/experiment1/case_1.sh index 614440b..67dd513 100755 --- a/example/diameter/launcher/resources/ft-client/tests/case_1.sh +++ b/example/diameter/launcher/resources/ft-client/tests/experiment1/case_1.sh @@ -27,20 +27,20 @@ cd `dirname $0` source common.sh # Clean traffic traces: -rm -f ../launcher.log* +rm -f ../../launcher.log* # Send incorrect AAR: send_hex $REQ1_HEX & # Monitor activity: -monitor_4_message ../launcher.log.recvfe 10 +monitor_4_message ../../launcher.log.recvfe 10 # Check if message was received: [ $? -ne 0 ] && test_failed "Missing answer from the server" # Check launcher.log.recvfe: -check_pattern "" ../launcher.log.recvfe -check_pattern "( *)" ../../launcher.log.recvfe +check_pattern "( *) +CHECKPATTERN ( *)$1 + rm -f .msg_received + + [ -z "$2" ] && _exit "ERROR: must provide '$FUNCNAME' timeout (second argument)" + sleep $2 & + local timerPid=$! + + # Monitor for incoming message: + tail -n0 -F --pid=$timerPid $1 | while read line + do + if echo $line | grep "^" >/dev/null; then + echo "Message received" + # stop the timer + kill -13 $timerPid + touch .msg_received + fi + done + + if [ ! -f .msg_received ]; then + echo "Timeout expired" + return 1 + fi + + return 0 +} + + +# $1: pattern; $2: file +check_pattern () { + echo "Matching pattern '$1' in file '$2' ..." + cat $2 | tr '\n' ' ' | egrep "$1" >/dev/null + res=${PIPESTATUS[2]} + [ $res -ne 0 ] && { echo " Cannot found pattern !!" ; test_failed ; } +} + +# $1: pattern file; $2: file +check_pattern_file () { + echo "Matching file '$1' in file '$2' ..." + grep -f $1 $2 >/dev/null + [ $? -ne 0 ] && { echo " Cannot found pattern file !!" ; test_failed ; } +} + +# Tests result: +test_ok () { + echo "$TC Ok" | tee -a $RESULT_LOG +} + +test_failed () { + echo "$TC Failed" | tee -a $RESULT_LOG + TEST_FAILED=1 +} + +process_tc () { + local tc_dn=`dirname $TC` + + echo + echo "***** Executing '$TC' ..." + + grep -v ^# $TC > $tmpdir/tc + TEST_FAILED=0 + while read -r line + do + oper=$(echo $line | awk '{ print $1 }') + param1="$(echo $line | cut -d' ' -f2-)" + + case $oper in + SENDXML2E) + operation_sendxml2e $tc_dn/$param1 & + ;; + + SENDHEX2E) + operation_sendhex2e $tc_dn/$param1 & + ;; + + WAIT4MESSAGE) + wait4message $RECV_LOG 5 + ;; + + CHECKPATTERN) + check_pattern "$param1" $RECV_LOG + ;; + + CHECKPATTERNFILE) + check_pattern_file "$param1" $RECV_LOG + ;; + + esac + [ $TEST_FAILED -eq 1 ] && return 1 + + done < $tmpdir/tc + + test_ok + return 0 +} + + +############# +# EXECUTION # +############# + +# Trap sigint: +trap sigint_handler SIGINT + +# Working directory is script dirname: +cd $CWD + +# Intro: +echo +echo "------------------" +echo "Test cases manager" +echo "------------------" +# Mandatory parameter: +[ -z "$1" ] && _exit "Usage: $SCR_BN " + +# Gather .tc files to be processed: +[ ! -f $1 ] && echo -e "\nGathering list of test cases from '`readlink -f $1`' ..." +echo +find $1 -name *.tc | xargs readlink -f | tee -a $tmpdir/tc_list +echo +echo + +echo "Start processing test cases:" +echo "----------------------------" +# Process test cases: +0> $RESULT_LOG +for TC in `cat $tmpdir/tc_list` +do + process_tc +done + +_exit "Done !" 0 + -- 2.20.1