1799b5ee9Sopenharmony_ci#!/bin/bash 2799b5ee9Sopenharmony_ci 3799b5ee9Sopenharmony_ci#Copyright (c) 2021 Huawei Device Co., Ltd. 4799b5ee9Sopenharmony_ci#Licensed under the Apache License, Version 2.0 (the "License"); 5799b5ee9Sopenharmony_ci#you may not use this file except in compliance with the License. 6799b5ee9Sopenharmony_ci#You may obtain a copy of the License at 7799b5ee9Sopenharmony_ci# 8799b5ee9Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 9799b5ee9Sopenharmony_ci# 10799b5ee9Sopenharmony_ci#Unless required by applicable law or agreed to in writing, software 11799b5ee9Sopenharmony_ci#distributed under the License is distributed on an "AS IS" BASIS, 12799b5ee9Sopenharmony_ci#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13799b5ee9Sopenharmony_ci#See the License for the specific language governing permissions and 14799b5ee9Sopenharmony_ci#limitations under the License. 15799b5ee9Sopenharmony_ci 16799b5ee9Sopenharmony_ciif [ "$1" = "" ]; then 17799b5ee9Sopenharmony_ci echo "vendor/ohemu/common/qemu_mini_test_monitor.sh [log.txt]" 18799b5ee9Sopenharmony_cifi 19799b5ee9Sopenharmony_ci 20799b5ee9Sopenharmony_citest_file=$1 21799b5ee9Sopenharmony_ciqemu_count_max=30 # 5 minutes 22799b5ee9Sopenharmony_ciqemu_count=0 23799b5ee9Sopenharmony_ci 24799b5ee9Sopenharmony_cirm -f $test_file 25799b5ee9Sopenharmony_ci 26799b5ee9Sopenharmony_cifunction kill_specified_process(){ 27799b5ee9Sopenharmony_ci qemu_name=$1 28799b5ee9Sopenharmony_ci while true 29799b5ee9Sopenharmony_ci do 30799b5ee9Sopenharmony_ci pid=`ps -ef | grep $qemu_name | grep -v grep | awk '{print $2}' | head -n 1` 31799b5ee9Sopenharmony_ci if [ "$pid" == "" ]; then 32799b5ee9Sopenharmony_ci break 33799b5ee9Sopenharmony_ci fi 34799b5ee9Sopenharmony_ci echo "kill pid $pid" 35799b5ee9Sopenharmony_ci kill -15 $pid 36799b5ee9Sopenharmony_ci done 37799b5ee9Sopenharmony_ci} 38799b5ee9Sopenharmony_ci 39799b5ee9Sopenharmony_cifunction kill_qemu() { 40799b5ee9Sopenharmony_ci kill_specified_process qemu-system- 41799b5ee9Sopenharmony_ci exit 0 42799b5ee9Sopenharmony_ci} 43799b5ee9Sopenharmony_ci 44799b5ee9Sopenharmony_ciwhile true 45799b5ee9Sopenharmony_cido 46799b5ee9Sopenharmony_ci if [ ! -f "$test_file" ]; then 47799b5ee9Sopenharmony_ci sleep 10s 48799b5ee9Sopenharmony_ci else 49799b5ee9Sopenharmony_ci result=`tail -1 $test_file` 50799b5ee9Sopenharmony_ci if [ "$result" = "--- Test End ---" ]; then 51799b5ee9Sopenharmony_ci kill_qemu 52799b5ee9Sopenharmony_ci break 53799b5ee9Sopenharmony_ci else 54799b5ee9Sopenharmony_ci sleep 10s 55799b5ee9Sopenharmony_ci fi 56799b5ee9Sopenharmony_ci fi 57799b5ee9Sopenharmony_ci let qemu_count++ 58799b5ee9Sopenharmony_ci if [ $qemu_count = "$qemu_count_max" ]; then 59799b5ee9Sopenharmony_ci kill_qemu 60799b5ee9Sopenharmony_ci break 61799b5ee9Sopenharmony_ci fi 62799b5ee9Sopenharmony_cidone 63