| # Copyright 2022 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/cpp/cpp_fuzzer.gni") |
| import("//build/fuzzing/fuzzer_package.gni") |
| import("//build/test.gni") |
| import("//build/testing/host_test_data.gni") |
| import("//build/testing/zbi_test.gni") |
| |
| is_elf = current_os != "mac" && current_os != "win" |
| |
| test("elfldltl-unittests") { |
| sources = [ |
| "abi-tests.cc", |
| "container-tests.cc", |
| "diagnostics-tests.cc", |
| "dynamic-tests.cc", |
| "field-tests.cc", |
| "file-tests.cc", |
| "initfini-tests.cc", |
| "internal-tests.cc", |
| "layout-tests.cc", |
| "load-tests.cc", |
| "mapped-fd-file-tests.cc", |
| "memory-tests.cc", |
| "note-tests.cc", |
| "phdr-tests.cc", |
| "relocation-tests.cc", |
| "soname-tests.cc", |
| "symbol-tests.cc", |
| "symbol-tests.h", |
| ] |
| |
| if (is_elf) { |
| sources += [ "self-tests.cc" ] |
| } |
| if (is_fuchsia) { |
| sources += [ "mapped-vmo-file-tests.cc" ] |
| } |
| |
| deps = [ |
| ":test-utils", |
| "..", |
| "//sdk/lib/stdcompat", |
| "//src/lib/fxl/test:gtest_main", |
| "//src/lib/symbolizer-markup", |
| ] |
| |
| if (is_elf) { |
| deps += [ ":loader-tests" ] |
| } |
| } |
| |
| source_set("test-utils") { |
| visibility = [ ":*" ] |
| testonly = true |
| |
| public = [ "tests.h" ] |
| public_deps = [ |
| "..", |
| "//third_party/googletest:gtest", |
| "//zircon/system/ulib/fbl", |
| ] |
| |
| sources = [ "get-test-data-path.cc" ] |
| deps = [] |
| if (is_fuchsia) { |
| sources += [ "get-test-lib.cc" ] |
| deps += [ |
| "//sdk/fidl/fuchsia.ldsvc:fuchsia.ldsvc_cpp", |
| "//sdk/lib/fdio", |
| "//zircon/system/ulib/zx", |
| ] |
| } |
| } |
| |
| if (current_os == "linux") { |
| config("linux-static-pie.config") { |
| # Avoid libc references from assert() in libc++ header code. |
| defines = [ "NDEBUG=1" ] |
| include_dirs = [ "//third_party/linux-syscall-support/src" ] |
| } |
| |
| static_library("linux-static-pie") { |
| sources = [ "linux-static-pie.cc" ] |
| configs -= [ "//build/config/linux:implicit-host-libs" ] |
| configs += [ ":linux-static-pie.config" ] |
| deps = [ ".." ] |
| } |
| |
| if (current_toolchain == host_toolchain) { |
| host_test("linux-static-pie-test") { |
| deps = [ ":linux-static-pie-test(//build/toolchain:linux_$host_cpu)" ] |
| binary_path = get_label_info(deps[0], "root_out_dir") + "/" + |
| get_label_info(deps[0], "name") |
| } |
| } else { |
| test("linux-static-pie-test") { |
| disable_syslog_backend = true |
| sources = [ "linux-static-pie-test.cc" ] |
| configs -= [ |
| "//build/config/linux:default-pie", |
| "//build/config/linux:implicit-host-libs", |
| ] |
| configs += [ ":linux-static-pie.config" ] |
| cflags = [ "-fPIE" ] |
| ldflags = [ |
| "-nostartfiles", |
| "-nostdlib++", |
| "-static-pie", |
| "-nolibc", |
| ] |
| deps = [ ":linux-static-pie" ] |
| |
| exclude_toolchain_tags = [ "instrumented" ] |
| } |
| } |
| } |
| |
| if (is_fuchsia) { |
| static_library("static-pie") { |
| sources = [ "fuchsia-static-pie.cc" ] |
| configs += [ "//build/config/fuchsia:static-pie-config" ] |
| deps = [ ".." ] |
| |
| # Avoid libc references from assert() in libc++ header code. |
| defines = [ "NDEBUG=1" ] |
| } |
| |
| test("fuchsia-static-pie-test") { |
| sources = [ "fuchsia-static-pie-test.cc" ] |
| |
| # Avoid libc references from assert() in libc++ header code. |
| defines = [ "NDEBUG=1" ] |
| |
| configs += [ "//build/config/fuchsia:static-pie-config" ] |
| if (zircon_toolchain == false) { |
| configs -= [ "//build/config/fuchsia:fdio_config" ] |
| } |
| disable_syslog_backend = true |
| |
| ldflags = [ |
| # The build system makes it impossible to avoid the libc dep. But this |
| # can avoid it creating a spurious DT_NEEDED, though that's harmless |
| # enough since nothing looks at those without a dynamic linker. |
| "-Wl,--as-needed", |
| |
| # A standalone binary should indicate its stack requirements. |
| # They should be minimal for this test. |
| "-Wl,-z,stack-size=0x1000", |
| ] |
| |
| deps = [ |
| ":static-pie", |
| "//src/zircon/lib/zircon", |
| "//zircon/third_party/ulib/musl/src/exit:abort", |
| "//zircon/third_party/ulib/musl/src/string:stdmem", |
| ] |
| |
| exclude_toolchain_tags = [ "instrumented" ] |
| } |
| |
| fuchsia_unittest_package("elfldltl-static-pie-test") { |
| deps = [ |
| ":fuchsia-static-pie-test", |
| "//src/sys/testing/elftest", |
| ] |
| } |
| } |
| |
| source_set("test-data") { |
| visibility = [ ":*" ] |
| testonly = true |
| |
| public = [ "test-data.h" ] |
| } |
| |
| template("load_test_lib") { |
| loadable_module(target_name) { |
| visibility = [ ":*" ] |
| testonly = true |
| |
| forward_variables_from(invoker, |
| [ |
| "cflags", |
| "defines", |
| "sources", |
| "ldflags", |
| ]) |
| |
| deps = [ |
| ":test-data", |
| "//zircon/system/public", |
| ] |
| |
| # These tests are trying to test something specific, specific segment |
| # types, etc, instrumentation will likely perturbe this, so disable |
| # it entirely. |
| exclude_toolchain_tags = [ "instrumented" ] |
| |
| if (is_linux) { |
| configs -= [ |
| "//build/config/linux:default-pie", |
| "//build/config/linux:implicit-host-libs", |
| ] |
| configs += [ "//build/config/zircon:nolibc" ] |
| } |
| if (is_fuchsia) { |
| # These shared objects aren't necessarily static pie's, this config |
| # disables sanitizers and other default libraries from being linked in. |
| configs += [ "//build/config/fuchsia:static-pie-config" ] |
| } |
| } |
| } |
| |
| load_test_lib("elfldltl-test-ret24") { |
| sources = [ "ret24.cc" ] |
| ldflags = [ "-Wl,-e,Return24" ] |
| } |
| |
| foreach(data_size, |
| [ |
| 0, |
| 65536, |
| ]) { |
| load_test_lib("elfldltest-no-execute-data-$data_size") { |
| sources = [ "no-x-segment.cc" ] |
| defines = [ "DATA_SIZE=$data_size" ] |
| ldflags = [ "-Wl,-e,test_data" ] |
| } |
| } |
| |
| load_test_lib("elfldltl-test-symbolic") { |
| sources = [ "symbolic.cc" ] |
| |
| # TODO(fxbug.dev/117866): clang will still perform interprocedural |
| # optimization in a PIC, this flag disallows that and requires the PLT call |
| # always be made so we can properly test applying plt relocations. |
| if (!is_gcc) { |
| cflags = [ "-fsemantic-interposition" ] |
| } |
| } |
| |
| load_test_data_deps = [ |
| "elfldltl-test-ret24", |
| "elfldltl-test-symbolic", |
| ] |
| |
| foreach(data_size, |
| [ |
| 0, |
| 65536, |
| ]) { |
| load_test_data_deps += [ "elfldltest-no-execute-data-$data_size" ] |
| } |
| |
| if (is_host && is_elf) { |
| host_test_data("loader-test-libs") { |
| deps = [] |
| sources = [] |
| |
| foreach(lib, load_test_data_deps) { |
| deps += [ ":$lib" ] |
| sources += [ "$root_out_dir/$lib.so" ] |
| } |
| |
| outputs = [ "$root_out_dir/test_data/elfldltl/{{source_file_part}}" ] |
| } |
| } else { |
| # On Fuchsia these are just included in /pkg/lib implicitly by dint |
| # of being in data_deps of the test code. |
| group("loader-test-libs") { |
| testonly = true |
| |
| deps = [] |
| foreach(lib, load_test_data_deps) { |
| deps += [ ":$lib" ] |
| } |
| } |
| } |
| |
| source_set("loader-tests") { |
| visibility = [ ":*" ] |
| testonly = true |
| |
| sources = [ "loader-tests.cc" ] |
| |
| deps = [ |
| ":test-data", |
| ":test-utils", |
| "..", |
| "//sdk/lib/stdcompat", |
| "//zircon/system/ulib/fbl", |
| ] |
| |
| data_deps = [ ":loader-test-libs" ] |
| } |
| |
| # Make that into a bootable ZBI with just the kernel. |
| zbi_test("zbi-static-pie-test") { |
| args = [ |
| "userboot.test.next=test/fuchsia-static-pie-test", |
| "kernel.enable-serial-syscalls=true", |
| ] |
| |
| deps = [ |
| ":fuchsia-static-pie-test", |
| "//zircon/kernel", |
| ] |
| assert_no_deps = [ |
| "//zircon/system/core/*", |
| "//zircon/system/dev/*", |
| ] |
| } |
| |
| fuchsia_unittest_package("elfldltl-tests") { |
| deps = [ ":elfldltl-unittests" ] |
| manifest = "meta/elfldltl-tests.cml" |
| } |
| |
| cpp_fuzzer("dynamic-fuzzer") { |
| sources = [ "dynamic-fuzzer.cc" ] |
| deps = [ ".." ] |
| } |
| |
| cpp_fuzzer("note-fuzzer") { |
| sources = [ "note-fuzzer.cc" ] |
| deps = [ ".." ] |
| } |
| |
| cpp_fuzzer("relocation-fuzzer") { |
| sources = [ "relocation-fuzzer.cc" ] |
| deps = [ ".." ] |
| } |
| |
| cpp_fuzzer("symbol-fuzzer") { |
| sources = [ "symbol-fuzzer.cc" ] |
| deps = [ ".." ] |
| } |
| |
| fuzzer_package("elfldltl-fuzzers") { |
| fuzz_host = true |
| cpp_fuzzers = [ |
| ":dynamic-fuzzer", |
| ":note-fuzzer", |
| ":relocation-fuzzer", |
| ":symbol-fuzzer", |
| ] |
| } |
| |
| group("tests") { |
| testonly = true |
| |
| deps = [ |
| ":elfldltl-fuzzers", |
| ":elfldltl-static-pie-test", |
| ":elfldltl-tests", |
| ":elfldltl-unittests($host_toolchain)", |
| ] |
| |
| if (host_os == "linux") { |
| deps += [ ":linux-static-pie-test($host_toolchain)" ] |
| } |
| } |
| |
| group("boot_tests") { |
| testonly = true |
| deps = [ ":zbi-static-pie-test" ] |
| } |