|
[ Source navigation ] [ Diff markup ] [ Identifier search ] |
|||
|
File indexing completed on 2024-01-05 15:56:52
0001 #!/bin/bash 0002 0003 #Copyright (c) 2020-2021 Huawei Device Co., Ltd. 0004 #Licensed under the Apache License, Version 2.0 (the "License"); 0005 #you may not use this file except in compliance with the License. 0006 #You may obtain a copy of the License at 0007 # 0008 # http://www.apache.org/licenses/LICENSE-2.0 0009 # 0010 #Unless required by applicable law or agreed to in writing, software 0011 #distributed under the License is distributed on an "AS IS" BASIS, 0012 #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0013 #See the License for the specific language governing permissions and 0014 #limitations under the License. 0015 0016 set -e 0017 0018 board=$(cat ohos_config.json | grep -oP '(?<="board": ")[^"]*' | sed -e 's/\\//g') 0019 kernel_type=$(cat ohos_config.json | grep -oP '(?<="kernel": ")[^"]*' | sed -e 's/\\//g') 0020 product=$(cat ohos_config.json | grep -oP '(?<="product": ")[^"]*' | sed -e 's/\\//g') 0021 product_path=$(cat ohos_config.json | grep -oP '(?<="product_path": ")[^"]*' | sed -e 's/\\//g') 0022 0023 real_cmd="${product_path}/qemu_run.sh" 0024 if [[ ! -x "${real_cmd}" ]]; then 0025 echo -e "Failed: ${real_cmd}" 0026 echo -e "Using 'hb set' to choose supported QEMU board\n" 0027 exit 0028 fi 0029 echo -e "board: ${board}\n" 0030 0031 rebuild_image="no" 0032 net_enable="no" 0033 vnc_enable="yes" 0034 add_boot_args="no" 0035 boot_args="no" 0036 gdb_enable="no" 0037 qemu_test="no" 0038 test_file="out/$board/$product/test_result.txt" 0039 elf_file="Invalid" 0040 qemu_help="no" 0041 0042 ################### qemu-run options ############################# 0043 help_info=$(cat <<-END 0044 Usage: qemu-run [OPTION]... 0045 Run a OHOS image in qemu according to the options. 0046 0047 Options: 0048 0049 -e, --exec file_name kernel exec file name 0050 -f, --force rebuild exec file 0051 -l, --local-desktop no VNC 0052 -b, --bootargs boot_arguments additional boot arguments(-bk1=v1,k2=v2...) 0053 -n, --net-enable enable net 0054 -g, --gdb enable gdb for kernel 0055 -t, --test test mode, exclusive with -g 0056 -h, --help print help info 0057 END 0058 ) 0059 0060 ############################## main ############################## 0061 ARGS=`getopt -o e:b:flngth -l force,net-enable,local-desktop,bootargs:,exec:,gdb,test,help -n "$0" -- "$@"` 0062 if [ $? != 0 ]; then 0063 echo "Try '$0 --help' for more information." 0064 exit 1 0065 fi 0066 eval set --"${ARGS}" 0067 0068 while true;do 0069 case "${1}" in 0070 -e|--exec) 0071 elf_file="${2}" 0072 shift; 0073 shift; 0074 ;; 0075 -f|--force) 0076 rebuild_image=yes 0077 shift; 0078 ;; 0079 -l|--local-desktop) 0080 vnc_enable=no 0081 shift; 0082 ;; 0083 -b|--bootargs) 0084 add_boot_args=yes 0085 boot_args="${2}" 0086 shift; 0087 shift; 0088 ;; 0089 -n|--net-enable) 0090 net_enable=yes 0091 shift; 0092 ;; 0093 -t|--test) 0094 qemu_test="test" 0095 shift; 0096 ;; 0097 -g|--gdb) 0098 gdb_enable=yes 0099 shift; 0100 echo -e "Qemu kernel gdb enable..." 0101 ;; 0102 -h|--help) 0103 shift; 0104 qemu_help=yes 0105 break; 0106 ;; 0107 --) 0108 shift; 0109 break; 0110 ;; 0111 esac 0112 done 0113 0114 if [ "$qemu_test" = "test" ] && [ "$gdb_enable" = "yes" ]; then 0115 echo "Error: '-g' '-t' options cannot be used together" 0116 exit 2 0117 fi 0118 0119 ############### qemu test ######################### 0120 function test_success() { 0121 echo "Test success!!!" 0122 exit 0 0123 } 0124 0125 function test_failed() { 0126 cat $test_file 0127 echo "Test failed!!!" 0128 exit 1 0129 } 0130 0131 function start_qemu_test() { 0132 if [ "$kernel_type" = "liteos_m" ]; then 0133 if [ ! -f "$test_file" ]; then 0134 test_failed 0135 else 0136 result=`tail -1 $test_file` 0137 if [ "$result" != "--- Test End ---" ]; then 0138 test_failed 0139 fi 0140 result=`tail -2 $test_file` 0141 failedresult=${result%,*} 0142 failed=${failedresult%:*} 0143 if [ "$failed" != "failed count" ]; then 0144 test_failed 0145 fi 0146 failedcount=${failedresult#*:} 0147 if [ "$failedcount" = "0" ]; then 0148 test_success 0149 else 0150 test_failed 0151 fi 0152 fi 0153 else 0154 echo "The kernel does not support the -t/--test option!"; 0155 fi 0156 } 0157 0158 function kill_specified_process(){ 0159 qemu_name=$1 0160 while true 0161 do 0162 pid=`ps -ef | grep $qemu_name | grep -v grep | awk '{print $2}' | head -n 1` 0163 if [ "$pid" == "" ]; then 0164 break 0165 fi 0166 kill -15 $pid 0167 done 0168 } 0169 0170 function start_qemu_monitor() { 0171 if [ "$kernel_type" = "liteos_m" ]; then 0172 kill_specified_process qemu_mini_test_ 0173 kill_specified_process qemu-system- 0174 ./vendor/ohemu/common/qemu_mini_test_monitor.sh $test_file & 0175 fi 0176 } 0177 0178 ######### qemu_run.sh parameters ###### 0179 # The order of parameters has strict requirements # 0180 qemu_parameters="\ 0181 $elf_file \ 0182 $rebuild_image \ 0183 $vnc_enable \ 0184 $add_boot_args $boot_args \ 0185 $net_enable \ 0186 $gdb_enable \ 0187 $qemu_test $test_file \ 0188 $qemu_help" 0189 0190 function start_qemu() { 0191 set +e 0192 if [ $qemu_help = no ]; then 0193 read -t 5 -p "Enter to start qemu[y/n]:" flag 0194 set -e 0195 start=${flag:-y} 0196 fi 0197 if [ $qemu_help = yes ] || [ ${start} = y ]; then 0198 if [ "$qemu_test" = "test" ]; then 0199 start_qemu_monitor 0200 fi 0201 0202 $real_cmd $qemu_parameters 0203 0204 if [ "$qemu_test" = "test" ]; then 0205 start_qemu_test 0206 fi 0207 else 0208 echo "Exit qemu-run" 0209 fi 0210 } 0211 0212 start_qemu
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] |
本网站由冷钦街制作 主页 |
蜀ICP备2022028677 |