| # 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/components/fuchsia_unittest_package.gni") |
| import("//build/dist/distribution_manifest.gni") |
| import("//build/test.gni") |
| import("//build/toolchain/zircon/user_basic_redirect.gni") |
| |
| is_elf = current_os != "mac" && current_os != "win" |
| |
| group("tests") { |
| testonly = true |
| |
| deps = [ |
| ":ld-tests", |
| ":ld-unittests($host_toolchain)", |
| ] |
| } |
| |
| test("ld-unittests") { |
| sources = [ |
| "abi-tests.cc", |
| "filter-view-tests.cc", |
| ] |
| deps = [ |
| "..:headers", |
| "../testing", |
| "//src/lib/fxl/test:gtest_main", |
| "//third_party/googletest:gmock", |
| ] |
| |
| if (is_elf) { |
| deps += [ ":load-tests" ] |
| } |
| if (is_fuchsia) { |
| sources += [ "mock-loader-service-tests.cc" ] |
| } |
| } |
| |
| fuchsia_unittest_package("ld-tests") { |
| deps = [ ":ld-unittests" ] |
| manifest = "meta/ld-tests.cml" |
| |
| # By default the packaging step will do checks that try to detect bugs in the |
| # build system by verifying that ELF files in a package match a bunch of |
| # hard-coded assumptions about the old dynamic linker and libc implementation |
| # that don't hold true for the test binaries here. |
| disable_elf_binaries_checks = true |
| } |
| |
| # This collects the -DLD_STARTUP_TEST_LIB=... flag in the response file. |
| generated_file("ld-startup-test-switches.rsp") { |
| visibility = [ ":*" ] |
| testonly = true |
| output_conversion = "list lines" |
| data_keys = [ "ld_startup_test_switches" ] |
| outputs = [ "$target_gen_dir/$target_name" ] |
| data_deps = [ ":load-test-data" ] |
| metadata = { |
| # Don't let manifests roll up ld.so.1 from here just because test code |
| # depends on this target. |
| distribution_entries_barrier = [] |
| } |
| } |
| |
| source_set("load-tests") { |
| visibility = [ ":*" ] |
| testonly = true |
| |
| sources = [ |
| "ld-load-tests-base.cc", |
| "ld-load-tests-base.h", |
| "load-tests.cc", |
| ] |
| deps = [ |
| "..:abi-headers", |
| "..:headers", |
| "..:posix-header", |
| "//src/lib/elfldltl", |
| "//src/lib/elfldltl/testing", |
| "//third_party/googletest:gtest", |
| "//zircon/system/ulib/fbl", |
| ] |
| if (is_fuchsia) { |
| sources += [ |
| "ld-load-zircon-ldsvc-tests-base.cc", |
| "ld-load-zircon-ldsvc-tests-base.h", |
| "ld-load-zircon-process-tests-base.cc", |
| "ld-load-zircon-process-tests-base.h", |
| "ld-remote-process-tests.cc", |
| "ld-remote-process-tests.h", |
| "ld-startup-create-process-tests.cc", |
| "ld-startup-create-process-tests.h", |
| "ld-startup-in-process-tests-zircon.cc", |
| "ld-startup-in-process-tests-zircon.h", |
| "ld-startup-spawn-process-tests-zircon.cc", |
| "ld-startup-spawn-process-tests-zircon.h", |
| ] |
| deps += [ |
| "../testing", |
| "//sdk/lib/fdio", |
| "//zircon/system/ulib/zx", |
| ] |
| } else { |
| sources += [ |
| "ld-startup-in-process-tests-posix.cc", |
| "ld-startup-in-process-tests-posix.h", |
| "ld-startup-spawn-process-tests-posix.cc", |
| "ld-startup-spawn-process-tests-posix.h", |
| ] |
| deps += [ ":test-chdir-guard" ] |
| } |
| |
| # Plumb in the switch via the response file to give the libprefix. |
| deps += [ ":ld-startup-test-switches.rsp" ] |
| inputs = get_target_outputs(":ld-startup-test-switches.rsp") |
| cflags = [ "@" + rebase_path(inputs[0], root_build_dir) ] |
| |
| data_deps = [ ":load-test-data" ] |
| } |
| |
| source_set("test-chdir-guard") { |
| testonly = true |
| public = [ "test-chdir-guard.h" ] |
| sources = [ "test-chdir-guard.cc" ] |
| deps = [ |
| "//src/lib/elfldltl/testing", |
| "//third_party/googletest:gtest", |
| ] |
| } |
| |
| if (!is_fuchsia) { |
| # For host tests, the test binaries must be packaged in host_test_data() at |
| # the expected path where elfldltl::testing::GetTestLib will find them. |
| test_tc = "" |
| if (is_linux) { |
| # The linux_$cpu (vs host_$cpu) handles shared libraries. |
| test_tc = "(//build/toolchain:linux_$current_cpu)" |
| } |
| |
| group("load-test-data") { |
| testonly = true |
| deps = [ "modules$test_tc" ] |
| } |
| |
| # This is reached via data_deps from the test_executable() targets in |
| # modules/ where they will be instantiated in the same toolchain via variant |
| # selection as the test, so that ld.so.1 gets the right libprefix. |
| if (current_toolchain != shlib_toolchain) { |
| # host_test_data() adds a dep on $target_name(${toolchain_variant.base}), |
| # which drops the shlib qualifier, so there is an extra dependency on this |
| # target that shouldn't really exist. It's crucial that the real target in |
| # $shlib_toolchain be the one reached via data_deps in modules. |
| group("ld-startup.test-data") { |
| visibility = [ "./*" ] |
| testonly = true |
| } |
| } else { |
| host_out_dir = get_label_info(".($host_toolchain)", "root_out_dir") |
| host_test_data("ld-startup.test-data") { |
| visibility = [ "./*" ] |
| deps = [ "..:ld-startup" ] |
| sources = [ "$root_out_dir/libld-startup.so" ] |
| outputs = [ "$host_out_dir/test_data/elfldltl/${toolchain_variant.libprefix}ld.so.1" ] |
| } |
| } |
| } else { |
| # On Fuchsia these are just included in /pkg/... implicitly by dint of being |
| # in data_deps of the test code. But we want to repackage those deps to put |
| # them into /pkg/lib/test/... instead so they can be fetched as executable |
| # via fuchsia.ldsvc. |
| |
| distribution_manifest("load-test-data") { |
| visibility = [ ":*" ] |
| testonly = true |
| |
| # This will collect the files from deps that would go into /pkg/... and |
| # rewrite their manifest entries to use /pkg/lib/test/... instead. |
| prefix = "lib/test" |
| |
| deps = [ ":modules.basic" ] |
| |
| # Make this manifest itself an input for collections via deps on this. |
| outputs = [ "$target_gen_dir/$target_name.json" ] |
| metadata = { |
| distribution_entries_files = [ |
| { |
| file = rebase_path(outputs[0], root_build_dir) |
| label = get_label_info(":$target_name", "label_with_toolchain") |
| }, |
| ] |
| } |
| } |
| |
| user_basic_redirect("modules.basic") { |
| visibility = [ ":*" ] |
| testonly = true |
| public_deps = [ "modules" ] |
| } |
| |
| # The dependency on this should already be in the user.basic environment |
| # because it comes from modules:test-executable, which is reached via the |
| # modules.basic redirect above. |
| group("ld-startup.test-data") { |
| testonly = true |
| public_deps = [ "..:ld-startup" ] |
| |
| # This gets the verification done on each variant that's being used by one |
| # or more tests. |
| data_deps = [ "..:ld-startup.verify-abi" ] |
| } |
| } |