diff options
| author | Jiajun Xu <jiajun.xu@intel.com> | 2010-09-01 23:38:53 +0800 |
|---|---|---|
| committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-09-02 11:00:08 +0100 |
| commit | 80993c4e1b9aa68651a026dd7416ba3d5e96c50c (patch) | |
| tree | 13af9707a9ae68fcd358e2cf36ad7b9f2d985f65 /scripts/qemuimage-testlib | |
| parent | 4b611b66743a5ec220aef34d796af63029bb5fd9 (diff) | |
| download | poky-80993c4e1b9aa68651a026dd7416ba3d5e96c50c.tar.gz | |
qemuimage-testlib: kill qemu process according to its pid, instead of process name
poky-qemu-internal will set up a tap lockfile when creating tap device. The lockfile
will be released when a TERM signal is received. In previous code, function
Test_Kill_Qemu uses pkill to kill all process named "qemu". This may cause lockfile
release function not work in poky-qemu-internal. Then poky-qemu-internal will be
hang when user start QEMU the second time. To prevent the issue, the new function
Test_Kill_Qemu kills all child pid with a given parent process ID.
Signed-off-by Jiajun Xu <jiajun.xu@intel.com>
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} ] |
