summaryrefslogtreecommitdiffstats
path: root/scripts/qemuimage-testlib
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/qemuimage-testlib')
-rwxr-xr-xscripts/qemuimage-testlib212
1 files changed, 55 insertions, 157 deletions
diff --git a/scripts/qemuimage-testlib b/scripts/qemuimage-testlib
index f8a5299a25..2c22bf2fa6 100755
--- a/scripts/qemuimage-testlib
+++ b/scripts/qemuimage-testlib
@@ -25,8 +25,9 @@ TOOLCHAIN_PROJECTS="$COREBASE/scripts/qemuimage-tests/toolchain_projects"
25# Test Directory on target for testing 25# Test Directory on target for testing
26TARGET_TEST_DIR="/opt/test" 26TARGET_TEST_DIR="/opt/test"
27 27
28# Global variable for process id 28# Global variables for process id
29PID=0 29XTERMPID=0
30QEMUPID=0
30 31
31# Global variable for target ip address 32# Global variable for target ip address
32TARGET_IPADDR=0 33TARGET_IPADDR=0
@@ -212,90 +213,33 @@ Test_Print_Result()
212# $1 is qemu process id, which needs to be killed 213# $1 is qemu process id, which needs to be killed
213Test_Kill_Qemu() 214Test_Kill_Qemu()
214{ 215{
215 local ret=0
216 local ppid=0
217 local i=0
218 local index=0 216 local index=0
219 local total=0 217 local total=0
220 declare local pid
221
222 # Check if $1 pid exists and is a qemu process
223 ps -wwfp $PID | grep -iq "qemu"
224
225 # Find all children pid of the pid $1
226 if [ $? -eq 0 ]; then
227
228 # Check if there is any child pid of the pid $PID
229 ppid=$PID
230 ps -f --ppid $ppid
231 ret=$?
232
233 while [ $ret -eq 0 ]
234 do
235 # If yes, get the child pid and check if the child pid has other child pid
236 # Continue the while loop until there is no child pid found
237 pid[$i]=`ps -f --ppid $ppid | awk '{if ($2 != "PID") print $2}'`
238 ppid=${pid[$i]}
239 i=$((i+1))
240 ps -f --ppid $ppid
241 ret=$?
242 done
243
244 # When TEST_SERIALIZE is set, qemu process will not be
245 # killed until all the cases are finished
246 if [ ${TEST_SERIALIZE} -eq 1 -a -e ${TEST_STATUS} ]; then
247 index=`sed -n 2p ${TEST_STATUS} | awk '{print $3}'`
248 total=`sed -n 2p ${TEST_STATUS} | awk '{print $4}'`
249 if [ ${index} != ${total} ]; then
250 Test_Info "Do not kill the qemu process and use it for later testing"
251 Test_Update_IPSAVE $PID $TARGET_IPADDR
252 else
253 # If it is the last case, let's kill it
254 while [ $i -ne 0 ]
255 do
256 i=$((i-1))
257 kill ${pid[$i]}
258 sleep 2
259 done
260
261 # Kill the parent id
262 kill $PID
263 fi
264 218
219 # When TEST_SERIALIZE is set, qemu process will not be
220 # killed until all the cases are finished
221 if [ ${TEST_SERIALIZE} -eq 1 -a -e ${TEST_STATUS} ]; then
222 index=`sed -n 2p ${TEST_STATUS} | awk '{print $3}'`
223 total=`sed -n 2p ${TEST_STATUS} | awk '{print $4}'`
224 if [ ${index} != ${total} ]; then
225 Test_Info "Do not kill the qemu process and use it for later testing"
226 Test_Update_IPSAVE $XTERMPID $TARGET_IPADDR
265 else 227 else
266 # Kill these children pids from the last one 228 kill -$QEMUPID
267 while [ $i -ne 0 ] 229 kill -$XTERMPID
268 do
269 i=$((i-1))
270 kill ${pid[$i]}
271 sleep 2
272 done
273
274 # Kill the parent id
275 kill $PID
276 fi 230 fi
231 else
232 kill -$QEMUPID
233 kill -$XTERMPID
277 fi 234 fi
278 235
279 return 236 return
280} 237}
281 238
282# function to check if there is any qemu process
283Test_Check_Qemu_UP()
284{
285 local count=`ps -eo command | cut -d " " -f 1 | grep -c "\(^qemu\|.*/qemu\)"`
286 if [ ${count} -lt 1 ]; then
287 Test_Info "There is no Qemu process"
288 return 1
289 else
290 Test_Info "There is at least one Qemu process running"
291 return 0
292 fi
293}
294
295# function to check if network is up 239# function to check if network is up
296Test_Check_IP_UP() 240Test_Check_IP_UP()
297{ 241{
298 ping -c1 $1 242 ping -c1 $1 1> /dev/null
299 if [ $? -ne 0 ]; then 243 if [ $? -ne 0 ]; then
300 Test_Info "IP $1 is not up" 244 Test_Info "IP $1 is not up"
301 return 1 245 return 1
@@ -377,46 +321,12 @@ Test_Find_Image()
377Test_Fetch_Target_IP() 321Test_Fetch_Target_IP()
378{ 322{
379 local opid=$1 323 local opid=$1
380 local ppid=0
381 local ip_addr=0 324 local ip_addr=0
382 local i=0
383 declare local pid
384 325
385 # Check if $1 pid exists and contains ipaddr of target 326 # Check if $1 pid exists and contains ipaddr of target
386 ps -wwfp $opid | grep -oq "192\.168\.7\.[0-9]*::" 327 ps -wwfp $opid | grep -oq "192\.168\.7\.[0-9]*::"
387 328
388 # Find all children pid of the pid $1 329 ip_addr=`ps -wwfp $opid | grep -o "192\.168\.7\.[0-9]*::" | awk -F":" '{print $1}'`
389 # and check if they contain ipaddr of target
390 if [ $? -ne 0 ]; then
391 # Check if there is any child pid of the pid $1
392 ppid=$opid
393 ps -f --ppid $ppid > /dev/zero
394 ret=$?
395
396 while [ $ret -eq 0 ]
397 do
398 # If yes, get the child pid and check if the child pid has other child pid
399 # Continue the while loop until there is no child pid found
400 pid[$i]=`ps -f --ppid $ppid | awk '{if ($2 != "PID") print $2}'`
401 ppid=${pid[$i]}
402 i=$((i+1))
403 ps -f --ppid $ppid > /dev/zero
404 ret=$?
405 done
406
407 # Check these children pids, if they have ipaddr included in command line
408 while [ $i -ne 0 ]
409 do
410 i=$((i-1))
411 ps -wwfp ${pid[$i]} | grep -oq "192\.168\.7\.[0-9]*::"
412 if [ $? -eq 0 ]; then
413 ip_addr=`ps -wwfp ${pid[$i]} | grep -o "192\.168\.7\.[0-9]*::" | awk -F":" '{print $1}'`
414 fi
415 sleep 1
416 done
417 else
418 ip_addr=`ps -wwfp $opid | grep -o "192\.168\.7\.[0-9]*::" | awk -F":" '{print $1}'`
419 fi
420 330
421 echo $ip_addr 331 echo $ip_addr
422 332
@@ -427,13 +337,10 @@ Test_Fetch_Target_IP()
427Test_Create_Qemu() 337Test_Create_Qemu()
428{ 338{
429 local timeout=$1 339 local timeout=$1
430 local ret=1
431 local up_time=0 340 local up_time=0
432 341
433 which runqemu 342 RUNQEMU=`which runqemu`
434 if [ $? -eq 0 ]; then 343 if [ $? -ne 0 ]; then
435 RUNQEMU=`which runqemu`
436 else
437 Test_Error "Can not find runqemu in \$PATH, return fail" 344 Test_Error "Can not find runqemu in \$PATH, return fail"
438 return 1 345 return 1
439 fi 346 fi
@@ -449,7 +356,7 @@ Test_Create_Qemu()
449 # If there is no kernel image found, return failed directly 356 # If there is no kernel image found, return failed directly
450 if [ $? -eq 1 ]; then 357 if [ $? -eq 1 ]; then
451 Test_Info "No kernel image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check" 358 Test_Info "No kernel image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check"
452 return $ret 359 return 1
453 fi 360 fi
454 361
455 ROOTFS_IMAGE=$(Test_Find_Image -l ${DEPLOY_DIR}/images -t ${QEMUTARGET} -a ${QEMUARCH}) 362 ROOTFS_IMAGE=$(Test_Find_Image -l ${DEPLOY_DIR}/images -t ${QEMUTARGET} -a ${QEMUARCH})
@@ -457,7 +364,7 @@ Test_Create_Qemu()
457 # If there is no rootfs image found, return failed directly 364 # If there is no rootfs image found, return failed directly
458 if [ $? -eq 1 ]; then 365 if [ $? -eq 1 ]; then
459 Test_Info "No ${QEMUTARGET} rootfs image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check" 366 Test_Info "No ${QEMUTARGET} rootfs image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check"
460 return $ret 367 return 1
461 fi 368 fi
462 369
463 TEST_ROOTFS_IMAGE="${TEST_TMP}/${QEMUTARGET}-${QEMUARCH}-test.ext3" 370 TEST_ROOTFS_IMAGE="${TEST_TMP}/${QEMUTARGET}-${QEMUARCH}-test.ext3"
@@ -467,7 +374,7 @@ Test_Create_Qemu()
467 # When TEST_SERIALIZE is set, we use the existing image under tmp folder 374 # When TEST_SERIALIZE is set, we use the existing image under tmp folder
468 if [ ${TEST_SERIALIZE} -eq 1 -a -e "$TARGET_IPSAVE" ]; then 375 if [ ${TEST_SERIALIZE} -eq 1 -a -e "$TARGET_IPSAVE" ]; then
469 # If TARGET_IPSAVE exists, check PID of the qemu process from it 376 # If TARGET_IPSAVE exists, check PID of the qemu process from it
470 PID=`awk '{print $1}' $TARGET_IPSAVE` 377 XTERMPID=`awk '{print $1}' $TARGET_IPSAVE`
471 timeout=50 378 timeout=50
472 else 379 else
473 rm -rf $TEST_ROOTFS_IMAGE 380 rm -rf $TEST_ROOTFS_IMAGE
@@ -475,22 +382,22 @@ Test_Create_Qemu()
475 $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE 382 $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE
476 if [ $? -ne 0 ]; then 383 if [ $? -ne 0 ]; then
477 Test_Info "Image ${ROOTFS_IMAGE} copy to ${TEST_ROOTFS_IMAGE} failed, return fail" 384 Test_Info "Image ${ROOTFS_IMAGE} copy to ${TEST_ROOTFS_IMAGE} failed, return fail"
478 return $ret 385 return 1
479 fi 386 fi
480 387
481 export MACHINE=$QEMUARCH 388 export MACHINE=$QEMUARCH
482 389
483 # Create Qemu in localhost VNC Port 1 390 # Create Qemu in localhost VNC Port 1
484 echo "Running xterm -display ${DISPLAY} -e 'OE_TMPDIR=${OE_TMPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE} && /bin/sleep 60' &" 391 echo "Running xterm -display ${DISPLAY} -e 'OE_TMPDIR=${OE_TMPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE} || /bin/sleep 60' &"
485 xterm -display ${DISPLAY} -e "OE_TMPDIR=${OE_TMPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE} && /bin/sleep 60" & 392 xterm -display ${DISPLAY} -e "OE_TMPDIR=${OE_TMPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE} || /bin/sleep 60" &
486 393
487 # Get the pid of the xterm processor, which will be used in Test_Kill_Qemu 394 # Get the pid of the xterm processor, which will be used in Test_Kill_Qemu
488 PID=$! 395 XTERMPID=$!
489 fi 396 fi
490 397
491 while [ ${up_time} -lt 10 ] 398 while [ ${up_time} -lt 10 ]
492 do 399 do
493 Test_Check_Qemu_UP 400 QEMUPID=`qemuimage-testlib-pythonhelper --findqemu $XTERMPID`
494 if [ $? -ne 0 ]; then 401 if [ $? -ne 0 ]; then
495 Test_Info "Wait for qemu up..." 402 Test_Info "Wait for qemu up..."
496 up_time=`expr $up_time + 5` 403 up_time=`expr $up_time + 5`
@@ -501,15 +408,17 @@ Test_Create_Qemu()
501 fi 408 fi
502 done 409 done
503 410
411 if [ ${up_time} == 10 ]; then
412 Test_Info "No qemu process appeared to start, exiting"
413 return 1
414 fi
415
504 # Parse IP address of target from the qemu command line 416 # Parse IP address of target from the qemu command line
505 if [ ${up_time} -lt ${timeout} ]; then 417 TARGET_IPADDR=`Test_Fetch_Target_IP $QEMUPID`
506 sleep 5 418 # If IP address is 0, means there is no qemu process found
507 TARGET_IPADDR=`Test_Fetch_Target_IP $PID` 419 if [ ${TARGET_IPADDR} == "0" ]; then
508 # If IP address is 0, means there is no qemu process found 420 Test_Info "There is no qemu process or qemu ip address found, return failed"
509 if [ ${TARGET_IPADDR} == "0" ]; then 421 return 1
510 Test_Info "There is no qemu process or qemu ip address found, return failed"
511 return $ret
512 fi
513 fi 422 fi
514 423
515 while [ ${up_time} -lt ${timeout} ] 424 while [ ${up_time} -lt ${timeout} ]
@@ -517,8 +426,7 @@ Test_Create_Qemu()
517 Test_Check_IP_UP ${TARGET_IPADDR} 426 Test_Check_IP_UP ${TARGET_IPADDR}
518 if [ $? -eq 0 ]; then 427 if [ $? -eq 0 ]; then
519 Test_Info "Qemu Network is up, ping with ${TARGET_IPADDR} is OK within ${up_time} seconds" 428 Test_Info "Qemu Network is up, ping with ${TARGET_IPADDR} is OK within ${up_time} seconds"
520 ret=0 429 return 0
521 break
522 else 430 else
523 Test_Info "Wait for Qemu Network up" 431 Test_Info "Wait for Qemu Network up"
524 up_time=`expr $up_time + 5` 432 up_time=`expr $up_time + 5`
@@ -526,14 +434,9 @@ Test_Create_Qemu()
526 fi 434 fi
527 done 435 done
528 436
529 if [ $ret -eq 0 ]; then 437 Test_Info "Qemu or its network is not up in ${timeout} seconds"
530 Test_Info "Qemu and its network is up" 438 Test_Update_IPSAVE $XTERMPID $TARGET_IPADDR
531 return $ret 439 return 1
532 else
533 Test_Info "Qemu or its network is not up in ${timeout} seconds"
534 Test_Update_IPSAVE $PID $TARGET_IPADDR
535 return $ret
536 fi
537} 440}
538 441
539# Function to prepare test project for toolchain test 442# Function to prepare test project for toolchain test
@@ -542,41 +445,36 @@ Test_Create_Qemu()
542Test_Project_Prepare() 445Test_Project_Prepare()
543{ 446{
544 local toolchain_dir=$1 447 local toolchain_dir=$1
545 local ret=1
546 448
547 if [ ! -d ${toolchain_dir} ]; then 449 if [ ! -d ${toolchain_dir} ]; then
548 mkdir -p ${toolchain_dir} 450 mkdir -p ${toolchain_dir}
549 ret=$? 451 if [ $? -ne 0 ]; then
550 452 ret=$?
551 if [ $ret -ne 0 ]; then
552 Test_Info "Create ${toolchain_dir} fail, return" 453 Test_Info "Create ${toolchain_dir} fail, return"
553 return $ret 454 return $ret
554 fi 455 fi
555 fi 456 fi
556 457
557 ret=0
558 # Download test project tarball if it does not exist 458 # Download test project tarball if it does not exist
559 if [ ! -f ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} ]; then 459 if [ ! -f ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} ]; then
560 wget -c -t 5 $PROJECT_DOWNLOAD_URL -O ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} 460 wget -c -t 5 $PROJECT_DOWNLOAD_URL -O ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix}
561 ret=$? 461 if [ $? -ne 0 ]; then
462 ret=$?
463 Test_Info "Fail to download ${2}-${PROJECT_PV}.${suffix} from $PROJECT_DOWNLOAD_URL"
464 rm -rf ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix}
465 return $ret
466 fi
562 fi 467 fi
563 468
564 # Extract the test project into ${TEST_TMP} 469 # Extract the test project into ${TEST_TMP}
565 if [ $ret -eq 0 ]; then 470 tar jxf ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} -C ${TEST_TMP}
566 tar jxf ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} -C ${TEST_TMP} 471 if [ $? -ne 0 ]; then
567 ret=$? 472 ret=$?
568 if [ $ret -eq 0 ]; then 473 Test_Info "Fail to extract ${2}-${PROJECT_PV}.${suffix} into ${TEST_TMP}"
569 Test_Info "Extract ${2}-${PROJECT_PV}.${suffix} into ${TEST_TMP} successfully"
570 return $ret
571 else
572 Test_Info "Fail to extract ${2}-${PROJECT_PV}.${suffix} into ${TEST_TMP}"
573 return $ret
574 fi
575 else
576 Test_Info "Fail to download ${2}-${PROJECT_PV}.${suffix} from $PROJECT_DOWNLOAD_URL"
577 rm -rf ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix}
578 return $ret 474 return $ret
579 fi 475 fi
476 Test_Info "Extract ${2}-${PROJECT_PV}.${suffix} into ${TEST_TMP} successfully"
477 return 0
580} 478}
581 479
582# Function to prepare toolchain environment 480# Function to prepare toolchain environment