GCC Code Coverage Report


Directory: ./
File: TESTS/TEST_GENERIC_CLOCK/main.cpp
Date: 2026-01-26 14:45:44
Exec Total Coverage
Lines: 35 35 100.0%
Functions: 5 5 100.0%
Branches: 50 50 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 <unistd.h>
9 #include <iomanip>
10 #include <iostream>
11 #include "data_stream_assert.h"
12 #include "phoenix_clock.h"
13 #include "PClockNs.h"
14
15 ///Definition of the test clock
16 typedef PGenericClock<PClockBackend, PClockMock> ClockSecond;
17
18 ///Definition of the test clock for more precise time
19 typedef PGenericClock<PClockNs, PClockMock> ClockNanoSecond;
20
21 ///Create a ClockMock ready to use
22 2 void testCreateClockMock(){
23
2/2
✓ Branch 0 (4→5) taken 2 times.
✓ Branch 2 (5→6) taken 2 times.
4 phoenix_createClockMock("", 3lu);
24
2/2
✓ Branch 0 (10→11) taken 2 times.
✓ Branch 2 (11→12) taken 2 times.
2 phoenix_createClockMock("long_clock_", 2000lu);
25 2 }
26
27 template<class _Clock>
28 2 void testSpecialisedClock(){
29
1/1
✓ Branch 0 (2→3) taken 2 times.
2 testCreateClockMock();
30
1/1
✓ Branch 0 (3→4) taken 2 times.
2 _Clock clock;
31
2/2
✓ Branch 0 (6→7) taken 2 times.
✓ Branch 2 (7→8) taken 2 times.
2 clock.setMockPrefix("");
32 //Let's try in normal mode
33 2 clock.setMode(PClockMode::NO_MOCK);
34
5/5
✓ Branch 0 (13→14) taken 2 times.
✓ Branch 2 (16→17) taken 2 times.
✓ Branch 4 (19→20) taken 2 times.
✓ Branch 6 (20→21) taken 2 times.
✓ Branch 8 (21→22) taken 2 times.
10 data_stream_assert(clock.now() != 0l);
35 //Let's play the mock clock
36 2 clock.setMode(PClockMode::MOCK);
37
5/5
✓ Branch 0 (31→32) taken 2 times.
✓ Branch 2 (34→35) taken 2 times.
✓ Branch 4 (37→38) taken 2 times.
✓ Branch 6 (38→39) taken 2 times.
✓ Branch 8 (39→40) taken 2 times.
12 data_stream_assert(clock.now() == 0l);
38
5/5
✓ Branch 0 (48→49) taken 2 times.
✓ Branch 2 (51→52) taken 2 times.
✓ Branch 4 (54→55) taken 2 times.
✓ Branch 6 (55→56) taken 2 times.
✓ Branch 8 (56→57) taken 2 times.
12 data_stream_assert(clock.now() == 1l);
39
5/5
✓ Branch 0 (65→66) taken 2 times.
✓ Branch 2 (68→69) taken 2 times.
✓ Branch 4 (71→72) taken 2 times.
✓ Branch 6 (72→73) taken 2 times.
✓ Branch 8 (73→74) taken 2 times.
12 data_stream_assert(clock.now() == 2l);
40
5/5
✓ Branch 0 (82→83) taken 2 times.
✓ Branch 2 (85→86) taken 2 times.
✓ Branch 4 (88→89) taken 2 times.
✓ Branch 6 (89→90) taken 2 times.
✓ Branch 8 (90→91) taken 2 times.
10 data_stream_assert(clock.now() == 0l);
41
1/1
✓ Branch 0 (97→98) taken 2 times.
2 clock.sleep(1000l); //Sleep for 1 microsecond
42 //Let's record the real clock
43 2 clock.setMode(PClockMode::MOCK_RECORD);
44
1/1
✓ Branch 0 (99→100) taken 2 times.
2 clock.sleep(1000l); //Sleep for 1 microsecond
45
1/1
✓ Branch 0 (100→101) taken 2 times.
2 time_t nowValue = clock.now();
46
4/4
✓ Branch 0 (103→104) taken 2 times.
✓ Branch 2 (106→107) taken 2 times.
✓ Branch 4 (109→110) taken 2 times.
✓ Branch 6 (110→111) taken 2 times.
10 data_stream_assert(nowValue != 0l);
47 //Let's replay the real clock
48 2 clock.setMode(PClockMode::MOCK);
49
1/1
✓ Branch 0 (118→119) taken 2 times.
2 clock.resetMockIndex();
50
1/1
✓ Branch 0 (119→120) taken 2 times.
2 clock.now(); //Skip first value (0)
51
1/1
✓ Branch 0 (120→121) taken 2 times.
2 clock.now(); //Skip second value (1)
52
1/1
✓ Branch 0 (121→122) taken 2 times.
2 clock.now(); //Skip third value (2)
53 // Last value should be the recorded one
54
5/5
✓ Branch 0 (124→125) taken 2 times.
✓ Branch 2 (127→128) taken 2 times.
✓ Branch 4 (130→131) taken 2 times.
✓ Branch 6 (131→132) taken 2 times.
✓ Branch 8 (132→133) taken 2 times.
10 data_stream_assert(clock.now() == nowValue);
55
1/1
✓ Branch 0 (139→140) taken 2 times.
2 clock.sleep(1000l); //Sleep for 1 microsecond
56 2 }
57
58 ///Test the PGenericClock
59 1 void testGenericClock(){
60 1 testSpecialisedClock<ClockSecond>();
61 1 testSpecialisedClock<ClockNanoSecond>();
62 1 }
63
64
65 1 int main(int argc, char** argv){
66 1 testGenericClock();
67 1 return 0;
68 }
69
70
71