GCC Code Coverage Report


Directory: ./
File: TESTS/TEST_DAEMONS/TEST_DAEMON_TIMEOUT/main.cpp
Date: 2026-01-15 15:35:36
Exec Total Coverage
Lines: 52 52 100.0%
Functions: 6 6 100.0%
Branches: 69 75 92.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 "swarm_mock_daemon.h"
11
12 ///Create the mock file fo the test Daemon
13 /** @param hostName : name of the host
14 * @param port : port to be used
15 * @param prefix : prefix of the mock file of the current test
16 */
17 1 void createMockFileTest(const PString & hostName, size_t port, const PString & prefix){
18
1/1
✓ Branch 0 (2→3) taken 1 times.
1 PMockBackend::Socket mock;
19
7/10
✓ 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.
✓ Branch 10 (14→15) taken 1 times.
✗ Branch 12 (16→17) not taken.
✓ Branch 13 (16→18) taken 1 times.
✗ Branch 14 (45→46) not taken.
✗ Branch 15 (45→47) not taken.
5 phoenix_assert(phoenix_createMockBackend(mock, PSocketParam{hostName, port}, prefix));
20 // PVecMockMessage vecOutput;
21 //Let's say, the main Daemon wants to call a function on test
22
1/1
✓ Branch 0 (24→25) taken 1 times.
1 Message message;
23
1/1
✓ Branch 0 (25→26) taken 1 times.
1 message.setId(1lu); //Anwser of the INT message
24
1/1
✓ Branch 0 (26→27) taken 1 times.
1 message.setSendTime(1lu);
25
1/1
✓ Branch 0 (27→28) taken 1 times.
1 message.setIsConfirmationNeeded(true);
26
1/1
✓ Branch 0 (28→29) taken 1 times.
1 message.setType(MessageType::RESULT_DATA);
27
2/2
✓ Branch 0 (29→30) taken 1 times.
✓ Branch 2 (30→31) taken 1 times.
1 message.setSender("main");
28 1 int data(42);
29
2/2
✓ Branch 0 (32→33) taken 1 times.
✓ Branch 2 (33→34) taken 1 times.
1 message.setData(phoenix_createData(data));
30
3/3
✓ Branch 0 (35→36) taken 1 times.
✓ Branch 2 (36→37) taken 1 times.
✓ Branch 4 (37→38) taken 1 times.
1 message.getVecRecver().push_back("test");
31
1/1
✓ Branch 0 (39→40) taken 1 times.
1 mock.sendData(message);
32 // phoenix_assert(phoenix_addMockMessage(vecOutput, message));
33 // phoenix_assert(phoenix_closeMockSocket(vecOutput, mockName));
34 1 }
35
36 ///Create the mock file to be used by the Daemon
37 /** @param hostName : name of the host
38 * @param port : port to be used
39 * @param prefix : prefix of the mock file of the current test
40 */
41 1 void createMockFileMain(const PString & hostName, size_t port, const PString & prefix){
42
1/1
✓ Branch 0 (2→3) taken 1 times.
1 PMockBackend::Socket mock;
43
7/10
✓ 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.
✓ Branch 10 (14→15) taken 1 times.
✗ Branch 12 (16→17) not taken.
✓ Branch 13 (16→18) taken 1 times.
✗ Branch 14 (38→39) not taken.
✗ Branch 15 (38→40) not taken.
5 phoenix_assert(phoenix_createMockBackend(mock, PSocketParam{hostName, port}, prefix));
44 1 PVecMockMessage vecOutput;
45
46 1 DataStreamMsg emptyMsg;
47 // vecOutput.push_back(emptyMsg);
48
1/1
✓ Branch 0 (26→27) taken 1 times.
1 mock.sendMsg(emptyMsg);
49
50 //Finally we stop the Daemon
51
1/1
✓ Branch 0 (27→28) taken 1 times.
1 Message messageStop;
52
1/1
✓ Branch 0 (28→29) taken 1 times.
1 messageStop.setId(1lu);
53
1/1
✓ Branch 0 (29→30) taken 1 times.
1 messageStop.setType(MessageType::STOP);
54
1/1
✓ Branch 0 (30→31) taken 1 times.
1 mock.sendData(messageStop);
55 // phoenix_assert(phoenix_addMockMessage(vecOutput, messageStop));
56 // phoenix_assert(phoenix_closeMockSocket(vecOutput, mockName));
57 1 }
58
59 ///Create and run the Daemon
60 /** @param fileName : name of the configuration toml file
61 * @param daemonName : name of the daemon of the current test
62 */
63 1 void createDaemon(const PPath & fileName, const PString & daemonName){
64 //Let's create and start the Daemon
65
1/1
✓ Branch 0 (2→3) taken 1 times.
1 SendDataDaemon daemon;
66
1/1
✓ Branch 0 (3→4) taken 1 times.
1 daemon.setSocketMode(PSocketMode::MOCK);
67
1/1
✓ Branch 0 (4→5) taken 1 times.
1 daemon.setClockMode(PClockMode::MOCK);
68
1/1
✓ Branch 0 (5→6) taken 1 times.
1 daemon.load(fileName, daemonName);
69
5/5
✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (11→12) taken 1 times.
✓ Branch 4 (14→15) taken 1 times.
✓ Branch 6 (15→16) taken 1 times.
✓ Branch 8 (16→17) taken 1 times.
5 phoenix_assert(daemon.run());
70 1 }
71
72 ///Test the load configuration of a Daemon
73 /** @param fileName : name of the configuration toml file
74 */
75 1 void testBaseDaemonLoadConfig(const PPath & fileName){
76 //Let's create the mock file
77
2/2
✓ Branch 0 (4→5) taken 1 times.
✓ Branch 2 (5→6) taken 1 times.
1 phoenix_createClockMock("main_", 5lu);
78
3/3
✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
✓ Branch 4 (10→11) taken 1 times.
1 createMockFileMain("localhost", 3390, "main_");
79 //No need to check the output of the messages sent by the Daemon, because the PMockBackend already does it for us
80
3/3
✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (14→15) taken 1 times.
✓ Branch 4 (15→16) taken 1 times.
1 createMockFileTest("localhost", 3391, "main_");
81 //Let's create and start the Daemon
82
2/2
✓ Branch 0 (18→19) taken 1 times.
✓ Branch 2 (19→20) taken 1 times.
1 createDaemon(fileName, "main");
83 1 }
84
85 1 void FindMessageInLog(const std::string & message){
86
1/1
✓ Branch 0 (2→3) taken 1 times.
1 std::ifstream logFile("daemon_main.log");
87
4/4
✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (8→9) taken 1 times.
✓ Branch 4 (11→12) taken 1 times.
✓ Branch 6 (13→14) taken 1 times.
6 phoenix_assert(logFile.is_open());
88 1 std::string logContent((std::istreambuf_iterator<char>(logFile)),
89
1/1
✓ Branch 0 (24→25) taken 1 times.
2 std::istreambuf_iterator<char>());
90
4/4
✓ Branch 0 (28→29) taken 1 times.
✓ Branch 2 (31→32) taken 1 times.
✓ Branch 4 (34→35) taken 1 times.
✓ Branch 6 (36→37) taken 1 times.
5 phoenix_assert(logContent.find(message) != std::string::npos);
91
1/1
✓ Branch 0 (43→44) taken 1 times.
1 logFile.close();
92 1 }
93
94 1 int main(int argc, char** argv){
95
3/3
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
✓ Branch 4 (4→5) taken 1 times.
1 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK_TOML));
96
1/1
✓ Branch 0 (7→8) taken 1 times.
1 PString messageToFind = "BaseDaemon::checkMessageTimeout() : Timeout Reached for message 1 sent to 'test'. Removing unconfirmed transaction";
97
1/1
✓ Branch 0 (8→9) taken 1 times.
1 FindMessageInLog(messageToFind);
98 1 return 0;
99 1 }
100
101
102