Optimize
[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 "       test stuff directory: contains msk files, specially a testcase description with xml files referenced."
26   echo "                             Those files, adding .msk extension, shall exists in the same directory. For example:"
27   echo "                                $0 st_examples/DynamicQualification"
28   echo
29   echo "       -s: start testing just after programming, using desired rate: $DESIRED_RATE test cases per second."
30   [ $ADML_INSTANCES -gt 1 ] && echo "           In your case, with $ADML_INSTANCES, a rate of $RATE_PER_INSTANCE ttps will be send per instance."
31   echo
32   _exit
33 }
34
35 children () {
36   bash_pid=$$
37   children=`ps -eo ppid | grep -w $bash_pid`
38   echo $children | wc -w
39 }
40
41
42 #############
43 # EXECUTION #
44 #############
45 miss_conf=
46 [ ! -f .st_conf_adml_instances ] && miss_conf=yes
47 [ ! -f .st_conf_n_testcases_program_layout ] && miss_conf=yes
48 [ ! -f .st_conf_cycle_repeats ] && miss_conf=yes
49 [ ! -f .st_conf_rate_per_instance ] && miss_conf=yes
50 [ ! -f .st_conf_desired_rate ] && miss_conf=yes
51 [ -n "$miss_conf" ] && _exit "You must run './configure.sh' script firtly !!"
52
53 echo
54 [ -z "$1" ] && usage
55 TESTCASE_DIR=$1
56 AUTOSTART=$2
57
58 [ ! -d $TESTCASE_DIR ] && _exit "Cannot found the test directory '$TESTCASE_DIR' !!"
59 TESTCASE=( `ls $TESTCASE_DIR/testcase*msk 2>/dev/null` )
60 TESTCASE_FILES=${#TESTCASE[@]}
61 [ $TESTCASE_FILES -ne 1 ] && _exit "One and only one 'testcase*msk' file must be present !!"
62
63 MAX_NUMBER_GROUPS=$(grep ^MAX_NUMBER_GROUPS= clone.sh | cut -d= -f2)
64 CLONE_GROUPS=$((MAX_NUMBER_GROUPS/ADML_INSTANCES))
65 #CLONE_GROUPS=1
66
67 children_before=$(children)
68 while read -r line
69 do
70   instance=$(echo $line | awk '{ print $1 }')
71   ini_seq=$(echo $line | awk '{ print $2 }')
72   fin_seq=$(echo $line | awk '{ print $3 }')
73   ADML_DIR=`readlink -f ADMLS/ADML-$instance`
74   ./clone.sh $ADML_DIR $TESTCASE $ini_seq $fin_seq $CLONE_GROUPS &
75
76 done < $PROGRAM_LAYOUT_FILE
77
78 # Wait background jobs to finish:
79 sleep 1
80 echo "Waiting for clone completion ..."
81 while true
82 do
83   [ $(children) -eq $children_before ] && break
84   sleep 1
85 done
86
87 echo
88 echo "Programming has finished !"
89 echo
90
91 echo "Configuring repeat cycles ..."
92 ./operation.sh "test|repeats|$REPEATS"
93
94 echo
95 echo
96 start_testing=
97 if [ "$AUTOSTART" = "-s" ]
98 then
99   start_testing=yes
100 else
101   echo "Input desired rate (test cases per second) to start testing [0: nothing done]:"
102   read desired_rate
103   if [ "$desired_rate" != "" ]
104   then
105     rate_per_instance=$((desired_rate/$ADML_INSTANCES))
106     [ $rate_per_instance -lt 1 ] && rate_per_instance=1
107     ./operation.sh "test|ttps|$rate_per_instance"
108   fi
109 fi
110
111 if [ -n "$start_testing" ]
112 then
113   echo
114   echo "Start testing to achieve desired rate of $DESIRED_RATE test cases per second ..."
115   echo
116   ./operation.sh "test|ttps|$RATE_PER_INSTANCE"
117 fi
118
119 echo
120 echo "Done !"
121 echo
122