Step 1: Move vm scripts to the right place
[integration/test.git] / test / tools / wcbench / loop_wcbench.sh
1 #!/usr/bin/env sh
2 # Helper script to run WCBench tests in a loop, used for testing
3 # Script assumes it lives in the same dir as wcbench.sh
4
5 # Exit codes
6 EX_USAGE=64
7 EX_OK=0
8
9 # Output verbose debug info (true) or not (anything else)
10 VERBOSE=false
11
12 ###############################################################################
13 # Prints usage message
14 # Globals:
15 #   None
16 # Arguments:
17 #   None
18 # Returns:
19 #   None
20 ###############################################################################
21 usage()
22 {
23     cat << EOF
24 Usage $0 [options]
25
26 Run WCBench against OpenDaylight in a loop.
27
28 OPTIONS:
29     -h Show this help message
30     -v Output verbose debug info
31     -l Loop WCBench runs without restarting ODL
32     -r Loop WCBench runs, restart ODL between runs
33     -t <time> Run WCBench for a given number of minutes
34     -p <processors> Pin ODL to given number of processors
35 EOF
36 }
37
38 ###############################################################################
39 # Starts ODL, optionally pinning it to a given number of processors
40 # Globals:
41 #   processors
42 #   VERBOSE
43 # Arguments:
44 #   None
45 # Returns:
46 #   WCBench exit status
47 ###############################################################################
48 start_odl()
49 {
50     if "$VERBOSE" = true; then
51         if [ -z $processors ]; then
52             # Start ODL, don't pass processor info
53             echo "Starting ODL, not passing processor info"
54             ./wcbench.sh -vo
55         else
56             # Start ODL, pinning it to given number of processors
57             echo "Pinning ODL to $processors processor(s)"
58             ./wcbench.sh -vp $processors -o
59         fi
60     else
61         if [ -z $processors ]; then
62             # Start ODL, don't pass processor info
63             echo "Starting ODL, not passing processor info"
64             ./wcbench.sh -o
65         else
66             # Start ODL, pinning it to given number of processors
67             echo "Pinning ODL to $processors processor(s)"
68             ./wcbench.sh -p $processors -o
69         fi
70     fi
71 }
72
73 ###############################################################################
74 # Run WCBench against ODL, optionally passing a WCBench run time
75 # Globals:
76 #   run_time
77 #   VERBOSE
78 # Arguments:
79 #   None
80 # Returns:
81 #   WCBench exit status
82 ###############################################################################
83 run_wcbench()
84 {
85     if "$VERBOSE" = true; then
86         if [ -z $run_time ]; then
87             # Flag means run WCBench
88             echo "Running WCBench, not passing run time info"
89             ./wcbench.sh -vr
90         else
91             # Flags mean use $run_time WCBench runs, run WCBench
92             echo "Running WCBench with $run_time minute(s) run time"
93             ./wcbench.sh -vt $run_time -r
94         fi
95     else
96         if [ -z $run_time ]; then
97             # Flag means run WCBench
98             echo "Running WCBench, not passing run time info"
99             ./wcbench.sh -r
100         else
101             # Flags mean use $run_time WCBench runs, run WCBench
102             echo "Running WCBench with $run_time minute(s) run time"
103             ./wcbench.sh -t $run_time -r
104         fi
105     fi
106 }
107
108 ###############################################################################
109 # Repeatedly run WCBench against ODL without restarting ODL
110 # Globals:
111 #   None
112 # Arguments:
113 #   None
114 # Returns:
115 #   Exit status of run_wcbench
116 ###############################################################################
117 loop_no_restart()
118 {
119     echo "Looping WCBench against ODL without restarting ODL"
120     while :; do
121         start_odl
122         run_wcbench
123     done
124 }
125
126 ###############################################################################
127 # Repeatedly run WCBench against ODL, restart ODL between runs
128 # Globals:
129 #   VERBOSE
130 # Arguments:
131 #   None
132 # Returns:
133 #   WCBench exit status
134 ###############################################################################
135 loop_with_restart()
136 {
137     echo "Looping WCBench against ODL, restarting ODL each run"
138     while :; do
139         start_odl
140         run_wcbench
141         # Stop ODL
142         if "$VERBOSE" = true; then
143             ./wcbench.sh -vk
144         else
145             ./wcbench.sh -k
146         fi
147     done
148 }
149
150 # If executed with no options
151 if [ $# -eq 0 ]; then
152     usage
153     exit $EX_USAGE
154 fi
155
156 # Used to output help if no valid action results from arguments
157 action_taken=false
158
159 # Parse options given from command line
160 while getopts ":hvlp:rt:" opt; do
161     case "$opt" in
162         h)
163             # Help message
164             usage
165             exit $EX_OK
166             ;;
167         v)
168             # Output debug info verbosely
169             VERBOSE=true
170             ;;
171         l)
172             # Loop without restarting ODL between WCBench runs
173             loop_no_restart
174             action_taken=true
175             ;;
176         p)
177             # Pin a given number of processors
178             # Note that this option must be given before -o (start ODL)
179             processors=${OPTARG}
180             if [ $processors -lt 1 ]; then
181                 echo "Can't pin ODL to less than one processor"
182                 exit $EX_USAGE
183             fi
184             ;;
185         r)
186             # Restart ODL between each WCBench run
187             loop_with_restart
188             action_taken=true
189             ;;
190         t)
191             # Set length of WCBench run in minutes
192             run_time=${OPTARG}
193             ;;
194         *)
195             # Print usage message
196             usage
197             exit $EX_USAGE
198     esac
199 done
200
201 # Output help message if no valid action was taken
202 if ! "$action_taken" = true; then
203     usage
204     exit $EX_USAGE
205 fi