GCC Code Coverage Report


Directory: ./
File: TESTS/TEST_DAEMON_LATENCY/main.cpp
Date: 2025-03-14 12:18:05
Exec Total Coverage
Lines: 51 51 100.0%
Branches: 75 75 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 <iostream>
9
10 #include "phoenix_assert.h"
11 #include "phoenix_check.h"
12
13 #include "DaemonEmptyBackend.h"
14 #include "Daemon.h"
15
16 typedef Daemon<DaemonEmptyBackend> TestDaemon;
17
18 ///Create the mock of the time
19 /** @param mockName : name of the mock file of the current test
20 */
21 1 void createMockTime(const PString & mockName){
22 //Let's write the mock of the time
23 1 VecTime vecTime;
24 //Let's write all the different time needed by the test
25
1/1
✓ Branch 1 taken 1 times.
1 vecTime.push_back(0lu); //Call of the clock
26
1/1
✓ Branch 1 taken 1 times.
1 vecTime.push_back(1lu); //Call of the clock
27
1/1
✓ Branch 1 taken 1 times.
1 vecTime.push_back(2lu); //Call of the clock
28
1/1
✓ Branch 1 taken 1 times.
1 vecTime.push_back(3lu); //Call of the clock
29
30
1/1
✓ Branch 1 taken 1 times.
1 phoenix_saveClockMock(vecTime);
31 1 }
32
33 ///Create the mock file fo the test Daemon
34 /** @param mockName : name of the mock file of the current test
35 */
36 1 void createMockFileTest(const PString & mockName){
37 1 PVecMockMessage vecOutput;
38 //Let's say, the main Daemon wants to call a function on test
39
1/1
✓ Branch 1 taken 1 times.
1 Message message;
40
1/1
✓ Branch 1 taken 1 times.
1 message.setId(0lu); //Anwser of the PING message
41
1/1
✓ Branch 1 taken 1 times.
1 message.setSendTime(0lu);
42
1/1
✓ Branch 1 taken 1 times.
1 message.setType(MessageType::PONG);
43
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 message.setSender("main");
44
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
1 message.getVecRecver().push_back("test");
45
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(phoenix_addMockMessage(vecOutput, message));
46
47
4/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 std::cout << "createMockFileTest : send time of ping-pong : " << message.getSendTime() << std::endl;
48
49
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(phoenix_closeMockSocket(vecOutput, mockName));
50 1 }
51
52 ///Create the mock file to be used by the Daemon
53 /** @param mockName : name of the mock file of the current test
54 */
55 1 void createMockFile(const PString & mockName){
56 1 PVecMockMessage vecOutput;
57 //Let's pretend our Daemon is receiving a PING message
58
1/1
✓ Branch 1 taken 1 times.
1 Message messageConfirmation;
59
1/1
✓ Branch 1 taken 1 times.
1 messageConfirmation.setId(0lu); //Same Id as the first message sent by Daemon to Test
60
1/1
✓ Branch 1 taken 1 times.
1 messageConfirmation.setSendTime(0lu);
61
1/1
✓ Branch 1 taken 1 times.
1 messageConfirmation.setType(MessageType::PING);
62
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 messageConfirmation.setSender("test");
63
64
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(phoenix_addMockMessage(vecOutput, messageConfirmation));
65 //It should answer a PONG in the test Daemon mock
66
67 //Finally we stop the Daemon
68
1/1
✓ Branch 1 taken 1 times.
1 Message message;
69
1/1
✓ Branch 1 taken 1 times.
1 message.setId(0lu);
70
1/1
✓ Branch 1 taken 1 times.
1 message.setType(MessageType::STOP);
71
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(phoenix_addMockMessage(vecOutput, message));
72
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(phoenix_closeMockSocket(vecOutput, mockName));
73 1 }
74
75 ///Create and run the Daemon
76 /** @param fileName : name of the configuration toml file
77 * @param daemonName : name of the daemon of the current test
78 */
79 1 void createDaemon(const PPath & fileName, const PString & daemonName){
80 //Let's create and start the Daemon
81
1/1
✓ Branch 1 taken 1 times.
1 TestDaemon daemon;
82
1/1
✓ Branch 1 taken 1 times.
1 daemon.setSocketMode(PSocketMode::MOCK);
83
1/1
✓ Branch 1 taken 1 times.
1 daemon.setClockMode(PClockMode::MOCK);
84
1/1
✓ Branch 1 taken 1 times.
1 daemon.load(fileName, daemonName);
85
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(daemon.run());
86 1 }
87
88 ///Test the load configuration of a Daemon
89 /** @param fileName : name of the configuration toml file
90 */
91 1 void testBaseDaemonLoadConfig(const PPath & fileName){
92
8/8
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 24 taken 1 times.
✓ Branch 27 taken 1 times.
1 phoenix_assert(phoenix_check("Message type name", phoenix_getTypeName<Message>(), "Message"));
93 //Let's create the mock file
94
1/1
✓ Branch 2 taken 1 times.
1 createMockTime("clock.pmockclock"); // need to check this
95
1/1
✓ Branch 2 taken 1 times.
1 createMockFile("localhost_3390.pmockbackend");
96 //No need to check the output of the messages sent by the Daemon, because the PMockBackend already does it for us
97
1/1
✓ Branch 2 taken 1 times.
1 createMockFileTest("localhost_3391.pmockbackend");
98 //Let's create and start the Daemon
99
1/1
✓ Branch 2 taken 1 times.
1 createDaemon(fileName, "main");
100 1 }
101
102 1 int main(int argc, char** argv){
103
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK));
104 1 return 0;
105 }
106
107
108