Skip to content

Commit 6bdaddc

Browse files
author
JeromeGalan
authored
Merge pull request #424 from Luos-io/feat/secure_tests_default_scenario
Secure unit test default scenario and cleanup build and stuff
2 parents d8f188c + 7c38415 commit 6bdaddc

27 files changed

+111
-821
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

platformio.ini

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ build_flags =
2626
-O1
2727
-include ./test/_resources/node_config.h
2828
-DUNIT_TEST
29+
-D LUOSHAL=STUB
2930

3031
build_type = debug
3132
test_build_src = true

source_filter_script.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,15 @@
101101
"\t* Telemetry disabled, please consider enabling it by removing the 'NOTELEMETRY' flag to help Luos_engine improve.", fg="red")
102102
click.secho("")
103103

104-
# Native only
104+
# Native only => we should put this on a specific script on engine/HAL/STUB
105105
for item in env.ParseFlags(env['BUILD_FLAGS'])["CPPDEFINES"]:
106106
if (item == 'UNIT_TEST'):
107107
click.secho("Native unit testing:", underline=True)
108108
current_os = pf.system()
109109
click.secho("\t* Native Mock HAL for %s is selected for Luos and Robus." %
110110
current_os, fg="green")
111-
find_HAL = True
112-
env.Replace(SRC_FILTER=sources)
113-
env.Append(SRC_FILTER=["-<test/>"])
114-
env.Append(SRC_FILTER=["+<../../../test/_resources/*>"])
115111

112+
env.Append(SRC_FILTER=["+<../../../test/_resources/*>"])
116113
for resources in scandir(getcwd() + "/test/_resources"):
117114
if resources.is_dir():
118115
env.Append(CPPPATH=[(resources.path)])

test/_resources/Mock/Mock_Luos_Assert.c

-27
This file was deleted.

test/_resources/Scenarios/default_scenario.c

+20-220
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,16 @@
55
* @version 1.0.0
66
******************************************************************************/
77
#include <stdio.h>
8-
#include "context.h"
98
#include "default_scenario.h"
10-
#include "unit_test.h"
11-
12-
/*******************************************************************************
13-
* Definitions
14-
******************************************************************************/
15-
#define LUOS_TASK_NUMBER 3
16-
#define TX_TASK_NUMBER 3
179

1810
/*******************************************************************************
1911
* Variables
2012
******************************************************************************/
21-
2213
default_scenario_t default_sc;
23-
extern volatile uint8_t msg_buffer[MSG_BUFFER_SIZE];
24-
25-
volatile uint8_t *transmit_msg;
26-
msg_t receive_msg[DUMMY_SERVICE_NUMBER];
27-
uint8_t stream_Buffer1[STREAM_BUFFER_SIZE] = {0};
28-
uint8_t stream_Buffer2[STREAM_BUFFER_SIZE] = {0};
29-
streaming_channel_t Default_StreamChannel1;
30-
streaming_channel_t Default_StreamChannel2;
3114

