169570cc8Sopenharmony_ci#!/bin/bash 269570cc8Sopenharmony_ci# Copyright (c) 2022 Huawei Device Co., Ltd. 369570cc8Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 469570cc8Sopenharmony_ci# you may not use this file except in compliance with the License. 569570cc8Sopenharmony_ci# You may obtain a copy of the License at 669570cc8Sopenharmony_ci# 769570cc8Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 869570cc8Sopenharmony_ci# 969570cc8Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 1069570cc8Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 1169570cc8Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1269570cc8Sopenharmony_ci# See the License for the specific language governing permissions and 1369570cc8Sopenharmony_ci# limitations under the License. 1469570cc8Sopenharmony_ci 1569570cc8Sopenharmony_ci# This Script used to push test data to devices 1669570cc8Sopenharmony_ci# Usage: 1769570cc8Sopenharmony_ci# ./prepare_testdata.sh path 1869570cc8Sopenharmony_ci# path is the rootdir of ohos projects. 1969570cc8Sopenharmony_ciset -e 2069570cc8Sopenharmony_ci 2169570cc8Sopenharmony_ciif [ $# -lt 1 ];then 2269570cc8Sopenharmony_ci echo "Usage $0 <product name>" 2369570cc8Sopenharmony_ci echo "example $0 rk3568" 2469570cc8Sopenharmony_ci exit 1 2569570cc8Sopenharmony_cifi 2669570cc8Sopenharmony_ci 2769570cc8Sopenharmony_cifunction get_root_dir() { 2869570cc8Sopenharmony_ci local cur_path=$(pwd) 2969570cc8Sopenharmony_ci while [ "${cur_path}" != "" ] 3069570cc8Sopenharmony_ci do 3169570cc8Sopenharmony_ci cur_path=${cur_path%/*} 3269570cc8Sopenharmony_ci if [ "${cur_path}" == "" ];then 3369570cc8Sopenharmony_ci echo "[error] get code root dir fail" 3469570cc8Sopenharmony_ci exit 1 3569570cc8Sopenharmony_ci fi 3669570cc8Sopenharmony_ci if [ "$(basename ${cur_path})" == "base" ]; then 3769570cc8Sopenharmony_ci ohos_root=${cur_path%/*} 3869570cc8Sopenharmony_ci return 3969570cc8Sopenharmony_ci fi 4069570cc8Sopenharmony_ci done 4169570cc8Sopenharmony_ci} 4269570cc8Sopenharmony_ci 4369570cc8Sopenharmony_cifunction hdc_shell_cmd() { 4469570cc8Sopenharmony_ci # do nothing if there are not any arguments 4569570cc8Sopenharmony_ci if [ $# -eq 0 ];then 4669570cc8Sopenharmony_ci return; 4769570cc8Sopenharmony_ci fi 4869570cc8Sopenharmony_ci echo "Running command $@" 4969570cc8Sopenharmony_ci hdc shell $@ 5069570cc8Sopenharmony_ci} 5169570cc8Sopenharmony_ci 5269570cc8Sopenharmony_cifunction hdc_push_cmd() { 5369570cc8Sopenharmony_ci # do nothing if there are not any arguments 5469570cc8Sopenharmony_ci if [ $# -ne 2 ];then 5569570cc8Sopenharmony_ci return; 5669570cc8Sopenharmony_ci fi 5769570cc8Sopenharmony_ci echo "Pushing resources to device" 5869570cc8Sopenharmony_ci hdc file send $@ 5969570cc8Sopenharmony_ci sleep 0.2 6069570cc8Sopenharmony_ci} 6169570cc8Sopenharmony_ci 6269570cc8Sopenharmony_ciget_root_dir 6369570cc8Sopenharmony_ciproduct_name=$1 6469570cc8Sopenharmony_ci 6569570cc8Sopenharmony_ciif [ ! -d "${ohos_root}/out/${product_name}" ]; then 6669570cc8Sopenharmony_ci echo "product ${product_name} not exist" 6769570cc8Sopenharmony_ci exit 1 6869570cc8Sopenharmony_cifi 6969570cc8Sopenharmony_ci 7069570cc8Sopenharmony_cihdc target mount 7169570cc8Sopenharmony_cisleep 0.2 7269570cc8Sopenharmony_cihdc_shell_cmd "mount -o remount,rw /" 7369570cc8Sopenharmony_ciut_target_path="/data/appspawn_ut" 7469570cc8Sopenharmony_ciecho "Remove ${ut_target_path}" 7569570cc8Sopenharmony_cihdc_shell_cmd "rm -rf ${ut_target_path}" 7669570cc8Sopenharmony_cihdc_shell_cmd "rm /bin/AppSpawn_ut" 7769570cc8Sopenharmony_ci 7869570cc8Sopenharmony_ciecho "Create ${ut_target_path}" 7969570cc8Sopenharmony_cihdc_shell_cmd "umask 022" 8069570cc8Sopenharmony_cihdc_shell_cmd "mkdir -p ${ut_target_path}" 8169570cc8Sopenharmony_cihdc_shell_cmd "mkdir -p ${ut_target_path}/proc" 8269570cc8Sopenharmony_ci 8369570cc8Sopenharmony_ciohos_init="${ohos_root}/base/startup" 8469570cc8Sopenharmony_ci 8569570cc8Sopenharmony_cihdc_shell_cmd "mkdir -p ${ut_target_path}/coverage" 8669570cc8Sopenharmony_cisleep 0.25 8769570cc8Sopenharmony_ci 8869570cc8Sopenharmony_ci# copy file to test 8969570cc8Sopenharmony_ci 9069570cc8Sopenharmony_cihdc file send ${ohos_root}/out/${product_name}/tests/unittest/appspawn/appspawn_l2/AppSpawn_ut ${ut_target_path}/ 9169570cc8Sopenharmony_cisleep 0.25 9269570cc8Sopenharmony_cihdc_shell_cmd "cp ${ut_target_path}/AppSpawn_ut /bin/AppSpawn_ut" 9369570cc8Sopenharmony_ci 9469570cc8Sopenharmony_cihdc_shell_cmd "chmod 777 ${ut_target_path}/* -R" 9569570cc8Sopenharmony_cisleep 0.2 9669570cc8Sopenharmony_cihdc_shell_cmd "chmod 777 /bin/AppSpawn_ut" 9769570cc8Sopenharmony_ci 9869570cc8Sopenharmony_cihdc_shell_cmd "export GCOV_PREFIX=${ut_target_path}/coverage&&export GCOV_PREFIX_STRIP=20&&AppSpawn_ut" 9969570cc8Sopenharmony_cisleep 0.2 10069570cc8Sopenharmony_ci 10169570cc8Sopenharmony_ciif [ $? -ne 0 ]; then 10269570cc8Sopenharmony_ci echo "Execute init_unittest in device failed. please check the log" 10369570cc8Sopenharmony_cifi 10469570cc8Sopenharmony_ciecho "Running appspawn unittests end..." 10569570cc8Sopenharmony_ciecho "Ready to generate coverage..." 10669570cc8Sopenharmony_cipushd ${ohos_init} 10769570cc8Sopenharmony_cirm -rf ./g.sh 10869570cc8Sopenharmony_cirm -rf *.gcno 10969570cc8Sopenharmony_cirm -rf *.gcda 11069570cc8Sopenharmony_ciecho "Copy .gcta files to ${ohos_init}}" 11169570cc8Sopenharmony_ci 11269570cc8Sopenharmony_cifor file in $(hdc_shell_cmd ls /data/appspawn_ut/coverage/*.gcda); do 11369570cc8Sopenharmony_ci hdc file recv ${file} ${ohos_init}/${file:27} 11469570cc8Sopenharmony_ci chmod 777 ${ohos_init}/${file:27} 11569570cc8Sopenharmony_cidone 11669570cc8Sopenharmony_ci 11769570cc8Sopenharmony_ci 11869570cc8Sopenharmony_ciecho "Find out all gcno files and copy to ${ohos_init}" 11969570cc8Sopenharmony_cifind ${ohos_root}/out/${product_name}/obj/base/startup/ -name "*.gcno" -type f -exec cp {} . \; 12069570cc8Sopenharmony_ciif [ $? -ne 0 ]; then 12169570cc8Sopenharmony_ci echo "find gcno failed." 12269570cc8Sopenharmony_ci popd 2>&1 > /dev/null 12369570cc8Sopenharmony_ci exit 1 12469570cc8Sopenharmony_cifi 12569570cc8Sopenharmony_ci 12669570cc8Sopenharmony_ciif [ ! -f "${ohos_init}/g.sh" ]; then 12769570cc8Sopenharmony_ci echo "create g.sh" 12869570cc8Sopenharmony_ci touch ${ohos_init}/g.sh 12969570cc8Sopenharmony_ci echo "${ohos_root}/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-cov gcov \$@" > ${ohos_init}/g.sh 13069570cc8Sopenharmony_ci chmod 755 ${ohos_init}/g.sh 13169570cc8Sopenharmony_cifi 13269570cc8Sopenharmony_ci 13369570cc8Sopenharmony_ciecho "Running command lcov" 13469570cc8Sopenharmony_cilcov -d . -o "${ohos_init}/appspawn_ut_tmp.info" -b . -c --gcov-tool ${ohos_init}/g.sh 13569570cc8Sopenharmony_ci 13669570cc8Sopenharmony_ciif [ $? -ne 0 ]; then 13769570cc8Sopenharmony_ci echo "Run command lcov failed" 13869570cc8Sopenharmony_ci popd 2>&1 > /dev/null 13969570cc8Sopenharmony_cifi 14069570cc8Sopenharmony_ci 14169570cc8Sopenharmony_ciecho "Filter out don\'t cared dir" 14269570cc8Sopenharmony_cilcov --remove appspawn_ut_tmp.info "*foundation*" "*third_party*" \ 14369570cc8Sopenharmony_ci "*device.c*" "*prebuilts*" "*test/unittest/*" "*utils/native/*" "*utils/system/*" \ 14469570cc8Sopenharmony_ci -o ${ohos_init}/appspawn_ut.info 14569570cc8Sopenharmony_ci 14669570cc8Sopenharmony_cigenhtml -o ${HOME}/appspawn_coverage appspawn_ut.info 14769570cc8Sopenharmony_ciif [ $? -ne 0 ]; then 14869570cc8Sopenharmony_ci echo "Run genhtml failed." 14969570cc8Sopenharmony_ci popd 2>&1 > /dev/null 15069570cc8Sopenharmony_ci exit 1 15169570cc8Sopenharmony_cifi 15269570cc8Sopenharmony_ciecho "Clear tmp files" 15369570cc8Sopenharmony_cirm -rf ./g.sh *.gcno *.gcda appspawn_ut.info appspawn_ut_tmp.info 15469570cc8Sopenharmony_cihdc_shell_cmd "rm -rf ${ut_target_path}" 15569570cc8Sopenharmony_ciecho 15669570cc8Sopenharmony_ciecho "Generate appspawn ut coverage done." 15769570cc8Sopenharmony_ciecho "Check coverage in ${HOME}/appspawn_coverage." 15869570cc8Sopenharmony_ciecho 15969570cc8Sopenharmony_cipopd 2>&1 > /dev/null 160