blob: 875732ea1b7b2dcaf112468c527a22908057308b [file] [log] [blame] [edit]
# Copyright 2021 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/components.gni")
import("//build/go/go_library.gni")
import("//build/go/go_test.gni")
import("//build/rust/rustc_binary.gni")
import("//build/zircon/c_utils.gni")
group("tests") {
testonly = true
# Ensure that these tests are built for the host, and not for Fuchsia.
# These tests use instrumententation for coverage, and they are intentionally
# disabled when sanitizer instrumentation is enabled.
if (!is_asan) {
deps = [
":clang_coverage_tests_on_target($host_toolchain)",
":rust_coverage_tests_on_target($host_toolchain)",
]
# Only run host coverage tests on Linux because they use ELF build ID that is only available on Linux.
if (host_os == "linux") {
deps += [
":clang_coverage_tests_on_host($host_toolchain)",
":rust_coverage_tests_on_host($host_toolchain)",
]
}
}
}
# This is a config so the flags included here come last in the compile invocation.
config("disable_hwasan_globals") {
cflags = [
# TODO(fxbug.dev/107896): 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.
"-mllvm",
"--hwasan-globals=0",
]
}
# Clang coverage test is compiled with coverage enabled.
# It generates an llvm raw profile (.profraw file) upon execution.
executable("clang_coverage_test_bin") {
testonly = true
sources = [ "clang_coverage_test.cc" ]
cflags = [
"-fprofile-instr-generate",
"-fcoverage-mapping",
]
ldflags = cflags
configs += [ ":disable_hwasan_globals" ]
# Coverage and profiling instrumentation are incompatible within the same TU,
# so ensure we don't instrument this test incorrectly by mixing them.
exclude_toolchain_tags = [ "profile" ]
}
clang_coverage_test_rspfile_on_host =
"$target_gen_dir/clang_coverage_test_bin_on_host.rsp"
link_output_rspfile("clang_coverage_test_bin_on_host.rsp") {
testonly = true
outputs = [ clang_coverage_test_rspfile_on_host ]
deps = [ ":clang_coverage_test_bin($host_toolchain)" ]
}
clang_coverage_test_binary_path_on_host =
"$target_out_dir/clang_coverage_test_bin_on_host"
action("copy_clang_coverage_test_binary_on_host") {
testonly = true
sources = [ clang_coverage_test_rspfile_on_host ]
deps = [ ":clang_coverage_test_bin_on_host.rsp" ]
script = "copy_coverage_test_binary.py"
outputs = [ clang_coverage_test_binary_path_on_host ]
depfile = "${outputs[0]}.d"
args = [
"--input",
rebase_path(sources[0], root_build_dir),
"--output",
rebase_path(outputs[0], root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
}
fuchsia_unittest_package("clang_coverage_test_package_on_target") {
manifest = "meta/clang_coverage_test_on_target.cml"
deps = [ ":clang_coverage_test_bin" ]
}
clang_coverage_test_rspfile_on_target =
"$target_gen_dir/clang_coverage_test_bin_on_target.rsp"
link_output_rspfile("clang_coverage_test_bin_on_target.rsp") {
testonly = true
outputs = [ clang_coverage_test_rspfile_on_target ]
deps = [ ":clang_coverage_test_bin($target_toolchain)" ]
}
clang_coverage_test_binary_path_on_target =
"$target_out_dir/clang_coverage_test_bin_on_target"
action("copy_clang_coverage_test_binary_on_target") {
testonly = true
sources = [ clang_coverage_test_rspfile_on_target ]
deps = [ ":clang_coverage_test_bin_on_target.rsp" ]
script = "copy_coverage_test_binary.py"
outputs = [ clang_coverage_test_binary_path_on_target ]
depfile = "${outputs[0]}.d"
args = [
"--input",
rebase_path(sources[0], root_build_dir),
"--output",
rebase_path(outputs[0], root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
}
# Rust coverage test is compiled with coverage enabled.
# It generates an llvm raw profile (.profraw file) upon execution.
rustc_binary("rust_coverage_test_bin") {
edition = "2021"
testonly = true
source_root = "rust_coverage_test.rs"
sources = [ "rust_coverage_test.rs" ]
configs += [ "//build/config/rust:coverage" ]
# TODO(fxbug.dev/104854): Figure out link errors when lto is enabled for
# this target.
exclude_toolchain_tags = [ "lto" ]
}
rust_coverage_test_rspfile_on_host =
"$target_gen_dir/rust_coverage_test_bin_on_host.rsp"
link_output_rspfile("rust_coverage_test_bin_on_host.rsp") {
testonly = true
outputs = [ rust_coverage_test_rspfile_on_host ]
deps = [ ":rust_coverage_test_bin($host_toolchain)" ]
}
rust_coverage_test_binary_path_on_host =
"$target_out_dir/rust_coverage_test_bin_on_host"
action("copy_rust_coverage_test_binary_on_host") {
testonly = true
sources = [ rust_coverage_test_rspfile_on_host ]
deps = [ ":rust_coverage_test_bin_on_host.rsp" ]
script = "copy_coverage_test_binary.py"
outputs = [ rust_coverage_test_binary_path_on_host ]
depfile = "${outputs[0]}.d"
args = [
"--input",
rebase_path(sources[0], root_build_dir),
"--output",
rebase_path(outputs[0], root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
}
fuchsia_unittest_package("rust_coverage_test_package_on_target") {
manifest = "meta/rust_coverage_test_on_target.cml"
deps = [ ":rust_coverage_test_bin" ]
}
rust_coverage_test_rspfile_on_target =
"$target_gen_dir/rust_coverage_test_bin_on_target.rsp"
link_output_rspfile("rust_coverage_test_bin_on_target.rsp") {
testonly = true
outputs = [ rust_coverage_test_rspfile_on_target ]
deps = [ ":rust_coverage_test_bin($target_toolchain)" ]
}
rust_coverage_test_binary_path_on_target =
"$target_out_dir/rust_coverage_test_bin_on_target"
action("copy_rust_coverage_test_binary_on_target") {
testonly = true
sources = [ rust_coverage_test_rspfile_on_target ]
deps = [ ":rust_coverage_test_bin_on_target.rsp" ]
script = "copy_coverage_test_binary.py"
outputs = [ rust_coverage_test_binary_path_on_target ]
depfile = "${outputs[0]}.d"
args = [
"--input",
rebase_path(sources[0], root_build_dir),
"--output",
rebase_path(outputs[0], root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
}
go_library("lib") {
testonly = true
deps = [
"//third_party/golibs:github.com/google/go-cmp",
"//tools/botanist:botanist_lib",
"//tools/debug/covargs:llvm_api",
"//tools/testing/runtests",
"//tools/testing/testrunner:lib",
]
sources = [ "launcher_test.go" ]
}
if (is_host) {
host_test_data("clang_coverage_test_deps") {
sources = [
"$host_out_dir/covargs",
"//prebuilt/third_party/clang/${host_platform}/bin/llvm-cov",
"//prebuilt/third_party/clang/${host_platform}/bin/llvm-profdata",
"clang_golden_coverage.json",
]
deps = [ "//tools/debug/covargs" ]
}
host_test_data("clang_coverage_test_deps_on_host") {
sources = [ clang_coverage_test_binary_path_on_host ]
deps = [ ":copy_clang_coverage_test_binary_on_host" ]
}
host_test_data("clang_coverage_test_deps_on_target") {
sources = [ clang_coverage_test_binary_path_on_target ]
deps = [ ":copy_clang_coverage_test_binary_on_target" ]
}
host_test_data("rust_coverage_test_deps") {
sources = [
"$host_out_dir/covargs",
"//prebuilt/third_party/clang/${host_platform}/bin/llvm-cov",
"rust_golden_coverage.json",
]
deps = [ "//tools/debug/covargs" ]
}
host_test_data("rust_coverage_test_deps_on_host") {
sources = [ rust_coverage_test_binary_path_on_host ]
deps = [ ":copy_rust_coverage_test_binary_on_host" ]
}
host_test_data("rust_coverage_test_deps_on_target") {
sources = [ rust_coverage_test_binary_path_on_target ]
deps = [ ":copy_rust_coverage_test_binary_on_target" ]
}
}
if (is_host) {
go_test("clang_coverage_tests_on_host") {
library = ":lib"
non_go_deps = [
":clang_coverage_test_bin($host_toolchain)",
":clang_coverage_test_deps($host_toolchain)",
":clang_coverage_test_deps_on_host($host_toolchain)",
]
args = [
"--covargs",
rebase_path("$host_out_dir/covargs", root_build_dir),
"--coverage-test-binary",
rebase_path(clang_coverage_test_binary_path_on_host, root_build_dir),
"--golden-coverage",
rebase_path("clang_golden_coverage.json", root_build_dir),
"--host",
"--llvm-cov",
rebase_path("//prebuilt/third_party/clang/${host_platform}/bin/llvm-cov",
root_build_dir),
"--llvm-profdata",
rebase_path(
"//prebuilt/third_party/clang/${host_platform}/bin/llvm-profdata",
root_build_dir),
]
}
}
go_test("clang_coverage_tests_on_target") {
library = ":lib"
non_go_deps = [
":clang_coverage_test_deps($host_toolchain)",
":clang_coverage_test_deps_on_target($host_toolchain)",
":clang_coverage_test_package_on_target($target_toolchain)",
]
# Declare this test as a host-target interaction test, so that Fuchsia
# should be running in an emulator before this test starts on the host.
if (is_host && target_cpu == "x64") {
environments = [ emu_env ]
args = [
"--covargs",
rebase_path("$host_out_dir/covargs", root_build_dir),
"--coverage-test-binary",
rebase_path(clang_coverage_test_binary_path_on_target, root_build_dir),
"--coverage-test-name",
"fuchsia-pkg://fuchsia.com/clang_coverage_test_package_on_target#meta/clang_coverage_test_package_on_target.cm",
"--golden-coverage",
rebase_path("clang_golden_coverage.json", root_build_dir),
"--llvm-cov",
rebase_path("//prebuilt/third_party/clang/${host_platform}/bin/llvm-cov",
root_build_dir),
"--llvm-profdata",
rebase_path(
"//prebuilt/third_party/clang/${host_platform}/bin/llvm-profdata",
root_build_dir),
]
}
}
if (is_host) {
go_test("rust_coverage_tests_on_host") {
library = ":lib"
non_go_deps = [
":rust_coverage_test_bin($host_toolchain)",
":rust_coverage_test_deps($host_toolchain)",
":rust_coverage_test_deps_on_host($host_toolchain)",
"//build/rust:prebuilt_toolchain_host_test_data($host_toolchain)",
]
args = [
"--covargs",
rebase_path("$host_out_dir/covargs", root_build_dir),
"--coverage-test-binary",
rebase_path(rust_coverage_test_binary_path_on_host, root_build_dir),
"--golden-coverage",
rebase_path("rust_golden_coverage.json", root_build_dir),
"--host",
"--llvm-cov",
rebase_path("//prebuilt/third_party/clang/${host_platform}/bin/llvm-cov",
root_build_dir),
"--llvm-profdata",
"$out_rustc_prefix/bin/llvm-profdata",
]
}
}
go_test("rust_coverage_tests_on_target") {
library = ":lib"
non_go_deps = [
":rust_coverage_test_deps($host_toolchain)",
":rust_coverage_test_deps_on_target($host_toolchain)",
":rust_coverage_test_package_on_target($target_toolchain)",
"//build/rust:prebuilt_toolchain_host_test_data($host_toolchain)",
]
# Declare this test as a host-target interaction test, so that Fuchsia
# should be running in an emulator before this test starts on the host.
if (is_host && target_cpu == "x64") {
environments = [ emu_env ]
args = [
"--covargs",
rebase_path("$host_out_dir/covargs", root_build_dir),
"--coverage-test-binary",
rebase_path(rust_coverage_test_binary_path_on_target, root_build_dir),
"--coverage-test-name",
"fuchsia-pkg://fuchsia.com/rust_coverage_test_package_on_target#meta/rust_coverage_test_package_on_target.cm",
"--golden-coverage",
rebase_path("rust_golden_coverage.json", root_build_dir),
"--llvm-cov",
rebase_path("//prebuilt/third_party/clang/${host_platform}/bin/llvm-cov",
root_build_dir),
"--llvm-profdata",
"$out_rustc_prefix/bin/llvm-profdata",
]
}
}