• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3#Copyright (c) 2021 Huawei Device Co., Ltd.
4#Licensed under the Apache License, Version 2.0 (the "License");
5#you may not use this file except in compliance with the License.
6#You may obtain a copy of the License at
7#
8#    http://www.apache.org/licenses/LICENSE-2.0
9#
10#Unless required by applicable law or agreed to in writing, software
11#distributed under the License is distributed on an "AS IS" BASIS,
12#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#See the License for the specific language governing permissions and
14#limitations under the License.
15
16if [ "$1" = "" ]; then
17  echo "vendor/ohemu/common/qemu_mini_test_monitor.sh [log.txt]"
18fi
19
20test_file=$1
21qemu_count_max=30 # 5 minutes
22qemu_count=0
23
24rm -f $test_file
25
26function kill_specified_process(){
27    qemu_name=$1
28    while true
29    do
30        pid=`ps -ef | grep $qemu_name | grep -v grep | awk '{print $2}' | head -n 1`
31        if [ "$pid" == "" ]; then
32            break
33        fi
34        echo "kill pid $pid"
35        kill -15 $pid
36    done
37}
38
39function kill_qemu() {
40    kill_specified_process qemu-system-
41    exit 0
42}
43
44while true
45do
46    if [ ! -f "$test_file" ]; then
47        sleep 10s
48    else
49        result=`tail -1 $test_file`
50        if [ "$result" = "--- Test End ---" ]; then
51            kill_qemu
52            break
53        else
54            sleep 10s
55        fi
56    fi
57    let qemu_count++
58    if [ $qemu_count = "$qemu_count_max" ]; then
59        kill_qemu
60        break
61    fi
62done
63