• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2024-2025 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        export LIBABCKIT_DEBUG_MODE="1"
108    fi
109
110    LD_LIBRARY_PATH=./arkcompiler/runtime_core/:./arkcompiler/ets_runtime/:./thirdparty/icu/:./thirdparty/zlib/:./thirdparty/libuv/:./arkui/napi/:./thirdparty/bounds_checking_function/:./arkui/napi/ \
111        LSAN_OPTIONS="$LSAN_OPTIONS" \
112        ASAN_OPTIONS=verify_asan_link_order=0 \
113        ./tests/unittest/arkcompiler/runtime_core/libabckit/abckit_gtests
114
115    if [ "$SANITIZERS" = "false" ]; then
116        ninja abckit_stress_tests_package
117
118        if [ "$TARGET" = "x64.debug" ]; then
119            ../../arkcompiler/runtime_core/libabckit/tests/stress/runner.py --build-dir $(realpath .)
120        else
121            ninja ark_js_vm
122            ../../arkcompiler/runtime_core/libabckit/tests/stress/stress_js_full.py --build-dir $(realpath .)
123            ../../arkcompiler/runtime_core/libabckit/tests/stress/stress_hermes_full.py --build-dir $(realpath .)
124        fi
125    fi
126
127    if [ "$COVERAGE" = "true" ]; then
128        ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-profdata merge -sparse abckit*.profraw -o abckit.profdata
129
130        ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-cov show \
131            --instr-profile=./abckit.profdata \
132            --summary-only --output-dir=abckit_coverage \
133            ./arkcompiler/runtime_core/libabckit.so
134
135        ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-cov report \
136            --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/.*)' \
137            --instr-profile=./abckit.profdata ./arkcompiler/runtime_core/libabckit.so |
138            sed 's|\([^ ]\) \([^ ]\)|\1_\2|g' |
139            tr -s ' ' |
140            grep -v '\------------' |
141            grep -v 'Files_which_contain_no_functions:' |
142            sed 's| |,|g' >abckit_coverage.csv
143
144        ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-cov report \
145            --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)' \
146            --instr-profile=./abckit.profdata ./arkcompiler/runtime_core/libabckit.so |
147            sed 's|\([^ ]\) \([^ ]\)|\1_\2|g' |
148            tr -s ' ' |
149            grep -v '\------------' |
150            grep -v 'Files_which_contain_no_functions:' |
151            sed 's| |,|g' >abckit_dynamic_coverage.csv
152
153        echo "Summary abckit coverage report file: $(realpath abckit_coverage.csv)"
154        echo "Summary abckit dynamic coverage report file: $(realpath abckit_dynamic_coverage.csv)"
155        echo "Verbose abckit coverage report dir: $(realpath abckit_coverage)"
156    fi
157
158    if [ "$SANITIZERS" = "true" ]; then
159        rm -f "$TMP"
160    fi
161
162    set +e
163}
164
165if [ -z "$OHOS_DIR" ]; then
166    echo "ERROR: Path to OHOS root was not provided"
167    print_usage
168    exit 1
169fi
170
171TARGET=x64.debug
172pushd "$OHOS_DIR" || exit 1
173build_standalone
174pushd out/$TARGET || exit 1
175run_check_documentation
176run_check_clang_format
177if [ "$COVERAGE" = "false" ] && [ "$SANITIZERS" = "false" ]; then
178    run_check_clang_tidy
179fi
180build_and_run_tests
181popd || exit 1
182
183if [ "$COVERAGE" = "false" ] && [ "$SANITIZERS" = "false" ]; then
184    TARGET=x64.release
185    pushd "$OHOS_DIR" || exit 1
186    build_standalone
187    pushd out/$TARGET || exit 1
188    run_check_documentation
189    run_check_clang_format
190    run_check_clang_tidy
191    build_and_run_tests
192    popd || exit 1
193fi
194
195popd || exit 1
196