2 Experiment for FT in shell script
authorEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Mon, 16 Mar 2015 22:40:21 +0000 (23:40 +0100)
committerEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Mon, 16 Mar 2015 22:40:21 +0000 (23:40 +0100)
example/diameter/launcher/main.cpp
example/diameter/launcher/resources/ft-client/tests/case_1.sh [deleted file]
example/diameter/launcher/resources/ft-client/tests/common.sh [deleted file]
example/diameter/launcher/resources/ft-client/tests/experiment1/case_1.sh [new file with mode: 0755]
example/diameter/launcher/resources/ft-client/tests/experiment1/common.sh [new file with mode: 0755]
example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/aar-bad.hex [new symlink]
example/diameter/launcher/resources/ft-client/tests/experiment2/ProtocolErrors/BadAARtoServer/case_1.tc [new file with mode: 0644]
example/diameter/launcher/resources/ft-client/tests/experiment2/go.sh [new file with mode: 0755]

index 416acce..c0d4d37 100644 (file)
@@ -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 (executable)
index 614440b..0000000
+++ /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 "<avp name=\"Result-Code\" data=\"5004\" alias=\"DIAMETER_INVALID_AVP_VALUE\"/>" ../launcher.log.recvfe
-check_pattern "<avp name=\"Failed-AVP\">( *)<avp name=\"Subscription-Id\"" ../launcher.log.recvfe
-
-# Test OK
-test_ok "Received answer to bad-aar message indicating Failed-AVP as Subscription-Id"
-
diff --git a/example/diameter/launcher/resources/ft-client/tests/common.sh b/example/diameter/launcher/resources/ft-client/tests/common.sh
deleted file mode 100755 (executable)
index c04c952..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/bin/bash
-
-#############
-# VARIABLES #
-#############
-tmpdir=$(mktemp -d)
-
-#############
-# FUNCTIONS #
-#############
-
-_exit () {
-  echo
-  echo $1
-  echo
-  rm -rf $tmpdir
-  exit 1
-}
-
-sigint_handler() {
-  _exit "Script interrupted. Cleanup & exit ..."
-}
-
-# $1: hex formatted file to send to the server
-send_xml () {
-  ../operation.sh "sendxml|$1"
-}
-
-send_hex () {
-  sleep 1
-  ../operation.sh "sendhex|$1"
-}
-
-# $1: pattern; $2: file
-check_pattern () {
-  echo "Matching pattern '$1' ..." 
-  cat $2 | tr '\n' ' ' | egrep "$1" >/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 "^</message>" >/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 (executable)
index 0000000..67dd513
--- /dev/null
@@ -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 "<avp name=\"Result-Code\" data=\"5004\" alias=\"DIAMETER_INVALID_AVP_VALUE\"/>" ../../launcher.log.recvfe
+check_pattern "<avp name=\"Failed-AVP\">( *)<avp name=\"Subscription-Id\"" ../../launcher.log.recvfe
+
+# Test OK
+test_ok "Received answer to bad-aar message indicating Failed-AVP as Subscription-Id"
+
diff --git a/example/diameter/launcher/resources/ft-client/tests/experiment1/common.sh b/example/diameter/launcher/resources/ft-client/tests/experiment1/common.sh
new file mode 100755 (executable)
index 0000000..d841491
--- /dev/null
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+#############
+# FUNCTIONS #
+#############
+
+_exit () {
+  echo
+  echo $1
+  echo
+  exit 1
+}
+
+sigint_handler() {
+  _exit "Script interrupted. Cleanup & exit ..."
+}
+
+# $1: hex formatted file to send to the server
+send_xml () {
+  ../../operation.sh "sendxml|$1"
+}
+
+send_hex () {
+  sleep 1
+  ../../operation.sh "sendhex|$1"
+}
+
+# $1: pattern; $2: file
+check_pattern () {
+  echo "Matching pattern '$1' ..." 
+  cat $2 | tr '\n' ' ' | egrep "$1" >/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 "^</message>" >/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 (symlink)
index 0000000..4c9a36f
--- /dev/null
@@ -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 (file)
index 0000000..0007882
--- /dev/null
@@ -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 <avp name="Result-Code" data="5004" alias="DIAMETER_INVALID_AVP_VALUE"/>
+CHECKPATTERN <avp name="Failed-AVP">( *)<avp name="Subscription-Id"
diff --git a/example/diameter/launcher/resources/ft-client/tests/experiment2/go.sh b/example/diameter/launcher/resources/ft-client/tests/experiment2/go.sh
new file mode 100755 (executable)
index 0000000..d9a939d
--- /dev/null
@@ -0,0 +1,179 @@
+#!/bin/bash
+
+#############
+# VARIABLES #
+#############
+CWD=`dirname $0`
+tmpdir=$(mktemp -d)
+SCR_BN=`basename $0`
+OPER_SCR=`readlink -f $CWD/../../operation.sh`
+RESULT_LOG=$CWD/result.log
+RECV_LOG=`readlink -f $CWD/../../launcher.log.recvfe`
+
+#############
+# FUNCTIONS #
+#############
+
+sigint_handler () {
+  _exit "Script interrupted. Cleanup and exit ..."
+}
+
+# $1: message; $2: optional rc (1 by default)
+_exit () {
+  rc=1
+  [ -n "$2" ] && rc=$2
+  echo
+  echo -e $1
+  echo
+  rm -rf $tmpdir
+  exit $rc
+}
+
+# $1: hex formatted file to send to the server
+operation_sendxml2e () {
+  sleep 0.5
+  $OPER_SCR "sendxml2e|$1"
+}
+
+# $1: hex formatted file to send to the server
+operation_sendhex2e () {
+  sleep 0.5
+  $OPER_SCR "sendhex2e|$1"
+}
+
+# $1: file to monitor
+# $2: timeout (request expiration) in seconds
+# Result: cats the message when completed
+wait4message () {
+  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 "^</message>" >/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 <test cases parent directory (or .tc file)>"
+
+# 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
+