blob: 6ebe446700bb090df0152cf381b74dcc6670c4e5 [file] [log] [blame]
# Copyright 2019 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/dist/generated_resource.gni")
import("//build/dist/renamed_binary.gni")
import("//build/dist/resource.gni")
import("//build/test.gni")
import("//build/testing/bootfs_test.gni")
test("runtests-utils") {
sources = [
"fuchsia-run-test.cc",
"log-exporter-test.cc",
"runtests-utils-test-utils.cc",
"runtests-utils-test.cc",
]
deps = [
"//sdk/fidl/fuchsia.logger:fuchsia.logger_c",
"//third_party/re2",
"//zircon/system/ulib/fbl",
"//zircon/system/ulib/fidl:fidl_base",
"//zircon/system/ulib/runtests-utils",
"//zircon/system/ulib/zxtest",
]
data_deps = [
":packaged-profile-helper",
":packaged-publish-data-helper",
":packaged-raw-profile",
":test-data",
":test-scripts",
]
# TODO(fxbug.dev/95833): This target uses the deprecated C bindings.
# Consider switching to the C++ bindings. See linked bug for details.
configs += [ "//build/c:fidl-deprecated-c-bindings" ]
}
executable("publish-data-helper") {
testonly = true
visibility = [ ":*" ]
sources = [ "helper/publish-data-helper.cc" ]
deps = [
"//sdk/lib/fdio",
"//zircon/system/ulib/zx",
"//zircon/system/ulib/zxtest",
]
# TODO: Don't instrument the helper until we have a way to route sinks
# from the inner runtests instance to the outer one so they make it
# into summary.json.
}
executable("profile-helper") {
testonly = true
visibility = [ ":*" ]
sources = [ "helper/profile-helper.cc" ]
deps = [
"//sdk/lib/fdio",
"//zircon/system/ulib/fbl",
"//zircon/system/ulib/zx",
"//zircon/system/ulib/zxtest",
]
}
renamed_binary("packaged-publish-data-helper") {
testonly = true
dest = "test/sys/runtests-utils-testdata/publish-data/publish-data-helper"
source = "$root_out_dir/publish-data-helper"
source_deps = [ ":publish-data-helper" ]
}
renamed_binary("packaged-profile-helper") {
testonly = true
dest = "test/sys/runtests-utils-testdata/profile/profile-helper"
source = "$root_out_dir/profile-helper"
source_deps = [ ":profile-helper" ]
}
resource("packaged-raw-profile") {
testonly = true
outputs = [
"test/sys/runtests-utils-testdata/profile/15822697145192797690.profraw",
]
sources = [ "helper/15822697145192797690.profraw" ]
}
generated_resource("test-data") {
testonly = true
contents = [ "Hello world!" ]
outputs = [ "test/sys/runtests-utils-testdata/test-data" ]
}
# Generates a build script with a sensible #! depending on what our target is.
# We used to generate these at runtime, but that design conflicts with our
# goals around verified execution, so now we pregenerate them and include them
# as part of a signed package.
template("runtests_test_script") {
forward_variables_from(invoker,
"*",
[
"contents",
"subdirectory",
])
assert(defined(invoker.contents))
if (!defined(invoker.subdirectory)) {
subdirectory = ""
} else {
subdirectory = "${invoker.subdirectory}/"
}
genfile = "$target_out_dir/test/sys/runtests-utils-testdata/${subdirectory}${target_name}"
rebased_genfile = rebase_path(genfile, root_build_dir)
action("${target_name}.txt") {
testonly = true
script = "/bin/bash"
args = [ "-c" ]
shebang = "#!/boot/bin/sh"
args += [ "printf '${shebang}\n\n${invoker.contents}\n' > $rebased_genfile && chmod a+x $rebased_genfile" ]
outputs = [ "$genfile" ]
}
resource("${target_name}") {
testonly = true
deps = [ ":${target_name}.txt" ]
outputs =
[ "test/sys/runtests-utils-testdata/${subdirectory}${target_name}" ]
sources = [ genfile ]
}
}
runtests_test_script("succeed.sh") {
contents = "exit 0"
}
runtests_test_script("expect-this-success.sh") {
contents = "echo Expect this!"
}
runtests_test_script("expect-this-failure.sh") {
contents = "echo Expect this! 1>&2\nexit 77"
}
runtests_test_script("a.sh") {
contents = ""
subdirectory = "runtestsbasicpass"
}
runtests_test_script("b.sh") {
contents = ""
subdirectory = "runtestsbasicpass"
}
runtests_test_script("test-basic-succeed.sh") {
contents = "echo Success! \$@"
subdirectory = "runtestsbasicfail"
}
runtests_test_script("test-basic-fail.sh") {
contents = "echo Failure! \$@ 1>&2\nexit 77"
subdirectory = "runtestsbasicfail"
}
runtests_test_script("test-globs-root.sh") {
contents = "echo Success! \$@"
subdirectory = "testglobs"
}
runtests_test_script("test-globs-one.sh") {
contents = "echo Success! \$@"
subdirectory = "testglobs/A/B/C"
}
runtests_test_script("test-globs-two.sh") {
contents = "echo Success! \$@"
subdirectory = "testglobs/A/D/C"
}
runtests_test_script("test-with-output-succeed.sh") {
contents = "echo Success! \$@"
subdirectory = "testwithoutput"
}
runtests_test_script("test-with-output-fail.sh") {
contents = "echo Failure! \$@ 1>&2\nexit 77"
subdirectory = "testwithoutput"
}
runtests_test_script("succeed-with-echo.sh") {
contents = "echo Success! \$@"
}
runtests_test_script("test-root-dir.sh") {
# Used by RunTestRootDir.
contents = "read line < \$TEST_ROOT_DIR/test/sys/runtests-utils-testdata/test-data\necho \\\"\$line\\\"\n"
}
runtests_test_script("test-inf-loop.sh") {
# Used by RunTestTimeout
contents = "while true; do echo \"\"; done"
}
group("test-scripts") {
testonly = true
deps = [
# Used by RunTestRootDir in fuchsia-run-test.cc
":test-root-dir.sh",
# Used by RunTestSuccess,
# DiscoverAndRunTestsFailsWithNoTestGlobsOrDefaultDirs,
# RunTestTimeout
":succeed.sh",
# Used in RunTestTimeout
":test-inf-loop.sh",
# Used by RunTestSuccessWithStdout
":expect-this-success.sh",
# Used by RunTestFailureWithStderr
":expect-this-failure.sh",
# Used by RunTestsWithVerbosity, RunTestsWithArguments, and
# DiscoverAndRunTestsFallsBackToDefaultDirs
":succeed-with-echo.sh",
# Used in an isolated directory by DiscoverAndRunTestsBasicPass
":a.sh",
":b.sh",
# Used in an isolated directory by DiscoverAndRunTestsBasicFail
":test-basic-fail.sh",
":test-basic-succeed.sh",
# Used in an isolated tree by DiscoverAndRunTestsWithGlobs
":test-globs-one.sh",
":test-globs-root.sh",
":test-globs-two.sh",
# Used in an isolated directory by DiscoverAndRunTestsWithOutput and
# DiscoverAndRunTestsWithSyslogOutput
":test-with-output-fail.sh",
":test-with-output-succeed.sh",
]
}
bootfs_test("runtests-utils-bootfs-test") {
name = "runtests-utils"
deps = [ ":runtests-utils" ]
}