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