summaryrefslogtreecommitdiffstats
path: root/scripts/qemuimage-testlib
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/qemuimage-testlib')
-rw-r--r--scripts/qemuimage-testlib110
1 files changed, 76 insertions, 34 deletions
diff --git a/scripts/qemuimage-testlib b/scripts/qemuimage-testlib
index b9afcf5bb6..823cbfa18b 100644
--- a/scripts/qemuimage-testlib
+++ b/scripts/qemuimage-testlib
@@ -39,6 +39,19 @@ Test_Info()
39 echo -e "\tTest_Info: $*" 39 echo -e "\tTest_Info: $*"
40} 40}
41 41
42# function to update target ip address
43# $1 is the process id of the process, which starts the qemu target
44# $2 is the ip address of the target
45Test_Update_IPSAVE()
46{
47 local pid=$1
48 local ip_addr=$2
49
50 if [ "$TEST_SERIALIZE" -eq 1 ]; then
51 echo "$pid $ip_addr" > $TARGET_IPSAVE
52 fi
53}
54
42# function to copy files from host into target 55# function to copy files from host into target
43# $1 is the ip address of target 56# $1 is the ip address of target
44# $2 is the files, which need to be copied into target 57# $2 is the files, which need to be copied into target
@@ -99,6 +112,11 @@ Test_SSH_UP()
99 local timeout=$2 112 local timeout=$2
100 local interval=0 113 local interval=0
101 114
115 # If TEST_SERIALIZE is set, use existing running qemu for testing
116 if [ ${TEST_SERIALIZE} -eq 1 -a -e ${TARGET_IPSAVE} ]; then
117 timeout=50
118 fi
119
102 while [ ${interval} -lt ${timeout} ] 120 while [ ${interval} -lt ${timeout} ]
103 do 121 do
104 Test_SSH ${ip_addr} "hostname" 122 Test_SSH ${ip_addr} "hostname"
@@ -106,13 +124,13 @@ Test_SSH_UP()
106 interval=`expr $interval + 10` 124 interval=`expr $interval + 10`
107 sleep 10 125 sleep 10
108 else 126 else
109 Test_Info "We can ssh on ${ip_addr} now" 127 Test_Info "We can ssh on ${ip_addr} within ${interval} seconds"
110 return 0 128 return 0
111 fi 129 fi
112 130
113 done 131 done
114 132
115 Test_Info "We can not ssh on ${ip_addr} in ${timeout}" 133 Test_Info "We can not ssh on ${ip_addr} in ${timeout} seconds"
116 return 1 134 return 1
117} 135}
118 136
@@ -162,6 +180,8 @@ Test_Kill_Qemu()
162 local ret=0 180 local ret=0
163 local ppid=0 181 local ppid=0
164 local i=0 182 local i=0
183 local index=0
184 local total=0
165 declare local pid 185 declare local pid
166 186
167 # Check if $1 pid exists and is a qemu process 187 # Check if $1 pid exists and is a qemu process
@@ -186,16 +206,39 @@ Test_Kill_Qemu()
186 ret=$? 206 ret=$?
187 done 207 done
188 208
189 # Kill these children pids from the last one 209 # When TEST_SERIALIZE is set, qemu process will not be
190 while [ $i -ne 0 ] 210 # killed until all the cases are finished
191 do 211 if [ ${TEST_SERIALIZE} -eq 1 -a -e ${TEST_STATUS} ]; then
192 i=$((i-1)) 212 index=`sed -n 2p ${TEST_STATUS} | awk '{print $3}'`
193 kill ${pid[$i]} 213 total=`sed -n 2p ${TEST_STATUS} | awk '{print $4}'`
194 sleep 2 214 if [ ${index} != ${total} ]; then
195 done 215 Test_Info "Do not kill the qemu process and use it for later testing"
216 Test_Update_IPSAVE $PID $TARGET_IPADDR
217 else
218 # If it is the last case, let's kill it
219 while [ $i -ne 0 ]
220 do
221 i=$((i-1))
222 kill ${pid[$i]}
223 sleep 2
224 done
225
226 # Kill the parent id
227 kill $PID
228 fi
196 229
197 # Kill the parent id 230 else
198 kill $PID 231 # Kill these children pids from the last one
232 while [ $i -ne 0 ]
233 do
234 i=$((i-1))
235 kill ${pid[$i]}
236 sleep 2
237 done
238
239 # Kill the parent id
240 kill $PID
241 fi
199 fi 242 fi
200 243
201 return 244 return
@@ -209,7 +252,7 @@ Test_Check_Qemu_UP()
209 Test_Info "There is no Qemu process" 252 Test_Info "There is no Qemu process"
210 return 1 253 return 1
211 else 254 else
212 Test_Info "There is at least Qemu process running" 255 Test_Info "There is at least one Qemu process running"
213 return 0 256 return 0
214 fi 257 fi
215} 258}
@@ -384,31 +427,29 @@ Test_Create_Qemu()
384 427
385 CP=`which cp` 428 CP=`which cp`
386 429
387 # When SHARE_IMAGE is set, we use the existing image under tmp folder 430 # When TEST_SERIALIZE is set, we use the existing image under tmp folder
388 if [ -e "$TEST_ROOTFS_IMAGE" ]; then 431 if [ ${TEST_SERIALIZE} -eq 1 -a -e "$TARGET_IPSAVE" ]; then
389 if [ ${SHARE_IMAGE} -eq 1 ]; then 432 # If TARGET_IPSAVE exists, check PID of the qemu process from it
390 ROOTFS_IMAGE="$TEST_ROOTFS_IMAGE" 433 PID=`awk '{print $1}' $TARGET_IPSAVE`
391 TEST_ROOTFS_IMAGE="${TEST_TMP}/${QEMUTARGET}-${QEMUARCH}-shared-test.ext3" 434 timeout=50
392 fi 435 else
393 rm -rf $TEST_ROOTFS_IMAGE 436 rm -rf $TEST_ROOTFS_IMAGE
394 fi 437 $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE
438 if [ $? -ne 0 ]; then
439 Test_Info "Image ${ROOTFS_IMAGE} copy to ${TEST_ROOTFS_IMAGE} failed, return fail"
440 return $ret
441 fi
395 442
396 $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE 443 export MACHINE=$QEMUARCH
397 444
398 if [ $? -ne 0 ]; then 445 # Create Qemu in localhost VNC Port 1
399 Test_Info "Image ${ROOTFS_IMAGE} copy to ${TEST_ROOTFS_IMAGE} failed, return fail" 446 echo "Running xterm -display ${DISPLAY} -e 'BUILDDIR=${TOPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}' &"
400 return $ret 447 xterm -display ${DISPLAY} -e "BUILDDIR=${TOPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}" &
448
449 # Get the pid of the xterm processor, which will be used in Test_Kill_Qemu
450 PID=$!
401 fi 451 fi
402 452
403 export MACHINE=$QEMUARCH
404
405 # Create Qemu in localhost VNC Port 1
406 echo "Running xterm -display ${DISPLAY} -e 'BUILDDIR=${TOPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}' &"
407 xterm -display ${DISPLAY} -e "BUILDDIR=${TOPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}" &
408
409 # Get the pid of the xterm processor, which will be used in Test_Kill_Qemu
410 PID=$!
411
412 while [ ${up_time} -lt 10 ] 453 while [ ${up_time} -lt 10 ]
413 do 454 do
414 Test_Check_Qemu_UP 455 Test_Check_Qemu_UP
@@ -437,7 +478,7 @@ Test_Create_Qemu()
437 do 478 do
438 Test_Check_IP_UP ${TARGET_IPADDR} 479 Test_Check_IP_UP ${TARGET_IPADDR}
439 if [ $? -eq 0 ]; then 480 if [ $? -eq 0 ]; then
440 Test_Info "Qemu Network is up, ping with ${TARGET_IPADDR} is OK" 481 Test_Info "Qemu Network is up, ping with ${TARGET_IPADDR} is OK within ${up_time} seconds"
441 ret=0 482 ret=0
442 break 483 break
443 else 484 else
@@ -451,7 +492,8 @@ Test_Create_Qemu()
451 Test_Info "Qemu and its network is up" 492 Test_Info "Qemu and its network is up"
452 return $ret 493 return $ret
453 else 494 else
454 Test_Info "Qemu or its network is not up in ${timeout}" 495 Test_Info "Qemu or its network is not up in ${timeout} seconds"
496 Test_Update_IPSAVE $PID $TARGET_IPADDR
455 return $ret 497 return $ret
456 fi 498 fi
457} 499}