Skip to content

Commit

Permalink
Improve pub_sub unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed May 5, 2023
1 parent 3af5b9b commit e90893a
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 389 deletions.
6 changes: 3 additions & 3 deletions engine/IO/src/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void Filter_AddServiceId(uint16_t service_id, uint16_t service_number)
******************************************************************************/
void Filter_AddTopic(uint16_t topic_id)
{
LUOS_ASSERT(topic_id <= LAST_TOPIC);
LUOS_ASSERT(topic_id < LAST_TOPIC);
// Add 1 to the bit corresponding to the topic in multicast mask
filter_ctx.TopicMask[(topic_id / 8)] |= 1 << (topic_id - ((int)(topic_id / 8)) * 8);
}
Expand All @@ -100,7 +100,7 @@ void Filter_AddTopic(uint16_t topic_id)
******************************************************************************/
void Filter_RmTopic(uint16_t topic_id)
{
LUOS_ASSERT(topic_id <= LAST_TOPIC);
LUOS_ASSERT(topic_id < LAST_TOPIC);
// Remove 1 to the bit corresponding to the topic in multicast mask
filter_ctx.TopicMask[(topic_id / 8)] &= ~(1 << (topic_id - ((int)(topic_id / 8)) * 8));
}
Expand Down Expand Up @@ -144,7 +144,7 @@ _CRITICAL bool Filter_Topic(uint16_t topic_id)
{
uint8_t compare = 0;
// Make sure there is a topic that can be received by the node
if (topic_id <= LAST_TOPIC)
if (topic_id < LAST_TOPIC)
{
compare = topic_id - ((topic_id / 8) * 8);
// Search if topic exists in mask
Expand Down
14 changes: 6 additions & 8 deletions engine/core/src/pub_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
******************************************************************************/
uint8_t PubSub_IsTopicSubscribed(service_t *service, uint16_t topic_id)
{
LUOS_ASSERT((topic_id < LAST_TOPIC)
&& (service != NULL));
unsigned char i;
for (i = 0; i < service->last_topic_position; i++)
{
Expand All @@ -48,8 +50,8 @@ uint8_t PubSub_IsTopicSubscribed(service_t *service, uint16_t topic_id)
error_return_t Luos_Subscribe(service_t *service, uint16_t topic)
{
// Assert if we add a topic that is greater than the max topic value
LUOS_ASSERT(topic <= LAST_TOPIC);
LUOS_ASSERT(service != 0);
LUOS_ASSERT((topic < LAST_TOPIC)
&& (service != 0));

// Put this topic in the multicast bank
Filter_AddTopic(topic);
Expand All @@ -72,19 +74,15 @@ error_return_t Luos_Subscribe(service_t *service, uint16_t topic)
******************************************************************************/
error_return_t Luos_Unsubscribe(service_t *service, uint16_t topic)
{
LUOS_ASSERT(topic <= LAST_TOPIC);
LUOS_ASSERT(service != 0);
LUOS_ASSERT((topic < LAST_TOPIC)
&& (service != 0));

error_return_t err = FAILED;
// Delete topic from service list
for (uint16_t i = 0; i < service->last_topic_position; i++)
{
if (service->topic_list[i] == topic)
{
if (service->last_topic_position >= LAST_TOPIC)
{
break;
}
memcpy(&service->topic_list[i], &service->topic_list[i + 1], service->last_topic_position - i);
service->last_topic_position--;
err = SUCCEED;
Expand Down
211 changes: 0 additions & 211 deletions test/test_robus/main.c

This file was deleted.

6 changes: 0 additions & 6 deletions test/test_robus/main.h

This file was deleted.

Loading

0 comments on commit e90893a

Please sign in to comment.