Skip to content

Commit

Permalink
unit test for Streaming_SendStreamingSize function
Browse files Browse the repository at this point in the history
  • Loading branch information
Salem-Tho authored and JeromeGalan committed Jan 28, 2022
1 parent e1c6b0c commit a175b90
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 66 deletions.
102 changes: 101 additions & 1 deletion test/luos/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,105 @@
#include "main.h"
#include "unit_test.h"
#include <stdio.h>
#include <unistd.h>
#include <default_scenario.h>

extern default_scenario_t default_sc;

void unittest_Streaming_SendStreamingSize()
{
NEW_TEST_CASE("Sample size sent to streaming < Available samples");
{
uint32_t ExpectedMaxSize;

Reset_Context();
// Init default scenario context
Init_Context();
// Init variable
ExpectedMaxSize = 1;
// Add samples
Stream_AddAvailableSampleNB(default_sc.streamChannel1, 2);

NEW_STEP("Verify 1 byte is received when stream channels size is 2");
Luos_SendStreamingSize(default_sc.App_1.app, default_sc.App_1.tx_msg, default_sc.streamChannel1, 1);
Luos_Loop();
// Verify
TEST_ASSERT_EQUAL(ExpectedMaxSize, default_sc.App_2.last_rx_msg->header.size);
}

NEW_TEST_CASE("Sample size sent to streaming = available samples");
{
uint32_t ExpectedMaxSize;

Reset_Context();
// Init default scenario context
Init_Context();
// Init variable
ExpectedMaxSize = 2;
// Add samples
Stream_AddAvailableSampleNB(default_sc.streamChannel1, 2);

NEW_STEP("Verify 2 byte are received when stream channels size is 2");
Luos_SendStreamingSize(default_sc.App_1.app, default_sc.App_1.tx_msg, default_sc.streamChannel1, 2);
Luos_Loop();
// Verify
TEST_ASSERT_EQUAL(ExpectedMaxSize, default_sc.App_2.last_rx_msg->header.size);
}

NEW_TEST_CASE("Sample size sent to streaming > available samples");
{
uint32_t ExpectedMaxSize;

Reset_Context();
// Init default scenario context
Init_Context();

// Init variable
ExpectedMaxSize = 2;

NEW_STEP("Verify 2 byte are received when we try to send 3 bytes");
// Add samples
Stream_AddAvailableSampleNB(default_sc.streamChannel1, 2);
Luos_SendStreamingSize(default_sc.App_1.app, default_sc.App_1.tx_msg, default_sc.streamChannel1, 3);
Luos_Loop();
// Verify
TEST_ASSERT_EQUAL(ExpectedMaxSize, default_sc.App_2.last_rx_msg->header.size);
}

NEW_TEST_CASE("Limit test");
{
uint32_t ExpectedMaxSize;

Reset_Context();
// Init default scenario context
Init_Context();

// Init variable test case

NEW_STEP("Try to send 0 byte : it does nothing");

// Init variable new step
ExpectedMaxSize = 0;

// Add samples
Stream_AddAvailableSampleNB(default_sc.streamChannel1, 2);
Luos_SendStreamingSize(default_sc.App_1.app, default_sc.App_1.tx_msg, default_sc.streamChannel1, 0);
Luos_Loop();
// Verify
TEST_ASSERT_EQUAL(ExpectedMaxSize, default_sc.App_2.last_rx_msg->header.size);

NEW_STEP("try to send 128 byte the max size of a msg");

// Init variable
ExpectedMaxSize = 128;

// Add samples
Stream_AddAvailableSampleNB(default_sc.streamChannel1, 128);
Luos_SendStreamingSize(default_sc.App_1.app, default_sc.App_1.tx_msg, default_sc.streamChannel1, 128);
Luos_Loop();
// Verify
TEST_ASSERT_EQUAL(ExpectedMaxSize, default_sc.App_2.last_rx_msg->header.size);
}
}

