GCC Code Coverage Report


Directory: ./
File: TESTS/TEST_DAEMON_TIMEOUT/main.cpp
Date: 2025-03-27 14:50:11
Exec Total Coverage
Lines: 60 60 100.0%
Branches: 76 76 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 "DaemonEmptyBackend.h"
11 #include "SendDataDaemon.h"
12
13 ///Create the mock of the time
14 /** @param mockName : name of the mock file of the current test
15 */
16 1 void createMockTime(const PString & mockName){
17 //Let's write the mock of the time
18
19 1 VecTime vecTime;
20 //Let's write all the different time needed by the test
21
1/1
✓ Branch 1 taken 1 times.
1 vecTime.push_back(0lu); //Call of the clock
22
1/1
✓ Branch 1 taken 1 times.
1 vecTime.push_back(250lu); //Call of the clock
23
1/1
✓ Branch 1 taken 1 times.
1 vecTime.push_back(251lu); //Call of the clock
24
1/1
✓ Branch 1 taken 1 times.
1 vecTime.push_back(252lu); //Call of the clock
25
26
1/1
✓ Branch 1 taken 1 times.
1 phoenix_saveClockMock(vecTime);
27 1 }
28
29 ///Create the mock file fo the test Daemon
30 /** @param mockName : name of the mock file of the current test
31 */
32 1 void createMockFileTest(const PString & mockName){
33 1 PVecMockMessage vecOutput;
34 //Let's say, the main Daemon wants to call a function on test
35
1/1
✓ Branch 1 taken 1 times.
1 Message message;
36
1/1
✓ Branch 1 taken 1 times.
1 message.setId(1lu); //Anwser of the INT message
37
1/1
✓ Branch 1 taken 1 times.
1 message.setSendTime(0lu);
38
1/1
✓ Branch 1 taken 1 times.
1 message.setIsConfirmationNeeded(true);
39
1/1
✓ Branch 1 taken 1 times.
1 message.setType(MessageType::RESULT_DATA);
40
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 message.setSender("main");
41 1 int data(42);
42
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 message.setData(phoenix_createData(data));
43
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
1 message.getVecRecver().push_back("test");
44
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));
45
46
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));
47 1 }
48
49 ///Create the mock file to be used by the Daemon
50 /** @param mockName : name of the mock file of the current test
51 */
52 1 void createMockFileMain(const PString & mockName){
53 1 PVecMockMessage vecOutput;
54
55 1 DataStreamMsg emptyMsg;
56
1/1
✓ Branch 1 taken 1 times.
1 vecOutput.push_back(emptyMsg);
57
58 //Finally we stop the Daemon
59
1/1
✓ Branch 1 taken 1 times.
1 Message messageStop;
60
1/1
✓ Branch 1 taken 1 times.
1 messageStop.setId(1lu);
61
1/1
✓ Branch 1 taken 1 times.
1 messageStop.setSendTime(0lu);
62
1/1
✓ Branch 1 taken 1 times.
1 messageStop.setType(MessageType::STOP);
63
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, messageStop));
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_closeMockSocket(vecOutput, mockName));
65 1 }
66
67 ///Create and run the Daemon
68 /** @param fileName : name of the configuration toml file
69 * @param daemonName : name of the daemon of the current test
70 */
71 1 void createDaemon(const PPath & fileName, const PString & daemonName){
72 //Let's create and start the Daemon
73
1/1
✓ Branch 1 taken 1 times.
1 SendDataDaemon daemon;
74
1/1
✓ Branch 1 taken 1 times.
1 daemon.setSocketMode(PSocketMode::MOCK);
75
1/1
✓ Branch 1 taken 1 times.
1 daemon.setClockMode(PClockMode::MOCK);
76
4/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 daemon.getLog().setFileName(PPath("Daemon.log"));
77
1/1
✓ Branch 1 taken 1 times.
1 daemon.load(fileName, daemonName);
78
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());
79 1 }
80
81 ///Test the load configuration of a Daemon
82 /** @param fileName : name of the configuration toml file
83 */
84 1 void testBaseDaemonLoadConfig(const PPath & fileName){
85 //Let's create the mock file
86
1/1
✓ Branch 2 taken 1 times.
1 createMockTime("clock.pmockclock"); // need to check this
87
1/1
✓ Branch 2 taken 1 times.
1 createMockFileMain("localhost_3390.pmockbackend");
88 //No need to check the output of the messages sent by the Daemon, because the PMockBackend already does it for us
89
1/1
✓ Branch 2 taken 1 times.
1 createMockFileTest("localhost_3391.pmockbackend");
90 //Let's create and start the Daemon
91
1/1
✓ Branch 2 taken 1 times.
1 createDaemon(fileName, "main");
92 1 }
93
94 1 void FindMessageInLog(const std::string & message){
95
1/1
✓ Branch 1 taken 1 times.
1 std::ifstream logFile("daemon_main.log");
96
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(logFile.is_open());
97 std::string logContent((std::istreambuf_iterator<char>(logFile)),
98
1/1
✓ Branch 4 taken 1 times.
1 std::istreambuf_iterator<char>());
99
4/4
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
1 phoenix_assert(logContent.find(message) != std::string::npos);
100
1/1
✓ Branch 1 taken 1 times.
1 logFile.close();
101 1 }
102
103 1 int main(int argc, char** argv){
104
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
1 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK_TOML));
105
1/1
✓ Branch 1 taken 1 times.
1 PString messageToFind = "BaseDaemon::checkMessageTimeout() : Timeout Reached for message 1 sent to test. Removing unconfirmed transaction";
106
1/1
✓ Branch 1 taken 1 times.
1 FindMessageInLog(messageToFind);
107 1 return 0;
108 1 }
109
110
111