07e76169b365bc65b02622adc602b059147b1ebe
[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 file with xml files referenced inside. Those"
28   echo "                             xml files (without the .msk extension) shall exists in the directory. For example:"
29   echo
30   echo "                                $0 st_examples/DynamicQualification"
31   echo
32   echo "                             Optionally, a file called 'specific' could exists containing testcase-specific information,"
33   echo "                             which normally will be used to specify database sentences. This file will be accumulated"
34   echo "                             as a cloning seed over the file 'specific.all' created on test stuff directory."
35   echo
36   echo
37   echo "       -s: start testing just after programming, using desired rate: $DESIRED_RATE test cases per second."
38   [ $ADML_INSTANCES -gt 1 ] && echo "           In your case, with $ADML_INSTANCES, a rate of $RATE_PER_INSTANCE ttps will be send per instance."
39   echo
40   _exit
41 }
42
43 #############
44 # EXECUTION #
45 #############
46 miss_conf=
47 [ ! -f .st_conf_adml_instances ] && miss_conf=yes
48 [ ! -f .st_conf_n_testcases_program_layout ] && miss_conf=yes
49 [ ! -f .st_conf_cycle_repeats ] && miss_conf=yes
50 [ ! -f .st_conf_rate_per_instance ] && miss_conf=yes
51 [ ! -f .st_conf_desired_rate ] && miss_conf=yes
52 [ -n "$miss_conf" ] && _exit "You must run './configure.sh' script firtly !!"
53
54 echo
55 [ -z "$1" ] && usage
56 echo "Starting testcases programming ..."
57 echo
58
59 ./operation.sh --ping >/dev/null
60 [ $? -ne 0 ] && _exit "Programming aborted (some ADML client process is not running) !"
61 TESTCASE_DIR=$1
62 AUTOSTART=$2
63
64 [ ! -d $TESTCASE_DIR ] && _exit "Cannot found the test directory '$TESTCASE_DIR' !!"
65 TESTCASE=( `ls $TESTCASE_DIR/testcase*msk 2>/dev/null` )
66 TESTCASE_FILES=${#TESTCASE[@]}
67 [ $TESTCASE_FILES -ne 1 ] && _exit "One and only one 'testcase*msk' file must be present !!"
68
69 MAX_NUMBER_GROUPS=$(grep ^MAX_NUMBER_GROUPS= clone.sh | cut -d= -f2)
70 CLONE_GROUPS=$((MAX_NUMBER_GROUPS/ADML_INSTANCES))
71 #CLONE_GROUPS=1
72 specific=
73 [ -f $TESTCASE_DIR/specific ] && specific=specific
74
75 [ -z "$ADML_CONCURRENT_PROVISION_JOBS" ] && ADML_CONCURRENT_PROVISION_JOBS=5
76
77 count=0
78 while read -r line
79 do
80   instance=$(echo $line | awk '{ print $1 }')
81   ini_seq=$(echo $line | awk '{ print $2 }')
82   fin_seq=$(echo $line | awk '{ print $3 }')
83   ADML_DIR=`readlink -f ADMLS/ADML-$instance`
84   echo -e "\rCloning interval [$ini_seq,$fin_seq] for $(basename $ADML_DIR) ..."
85   ./clone.sh $ADML_DIR $TESTCASE $ini_seq $fin_seq $CLONE_GROUPS $specific &
86   sleep 0.1
87   count=$((count+1))
88   if [ $count -eq $ADML_CONCURRENT_PROVISION_JOBS ]
89   then
90     idle_cpu=$(top -b -d 0.1 -n 2 | grep 'Cpu(s):'| tail -1 |awk '{print $8}')
91     echo
92     echo "Idle cpu = $idle_cpu%"
93     echo "if cpu is not overcommited, consider increase ADML_CONCURRENT_PROVISION_JOBS environment variable (now $ADML_CONCURRENT_PROVISION_JOBS)"
94     echo
95     wait $(jobs -p)
96     count=0
97   fi
98
99 done < $PROGRAM_LAYOUT_FILE
100
101 # Wait background jobs to finish:
102 sleep 5
103 echo "Waiting for clone completion ..."
104 echo "(please be patient, this may take a while)"
105 echo
106 echo "Background Jobs: $(jobs -p | wc -l)"
107 wait $(jobs -p)
108
109 echo
110 echo "Programming has finished !"
111 echo
112
113 echo "Configuring repeat cycles ..."
114 ./operation.sh "test|repeats|$REPEATS"
115
116 if [ -n "$specific" ]
117 then
118   echo "A new file '$TESTCASE_DIR/specific.all' has been created."
119   echo "Probably you need to apply it before starting traffic."
120   echo
121   echo "Press ENTER to continue, CTRL-C to abort ..."
122   read dummy
123 fi
124
125 echo
126 echo
127 start_testing=
128 if [ "$AUTOSTART" = "-s" ]
129 then
130   start_testing=yes
131 else
132   echo "Input desired rate (test cases per second) to start testing [0: nothing done]:"
133   read desired_rate
134   if [ "$desired_rate" != "" ]
135   then
136     rate_per_instance=$((desired_rate/$ADML_INSTANCES))
137     [ $rate_per_instance -lt 1 ] && rate_per_instance=1
138     ./operation.sh "test|ttps|$rate_per_instance"
139   else
140     echo "Remember that you could start traffic using:"
141     echo "   ./operation.sh \"test|ttps|<test cases per second rate>\""
142     echo
143     echo "For example, to reach $DESIRED_RATE test cases per second:"
144     echo "   ./operation.sh \"test|ttps|$RATE_PER_INSTANCE\""
145   fi
146 fi
147
148 if [ -n "$start_testing" ]
149 then
150   echo
151   echo "Start testing to achieve desired rate of $DESIRED_RATE test cases per second ..."
152   echo
153   ./operation.sh "test|ttps|$RATE_PER_INSTANCE"
154 fi
155
156 echo
157 echo "Done !"
158 echo
159