This patch includes updated scripts to enable ftrace and collect
[kvmfornfv.git] / ci / test_kvmfornfv.sh
1 #!/bin/bash
2
3 ############################################################
4 ## This script  is an interface to trigger the
5 ## cyclicTestTrigger.sh for test type like patch verification,
6 ## daily testing.
7 ## Releng will trigger this script by passing test type as
8 ## verify/daily and test name as idle_idle/stress_idle/
9 ## packet_forward as arguments.
10 ## Verify Job runs idle_idle,packet_forward test
11 ## daily job runs base on the test name parameter
12 ############################################################
13
14 test_type=$1
15 test_name=$2
16 ftrace_enable=0
17 cyclictest_env_verify=("idle_idle" "cpustress_idle" "memorystress_idle" "iostress_idle") #cyclictest environment
18 cyclictest_env_daily=("idle_idle" "cpustress_idle" "memorystress_idle" "iostress_idle")
19 cyclictest_result=0 #exit code of cyclictest
20 packetforward_result=0 #exit code of packet forward
21 source $WORKSPACE/ci/envs/host-config
22
23 function packetForward {
24    #executing packet forwarding test cases based on the job type.
25    if [ ${test_type} == "verify" ];then
26       echo "packet forwarding test cases are not yet implemented for verify job"
27       packetforward_result=0
28    elif [ ${test_type} == "daily" ];then
29       source $WORKSPACE/ci/cyclicTestTrigger.sh $HOST_IP
30       connect_host
31       #Waiting for ssh to be available for the host machine.
32       sleep 20
33       # copy files and rpms and setup environment required for executing test cases
34       setUpPacketForwarding
35       sleep 1
36       #Verifying whether the test node is up and running
37       connect_host
38       sleep 20
39       #Install and Execute packet forwarding test cases
40       runPacketForwarding $test_type
41       packetforward_result=$?
42    else
43       echo "Incorrect test type ${test_type}"
44       exit 1
45    fi
46 }
47
48 function cyclictest {
49    test_case=$1
50    source $WORKSPACE/ci/cyclicTestTrigger.sh $HOST_IP $test_time $test_type $test_case
51    #Verifying whether the test node is up and running
52    connect_host
53    #Waiting for ssh to be available for the host machine.
54    sleep 20
55    #calculating and verifying sha512sum of the guestimage.
56    if ! verifyGuestImage;then
57       exit 1
58    fi
59    #Update kvmfornfv_cyclictest_${testName}.yaml with test_time and pod.yaml with IP
60    updateYaml
61    #Running PCM utility
62    collect_MBWInfo $test_type
63    #Cleaning the environment before running cyclictest through yardstick
64    env_clean
65    #Creating a docker image with yardstick installed and launching ubuntu docker to run yardstick cyclic testcase
66    if runCyclicTest ${ftrace_enable};then
67       cyclictest_result=`expr ${cyclictest_result} + 0`
68    else
69       echo "Test case execution FAILED for ${test_case} environment"
70       cyclictest_result=`expr ${cyclictest_result} + 1`
71    fi
72    echo "Terminating PCM Process"
73    sudo ssh root@${HOST_IP} "pid=\$(ps aux | grep 'pcm' | awk '{print \$2}' | head -1); echo \$pid |xargs kill -SIGTERM"
74 }
75 function collect_MBWInfo {
76    #Collecting the Memory Bandwidth Information using pcm-memory utility
77    source $WORKSPACE/ci/envs/host-config
78    testType=$1
79    timeStamp=$(date +%Y%m%d%H%M%S)
80    echo "Running PCM memory to collect memory bandwidth"
81    sudo ssh root@${HOST_IP} "mkdir -p /root/MBWInfo"
82    sudo ssh root@${HOST_IP} "${pcm_memory} 60 &>/root/MBWInfo/MBWInfo_${testType}_${timeStamp} &disown"
83 }
84 function install_pcm {
85    source $WORKSPACE/ci/envs/host-config
86    sudo ssh root@${HOST_IP} '
87    modelName=`cat /proc/cpuinfo | grep -i "model name" | uniq`
88    if echo "$modelName" | grep -i "xeon" ;then
89       echo "pcm utility supports $modelName processor"
90    else
91       echo "check for the pcm utility supported processors"
92       exit 1
93    fi
94    cd /root
95    if [ ! -d "pcm" ]; then
96      `git clone https://github.com/opcm/pcm`
97       cd pcm
98       make
99       echo "Disabling NMI Watchdog"
100       echo 0 > /proc/sys/kernel/nmi_watchdog
101       echo "To Access MSR registers installing msr-tools"
102       sudo yum install msr-tools
103       sudo modprobe msr
104    fi
105    '
106 }
107
108 #Execution of testcases based on test type and test name from releng.
109 if [ ${test_type} == "verify" ];then
110    HOST_IP="10.10.100.21"
111    test_time=1000 # 1s
112    install_pcm
113    if [ ${ftrace_enable} -eq '1' ]; then
114       for env in ${cyclictest_env_verify[@]}
115       do
116          #Enabling ftrace for kernel debugging.
117          sed -i '/host-setup1.sh/a\    \- \"enable-trace.sh\"' $WORKSPACE/tests/kvmfornfv_cyclictest_hostenv_guestenv.yaml
118          #Executing cyclictest through yardstick.
119          cyclictest ${env}
120          sleep 10
121       done
122       #Execution of packet forwarding test cases.
123       packetForward
124    else
125       for env in ${cyclictest_env_verify[@]}
126       do
127          #Executing cyclictest through yardstick.
128          cyclictest ${env}
129          sleep 10
130       done
131       #Execution of packet forwarding test cases.
132       packetForward
133    fi
134    if [ ${cyclictest_result} -ne 0 ] ||  [ ${packetforward_result} -ne 0 ];then
135       echo "Test case FAILED"
136       test_exit 1
137    else
138       test_exit 0
139    fi
140 elif [ ${test_type} == "daily" ];then
141    HOST_IP="10.10.100.22"
142    test_time=3600000 #1h
143    install_pcm
144    if [ ${test_name} == "packet_forward" ];then
145       packetForward
146       packet_fwd_logs
147       #clean the test environment after the test case execution.
148       sudo ssh root@${HOST_IP} "rm -rf /root/workspace/*"
149       host_clean
150       if [ ${packetforward_result} -ne 0 ] ; then
151          echo "Execution of packet forwarding test cases FAILED"
152          packet_fwd_exit 1
153       else
154          echo "Executed packet forwarding test cases SUCCESSFULLY"
155          packet_fwd_exit 0
156       fi
157    elif [ ${test_name} == "cyclictest" ];then
158       if [ ${ftrace_enable} -eq '1' ]; then
159          for env in ${cyclictest_env_daily[@]}
160          do
161             #Enabling ftrace for kernel debugging.
162             sed -i '/host-setup1.sh/a\    \- \"enable-trace.sh\"' kvmfornfv_cyclictest_hostenv_guestenv.yaml
163             #Executing cyclictest through yardstick.
164             cyclictest ${env}
165             #disabling ftrace and collecting the logs to upload to artifact repository. 
166             ftrace_disable
167             sleep 5
168          done
169       else
170          for env in ${cyclictest_env_daily[@]}
171          do
172          #Executing cyclictest through yardstick.
173          cyclictest ${env}
174          sleep 5
175          done
176       fi
177          if [ ${cyclictest_result} -ne 0 ] ; then
178             echo "Cyclictest case execution FAILED"
179             test_exit 1
180          else
181             echo "Cyclictest case executed SUCCESSFULLY"
182             test_exit 0
183          fi
184    fi
185 elif [ ${test_type} == "merge" ];then
186    echo "Test is not enabled for ${test_type}"
187    exit 0
188 else
189    echo "Incorrect test type ${test_type}"
190 fi