int main(int argc, char **argv)
{
Expand Down
38 changes: 0 additions & 38 deletions test/luos/streaming.c

This file was deleted.

36 changes: 20 additions & 16 deletions test/resources/Scenarios/default_scenario.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
******************************************************************************/
msg_t transmit_msg[DUMMY_SERVICE_NUMBER];
msg_t receive_msg[DUMMY_SERVICE_NUMBER];
streaming_channel_t streamChan[DUMMY_SERVICE_NUMBER];
uint8_t stream_Buffer[DUMMY_SERVICE_NUMBER][STREAM_BUFFER_SIZE] = {0};
uint8_t stream_Buffer1[STREAM_BUFFER_SIZE] = {0};
uint8_t stream_Buffer2[STREAM_BUFFER_SIZE] = {0};
streaming_channel_t Default_StreamChannel1;
streaming_channel_t Default_StreamChannel2;

/*******************************************************************************
* Function
******************************************************************************/
extern void MsgAlloc_LuosTaskAlloc(ll_service_t *service_concerned_by_current_msg, msg_t *concerned_msg);

static void Reset_Context(void);
static void Init_Messages(void);
static void Reset_Streaming(void);
static void Init_Messages(void);
static void Detection(service_t *service);
static void App_1_MsgHandler(service_t *service, msg_t *msg);
static void App_2_MsgHandler(service_t *service, msg_t *msg);
Expand All @@ -51,10 +52,10 @@ void Init_Context(void)
default_sc.App_2.app = Luos_CreateService(App_2_MsgHandler, VOID_TYPE, "Dummy_App_2", revision);
default_sc.App_3.app = Luos_CreateService(App_3_MsgHandler, VOID_TYPE, "Dummy_App_3", revision);

Reset_Streaming();
// Create stream channels
default_sc.App_1.streamChannel = Stream_CreateStreamingChannel(&stream_Buffer[0], STREAM_BUFFER_SIZE, streamChan[0].data_size);
default_sc.App_1.streamChannel = Stream_CreateStreamingChannel(&stream_Buffer[1], STREAM_BUFFER_SIZE, streamChan[1].data_size);
default_sc.App_1.streamChannel = Stream_CreateStreamingChannel(&stream_Buffer[2], STREAM_BUFFER_SIZE, streamChan[2].data_size);
Default_StreamChannel1 = Stream_CreateStreamingChannel(stream_Buffer1, STREAM_BUFFER_SIZE, 1);
Default_StreamChannel1 = Stream_CreateStreamingChannel(stream_Buffer2, STREAM_BUFFER_SIZE, 1);

// Fill basic messages
Init_Messages();
Expand Down Expand Up @@ -82,11 +83,11 @@ void Init_Context(void)
******************************************************************************/
void Reset_Context(void)
{
Luos_ServicesClear();
RoutingTB_Erase(); // Delete RTB
Luos_Init();
Init_Messages();
Reset_Streaming();
Detection(default_sc.App_1.app);
}

/******************************************************************************
Expand All @@ -103,7 +104,7 @@ static void Detection(service_t *service)
}

/******************************************************************************
* @brief Messages are reseted to default values
* @brief Messages are reseted to default values
* @param None
* @return None
******************************************************************************/
Expand Down Expand Up @@ -170,20 +171,23 @@ void Init_Messages(void)
}

/******************************************************************************
* @brief Create a streaming channel
* @brief Create a streaming channel
* @param None
* @return None
******************************************************************************/
void Reset_Streaming(void)
static void Reset_Streaming(void)
{
// Stream Channel Creation
for (uint16_t i; i < DUMMY_SERVICE_NUMBER; i++)
// Stream Channel reset
Stream_ResetStreamingChannel(&Default_StreamChannel1);
Stream_ResetStreamingChannel(&Default_StreamChannel2);
default_sc.streamChannel1 = &Default_StreamChannel1;
default_sc.streamChannel2 = &Default_StreamChannel2;
for (uint16_t i = 0; i < STREAM_BUFFER_SIZE; i++)
{
Stream_ResetStreamingChannel(&streamChan[i]);
streamChan[i].data_size = 1;
stream_Buffer1[i] = (uint8_t)(i);
stream_Buffer2[i] = (uint8_t)(i);
}
}

/******************************************************************************
* @brief Loop Service App_1
* @param None
Expand Down
18 changes: 7 additions & 11 deletions test/resources/Scenarios/default_scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,24 @@
/*******************************************************************************
* Definitions
******************************************************************************/
#define DUMMY_SERVICE_NUMBER 3
#define STREAM_BUFFER_SIZE 1024
#define DUMMY_SERVICE_NUMBER 3
#define DUMMY_STREAMING_CHANNEL_NUMBER 3
#define STREAM_BUFFER_SIZE 1024

typedef struct
{
service_t *app;
msg_t *tx_msg;
msg_t *last_rx_msg;
streaming_channel_t streamChannel;
//next here
/*
* streaming_channel_t à remplir
* buffer cmd à remplir
* task à remplir
*/

} dummy_app_t;

typedef struct
{
dummy_app_t App_1;
dummy_app_t App_2;
dummy_app_t App_3;
streaming_channel_t *streamChannel1;
streaming_channel_t *streamChannel2;
} default_scenario_t;

typedef enum
Expand All @@ -44,9 +39,10 @@ default_scenario_t default_sc;
/*******************************************************************************
* Function
******************************************************************************/
void Reset_Context(void);
void Init_Context(void);
void App_1_Loop(void);
void App_2_Loop(void);
void App_3_Loop(void);

#endif //DEFAULT_SCENARIO_H
#endif // DEFAULT_SCENARIO_H

0 comments on commit a175b90

Please sign in to comment.