diff options
Diffstat (limited to 'scripts/qemuimage-testlib')
-rw-r--r-- | scripts/qemuimage-testlib | 127 |
1 files changed, 99 insertions, 28 deletions
diff --git a/scripts/qemuimage-testlib b/scripts/qemuimage-testlib index c2c394d5e..823cbfa18 100644 --- a/scripts/qemuimage-testlib +++ b/scripts/qemuimage-testlib @@ -39,6 +39,19 @@ Test_Info() echo -e "\tTest_Info: $*" } +# function to update target ip address +# $1 is the process id of the process, which starts the qemu target +# $2 is the ip address of the target +Test_Update_IPSAVE() +{ + local pid=$1 + local ip_addr=$2 + + if [ "$TEST_SERIALIZE" -eq 1 ]; then + echo "$pid $ip_addr" > $TARGET_IPSAVE + fi +} + # function to copy files from host into target # $1 is the ip address of target # $2 is the files, which need to be copied into target @@ -99,6 +112,11 @@ Test_SSH_UP() local timeout=$2 local interval=0 + # If TEST_SERIALIZE is set, use existing running qemu for testing + if [ ${TEST_SERIALIZE} -eq 1 -a -e ${TARGET_IPSAVE} ]; then + timeout=50 + fi + while [ ${interval} -lt ${timeout} ] do Test_SSH ${ip_addr} "hostname" @@ -106,13 +124,13 @@ Test_SSH_UP() interval=`expr $interval + 10` sleep 10 else - Test_Info "We can ssh on ${ip_addr} now" + Test_Info "We can ssh on ${ip_addr} within ${interval} seconds" return 0 fi done - Test_Info "We can not ssh on ${ip_addr} in ${timeout}" + Test_Info "We can not ssh on ${ip_addr} in ${timeout} seconds" return 1 } @@ -162,6 +180,8 @@ Test_Kill_Qemu() local ret=0 local ppid=0 local i=0 + local index=0 + local total=0 declare local pid # Check if $1 pid exists and is a qemu process @@ -186,16 +206,39 @@ Test_Kill_Qemu() ret=$? done - # Kill these children pids from the last one - while [ $i -ne 0 ] - do - i=$((i-1)) - kill ${pid[$i]} - sleep 2 - done + # When TEST_SERIALIZE is set, qemu process will not be + # killed until all the cases are finished + if [ ${TEST_SERIALIZE} -eq 1 -a -e ${TEST_STATUS} ]; then + index=`sed -n 2p ${TEST_STATUS} | awk '{print $3}'` + total=`sed -n 2p ${TEST_STATUS} | awk '{print $4}'` + if [ ${index} != ${total} ]; then + Test_Info "Do not kill the qemu process and use it for later testing" + Test_Update_IPSAVE $PID $TARGET_IPADDR + else + # If it is the last case, let's kill it + while [ $i -ne 0 ] + do + i=$((i-1)) + kill ${pid[$i]} + sleep 2 + done + + # Kill the parent id + kill $PID + fi - # Kill the parent id - kill $PID + else + # Kill these children pids from the last one + while [ $i -ne 0 ] + do + i=$((i-1)) + kill ${pid[$i]} + sleep 2 + done + + # Kill the parent id + kill $PID + fi fi return @@ -204,12 +247,12 @@ Test_Kill_Qemu() # function to check if there is any qemu process Test_Check_Qemu_UP() { - local count=`ps -ef | grep -c qemu` - if [ ${count} -lt 2 ]; then + local count=`ps -eo command | cut -d " " -f 1 | grep -c "\(^qemu\|.*/qemu\)"` + if [ ${count} -lt 1 ]; then Test_Info "There is no Qemu process" return 1 else - Test_Info "There is at least Qemu process running" + Test_Info "There is at least one Qemu process running" return 0 fi } @@ -365,27 +408,49 @@ Test_Create_Qemu() elif [ "$QEMUARCH" = "qemumips" ]; then KERNEL=$(Test_Find_Image -l ${DEPLOY_DIR}/images -k vmlinux -a ${QEMUARCH}) fi + + # If there is no kernel image found, return failed directly + if [ $? -eq 1 ]; then + Test_Info "No kernel image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check" + return $ret + fi ROOTFS_IMAGE=$(Test_Find_Image -l ${DEPLOY_DIR}/images -t ${QEMUTARGET} -a ${QEMUARCH}) + + # If there is no rootfs image found, return failed directly + if [ $? -eq 1 ]; then + Test_Info "No ${QEMUTARGET} rootfs image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check" + return $ret + fi + TEST_ROOTFS_IMAGE="${TEST_TMP}/${QEMUTARGET}-${QEMUARCH}-test.ext3" CP=`which cp` - if [ -e "$TEST_ROOTFS_IMAGE" ]; then - rm -rf $TEST_ROOTFS_IMAGE - fi - $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE - - export MACHINE=$QEMUARCH - # Create Qemu in localhost VNC Port 1 - xterm -display ${DISPLAY} -e "${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}" & + # When TEST_SERIALIZE is set, we use the existing image under tmp folder + if [ ${TEST_SERIALIZE} -eq 1 -a -e "$TARGET_IPSAVE" ]; then + # If TARGET_IPSAVE exists, check PID of the qemu process from it + PID=`awk '{print $1}' $TARGET_IPSAVE` + timeout=50 + else + rm -rf $TEST_ROOTFS_IMAGE + $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE + if [ $? -ne 0 ]; then + Test_Info "Image ${ROOTFS_IMAGE} copy to ${TEST_ROOTFS_IMAGE} failed, return fail" + return $ret + fi - # Get the pid of the xterm processor, which will be used in Test_Kill_Qemu - PID=$! + export MACHINE=$QEMUARCH - sleep 5 + # Create Qemu in localhost VNC Port 1 + echo "Running xterm -display ${DISPLAY} -e 'BUILDDIR=${TOPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}' &" + xterm -display ${DISPLAY} -e "BUILDDIR=${TOPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}" & - while [ ${up_time} -lt ${timeout} ] + # Get the pid of the xterm processor, which will be used in Test_Kill_Qemu + PID=$! + fi + + while [ ${up_time} -lt 10 ] do Test_Check_Qemu_UP if [ $? -ne 0 ]; then @@ -402,13 +467,18 @@ Test_Create_Qemu() if [ ${up_time} -lt ${timeout} ]; then sleep 5 TARGET_IPADDR=`Test_Fetch_Target_IP $PID` + # If IP address is 0, means there is no qemu process found + if [ ${TARGET_IPADDR} == "0" ]; then + Test_Info "There is no qemu process or qemu ip address found, return failed" + return $ret + fi fi while [ ${up_time} -lt ${timeout} ] do Test_Check_IP_UP ${TARGET_IPADDR} if [ $? -eq 0 ]; then - Test_Info "Qemu Network is up, ping with ${TARGET_IPADDR} is OK" + Test_Info "Qemu Network is up, ping with ${TARGET_IPADDR} is OK within ${up_time} seconds" ret=0 break else @@ -422,7 +492,8 @@ Test_Create_Qemu() Test_Info "Qemu and its network is up" return $ret else - Test_Info "Qemu or its network is not up in ${timeout}" + Test_Info "Qemu or its network is not up in ${timeout} seconds" + Test_Update_IPSAVE $PID $TARGET_IPADDR return $ret fi } |