SpiecsEngine
 
Loading...
Searching...
No Matches
ThreadPoolFixed_test.h
Go to the documentation of this file.
1/**
2* @file ThreadPoolFixed_test.h.
3* @brief The ThreadPoolFixed_test Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include <gmock/gmock.h>
9#include <Core/Thread/ThreadPoolBasic.h>
10#include "Instrumentor.h"
11
12namespace SpicesTest {
13
14 /**
15 * @brief Test Function Class.
16 */
18 {
19 public:
20
21 /**
22 * @brief Basic Override Class Function.
23 * @return Returns true.
24 */
25 bool Test() { return true; }
26
27 /**
28 * @brief Basic Override Class Function.
29 * @param[in] str In String.
30 * @return Returns In String.
31 */
32 std::string Test(std::string str) { return str; }
33
34 /**
35 * @brief Basic Class Function.
36 * @param[in] a In a.
37 * @param[in] b In b.
38 * @return Returns a + b.
39 */
40 int Test0(int a, int b) { return a + b; }
41
42 /**
43 * @brief Static Class Function.
44 * @return Returns false.
45 */
46 static bool Test1() { return false; }
47 };
48
49 /**
50 * @brief Template Function.
51 * @tparam RType Return type.
52 * @tparam Args any type.
53 */
54 template<typename RType, typename ...Args>
55 RType ThreadPoolTestT(Args&& ...args)
56 {
57 return RType();
58 }
59
60 /**
61 * @brief The interface is inherited from testing::Test.
62 * Registy on Initialize.
63 */
65 {
66 protected:
67
68 /**
69 * @brief The interface is inherited from testing::Test.
70 * Registry on Initialize.
71 */
72 void SetUp() override {
73 m_ThreadPool.SetMode(Spices::PoolMode::MODE_FIXED);
74 m_ThreadPool.Start(nThreads);
75 }
76
78 m_ThreadPool.Wait();
79 }
80
81 /**
82 * @brief ThreadPool.
83 */
84 Spices::ThreadPool m_ThreadPool;
85
86 /**
87 * @brief Number of Threads in ThreadPool.
88 */
89 int nThreads = std::thread::hardware_concurrency();
90 };
91
92 /**
93 * @brief Testing if initialize successfully.
94 */
96
98
99 std::cout << "Hardware threads: " << nThreads << std::endl;
100
101 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
102 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
103 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
104 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
105 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
106 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
107 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
108 }
109
110 /**
111 * @brief Testing if submit different type of function successfully.
112 */
114
116
117 ThreadPoolFuncTest funcTestClass;
118
119 std::future<bool> future0 = m_ThreadPool.SubmitPoolTask(std::bind((bool(ThreadPoolFuncTest::*)())&ThreadPoolFuncTest::Test, &funcTestClass)); /* @brief Override Class Function. */
120 std::future<std::string> future1 = m_ThreadPool.SubmitPoolTask(std::bind((std::string(ThreadPoolFuncTest::*)(std::string))&ThreadPoolFuncTest::Test, &funcTestClass, "Hello")); /* @brief Override Class Function. */
121 std::future<int> future2 = m_ThreadPool.SubmitPoolTask(std::bind(&ThreadPoolFuncTest::Test0, &funcTestClass, 1, 2)); /* @brief Class Function. */
122 std::future<bool> future3 = m_ThreadPool.SubmitPoolTask(std::bind(&ThreadPoolFuncTest::Test1)); /* @brief Static Class Function. */
123 std::future<float> future4 = m_ThreadPool.SubmitPoolTask(std::bind(&ThreadPoolTestT<float, int&, std::string&&>, 2, "")); /* @brief Template Function. */
124
125 std::future<bool> future5 = m_ThreadPool.SubmitPoolTask([&]() { return funcTestClass.Test(); }); /* @brief Lambda Override Class Function. */
126 std::future<std::string> future6 = m_ThreadPool.SubmitPoolTask([&]() { return funcTestClass.Test("Hello"); }); /* @brief Lambda Override Class Function. */
127 std::future<int> future7 = m_ThreadPool.SubmitPoolTask([&]() { return funcTestClass.Test0(1, 2); }); /* @brief Lambda Class Function. */
128 std::future<bool> future8 = m_ThreadPool.SubmitPoolTask([&]() { return ThreadPoolFuncTest::Test1(); }); /* @brief Lambda Static Class Function. */
129 std::future<float> future9 = m_ThreadPool.SubmitPoolTask([&]() { return ThreadPoolTestT<float, int, std::string>(2, ""); }); /* @brief Lambda Template Function. */
130
131 std::future<bool> future10 = m_ThreadPool.SubmitPoolTask([](bool val) { return val; }, true); /* @brief Lambda Function. */
132
133
134 EXPECT_EQ(future0.get(), true );
135 EXPECT_EQ(future1.get(), "Hello" );
136 EXPECT_EQ(future2.get(), 3 );
137 EXPECT_EQ(future3.get(), false );
138 EXPECT_EQ(future4.get(), 0.0f );
139
140 EXPECT_EQ(future5.get(), true );
141 EXPECT_EQ(future6.get(), "Hello" );
142 EXPECT_EQ(future7.get(), 3 );
143 EXPECT_EQ(future8.get(), false );
144 EXPECT_EQ(future9.get(), 0.0f );
145
146 EXPECT_EQ(future10.get(), true );
147 }
148
149 /**
150 * @brief Testing if submit task get correct blocked result successfully.
151 * With profermance test.
152 */
154
156
157 auto func = [](uint32_t a, uint32_t b) -> uint32_t
158 {
159 uint32_t val = 0;
160 for (uint32_t i = a; i < b; i++)
161 {
162 val += i;
163 }
164 return val;
165 };
166
167 auto inTime = std::chrono::high_resolution_clock::now();
168
169 std::future<uint32_t> future0 = m_ThreadPool.SubmitPoolTask(std::bind(func, 0 , 100000000));
170 std::future<uint32_t> future1 = m_ThreadPool.SubmitPoolTask(std::bind(func, 100000000, 200000000));
171 std::future<uint32_t> future2 = m_ThreadPool.SubmitPoolTask(std::bind(func, 200000000, 300000000));
172 std::future<uint32_t> future3 = m_ThreadPool.SubmitPoolTask(std::bind(func, 300000000, 400000000));
173 std::future<uint32_t> future4 = m_ThreadPool.SubmitPoolTask(std::bind(func, 400000000, 500000000));
174
175 const uint32_t subThreadCalVal = future0.get() + future1.get() + future2.get() + future3.get() + future4.get();
176
177 auto multiThreadTime = std::chrono::high_resolution_clock::now();
178
179 std::cout << "Calculate with multiple thread cost: " << std::chrono::duration_cast<std::chrono::milliseconds>(multiThreadTime - inTime).count() << std::endl;
180
181 inTime = std::chrono::high_resolution_clock::now();
182
183 const uint32_t mainThreadCalVal = func(0, 500000000);
184
185 multiThreadTime = std::chrono::high_resolution_clock::now();
186
187 std::cout << "Calculate with main thread cost: " << std::chrono::duration_cast<std::chrono::milliseconds>(multiThreadTime - inTime).count() << std::endl;
188
189 EXPECT_EQ(mainThreadCalVal, subThreadCalVal);
190 }
191
192 /**
193 * @brief Testing if submit one pool task successfully.
194 */
196
198
199 auto func = [](int sec) -> bool
200 {
201 std::this_thread::sleep_for(std::chrono::seconds(sec));
202 return true;
203 };
204
205 std::future<bool> future = m_ThreadPool.SubmitPoolTask(std::bind(func, 2));
206
207 func(1); /* @brief Wait for task execute. */
208
209 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
210 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads - 1 );
211 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
212 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
213 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
214 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
215 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
216
217 m_ThreadPool.Wait(); /* @brief Wait for sub thread finish. */
218
219 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
220 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
221 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
222 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
223 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
224 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
225 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
226 }
227
228 /**
229 * @brief Testing if submit nThreads pool task successfully.
230 */
232
234
235 auto func = [](int sec) -> bool
236 {
237 std::this_thread::sleep_for(std::chrono::seconds(sec));
238 return true;
239 };
240
241 std::vector<std::future<bool>> futures(nThreads);
242 for (int i = 0; i < nThreads; i++)
243 {
244 futures[i] = m_ThreadPool.SubmitPoolTask(std::bind(func, 2));
245 }
246
247 func(1); /* @brief Wait for task execute. */
248
249 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
250 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,0 );
251 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
252 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
253 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
254 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
255 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
256
257 /* @brief Wait for sub thread finish. */
258 m_ThreadPool.Wait();
259
260 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
261 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
262 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
263 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
264 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
265 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
266 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
267 }
268
269 /**
270 * @brief Testing if submit 2 nThreads pool task successfully.
271 */
273
275
276 auto func = [](int sec) -> bool
277 {
278 std::this_thread::sleep_for(std::chrono::seconds(sec));
279 return true;
280 };
281
282 std::vector<std::future<bool>> futures(2 * nThreads);
283 for (int i = 0; i < 2 * nThreads; i++)
284 {
285 futures[i] = m_ThreadPool.SubmitPoolTask(std::bind(func, 2));
286 }
287
288 func(1); /* @brief Wait for task execute. */
289
290 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
291 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,0 );
292 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
293 EXPECT_EQ(m_ThreadPool.GetTasks() ,nThreads );
294 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
295 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
296 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
297
298 func(2); /* @brief Wait for part tasks finish. */
299
300 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
301 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,0 );
302 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
303 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
304 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
305 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
306 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
307
308 /* @brief Wait for sub thread finish. */
309 m_ThreadPool.Wait();
310
311 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
312 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
313 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
314 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
315 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
316 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
317 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
318 }
319
320 /**
321 * @brief Testing if submit very much pool task successfully.
322 */
324
326
327 auto func = [](int sec) -> bool
328 {
329 std::this_thread::sleep_for(std::chrono::microseconds(sec));
330 return true;
331 };
332
333 std::vector<std::future<bool>> futures(10000);
334 for (int i = 0; i < 10000; i++)
335 {
336 futures[i] = m_ThreadPool.SubmitPoolTask(std::bind(func, 1));
337 }
338
339 /* @brief Wait for subthread finish. */
340 m_ThreadPool.Wait();
341
342 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
343 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
344 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
345 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
346 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
347 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
348 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
349 }
350
351 /**
352 * @brief Testing if submit one thread task successfully.
353 */
355
357
358 auto func = []() -> void
359 {
360 std::this_thread::sleep_for(std::chrono::seconds(2));
361 };
362
363 m_ThreadPool.SubmitThreadTask_LightWeight(0, func);
364
365 /* @brief Wait for all tasks finish. */
366 m_ThreadPool.Wait();
367
368 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
369 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
370 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
371 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
372 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
373 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
374 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
375
376 for (auto& pair : m_ThreadPool.GetThreads())
377 {
378 EXPECT_EQ(pair.second->GetThreadTasksCount(),0);
379 }
380 }
381
382 /**
383 * @brief Testing if submit thread task for each successfully.
384 */
386
388
389 auto func = []() -> void
390 {
391 std::this_thread::sleep_for(std::chrono::seconds(2));
392 };
393
394 m_ThreadPool.SubmitThreadTask_LightWeight_ForEach(func);
395
396 /* @brief Wait for all tasks finish. */
397 m_ThreadPool.Wait();
398
399 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
400 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
401 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
402 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
403 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
404 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
405 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
406
407 for (auto& pair : m_ThreadPool.GetThreads())
408 {
409 EXPECT_EQ(pair.second->GetThreadTasksCount(),0);
410 }
411 }
412
413 /**
414 * @brief Testing if submit thread task for each twice successfully.
415 */
417
419
420 auto func = []() -> void
421 {
422 std::this_thread::sleep_for(std::chrono::seconds(1));
423 };
424
425 m_ThreadPool.SubmitThreadTask_LightWeight_ForEach(func);
426 m_ThreadPool.SubmitThreadTask_LightWeight_ForEach(func);
427
428 /* @brief Wait for all tasks finish. */
429 m_ThreadPool.Wait();
430
431 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
432 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
433 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
434 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
435 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
436 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
437 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
438
439 for (auto& pair : m_ThreadPool.GetThreads())
440 {
441 EXPECT_EQ(pair.second->GetThreadTasksCount(),0);
442 }
443 }
444
445 /**
446 * @brief Testing if submit very much thread task successfully.
447 */
449
451
452 auto func = []() -> void
453 {
454 std::this_thread::sleep_for(std::chrono::microseconds(1));
455 };
456
457 for (int i = 0; i < 2000; i++)
458 {
459 m_ThreadPool.SubmitThreadTask_LightWeight_ForEach(func);
460 }
461
462 /* @brief Wait for all tasks finish. */
463 m_ThreadPool.Wait();
464
465 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
466 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
467 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
468 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
469 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
470 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
471 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
472
473 for (auto& pair : m_ThreadPool.GetThreads())
474 {
475 EXPECT_EQ(pair.second->GetThreadTasksCount(),0);
476 }
477 }
478
479 /**
480 * @brief Testing if submit very much mixed task successfully.
481 */
483
485
486 auto func = []() -> void
487 {
488 std::this_thread::sleep_for(std::chrono::microseconds(1));
489 };
490
491 for (int i = 0; i < 5000; i++)
492 {
493 m_ThreadPool.SubmitPoolTask(func);
494 }
495
496 for (int i = 0; i < 1000; i++)
497 {
498 m_ThreadPool.SubmitThreadTask_LightWeight_ForEach(func);
499 }
500
501 /* @brief Wait for all tasks finish. */
502 m_ThreadPool.Wait();
503
504 EXPECT_EQ(m_ThreadPool.GetInitThreadSize() ,nThreads );
505 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize() ,nThreads );
506 EXPECT_EQ(m_ThreadPool.GetPoolMode() ,Spices::PoolMode::MODE_FIXED );
507 EXPECT_EQ(m_ThreadPool.GetTasks() ,0 );
508 EXPECT_EQ(m_ThreadPool.GetThreadsCount() ,nThreads );
509 EXPECT_EQ(m_ThreadPool.GetThreadIdleTimeOut(),Spices::THREAD_MAX_IDLE_TIME );
510 EXPECT_EQ(m_ThreadPool.IsPoolRunning() ,true );
511
512 for (auto& pair : m_ThreadPool.GetThreads())
513 {
514 EXPECT_EQ(pair.second->GetThreadTasksCount(),0);
515 }
516 }
517
518 /**
519 * @brief Testing Continue/Suspend API.
520 */
522
524
525 m_ThreadPool.Suspend();
526
527 std::atomic_int executeCount;
528
529 {
530 SPICESTEST_PROFILE_SCOPE("Quick Task");
531
532 for (int i = 0; i < 10; i++)
533 {
534 m_ThreadPool.SubmitPoolTask([&]() {
535 ++executeCount;
536 });
537 }
538
539 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), nThreads);
540 EXPECT_EQ(m_ThreadPool.GetTasks(), 10);
541
542 m_ThreadPool.Continue();
543
544 m_ThreadPool.Wait();
545 m_ThreadPool.Suspend();
546
547 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), nThreads);
548 EXPECT_EQ(m_ThreadPool.GetTasks(), 0);
549 EXPECT_EQ(executeCount.load(), 10);
550 }
551
552 {
553 SPICESTEST_PROFILE_SCOPE("Slow Task");
554
555 for (int i = 0; i < 30; i++)
556 {
557 m_ThreadPool.SubmitPoolTask([&]() {
558 std::this_thread::sleep_for(std::chrono::seconds(2));
559 ++executeCount;
560 });
561 }
562
563 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), nThreads);
564 EXPECT_EQ(m_ThreadPool.GetTasks(), 30);
565
566 m_ThreadPool.Continue();
567 std::this_thread::sleep_for(std::chrono::seconds(1));
568 m_ThreadPool.Suspend();
569 std::this_thread::sleep_for(std::chrono::seconds(2));
570
571 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), nThreads);
572 EXPECT_EQ(m_ThreadPool.GetTasks(), 30 - nThreads);
573 EXPECT_EQ(executeCount.load(), 10 + nThreads);
574
575 m_ThreadPool.Continue();
576 m_ThreadPool.Wait();
577
578 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), nThreads);
579 EXPECT_EQ(m_ThreadPool.GetTasks(), 0);
580 EXPECT_EQ(executeCount.load(), 40);
581 }
582 }
583}
#define UPROPERTYS(...)
#define UCONSTRUCT(T, N)
#define UPROPERTY(N)
#define UFUNCTION(N)
#define UFUNCTION_T(T, N)
#define END_CLASS
#define UFUNCTIONS(...)
#define UDECONSTRUCT(T, N)
#define UPROPERTY_S(N)
#define UCLASS()
Definition ClassTraits.h:31
#define CLASS_SCOPE
#define DELEGATE_ONE_PARAM(name, p0)
Use this macro to instance a Delegate Class. One Parameter Specific.
#define DELEGATE_THREE_PARAM(name, p0, p1, p2)
Use this macro to instance a Delegate Class. Three Parameter Specific.
#define DELEGATE_SIX_PARAM(name, p0, p1, p2, p3, p4, p5)
Use this macro to instance a Delegate Class. Six Parameter Specific.
#define DELEGATE_FIVE_PARAM(name, p0, p1, p2, p3, p4)
Use this macro to instance a Delegate Class. Five Parameter Specific.
#define DELEGATE_NONE_PARAM(name)
Use this macro to instance a Delegate Class. None Parameter Specific.
#define DELEGATE_SEVEN_PARAM(name, p0, p1, p2, p3, p4, p5, p6)
Use this macro to instance a Delegate Class. Seven Parameter Specific.
#define DELEGATE_EIGHT_PARAM(name, p0, p1, p2, p3, p4, p5, p6, p7)
Use this macro to instance a Delegate Class. Eight Parameter Specific.
#define DELEGATE_TWO_PARAM(name, p0, p1)
Use this macro to instance a Delegate Class. Two Parameter Specific.
#define DELEGATE_FOUR_PARAM(name, p0, p1, p2, p3)
Use this macro to instance a Delegate Class. Four Parameter Specific.
#define DELEGATE_NINE_PARAM(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)
Use this macro to instance a Delegate Class. Nine Parameter Specific.
#define SPICES_FUNC_SIG
#define SPICESTEST_PROFILE_SCOPE_LINE2(name, line)
#define SPICESTEST_PROFILE_SCOPE(name)
#define SPICES_PROFILE
#define SPICESTEST_PROFILE_END_SESSION()
#define SPICESTEST_PROFILE_BEGIN_SESSION(name, filepath)
#define SPICESTEST_PROFILE_SCOPE_LINE(name, line)
#define SPICESTEST_PROFILE_FUNCTION()
#define SPICES_PROFILE_ZONE
void Test0(int a, int b)
Basic Class Function.
void Test(float f)
Basic Override Class Function.
void Test()
Basic Override Class Function.
static void Test1()
Static Class Function.
Test Function Class.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
void TearDown() override
Testing class TearDown function.
Instance Delegate Class.
bool b(int q, float w) const
static bool c(int q, float w)
const volatile std::string m_Name_b
FieldTraitsTest(const std::string &name)
static bool sf(int a, float b, void *c)
bool fc(int a, float b, void *c) const
auto GetFResult(T &&func, Args &&... args) -> decltype(func(std::forward< Args >(args)...))
InstrumentationTimer(const char *name)
std::chrono::time_point< std::chrono::steady_clock > m_StartTimepoint
Instrumentor(Instrumentor &&)=delete
static Instrumentor & Get()
void BeginSession(const std::string &name, const std::string &filepath="results.json")
void WriteProfile(const ProfileResult &result)
InstrumentationSession * m_CurrentSession
std::ofstream m_OutputStream
Instrumentor(const Instrumentor &)=delete
MemoryPoolTest2(const MemoryPoolTest2 &)=delete
MemoryPoolTest2 & operator=(const MemoryPoolTest2 &)=delete
static constexpr size_t y
std::array< std::array< int, x >, y > datas
static constexpr size_t x
MemoryPoolTest(const MemoryPoolTest &)=delete
MemoryPoolTest & operator=(const MemoryPoolTest &)=delete
std::tuple< int, float, void * > m_Tuple
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
static constexpr size_t n2
Iter counts 2.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
static constexpr size_t n
Iter counts.
The interface is inherited from testing::Test. Registry on Initialize.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
std::unique_ptr< Spices::ObjectPool< Object > > m_ObjectPool
ObjectPool.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
static constexpr size_t n
ObjectPool objects number.
The interface is inherited from testing::Test. Registry on Initialize.
virtual ~Object()=default
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
Spices::PageCache pc
PageCache.
static constexpr size_t n
Test iter number.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
The interface is inherited from testing::Test. Registry on Initialize.
Declare Empty Class.
ThreadCacheTest & operator=(const ThreadCacheTest &)=delete
std::tuple< int, float, void * > m_Tuple
ThreadCacheTest(const ThreadCacheTest &)=delete
static constexpr size_t n
Iter counts.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
Spices::ThreadCache tc
ThreadCache.
The interface is inherited from testing::Test. Registry on Initialize.
int nThreads
Number of Threads in ThreadPool.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
Spices::ThreadPool m_ThreadPool
ThreadPool.
The interface is inherited from testing::Test. Registy on Initialize.
std::string Test(std::string str)
Basic Override Class Function.
static bool Test1()
Static Class Function.
int Test0(int a, int b)
Basic Class Function.
bool Test()
Basic Override Class Function.
void Test(float f)
Basic Override Class Function.
void Test()
Basic Override Class Function.
void TearDown() override
Testing class TearDown function.
std::vector< scl::directed_acyclic_node > m_Nodes
void SetUp() override
Testing class initialize function.
The interface is inherited from testing::Test. Registy on Initialize.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
The interface is inherited from testing::Test. Registry on Initialize.
scl::kd_tree< 2 > m_KDTree
Create a KDTree with 2 dimensions.
Definition KDTree_test.h:57
void TearDown() override
Testing class TearDown function.
Definition KDTree_test.h:52
void SetUp() override
Testing class initialize function.
Definition KDTree_test.h:27
The interface is inherited from testing::Test. Registry on Initialize.
Definition KDTree_test.h:21
scl::linked_unordered_map< int, std::string > c1
scl::linked_unordered_map< float, std::string > c2
scl::linked_unordered_map< std::string, std::string > c0
void SetUp() override
Testing class initialize function.
void TearDown() override
Testing class TearDown function.
The interface is inherited from testing::Test. Registry on Initialize.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
void TearDown() override
Testing class TearDown function.
Unit Test for RuntimeMemoryBlock.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
The interface is inherited from testing::Test. Registry on Initialize.
static std::string GetClassString(ClassType t)
Get Class Name as string.
Class Static Function Library.
virtual ~ClassTraitsTest()=default
bool f(int q, float w, void *c, bool(ClassTraitsTest::*)(int **, int &&))
std::reference_wrapper< const int > cir
bool f(int q, float w)
std::reference_wrapper< int * > ipr
std::reference_wrapper< const int * > cipr
std::reference_wrapper< const int const *const > cicpcr
bool fc(int q, float w) const
static bool fs(int q, float w)
auto mfc(F func, Args ...args) -> decltype(f(std::forward< Args >(args)...))
std::reference_wrapper< int > ir
static bool FileLibrary_Size(const FileHandle *handle, uint64_t *out_size)
Calculate The file size.
static bool FileLibrary_Read(const FileHandle *handle, uint64_t data_size, void *out_data, uint64_t *out_bytes_read)
Read Specific size of data form the current file handle pointer, and move pointer the same size.
static bool FileLibrary_Write_Line(const FileHandle *handle, const char *text)
Write one line data to the file handle pointer.
static bool FileLibrary_Write(const FileHandle *handle, uint64_t data_size, const void *data, uint64_t *out_bytes_written)
Write given data to the file handle pointer.
static bool FileLibrary_Open(const char *path, FileModes mode, bool binary, FileHandle *out_handle)
Open the file using given string.
static void FileLibrary_Close(FileHandle *handle)
Close the file by the file handle.
static bool FileLibrary_Delete(const char *filePath)
Delete a file from disk.
static bool FileLibrary_CopyFile(std::string srcFilePath, std::string dstFilePath)
Copy a file to dst path.
static bool FileLibrary_Read_Line(const FileHandle *handle, uint64_t max_length, char *line_buf, uint64_t *out_line_length)
Read one line from the current file handle pointer, and move pointer the same size.
static bool FileLibrary_Exists(const char *path)
Determine whether the given string is existing a file.
static bool FileLibrary_Read_all_bytes(const FileHandle *handle, char *out_bytes, uint64_t *out_bytes_read)
Read all data form the current file handle pointer.
File Static Function Library.
Definition FileLibrary.h:49
static void Init()
Init Log.
Definition Log.cpp:24
static void ShutDown()
Shutdown Log.
Definition Log.cpp:82
static void Free(void *ptr)
Free memory entry point.
static void *& PointerSpace(void *obj)
Get object first 4/8 bytes as a pointer.
MemoryPool Class.
Definition MemoryPool.h:22
Page memory cache. Third level of memory allocator.
Definition PageCache.h:21
static bool CloseProcess(const char *processName)
Close a Process with command.
static bool OpenProcess(const char *processPath, const char *commandLine="")
Open a Process with command.
static float ProcessMemoryInUsed()
Get this Process Memory used( GB ).
Process Static Function Library.
static bool StringsEqual(const char *str0, const char *str1)
Determine if the strings given are equal. Platform Specific.
String Static Function Library.
Thread memory cache. First level of memory allocator.
Definition ThrealCache.h:19
static bool SetThreadName(const std::string &name)
Set Thread name.
Thread Static Function Library.
behave_state_list. wrapper of combing all state behaves.
bool Empty() const
Determine if this list is empty.
Definition FreeList.h:50
void Push(void *obj)
Recycle a object memory to this free list.
Definition FreeList.cpp:13
void *& Begin()
Get current pointer (no const & reference version).
Definition FreeList.h:94
void *& End()
Get end pointer (no const & reference version).
Definition FreeList.h:100
Free list for memory pool.
Definition FreeList.h:16
The kd_tree with K dimensions container Class. K the number of dimensions. Every node in the tree is ...
Definition KDTree.h:27
The container combines hashmap and list together. Used in the case that we want iter a hashmap in ord...
void build()
Malloc a memory to begin_.
void add_element(const std::string &name, const std::string &type)
Add a element to object_, means a memory block will be occupied with given param type.
runtime_memory_block()=default
Constructor Function.
void * get_addr() const
Get the begin_.
The container is wrapper of a continue memory block. Used in Material::BuildMaterial(),...
Bidirectional cyclic linked list for span.
Definition SpanList.h:73
span * m_Next
next span.
Definition SpanList.h:41
span * m_Prev
previous span.
Definition SpanList.h:46
Used for manage multiple page memory.
Definition SpanList.h:15
simple tree.
Definition Tree.h:18
This Class is similar to std::vector, the difference between that is this one allocates memory by mal...
Definition Vector.h:18
int main(int argc, char **argv)
The Entry of SpicesTest.
Definition main.cpp:76
static bool sf(int a, float b, void *c)
constexpr auto CleanupOutputString(const char(&expr)[N], const char(&remove)[K])
TEST_F(free_list_test, PushPop)
Testing scl::free_list::Push/Pop.
TEST_F(runtime_memory_block_test, Initialize)
Testing if initialize successfully.
TEST_F(directed_acyclic_graph_test, Addnode)
Testing if add node successfully.
TEST_F(ThreadPoolFixed_test, Initialize)
Testing if initialize successfully.
TEST_F(span_list_test, Initialize)
Testing scl::span_list::Initialize.
TEST_F(linked_unordered_map_test, Initialize)
Testing if initialize successfully.
TEST_F(kd_tree_test, Insert)
Testing if Insert successfully.
Definition KDTree_test.h:63
void DelegateTestT(Args ...args)
Template Function.
TEST_F(MemoryPool_test, PointerSpace)
Testing Spices::MemoryPool::PointerSpace.
TEST(tuple_test, IterTuple)
Testing std::tuple Helper Function.
Definition Tuple_test.h:17
RType ThreadPoolTestT(Args &&...args)
Template Function.
TEST_F(ObjectPool_test, Initialize)
Testing Spices::ObjectPool::Initialize.
TEST_F(Delegate_test, Bind)
Testing if bind successfully.
TEST_F(ThreadCache_test, AllocateDeallocate)
Testing Spices::ThreadCache::Allocate/Deallocate.
TEST_F(PageCache_test, NewSpan)
Testing Spices::PageCache::NewSpan.
constexpr bool is_pointer_v< _Ty *const volatile >
Definition IsPointer.h:27
Spices::ClassTraitsTest inst
constexpr bool is_pointer_v< _Ty *const >
Definition IsPointer.h:21
const int * ecip
constexpr bool is_const_v
value of is_const.
Definition IsConst.h:100
ClassItemType
class property/function type.
Definition ClassTraits.h:19
constexpr bool is_pointer_v< _Ty * >
Definition IsPointer.h:18
constexpr bool is_pointer_v< _Ty *volatile >
Definition IsPointer.h:24
FileModes
file mode
Definition FileLibrary.h:32
@ FILE_MODE_READ
model : read
Definition FileLibrary.h:37
@ FILE_MODE_WRITE
model : write
Definition FileLibrary.h:42
constexpr bool is_pointer_v
Declare of is_pointer.
Definition IsPointer.h:15
void IterTuple(Tuple &tuple, Function &&f)
Iter a tuple.
Definition Tuple.h:34
std::thread::id ThreadID
std::chrono::microseconds ElapsedTime
FloatingPointMicroseconds Start
static constexpr bool value
static constexpr bool value
void * handle
FILE* handle. Need cast while use.
Definition FileLibrary.h:21
bool is_valid
Is this handle Valid.
Definition FileLibrary.h:26
This Struct is FILE* handle pointer Wrapper.
Definition FileLibrary.h:15
bool operator==(const String2 &other) const
equal operation.
Definition Math.h:88
double string
Definition Math.h:63
bool operator==(const UInt2 &other) const
equal operation.
Definition Math.h:42
UInt2(const uint32_t &x, const uint32_t &y)
Constructor Function.
Definition Math.h:30
double unsigned int
Definition Math.h:17
constexpr bool is_variable() const
Definition FieldTraits.h:83
constexpr bool is_function() const
Definition FieldTraits.h:78
constexpr bool is_variable() const
Definition FieldTraits.h:48
constexpr bool is_member() const
Definition FieldTraits.h:33
constexpr bool is_function() const
Definition FieldTraits.h:43
constexpr bool is_const() const
Definition FieldTraits.h:38
constexpr size_t param_count() const
Definition FieldTraits.h:53
static constexpr bool value
Definition IsConst.h:52
is_const remove pointer from type.
Definition IsConst.h:51
is_const remove reference(both pointer) from type. For reference and pointer can be mixed together.
Definition IsConst.h:62
static constexpr bool value
Definition IsConst.h:31
static constexpr bool value
Definition IsConst.h:21
Declare of is_const.
Definition IsConst.h:20
Store Non Member Variable Type.
T pointer
Field pointer.
std::string_view name
Field Name.
size_t offset
Field offset.
constexpr field_traits(T &&p, std::string_view n, size_t offset=0)
Definition FieldTraits.h:96
Field Traits template.
Definition FieldTraits.h:95
Collection of Type and Class.
is_const process pointer or reference.
Definition IsConst.h:93
Container of store Types.
Definition TypeList.h:20