| 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 | #include "Daemon.h" | ||
| 13 | #include "DaemonEmptyBackend.h" | ||
| 14 | |||
| 15 | #include "swarm_mock_daemon.h" | ||
| 16 | |||
| 17 | typedef Daemon<DaemonEmptyBackend> TestDaemon; | ||
| 18 | |||
| 19 | ///Create the mock file to be used by the Daemon | ||
| 20 | /** @param hostName : name of the host | ||
| 21 | * @param port : port to be used | ||
| 22 | * @param prefix : prefix of the mock file of the current test | ||
| 23 | */ | ||
| 24 | 1 | void createMockFile(const PString & hostName, size_t port, const PString & prefix){ | |
| 25 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PMockBackend::Socket mock; |
| 26 |
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 (33→34) not taken.
✗ Branch 15 (33→35) not taken.
|
5 | phoenix_assert(phoenix_createMockBackend(mock, PSocketParam{hostName, port}, prefix)); |
| 27 |
1/1✓ Branch 0 (24→25) taken 1 times.
|
1 | Message message; |
| 28 |
1/1✓ Branch 0 (25→26) taken 1 times.
|
1 | message.setId(0lu); |
| 29 |
1/1✓ Branch 0 (26→27) taken 1 times.
|
1 | message.setType(MessageType::STOP); |
| 30 |
1/1✓ Branch 0 (27→28) taken 1 times.
|
1 | mock.sendData(message); |
| 31 | 1 | } | |
| 32 | |||
| 33 | ///Test the load configuration of a Daemon | ||
| 34 | /** @param fileName : name of the configuration toml file | ||
| 35 | */ | ||
| 36 | 1 | void testBaseDaemonLoadConfig(const PPath & fileName){ | |
| 37 |
8/8✓ Branch 0 (4→5) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
✓ Branch 4 (10→11) taken 1 times.
✓ Branch 6 (13→14) taken 1 times.
✓ Branch 8 (14→15) taken 1 times.
✓ Branch 10 (17→18) taken 1 times.
✓ Branch 12 (18→19) taken 1 times.
✓ Branch 14 (19→20) taken 1 times.
|
9 | phoenix_assert(phoenix_check("Message type name", phoenix_getTypeName<Message>(), "Message")); |
| 38 | //Let's create the mock file | ||
| 39 |
3/3✓ Branch 0 (31→32) taken 1 times.
✓ Branch 2 (32→33) taken 1 times.
✓ Branch 4 (33→34) taken 1 times.
|
1 | createMockFile("localhost", 3390, "main_"); |
| 40 |
2/2✓ Branch 0 (38→39) taken 1 times.
✓ Branch 2 (39→40) taken 1 times.
|
1 | phoenix_createClockMock("main_", 8lu); |
| 41 | //Let's create and start the Daemon | ||
| 42 |
1/1✓ Branch 0 (42→43) taken 1 times.
|
1 | TestDaemon daemon; |
| 43 |
1/1✓ Branch 0 (43→44) taken 1 times.
|
1 | daemon.setSocketMode(PSocketMode::MOCK); |
| 44 |
1/1✓ Branch 0 (44→45) taken 1 times.
|
1 | daemon.setClockMode(PClockMode::MOCK); |
| 45 |
2/2✓ Branch 0 (47→48) taken 1 times.
✓ Branch 2 (48→49) taken 1 times.
|
1 | phoenix_createClockMock("main_", 4lu); |
| 46 |
2/2✓ Branch 0 (51→52) taken 1 times.
✓ Branch 2 (52→53) taken 1 times.
|
1 | daemon.load(fileName, "main"); |
| 47 |
5/5✓ Branch 0 (56→57) taken 1 times.
✓ Branch 2 (59→60) taken 1 times.
✓ Branch 4 (62→63) taken 1 times.
✓ Branch 6 (63→64) taken 1 times.
✓ Branch 8 (64→65) taken 1 times.
|
5 | phoenix_assert(daemon.run()); |
| 48 | 1 | } | |
| 49 | |||
| 50 | |||
| 51 | ///Create a mock file with MESSAGE_CONFIRMATION and RESULT_DATA for processInputMessage coverage | ||
| 52 | /** @param hostName : name of the host | ||
| 53 | * @param port : port to be used | ||
| 54 | * @param prefix : prefix of the mock file of the current test | ||
| 55 | */ | ||
| 56 | 1 | void createMockFileWithMessages(const PString & hostName, size_t port, const PString & prefix){ | |
| 57 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PMockBackend::Socket mock; |
| 58 |
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 (61→62) not taken.
✗ Branch 15 (61→63) not taken.
|
5 | phoenix_assert(phoenix_createMockBackend(mock, PSocketParam{hostName, port}, prefix)); |
| 59 | // PVecMockMessage vecOutput; | ||
| 60 |
1/1✓ Branch 0 (24→25) taken 1 times.
|
1 | Message msgNeedConfirm; |
| 61 |
1/1✓ Branch 0 (25→26) taken 1 times.
|
1 | msgNeedConfirm.setId(10lu); |
| 62 |
1/1✓ Branch 0 (26→27) taken 1 times.
|
1 | msgNeedConfirm.setType(MessageType::RESULT_DATA); |
| 63 |
2/2✓ Branch 0 (27→28) taken 1 times.
✓ Branch 2 (28→29) taken 1 times.
|
1 | msgNeedConfirm.setSender("main"); |
| 64 |
1/1✓ Branch 0 (30→31) taken 1 times.
|
1 | msgNeedConfirm.setIsConfirmationNeeded(true); |
| 65 |
1/1✓ Branch 0 (31→32) taken 1 times.
|
1 | mock.sendData(msgNeedConfirm); |
| 66 | // phoenix_assert(phoenix_addMockMessage(vecOutput, msgNeedConfirm)); | ||
| 67 | |||
| 68 | // MESSAGE_CONFIRMATION | ||
| 69 |
1/1✓ Branch 0 (32→33) taken 1 times.
|
1 | Message msgConfirmation; |
| 70 |
1/1✓ Branch 0 (33→34) taken 1 times.
|
1 | msgConfirmation.setId(1lu); |
| 71 |
1/1✓ Branch 0 (34→35) taken 1 times.
|
1 | msgConfirmation.setType(MessageType::MESSAGE_CONFIRMATION); |
| 72 |
2/2✓ Branch 0 (35→36) taken 1 times.
✓ Branch 2 (36→37) taken 1 times.
|
1 | msgConfirmation.setSender("sender1"); |
| 73 |
1/1✓ Branch 0 (38→39) taken 1 times.
|
1 | mock.sendData(msgConfirmation); |
| 74 | // phoenix_assert(phoenix_addMockMessage(vecOutput, msgConfirmation)); | ||
| 75 | |||
| 76 | // RESULT_DATA | ||
| 77 |
1/1✓ Branch 0 (39→40) taken 1 times.
|
1 | Message msgResultData; |
| 78 |
1/1✓ Branch 0 (40→41) taken 1 times.
|
1 | msgResultData.setId(2lu); |
| 79 |
1/1✓ Branch 0 (41→42) taken 1 times.
|
1 | msgResultData.setType(MessageType::RESULT_DATA); |
| 80 |
2/2✓ Branch 0 (42→43) taken 1 times.
✓ Branch 2 (43→44) taken 1 times.
|
1 | msgResultData.setSender("sender2"); |
| 81 |
1/1✓ Branch 0 (45→46) taken 1 times.
|
1 | Data data; |
| 82 |
1/1✓ Branch 0 (46→47) taken 1 times.
|
1 | msgResultData.setData(data); |
| 83 |
1/1✓ Branch 0 (47→48) taken 1 times.
|
1 | mock.sendData(msgResultData); |
| 84 | // phoenix_assert(phoenix_addMockMessage(vecOutput, msgResultData)); | ||
| 85 | |||
| 86 | // STOP to end the run loop | ||
| 87 |
1/1✓ Branch 0 (48→49) taken 1 times.
|
1 | Message msgStop; |
| 88 |
1/1✓ Branch 0 (49→50) taken 1 times.
|
1 | msgStop.setId(3lu); |
| 89 |
1/1✓ Branch 0 (50→51) taken 1 times.
|
1 | msgStop.setType(MessageType::STOP); |
| 90 |
1/1✓ Branch 0 (51→52) taken 1 times.
|
1 | mock.sendData(msgStop); |
| 91 | // phoenix_assert(phoenix_addMockMessage(vecOutput, msgStop)); | ||
| 92 | // phoenix_assert(phoenix_closeMockSocket(vecOutput, mockName)); | ||
| 93 | 1 | } | |
| 94 | |||
| 95 | ///Test Daemon::run with MESSAGE_CONFIRMATION and RESULT_DATA messages | ||
| 96 | /** @param fileName : name of the configuration file | ||
| 97 | */ | ||
| 98 | 1 | void testProcessInputMessageCases(const PPath & fileName){ | |
| 99 |
3/3✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
✓ Branch 4 (4→5) taken 1 times.
|
1 | createMockFileWithMessages("localhost", 3390, "main_"); |
| 100 |
1/1✓ Branch 0 (7→8) taken 1 times.
|
1 | TestDaemon daemon; |
| 101 |
1/1✓ Branch 0 (8→9) taken 1 times.
|
1 | daemon.setSocketMode(PSocketMode::MOCK); |
| 102 |
1/1✓ Branch 0 (9→10) taken 1 times.
|
1 | daemon.setClockMode(PClockMode::MOCK); |
| 103 |
2/2✓ Branch 0 (10→11) taken 1 times.
✓ Branch 2 (11→12) taken 1 times.
|
1 | daemon.load(fileName, "main"); |
| 104 |
6/8✗ Branch 0 (13→14) not taken.
✓ Branch 2 (16→17) taken 1 times.
✓ Branch 4 (19→20) taken 1 times.
✓ Branch 6 (22→23) taken 1 times.
✓ Branch 8 (23→24) taken 1 times.
✗ Branch 10 (41→42) not taken.
✓ Branch 11 (41→43) taken 1 times.
✓ Branch 12 (44→14) taken 1 times.
|
6 | PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::SocketStatusException, daemon.run()); |
| 105 | 1 | } | |
| 106 | |||
| 107 | 1 | int main(int argc, char** argv){ | |
| 108 |
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)); |
| 109 |
3/3✓ Branch 0 (7→8) taken 1 times.
✓ Branch 2 (8→9) taken 1 times.
✓ Branch 4 (9→10) taken 1 times.
|
1 | testProcessInputMessageCases(PPath(DAEMON_CONFIG_OK)); |
| 110 | 1 | return 0; | |
| 111 | } | ||
| 112 | |||
| 113 | |||
| 114 |