1# Copyright 2020 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_build/facade.gni") 18import("$dir_pw_build/module_config.gni") 19import("$dir_pw_build/target_types.gni") 20import("$dir_pw_docgen/docs.gni") 21import("$dir_pw_protobuf_compiler/proto.gni") 22import("$dir_pw_unit_test/test.gni") 23import("backend.gni") 24 25declare_args() { 26 # The build target that overrides the default configuration options for this 27 # module. This should point to a source set that provides defines through a 28 # public config (which may -include a file or add defines directly). 29 pw_thread_CONFIG = pw_build_DEFAULT_MODULE_CONFIG 30} 31 32config("public_include_path") { 33 include_dirs = [ "public" ] 34 visibility = [ ":*" ] 35} 36 37pw_source_set("config") { 38 public_deps = [ pw_thread_CONFIG ] 39 public = [ "public/pw_thread/config.h" ] 40 public_configs = [ ":public_include_path" ] 41 visibility = [ ":*" ] 42} 43 44pw_facade("id") { 45 backend = pw_thread_ID_BACKEND 46 public_configs = [ ":public_include_path" ] 47 public = [ "public/pw_thread/id.h" ] 48} 49 50pw_facade("sleep") { 51 backend = pw_thread_SLEEP_BACKEND 52 public_configs = [ ":public_include_path" ] 53 public = [ "public/pw_thread/sleep.h" ] 54 public_deps = [ 55 "$dir_pw_chrono:system_clock", 56 "$dir_pw_preprocessor", 57 ] 58 sources = [ "sleep.cc" ] 59} 60 61pw_facade("thread") { 62 backend = pw_thread_THREAD_BACKEND 63 public_configs = [ ":public_include_path" ] 64 public = [ 65 "public/pw_thread/detached_thread.h", 66 "public/pw_thread/thread.h", 67 ] 68 public_deps = [ 69 ":id", 70 ":thread_core", 71 dir_pw_function, 72 ] 73 sources = [ "thread.cc" ] 74} 75 76pw_source_set("deprecated_or_new_thread_function") { 77 public_configs = [ ":public_include_path" ] 78 public = [ "public/pw_thread/deprecated_or_new_thread_function.h" ] 79 public_deps = [ dir_pw_function ] 80} 81 82pw_test("deprecated_or_new_thread_function_test") { 83 sources = [ "deprecated_or_new_thread_function_test.cc" ] 84 deps = [ ":deprecated_or_new_thread_function" ] 85} 86 87pw_facade("test_thread_context") { 88 backend = pw_thread_TEST_THREAD_CONTEXT_BACKEND 89 public_configs = [ ":public_include_path" ] 90 public = [ "public/pw_thread/test_thread_context.h" ] 91} 92 93pw_source_set("thread_core") { 94 public_configs = [ ":public_include_path" ] 95 public = [ "public/pw_thread/thread_core.h" ] 96} 97 98pw_facade("thread_iteration") { 99 backend = pw_thread_THREAD_ITERATION_BACKEND 100 public_configs = [ ":public_include_path" ] 101 public = [ "public/pw_thread/thread_iteration.h" ] 102 public_deps = [ 103 ":thread_info", 104 "$dir_pw_function", 105 "$dir_pw_status", 106 ] 107} 108 109pw_facade("yield") { 110 backend = pw_thread_YIELD_BACKEND 111 public_configs = [ ":public_include_path" ] 112 public = [ "public/pw_thread/yield.h" ] 113 public_deps = [ "$dir_pw_preprocessor" ] 114 sources = [ "yield.cc" ] 115} 116 117pw_source_set("snapshot") { 118 public_configs = [ ":public_include_path" ] 119 public_deps = [ 120 "$dir_pw_thread:protos.pwpb", 121 dir_pw_bytes, 122 dir_pw_function, 123 dir_pw_protobuf, 124 dir_pw_status, 125 ] 126 public = [ "public/pw_thread/snapshot.h" ] 127 sources = [ "snapshot.cc" ] 128 deps = [ 129 ":config", 130 dir_pw_log, 131 ] 132} 133 134pw_source_set("thread_info") { 135 public_configs = [ ":public_include_path" ] 136 public_deps = [ dir_pw_span ] 137 public = [ "public/pw_thread/thread_info.h" ] 138 deps = [ ":config" ] 139} 140 141pw_source_set("thread_snapshot_service") { 142 public_configs = [ ":public_include_path" ] 143 public = [ "public/pw_thread/thread_snapshot_service.h" ] 144 public_deps = [ 145 ":protos.pwpb", 146 ":protos.raw_rpc", 147 ":thread_info", 148 "$dir_pw_rpc/raw:server_api", 149 "$dir_pw_status:pw_status", 150 ] 151 sources = [ 152 "pw_thread_private/thread_snapshot_service.h", 153 "thread_snapshot_service.cc", 154 ] 155 deps = [ 156 ":config", 157 ":thread_iteration", 158 "$dir_pw_log", 159 "$dir_pw_protobuf", 160 "$dir_pw_rpc/raw:server_api", 161 "$dir_pw_span", 162 "$dir_pw_status:pw_status", 163 ] 164} 165 166pw_test_group("tests") { 167 tests = [ 168 ":deprecated_or_new_thread_function_test", 169 ":id_facade_test", 170 ":sleep_facade_test", 171 ":thread_info_test", 172 ":yield_facade_test", 173 ":test_thread_context_facade_test", 174 ":thread_snapshot_service_test", 175 ] 176} 177 178pw_test("test_thread_context_facade_test") { 179 # TODO: b/317922402 - On Windows, this test can easily hang indefinitely. 180 # Disable on Windows until we can test with the native Windows SDK libraries 181 # for threading. 182 enable_if = pw_thread_TEST_THREAD_CONTEXT_BACKEND != "" && current_os != "win" 183 sources = [ "test_thread_context_facade_test.cc" ] 184 deps = [ 185 ":test_thread_context", 186 ":thread", 187 "$dir_pw_sync:binary_semaphore", 188 ] 189} 190 191pw_test("id_facade_test") { 192 enable_if = pw_thread_ID_BACKEND != "" 193 sources = [ "id_facade_test.cc" ] 194 deps = [ ":id" ] 195} 196 197pw_test("thread_snapshot_service_test") { 198 enable_if = pw_thread_THREAD_ITERATION_BACKEND != "" 199 sources = [ 200 "pw_thread_private/thread_snapshot_service.h", 201 "thread_snapshot_service_test.cc", 202 ] 203 deps = [ 204 ":protos.pwpb", 205 ":thread_iteration", 206 "$dir_pw_protobuf", 207 "$dir_pw_span", 208 "$dir_pw_sync:thread_notification", 209 "$dir_pw_thread:thread_info", 210 "$dir_pw_thread:thread_snapshot_service", 211 ] 212} 213 214pw_test("sleep_facade_test") { 215 enable_if = pw_thread_SLEEP_BACKEND != "" && pw_thread_ID_BACKEND != "" 216 sources = [ 217 "sleep_facade_test.cc", 218 "sleep_facade_test_c.c", 219 ] 220 deps = [ 221 ":id", 222 ":sleep", 223 "$dir_pw_chrono:system_clock", 224 ] 225} 226 227pw_source_set("non_portable_test_thread_options") { 228 public_configs = [ ":public_include_path" ] 229 public = [ "public/pw_thread/non_portable_test_thread_options.h" ] 230 public_deps = [ ":thread" ] 231} 232 233# To instantiate this facade test based on a selected backend to provide 234# test_threads you can create a pw_test target which depends on this 235# pw_source_set and a pw_source_set which provides the implementation of 236# test_threads. See "$dir_pw_thread_stl:thread_backend_test" as an example. 237pw_source_set("thread_facade_test") { 238 testonly = pw_unit_test_TESTONLY 239 sources = [ "thread_facade_test.cc" ] 240 deps = [ 241 ":id", 242 ":non_portable_test_thread_options", 243 ":sleep", 244 ":thread", 245 "$dir_pw_sync:binary_semaphore", 246 dir_pw_unit_test, 247 ] 248} 249 250pw_test("thread_info_test") { 251 sources = [ "thread_info_test.cc" ] 252 deps = [ 253 ":thread_info", 254 dir_pw_span, 255 ] 256} 257 258pw_test("yield_facade_test") { 259 enable_if = pw_thread_YIELD_BACKEND != "" && pw_thread_ID_BACKEND != "" 260 sources = [ 261 "yield_facade_test.cc", 262 "yield_facade_test_c.c", 263 ] 264 deps = [ 265 ":id", 266 ":yield", 267 ] 268} 269 270pw_proto_library("protos") { 271 sources = [ 272 "pw_thread_protos/thread.proto", 273 "pw_thread_protos/thread_snapshot_service.proto", 274 ] 275 deps = [ "$dir_pw_tokenizer:proto" ] 276} 277 278pw_doc_group("docs") { 279 inputs = 280 [ "$dir_pw_thread_stl/public/pw_thread_stl/test_thread_context_native.h" ] 281 sources = [ 282 "backends.rst", 283 "docs.rst", 284 ] 285} 286