02_unit_testing: Create thread for unit test server http://pwrev.dev/253913 updates Pigweed's unit testing RPC server to require a dedicated thread on which to run tests. This defines that thread and provides it to the server. Bug: 408449338 Change-Id: Iedecc4f638386ac32f685c69a441f0fb28abc91c Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/examples/+/280655 Reviewed-by: Armando Montanez <amontanez@google.com> Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> Pigweed-Auto-Submit: Alexei Frolov <frolv@google.com> Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com> Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
diff --git a/examples/02_unit_testing/BUILD.bazel b/examples/02_unit_testing/BUILD.bazel index 0483a25..0c5fa02 100644 --- a/examples/02_unit_testing/BUILD.bazel +++ b/examples/02_unit_testing/BUILD.bazel
@@ -50,6 +50,7 @@ "@pigweed//pw_chrono:system_timer", "@pigweed//pw_log", "@pigweed//pw_system", + "@pigweed//pw_thread:thread", "@pigweed//pw_unit_test:rpc_service", ], )
diff --git a/examples/02_unit_testing/BUILD.gn b/examples/02_unit_testing/BUILD.gn index 5e6e65d..7c5d80e 100644 --- a/examples/02_unit_testing/BUILD.gn +++ b/examples/02_unit_testing/BUILD.gn
@@ -33,6 +33,7 @@ ":bitops_test.lib", "$dir_pw_system:pw_system", "$dir_pw_system:rpc_server", + "$dir_pw_thread:thread", "$dir_pw_unit_test:rpc_service", ] }
diff --git a/examples/02_unit_testing/main.cc b/examples/02_unit_testing/main.cc index 988d0fd..b5ec3d1 100644 --- a/examples/02_unit_testing/main.cc +++ b/examples/02_unit_testing/main.cc
@@ -14,14 +14,30 @@ #define PW_LOG_MODULE_NAME "user_init" #include "pw_system/rpc_server.h" +#include "pw_thread/thread.h" #include "pw_unit_test/unit_test_service.h" +namespace { + +constexpr pw::ThreadAttrs kUnitTestThreadAttrs = + pw::ThreadAttrs() + .set_name("UnitTestThread") + .set_priority(pw::ThreadPriority::Medium()) + .set_stack_size_bytes(8192); +pw::ThreadContextFor<kUnitTestThreadAttrs> unit_test_thread_context; + +pw::unit_test::UnitTestThread unit_test_thread; + +} // namespace + namespace pw::system { -pw::unit_test::UnitTestService unit_test_service; - // This will run once after pw::system::Init() completes. This callback must // return or it will block the work queue. -void UserAppInit() { GetRpcServer().RegisterService(unit_test_service); } +void UserAppInit() { + pw::Thread(pw::GetThreadOptions(unit_test_thread_context), unit_test_thread) + .detach(); + GetRpcServer().RegisterService(unit_test_thread.service()); +} } // namespace pw::system
diff --git a/third_party/pigweed b/third_party/pigweed index 74fc655..b6ba89f 160000 --- a/third_party/pigweed +++ b/third_party/pigweed
@@ -1 +1 @@ -Subproject commit 74fc6559bf6c6e557c7b0c3fa0394cd7cff01acc +Subproject commit b6ba89f7c4a12b7af74d5336883023f103375127