blob: 3f447a1109932e620117e8527c1c24f877bd3bb4 [file] [log] [blame]
# Copyright 2023 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/testing/boot_tests/kernel_zbi_test.gni")
import("//build/testing/boot_tests/zbi_test_executable.gni")
import("//build/toolchain/variant_tags.gni")
import(
"//src/tests/early-boot-coverage/host-test/coverage_verification_test.gni")
if (is_fuchsia) {
config("coverage") {
cflags = [
"-fprofile-instr-generate",
"-fcoverage-mapping",
]
if (toolchain_variant.tags + [ "hwasan" ] - [ "hwasan" ] !=
toolchain_variant.tags) {
# TODO(https://fxbug.dev/42059295): We run into a linker error where a tagged
# definition of __llvm_profile_counter_bias is provided in this executable,
# but the statically-linked profile runtime is not hwasan instrumented, so
# any reference to the tagged __llvm_profile_counter_bias fails during an
# overflow check in the R_AARCH64_ADR_PREL_PG_HI21 relocation since the tag
# is outside the 32-bit range. For now, we can disable hwasan from
# instrumenting globals generated by the profile runtime.
cflags += [
"-mllvm",
"--hwasan-globals=0",
]
}
ldflags = cflags
}
# Represents a standalone elf that provides coverage data. This is a toy
# example of what things like core-test would do.
zbi_test_executable("standalone-main-bin") {
sources = [ "standalone-main.cc" ]
configs += [ ":coverage" ]
# In the coverage or profile variant, make sure the variant's flags can't
# interfere with the flags from our own config.
configs += [
"//build/config/profile",
"//build/config/profile:coverage",
]
configs -= [
"//build/config/profile",
"//build/config/profile:coverage",
]
deps = [
"//src/lib/llvm-profdata:coverage-example",
"//src/zircon/testing/standalone-test",
]
}
# Generate a kernel_zbi test with the executable as a test.
kernel_zbi_test("standalone-coverage-zbi") {
generate_cuckoo = true
deps = [ ":standalone-main-bin" ]
# TODO(https://fxbug.dev/42066527): This ZBI is not actually a ZBI test, but relies
# on the specification just for the `images` metadata implicitly set by
# `zbi_test()` and not `zbi()`. Investigate whether we can have `zbi()`
# targets set this metadata and update this target accordingly - and
# disable the ZBI from being booted as a ZBI test for now.
disabled = true
}
}
if (is_host) {
coverage_verification_test("standalone-coverage-verification-test") {
instrumented_target = ":standalone-main-bin($target_toolchain)"
assembled_system =
":standalone-coverage-zbi.cuckoo.assembled_system($default_toolchain)"
test_uri = "fuchsia-pkg://fuchsia.com/standalone-coverage-zbi.cuckoo.test#meta/standalone-coverage-zbi.cuckoo.test.cm"
expectations = [
{
source = "//src/lib/llvm-profdata/coverage-example.cc"
functions = [
{
name = "LinkTimeDeadFunction()"
count = 0
},
{
name = "RunTimeDeadFunction()"
count = 0
},
{
name = "MaybeCallRunTimeDeadFunction(bool)"
count = 1
},
{
name = "RunTimeCoveredFunction()"
count = 2
},
]
},
]
}
}
group("standalone-test") {
testonly = true
deps = [ ":standalone-coverage-verification-test($host_toolchain)" ]
}