3215
/*******************************************************************************
3316
* Function
3417
******************************************************************************/
35-
extern void MsgAlloc_LuosTaskAlloc(ll_service_t *service_concerned_by_current_msg, msg_t *concerned_msg);
36-
37-
static void Reset_Streaming(void);
38-
static void Init_Messages(void);
3918
static void Detection(service_t *service);
4019
static void App_1_MsgHandler(service_t *service, msg_t *msg);
4120
static void App_2_MsgHandler(service_t *service, msg_t *msg);
@@ -48,6 +27,18 @@ static void App_3_MsgHandler(service_t *service, msg_t *msg);
4827
******************************************************************************/
4928
void Init_Context(void)
5029
{
30+
// Reset context
31+
RESET_ASSERT();
32+
Luos_ServicesClear();
33+
RoutingTB_Erase(); // Delete RTB
34+
Luos_Init();
35+
if (IS_ASSERT())
36+
{
37+
printf("[FATAL] Can't reset scenario context\n");
38+
TEST_ASSERT_TRUE(IS_ASSERT());
39+
}
40+
Luos_Loop();
41+
5142
RESET_ASSERT();
5243
Luos_Init();
5344

@@ -57,49 +48,17 @@ void Init_Context(void)
5748
default_sc.App_2.app = Luos_CreateService(App_2_MsgHandler, VOID_TYPE, "Dummy_App_2", revision);
5849
default_sc.App_3.app = Luos_CreateService(App_3_MsgHandler, VOID_TYPE, "Dummy_App_3", revision);
5950

60-
Reset_Streaming();
61-
// Create stream channels
62-
Default_StreamChannel1 = Stream_CreateStreamingChannel(stream_Buffer1, STREAM_BUFFER_SIZE, 1);
63-
Default_StreamChannel2 = Stream_CreateStreamingChannel(stream_Buffer2, STREAM_BUFFER_SIZE, 1);
64-
6551
// Detection
6652
Detection(default_sc.App_1.app);
6753
Luos_Loop();
6854

69-
// Init messages pointers
70-
transmit_msg = msg_buffer;
71-
72-
// Fill basic messages
73-
Init_Messages();
74-
7555
if (IS_ASSERT())
7656
{
7757
printf("[FATAL] Can't initialize scenario context\n");
7858
TEST_ASSERT_TRUE(IS_ASSERT());
7959
}
8060
}
8161

