Ocean
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 
12 
14 #include "ocean/base/Signal.h"
15 #include "ocean/base/Thread.h"
16 
17 namespace Ocean
18 {
19 
20 namespace Test
21 {
22 
23 namespace TestBase
24 {
25 
26 /**
27  * This class implements signal tests.
28  * @ingroup testbase
29  */
30 class OCEAN_TEST_BASE_EXPORT TestSignal
31 {
32  private:
33 
34  /**
35  * This class implements a simple helper thread allowing to invoke/pulse a signal after a specified time.
36  */
37  class SignalThread : public Thread
38  {
39  public:
40 
41  /**
42  * Creates a new thread object.
43  * @param timer The timer providing the same time value for all threads
44  * @param timeout The timeout the thread will wait until the corresponding signal will be pulsed, in seconds with range (0, infinity)
45  * @param signal The signal to be used
46  */
47  SignalThread(const HighPerformanceTimer& timer, const double timeout, Signal& signal);
48 
49  private:
50 
51  /**
52  * Thread function.
53  * @see Thread::threadRun().
54  */
55  void threadRun() override;
56 
57  private:
58 
59  /// The timer providing the same time value for all threads.
61 
62  /// Timeout for the thread, in seconds with range (0, infinity)
63  const double timeout_;
64 
65  /// Signal to be used.
67  };
68 
69  /**
70  * This class implements a simple helper thread simulating an async function execution.
71  */
72  class AsyncFunctionThread : public Thread
73  {
74  public:
75 
76  /**
77  * Creates a new thread object and starts the thread.
78  */
80 
81  /**
82  * Destructs the thread object and stops any ongoing async function as fast as possible.
83  */
85 
86  /**
87  * Starts the async function.
88  */
90 
91  private:
92 
93  /**
94  * Thread function.
95  * @see Thread::threadRun().
96  */
97  void threadRun() override;
98 
99  /**
100  * The async function.
101  */
103 
104  private:
105 
106  /// The signal for starting the async function.
108 
109  /// The signal for the finished async function.
111  };
112 
113  public:
114 
115  /**
116  * Tests the entire signal functionalities.
117  * @param testDuration Number of seconds for each test, with range (0, infinity)
118  * @return True, if succeeded
119  */
120  static bool test(const double testDuration);
121 
122  /**
123  * Tests basic signal functions.
124  * @return True, if succeeded
125  */
126  static bool testSignalBasics();
127 
128  /**
129  * Tests one signal without timeout.
130  * @return True, if succeeded
131  */
133 
134  /**
135  * Tests one signal with timeout.
136  * @return True, if succeeded
137  */
138  static bool testSingleSignalTimeout();
139 
140  /**
141  * Tests one signal in a loop.
142  * @return True, if succeeded
143  */
144  static bool testSingleSignalLoop();
145 
146  /**
147  * Tests a pulse, wait, release cycle via an async function execution.
148  * @param testDuration Number of seconds for each test, with range (0, infinity)
149  * @return True, if succeeded
150  */
151  static bool testAsyncFunction(const double testDuration);
152 
153  /**
154  * Tests the set of multiple signals.
155  * @return True, if succeeded
156  */
157  static bool testMultipleSignals();
158 
159  /**
160  * Tests the subset of multiple signals without timeout.
161  * @return True, if succeeded
162  */
164 
165  /**
166  * Tests the subset of multiple signals with timeout.
167  * @return True, if succeeded
168  */
170 };
171 
172 }
173 
174 }
175 
176 }
177 
178 #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:73
~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:110
Signal signalAsyncStart_
The signal for starting the async function.
Definition: TestSignal.h:107
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:38
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:63
void threadRun() override
Thread function.
const HighPerformanceTimer & timer_
The timer providing the same time value for all threads.
Definition: TestSignal.h:60
Signal & signal_
Signal to be used.
Definition: TestSignal.h:66
This class implements signal tests.
Definition: TestSignal.h:31
static bool testSubsetSignalsTimeout()
Tests the subset of multiple signals with timeout.
static bool testMultipleSignals()
Tests the set of multiple signals.
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.
static bool test(const double testDuration)
Tests the entire signal functionalities.
This class implements a thread.
Definition: Thread.h:115
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15