diff options
Diffstat (limited to 'scripts/qemuimage-testlib')
| -rw-r--r-- | scripts/qemuimage-testlib | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/scripts/qemuimage-testlib b/scripts/qemuimage-testlib index 6dc219da27..733cd12c05 100644 --- a/scripts/qemuimage-testlib +++ b/scripts/qemuimage-testlib | |||
| @@ -16,6 +16,9 @@ | |||
| 16 | 16 | ||
| 17 | TYPE="ext3" | 17 | TYPE="ext3" |
| 18 | 18 | ||
| 19 | # Global variable for process id | ||
| 20 | PID=0 | ||
| 21 | |||
| 19 | # common function for information print | 22 | # common function for information print |
| 20 | Test_Error() | 23 | Test_Error() |
| 21 | { | 24 | { |
| @@ -92,11 +95,50 @@ Test_Print_Result() | |||
| 92 | echo -e "\t$1\t\t$PASS\t$FAIL\t$NORESULT" >> $TEST_RESULT/testresult.log | 95 | echo -e "\t$1\t\t$PASS\t$FAIL\t$NORESULT" >> $TEST_RESULT/testresult.log |
| 93 | } | 96 | } |
| 94 | 97 | ||
| 95 | # function to kill qemu | 98 | # Test_Kill_Qemu to kill child pid with parent pid given |
| 99 | # $1 is qemu process id, which needs to be killed | ||
| 96 | Test_Kill_Qemu() | 100 | Test_Kill_Qemu() |
| 97 | { | 101 | { |
| 98 | sudo pkill -9 qemu | 102 | local ret=0 |
| 99 | return $? | 103 | local ppid=0 |
| 104 | local i=0 | ||
| 105 | declare local pid | ||
| 106 | |||
| 107 | # Check if $1 pid exists and is a qemu process | ||
| 108 | ps -fp $PID | grep -iq "qemu" | ||
| 109 | |||
| 110 | # Find all children pid of the pid $1 | ||
| 111 | if [ $? -eq 0 ]; then | ||
| 112 | |||
| 113 | # Check if there is any child pid of the pid $PID | ||
| 114 | ppid=$PID | ||
| 115 | ps -f --ppid $ppid | ||
| 116 | ret=$? | ||
| 117 | |||
| 118 | while [ $ret -eq 0 ] | ||
| 119 | do | ||
| 120 | # If yes, get the child pid and check if the child pid has other child pid | ||
| 121 | # Continue the while loop until there is no child pid found | ||
| 122 | pid[$i]=`ps -f --ppid $ppid | awk '{if ($2 != "PID") print $2}'` | ||
| 123 | ppid=${pid[$i]} | ||
| 124 | i=$((i+1)) | ||
| 125 | ps -f --ppid $ppid | ||
| 126 | ret=$? | ||
| 127 | done | ||
| 128 | |||
| 129 | # Kill these children pids from the last one | ||
| 130 | while [ $i -ne 0 ] | ||
| 131 | do | ||
| 132 | i=$((i-1)) | ||
| 133 | kill ${pid[$i]} | ||
| 134 | sleep 2 | ||
| 135 | done | ||
| 136 | |||
| 137 | # Kill the parent id | ||
| 138 | kill $PID | ||
| 139 | fi | ||
| 140 | |||
| 141 | return | ||
| 100 | } | 142 | } |
| 101 | 143 | ||
| 102 | # function to check if there is any qemu process | 144 | # function to check if there is any qemu process |
| @@ -224,10 +266,13 @@ Test_Create_Qemu() | |||
| 224 | $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE | 266 | $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE |
| 225 | 267 | ||
| 226 | export MACHINE=$QEMUARCH | 268 | export MACHINE=$QEMUARCH |
| 227 | # Create Qemu in localhost VNC Port 1 | ||
| 228 | 269 | ||
| 270 | # Create Qemu in localhost VNC Port 1 | ||
| 229 | xterm -display ${DISPLAY} -e "${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}" & | 271 | xterm -display ${DISPLAY} -e "${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}" & |
| 230 | 272 | ||
| 273 | # Get the pid of the xterm processor, which will be used in Test_Kill_Qemu | ||
| 274 | PID=$! | ||
| 275 | |||
| 231 | sleep 5 | 276 | sleep 5 |
| 232 | 277 | ||
| 233 | while [ ${up_time} -lt ${timeout} ] | 278 | while [ ${up_time} -lt ${timeout} ] |