82-
/******************************************************************************
83-
* @brief Reset context to init state
84-
* @param None
85-
* @return None
86-
******************************************************************************/
87-
void Reset_Context(void)
88-
{
89-
RESET_ASSERT();
90-
Luos_ServicesClear();
91-
RoutingTB_Erase(); // Delete RTB
92-
Luos_Init();
93-
transmit_msg = msg_buffer;
94-
Init_Messages();
95-
Reset_Streaming();
96-
if (IS_ASSERT())
97-
{
98-
printf("[FATAL] Can't reset scenario context\n");
99-
TEST_ASSERT_TRUE(IS_ASSERT());
100-
}
101-
}
102-
10362
/******************************************************************************
10463
* @brief Launch a detection
10564
* @param Service who launches the detection
@@ -110,123 +69,14 @@ static void Detection(service_t *service)
11069
search_result_t result;
11170

11271
Luos_Detect(service);
113-
Luos_Loop();
72+
do
73+
{
74+
Luos_Loop();
75+
} while (!Luos_IsNodeDetected());
11476

11577
RTFilter_Reset(&result);
11678
printf("[INFO] %d services are active\n", result.result_nbr);
117-
TEST_ASSERT_EQUAL(DUMMY_SERVICE_NUMBER, result.result_nbr);
118-
}
119-
120-
/******************************************************************************
121-
* @brief Messages are reseted to default values
122-
* @param None
123-
* @return None
124-
******************************************************************************/
125-
void Init_Messages(void)
126-
{
127-
// Init tx messages pointers
128-
default_sc.App_1.tx_msg = (msg_t *)(&msg_buffer[0]);
129-
default_sc.App_2.tx_msg = (msg_t *)(&msg_buffer[sizeof(msg_t)]);
130-
default_sc.App_3.tx_msg = (msg_t *)(&msg_buffer[0]);
131-
132-
// Init rx messages pointers
133-
default_sc.App_1.last_rx_msg = &receive_msg[0];
134-
default_sc.App_2.last_rx_msg = &receive_msg[1];
135-
default_sc.App_3.last_rx_msg = &receive_msg[2];
136-
137-
// App 1 : Send message to App 2
138-
// -------------------------------
139-
default_sc.App_1.tx_msg->header.config = PROTOCOL_REVISION;
140-
default_sc.App_1.tx_msg->header.source = 1;
141-
default_sc.App_1.tx_msg->header.target = 2;
142-
default_sc.App_1.tx_msg->header.target_mode = SERVICEIDACK;
143-
default_sc.App_1.tx_msg->header.cmd = DEFAULT_CMD;
144-
default_sc.App_1.tx_msg->header.size = MAX_DATA_MSG_SIZE;
145-
146-
// App 2 : Send message to App 1
147-
// -------------------------------
148-
default_sc.App_2.tx_msg->header.config = PROTOCOL_REVISION;
149-
default_sc.App_2.tx_msg->header.source = 2;
150-
default_sc.App_2.tx_msg->header.target = 1;
151-
default_sc.App_2.tx_msg->header.target_mode = SERVICEIDACK;
152-
default_sc.App_2.tx_msg->header.cmd = DEFAULT_CMD;
153-
default_sc.App_2.tx_msg->header.size = MAX_DATA_MSG_SIZE; // data = half of max size
154-
155-
// App 3 : Send message to App 2
156-
// -------------------------------
157-
default_sc.App_3.tx_msg->header.config = PROTOCOL_REVISION;
158-
default_sc.App_3.tx_msg->header.source = 3;
159-
default_sc.App_3.tx_msg->header.target = 2;
160-
default_sc.App_3.tx_msg->header.target_mode = SERVICEIDACK;
161-
default_sc.App_3.tx_msg->header.cmd = DEFAULT_CMD;
162-
default_sc.App_3.tx_msg->header.size = MAX_DATA_MSG_SIZE; // data = half of max size
163-
164-
// TX message : Only fill half of datas with a counter
165-
for (uint16_t i = 0; i < MAX_DATA_MSG_SIZE / 2; i++)
166-
{
167-
default_sc.App_1.tx_msg->data[i] = (uint8_t)i;
168-
default_sc.App_2.tx_msg->data[i] = (uint8_t)i;
169-
default_sc.App_3.tx_msg->data[i] = (uint8_t)i;
170-
}
171-
// TX message : Last half of datas is set to 0
172-
for (uint16_t i = MAX_DATA_MSG_SIZE / 2; i < MAX_DATA_MSG_SIZE; i++)
173-
{
174-
default_sc.App_1.tx_msg->data[i] = 0;
175-
default_sc.App_2.tx_msg->data[i] = 0;
176-
default_sc.App_3.tx_msg->data[i] = 0;
177-
}
178-
// RX message : datas are set to 0
179-
for (uint16_t i = 0; i < MAX_DATA_MSG_SIZE; i++)
180-
{
181-
default_sc.App_1.last_rx_msg->data[i] = 0;
182-
default_sc.App_2.last_rx_msg->data[i] = 0;
183-
default_sc.App_3.last_rx_msg->data[i] = 0;
184-
}
185-
}
186-
187-
/******************************************************************************
188-
* @brief Create a streaming channel
189-
* @param None
190-
* @return None
191-
******************************************************************************/
192-
static void Reset_Streaming(void)
193-
{
194-
// Stream Channel reset
195-
Stream_ResetStreamingChannel(&Default_StreamChannel1);
196-
Stream_ResetStreamingChannel(&Default_StreamChannel2);
197-
default_sc.streamChannel1 = &Default_StreamChannel1;
198-
default_sc.streamChannel2 = &Default_StreamChannel2;
199-
for (uint16_t i = 0; i < STREAM_BUFFER_SIZE; i++)
200-
{
201-
stream_Buffer1[i] = (uint8_t)(i);
202-
stream_Buffer2[i] = (uint8_t)(i);
203-
}
204-
}
205-
/******************************************************************************
206-
* @brief Loop Service App_1
207-
* @param None
208-
* @return None
209-
******************************************************************************/
210-
void App_1_Loop(void)
211-
{
212-
}
213-
214-
/******************************************************************************
215-
* @brief Loop Service App_2
216-
* @param None
217-
* @return None
218-
******************************************************************************/
219-
void App_2_Loop(void)
220-
{
221-
}
222-
223-
/******************************************************************************
224-
* @brief Loop Service App_3
225-
* @param None
226-
* @return None
227-
******************************************************************************/
228-
void App_3_Loop(void)
229-
{
79+
TEST_ASSERT_EQUAL(3, result.result_nbr);
23080
}
23181

