System test refinement
[anna.git] / example / diameter / launcher / deployments / st-client / program.sh
diff --git a/example/diameter/launcher/deployments/st-client/program.sh b/example/diameter/launcher/deployments/st-client/program.sh
new file mode 100755 (executable)
index 0000000..fccfe07
--- /dev/null
@@ -0,0 +1,112 @@
+#!/bin/bash
+
+#############
+# VARIABLES #
+#############
+ADML_INSTANCES=`cat .st_conf_adml_instances 2>/dev/null`
+RATE_PER_INSTANCE=`cat .st_conf_rate_per_instance 2>/dev/null`
+DESIRED_RATE=`cat .st_conf_desired_rate 2>/dev/null`
+REPEATS=`cat .st_conf_cycle_repeats 2>/dev/null`
+PROGRAM_LAYOUT_FILE=.st_conf_n_testcases_program_layout
+
+#############
+# FUNCTIONS #
+#############
+_exit() {
+  echo
+  echo $1
+  echo
+  exit 1
+}
+
+usage() {
+  echo "Usage: $0 <test stuff directory> [-s]"
+  echo
+  echo "       test stuff directory: contains msk files, specially a testcase description with xml files referenced."
+  echo "                             Those files, adding .msk extension, shall exists in the same directory. For example:"
+  echo "                                $0 st_examples/DynamicQualification"
+  echo
+  echo "       -s: start testing just after programming, using desired rate: $DESIRED_RATE test cases per second."
+  [ $ADML_INSTANCES -gt 1 ] && echo "           In your case, with $ADML_INSTANCES, a rate of $RATE_PER_INSTANCE ttps will be send per instance"
+  echo
+  _exit
+}
+
+children () {
+  bash_pid=$$
+  children=`ps -eo ppid | grep -w $bash_pid`
+  echo $children | wc -w
+}
+
+
+#############
+# EXECUTION #
+#############
+miss_conf=
+[ ! -f .st_conf_adml_instances ] && miss_conf=yes
+[ ! -f .st_conf_n_testcases_program_layout ] && miss_conf=yes
+[ ! -f .st_conf_cycle_repeats ] && miss_conf=yes
+[ ! -f .st_conf_rate_per_instance ] && miss_conf=yes
+[ ! -f .st_conf_desired_rate ] && miss_conf=yes
+[ -n "$miss_conf" ] && _exit "You must run './configure.sh' script firtly !!"
+
+echo
+[ -z "$1" ] && usage
+TESTCASE_DIR=$1
+AUTOSTART=$2
+
+[ ! -d $TESTCASE_DIR ] && _exit "Cannot found the test directory '$TESTCASE_DIR' !!"
+TESTCASE=( `ls $TESTCASE_DIR/testcase*msk 2>/dev/null` )
+TESTCASE_FILES=${#TESTCASE[@]}
+[ $TESTCASE_FILES -ne 1 ] && _exit "One and only one 'testcase*msk' file must be present !!"
+
+children_before=$(children)
+while read -r line
+do
+  instance=$(echo $line | awk '{ print $1 }')
+  ini_seq=$(echo $line | awk '{ print $2 }')
+  fin_seq=$(echo $line | awk '{ print $3 }')
+  ADML_DIR=`readlink -f ADMLS/$instance`
+  ./clone.sh $ADML_DIR $TESTCASE $ini_seq $fin_seq 1 &
+
+done < $PROGRAM_LAYOUT_FILE
+
+# Wait background jobs to finish:
+sleep 1
+echo "Waiting for clone completion ..."
+while true
+do
+  [ $(children) -eq $children_before ] && break
+  sleep 1
+done
+
+echo "Configuring repeat cycles ..."
+./operation.sh "test|repeats|$REPEATS"
+
+start_testing=
+if [ "$AUTOSTART" = "-s" ]
+then
+  start_testing=yes
+else
+  echo "Input desired rate (test cases per second) to start testing [0: nothing done]:"
+  read desired_rate
+  if [ "$desired_rate" != "" ]
+  then
+    rate_per_instance=$((desired_rate/$ADML_INSTANCES))
+    [ $rate_per_instance -lt 1 ] && rate_per_instance=1
+    ./operation.sh "test|ttps|$rate_per_instance"
+  fi
+fi
+
+if [ -n "$start_testing" ]
+then
+  echo
+  echo "Start testing to achieve desired rate of $DESIRED_RATE test cases per second ..."
+  echo
+  ./operation.sh "test|ttps|$RATE_PER_INSTANCE"
+fi
+
+echo
+echo "Done !"
+echo
+