1#!/bin/bash
2# Copyright (c) 2023 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15set -e
16
17script_path=$(cd $(dirname $0);pwd)
18pre_dir_path=$(dirname ${script_path})
19pre_dir_path=$(dirname ${pre_dir_path})
20root_path=$(dirname ${pre_dir_path})
21echo $root_path
22
23CONFIG_PATH=$root_path/build/test/example/build_example.json
24SRC_BUNDLE_PATH=$root_path/build/test/example/test_build.json
25DEST_BUNDLE_PATH=$root_path/build/common/bundle.json
26echo $CONFIG_PATH
27
28
29
30function read_file() {
31    FILENAME=$1;KEY=$2
32    RESULT=$(cat $FILENAME | grep $KEY | awk -F\" '{ print $4 }')
33    echo $RESULT
34}
35
36function generate_build_option_report() {
37    option_report_path=$(read_file $CONFIG_PATH option_report_path)
38    option_script_path=$(read_file $CONFIG_PATH option_script_path)
39    pytest -vs --html $root_path$option_report_path $root_path$option_script_path
40    pkill -f '/pyd.py --root .*/.pycache --start'
41}
42
43function generate_gn_template_report() {
44    gn_template_report_path=$(read_file $CONFIG_PATH gn_template_report_path)
45    gn_template_script_path=$(read_file $CONFIG_PATH gn_template_script_path)
46    pytest -vs --html $root_path$gn_template_report_path $root_path$gn_template_script_path
47}
48
49function generate_performance_report() {
50    performance_script_path=$(read_file $CONFIG_PATH performance_script_path)
51    python3 $root_path$performance_script_path
52}
53
54function start() {
55    if [[ $# -eq 1 && $1 == 'all' ]]; then
56      generate_build_option_report
57      generate_performance_report
58      generate_gn_template_report
59    elif [[ $# -eq 1 && $1 == 'option' ]]; then
60      generate_build_option_report
61    elif [[ $# -eq 1 && $1 == 'template' ]]; then
62      generate_gn_template_report
63    elif [[ $# -eq 1 && $1 == 'performance' ]]; then
64      generate_performance_report
65    else
66      echo 'args wrong'
67    fi
68}
69
70rm -rf $root_path/out
71product_path=$(read_file $CONFIG_PATH product_path)
72mkdir -p $root_path$product_path
73
74cp $SRC_BUNDLE_PATH $DEST_BUNDLE_PATH
75
76start "$@"
77
78
79
80
81