GCC Code Coverage Report


Directory: ./
File: TESTS/TEST_DAEMONS/TEST_DAEMON_RECV_DATA/main.cpp
Date: 2026-01-15 15:35:36
Exec Total Coverage
Lines: 63 63 100.0%
Functions: 5 5 100.0%
Branches: 96 102 94.1%

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 #include "swarm_mock_daemon.h"
9
10 /*---------------------------------------------------------------------------------------
11 Configuration:
12 - localhost:3390 is the Recv mock file to stop the Daemon
13 - localhost:3391 is the Send mock file to test the Daemon
14
15 Workflow :
16 1. We mock the fact that the 'test' daemon sends two data (a Shadok and a Gibis) to the 'main' Daemon using the mock file 'main_localhost_3390'.
17 2. The main daemon is configured to have callable functions to process Shadok and Gibis data.
18 So as we read a data from the mock file, it deserializes it and process it using the appropriate type.
19 3. The main daemon has also an extraLoopProcessing function that checks if the data received have the expected type (here one Shadok and one Gibis).
20 4. THen in the mock file 'main_localhost_3391', we mock the fact that the 'main' Daemon has sent a confirmation message for each data received.
21 5. Finally, the 'main' Daemon is stopped by a STOP message from another daemon
22
23 +----------------+ +-----------------------------------+ +---------------------------------------+
24 | main daemon | | Mock file (main_localhost_3390) | | Mock file (main_localhost_3391) |
25 +----------------+ +-----------------------------------+ +---------------------------------------+
26 | | |
27 | <--- RESULT_DATA (Shadok)--------------| |
28 | | |
29 | --- MESSAGE_CONFIRMATION (Shadok) -----------------------------------------> |
30 | | |
31 | <--- RESULT_DATA (Gibis) --------------| |
32 | | |
33 | --- MESSAGE_CONFIRMATION (Gibis) ------------------------------------------> |
34 | | |
35 | <--- STOP message --------------- | |
36 | | |
37 -----------------------------------------------------------------------------------------*/
38
39 ///Simulate data to send
40 /** @param hostName : name of the host
41 * @param port : port to be used
42 * @param prefix : prefix of the mock file of the current test
43 */
44 1 void createMockFileMainSend(const PString & hostName, size_t port, const PString & prefix){
45
1/1
✓ Branch 0 (2→3) taken 1 times.
1 PMockBackend::Socket mock;
46
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 (56→57) not taken.
✗ Branch 15 (56→58) not taken.
5 phoenix_assert(phoenix_createMockBackend(mock, PSocketParam{hostName, port}, prefix));
47 1 PVecMockMessage vecOutput;
48 //At time 0, whe receive a confiramtion for the Shadok message sent
49
1/1
✓ Branch 0 (25→26) taken 1 times.
1 Message confirmationShadok;
50
1/1
✓ Branch 0 (26→27) taken 1 times.
1 confirmationShadok.setSendTime(0lu);
51
1/1
✓ Branch 0 (27→28) taken 1 times.
1 confirmationShadok.setId(1lu);
52
2/2
✓ Branch 0 (28→29) taken 1 times.
✓ Branch 2 (29→30) taken 1 times.
1 confirmationShadok.setSender("main");
53
1/1
✓ Branch 0 (31→32) taken 1 times.
1 confirmationShadok.setType(MessageType::MESSAGE_CONFIRMATION);
54
3/3
✓ Branch 0 (32→33) taken 1 times.
✓ Branch 2 (33→34) taken 1 times.
✓ Branch 4 (34→35) taken 1 times.
1 confirmationShadok.getVecRecver().push_back("test");
55
1/1
✓ Branch 0 (36→37) taken 1 times.
1 mock.sendData(confirmationShadok);
56
57 //At time 1, we receive a confirmation for the Gibis message sent
58
1/1
✓ Branch 0 (37→38) taken 1 times.
1 Message confirmationGibis;
59
1/1
✓ Branch 0 (38→39) taken 1 times.
1 confirmationGibis.setSendTime(1lu);
60
1/1
✓ Branch 0 (39→40) taken 1 times.
1 confirmationGibis.setId(2lu);
61
2/2
✓ Branch 0 (40→41) taken 1 times.
✓ Branch 2 (41→42) taken 1 times.
1 confirmationGibis.setSender("main");
62
1/1
✓ Branch 0 (43→44) taken 1 times.
1 confirmationGibis.setType(MessageType::MESSAGE_CONFIRMATION);
63
3/3
✓ Branch 0 (44→45) taken 1 times.
✓ Branch 2 (45→46) taken 1 times.
✓ Branch 4 (46→47) taken 1 times.
1 confirmationGibis.getVecRecver().push_back("test");
64
1/1
✓ Branch 0 (48→49) taken 1 times.
1 mock.sendData(confirmationGibis);
65 1 }
66
67 ///Simulate data to send
68 /** @param mockName : name of the associated mock
69 */
70 1 void createMockFileMainRecv(const PString & hostName, size_t port, const PString & prefix){
71
1/1
✓ Branch 0 (2→3) taken 1 times.
1 PMockBackend::Socket mock;
72
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 (75→76) not taken.
✗ Branch 15 (75→77) not taken.
5 phoenix_assert(phoenix_createMockBackend(mock, PSocketParam{hostName, port}, prefix));
73
74 //We receive a Shadok message
75
1/1
✓ Branch 0 (24→25) taken 1 times.
1 Message shadokMsg;
76
1/1
✓ Branch 0 (25→26) taken 1 times.
1 shadokMsg.setId(1lu);
77
1/1
✓ Branch 0 (26→27) taken 1 times.
1 shadokMsg.setSendTime(0lu);
78
1/1
✓ Branch 0 (27→28) taken 1 times.
1 shadokMsg.setIsConfirmationNeeded(true);
79
1/1
✓ Branch 0 (28→29) taken 1 times.
1 shadokMsg.setType(MessageType::RESULT_DATA);
80
2/2
✓ Branch 0 (29→30) taken 1 times.
✓ Branch 2 (30→31) taken 1 times.
1 shadokMsg.setSender("test");
81
2/2
✓ Branch 0 (32→33) taken 1 times.
✓ Branch 2 (33→34) taken 1 times.
1 Shadok shadok("Bob", 42);
82
2/2
✓ Branch 0 (35→36) taken 1 times.
✓ Branch 2 (36→37) taken 1 times.
1 shadokMsg.setData(phoenix_createData(shadok));
83
3/3
✓ Branch 0 (38→39) taken 1 times.
✓ Branch 2 (39→40) taken 1 times.
✓ Branch 4 (40→41) taken 1 times.
1 shadokMsg.getVecRecver().push_back("main");
84
1/1
✓ Branch 0 (42→43) taken 1 times.
1 mock.sendData(shadokMsg);
85
86 //We receive a Gibis message
87
1/1
✓ Branch 0 (43→44) taken 1 times.
1 Message gibisMsg;
88
1/1
✓ Branch 0 (44→45) taken 1 times.
1 gibisMsg.setId(2lu);
89
1/1
✓ Branch 0 (45→46) taken 1 times.
1 gibisMsg.setSendTime(1lu);
90
1/1
✓ Branch 0 (46→47) taken 1 times.
1 gibisMsg.setIsConfirmationNeeded(true);
91
1/1
✓ Branch 0 (47→48) taken 1 times.
1 gibisMsg.setType(MessageType::RESULT_DATA);
92
2/2
✓ Branch 0 (48→49) taken 1 times.
✓ Branch 2 (49→50) taken 1 times.
1 gibisMsg.setSender("test");
93
2/2
✓ Branch 0 (51→52) taken 1 times.
✓ Branch 2 (52→53) taken 1 times.
1 Gibis gibis("Red", 100);
94
2/2
✓ Branch 0 (54→55) taken 1 times.
✓ Branch 2 (55→56) taken 1 times.
1 gibisMsg.setData(phoenix_createData(gibis));
95
3/3
✓ Branch 0 (57→58) taken 1 times.
✓ Branch 2 (58→59) taken 1 times.
✓ Branch 4 (59→60) taken 1 times.
1 gibisMsg.getVecRecver().push_back("main");
96
1/1
✓ Branch 0 (61→62) taken 1 times.
1 mock.sendData(gibisMsg);
97
98 //Finally we stop the Daemon
99
1/1
✓ Branch 0 (62→63) taken 1 times.
1 Message messageStop;
100
1/1
✓ Branch 0 (63→64) taken 1 times.
1 messageStop.setId(3lu);
101
1/1
✓ Branch 0 (64→65) taken 1 times.
1 messageStop.setType(MessageType::STOP);
102
1/1
✓ Branch 0 (65→66) taken 1 times.
1 mock.sendData(messageStop);
103 1 }
104
105 ///Create a simple Daemon stat manager
106 /** @param fileName : Daemon configuration
107 * @param daemonName : name of the current Daemon
108 */
109 1 void createDaemon(const PPath & fileName, const PString & daemonName){
110
1/1
✓ Branch 0 (2→3) taken 1 times.
1 RecvDataDaemon daemon;
111
1/1
✓ Branch 0 (3→4) taken 1 times.
1 daemon.setSocketMode(PSocketMode::MOCK);
112
1/1
✓ Branch 0 (4→5) taken 1 times.
1 daemon.setClockMode(PClockMode::MOCK);
113
5/5
✓ Branch 0 (7→8) taken 1 times.
✓ Branch 2 (10→11) taken 1 times.
✓ Branch 4 (13→14) taken 1 times.
✓ Branch 6 (14→15) taken 1 times.
✓ Branch 8 (15→16) taken 1 times.
6 phoenix_assert(daemon.load(fileName, daemonName));
114
5/5
✓ Branch 0 (24→25) taken 1 times.
✓ Branch 2 (27→28) taken 1 times.
✓ Branch 4 (30→31) taken 1 times.
✓ Branch 6 (31→32) taken 1 times.
✓ Branch 8 (32→33) taken 1 times.
5 phoenix_assert(daemon.run());
115 1 }
116
117 ///Test a simple Daemon stat manager
118 /** @param fileName : Daemon configuration
119 */
120 1 void testStatDaemonManager(const PPath & fileName){
121
2/2
✓ Branch 0 (4→5) taken 1 times.
✓ Branch 2 (5→6) taken 1 times.
1 phoenix_createClockMock("main_", 4lu);
122
3/3
✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
✓ Branch 4 (10→11) taken 1 times.
1 createMockFileMainSend("localhost", 3391lu, "main_");
123
3/3
✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (14→15) taken 1 times.
✓ Branch 4 (15→16) taken 1 times.
1 createMockFileMainRecv("localhost", 3390, "main_");
124
2/2
✓ Branch 0 (18→19) taken 1 times.
✓ Branch 2 (19→20) taken 1 times.
1 createDaemon(fileName, "main");
125 1 }
126
127 1 int main(int argc, char** argv){
128
3/3
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
✓ Branch 4 (4→5) taken 1 times.
1 testStatDaemonManager(PPath(DAEMON_CONFIG_OK));
129 1 return 0;
130 }
131
132
133