030877134b9fa83e4b4fcb71676d3d8bfe5d7d7c
[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 children () {
44   bash_pid=$$
45   children=`ps -eo ppid | grep -w $bash_pid`
46   echo $children | wc -w
47 }
48
49
50 #############
51 # EXECUTION #
52 #############
53 miss_conf=
54 [ ! -f .st_conf_adml_instances ] && miss_conf=yes
55 [ ! -f .st_conf_n_testcases_program_layout ] && miss_conf=yes
56 [ ! -f .st_conf_cycle_repeats ] && miss_conf=yes
57 [ ! -f .st_conf_rate_per_instance ] && miss_conf=yes
58 [ ! -f .st_conf_desired_rate ] && miss_conf=yes
59 [ -n "$miss_conf" ] && _exit "You must run './configure.sh' script firtly !!"
60
61 echo
62 [ -z "$1" ] && usage
63 ./operation.sh --ping
64 [ $? -ne 0 ] && _exit "Programming aborted (some ADML client process is not running) !"
65 TESTCASE_DIR=$1
66 AUTOSTART=$2
67
68 [ ! -d $TESTCASE_DIR ] && _exit "Cannot found the test directory '$TESTCASE_DIR' !!"
69 TESTCASE=( `ls $TESTCASE_DIR/testcase*msk 2>/dev/null` )
70 TESTCASE_FILES=${#TESTCASE[@]}
71 [ $TESTCASE_FILES -ne 1 ] && _exit "One and only one 'testcase*msk' file must be present !!"
72
73 MAX_NUMBER_GROUPS=$(grep ^MAX_NUMBER_GROUPS= clone.sh | cut -d= -f2)
74 CLONE_GROUPS=$((MAX_NUMBER_GROUPS/ADML_INSTANCES))
75 #CLONE_GROUPS=1
76 specific=
77 [ -f $TESTCASE_DIR/specific ] && specific=specific
78
79 children_before=$(children)
80 while read -r line
81 do
82   instance=$(echo $line | awk '{ print $1 }')
83   ini_seq=$(echo $line | awk '{ print $2 }')
84   fin_seq=$(echo $line | awk '{ print $3 }')
85   ADML_DIR=`readlink -f ADMLS/ADML-$instance`
86   ./clone.sh $ADML_DIR $TESTCASE $ini_seq $fin_seq $CLONE_GROUPS $specific &
87
88 done < $PROGRAM_LAYOUT_FILE
89
90 # Wait background jobs to finish:
91 sleep 1
92 echo "Waiting for clone completion ..."
93 while true
94 do
95   [ $(children) -eq $children_before ] && break
96   sleep 1
97 done
98
99 echo
100 echo "Programming has finished !"
101 echo
102
103 echo "Configuring repeat cycles ..."
104 ./operation.sh "test|repeats|$REPEATS"
105
106 if [ -n "$specific" ]
107 then
108   echo "A new file '$TESTCASE_DIR/specific.all' has been created."
109   echo "Probably you need to apply it before starting traffic."
110   echo
111   echo "Press ENTER to continue, CTRL-C to abort ..."
112   read dummy
113 fi
114
115 echo
116 echo
117 start_testing=
118 if [ "$AUTOSTART" = "-s" ]
119 then
120   start_testing=yes
121 else
122   echo "Input desired rate (test cases per second) to start testing [0: nothing done]:"
123   read desired_rate
124   if [ "$desired_rate" != "" ]
125   then
126     rate_per_instance=$((desired_rate/$ADML_INSTANCES))
127     [ $rate_per_instance -lt 1 ] && rate_per_instance=1
128     ./operation.sh "test|ttps|$rate_per_instance"
129   else
130     echo "Remember that you could start traffic using:"
131     echo "   ./operation.sh \"test|ttps|<test cases per second rate>\""
132   fi
133 fi
134
135 if [ -n "$start_testing" ]
136 then
137   echo
138   echo "Start testing to achieve desired rate of $DESIRED_RATE test cases per second ..."
139   echo
140   ./operation.sh "test|ttps|$RATE_PER_INSTANCE"
141 fi
142
143 echo
144 echo "Done !"
145 echo
146