blob: d22ac54f5dacbc6a087a2d4b08b83b581d328565 [file] [log] [blame]
# 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 this test is built for the host, and not for Fuchsia.
# This test uses instrumententation for coverage, and it is intentionally
# disabled when sanitizer instrumentation is enabled.
if (!is_asan) {
deps = [
":clang_coverage_tests($host_toolchain)",
":rust_coverage_tests($host_toolchain)",
]
}
}
# Clang coverage test is compiled with coverage enabled.
# It runs on the target, and generates an llvm-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
}
fuchsia_unittest_package("clang_coverage_test_package") {
manifest = "meta/clang_coverage_test.cml"
deps = [ ":clang_coverage_test_bin" ]
}
clang_coverage_test_rspfile = "$target_gen_dir/clang_coverage_test_bin.rsp"
link_output_rspfile("clang_coverage_test_bin.rsp") {
testonly = true
outputs = [ clang_coverage_test_rspfile ]
deps = [ ":clang_coverage_test_bin($target_toolchain)" ]
}
clang_coverage_test_binary_path = "$target_out_dir/clang_coverage_test_bin"
action("copy_clang_coverage_test_binary") {
testonly = true
sources = [ clang_coverage_test_rspfile ]
deps = [ ":clang_coverage_test_bin.rsp" ]
script = "copy_coverage_test_binary.py"
outputs = [ clang_coverage_test_binary_path ]
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.
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" ]
}
fuchsia_unittest_package("rust_coverage_test_package") {
manifest = "meta/rust_coverage_test.cml"
deps = [ ":rust_coverage_test_bin" ]
}
rust_coverage_test_rspfile = "$target_gen_dir/rust_coverage_test_bin.rsp"
link_output_rspfile("rust_coverage_test_bin.rsp") {
testonly = true
outputs = [ rust_coverage_test_rspfile ]
deps = [ ":rust_coverage_test_bin($target_toolchain)" ]
}
rust_coverage_test_binary_path = "$target_out_dir/rust_coverage_test_bin"
action("copy_rust_coverage_test_binary") {
testonly = true
sources = [ rust_coverage_test_rspfile ]
deps = [ ":rust_coverage_test_bin.rsp" ]
script = "copy_coverage_test_binary.py"
outputs = [ rust_coverage_test_binary_path ]
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",
clang_coverage_test_binary_path,
]
deps = [
":copy_clang_coverage_test_binary",
"//tools/debug/covargs",
]
}
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",
rust_coverage_test_binary_path,
]
deps = [
":copy_rust_coverage_test_binary",
"//tools/debug/covargs",
]
}
}
go_test("clang_coverage_tests") {
gopackages = [ "go.fuchsia.dev/fuchsia/src/tests/coverage" ]
deps = [ ":lib" ]
non_go_deps = [
":clang_coverage_test_deps($host_toolchain)",
":clang_coverage_test_package($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, root_build_dir),
"--coverage-test-name",
"fuchsia-pkg://fuchsia.com/clang_coverage_test_package#meta/clang_coverage_test_package.cm",
"--golden-coverage",
rebase_path("clang_golden_coverage.json", root_build_dir),
"--llvm-profdata",
rebase_path(
"//prebuilt/third_party/clang/${host_platform}/bin/llvm-profdata",
root_build_dir),
"--llvm-cov",
rebase_path("//prebuilt/third_party/clang/${host_platform}/bin/llvm-cov",
root_build_dir),
]
}
}
go_test("rust_coverage_tests") {
gopackages = [ "go.fuchsia.dev/fuchsia/src/tests/coverage" ]
deps = [ ":lib" ]
non_go_deps = [
":rust_coverage_test_deps($host_toolchain)",
":rust_coverage_test_package($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, root_build_dir),
"--coverage-test-name",
"fuchsia-pkg://fuchsia.com/rust_coverage_test_package#meta/rust_coverage_test_package.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",
]
}
}