• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2020-2021 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
17echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
18date +%F' '%H:%M:%S
19echo $@
20
21BASE_HOME=$(dirname $(dirname $(dirname $(dirname $(dirname $(cd $(dirname $0); pwd))))))
22PRODUCT=""
23PLATFORM=""
24TARGET=""
25KERNEL=""
26DEVICECOMPANY="hisilicon"
27BUILD_OUTFILE=*_allinone.bin
28DIST_DIR=$BASE_HOME/dist
29
30BUILD_TARGETS=""
31#BUILD_TARGETS="${BUILD_TARGETS},//utils/native/lite/test/kv_store_hal:KvStoreTest"
32
33
34usage()
35{
36    echo
37    echo "USAGE"
38    echo "       ./build_testcase.sh product=PRODUCT [kernel=KERNEL] [devicecompany=DEVICECOMPANY] [target=TARGET]"
39    echo
40    echo "        product   : PRODUCT  product name, such as wifiiot_hispark_pegasus"
41    echo "        target    : TARGET   the target for build, such as //utils/native/lite/test:liteos_m_unittest."
42    echo "        kernel : KERNEL   the target for kernel, such as liteos_m"
43    echo "        devicecompany : DEVICECOMPANY   the devicecompany for build, such as hisilicon"
44    echo
45    exit 1
46}
47
48parse_parameter()
49{
50    while [ -n "$1" ]
51    do
52        var="$1"
53        OPTIONS=$(echo ${var%%=*})
54        PARAM=$(echo ${var#*=})
55        case "$OPTIONS" in
56        product)    PRODUCT="$PARAM"
57                    ;;
58        target)     TARGET="$PARAM"
59                    ;;
60        kernel)     KERNEL="$PARAM"
61                    ;;
62        devicecompany) DEVICECOMPANY="$PARAM"
63                    ;;
64        *)   usage
65             break;;
66        esac
67        shift
68    done
69
70    if [ "$KERNEL" = "" ];then
71        echo "kernel is required, for kernel $KERNEL"
72        usage
73    fi
74
75    if [ "$PRODUCT" = "" ];then
76        echo "product is required, for product $PRODUCT"
77        usage
78    fi
79}
80
81
82build_testcases()
83{
84    cd $BASE_HOME
85    if [ "$KERNEL" = "liteos_m" ]; then
86        board_name=${PRODUCT#*_}
87        out_dir="${BASE_HOME}/out/${board_name}/${PRODUCT}"
88        suite_root_dir="${out_dir}/suites"
89        if [ "${BUILD_TARGETS}" != "" ];then
90            build_liteos_m_targets "acts" $BUILD_TARGETS
91        else
92            echo "BUILD_TARGETS=${BUILD_TARGETS}"
93        fi
94        if [ -d "$DIST_DIR" ];then
95            rm -rf $DIST_DIR
96        fi
97    fi
98}
99
100
101build_liteos_m_targets()
102{
103    current_name=$1
104    current_target=$2
105    tdd_root_dir="${suite_root_dir}/${current_name}"
106    suite_out_dir="${tdd_root_dir}/testcases"
107    suite_out_zip="${tdd_root_dir}.zip"
108
109    mkdir -p $DIST_DIR
110    IFS=',' read -r -a array <<< "${current_target}"
111    echo "--------------------------------------------${array[@]}"
112    set -e
113    mkdir -p ${DIST_DIR}/json
114
115    for element in ${array[*]}
116    do
117        echo "python build.py -p ${PRODUCT}@${DEVICECOMPANY} -f -t xts ${element}"
118        python build.py -p ${PRODUCT}@${DEVICECOMPANY} -f -t xts ${element}
119
120        suite_build_target=$(echo "${element}" | awk -F "[/:]" '{print $NF}')
121        echo "suite_build_target=${suite_build_target}"
122        module_list_file=$suite_out_dir/module_info.json
123        echo "module_list_file=${module_list_file}"
124        suite_module_name=$(python test/xts/tools/lite/build/utils.py --method_name get_modulename_by_buildtarget --arguments module_list_file=${module_list_file}#build_target=${suite_build_target})
125        echo "suite_module_name=${suite_module_name}"
126        subsystem_name=$(python test/xts/tools/lite/build/utils.py --method_name get_subsystem_name --arguments path=${element})
127        echo "subsystem_name=${subsystem_name}"
128        python test/xts/tools/lite/build/utils.py --method_name record_testmodule_info --arguments build_target_name=${suite_module_name}#module_name=${suite_module_name}#subsystem_name=${subsystem_name}#suite_out_dir=${DIST_DIR}/json#same_file=True
129
130        mkdir -p ${suite_out_dir}/${subsystem_name}
131        cp -rf ${BASE_HOME}/out/${board_name}/${PRODUCT}/${BUILD_OUTFILE} ${suite_out_dir}/${subsystem_name}/${suite_module_name}.bin
132        if [ -f "${suite_out_dir}/${subsystem_name}/*.a" ];then
133            rm -f ${suite_out_dir}/${subsystem_name}/*.a
134        fi
135        cp -rf ${tdd_root_dir} ${DIST_DIR}
136    done
137
138    cp -rf ${DIST_DIR}/${current_name} ${suite_root_dir}
139    rm -rf ${suite_out_dir}/.bin
140    cp -rf ${DIST_DIR}/json/module_info.json ${suite_out_dir}
141    cd $suite_root_dir
142    if [ -f "${suite_out_zip}" ];then
143        rm -f ${suite_out_zip}
144    fi
145    zip -rv ${suite_out_zip} ${current_name}
146
147    mkdir -p ${out_dir}/test
148    mv ${tdd_root_dir}/testcases/module_info.json ${out_dir}/test/
149    mv ${tdd_root_dir}/testcases/test_component.json ${out_dir}/test/
150    mv ${tdd_root_dir}/testcases ${out_dir}/test/unittest
151    cd $BASE_HOME
152}
153
154echo $BASE_HOME
155parse_parameter $@
156build_testcases
157
158date +%F' '%H:%M:%S
159echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
160