improvs
[anna.git] / example / diameter / launcher / deployments / st-client / program.sh
index 93cd866..6d0dbb1 100755 (executable)
@@ -20,25 +20,69 @@ _exit() {
 }
 
 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."
+  cat << EOF
+Usage: $0 <test stuff directory|dynamic> [-s]
+
+       Performs test case programming from scratch (current test cases will be dropped
+        from ADML involved instances). There are two types of programming depending on
+        the first argument provided:
+
+       test stuff directory:
+
+          The folder provided must contain msk files, specially a testcase file with
+          xml files referenced inside. Those xml files (without the .msk extension)
+          shall exists in the directory. For example:
+
+             $0 st_examples/DynamicQualification
+
+          Optionally, a file 'specific' could exists containing testcase-specific
+          information, which normally will be used to specify database sentences.
+          This file will be accumulated as a cloning seed over the file 'specific.all'
+          created on test stuff directory.
+
+          Template type programming could be used for medium-duration testings, because
+          the scripting used for programming, have lots of groups divisions which even
+          background-executed are much more slower on programming than a c++ builtin
+          procedure: dynamic type is the one for large sets of test cases:
+
+
+       dynamic:
+
+          The current dynamic procedure selected by mean 'dynlibs/select.sh' script,
+          will be programmed using its dirname resources: inside, you may found not
+          only the .so library but the needed xml files for the implemented scenary
+          and a file called 'dynamic.suffix' used to complete the dynamic operation
+          in this way:
+
+             dynamic|<initial sequence>|<final sequence>|<dynamic.suffix content>
+
+          For example, you could have this content for 'dynamic.suffix':
+
+             7|CCR-I.xml|CCR-T.xml
+
+          in order to generate the operation:
+
+             dynamic|<initial sequence>|<final sequence>|7|CCR-I.xml|CCR-T.xml
+
+          which would be parsed for the specific ADML instance programmed:
+
+             dynamic|2000001|2001000|7|CCR-I.xml|CCR-T.xml
+
+          The file 'dynamic.suffix' could have several lines for several scenaries.
+          In this case, this script will prompt for the desired one.
+
+          This script will build every operation for the configured ADML instances
+          to complete all the sequence ranges along the whole test system.
+
+
+
+       -s: start testing just after programming, using desired rate: $DESIRED_RATE test cases per second.
+EOF
   [ $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 #
 #############
@@ -52,46 +96,143 @@ miss_conf=
 
 echo
 [ -z "$1" ] && usage
-TESTCASE_DIR=$1
+echo "Starting testcases programming ..."
+echo
+
+./operation.sh --ping >/dev/null
+[ $? -ne 0 ] && _exit "Programming aborted (some ADML client process is not running) !"
+
+# Arguments:
+PROG_TYPE=$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 !!"
-
-#CLONE_GROUPS=1
-MAX_NUMBER_GROUPS=$(grep ^MAX_NUMBER_GROUPS= clone.sh | cut -d= -f2)
-ADML_INSTANCES=`cat .st_conf_adml_instances`
-CLONE_GROUPS=$((MAX_NUMBER_GROUPS/ADML_INSTANCES))
-
-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/ADML-$instance`
-  ./clone.sh $ADML_DIR $TESTCASE $ini_seq $fin_seq $CLONE_GROUPS &
-
-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
+# test case stuff programming #########################################################
+if [ "$PROG_TYPE" != "dynamic" ]
+then
+  TESTCASE_DIR=$PROG_TYPE
 
-echo
-echo "Programming has finished !"
-echo
+  [ ! -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 !!"
 
-echo "Configuring repeat cycles ..."
-./operation.sh "test|repeats|$REPEATS"
+  MAX_NUMBER_GROUPS=$(grep ^MAX_NUMBER_GROUPS= clone.sh | cut -d= -f2)
+  CLONE_GROUPS=$((MAX_NUMBER_GROUPS/ADML_INSTANCES))
+  #CLONE_GROUPS=1
+  specific=
+  [ -f $TESTCASE_DIR/specific ] && specific=specific
+  
+  [ -z "$ADML_CONCURRENT_PROVISION_JOBS" ] && ADML_CONCURRENT_PROVISION_JOBS=5
+  
+  count=0
+  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/ADML-$instance`
+    echo -e "\rCloning interval [$ini_seq,$fin_seq] for $(basename $ADML_DIR) ..."
+    ./clone.sh $ADML_DIR $TESTCASE $ini_seq $fin_seq $CLONE_GROUPS $specific &
+    sleep 0.1
+    count=$((count+1))
+    if [ $count -eq $ADML_CONCURRENT_PROVISION_JOBS ]
+    then
+      idle_cpu=$(top -b -d 0.1 -n 2 | grep 'Cpu(s):'| tail -1 |awk '{print $8}')
+      echo
+      echo "Idle cpu = $idle_cpu%"
+      echo "if cpu is not overcommited, consider increase ADML_CONCURRENT_PROVISION_JOBS environment variable (now $ADML_CONCURRENT_PROVISION_JOBS)"
+      echo
+      wait $(jobs -p)
+      count=0
+    fi
+  
+  done < $PROGRAM_LAYOUT_FILE
+  
+  # Wait background jobs to finish:
+  sleep 5
+  echo "Waiting for clone completion ..."
+  echo "(please be patient, this may take a while)"
+  echo
+  echo "Background Jobs: $(jobs -p | wc -l)"
+  wait $(jobs -p)
+  
+  echo
+  echo "Programming has finished !"
+  echo
+  
+  echo "Configuring repeat cycles ..."
+  ./operation.sh "test|repeats|$REPEATS"
+  
+  if [ -n "$specific" ]
+  then
+    echo "A new file '$TESTCASE_DIR/specific.all' has been created."
+    echo "Probably you need to apply it before starting traffic."
+    echo
+    echo "Press ENTER to continue, CTRL-C to abort ..."
+    read dummy
+  fi
+
+# dynamic programming #################################################################
+else
+  TESTCASE_DIR=$(readlink -f dynlibs/libanna_dynamicLauncherProcedure.so | xargs dirname)
+  DYNAMIC_SUFFIX_FILE=$TESTCASE_DIR/dynamic.suffix
+
+  [ ! -f $DYNAMIC_SUFFIX_FILE ] && _exit "Missing '$DYNAMIC_SUFFIX_FILE' file. Use 'dynlibs/select.sh' to change the dynamic procedure and restart the ADML instances."
+  dynamic_suffix=( $(grep -v ^# $DYNAMIC_SUFFIX_FILE) )
+
+  # Multiple scenarios:
+  suffixes=${#dynamic_suffix[@]}
+  if [ $suffixes -gt 1 ]
+  then
+    echo "Detected $suffixes scenarios. Please, select the desired option:"
+    echo
+    tmpfile=$(mktemp)
+    opt=1
+    for line in $(grep -v ^# $DYNAMIC_SUFFIX_FILE)
+    do
+      echo "${opt}) $line"
+      opt=$((opt+1))
+    done > $tmpfile
+    cat $tmpfile
+    echo
+    read option
+    while [ -z "$option" ]; do read option ; done
+    dynamic_suffix=$(grep "^${option}) " $tmpfile | cut -d" " -f2-)
+    [ -z "$dynamic_suffix" ] && _exit "Invalid option !"
+  fi
+
+  # Modify xml files path:
+  xmls=( $(echo $dynamic_suffix | sed 's/'\|'/ /g') )
+  dynamic_suffix=$(for xml in ${xmls[@]}
+  do
+    echo $xml | grep -q "\.xml$"
+    [ $? -eq 0 ] && echo -n "$TESTCASE_DIR/"
+    echo -n "${xml}|"
+  done | sed 's/'\|'$//')
+
+  # If still idle CPU, you could increase chunks number of background jobs
+  CHUNKS=10
+  echo "Dynamic programming ..."
+  echo
+  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/ADML-$instance`
+  
+    cd $ADML_DIR                                                      
+    ./operation.sh -t 60 "dynamic|$ini_seq|$fin_seq|$dynamic_suffix" &
+    count=$((count+1))                                                
+    [ $count -eq $CHUNKS ] && { wait $(jobs -p) ; count=1 ; }               
+    cd - >/dev/null                                                   
+  
+  done < $PROGRAM_LAYOUT_FILE
+
+fi
 
+echo
+echo
 start_testing=
 if [ "$AUTOSTART" = "-s" ]
 then
@@ -104,6 +245,52 @@ else
     rate_per_instance=$((desired_rate/$ADML_INSTANCES))
     [ $rate_per_instance -lt 1 ] && rate_per_instance=1
     ./operation.sh "test|ttps|$rate_per_instance"
+  else
+    cat << EOF
+
+To start testing, you must use the './operation.sh' script. Use '-h'
+ to get detailed help. The most common commands used for testing are:
+
+ * Enable reports dump for failed tests:
+    ./operation.sh "test|report|failed"
+
+ * Launch traffic:
+    ./operation.sh "test|ttps|<test cases per second and instance(*)>"
+
+    (*) note: ttps value is related to a single instance: you should"
+              divide the desired CPS by the number of instances. For"
+              exampl, if you need $DESIRED_RATE test cases per second:
+
+                ./operation.sh "test|ttps|$RATE_PER_INSTANCE"
+
+ * Stop traffic:
+    ./operation.sh "test|ttps|0"
+
+ * Reset already classified (Success/Failed) test cases:
+    ./operation.sh "test|reset[|soft]"
+
+ * Reset also 'in-progress' state test cases:
+    ./operation.sh "test|reset|hard"
+
+Remember that './operation.sh' broadcasts the operation scripts along
+ the ADML instances, then some operations should better be used within
+ a specific 'ADMLS/ADML-<instance>' directory to avoid console spam,
+ for example: 
+
+ * Check a testcase in runtime:
+   ADMLS/ADML-001/operation.sh "test|look|<test id>"
+
+ * Execute the next programmed test case:
+   ADMLS/ADML-001/operation.sh "test|next"
+
+ * Interactive-step execution:
+   ADMLS/ADML-001/operation.sh "test|interact|<steps to execute>|<test id>"
+
+ * Summary:
+   ADMLS/ADML-001/operation.sh "test|summary"
+
+EOF
+
   fi
 fi