1#!/bin/bash 2# Copyright (c) 2024 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 -x 16set -e 17set -o pipefail 18 19OHOS_DIR="" 20SANITIZERS=false 21COVERAGE=false 22 23print_usage() { 24 set +x 25 echo "Usage: self-check.sh [options] [mode] --dir=<ohos_dir> " 26 echo " " 27 echo " <ohos_dir> -- path to OHOS root " 28 echo "Mode: " 29 echo " -s, --sanitize build with sanitizers " 30 echo " -c, --coverage collect code coverage " 31 echo " " 32 echo "Options: " 33 echo " -h, --help print help text " 34 set -x 35} 36 37for i in "$@"; do 38 case "$i" in 39 -c | --coverage) 40 COVERAGE=true 41 shift 42 ;; 43 -s | --sanitize) 44 SANITIZERS=true 45 shift 46 ;; 47 --dir=*) 48 OHOS_DIR="${i#*=}" 49 OHOS_DIR="${OHOS_DIR/#\~/$HOME}" 50 shift 51 ;; 52 -h | --help) 53 print_usage 54 exit 1 55 ;; 56 *) 57 echo "Unknown option \"$i\"" 58 print_usage 59 exit 1 60 ;; 61 esac 62done 63 64build_standalone() { 65 set -e 66 rm -rf out/$TARGET 67 68 ./ark.py $TARGET abckit_packages --gn-args="is_standard_system=true abckit_with_sanitizers=$SANITIZERS enable_notice_collection=false abckit_with_coverage=$COVERAGE ohos_components_checktype=3 abckit_enable=true" 69 70 set +e 71} 72 73run_check_clang_format() { 74 set -e 75 ninja abckit_check_clang_format 76 set +e 77} 78 79run_check_clang_tidy() { 80 set -e 81 ninja abckit_check_clang_tidy 82 set +e 83} 84 85run_check_documentation() { 86 set -e 87 ninja abckit_documentation 88 set +e 89} 90 91build_and_run_tests() { 92 set -e 93 ninja abckit_gtests 94 95 LSAN_OPTIONS="" 96 if [ "$SANITIZERS" = "true" ]; then 97 LSAN_OPTIONS="suppressions=$OHOS_DIR/arkcompiler/runtime_core/libabckit/tests/sanitizers/ignored_leaks.supp" 98 99 if [ -f /etc/ld.so.preload ]; then 100 echo "/etc/ld.so.preload detected! Trying to manually specify LD_PRELOAD" 101 export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6 102 fi 103 fi 104 105 if [ "$COVERAGE" = "true" ]; then 106 export LLVM_PROFILE_FILE="abckit%m.profraw" 107 fi 108 109 LD_LIBRARY_PATH=./arkcompiler/runtime_core/:./arkcompiler/ets_runtime/:./thirdparty/icu/:./thirdparty/zlib/ \ 110 LSAN_OPTIONS="$LSAN_OPTIONS" \ 111 ASAN_OPTIONS=verify_asan_link_order=0 \ 112 ./tests/unittest/arkcompiler/runtime_core/libabckit/abckit_gtests 113 114 if [ "$SANITIZERS" = "false" ]; then 115 ninja abckit_stress_tests_package 116 117 if [ "$TARGET" = "x64.debug" ]; then 118 ../../arkcompiler/runtime_core/libabckit/tests/stress/stress.py --build-dir $(realpath .) 119 ../../arkcompiler/runtime_core/libabckit/tests/stress/stress_ets.py --build-dir $(realpath .) 120 ../../arkcompiler/runtime_core/libabckit/tests/stress/stress_hermes.py --build-dir $(realpath .) 121 ../../arkcompiler/runtime_core/libabckit/tests/stress/stress_node_js.py --build-dir $(realpath .) 122 else 123 ninja ark_js_vm 124 ../../arkcompiler/runtime_core/libabckit/tests/stress/stress_js_full.py --build-dir $(realpath .) 125 ../../arkcompiler/runtime_core/libabckit/tests/stress/stress_hermes_full.py --build-dir $(realpath .) 126 fi 127 fi 128 129 if [ "$COVERAGE" = "true" ]; then 130 ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-profdata merge -sparse abckit*.profraw -o abckit.profdata 131 132 ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-cov show \ 133 --instr-profile=./abckit.profdata \ 134 --summary-only --output-dir=abckit_coverage \ 135 ./arkcompiler/runtime_core/libabckit.so 136 137 ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-cov report \ 138 --ignore-filename-regex='(.*third_party/.*|.*/runtime_core/static_core/.*|.*/runtime_core/libpandabase/.*|.*/arkcompiler/ets_frontend/|.*/runtime_core/abc2program/.*|.*/runtime_core/libpandafile/.*|.*/runtime_core/assembler/.*|.*/runtime_core/platforms/.*)' \ 139 --instr-profile=./abckit.profdata ./arkcompiler/runtime_core/libabckit.so | 140 sed 's|\([^ ]\) \([^ ]\)|\1_\2|g' | 141 tr -s ' ' | 142 grep -v '\------------' | 143 grep -v 'Files_which_contain_no_functions:' | 144 sed 's| |,|g' >abckit_coverage.csv 145 146 ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-cov report \ 147 --ignore-filename-regex='(.*third_party/.*|.*/runtime_core/libabckit/src/adapter_static/.*|.*/runtime_core/static_core/.*|.*/runtime_core/abc2program/.*|.*/runtime_core/libpandabase/.*|.*/arkcompiler/ets_frontend/|.*/runtime_core/libpandafile/.*|.*/runtime_core/assembler/.*|.*/runtime_core/platforms/.*|.*/runtime_core/libabckit/src/codegen/generated/insn_selection_static.cpp|.*/runtime_core/libabckit/src/codegen/codegen_static.cpp|.*/runtime_core/libabckit/src/codegen/generated/codegen_intrinsics_static.cpp|.*/runtime_core/libabckit/src/isa_static_impl.cpp|.*/runtime_core/libabckit/src/codegen/codegen_static.h|.*/runtime_core/libabckit/src/codegen/generated/codegen_visitors_static.inc|.*/runtime_core/libabckit/src/codegen/generated/codegen_call_intrinsics_static.inc)' \ 148 --instr-profile=./abckit.profdata ./arkcompiler/runtime_core/libabckit.so | 149 sed 's|\([^ ]\) \([^ ]\)|\1_\2|g' | 150 tr -s ' ' | 151 grep -v '\------------' | 152 grep -v 'Files_which_contain_no_functions:' | 153 sed 's| |,|g' >abckit_dynamic_coverage.csv 154 155 echo "Summary abckit coverage report file: $(realpath abckit_coverage.csv)" 156 echo "Summary abckit dynamic coverage report file: $(realpath abckit_dynamic_coverage.csv)" 157 echo "Verbose abckit coverage report dir: $(realpath abckit_coverage)" 158 fi 159 160 if [ "$SANITIZERS" = "true" ]; then 161 rm -f "$TMP" 162 fi 163 164 set +e 165} 166 167if [ -z "$OHOS_DIR" ]; then 168 echo "ERROR: Path to OHOS root was not provided" 169 print_usage 170 exit 1 171fi 172 173TARGET=x64.debug 174pushd "$OHOS_DIR" || exit 1 175build_standalone 176pushd out/$TARGET || exit 1 177run_check_documentation 178run_check_clang_format 179if [ "$COVERAGE" = "false" ] && [ "$SANITIZERS" = "false" ]; then 180 run_check_clang_tidy 181fi 182build_and_run_tests 183popd || exit 1 184 185if [ "$COVERAGE" = "false" ] && [ "$SANITIZERS" = "false" ]; then 186 TARGET=x64.release 187 pushd "$OHOS_DIR" || exit 1 188 build_standalone 189 pushd out/$TARGET || exit 1 190 run_check_documentation 191 run_check_clang_format 192 run_check_clang_tidy 193 build_and_run_tests 194 popd || exit 1 195fi 196 197popd || exit 1 198