| # 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.gni") |
| import("//build/test.gni") |
| import( |
| "//src/lib/testing/expectation/fuchsia_test_with_expectations_package.gni") |
| import("//src/lib/testing/expectation/generated_expectations_file.gni") |
| import("//src/lib/testing/sharding/fuchsia_sharded_test_package.gni") |
| |
| config("gvisor_test_util_config") { |
| include_dirs = [ "gvisor" ] |
| } |
| |
| static_library("gvisor_test_util") { |
| testonly = true |
| public = [ |
| "gvisor/test/util/capability_util.h", |
| "gvisor/test/util/cleanup.h", |
| "gvisor/test/util/file_descriptor.h", |
| "gvisor/test/util/fs_util.h", |
| "gvisor/test/util/logging.h", |
| "gvisor/test/util/posix_error.h", |
| "gvisor/test/util/save_util.h", |
| "gvisor/test/util/socket_util.h", |
| "gvisor/test/util/temp_path.h", |
| "gvisor/test/util/test_util.h", |
| "gvisor/test/util/thread_util.h", |
| "gvisor/test/util/timer_util.h", |
| ] |
| sources = [ |
| "gvisor/test/util/capability_util.h", |
| "gvisor/test/util/cleanup.h", |
| "gvisor/test/util/file_descriptor.h", |
| "gvisor/test/util/fs_util.cc", |
| "gvisor/test/util/fs_util.h", |
| "gvisor/test/util/fuchsia_capability_util.cc", |
| "gvisor/test/util/logging.cc", |
| "gvisor/test/util/logging.h", |
| "gvisor/test/util/posix_error.cc", |
| "gvisor/test/util/posix_error.h", |
| "gvisor/test/util/save_util.cc", |
| "gvisor/test/util/save_util.h", |
| "gvisor/test/util/save_util_other.cc", |
| "gvisor/test/util/socket_util.cc", |
| "gvisor/test/util/socket_util.h", |
| "gvisor/test/util/socket_util_impl.cc", |
| "gvisor/test/util/temp_path.cc", |
| "gvisor/test/util/temp_path.h", |
| "gvisor/test/util/test_util.cc", |
| "gvisor/test/util/test_util.h", |
| "gvisor/test/util/thread_util.h", |
| "gvisor/test/util/timer_util.cc", |
| "gvisor/test/util/timer_util.h", |
| ] |
| deps = [ |
| "//third_party/abseil-cpp/absl/base:core_headers", |
| "//third_party/abseil-cpp/absl/flags:flag", |
| "//third_party/abseil-cpp/absl/flags:parse", |
| "//third_party/abseil-cpp/absl/memory", |
| "//third_party/abseil-cpp/absl/status:statusor", |
| "//third_party/abseil-cpp/absl/strings", |
| "//third_party/abseil-cpp/absl/strings:str_format", |
| "//third_party/abseil-cpp/absl/time", |
| "//third_party/abseil-cpp/absl/types:optional", |
| "//third_party/abseil-cpp/absl/types:variant", |
| ] |
| public_deps = [ |
| "//third_party/googletest:gmock", |
| "//third_party/googletest:gtest", |
| ] |
| public_configs = [ ":gvisor_test_util_config" ] |
| } |
| |
| generic_test_label = "generic" |
| loopback_test_label = "loopback" |
| loopback_isolated_test_label = "loopback_isolated" |
| raw_packet_test_label = "raw_packet" |
| udp_test_label = "udp" |
| udp_raw_test_label = "udp_raw" |
| udp_unbound_test_label = "udp_unbound" |
| tcp_test_label = "tcp" |
| tcp_blocking_test_label = "tcp_blocking" |
| |
| source_set("${raw_packet_test_label}_socket_tests") { |
| sources = [ |
| "gvisor/test/syscalls/linux/ip_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/ip_socket_test_util.h", |
| "gvisor/test/syscalls/linux/packet_socket.cc", |
| "gvisor/test/syscalls/linux/packet_socket_dgram.cc", |
| "gvisor/test/syscalls/linux/packet_socket_raw.cc", |
| "gvisor/test/syscalls/linux/raw_socket.cc", |
| "gvisor/test/syscalls/linux/raw_socket_hdrincl.cc", |
| "gvisor/test/syscalls/linux/raw_socket_icmp.cc", |
| "gvisor/test/syscalls/linux/unix_domain_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/unix_domain_socket_test_util.h", |
| ] |
| |
| deps = [ |
| ":gvisor_test_util", |
| "//third_party/abseil-cpp/absl/base:endian", |
| "//third_party/abseil-cpp/absl/strings", |
| ] |
| |
| testonly = true |
| } |
| |
| source_set("${udp_unbound_test_label}_socket_tests") { |
| sources = [ |
| "gvisor/test/syscalls/linux/ip_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/ip_socket_test_util.h", |
| "gvisor/test/syscalls/linux/socket_ipv4_datagram_based_socket_unbound.cc", |
| "gvisor/test/syscalls/linux/socket_ipv4_datagram_based_socket_unbound.h", |
| "gvisor/test/syscalls/linux/socket_ipv4_datagram_based_socket_unbound_loopback.cc", |
| "gvisor/test/syscalls/linux/socket_ipv4_udp_unbound.cc", |
| "gvisor/test/syscalls/linux/socket_ipv4_udp_unbound.h", |
| "gvisor/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.cc", |
| "gvisor/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking_test.cc", |
| "gvisor/test/syscalls/linux/socket_ipv4_udp_unbound_loopback.cc", |
| "gvisor/test/syscalls/linux/socket_ipv4_udp_unbound_loopback_nogotsan.cc", |
| "gvisor/test/syscalls/linux/socket_ipv6_udp_unbound.cc", |
| "gvisor/test/syscalls/linux/socket_ipv6_udp_unbound.h", |
| "gvisor/test/syscalls/linux/socket_ipv6_udp_unbound_external_networking.cc", |
| "gvisor/test/syscalls/linux/socket_ipv6_udp_unbound_external_networking_test.cc", |
| "gvisor/test/syscalls/linux/socket_ipv6_udp_unbound_loopback.cc", |
| ] |
| |
| deps = [ |
| ":gvisor_test_util", |
| "//third_party/abseil-cpp/absl/memory", |
| "//third_party/abseil-cpp/absl/strings", |
| "//third_party/abseil-cpp/absl/strings:str_format", |
| ] |
| |
| testonly = true |
| } |
| |
| source_set("${udp_test_label}_socket_tests") { |
| sources = [ |
| "gvisor/test/syscalls/linux/ip_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/ip_socket_test_util.h", |
| "gvisor/test/syscalls/linux/socket_generic.h", |
| "gvisor/test/syscalls/linux/socket_generic.h", |
| "gvisor/test/syscalls/linux/socket_generic_test_cases.cc", |
| "gvisor/test/syscalls/linux/socket_ip_udp_generic.cc", |
| "gvisor/test/syscalls/linux/socket_ip_udp_generic.h", |
| "gvisor/test/syscalls/linux/socket_ip_udp_loopback.cc", |
| "gvisor/test/syscalls/linux/socket_ip_udp_loopback_blocking.cc", |
| "gvisor/test/syscalls/linux/socket_ip_udp_loopback_nonblock.cc", |
| "gvisor/test/syscalls/linux/socket_non_blocking.cc", |
| "gvisor/test/syscalls/linux/socket_non_blocking.h", |
| "gvisor/test/syscalls/linux/socket_non_stream.cc", |
| "gvisor/test/syscalls/linux/socket_non_stream.h", |
| "gvisor/test/syscalls/linux/socket_non_stream_blocking.cc", |
| "gvisor/test/syscalls/linux/socket_non_stream_blocking.h", |
| "gvisor/test/syscalls/linux/udp_bind.cc", |
| "gvisor/test/syscalls/linux/udp_socket.cc", |
| "gvisor/test/syscalls/linux/unix_domain_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/unix_domain_socket_test_util.h", |
| ] |
| |
| deps = [ |
| ":gvisor_test_util", |
| "//third_party/abseil-cpp/absl/memory", |
| "//third_party/abseil-cpp/absl/strings", |
| "//third_party/abseil-cpp/absl/strings:str_format", |
| ] |
| |
| testonly = true |
| } |
| |
| source_set("${udp_raw_test_label}_socket_tests") { |
| sources = [ "gvisor/test/syscalls/linux/udp_raw_socket.cc" ] |
| |
| deps = [ |
| ":gvisor_test_util", |
| "//third_party/abseil-cpp/absl/base", |
| ] |
| |
| testonly = true |
| } |
| |
| source_set("${tcp_test_label}_socket_tests") { |
| sources = [ |
| "gvisor/test/syscalls/linux/ip_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/ip_socket_test_util.h", |
| "gvisor/test/syscalls/linux/socket_generic.h", |
| "gvisor/test/syscalls/linux/socket_generic_test_cases.cc", |
| "gvisor/test/syscalls/linux/socket_ip_tcp_generic.cc", |
| "gvisor/test/syscalls/linux/socket_ip_tcp_generic.h", |
| "gvisor/test/syscalls/linux/socket_ip_tcp_generic_loopback.cc", |
| "gvisor/test/syscalls/linux/socket_ip_tcp_loopback.cc", |
| "gvisor/test/syscalls/linux/socket_ip_tcp_loopback_nonblock.cc", |
| "gvisor/test/syscalls/linux/socket_non_blocking.cc", |
| "gvisor/test/syscalls/linux/socket_non_blocking.h", |
| "gvisor/test/syscalls/linux/tcp_socket.cc", |
| "gvisor/test/syscalls/linux/unix_domain_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/unix_domain_socket_test_util.h", |
| ] |
| deps = [ |
| ":gvisor_test_util", |
| "//third_party/abseil-cpp/absl/strings:str_format", |
| "//third_party/abseil-cpp/absl/time", |
| ] |
| |
| testonly = true |
| } |
| |
| source_set("${tcp_blocking_test_label}_socket_tests") { |
| sources = [ |
| "gvisor/test/syscalls/linux/ip_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/ip_socket_test_util.h", |
| "gvisor/test/syscalls/linux/socket_ip_tcp_loopback_blocking.cc", |
| "gvisor/test/syscalls/linux/socket_stream_blocking.cc", |
| "gvisor/test/syscalls/linux/socket_stream_blocking.h", |
| ] |
| deps = [ |
| ":gvisor_test_util", |
| "//third_party/abseil-cpp/absl/strings:str_format", |
| ] |
| |
| testonly = true |
| } |
| |
| source_set("${generic_test_label}_socket_tests") { |
| sources = [ |
| "gvisor/test/syscalls/linux/ip_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/ip_socket_test_util.h", |
| "gvisor/test/syscalls/linux/socket.cc", |
| "gvisor/test/syscalls/linux/socket_blocking.cc", |
| "gvisor/test/syscalls/linux/socket_blocking.h", |
| "gvisor/test/syscalls/linux/socket_ip_loopback_blocking.cc", |
| "gvisor/test/syscalls/linux/socket_ip_tcp_udp_generic.cc", |
| "gvisor/test/syscalls/linux/socket_ip_unbound.cc", |
| "gvisor/test/syscalls/linux/unix_domain_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/unix_domain_socket_test_util.h", |
| ] |
| deps = [ |
| ":gvisor_test_util", |
| "//third_party/abseil-cpp/absl/memory", |
| "//third_party/abseil-cpp/absl/strings", |
| "//third_party/abseil-cpp/absl/strings:str_format", |
| "//third_party/abseil-cpp/absl/time", |
| ] |
| |
| testonly = true |
| } |
| |
| source_set("${loopback_test_label}_socket_tests") { |
| sources = [ |
| "gvisor/test/syscalls/linux/ip_socket_test_util.cc", |
| "gvisor/test/syscalls/linux/ip_socket_test_util.h", |
| "gvisor/test/syscalls/linux/socket_inet_loopback.cc", |
| ] |
| deps = [ |
| ":gvisor_test_util", |
| "//third_party/abseil-cpp/absl/memory", |
| "//third_party/abseil-cpp/absl/strings:str_format", |
| ] |
| |
| testonly = true |
| } |
| |
| source_set("${loopback_isolated_test_label}_socket_tests") { |
| sources = [ "gvisor/test/syscalls/linux/socket_inet_loopback_isolated.cc" ] |
| deps = [ |
| ":gvisor_test_util", |
| "//third_party/abseil-cpp/absl/strings:str_format", |
| "//third_party/abseil-cpp/absl/time", |
| ] |
| |
| testonly = true |
| } |
| |
| # Defines test targets and unittest packages based on the |
| # provided suite name for all versions of the Netstack under |
| # test. |
| # |
| # Parameters |
| # |
| # run_with_fast_udp (optional) |
| # Identifies whether or not the suite should be run against Netstack2 |
| # with Fast UDP enabled. |
| # Type: bool |
| # Default: true |
| # |
| # debug_netstack2 (optional) |
| # When true, use the debug NS2 component, and otherwise the regular one. |
| # Debug NS2 enables packet tracing and debug logs, which may overload some |
| # systems (https://fxbug.dev/328822330). |
| # Type: bool |
| # Default: true |
| # |
| # test_srcs_target (optional) |
| # The local target containing the test source files used to run the suite. |
| # Type: string |
| # Default: When unset, the test source target constructed as |
| # ":${target_name}_socket_tests" |
| # |
| # with_distinct_fast_udp_expectations (optional) |
| # If this is true, then we'll look for expectation files with _syncudp and |
| # _fastudp suffixes. |
| # |
| # num_shards (optional) |
| # If set, this will override the number of shards the suite is sharded into. |
| template("syscall_test_suite") { |
| not_needed([ "invoker" ]) |
| suite_label = target_name |
| |
| _num_shards = 5 |
| if (defined(invoker.num_shards)) { |
| _num_shards = invoker.num_shards |
| } |
| |
| ns3_label = "netstack3" |
| |
| debug_netstack2 = true |
| if (defined(invoker.debug_netstack2)) { |
| debug_netstack2 = invoker.debug_netstack2 |
| } |
| |
| stacks = [ |
| { |
| label = ns3_label |
| component = "//src/connectivity/network/netstack3:component-debug" |
| manifest = "meta/netstack3/${suite_label}_syscall_tests.cml" |
| }, |
| ] |
| ns2_syncudp_stack = { |
| label = "netstack2_syncudp" |
| component = |
| "//src/connectivity/network/netstack:component-with-sync-udp-debug" |
| manifest = "meta/netstack2/syncudp/${suite_label}_syscall_tests.cml" |
| } |
| if (debug_netstack2) { |
| ns2_syncudp_stack.component = |
| "//src/connectivity/network/netstack:component-with-sync-udp-debug" |
| } else { |
| ns2_syncudp_stack.component = |
| "//src/connectivity/network/netstack:component-with-sync-udp" |
| } |
| |
| stacks += [ ns2_syncudp_stack ] |
| |
| run_with_fast_udp = true |
| if (defined(invoker.run_with_fast_udp)) { |
| run_with_fast_udp = invoker.run_with_fast_udp |
| } |
| |
| ns2_fastudp_label = "netstack2_fastudp" |
| |
| if (run_with_fast_udp) { |
| ns2_fastudp_stack = { |
| label = ns2_fastudp_label |
| manifest = "meta/netstack2/fastudp/${suite_label}_syscall_tests.cml" |
| } |
| if (debug_netstack2) { |
| ns2_fastudp_stack.component = |
| "//src/connectivity/network/netstack:component-with-fast-udp-debug" |
| } else { |
| ns2_fastudp_stack.component = |
| "//src/connectivity/network/netstack:component-with-fast-udp" |
| } |
| stacks += [ ns2_fastudp_stack ] |
| } else { |
| not_needed([ "ns2_fastudp_label" ]) |
| } |
| |
| ns2_test_deps = [] |
| ns3_test_deps = [] |
| foreach(stack, stacks) { |
| combined_label = "${stack.label}_${suite_label}" |
| |
| test_target_label = "${combined_label}_socket_tests" |
| test_srcs_target = ":${suite_label}_socket_tests" |
| if (defined(invoker.test_srcs_target)) { |
| test_srcs_target = invoker.test_srcs_target |
| } |
| test(test_target_label) { |
| deps = [ |
| "${test_srcs_target}", |
| "//src/lib/fxl/test:gtest_main", |
| ] |
| } |
| |
| test_package_label = "${combined_label}_syscall" |
| component_label = "${test_package_label}_tests" |
| |
| with_distinct_fast_udp_expectations = false |
| if (defined(invoker.with_distinct_fast_udp_expectations)) { |
| with_distinct_fast_udp_expectations = |
| invoker.with_distinct_fast_udp_expectations |
| } |
| |
| expectations_target_name = "${component_label}_expectations" |
| generated_expectations_file(expectations_target_name) { |
| includes = [] |
| if (stack.label == ns3_label) { |
| includes = [ "expects/netstack3/${suite_label}.json5" ] |
| } else { |
| _netstack2_expects_dir = "expects/netstack2" |
| if (with_distinct_fast_udp_expectations) { |
| if (stack.label == ns2_fastudp_label) { |
| includes = |
| [ "$_netstack2_expects_dir/${suite_label}_fastudp.json5" ] |
| } else { |
| includes = |
| [ "$_netstack2_expects_dir/${suite_label}_syncudp.json5" ] |
| } |
| } else { |
| includes = [ "$_netstack2_expects_dir/${suite_label}.json5" ] |
| } |
| } |
| } |
| |
| fuchsia_sharded_test_package(test_package_label) { |
| forward_variables_from(invoker, [ "test_specs" ]) |
| test_components = [ |
| { |
| name = component_label |
| deps = [ |
| ":${test_target_label}", |
| stack.component, |
| ] |
| manifest = stack.manifest |
| generated_expectations = ":${expectations_target_name}" |
| num_shards = _num_shards |
| |
| # Matches the first two slash delimited parts of the test name, or |
| # just the whole name if there are no slashes. For example, from |
| # "All/SocketInetLoopbackTest.TCPListenCloseDuringConnect/ListenV4MappedAny_ConnectV4Any" |
| # matches "All/SocketInetLoopbackTest.TCPListenCloseDuringConnect" |
| # and matches all of "SocketTest.UnixSocketPairProtocol". |
| shard_part_regex = "([^/]+(?:/[^/]+)?).*" |
| }, |
| ] |
| } |
| |
| if (stack.label == ns3_label) { |
| ns3_test_deps += [ ":${test_package_label}" ] |
| } else { |
| ns2_test_deps += [ ":${test_package_label}" ] |
| } |
| } |
| |
| group("${suite_label}_ns3") { |
| testonly = true |
| public_deps = ns3_test_deps |
| } |
| group("${suite_label}_ns2") { |
| testonly = true |
| public_deps = ns2_test_deps |
| } |
| } |
| |
| syscall_test_suite(generic_test_label) { |
| } |
| syscall_test_suite(loopback_test_label) { |
| # The loopback suite was previously manually sharded into multiple different |
| # suites because it is longer-running and has more cases than many of the |
| # other suites. To compensate for this, use additional shards. |
| # The loopback test suite takes longer on riscv builders, break the suite |
| # into more shards. This is done for all builders to avoid confusion. |
| num_shards = 15 |
| |
| # These tests are generating too much logging. https://fxbug.dev/328822330 |
| debug_netstack2 = false |
| } |
| syscall_test_suite(loopback_isolated_test_label) { |
| # The loopback_isolated suite was previously manually sharded into multiple |
| # different suites because it is longer-running and has more cases than many |
| # of the other suites. To compensate for this, use additional shards. |
| num_shards = 10 |
| } |
| syscall_test_suite(raw_packet_test_label) { |
| } |
| syscall_test_suite(udp_test_label) { |
| with_distinct_fast_udp_expectations = true |
| } |
| syscall_test_suite(udp_raw_test_label) { |
| } |
| syscall_test_suite(udp_unbound_test_label) { |
| } |
| syscall_test_suite(tcp_blocking_test_label) { |
| run_with_fast_udp = false |
| } |
| syscall_test_suite(tcp_test_label) { |
| run_with_fast_udp = false |
| |
| # The TCP suite is particularly large and needs to be sharded further |
| # in order to complete within a reasonable period of time on RISC-V. |
| num_shards = 10 |
| } |
| |
| suite_labels = [ |
| generic_test_label, |
| loopback_isolated_test_label, |
| loopback_test_label, |
| raw_packet_test_label, |
| tcp_blocking_test_label, |
| tcp_test_label, |
| udp_raw_test_label, |
| udp_test_label, |
| udp_unbound_test_label, |
| ] |
| |
| ns3_labels = [] |
| foreach(label, suite_labels) { |
| ns3_labels += [ ":${label}_ns3" ] |
| } |
| |
| all_packages = ns3_labels |
| |
| ns2_labels = [] |
| foreach(label, suite_labels) { |
| ns2_labels += [ ":${label}_ns2" ] |
| } |
| |
| # RISC-V on Fuchsia does not support Golang. |
| if (target_cpu != "riscv64") { |
| all_packages += ns2_labels |
| } |
| |
| group("tests") { |
| testonly = true |
| public_deps = all_packages |
| } |