blob: f82ae23d437695f62bb35596af7e4540a1796a20 [file]
# Copyright 2023 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
import("//build_overrides/pigweed.gni")
import("$dir_pw_async2/backend.gni")
import("$dir_pw_build/facade.gni")
import("$dir_pw_build/module_config.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_chrono/backend.gni")
import("$dir_pw_sync/backend.gni")
import("$dir_pw_thread/backend.gni")
import("$dir_pw_toolchain/traits.gni")
import("$dir_pw_unit_test/test.gni")
declare_args() {
# The build target that overrides the default configuration options for this
# module. This should point to a source set that provides defines through a
# public config (which may -include a file or add defines directly).
pw_async2_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
}
config("public_include_path") {
include_dirs = [ "public" ]
visibility = [ ":*" ]
}
pw_test("poll_test") {
deps = [
":pw_async2",
"$dir_pw_result",
]
sources = [ "poll_test.cc" ]
enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != ""
}
pw_test("await_test") {
deps = [
":pw_async2",
":testing",
":value_future",
"$dir_pw_result",
]
sources = [ "await_test.cc" ]
enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != ""
}
pw_source_set("pw_async2") {
public_configs = [ ":public_include_path" ]
public = [
"public/pw_async2/await.h",
"public/pw_async2/context.h",
"public/pw_async2/dispatcher.h",
"public/pw_async2/func_task.h",
"public/pw_async2/future.h",
"public/pw_async2/future_task.h",
"public/pw_async2/internal/poll_internal.h",
"public/pw_async2/poll.h",
"public/pw_async2/runnable_dispatcher.h",
"public/pw_async2/task.h",
"public/pw_async2/try.h",
"public/pw_async2/waker.h",
]
public_deps = [
":internal",
"$dir_pw_allocator",
"$dir_pw_assert",
"$dir_pw_containers:intrusive_forward_list",
"$dir_pw_containers:intrusive_list",
"$dir_pw_containers:intrusive_queue",
"$dir_pw_containers:optional",
"$dir_pw_log:args",
"$dir_pw_string:to_string",
"$dir_pw_sync:lock_annotations",
"$pw_external_fuchsia:stdcompat",
dir_pw_function,
dir_pw_log,
dir_pw_memory,
dir_pw_polyfill,
dir_pw_preprocessor,
dir_pw_tokenizer,
]
deps = [
":yield",
"$dir_pw_assert:check",
"$dir_pw_thread:sleep",
]
sources = [
"dispatcher.cc",
"future.cc",
"runnable_dispatcher.cc",
"task.cc",
"waker.cc",
]
}
config("private_include_path") {
include_dirs = [ "private" ]
visibility = [ ":*" ]
}
pw_source_set("yield") {
public = [ "private/pw_async2_private/yield.h" ]
public_configs = [ ":private_include_path" ]
public_deps = [
":internal",
"$dir_pw_chrono:system_clock",
"$dir_pw_thread:sleep",
]
visibility = [ ":*" ]
}
group("dispatcher") {
public_deps = [ ":pw_async2" ]
}
pw_source_set("internal") {
public_configs = [ ":public_include_path" ]
public = [
"public/pw_async2/internal/config.h",
"public/pw_async2/internal/lock.h",
"public/pw_async2/internal/logging.h",
]
public_deps = [
"$dir_pw_memory:no_destructor",
"$dir_pw_sync:interrupt_spin_lock",
dir_pw_polyfill,
pw_async2_CONFIG,
]
visibility = [ ":*" ]
}
pw_source_set("basic_dispatcher") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/basic_dispatcher.h" ]
public_deps = [
":pw_async2",
"$dir_pw_sync:thread_notification",
]
}
pw_source_set("notified_dispatcher") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/notified_dispatcher.h" ]
public_deps = [
":pw_async2",
"$dir_pw_sync:thread_notification",
]
}
pw_source_set("testing") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/dispatcher_for_test.h" ]
deps = [ dir_pw_assert ]
public_deps = [ ":pw_async2" ]
if (pw_async2_DISPATCHER_FOR_TEST_BACKEND != "") {
public_deps += [ pw_async2_DISPATCHER_FOR_TEST_BACKEND ]
}
sources = [ "dispatcher_for_test.cc" ]
testonly = pw_unit_test_TESTONLY
}
pw_source_set("channel_testing_internal") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/internal/channel_test_util.h" ]
public_deps = [
":channel",
":pw_async2",
"$dir_pw_containers:vector",
]
testonly = pw_unit_test_TESTONLY
visibility = [ ":*" ]
}
pw_source_set("coro_testing_internal") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/internal/coro_test_util.h" ]
testonly = pw_unit_test_TESTONLY
visibility = [ ":*" ]
}
config("basic_dispatcher_for_test_public_overrides") {
include_dirs = [ "dispatcher_for_test_public_overrides" ]
visibility = [ ":*" ]
}
pw_source_set("basic_dispatcher_for_test") {
public_configs = [ ":basic_dispatcher_for_test_public_overrides" ]
public = [ "dispatcher_for_test_public_overrides/pw_async2_backend/native_dispatcher_for_test.h" ]
public_deps = [ ":basic_dispatcher" ]
testonly = pw_unit_test_TESTONLY
}
pw_source_set("epoll_dispatcher") {
public_configs = [ ":public_include_path" ]
public_deps = [
":pw_async2",
"$dir_pw_assert",
"$dir_pw_status",
]
deps = [ "$dir_pw_log" ]
public = [ "public/pw_async2/epoll_dispatcher.h" ]
sources = [ "epoll_dispatcher.cc" ]
}
config("epoll_dispatcher_for_test_public_overrides") {
include_dirs = [ "epoll_dispatcher_for_test_public_overrides" ]
visibility = [ ":*" ]
}
pw_source_set("epoll_dispatcher_for_test") {
public_configs = [ ":epoll_dispatcher_for_test_public_overrides" ]
public = [ "epoll_dispatcher_for_test_public_overrides/pw_async2_backend/native_dispatcher_for_test.h" ]
public_deps = [ ":epoll_dispatcher" ]
}
pw_test("dispatcher_test") {
enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" &&
pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND != ""
deps = [
":pw_async2",
":testing",
":value_future",
"$dir_pw_containers:vector",
]
sources = [ "dispatcher_test.cc" ]
}
pw_test("future_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":pw_async2",
":select",
":testing",
]
sources = [ "future_test.cc" ]
negative_compilation_tests = true
}
pw_test("future_task_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":pw_async2",
":testing",
":value_future",
]
sources = [ "future_task_test.cc" ]
}
pw_source_set("future_timeout") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/future_timeout.h" ]
public_deps = [
":channel",
":pw_async2",
":system_time_provider",
":time_provider",
":value_future",
"$dir_pigweed/third_party/fuchsia:stdcompat",
"$dir_pw_assert:assert",
"$dir_pw_chrono:system_clock",
dir_pw_function,
dir_pw_preprocessor,
dir_pw_status,
]
}
pw_test("future_timeout_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":channel",
":future_timeout",
":pw_async2",
":simulated_time_provider",
":testing",
":value_future",
"$dir_pw_chrono:system_clock",
dir_pw_function,
dir_pw_result,
dir_pw_status,
]
negative_compilation_tests = true
sources = [ "future_timeout_test.cc" ]
}
pw_source_set("box") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/box.h" ]
public_deps = [
":pw_async2",
dir_pw_allocator,
]
}
pw_test("box_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":box",
":channel",
":pw_async2",
":select",
":testing",
":transform",
":value_future",
"$dir_pw_allocator:testing",
]
sources = [ "box_test.cc" ]
}
pw_source_set("transform") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/transform.h" ]
public_deps = [
":pw_async2",
":value_future",
]
}
pw_test("transform_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":channel",
":pw_async2",
":select",
":testing",
":transform",
":value_future",
]
sources = [ "transform_test.cc" ]
}
pw_source_set("value_future") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/value_future.h" ]
sources = [ "value_future.cc" ]
public_deps = [ ":pw_async2" ]
deps = [
"$dir_pw_assert:assert",
"$dir_pw_assert:check",
"$dir_pw_sync:interrupt_spin_lock",
dir_pw_polyfill,
]
}
pw_test("value_future_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":pw_async2",
":testing",
":value_future",
]
sources = [ "value_future_test.cc" ]
}
pw_test("value_future_thread_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
sources = [ "value_future_thread_test.cc" ]
deps = [
":callback_task",
":pw_async2",
":testing",
":value_future",
"$dir_pw_thread:sleep",
"$dir_pw_thread:test_thread_context",
"$dir_pw_thread:thread",
"$dir_pw_thread:yield",
]
}
pw_test("func_task_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":pw_async2",
":testing",
]
sources = [ "func_task_test.cc" ]
}
pw_source_set("callback_task") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/callback_task.h" ]
public_deps = [
":pw_async2",
dir_pw_function,
]
}
pw_test("callback_task_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":callback_task",
":pw_async2",
":testing",
":value_future",
dir_pw_function,
]
sources = [ "callback_task_test.cc" ]
enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != ""
}
pw_test("allocate_task_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":pw_async2",
":testing",
":value_future",
"$dir_pw_allocator:testing",
"$dir_pw_function",
"$dir_pw_status",
]
sources = [ "allocate_task_test.cc" ]
}
pw_source_set("notification") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/notification.h" ]
public_deps = [ ":value_future" ]
}
pw_test("notification_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":notification",
":pw_async2",
":testing",
]
sources = [ "notification_test.cc" ]
}
if (pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX20) {
pw_source_set("coro") {
public_configs = [ ":public_include_path" ]
public = [
"public/pw_async2/coro.h",
"public/pw_async2/coro_task.h",
"public/pw_async2/fallible_coro_task.h",
]
public_deps = [
":internal",
":pw_async2",
"$dir_pw_assert:assert",
"$dir_pw_containers:optional",
dir_pw_allocator,
dir_pw_function,
]
deps = [
"$dir_pw_assert:check",
"$dir_pw_bytes:alignment",
dir_pw_log,
]
sources = [
"coro.cc",
"coro_task.cc",
"public/pw_async2/coro_or_else_task.h",
]
allow_circular_includes_from = [ ":pw_async2" ]
}
pw_test("coro_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":coro",
":coro_testing_internal",
":pw_async2",
":testing",
":value_future",
"$dir_pw_allocator:null_allocator",
"$dir_pw_allocator:testing",
"$dir_pw_containers:test_helpers",
"$dir_pw_status",
]
sources = [ "coro_test.cc" ]
negative_compilation_tests = true
}
pw_test("fallible_coro_task_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
sources = [ "fallible_coro_task_test.cc" ]
deps = [
":coro",
":coro_testing_internal",
":pw_async2",
":testing",
":value_future",
"$dir_pw_allocator:null_allocator",
"$dir_pw_allocator:testing",
"$dir_pw_containers:test_helpers",
"$dir_pw_status",
]
}
pw_test("coro_task_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
sources = [ "coro_task_test.cc" ]
deps = [
":coro",
":coro_testing_internal",
":pw_async2",
":testing",
"$dir_pw_allocator:testing",
"$dir_pw_status",
]
}
pw_test("allocate_task_coro_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
sources = [ "allocate_task_coro_test.cc" ]
deps = [
":coro",
":pw_async2",
":testing",
"$dir_pw_allocator:testing",
]
}
}
pw_source_set("time_provider") {
public = [ "public/pw_async2/time_provider.h" ]
sources = [ "time_provider.cc" ]
public_configs = [ ":public_include_path" ]
public_deps = [
":pw_async2",
"$dir_pw_chrono:virtual_clock",
"$dir_pw_containers:intrusive_list",
"$dir_pw_memory:no_destructor",
"$dir_pw_sync:interrupt_spin_lock",
dir_pw_assert,
dir_pw_function,
dir_pw_memory,
dir_pw_span,
]
}
pw_source_set("system_time_provider") {
public = [ "public/pw_async2/system_time_provider.h" ]
public_configs = [ ":public_include_path" ]
public_deps = [
":time_provider",
"$dir_pw_chrono:system_clock",
]
sources = [ "system_time_provider.cc" ]
deps = [
"$dir_pw_chrono:system_timer",
"$dir_pw_memory:no_destructor",
]
}
pw_test("system_time_provider_test") {
enable_if =
pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" && pw_thread_YIELD_BACKEND != ""
sources = [ "system_time_provider_test.cc" ]
deps = [
":system_time_provider",
":testing",
]
}
pw_source_set("simulated_time_provider") {
public = [ "public/pw_async2/simulated_time_provider.h" ]
public_configs = [ ":public_include_path" ]
public_deps = [
":time_provider",
"$dir_pw_sync:interrupt_spin_lock",
]
}
pw_test("simulated_time_provider_test") {
enable_if =
pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" && pw_thread_YIELD_BACKEND != ""
sources = [ "simulated_time_provider_test.cc" ]
deps = [
":simulated_time_provider",
":testing",
"$dir_pw_chrono:system_clock",
]
}
pw_source_set("join") {
public = [ "public/pw_async2/join.h" ]
public_configs = [ ":public_include_path" ]
public_deps = [ ":pw_async2" ]
}
pw_test("join_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
sources = [ "join_test.cc" ]
deps = [
":join",
":pw_async2",
":testing",
":value_future",
]
negative_compilation_tests = true
}
pw_source_set("select") {
public = [ "public/pw_async2/select.h" ]
public_configs = [ ":public_include_path" ]
public_deps = [
":pw_async2",
"$dir_pw_containers:optional_tuple",
]
}
pw_test("select_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
sources = [ "select_test.cc" ]
deps = [
":pw_async2",
":select",
":testing",
":value_future",
"$dir_pw_unit_test:constexpr",
]
}
pw_source_set("cancellable_task") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/cancellable_task.h" ]
public_deps = [ ":pw_async2" ]
}
pw_test("cancellable_task_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
deps = [
":cancellable_task",
":pw_async2",
":testing",
dir_pw_function,
]
sources = [ "cancellable_task_test.cc" ]
enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != ""
}
pw_source_set("channel") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_async2/channel.h" ]
sources = [ "channel.cc" ]
public_deps = [
":callback_task",
":pw_async2",
"$dir_pw_allocator",
"$dir_pw_assert",
"$dir_pw_containers:deque",
"$dir_pw_numeric:checked_arithmetic",
"$dir_pw_sync:interrupt_spin_lock",
"$dir_pw_sync:timed_thread_notification",
"$pw_external_fuchsia:stdcompat",
]
}
pw_test("channel_test") {
# TODO: b/474661031 - Disable test on Windows since it crashes the compiler.
enable_if = host_os != "win" && pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
sources = [ "channel_test.cc" ]
deps = [
":channel",
":channel_testing_internal",
":pw_async2",
":testing",
"$dir_pw_allocator:testing",
"$dir_pw_containers:vector",
dir_pw_function,
]
}
pw_test("channel_thread_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
sources = [ "channel_thread_test.cc" ]
deps = [
":channel",
":channel_testing_internal",
":pw_async2",
":testing",
"$dir_pw_containers:vector",
"$dir_pw_thread:test_thread_context",
"$dir_pw_thread:thread",
"$dir_pw_thread_stl:thread",
dir_pw_function,
]
}
pw_test("channel_typed_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != "" &&
pw_unit_test_BACKEND != "" &&
pw_unit_test_BACKEND != "$dir_pw_unit_test:light"
sources = [ "channel_typed_test.cc" ]
deps = [
":channel",
":pw_async2",
":testing",
"$dir_pw_allocator:testing",
"$dir_pw_containers:vector",
]
}
pw_test("task_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != "" &&
pw_thread_TEST_THREAD_CONTEXT_BACKEND != ""
deps = [
":pw_async2",
":testing",
"$dir_pw_sync:binary_semaphore",
"$dir_pw_sync:mutex",
"$dir_pw_thread:sleep",
"$dir_pw_thread:test_thread_context",
"$dir_pw_thread:thread",
]
sources = [ "task_test.cc" ]
}
pw_test("dispatcher_thread_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != "" &&
pw_thread_TEST_THREAD_CONTEXT_BACKEND != ""
deps = [
":pw_async2",
":testing",
"$dir_pw_sync:thread_notification",
"$dir_pw_thread:sleep",
"$dir_pw_thread:test_thread_context",
"$dir_pw_thread:thread",
]
sources = [ "dispatcher_thread_test.cc" ]
}
pw_test("dispatcher_stress_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != "" &&
pw_thread_TEST_THREAD_CONTEXT_BACKEND != ""
deps = [
":notified_dispatcher",
":pw_async2",
"$dir_pw_allocator:libc_allocator",
"$dir_pw_containers:dynamic_queue",
"$dir_pw_containers:dynamic_vector",
"$dir_pw_log",
"$dir_pw_sync:lock_annotations",
"$dir_pw_sync:mutex",
"$dir_pw_sync:thread_notification",
"$dir_pw_thread:test_thread_context",
"$dir_pw_thread:thread",
"$dir_pw_thread:yield",
dir_pw_assert,
]
sources = [ "dispatcher_stress_test.cc" ]
}
if (pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX20) {
pw_test("channel_coro_test") {
enable_if = pw_async2_DISPATCHER_FOR_TEST_BACKEND != ""
sources = [ "channel_coro_test.cc" ]
deps = [
":channel",
":coro",
":pw_async2",
":testing",
"$dir_pw_allocator:testing",
"$dir_pw_containers:vector",
]
}
}
pw_test_group("tests") {
tests = [
":allocate_task_test",
":box_test",
":callback_task_test",
":cancellable_task_test",
":channel_test",
":dispatcher_test",
":dispatcher_thread_test",
":dispatcher_stress_test",
":future_test",
":join_test",
":poll_test",
":func_task_test",
":notification_test",
":select_test",
":simulated_time_provider_test",
":system_time_provider_test",
":task_test",
":transform_test",
":value_future_test",
":await_test",
]
if (pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX20) {
tests += [
":channel_coro_test",
":coro_test",
":coro_task_test",
":fallible_coro_task_test",
":allocate_task_coro_test",
]
}
}