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 assert(pw_thread_THREAD_CREATION_BACKEND != "", 63 "pw_thread_THREAD_CREATION_BACKEND cannot be set to \"\". Set it to " + 64 "\"$dir_pw_thread:generic_thread_creation_unsupported\" if it " + 65 "not implemented") 66 67 backend = pw_thread_THREAD_BACKEND 68 public_configs = [ ":public_include_path" ] 69 public = [ 70 "public/pw_thread/attrs.h", 71 "public/pw_thread/context.h", 72 "public/pw_thread/detached_thread.h", 73 "public/pw_thread/native_options.h", 74 "public/pw_thread/priority.h", 75 "public/pw_thread/stack.h", 76 "public/pw_thread/stack_not_supported.h", 77 "public/pw_thread/thread.h", 78 ] 79 public_deps = [ 80 ":generic_priority", 81 ":id", 82 ":options", 83 dir_pw_function, 84 dir_pw_preprocessor, 85 dir_pw_span, 86 pw_thread_THREAD_CREATION_BACKEND, 87 ] 88} 89 90config("null_thread_creation_public_include_path") { 91 include_dirs = [ "null_thread_creation_public_overrides" ] 92 visibility = [ ":*" ] 93} 94 95pw_source_set("generic_thread_creation_unsupported") { 96 public_configs = [ ":null_thread_creation_public_include_path" ] 97 public = [ 98 "null_thread_creation_public_overrides/pw_thread_backend/context.h", 99 "null_thread_creation_public_overrides/pw_thread_backend/options.h", 100 "null_thread_creation_public_overrides/pw_thread_backend/priority.h", 101 "null_thread_creation_public_overrides/pw_thread_backend/stack.h", 102 ] 103} 104 105pw_source_set("options") { 106 public_configs = [ ":public_include_path" ] 107 public = [ "public/pw_thread/options.h" ] 108} 109 110pw_facade("test_thread_context") { 111 backend = pw_thread_TEST_THREAD_CONTEXT_BACKEND 112 public_configs = [ ":public_include_path" ] 113 public = [ "public/pw_thread/test_thread_context.h" ] 114} 115 116pw_source_set("thread_core") { 117 public_configs = [ ":public_include_path" ] 118 public = [ "public/pw_thread/thread_core.h" ] 119 public_deps = [ dir_pw_function ] 120} 121 122pw_facade("thread_iteration") { 123 backend = pw_thread_THREAD_ITERATION_BACKEND 124 public_configs = [ ":public_include_path" ] 125 public = [ "public/pw_thread/thread_iteration.h" ] 126 public_deps = [ 127 ":thread_info", 128 "$dir_pw_function", 129 "$dir_pw_status", 130 ] 131} 132 133pw_facade("yield") { 134 backend = pw_thread_YIELD_BACKEND 135 public_configs = [ ":public_include_path" ] 136 public = [ "public/pw_thread/yield.h" ] 137 public_deps = [ "$dir_pw_preprocessor" ] 138 sources = [ "yield.cc" ] 139} 140 141pw_source_set("generic_priority") { 142 public_configs = [ ":public_include_path" ] 143 public_deps = [ 144 "$dir_pw_numeric:integer_division", 145 "$dir_pw_third_party/fuchsia:stdcompat", 146 dir_pw_assert, 147 dir_pw_polyfill, 148 ] 149 sources = [ "public/pw_thread/internal/priority.h" ] 150 visibility = [ ":*" ] 151} 152 153pw_test("priority_test") { 154 sources = [ "priority_test.cc" ] 155 deps = [ 156 ":generic_priority", 157 "$dir_pw_unit_test:constexpr", 158 ] 159 negative_compilation_tests = true 160} 161 162pw_test("thread_creation_test") { 163 sources = [ "thread_creation_test.cc" ] 164 deps = [ ":thread" ] 165 negative_compilation_tests = true 166 167 # TODO: b/388048843 - Build on Windows when the toolchain is updated. 168 enable_if = host_os != "win" && pw_thread_THREAD_BACKEND != "" 169} 170 171pw_test("attrs_test") { 172 sources = [ "attrs_test.cc" ] 173 deps = [ 174 ":thread", 175 "$dir_pw_unit_test:constexpr", 176 ] 177 negative_compilation_tests = true 178 enable_if = pw_thread_THREAD_BACKEND != "" 179} 180 181pw_test("stack_test") { 182 sources = [ "stack_test.cc" ] 183 deps = [ ":thread" ] 184 enable_if = pw_thread_THREAD_BACKEND != "" 185} 186 187pw_source_set("snapshot") { 188 public_configs = [ ":public_include_path" ] 189 public_deps = [ 190 "$dir_pw_thread:protos.pwpb", 191 dir_pw_bytes, 192 dir_pw_function, 193 dir_pw_protobuf, 194 dir_pw_status, 195 ] 196 public = [ "public/pw_thread/snapshot.h" ] 197 sources = [ "snapshot.cc" ] 198 deps = [ 199 ":config", 200 dir_pw_log, 201 ] 202} 203 204pw_source_set("thread_info") { 205 public_configs = [ ":public_include_path" ] 206 public_deps = [ dir_pw_span ] 207 public = [ "public/pw_thread/thread_info.h" ] 208 deps = [ ":config" ] 209} 210 211pw_source_set("thread_snapshot_service") { 212 public_configs = [ ":public_include_path" ] 213 public = [ "public/pw_thread/thread_snapshot_service.h" ] 214 public_deps = [ 215 ":protos.pwpb", 216 ":protos.raw_rpc", 217 ":thread_info", 218 "$dir_pw_rpc/raw:server_api", 219 "$dir_pw_status:pw_status", 220 ] 221 sources = [ 222 "pw_thread_private/thread_snapshot_service.h", 223 "thread_snapshot_service.cc", 224 ] 225 deps = [ 226 ":config", 227 ":thread_iteration", 228 "$dir_pw_log", 229 "$dir_pw_protobuf", 230 "$dir_pw_rpc/raw:server_api", 231 "$dir_pw_span", 232 "$dir_pw_status:pw_status", 233 ] 234} 235 236pw_test_group("tests") { 237 tests = [ 238 ":attrs_test", 239 ":id_facade_test", 240 ":options_test", 241 ":priority_test", 242 ":sleep_facade_test", 243 ":stack_test", 244 ":test_thread_context_facade_test", 245 ":thread_creation_test", 246 ":thread_info_test", 247 ":thread_snapshot_service_test", 248 ":yield_facade_test", 249 ] 250} 251 252pw_test("test_thread_context_facade_test") { 253 # TODO: b/317922402 - On Windows, this test can easily hang indefinitely. 254 # Disable on Windows until we can test with the native Windows SDK libraries 255 # for threading. 256 enable_if = pw_thread_TEST_THREAD_CONTEXT_BACKEND != "" && current_os != "win" 257 sources = [ "test_thread_context_facade_test.cc" ] 258 deps = [ 259 ":test_thread_context", 260 ":thread", 261 "$dir_pw_sync:binary_semaphore", 262 ] 263} 264 265pw_test("id_facade_test") { 266 enable_if = pw_thread_ID_BACKEND != "" 267 sources = [ "id_facade_test.cc" ] 268 deps = [ ":thread" ] 269} 270 271pw_test("thread_snapshot_service_test") { 272 enable_if = pw_thread_THREAD_ITERATION_BACKEND != "" 273 sources = [ 274 "pw_thread_private/thread_snapshot_service.h", 275 "thread_snapshot_service_test.cc", 276 ] 277 deps = [ 278 ":protos.pwpb", 279 ":thread_iteration", 280 "$dir_pw_protobuf", 281 "$dir_pw_span", 282 "$dir_pw_sync:thread_notification", 283 "$dir_pw_thread:thread_info", 284 "$dir_pw_thread:thread_snapshot_service", 285 ] 286} 287 288pw_test("sleep_facade_test") { 289 enable_if = pw_thread_SLEEP_BACKEND != "" && pw_thread_ID_BACKEND != "" 290 sources = [ 291 "sleep_facade_test.cc", 292 "sleep_facade_test_c.c", 293 ] 294 deps = [ 295 ":sleep", 296 ":thread", 297 "$dir_pw_chrono:system_clock", 298 ] 299} 300 301pw_source_set("non_portable_test_thread_options") { 302 public_configs = [ ":public_include_path" ] 303 public = [ "public/pw_thread/non_portable_test_thread_options.h" ] 304 public_deps = [ ":thread" ] 305} 306 307# To instantiate this facade test based on a selected backend to provide 308# test_threads you can create a pw_test target which depends on this 309# pw_source_set and a pw_source_set which provides the implementation of 310# test_threads. See "$dir_pw_thread_stl:thread_backend_test" as an example. 311pw_source_set("thread_facade_test") { 312 testonly = pw_unit_test_TESTONLY 313 sources = [ "thread_facade_test.cc" ] 314 deps = [ 315 ":non_portable_test_thread_options", 316 ":sleep", 317 ":thread", 318 ":thread_core", 319 "$dir_pw_sync:binary_semaphore", 320 dir_pw_unit_test, 321 ] 322} 323 324pw_test("options_test") { 325 sources = [ "options_test.cc" ] 326 deps = [ ":options" ] 327 negative_compilation_tests = true 328} 329 330pw_test("thread_info_test") { 331 sources = [ "thread_info_test.cc" ] 332 deps = [ 333 ":thread_info", 334 dir_pw_span, 335 ] 336} 337 338pw_test("yield_facade_test") { 339 enable_if = pw_thread_YIELD_BACKEND != "" && pw_thread_ID_BACKEND != "" 340 sources = [ 341 "yield_facade_test.cc", 342 "yield_facade_test_c.c", 343 ] 344 deps = [ 345 ":thread", 346 ":yield", 347 ] 348} 349 350pw_proto_library("protos") { 351 sources = [ 352 "pw_thread_protos/thread.proto", 353 "pw_thread_protos/thread_snapshot_service.proto", 354 ] 355 deps = [ "$dir_pw_tokenizer:proto" ] 356} 357 358pw_doc_group("docs") { 359 inputs = 360 [ "$dir_pw_thread_stl/public/pw_thread_stl/test_thread_context_native.h" ] 361 sources = [ 362 "backends.rst", 363 "docs.rst", 364 ] 365} 366