Add Ericsson Sy selector for sniffing (disect selector for tshark)
[anna.git] / example / diameter / launcher / deployments / st-client / program.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6 ADML_INSTANCES=`cat .st_conf_adml_instances 2>/dev/null`
7 RATE_PER_INSTANCE=`cat .st_conf_rate_per_instance 2>/dev/null`
8 DESIRED_RATE=`cat .st_conf_desired_rate 2>/dev/null`
9 REPEATS=`cat .st_conf_cycle_repeats 2>/dev/null`
10 PROGRAM_LAYOUT_FILE=.st_conf_n_testcases_program_layout
11
12 #############
13 # FUNCTIONS #
14 #############
15 _exit() {
16   echo
17   echo $1
18   echo
19   exit 1
20 }
21
22 usage() {
23   echo "Usage: $0 <test stuff directory> [-s]"
24   echo
25   echo "       Performs test case programming from scratch (current test cases will be dropped from ADML involved instances)."
26   echo
27   echo "       test stuff directory: contains msk files, specially a testcase description with xml files referenced."
28   echo "                             Those files, adding .msk extension, shall exists in the same directory. For example:"
29   echo
30   echo "                                $0 st_examples/DynamicQualification"
31   echo
32   echo "       -s: start testing just after programming, using desired rate: $DESIRED_RATE test cases per second."
33   [ $ADML_INSTANCES -gt 1 ] && echo "           In your case, with $ADML_INSTANCES, a rate of $RATE_PER_INSTANCE ttps will be send per instance."
34   echo
35   _exit
36 }
37
38 children () {
39   bash_pid=$$
40   children=`ps -eo ppid | grep -w $bash_pid`
41   echo $children | wc -w
42 }
43
44
45 #############
46 # EXECUTION #
47 #############
48 miss_conf=
49 [ ! -f .st_conf_adml_instances ] && miss_conf=yes
50 [ ! -f .st_conf_n_testcases_program_layout ] && miss_conf=yes
51 [ ! -f .st_conf_cycle_repeats ] && miss_conf=yes
52 [ ! -f .st_conf_rate_per_instance ] && miss_conf=yes
53 [ ! -f .st_conf_desired_rate ] && miss_conf=yes
54 [ -n "$miss_conf" ] && _exit "You must run './configure.sh' script firtly !!"
55
56 echo
57 [ -z "$1" ] && usage
58 ./operation.sh --ping
59 [ $? -ne 0 ] && _exit "Programming aborted (some ADML client process is not running) !"
60 TESTCASE_DIR=$1
61 AUTOSTART=$2
62
63 [ ! -d $TESTCASE_DIR ] && _exit "Cannot found the test directory '$TESTCASE_DIR' !!"
64 TESTCASE=( `ls $TESTCASE_DIR/testcase*msk 2>/dev/null` )
65 TESTCASE_FILES=${#TESTCASE[@]}
66 [ $TESTCASE_FILES -ne 1 ] && _exit "One and only one 'testcase*msk' file must be present !!"
67
68 MAX_NUMBER_GROUPS=$(grep ^MAX_NUMBER_GROUPS= clone.sh | cut -d= -f2)
69 CLONE_GROUPS=$((MAX_NUMBER_GROUPS/ADML_INSTANCES))
70 #CLONE_GROUPS=1
71
72 children_before=$(children)
73 while read -r line
74 do
75   instance=$(echo $line | awk '{ print $1 }')
76   ini_seq=$(echo $line | awk '{ print $2 }')
77   fin_seq=$(echo $line | awk '{ print $3 }')
78   ADML_DIR=`readlink -f ADMLS/ADML-$instance`
79   ./clone.sh $ADML_DIR $TESTCASE $ini_seq $fin_seq $CLONE_GROUPS &
80
81 done < $PROGRAM_LAYOUT_FILE
82
83 # Wait background jobs to finish:
84 sleep 1
85 echo "Waiting for clone completion ..."
86 while true
87 do
88   [ $(children) -eq $children_before ] && break
89   sleep 1
90 done
91
92 echo
93 echo "Programming has finished !"
94 echo
95
96 echo "Configuring repeat cycles ..."
97 ./operation.sh "test|repeats|$REPEATS"
98
99 echo
100 echo
101 start_testing=
102 if [ "$AUTOSTART" = "-s" ]
103 then
104   start_testing=yes
105 else
106   echo "Input desired rate (test cases per second) to start testing [0: nothing done]:"
107   read desired_rate
108   if [ "$desired_rate" != "" ]
109   then
110     rate_per_instance=$((desired_rate/$ADML_INSTANCES))
111     [ $rate_per_instance -lt 1 ] && rate_per_instance=1
112     ./operation.sh "test|ttps|$rate_per_instance"
113   else
114     echo "Remember that you could start traffic using:"
115     echo "   ./operation.sh \"test|ttps|<test cases per second rate>\""
116   fi
117 fi
118
119 if [ -n "$start_testing" ]
120 then
121   echo
122   echo "Start testing to achieve desired rate of $DESIRED_RATE test cases per second ..."
123   echo
124   ./operation.sh "test|ttps|$RATE_PER_INSTANCE"
125 fi
126
127 echo
128 echo "Done !"
129 echo
130