GCC Code Coverage Report


Directory: ./
File: TESTS/TEST_DAEMONS/TEST_DAEMON_SEND_DATA/main.cpp
Date: 2026-01-15 15:35:36
Exec Total Coverage
Lines: 40 40 100.0%
Functions: 5 5 100.0%
Branches: 62 68 91.2%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include <iostream>
8
9 #include "swarm_mock_daemon.h"
10
11 //{The mock of the \b{test} \b{Daemon} :
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 /*-----------------------------------
18 Configuration:
19 - localhost:3390 is the Recv mock file to stop the Daemon
20 - localhost:3391 is the Send mock file to test the Daemon
21
22 Workflow :
23 1. The 'main' SendDataDaemon sends an INT data to the 'test' Daemon.
24 2. As we are in mock mode, we check that the sent data are correctly serialized in the mock file.
25 3. The 'main' Daemon receives the data and process it (here we do nothing with it).
26 4. Finally, the 'main' Daemon is stopped by a STOP message from another daemon.
27
28 +----------------+ +-----------------------------------+
29 | main daemon |--- RESULT_DATA (INT=42)-->| Mock file (main_localhost_3391) |
30 +----------------+ +-----------------------------------+
31 |
32 | <--- STOP message ---------------
33 |
34 ------------------------------------*/
35 2 void createMockFileMainSend(const PString & hostName, size_t port, const PString & prefix){
36
1/1
✓ Branch 0 (2→3) taken 2 times.
2 PMockBackend::Socket mock;
37
7/10
✓ Branch 0 (5→6) taken 2 times.
✓ Branch 2 (8→9) taken 2 times.
✓ Branch 4 (11→12) taken 2 times.
✓ Branch 6 (12→13) taken 2 times.
✓ Branch 8 (13→14) taken 2 times.
✓ Branch 10 (14→15) taken 2 times.
✗ Branch 12 (16→17) not taken.
✓ Branch 13 (16→18) taken 2 times.
✗ Branch 14 (45→46) not taken.
✗ Branch 15 (45→47) not taken.
10 phoenix_assert(phoenix_createMockBackend(mock, PSocketParam{hostName, port}, prefix));
38 // PVecMockMessage vecOutput;
39 //Let's say, the main Daemon wants to call a function on test
40
1/1
✓ Branch 0 (24→25) taken 2 times.
2 Message message;
41
1/1
✓ Branch 0 (25→26) taken 2 times.
2 message.setId(1lu); //Anwser of the INT message
42
1/1
✓ Branch 0 (26→27) taken 2 times.
2 message.setSendTime(1lu);
43
1/1
✓ Branch 0 (27→28) taken 2 times.
2 message.setIsConfirmationNeeded(true);
44
1/1
✓ Branch 0 (28→29) taken 2 times.
2 message.setType(MessageType::RESULT_DATA);
45
2/2
✓ Branch 0 (29→30) taken 2 times.
✓ Branch 2 (30→31) taken 2 times.
2 message.setSender("main");
46 2 int data(42);
47
2/2
✓ Branch 0 (32→33) taken 2 times.
✓ Branch 2 (33→34) taken 2 times.
2 message.setData(phoenix_createData(data));
48
3/3
✓ Branch 0 (35→36) taken 2 times.
✓ Branch 2 (36→37) taken 2 times.
✓ Branch 4 (37→38) taken 2 times.
2 message.getVecRecver().push_back("test");
49
1/1
✓ Branch 0 (39→40) taken 2 times.
2 mock.sendData(message);
50 2 }
51
52 //{The mock of the \b{main} \b{Daemon} :
53 ///Create the mock file to be used by the Daemon
54 /** @param hostName : name of the host
55 * @param port : port to be used
56 * @param prefix : prefix of the mock file of the current test
57 */
58 2 void createMockFileMainRecv(const PString & hostName, size_t port, const PString & prefix){
59
1/1
✓ Branch 0 (2→3) taken 2 times.
2 PMockBackend::Socket mock;
60
7/10
✓ Branch 0 (5→6) taken 2 times.
✓ Branch 2 (8→9) taken 2 times.
✓ Branch 4 (11→12) taken 2 times.
✓ Branch 6 (12→13) taken 2 times.
✓ Branch 8 (13→14) taken 2 times.
✓ Branch 10 (14→15) taken 2 times.
✗ Branch 12 (16→17) not taken.
✓ Branch 13 (16→18) taken 2 times.
✗ Branch 14 (33→34) not taken.
✗ Branch 15 (33→35) not taken.
10 phoenix_assert(phoenix_createMockBackend(mock, PSocketParam{hostName, port}, prefix));
61
62 //Finally we stop the Daemon
63
1/1
✓ Branch 0 (24→25) taken 2 times.
2 Message messageStop;
64
1/1
✓ Branch 0 (25→26) taken 2 times.
2 messageStop.setId(2lu);
65
1/1
✓ Branch 0 (26→27) taken 2 times.
2 messageStop.setType(MessageType::STOP);
66
1/1
✓ Branch 0 (27→28) taken 2 times.
2 mock.sendData(messageStop);
67 2 }
68
69 //{Then, we craete the \b{Daemon} :
70 ///Create and run the Daemon
71 /** @param fileName : name of the configuration toml file
72 * @param daemonName : name of the daemon of the current test
73 */
74 2 void createDaemon(const PPath & fileName, const PString & daemonName){
75 //Let's create and start the Daemon
76
1/1
✓ Branch 0 (2→3) taken 2 times.
2 SendDataDaemon daemon;
77
1/1
✓ Branch 0 (3→4) taken 2 times.
2 daemon.setSocketMode(PSocketMode::MOCK);
78
1/1
✓ Branch 0 (4→5) taken 2 times.
2 daemon.setClockMode(PClockMode::MOCK);
79
4/4
✓ Branch 0 (5→6) taken 2 times.
✓ Branch 2 (6→7) taken 2 times.
✓ Branch 4 (7→8) taken 2 times.
✓ Branch 6 (8→9) taken 2 times.
2 daemon.getLog().setFileName(PPath("Daemon.log"));
80
1/1
✓ Branch 0 (11→12) taken 2 times.
2 daemon.load(fileName, daemonName);
81
5/5
✓ Branch 0 (14→15) taken 2 times.
✓ Branch 2 (17→18) taken 2 times.
✓ Branch 4 (20→21) taken 2 times.
✓ Branch 6 (21→22) taken 2 times.
✓ Branch 8 (22→23) taken 2 times.
10 phoenix_assert(daemon.run());
82 2 }
83
84 //{Now, we load the config :
85 ///Test the load configuration of a Daemon
86 /** @param fileName : name of the configuration toml file
87 */
88 4 void testBaseDaemonLoadConfig(const PPath & fileName){
89 //Let's create the mock file
90
2/2
✓ Branch 0 (4→5) taken 2 times.
✓ Branch 2 (5→6) taken 2 times.
2 phoenix_createClockMock("main_", 4lu);
91
3/3
✓ Branch 0 (8→9) taken 2 times.
✓ Branch 2 (9→10) taken 2 times.
✓ Branch 4 (10→11) taken 2 times.
2 createMockFileMainRecv("localhost", 3390, "main_");
92 //No need to check the output of the messages sent by the Daemon, because the PMockBackend already does it for us
93
3/3
✓ Branch 0 (13→14) taken 2 times.
✓ Branch 2 (14→15) taken 2 times.
✓ Branch 4 (15→16) taken 2 times.
2 createMockFileMainSend("localhost", 3391, "main_");
94 //Let's create and start the Daemon
95
2/2
✓ Branch 0 (18→19) taken 2 times.
✓ Branch 2 (19→20) taken 2 times.
2 createDaemon(fileName, "main");
96 2 }
97
98 //{And finally the \func{main} function with two configuration files :
99 1 int main(int argc, char** argv){
100
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));
101
3/3
✓ Branch 0 (7→8) taken 1 times.
✓ Branch 2 (8→9) taken 1 times.
✓ Branch 4 (9→10) taken 1 times.
1 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK_YAML));
102 1 return 0;
103 }
104
105
106