1 // Copyright 2023 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 15 // IMPORTANT: DO NOT USE THIS HEADER FOR UNIT TESTS!!! 16 // 17 // Instead, use pw::thread::test::TestThreadContext in 18 // pw_thread/test_thread_context.h. See 19 // https://pigweed.dev/pw_thread#unit-testing-with-threads. 20 // 21 // pw_thread/non_portable_test_thread_options.h is not a facade. Code written 22 // against it is not portable. It was created for testing of pw_thread itself, 23 // so threads with different configurations can be instantiated in tests. 24 #pragma once 25 26 #include "pw_thread/thread.h" 27 28 namespace pw::thread::test { 29 30 // Two test threads are used to verify the thread facade. 31 // 32 // These functions are NOT part of a facade! They are used to allocate thread 33 // options for testing pw_thread backends only. Multiple variations of these 34 // functions may be instantiated within a single toolchain for testing purposes. 35 // Do NOT use unless absolutely necessary. Instead, use the TestThreadContext 36 // facade for unit tests. 37 const Options& TestOptionsThread0(); 38 const Options& TestOptionsThread1(); 39 40 // The proper way to ensure a thread is finished and cleaned up is to call 41 // join(). However, the pw_thread facade tests must test detached thread 42 // functionality. This backend-specific cleanup API blocks until all the test 43 // threads above have finished executing. 44 // 45 // Threads may be backed by static contexts or dynamic context heap allocations. 46 // After this function returns, the threads' static contexts are ready for reuse 47 // and/or their dynamically allocated memory has been freed. 48 // 49 // Precondition: The threads must have started to execute before calling this 50 // if cleanup is expected. 51 void WaitUntilDetachedThreadsCleanedUp(); 52 53 } // namespace pw::thread::test 54