7c8476735d97b18a15968fd662125463d8bb2ced
[vswitchperf.git] / ci / build-vsperf.sh
1 #!/bin/bash
2 #
3 # Copyright 2015 Intel Corporation.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #   http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # VSPERF nightly build execution script
18
19 # Usage:
20 #       build-vsperf.sh job_type
21 #   where job_type is one of "verify", "merge", "daily"
22
23 #
24 # configuration
25 #
26
27 EXIT=0
28 VSPERF_BIN='./vsperf'
29 LOG_FILE_USER='/tmp/vsperf_user.log'
30 LOG_FILE_VANILLA='/tmp/vsperf_vanilla.log'
31 LOG_FILE_PREFIX="/tmp/vsperf_build_"
32 OPNFV_POD="intel-pod3"
33
34 # CI job specific configuration
35 # VERIFY - run basic set of TCs with default settings
36 TESTCASES_VERIFY="phy2phy_tput pvp_tput"
37 TESTPARAM_VERIFY=""
38 # MERGE - run selected TCs with default settings
39 TESTCASES_MERGE="phy2phy_tput back2back phy2phy_cont pvp_tput pvvp_tput"
40 TESTPARAM_MERGE=""
41 # DAILY - run selected TCs for defined packet sizes
42 TESTCASES_DAILY='phy2phy_tput back2back phy2phy_tput_mod_vlan phy2phy_scalability pvp_tput pvp_back2back pvvp_tput pvvp_back2back'
43 TESTPARAM_DAILY='--test-params pkt_sizes=64,128,512,1024,1518'
44 # check if user config file exists if not then we will use default settings
45 [ -f $HOME/vsperf.conf ] && CONF_FILE="--conf-file ${HOME}/vsperf.conf" || CONF_FILE=""
46
47 #
48 # functions
49 #
50
51 # terminate vsperf and all its utilities
52 # it is expected that vsperf is the only python3 app
53 # and no other ovs or qemu instances are running
54 # at CI machine
55 # parameters:
56 #   none
57 function terminate_vsperf() {
58     sudo pkill stress &> /dev/null
59     sudo pkill python3 &> /dev/null
60     sudo killall -9 qemu-system-x86_64 &> /dev/null
61
62     # sometimes qemu resists to terminate, so wait a bit and kill it again
63     if pgrep qemu-system-x86_64 &> /dev/null ; then
64         sleep 5
65         sudo killall -9 qemu-system-x86_64 &> /dev/null
66         sleep 5
67     fi
68
69     sudo pkill ovs-vswitchd &> /dev/null
70     sleep 1
71     sudo pkill ovsdb-server &> /dev/null
72     sleep 1
73 }
74
75 # check and print testcase execution status
76 # parameters:
77 #   $1 - directory with results
78 function print_results() {
79     for i in $TESTCASES ; do
80         if [[ $i == *"pvp"* ]]; then
81             DEPLOYMENT="pvp"
82         elif [[ $i == *"pvvp"* ]]; then
83             DEPLOYMENT="pvvp"
84         else
85             DEPLOYMENT="p2p"
86         fi
87         RES_FILE="result_${i}_${DEPLOYMENT}.csv"
88
89         if [ -e "${1}/${RES_FILE}" ]; then
90             printf "    %-70s %-6s\n" $RES_FILE "OK"
91         else
92             printf "    %-70s %-6s\n" $RES_FILE "FAILED"
93             EXIT=1
94         fi
95     done
96 }
97
98 # execute tests and display results
99 # parameters:
100 #   $1 - vswitch and vnf combination, one of OVS_vanilla, OVS_with_DPDK_and_vHost_Cuse, OVS_with_DPDK_and_vHost_User
101 #   $2 - CI job type, one of verify, merge, daily
102 function execute_vsperf() {
103     # figure out log file name
104     LOG_FILE="${LOG_FILE_PREFIX}"`date "+%Y%m%d_%H%M%S%N"`".log"
105
106     # figure out list of TCs and execution parameters
107     case $2 in
108         "verify")
109             TESTPARAM=$TESTPARAM_VERIFY
110             TESTCASES=$TESTCASES_VERIFY
111             ;;
112         "merge")
113             TESTPARAM=$TESTPARAM_MERGE
114             TESTCASES=$TESTCASES_MERGE
115             ;;
116         *)
117             # by default use daily build
118             TESTPARAM=$TESTPARAM_DAILY
119             TESTCASES=$TESTCASES_DAILY
120             ;;
121     esac
122
123     # execute testcases
124     echo -e "\nExecution of VSPERF for $1"
125     # vsperf must be executed directly from vsperf directory
126     cd ..
127     case $1 in
128         "OVS_vanilla")
129             echo "$VSPERF_BIN --opnfvpod="$OPNFV_POD" --vswitch OvsVanilla --vnf QemuVirtioNet $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE"
130             $VSPERF_BIN --opnfvpod="$OPNFV_POD" --vswitch OvsVanilla --vnf QemuVirtioNet $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE
131             ;;
132         "OVS_with_DPDK_and_vHost_Cuse")
133             echo "$VSPERF_BIN --opnfvpod="$OPNFV_POD" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostCuse $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE"
134             $VSPERF_BIN --opnfvpod="$OPNFV_POD" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostCuse $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE
135             ;;
136         *)
137             echo "$VSPERF_BIN --opnfvpod="$OPNFV_POD" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES > $LOG_FILE"
138             $VSPERF_BIN --opnfvpod="$OPNFV_POD" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE
139             ;;
140     esac
141     # let's go back to CI dir
142     cd -
143
144     # evaluation of results
145     echo -e "\nResults for $1"
146     RES_DIR=`grep "Creating result directory" $LOG_FILE | cut -d'/' -f2-`
147     if [ "x" == "x${RES_DIR}" ] ; then
148         echo "FAILURE: Results are not available."
149     else
150         print_results "/${RES_DIR}"
151     fi
152 }
153
154 #
155 # main
156 #
157
158 # execute job based on passed parameter
159 case $1 in
160     "verify")
161         echo "VSPERF verify job"
162         echo "================="
163
164         #execute_vsperf OVS_with_DPDK_and_vHost_User $1
165
166         exit $EXIT
167         ;;
168     "merge")
169         echo "VSPERF merge job"
170         echo "================"
171
172         #execute_vsperf OVS_with_DPDK_and_vHost_User $1
173
174         exit $EXIT
175         ;;
176     *)
177         echo "VSPERF daily job"
178         echo "================"
179
180         terminate_vsperf
181         execute_vsperf OVS_with_DPDK_and_vHost_User $1
182         terminate_vsperf
183         execute_vsperf OVS_vanilla $1
184         terminate_vsperf
185
186         exit $EXIT
187         ;;
188 esac
189
190 exit $EXIT
191
192 #
193 # end
194 #