e470e80991fd8a0e547119464fcb4a6b55e35cb1
[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   cat << EOF
24 Usage: $0 <test stuff directory|dynamic> [-s]
25
26        Performs test case programming from scratch (current test cases will be dropped
27         from ADML involved instances). There are two types of programming depending on
28         the first argument provided:
29
30        test stuff directory:
31
32           The folder provided must contain msk files, specially a testcase file with
33           xml files referenced inside. Those xml files (without the .msk extension)
34           shall exists in the directory. For example:
35
36              $0 st_examples/DynamicQualification
37
38           Optionally, a file 'specific' could exists containing testcase-specific
39           information, which normally will be used to specify database sentences.
40           This file will be accumulated as a cloning seed over the file 'specific.all'
41           created on test stuff directory.
42
43           Template type programming could be used for medium-duration testings, because
44           the scripting used for programming, have lots of groups divisions which even
45           background-executed are much more slower on programming than a c++ builtin
46           procedure: dynamic type is the one for large sets of test cases:
47
48
49        dynamic:
50
51           The current dynamic procedure selected by mean 'dynlibs/select.sh' script,
52           will be programmed using its dirname resources: inside, you may found not
53           only the .so library but the needed xml files for the implemented scenary
54           and a file called 'dynamic.suffix' used to complete the dynamic operation
55           in this way:
56
57              dynamic|<initial sequence>|<final sequence>|<dynamic.suffix content>
58
59           For example, you could have this content for 'dynamic.suffix':
60
61              7|CCR-I.xml|CCR-T.xml
62
63           in order to generate the operation:
64
65              dynamic|<initial sequence>|<final sequence>|7|CCR-I.xml|CCR-T.xml
66
67           which would be parsed for the specific ADML instance programmed:
68
69              dynamic|2000001|2001000|7|CCR-I.xml|CCR-T.xml
70
71           The file 'dynamic.suffix' could have several lines for several scenaries.
72           In this case, this script will prompt for the desired one.
73
74           This script will build every operation for the configured ADML instances
75           to complete all the sequence ranges along the whole test system.
76
77
78
79        -s: start testing just after programming, using desired rate: $DESIRED_RATE test cases per second.
80 EOF
81   [ $ADML_INSTANCES -gt 1 ] && echo "           In your case, with $ADML_INSTANCES, a rate of $RATE_PER_INSTANCE ttps will be send per instance."
82   echo
83   _exit
84 }
85
86 #############
87 # EXECUTION #
88 #############
89 miss_conf=
90 [ ! -f .st_conf_adml_instances ] && miss_conf=yes
91 [ ! -f .st_conf_n_testcases_program_layout ] && miss_conf=yes
92 [ ! -f .st_conf_cycle_repeats ] && miss_conf=yes
93 [ ! -f .st_conf_rate_per_instance ] && miss_conf=yes
94 [ ! -f .st_conf_desired_rate ] && miss_conf=yes
95 [ -n "$miss_conf" ] && _exit "You must run './configure.sh' script firtly !!"
96
97 echo
98 [ -z "$1" ] && usage
99 echo "Starting testcases programming ..."
100 echo
101
102 ./operation.sh --ping >/dev/null
103 [ $? -ne 0 ] && _exit "Programming aborted (some ADML client process is not running) !"
104
105 # Arguments:
106 PROG_TYPE=$1
107 AUTOSTART=$2
108
109 # test case stuff programming #########################################################
110 if [ "$PROG_TYPE" != "dynamic" ]
111 then
112   TESTCASE_DIR=$PROG_TYPE
113
114   [ ! -d $TESTCASE_DIR ] && _exit "Cannot found the test directory '$TESTCASE_DIR' !!"
115   TESTCASE=( `ls $TESTCASE_DIR/testcase*msk 2>/dev/null` )
116   TESTCASE_FILES=${#TESTCASE[@]}
117   [ $TESTCASE_FILES -ne 1 ] && _exit "One and only one 'testcase*msk' file must be present !!"
118
119   MAX_NUMBER_GROUPS=$(grep ^MAX_NUMBER_GROUPS= clone.sh | cut -d= -f2)
120   CLONE_GROUPS=$((MAX_NUMBER_GROUPS/ADML_INSTANCES))
121   #CLONE_GROUPS=1
122   specific=
123   [ -f $TESTCASE_DIR/specific ] && specific=specific
124   
125   [ -z "$ADML_CONCURRENT_PROVISION_JOBS" ] && ADML_CONCURRENT_PROVISION_JOBS=5
126   
127   count=0
128   while read -r line
129   do
130     instance=$(echo $line | awk '{ print $1 }')
131     ini_seq=$(echo $line | awk '{ print $2 }')
132     fin_seq=$(echo $line | awk '{ print $3 }')
133     ADML_DIR=`readlink -f ADMLS/ADML-$instance`
134     echo -e "\rCloning interval [$ini_seq,$fin_seq] for $(basename $ADML_DIR) ..."
135     ./clone.sh $ADML_DIR $TESTCASE $ini_seq $fin_seq $CLONE_GROUPS $specific &
136     sleep 0.1
137     count=$((count+1))
138     if [ $count -eq $ADML_CONCURRENT_PROVISION_JOBS ]
139     then
140       idle_cpu=$(top -b -d 0.1 -n 2 | grep 'Cpu(s):'| tail -1 |awk '{print $8}')
141       echo
142       echo "Idle cpu = $idle_cpu%"
143       echo "if cpu is not overcommited, consider increase ADML_CONCURRENT_PROVISION_JOBS environment variable (now $ADML_CONCURRENT_PROVISION_JOBS)"
144       echo
145       wait $(jobs -p)
146       count=0
147     fi
148   
149   done < $PROGRAM_LAYOUT_FILE
150   
151   # Wait background jobs to finish:
152   sleep 5
153   echo "Waiting for clone completion ..."
154   echo "(please be patient, this may take a while)"
155   echo
156   echo "Background Jobs: $(jobs -p | wc -l)"
157   wait $(jobs -p)
158   
159   echo
160   echo "Programming has finished !"
161   echo
162   
163   echo "Configuring repeat cycles ..."
164   ./operation.sh "test|repeats|$REPEATS"
165   
166   if [ -n "$specific" ]
167   then
168     echo "A new file '$TESTCASE_DIR/specific.all' has been created."
169     echo "Probably you need to apply it before starting traffic."
170     echo
171     echo "Press ENTER to continue, CTRL-C to abort ..."
172     read dummy
173   fi
174
175 # dynamic programming #################################################################
176 else
177   TESTCASE_DIR=$(readlink -f dynlibs/libanna_dynamicLauncherProcedure.so | xargs dirname)
178   DYNAMIC_SUFFIX_FILE=$TESTCASE_DIR/dynamic.suffix
179
180   [ ! -f $DYNAMIC_SUFFIX_FILE ] && _exit "Missing '$DYNAMIC_SUFFIX_FILE' file. Use 'dynlibs/select.sh' to change the dynamic procedure and restart the ADML instances."
181   dynamic_suffix=( $(grep -v ^# $DYNAMIC_SUFFIX_FILE) )
182
183   # Multiple scenarios:
184   suffixes=${#dynamic_suffix[@]}
185   if [ $suffixes -gt 1 ]
186   then
187     echo "Detected $suffixes scenarios. Please, select the desired option:"
188     echo
189     tmpfile=$(mktemp)
190     opt=1
191     for line in $(grep -v ^# $DYNAMIC_SUFFIX_FILE)
192     do
193       echo "${opt}) $line"
194       opt=$((opt+1))
195     done > $tmpfile
196     cat $tmpfile
197     echo
198     read option
199     while [ -z "$option" ]; do read option ; done
200     dynamic_suffix=$(grep "^${option}) " $tmpfile | cut -d" " -f2-)
201     [ -z "$dynamic_suffix" ] && _exit "Invalid option !"
202   fi
203
204   # Modify xml files path:
205   xmls=( $(echo $dynamic_suffix | sed 's/'\|'/ /g') )
206   dynamic_suffix=$(for xml in ${xmls[@]}
207   do
208     echo $xml | grep -q "\.xml$"
209     [ $? -eq 0 ] && echo -n "$TESTCASE_DIR/"
210     echo -n "${xml}|"
211   done | sed 's/'\|'$//')
212
213   while read -r line
214   do
215     instance=$(echo $line | awk '{ print $1 }')
216     ini_seq=$(echo $line | awk '{ print $2 }')
217     fin_seq=$(echo $line | awk '{ print $3 }')
218     ADML_DIR=`readlink -f ADMLS/ADML-$instance`
219   
220     cd $ADML_DIR
221     ./operation.sh -t 60 "dynamic|$ini_seq|$fin_seq|$dynamic_suffix"
222     cd - >/dev/null
223   
224   done < $PROGRAM_LAYOUT_FILE
225
226 fi
227
228 echo
229 echo
230 start_testing=
231 if [ "$AUTOSTART" = "-s" ]
232 then
233   start_testing=yes
234 else
235   echo "Input desired rate (test cases per second) to start testing [0: nothing done]:"
236   read desired_rate
237   if [ "$desired_rate" != "" ]
238   then
239     rate_per_instance=$((desired_rate/$ADML_INSTANCES))
240     [ $rate_per_instance -lt 1 ] && rate_per_instance=1
241     ./operation.sh "test|ttps|$rate_per_instance"
242   else
243     echo "Remember that you could start traffic using:"
244     echo "   ./operation.sh \"test|ttps|<test cases per second rate>\""
245     echo
246     echo "For example, to reach $DESIRED_RATE test cases per second:"
247     echo "   ./operation.sh \"test|ttps|$RATE_PER_INSTANCE\""
248   fi
249 fi
250
251 if [ -n "$start_testing" ]
252 then
253   echo
254   echo "Start testing to achieve desired rate of $DESIRED_RATE test cases per second ..."
255   echo
256   ./operation.sh "test|ttps|$RATE_PER_INSTANCE"
257 fi
258
259 echo
260 echo "Done !"
261 echo
262