23282
/******************************************************************************
@@ -237,23 +87,7 @@ void App_3_Loop(void)
23787
******************************************************************************/
23888
static void App_1_MsgHandler(service_t *service, msg_t *msg)
23989
{
240-
default_sc.App_1.last_rx_msg->header.config = msg->header.config;
241-
default_sc.App_1.last_rx_msg->header.source = msg->header.source;
242-
default_sc.App_1.last_rx_msg->header.target = msg->header.target;
243-
default_sc.App_1.last_rx_msg->header.target_mode = msg->header.target_mode;
244-
default_sc.App_1.last_rx_msg->header.cmd = msg->header.cmd;
245-
default_sc.App_1.last_rx_msg->header.size = msg->header.size;
246-
for (uint16_t i = 0; i < msg->header.size; i++)
247-
{
248-
default_sc.App_1.last_rx_msg->data[i] = msg->data[i];
249-
}
250-
if (msg->header.config == TIMESTAMP_PROTOCOL)
251-
{
252-
for (uint16_t i = 0; i < sizeof(time_luos_t); i++)
253-
{
254-
default_sc.App_1.last_rx_msg->data[msg->header.size + i] = msg->data[msg->header.size + i];
255-
}
256-
}
90+
memcpy(&default_sc.App_1.last_rx_msg, msg, sizeof(msg_t));
25791
}
25892

25993
/******************************************************************************
@@ -264,23 +98,7 @@ static void App_1_MsgHandler(service_t *service, msg_t *msg)
26498
******************************************************************************/
26599
static void App_2_MsgHandler(service_t *service, msg_t *msg)
266100
{
267-
default_sc.App_2.last_rx_msg->header.config = msg->header.config;
268-
default_sc.App_2.last_rx_msg->header.source = msg->header.source;
269-
default_sc.App_2.last_rx_msg->header.target = msg->header.target;
270-
default_sc.App_2.last_rx_msg->header.target_mode = msg->header.target_mode;
271-
default_sc.App_2.last_rx_msg->header.cmd = msg->header.cmd;
272-
default_sc.App_2.last_rx_msg->header.size = msg->header.size;
273-
for (uint16_t i = 0; i < msg->header.size; i++)
274-
{
275-
default_sc.App_2.last_rx_msg->data[i] = msg->data[i];
276-
}
277-
if (msg->header.config == TIMESTAMP_PROTOCOL)
278-
{
279-
for (uint16_t i = 0; i < sizeof(time_luos_t); i++)
280-
{
281-
default_sc.App_2.last_rx_msg->data[msg->header.size + i] = msg->data[msg->header.size + i];
282-
}
283-
}
101+
memcpy(&default_sc.App_2.last_rx_msg, msg, sizeof(msg_t));
284102
}
285103

286104
/******************************************************************************
@@ -291,23 +109,5 @@ static void App_2_MsgHandler(service_t *service, msg_t *msg)
291109
******************************************************************************/
292110
static void App_3_MsgHandler(service_t *service, msg_t *msg)
293111
{
294-
// Save last message
295-
default_sc.App_3.last_rx_msg->header.config = msg->header.config;
296-
default_sc.App_3.last_rx_msg->header.source = msg->header.source;
297-
default_sc.App_3.last_rx_msg->header.target = msg->header.target;
298-
default_sc.App_3.last_rx_msg->header.target_mode = msg->header.target_mode;
299-
default_sc.App_3.last_rx_msg->header.cmd = msg->header.cmd;
300-
default_sc.App_3.last_rx_msg->header.size = msg->header.size;
301-
for (uint16_t i = 0; i < msg->header.size; i++)
302-
{
303-
default_sc.App_3.last_rx_msg->data[i] = msg->data[i];
304-
}
305-
306-
if (msg->header.config == TIMESTAMP_PROTOCOL)
307-
{
308-
for (uint16_t i = 0; i < sizeof(time_luos_t); i++)
309-
{
310-
default_sc.App_3.last_rx_msg->data[msg->header.size + i] = msg->data[msg->header.size + i];
311-
}
312-
}
112+
memcpy(&default_sc.App_3.last_rx_msg, msg, sizeof(msg_t));
313113
}

0 commit comments

Comments
 (0)