#include <test_thread_context.h>
Public Member Functions | |
TestThreadContext (const TestThreadContext &)=delete | |
TestThreadContext & | operator= (const TestThreadContext &)=delete |
const Options & | options () const |
TestThreadContext
is a facade class for creating threads for unit tests in a platform independent way. To use it, set pw_thread_TEST_THREAD_CONTEXT_BACKEND
to a backend that implements the pw::thread::test::backend::TestThreadContextNative
class.
To create a thread for unit testing, instantiate a TestThreadContext
, then call options()
to obtain a pw::thread::Options
. Use that Options
to start a Thread
. Users must ensure the context's lifespan outlives the thread it creates. Recycling or destroying the context is only allowed if join()
is called on the thread first.
Threads created with TestThreadContext
cannot be configured in any way. Backends should create threads with sufficient resources to execute typical unit tests. Tests for complex scenarios or interactions where e.g. priority matters are not portable, and TestThreadContext
may not work for them. Non-portable tests may include backend-specific headers and instantiate thread options for their platforms as required.
TestThreadContext
may only be detached if the context has a static lifetime, meaning the context is both never re-used and not destroyed before the end of the lifetime of the application.
|
inline |
pw::thread::test::TestThreadContext
returns a pw::thread::Options
associated with the this object, which can be used to contruct a thread.