From: Eduardo Ramos Testillano Date: Mon, 16 Mar 2015 22:40:21 +0000 (+0100) Subject: 2 Experiment for FT in shell script X-Git-Tag: REFACTORING_TESTING_LIBRARY~224 X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;h=bed9cb7ee096fbd3981de37972c86bce00840022;p=anna.git 2 Experiment for FT in shell script --- 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/case_1.sh deleted file mode 100755 index 614440b..0000000 --- a/example/diameter/launcher/resources/ft-client/tests/case_1.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# In this test we will send a incorrect message (AAR) to the server peer: -# Warning | source/diameter/codec/Message.cpp (387) | Internal Avp decoding error (avp code = 443): Avp format error, the avp length is incorrect (must be multiple of 4 on grouped type) -# -# The server shall answer with the FailedAVP and we will check this to validate the test. - -############# -# VARIABLES # -############# -# Paths from the point of view of ADL executable: -REQ1_HEX=./hex_examples/aar-bad.hex - -############# -# FUNCTIONS # -############# - - -############# -# EXECUTION # -############# - -# Goto working directory -cd `dirname $0` - -# Source utils: -source common.sh - -# Clean traffic traces: -rm -f ../launcher.log* - -# Send incorrect AAR: -send_hex $REQ1_HEX & - -# Monitor activity: -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 "( *)/dev/null - res=${PIPESTATUS[2]} - [ $? -ne 0 ] && _exit "Test failed: miss pattern !!" -} - -test_ok () { - echo - echo $1 - echo "Test OK !" - echo - exit 0 -} - -test_failed () { - echo - echo $1 - echo "Test FAILED !" - echo - exit 1 -} - - -# $1: traffic log to monitor -# $2: timeout (request expiration) in seconds -# Result: cats the message when completed -monitor_4_message () { - 0>$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 -} - -############# -# EXECUTION # -############# - -# Trap sigint signal: -trap sigint_handler SIGINT - diff --git a/example/diameter/launcher/resources/ft-client/tests/experiment1/case_1.sh b/example/diameter/launcher/resources/ft-client/tests/experiment1/case_1.sh new file mode 100755 index 0000000..67dd513 --- /dev/null +++ b/example/diameter/launcher/resources/ft-client/tests/experiment1/case_1.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# In this test we will send a incorrect message (AAR) to the server peer: +# Warning | source/diameter/codec/Message.cpp (387) | Internal Avp decoding error (avp code = 443): Avp format error, the avp length is incorrect (must be multiple of 4 on grouped type) +# +# The server shall answer with the FailedAVP and we will check this to validate the test. + +############# +# VARIABLES # +############# +# Paths from the point of view of ADL executable: +REQ1_HEX=./hex_examples/aar-bad.hex + +############# +# FUNCTIONS # +############# + + +############# +# EXECUTION # +############# + +# Goto working directory +cd `dirname $0` + +# Source utils: +source common.sh + +# Clean traffic traces: +rm -f ../../launcher.log* + +# Send incorrect AAR: +send_hex $REQ1_HEX & + +# Monitor activity: +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 "( *)/dev/null + res=${PIPESTATUS[2]} + [ $? -ne 0 ] && _exit "Test failed: miss pattern !!" +} + +test_ok () { + echo + echo $1 + echo "Test OK !" + echo + exit 0 +} + +test_failed () { + echo + echo $1 + echo "Test FAILED !" + echo + exit 1 +} + + +# $1: traffic log to monitor +# $2: timeout (request expiration) in seconds +# Result: cats the message when completed +monitor_4_message () { + 0>$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 +} + +############# +# EXECUTION # +############# + +# Trap sigint signal: +trap sigint_handler SIGINT + diff --git a/example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/aar-bad.hex b/example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/aar-bad.hex new file mode 120000 index 0000000..4c9a36f --- /dev/null +++ b/example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/aar-bad.hex @@ -0,0 +1 @@ +../../../../hex_examples/aar-bad.hex \ No newline at end of file diff --git a/example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/case_1.tc b/example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/case_1.tc new file mode 100644 index 0000000..0007882 --- /dev/null +++ b/example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/case_1.tc @@ -0,0 +1,9 @@ +# Send malformed AAR to the server: +SENDHEX2E aar-bad.hex + +# Wait for message: +WAIT4MESSAGE + +# Check Failed-AVP & Subscription-Id within: +CHECKPATTERN +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 +