Ocean
TestWorker.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_WORKER_H
9 #define META_OCEAN_TEST_TESTBASE_WORKER_H
10 
12 
13 #include "ocean/base/Worker.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Test
19 {
20 
21 namespace TestBase
22 {
23 
24 /**
25  * This class implements worker tests.
26  * @ingroup testbase
27  */
28 class OCEAN_TEST_BASE_EXPORT TestWorker : protected Worker
29 {
30  public:
31 
32  /**
33  * Tests the entire worker functionalities.
34  * @param testDuration The number of seconds for each test, with range (0, infinity)
35  * @return True, if succeeded
36  */
37  static bool test(const double testDuration);
38 
39  /**
40  * Tests the constructor.
41  * @return True, if succeeded
42  */
43  static bool testConstructor();
44 
45  /**
46  * Tests the worker delay.
47  * @param testDuration The number of seconds for each test, with range (0, infinity)
48  * @param worker The worker object to be used
49  * @return True, if succeeded
50  */
51  static bool testDelay(const double testDuration, Worker& worker);
52 
53  /**
54  * Tests the worker calling a static function.
55  * @param worker The worker object to be used
56  * @return True, if succeeded
57  */
58  static bool testStaticWorker(Worker& worker);
59 
60  /**
61  * Tests the validation of the worker calling a static function.
62  * @param testDuration The number of seconds for each test, with range (0, infinity)
63  * @param worker The worker object to be used
64  * @return True, if succeeded
65  */
66  static bool testStaticWorkerSumOfSquares(const double testDuration, Worker& worker);
67 
68  /**
69  * Tests the validation of the worker calling a static function.
70  * @param testDuration The number of seconds for each test, with range (0, infinity)
71  * @param worker The worker object to be used
72  * @return True, if succeeded
73  */
74  static bool testStaticWorkerSumOfSquareRoots(const double testDuration, Worker& worker);
75 
76  /**
77  * Tests the validation of the worker calling a static abortable function.
78  * @param worker The worker object to be used
79  * @return True, if succeeded
80  */
81  static bool testAbortableFunction(Worker& worker);
82 
83  /**
84  * Tests the validation of the worker calling a static separable and abortable function.
85  * @param worker The worker object to be used
86  * @return True, if succeeded
87  */
89 
90  private:
91 
92  /**
93  * Static worker function.
94  * @param time The time parameters, must be valid
95  * @param first The first element
96  * @param size The number of elements, with range [1, infinity)
97  */
98  static void staticWorkerFunctionDelay(uint64_t* time, const unsigned int first, const unsigned int size);
99 
100  /**
101  * Static worker function.
102  * @param first The first element
103  * @param size The number of elements, with range [1, infinity)
104  */
105  static void staticWorkerFunction(const unsigned int first, const unsigned int size);
106 
107  /**
108  * Static worker function to calculate the sum of square values.
109  * @param values The values to be handled, must be valid
110  * @param first The first element
111  * @param size The number of elements, with range [1, infinity)
112  */
113  static void staticWorkerFunctionSumOfSquares(unsigned int* values, const unsigned int first, const unsigned int size);
114 
115  /**
116  * Static worker function to calculate the sum of square root values.
117  * @param values The values to be handled, must be valid
118  * @param first The first element
119  * @param size The number of elements, with range [1, infinity)
120  */
121  static void staticWorkerFunctionSumOfSquareRoots(double* values, const unsigned int first, const unsigned int size);
122 
123  /**
124  * Static abortable worker function.
125  * @param result Function result
126  * @param abort The abort state
127  * @return True, if succeeded and not aborted
128  */
129  static bool staticWorkerFunctionAbortable(double* result, bool* abort);
130 
131  /**
132  * Static separable and abortable worker function.
133  * @param result Function result
134  * @param first The first object to be handled
135  * @param size Number of objects to be handled
136  * @param abort The abort state
137  * @return True, if succeeded and not aborted
138  */
139  static bool staticWorkerFunctionSeparableAndAbortable(double* result, const unsigned int first, const unsigned int size, bool* abort);
140 };
141 
142 }
143 
144 }
145 
146 }
147 
148 #endif // META_OCEAN_TEST_TESTBASE_WORKER_H
This class implements worker tests.
Definition: TestWorker.h:29
static bool testConstructor()
Tests the constructor.
static bool staticWorkerFunctionAbortable(double *result, bool *abort)
Static abortable worker function.
static bool staticWorkerFunctionSeparableAndAbortable(double *result, const unsigned int first, const unsigned int size, bool *abort)
Static separable and abortable worker function.
static bool testStaticWorkerSumOfSquareRoots(const double testDuration, Worker &worker)
Tests the validation of the worker calling a static function.
static bool testStaticWorker(Worker &worker)
Tests the worker calling a static function.
static void staticWorkerFunctionDelay(uint64_t *time, const unsigned int first, const unsigned int size)
Static worker function.
static bool test(const double testDuration)
Tests the entire worker functionalities.
static void staticWorkerFunctionSumOfSquareRoots(double *values, const unsigned int first, const unsigned int size)
Static worker function to calculate the sum of square root values.
static bool testStaticWorkerSumOfSquares(const double testDuration, Worker &worker)
Tests the validation of the worker calling a static function.
static bool testDelay(const double testDuration, Worker &worker)
Tests the worker delay.
static void staticWorkerFunction(const unsigned int first, const unsigned int size)
Static worker function.
static bool testSeparableAndAbortableFunction(Worker &worker)
Tests the validation of the worker calling a static separable and abortable function.
static bool testAbortableFunction(Worker &worker)
Tests the validation of the worker calling a static abortable function.
static void staticWorkerFunctionSumOfSquares(unsigned int *values, const unsigned int first, const unsigned int size)
Static worker function to calculate the sum of square values.
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15