Ocean
Loading...
Searching...
No Matches
TestSignal.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TESTBASE_TEST_SIGNAL_H
9#define META_OCEAN_TEST_TESTBASE_TEST_SIGNAL_H
10
13
15#include "ocean/base/Signal.h"
16#include "ocean/base/Thread.h"
17
18namespace Ocean
19{
20
21namespace Test
22{
23
24namespace TestBase
25{
26
27/**
28 * This class implements signal tests.
29 * @ingroup testbase
30 */
31class OCEAN_TEST_BASE_EXPORT TestSignal
32{
33 private:
34
35 /**
36 * This class implements a simple helper thread allowing to invoke/pulse a signal after a specified time.
37 */
38 class SignalThread : public Thread
39 {
40 public:
41
42 /**
43 * Creates a new thread object.
44 * @param timer The timer providing the same time value for all threads
45 * @param timeout The timeout the thread will wait until the corresponding signal will be pulsed, in seconds with range (0, infinity)
46 * @param signal The signal to be used
47 */
48 SignalThread(const HighPerformanceTimer& timer, const double timeout, Signal& signal);
49
50 private:
51
52 /**
53 * Thread function.
54 * @see Thread::threadRun().
55 */
56 void threadRun() override;
57
58 private:
59
60 /// The timer providing the same time value for all threads.
62
63 /// Timeout for the thread, in seconds with range (0, infinity)
64 const double timeout_;
65
66 /// Signal to be used.
68 };
69
70 /**
71 * This class implements a simple helper thread simulating an async function execution.
72 */
74 {
75 public:
76
77 /**
78 * Creates a new thread object and starts the thread.
79 */
81
82 /**
83 * Destructs the thread object and stops any ongoing async function as fast as possible.
84 */
86
87 /**
88 * Starts the async function.
89 */
91
92 private:
93
94 /**
95 * Thread function.
96 * @see Thread::threadRun().
97 */
98 void threadRun() override;
99
100 /**
101 * The async function.
102 */
104
105 private:
106
107 /// The signal for starting the async function.
109
110 /// The signal for the finished async function.
112 };
113
114 public:
115
116 /**
117 * Tests the entire signal functionalities.
118 * @param testDuration Number of seconds for each test, with range (0, infinity)
119 * @param selector Optional test selector
120 * @return True, if succeeded
121 */
122 static bool test(const double testDuration, const TestSelector& selector = TestSelector());
123
124 /**
125 * Tests basic signal functions.
126 * @return True, if succeeded
127 */
128 static bool testSignalBasics();
129
130 /**
131 * Tests one signal without timeout.
132 * @return True, if succeeded
133 */
135
136 /**
137 * Tests one signal with timeout.
138 * @return True, if succeeded
139 */
141
142 /**
143 * Tests one signal in a loop.
144 * @return True, if succeeded
145 */
146 static bool testSingleSignalLoop();
147
148 /**
149 * Tests a pulse, wait, release cycle via an async function execution.
150 * @param testDuration Number of seconds for each test, with range (0, infinity)
151 * @return True, if succeeded
152 */
153 static bool testAsyncFunction(const double testDuration);
154
155 /**
156 * Tests the set of multiple signals.
157 * @return True, if succeeded
158 */
159 static bool testMultipleSignals();
160
161 /**
162 * Tests the subset of multiple signals without timeout.
163 * @return True, if succeeded
164 */
166
167 /**
168 * Tests the subset of multiple signals with timeout.
169 * @return True, if succeeded
170 */
172};
173
174}
175
176}
177
178}
179
180#endif // META_OCEAN_TEST_TESTBASE_TEST_SIGNAL_H
This class implements a high performance timer.
Definition HighPerformanceTimer.h:31
This class implements a signal.
Definition Signal.h:31
This class implements a simple helper thread simulating an async function execution.
Definition TestSignal.h:74
~AsyncFunctionThread() override
Destructs the thread object and stops any ongoing async function as fast as possible.
AsyncFunctionThread()
Creates a new thread object and starts the thread.
Signal signalAsyncStopped_
The signal for the finished async function.
Definition TestSignal.h:111
Signal signalAsyncStart_
The signal for starting the async function.
Definition TestSignal.h:108
void startAsyncFunction()
Starts the async function.
This class implements a simple helper thread allowing to invoke/pulse a signal after a specified time...
Definition TestSignal.h:39
SignalThread(const HighPerformanceTimer &timer, const double timeout, Signal &signal)
Creates a new thread object.
const double timeout_
Timeout for the thread, in seconds with range (0, infinity)
Definition TestSignal.h:64
void threadRun() override
Thread function.
const HighPerformanceTimer & timer_
The timer providing the same time value for all threads.
Definition TestSignal.h:61
Signal & signal_
Signal to be used.
Definition TestSignal.h:67
This class implements signal tests.
Definition TestSignal.h:32
static bool testSubsetSignalsTimeout()
Tests the subset of multiple signals with timeout.
static bool testMultipleSignals()
Tests the set of multiple signals.
static bool test(const double testDuration, const TestSelector &selector=TestSelector())
Tests the entire signal functionalities.
static bool testSubsetSignalsStandard()
Tests the subset of multiple signals without timeout.
static bool testSingleSignalTimeout()
Tests one signal with timeout.
static bool testSingleSignalStandard()
Tests one signal without timeout.
static bool testSingleSignalLoop()
Tests one signal in a loop.
static bool testAsyncFunction(const double testDuration)
Tests a pulse, wait, release cycle via an async function execution.
static bool testSignalBasics()
Tests basic signal functions.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
This class implements a thread.
Definition Thread.h:115
The namespace covering the entire Ocean framework.
Definition Accessor.h:15