# Copyright (c) 2025 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("../companion_device_auth.gni")
# Sanitize config for unit tests - disable CFI when coverage is enabled
# to avoid bitcode and speed up linking
if (companion_device_auth_enable_coverage) {
companion_device_auth_unit_test_sanitize =
companion_device_auth_no_cfi_sanitize
} else {
companion_device_auth_unit_test_sanitize =
companion_device_auth_default_sanitize
}
_unit_test_coverage_cflags = []
_unit_test_coverage_ldflags = []
_fuzz_test_coverage_cflags = [ "-fno-sanitize=cfi" ]
_fuzz_test_coverage_ldflags = [ "-fno-sanitize=cfi" ]
_coverage_rustflags = []
if (companion_device_auth_enable_coverage) {
_unit_test_coverage_cflags += [
"-fprofile-instr-generate",
"-fcoverage-mapping",
"-fno-sanitize=cfi",
]
_unit_test_coverage_ldflags += [
"-fprofile-instr-generate",
"-fno-sanitize=cfi",
]
_fuzz_test_coverage_cflags += [ "--coverage" ]
_fuzz_test_coverage_ldflags += [ "--coverage" ]
_coverage_rustflags += [
"-C",
"instrument-coverage",
]
}
_test_cflags = [
"-g",
"-O0",
"-fno-lto",
"-DENABLE_TEST",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
"-Dprivate=public",
"-Dprotected=public",
]
_test_ldflags = [
"-g",
"-fno-lto",
]
companion_device_auth_unit_test_cflags =
[ "-DGTEST_HAS_CLONE=0" ] + _test_cflags + _unit_test_coverage_cflags
companion_device_auth_unit_test_ldflags =
_test_ldflags + _unit_test_coverage_ldflags
companion_device_auth_unit_test_external_deps = [
"googletest:gmock_main",
"googletest:gtest_main",
]
companion_device_auth_rust_test_flags = _coverage_rustflags
companion_device_auth_fuzz_test_cflags =
_test_cflags + _fuzz_test_coverage_cflags
companion_device_auth_fuzz_test_ldflags =
_test_ldflags + _fuzz_test_coverage_ldflags