Ocean
TestThreadPool.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_THREAD_POOL_H
9 #define META_OCEAN_TEST_TESTBASE_TEST_THREAD_POOL_H
10 
12 
13 #include "ocean/base/Lock.h"
14 #include "ocean/base/Singleton.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Test
20 {
21 
22 namespace TestBase
23 {
24 
25 /**
26  * This class implements tests for the ThreadPool class.
27  * @ingroup testbase
28  */
29 class OCEAN_TEST_BASE_EXPORT TestThreadPool
30 {
31  protected:
32 
33  /**
34  * This class implements a helper class allowing to keep track of function executions.
35  */
36  class Executions : public Singleton<Executions>
37  {
38  public:
39 
40  /**
41  * Adds a new id.
42  * @param id The id to add
43  */
44  void addId(const unsigned int id);
45 
46  /**
47  * Returns the added ids.
48  * @return The singleton's ids
49  */
51 
52  /**
53  * Returns whether at least one id exists.
54  * @return True, if so
55  */
56  bool hasId() const;
57 
58  /**
59  * Clears all ids.
60  */
61  void clear();
62 
63  protected:
64 
65  /// The ids.
67 
68  /// The singleton's lock.
69  mutable Lock lock_;
70  };
71 
72  public:
73 
74  /**
75  * Tests all TestThreadPool functions.
76  * @param testDuration Number of seconds for each test, with range (0, infinity)
77  * @return True, if succeeded
78  */
79  static bool test(const double testDuration);
80 
81  /**
82  * Tests to invoke several functions.
83  * @param testDuration Number of seconds for the test, with range (0, infinity)
84  * @return True, if succeeded
85  */
86  static bool testInvokeFunctions(const double testDuration);
87 };
88 
89 }
90 
91 }
92 
93 }
94 
95 #endif // META_OCEAN_TEST_TESTBASE_TEST_WORKER_POOL_H
This class implements a recursive lock object.
Definition: Lock.h:31
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
This class implements a helper class allowing to keep track of function executions.
Definition: TestThreadPool.h:37
void addId(const unsigned int id)
Adds a new id.
bool hasId() const
Returns whether at least one id exists.
Lock lock_
The singleton's lock.
Definition: TestThreadPool.h:69
UnorderedIndexSet32 ids_
The ids.
Definition: TestThreadPool.h:66
UnorderedIndexSet32 ids() const
Returns the added ids.
This class implements tests for the ThreadPool class.
Definition: TestThreadPool.h:30
static bool testInvokeFunctions(const double testDuration)
Tests to invoke several functions.
static bool test(const double testDuration)
Tests all TestThreadPool functions.
std::unordered_set< Index32 > UnorderedIndexSet32
Definition of an unordered_set holding 32 bit indices.
Definition: Base.h:126
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15