GCC Code Coverage Report


Directory: ./
File: TESTS/TEST_DETACH_POOL/main.cpp
Date: 2025-11-27 16:39:31
Exec Total Coverage
Lines: 66 66 100.0%
Functions: 7 7 100.0%
Branches: 103 103 100.0%

Line Branch Exec Source
1
2 /***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : CeCILL-C
6 ****************************************/
7
8 #include <sstream>
9 #include <iostream>
10 #include "phoenix_assert.h"
11 #include "DetachPool.h"
12
13 ///Check status convert to string
14 1 void checkStatusToString(){
15
6/6
✓ Branch 0 (4→5) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
✓ Branch 4 (10→11) taken 1 times.
✓ Branch 6 (11→12) taken 1 times.
✓ Branch 8 (12→13) taken 1 times.
✓ Branch 10 (13→14) taken 1 times.
6 phoenix_assert(phoenix_statusToString(PEXIT_STATUS_NOT_FIHISHED) == "\033[33mStill Running\033[0m");
16
6/6
✓ Branch 0 (23→24) taken 1 times.
✓ Branch 2 (26→27) taken 1 times.
✓ Branch 4 (29→30) taken 1 times.
✓ Branch 6 (30→31) taken 1 times.
✓ Branch 8 (31→32) taken 1 times.
✓ Branch 10 (32→33) taken 1 times.
6 phoenix_assert(phoenix_statusToString(PEXIT_STATUS_OK) == "\033[32mSUCCESS\033[0m");
17
6/6
✓ Branch 0 (42→43) taken 1 times.
✓ Branch 2 (45→46) taken 1 times.
✓ Branch 4 (48→49) taken 1 times.
✓ Branch 6 (49→50) taken 1 times.
✓ Branch 8 (50→51) taken 1 times.
✓ Branch 10 (51→52) taken 1 times.
6 phoenix_assert(phoenix_statusToString(PEXIT_STATUS_FAIL) == "\033[31mFAIL\033[0m");
18
6/6
✓ Branch 0 (61→62) taken 1 times.
✓ Branch 2 (64→65) taken 1 times.
✓ Branch 4 (67→68) taken 1 times.
✓ Branch 6 (68→69) taken 1 times.
✓ Branch 8 (69→70) taken 1 times.
✓ Branch 10 (70→71) taken 1 times.
5 phoenix_assert(phoenix_statusToString(42) == "\033[31mFAIL\033[0m"); //Any unknown values are considered as fail
19 1 }
20
21 ///Example of thread with perform work
22 /** @param[out] exitStatus : exit status of the current thread
23 * @param workingTime : ellapsed time in second, where the thread will pretend to work
24 */
25 12 void functionInDetachedThread(int & exitStatus, int workingTime){
26 12 sleep(workingTime); //Simulate some computation
27
28 2 exitStatus = PEXIT_STATUS_OK;
29 2 }
30
31 ///Check DetachPool
32 /** @return true on success, false otherwise
33 */
34 1 bool checkDetachPool(){
35 // std::cout << "checkDetachPool : Start" << std::endl;
36
1/1
✓ Branch 0 (2→3) taken 1 times.
1 DetachPool pool;
37
2/2
✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
2 pool.addThread("", functionInDetachedThread, 2);
38
2/2
✓ Branch 0 (20→10) taken 5 times.
✓ Branch 1 (20→21) taken 1 times.
6 for(size_t i(0lu); i < 5; ++i){
39
1/1
✓ Branch 0 (10→11) taken 5 times.
5 std::stringstream threadDescription;
40
2/2
✓ Branch 0 (11→12) taken 5 times.
✓ Branch 2 (12→13) taken 5 times.
5 threadDescription << "Thread " << i;
41
2/2
✓ Branch 0 (13→14) taken 5 times.
✓ Branch 2 (14→15) taken 5 times.
5 pool.addThread(threadDescription.str(), functionInDetachedThread, 2 + i);
42
1/1
✓ Branch 0 (16→17) taken 5 times.
5 usleep(10);
43
1/1
✓ Branch 0 (17→18) taken 5 times.
5 pool.refresh(); //If some thread finish when others are started
44 5 }
45 // std::cerr << "checkDetachPool : let's wait until all threads have finished" << std::endl;
46
1/1
✓ Branch 0 (21→22) taken 1 times.
1 pool.waitUntilAllFinish(100000);
47
1/1
✓ Branch 0 (22→23) taken 1 times.
1 ListThreadDetachInfo listThread = pool.getListThreadInfo();
48
1/1
✓ Branch 0 (23→24) taken 1 times.
1 phoenix_printThreadStatus(listThread);
49 // std::cout << "checkDetachPool : OK" << std::endl;
50 1 return true;
51 1 }
52
53 ///Check DetachPool
54 /** @return true on success, false otherwise
55 */
56 1 bool checkDetachPoolLessWait(){
57 // std::cout << "checkDetachPoolLessWait : Start" << std::endl;
58
1/1
✓ Branch 0 (2→3) taken 1 times.
1 DetachPool pool;
59
2/2
✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
2 pool.addThread("", functionInDetachedThread, 2);
60
2/2
✓ Branch 0 (20→10) taken 5 times.
✓ Branch 1 (20→21) taken 1 times.
6 for(size_t i(0lu); i < 5; ++i){
61
1/1
✓ Branch 0 (10→11) taken 5 times.
5 std::stringstream threadDescription;
62
2/2
✓ Branch 0 (11→12) taken 5 times.
✓ Branch 2 (12→13) taken 5 times.
5 threadDescription << "Thread " << i;
63
2/2
✓ Branch 0 (13→14) taken 5 times.
✓ Branch 2 (14→15) taken 5 times.
5 pool.addThread(threadDescription.str(), functionInDetachedThread, 2 + i);
64
1/1
✓ Branch 0 (16→17) taken 5 times.
5 usleep(10);
65
1/1
✓ Branch 0 (17→18) taken 5 times.
5 pool.refresh(); //If some thread finish when others are started
66 5 }
67 // std::cerr << "checkDetachPoolLessWait : let's wait until all threads have finished (but only 3 seconds)" << std::endl;
68
1/1
✓ Branch 0 (21→22) taken 1 times.
1 pool.waitUntilAllFinish(300000);
69
1/1
✓ Branch 0 (22→23) taken 1 times.
1 ListThreadDetachInfo listThread = pool.getListThreadInfo();
70
1/1
✓ Branch 0 (23→24) taken 1 times.
1 phoenix_printThreadStatus(listThread);
71 // std::cout << "checkDetachPoolLessWait : OK" << std::endl;
72 1 return true;
73 1 }
74
75 ///Check copy of DetachPool
76 1 void testCopyDetachPool(){
77
1/1
✓ Branch 0 (2→3) taken 1 times.
1 DetachPool pool;
78
1/1
✓ Branch 0 (3→4) taken 1 times.
1 pool.setDestructionWaitTime(42);
79
1/1
✓ Branch 0 (4→5) taken 1 times.
1 pool.setRefreshTime(1000);
80
1/1
✓ Branch 0 (5→6) taken 1 times.
1 DetachPool cpyPool(pool);
81
1/1
✓ Branch 0 (6→7) taken 1 times.
1 DetachPool equalPool;
82
1/1
✓ Branch 0 (7→8) taken 1 times.
1 equalPool = pool;
83
6/6
✓ Branch 0 (10→11) taken 1 times.
✓ Branch 2 (13→14) taken 1 times.
✓ Branch 4 (16→17) taken 1 times.
✓ Branch 6 (17→18) taken 1 times.
✓ Branch 8 (18→19) taken 1 times.
✓ Branch 10 (19→20) taken 1 times.
6 phoenix_assert(pool.getDestructorWaitTime() == cpyPool.getDestructorWaitTime());
84
6/6
✓ Branch 0 (28→29) taken 1 times.
✓ Branch 2 (31→32) taken 1 times.
✓ Branch 4 (34→35) taken 1 times.
✓ Branch 6 (35→36) taken 1 times.
✓ Branch 8 (36→37) taken 1 times.
✓ Branch 10 (37→38) taken 1 times.
6 phoenix_assert(pool.getRefreshTime() == cpyPool.getRefreshTime());
85
6/6
✓ Branch 0 (46→47) taken 1 times.
✓ Branch 2 (49→50) taken 1 times.
✓ Branch 4 (52→53) taken 1 times.
✓ Branch 6 (53→54) taken 1 times.
✓ Branch 8 (54→55) taken 1 times.
✓ Branch 10 (55→56) taken 1 times.
6 phoenix_assert(pool.getDestructorWaitTime() == equalPool.getDestructorWaitTime());
86
6/6
✓ Branch 0 (64→65) taken 1 times.
✓ Branch 2 (67→68) taken 1 times.
✓ Branch 4 (70→71) taken 1 times.
✓ Branch 6 (71→72) taken 1 times.
✓ Branch 8 (72→73) taken 1 times.
✓ Branch 10 (73→74) taken 1 times.
5 phoenix_assert(pool.getRefreshTime() == equalPool.getRefreshTime());
87 1 }
88
89 ///Check DetachPool
90 /** @return true on success, false otherwise
91 */
92 1 bool checkDetachPoolEmpty(){
93 // std::cout << "checkDetachPoolEmpty : Start" << std::endl;
94
1/1
✓ Branch 0 (2→3) taken 1 times.
1 DetachPool pool;
95 // std::cerr << "checkDetachPoolEmpty : let's wait until all threads have finished (but only 3 seconds)" << std::endl;
96
1/1
✓ Branch 0 (3→4) taken 1 times.
1 pool.waitUntilAllFinish(300000);
97
1/1
✓ Branch 0 (4→5) taken 1 times.
1 ListThreadDetachInfo listThread = pool.getListThreadInfo();
98
1/1
✓ Branch 0 (5→6) taken 1 times.
1 phoenix_printThreadStatus(listThread);
99 // std::cout << "checkDetachPoolEmpty : OK" << std::endl;
100 1 return true;
101 1 }
102
103 1 int main(int argc, char **argv){
104 1 checkStatusToString();
105
5/5
✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (8→9) taken 1 times.
✓ Branch 4 (11→12) taken 1 times.
✓ Branch 6 (12→13) taken 1 times.
✓ Branch 8 (13→14) taken 1 times.
6 phoenix_assert(checkDetachPool());
106
5/5
✓ Branch 0 (22→23) taken 1 times.
✓ Branch 2 (25→26) taken 1 times.
✓ Branch 4 (28→29) taken 1 times.
✓ Branch 6 (29→30) taken 1 times.
✓ Branch 8 (30→31) taken 1 times.
5 phoenix_assert(checkDetachPoolLessWait());
107 1 testCopyDetachPool();
108
5/5
✓ Branch 0 (40→41) taken 1 times.
✓ Branch 2 (43→44) taken 1 times.
✓ Branch 4 (46→47) taken 1 times.
✓ Branch 6 (47→48) taken 1 times.
✓ Branch 8 (48→49) taken 1 times.
5 phoenix_assert(checkDetachPoolEmpty());
109 1 return 0;
110 }
111
112
113
114
115