add ring queue/message queue/mail queue, binary heap/priority queue/priority message queue/priority mail queue
1. remove the old msg queue and queue: i. msg queue is not a common and reusable/flexible component(need user to config the msg pool size and this componet can only be used by tos_queue) ii. tos_queue can only deliver the pointer message(cannot do a memory buffer deliver) 2. add ring queue(tos_ring_q) componet rinq queue can be reused by tos_chr_fifi/tos_msg_q/tos_mail_q as the foundational data container 3. add message queue(tos_msg_q) a little like the old queue mechanism, supply the capability to deliver a pointer message 4. add mail queue(tos_mail_q) supply the capability to deliver a memory buffer 5. add binary heap(tos_bin_heap) the basement componet to implement priority queue 6. add priority queue(tos_prio_q) can be reused by the priority message/mail queue as the foundational data container. 7. add priority message queue(tos_prio_msg_q) a message(pointer) deliver mechanism, supply the capability of delivering the message with priority(message with higher priority comes faster to the pender than with lower) 8. add priority mail queue(tos_prio_mail_q) a mail(memory buffer) deliver mechanism, supply the capability of delivering the mail with priority(mail with higher priority comes faster to the pender than with lower)
This commit is contained in:
@@ -6,10 +6,15 @@
|
||||
#include "test/test_task.h"
|
||||
#include "test/test_mutex.h"
|
||||
#include "test/test_sem.h"
|
||||
#include "test/test_queue.h"
|
||||
#include "test/test_msg_queue.h"
|
||||
#include "test/test_mmblk.h"
|
||||
#include "test/test_fifo.h"
|
||||
#include "test/test_char_fifo.h"
|
||||
#include "test/test_ring_queue.h"
|
||||
#include "test/test_mail_queue.h"
|
||||
#include "test/test_message_queue.h"
|
||||
#include "test/test_binary_heap.h"
|
||||
#include "test/test_priority_queue.h"
|
||||
#include "test/test_priority_message_queue.h"
|
||||
#include "test/test_priority_mail_queue.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
5
test/include/test/test_binary_heap.h
Normal file
5
test/include/test/test_binary_heap.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#ifndef _TEST_BINARY_HEAP_H_
|
||||
#define _TEST_BINARY_HEAP_H_
|
||||
|
||||
#endif
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#ifndef _TEST_FIFO_H_
|
||||
#define _TEST_FIFO_H_
|
||||
#ifndef _TEST_CHAR_FIFO_H_
|
||||
#define _TEST_CHAR_FIFO_H_
|
||||
|
||||
#define FIFO_BUFFER_SIZE 5
|
||||
|
||||
extern k_fifo_t test_fifo_00;
|
||||
extern k_fifo_t test_fifo_01;
|
||||
extern k_fifo_t test_fifo_02;
|
||||
extern k_chr_fifo_t test_fifo_00;
|
||||
extern k_chr_fifo_t test_fifo_01;
|
||||
extern k_chr_fifo_t test_fifo_02;
|
||||
|
||||
extern uint8_t fifo_buffer_00[FIFO_BUFFER_SIZE];
|
||||
extern uint8_t fifo_buffer_01[FIFO_BUFFER_SIZE];
|
5
test/include/test/test_mail_queue.h
Normal file
5
test/include/test/test_mail_queue.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#ifndef _TEST_MAIL_QUEUE_H_
|
||||
#define _TEST_MAIL_QUEUE_H_
|
||||
|
||||
#endif
|
||||
|
5
test/include/test/test_message_queue.h
Normal file
5
test/include/test/test_message_queue.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#ifndef _TEST_MSG_QUEUE_H_
|
||||
#define _TEST_MSG_QUEUE_H_
|
||||
|
||||
#endif
|
||||
|
@@ -1,9 +0,0 @@
|
||||
#ifndef _TEST_MSG_QUEUE_H_
|
||||
#define _TEST_MSG_QUEUE_H_
|
||||
|
||||
extern k_msg_queue_t test_msg_queue_00;
|
||||
extern k_msg_queue_t test_msg_queue_01;
|
||||
extern k_msg_queue_t test_msg_queue_02;
|
||||
|
||||
#endif
|
||||
|
5
test/include/test/test_priority_mail_queue.h
Normal file
5
test/include/test/test_priority_mail_queue.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#ifndef _TEST_PRIORITY_MAIL_QUEUE_H_
|
||||
#define _TEST_PRIORITY_MAIL_QUEUE_H_
|
||||
|
||||
#endif
|
||||
|
6
test/include/test/test_priority_message_queue.h
Normal file
6
test/include/test/test_priority_message_queue.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _TEST_PRIORITY_MESSAGE_QUEUE_H_
|
||||
#define _TEST_PRIORITY_MESSAGE_QUEUE_H_
|
||||
|
||||
|
||||
#endif
|
||||
|
5
test/include/test/test_priority_queue.h
Normal file
5
test/include/test/test_priority_queue.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#ifndef _TEST_PRIORITY_QUEUE_H_
|
||||
#define _TEST_PRIORITY_QUEUE_H_
|
||||
|
||||
#endif
|
||||
|
@@ -1,9 +0,0 @@
|
||||
#ifndef _TEST_QUEUE_H_
|
||||
#define _TEST_QUEUE_H_
|
||||
|
||||
extern k_queue_t test_queue_00;
|
||||
extern k_queue_t test_queue_01;
|
||||
extern k_queue_t test_queue_02;
|
||||
|
||||
#endif
|
||||
|
5
test/include/test/test_ring_queue.h
Normal file
5
test/include/test/test_ring_queue.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#ifndef _TEST_RING_QUEUE_H_
|
||||
#define _TEST_RING_QUEUE_H_
|
||||
|
||||
#endif
|
||||
|
@@ -13,6 +13,16 @@ typedef enum test_context_en {
|
||||
TEST_CONTEXT_07,
|
||||
} test_context_t;
|
||||
|
||||
typedef struct test_mail_st {
|
||||
int a;
|
||||
char *b;
|
||||
char c;
|
||||
} test_mail_t;
|
||||
|
||||
typedef test_mail_t test_bin_heap_item_t;
|
||||
|
||||
typedef test_mail_t test_prio_q_item_t;
|
||||
|
||||
extern void (*test_task_hook)(void);
|
||||
|
||||
extern volatile uint32_t test_count;
|
||||
@@ -21,9 +31,11 @@ extern k_err_t test_err;
|
||||
|
||||
extern test_context_t test_context;
|
||||
|
||||
extern void *test_msg_addr;
|
||||
extern void *test_msg;
|
||||
|
||||
extern size_t test_msg_size;
|
||||
extern test_mail_t test_mail;
|
||||
|
||||
extern size_t test_mail_size;
|
||||
|
||||
extern k_event_flag_t test_event_match;
|
||||
|
||||
@@ -33,7 +45,11 @@ void test_event_set(k_event_flag_t event_match);
|
||||
|
||||
void test_msg_reset(void);
|
||||
|
||||
void test_msg_set(void *msg_addr, size_t msg_size);
|
||||
void test_msg_set(void *msg);
|
||||
|
||||
void test_mail_reset(void);
|
||||
|
||||
void test_mail_set(void *mail, size_t mail_size);
|
||||
|
||||
void test_err_reset(void);
|
||||
|
||||
|
543
test/suit_binary_heap.c
Normal file
543
test/suit_binary_heap.c
Normal file
@@ -0,0 +1,543 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
SUITE(suit_binary_heap);
|
||||
|
||||
k_bin_heap_t test_bin_heap_00;
|
||||
k_bin_heap_t test_bin_heap_01;
|
||||
|
||||
#define TEST_BIN_HEAP_ITEM_CNT 16
|
||||
uint8_t test_bin_heap_pool_00[sizeof(test_bin_heap_item_t) * TEST_BIN_HEAP_ITEM_CNT];
|
||||
uint8_t test_bin_heap_pool_01[sizeof(test_bin_heap_item_t) * TEST_BIN_HEAP_ITEM_CNT];
|
||||
|
||||
uint8_t test_bin_heap_int_pool_00[sizeof(int) * TEST_BIN_HEAP_ITEM_CNT];
|
||||
uint8_t test_bin_heap_int_pool_01[sizeof(int) * TEST_BIN_HEAP_ITEM_CNT];
|
||||
|
||||
int test_bin_heap_cmp_dummy(void *first, void *second)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_bin_heap_min_cmp_dummy(void *first, void *second)
|
||||
{
|
||||
test_bin_heap_item_t *item_first, *item_second;
|
||||
|
||||
item_first = (test_bin_heap_item_t *)first;
|
||||
item_second = (test_bin_heap_item_t *)second;
|
||||
|
||||
if (item_first->a < item_second->a) {
|
||||
return K_TRUE;
|
||||
}
|
||||
return K_FALSE;
|
||||
}
|
||||
|
||||
int test_bin_heap_max_cmp_dummy(void *first, void *second)
|
||||
{
|
||||
test_bin_heap_item_t *item_first, *item_second;
|
||||
|
||||
item_first = (test_bin_heap_item_t *)first;
|
||||
item_second = (test_bin_heap_item_t *)second;
|
||||
|
||||
if (item_first->a > item_second->a) {
|
||||
return K_TRUE;
|
||||
}
|
||||
return K_FALSE;
|
||||
}
|
||||
|
||||
|
||||
int test_bin_heap_min_int_cmp_dummy(void *first, void *second)
|
||||
{
|
||||
int *item_first, *item_second;
|
||||
|
||||
item_first = (int *)first;
|
||||
item_second = (int *)second;
|
||||
|
||||
if (*item_first < *item_second) {
|
||||
return K_TRUE;
|
||||
}
|
||||
return K_FALSE;
|
||||
}
|
||||
|
||||
int test_bin_heap_max_int_cmp_dummy(void *first, void *second)
|
||||
{
|
||||
int *item_first, *item_second;
|
||||
|
||||
item_first = (int *)first;
|
||||
item_second = (int *)second;
|
||||
|
||||
if (*item_first > *item_second) {
|
||||
return K_TRUE;
|
||||
}
|
||||
return K_FALSE;
|
||||
}
|
||||
|
||||
TEST test_tos_binary_heap_create(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
err = tos_bin_heap_create(&test_bin_heap_00, test_bin_heap_pool_00, TEST_BIN_HEAP_ITEM_CNT, sizeof(test_bin_heap_item_t), K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
err = tos_bin_heap_create(K_NULL, test_bin_heap_pool_00, TEST_BIN_HEAP_ITEM_CNT, sizeof(test_bin_heap_item_t), test_bin_heap_cmp_dummy);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
err = tos_bin_heap_create(&test_bin_heap_00, test_bin_heap_pool_00, TEST_BIN_HEAP_ITEM_CNT, sizeof(test_bin_heap_item_t), test_bin_heap_cmp_dummy);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_bin_heap_create(&test_bin_heap_01, test_bin_heap_pool_01, TEST_BIN_HEAP_ITEM_CNT, sizeof(test_bin_heap_item_t), test_bin_heap_cmp_dummy);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_bin_heap_destroy(&test_bin_heap_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_bin_heap_destroy(&test_bin_heap_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_binary_heap_destroy(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
err = tos_bin_heap_destroy(&test_bin_heap_00);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_INVALID);
|
||||
#endif
|
||||
|
||||
err = tos_bin_heap_destroy(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_binary_heap_min_push(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
test_bin_heap_item_t items[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
{ 2, "222", '2' },
|
||||
{ 4, "444", '4' },
|
||||
{ 1, "111", '1' },
|
||||
{ 7, "777", '7' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 2, "222", '2' },
|
||||
{ 0, "000", '0' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 5, "555", '5' },
|
||||
{ 12, "ccc", 'c' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 3, "333", '3' },
|
||||
{ 6, "666", '6' },
|
||||
{ 8, "888", '8' },
|
||||
};
|
||||
test_bin_heap_item_t items_should[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
{ 0, "000", '0' },
|
||||
{ 1, "111", '1' },
|
||||
{ 2, "222", '2' },
|
||||
{ 2, "222", '2' },
|
||||
{ 3, "333", '3' },
|
||||
{ 4, "444", '4' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 6, "666", '6' },
|
||||
{ 7, "777", '7' },
|
||||
{ 8, "888", '8' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 12, "ccc", 'c' },
|
||||
};
|
||||
test_bin_heap_item_t item_popped;
|
||||
size_t item_size;
|
||||
|
||||
// we gonna build a min heap
|
||||
err = tos_bin_heap_create(&test_bin_heap_00, test_bin_heap_pool_00, TEST_BIN_HEAP_ITEM_CNT, sizeof(test_bin_heap_item_t), test_bin_heap_min_cmp_dummy);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_push(&test_bin_heap_00, &items[i], sizeof(test_bin_heap_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_full(&test_bin_heap_00));
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_pop(&test_bin_heap_00, &item_popped, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(test_bin_heap_item_t));
|
||||
ASSERT_EQ(item_popped.a, items_should[i].a);
|
||||
ASSERT_EQ(strcmp(item_popped.b, items_should[i].b), 0);
|
||||
ASSERT_EQ(item_popped.c, items_should[i].c);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_empty(&test_bin_heap_00));
|
||||
|
||||
err = tos_bin_heap_destroy(&test_bin_heap_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_binary_heap_max_push(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
test_bin_heap_item_t items[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
{ 2, "222", '2' },
|
||||
{ 4, "444", '4' },
|
||||
{ 1, "111", '1' },
|
||||
{ 7, "777", '7' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 2, "222", '2' },
|
||||
{ 0, "000", '0' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 5, "555", '5' },
|
||||
{ 12, "ccc", 'c' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 3, "333", '3' },
|
||||
{ 6, "666", '6' },
|
||||
{ 8, "888", '8' },
|
||||
};
|
||||
test_bin_heap_item_t items_should[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
{ 12, "ccc", 'c' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 9, "999", '9' },
|
||||
{ 8, "888", '8' },
|
||||
{ 7, "777", '7' },
|
||||
{ 6, "666", '6' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 4, "444", '4' },
|
||||
{ 3, "333", '3' },
|
||||
{ 2, "222", '2' },
|
||||
{ 2, "222", '2' },
|
||||
{ 1, "111", '1' },
|
||||
{ 0, "000", '0' },
|
||||
};
|
||||
test_bin_heap_item_t item_popped;
|
||||
size_t item_size;
|
||||
|
||||
// we gonna build a max heap
|
||||
err = tos_bin_heap_create(&test_bin_heap_00, test_bin_heap_pool_00, TEST_BIN_HEAP_ITEM_CNT, sizeof(test_bin_heap_item_t), test_bin_heap_max_cmp_dummy);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_push(&test_bin_heap_00, &items[i], sizeof(test_bin_heap_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_full(&test_bin_heap_00));
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_pop(&test_bin_heap_00, &item_popped, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(test_bin_heap_item_t));
|
||||
ASSERT_EQ(item_popped.a, items_should[i].a);
|
||||
ASSERT_EQ(strcmp(item_popped.b, items_should[i].b), 0);
|
||||
ASSERT_EQ(item_popped.c, items_should[i].c);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_empty(&test_bin_heap_00));
|
||||
|
||||
err = tos_bin_heap_destroy(&test_bin_heap_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_binary_heap_min_int_push(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
int items[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
7,
|
||||
5,
|
||||
5,
|
||||
2,
|
||||
0,
|
||||
9,
|
||||
10,
|
||||
5,
|
||||
12,
|
||||
11,
|
||||
3,
|
||||
6,
|
||||
8,
|
||||
};
|
||||
int items_should[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
};
|
||||
int item_popped;
|
||||
size_t item_size;
|
||||
|
||||
// we gonna build a min heap
|
||||
err = tos_bin_heap_create(&test_bin_heap_00, test_bin_heap_int_pool_00, TEST_BIN_HEAP_ITEM_CNT, sizeof(int), test_bin_heap_min_int_cmp_dummy);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_push(&test_bin_heap_00, &items[i], sizeof(int));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_full(&test_bin_heap_00));
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_pop(&test_bin_heap_00, &item_popped, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(int));
|
||||
ASSERT_EQ(item_popped, items_should[i]);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_empty(&test_bin_heap_00));
|
||||
|
||||
err = tos_bin_heap_destroy(&test_bin_heap_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_binary_heap_max_int_push(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
int items[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
7,
|
||||
5,
|
||||
5,
|
||||
2,
|
||||
0,
|
||||
9,
|
||||
10,
|
||||
5,
|
||||
12,
|
||||
11,
|
||||
3,
|
||||
6,
|
||||
8,
|
||||
};
|
||||
int items_should[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
12,
|
||||
11,
|
||||
10,
|
||||
9,
|
||||
8,
|
||||
7,
|
||||
6,
|
||||
5,
|
||||
5,
|
||||
5,
|
||||
4,
|
||||
3,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
0,
|
||||
};
|
||||
int item_popped;
|
||||
size_t item_size;
|
||||
|
||||
// we gonna build a max heap
|
||||
err = tos_bin_heap_create(&test_bin_heap_00, test_bin_heap_int_pool_00, TEST_BIN_HEAP_ITEM_CNT, sizeof(int), test_bin_heap_max_int_cmp_dummy);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_push(&test_bin_heap_00, &items[i], sizeof(int));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_full(&test_bin_heap_00));
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_pop(&test_bin_heap_00, &item_popped, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(int));
|
||||
ASSERT_EQ(item_popped, items_should[i]);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_empty(&test_bin_heap_00));
|
||||
|
||||
err = tos_bin_heap_destroy(&test_bin_heap_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_binary_heap_push_limit(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
test_bin_heap_item_t items[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
{ 2, "222", '2' },
|
||||
{ 4, "444", '4' },
|
||||
{ 1, "111", '1' },
|
||||
{ 7, "777", '7' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 2, "222", '2' },
|
||||
{ 0, "000", '0' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 5, "555", '5' },
|
||||
{ 12, "ccc", 'c' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 3, "333", '3' },
|
||||
{ 6, "666", '6' },
|
||||
{ 8, "888", '8' },
|
||||
};
|
||||
test_bin_heap_item_t items_should[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
{ 12, "ccc", 'c' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 9, "999", '9' },
|
||||
{ 8, "888", '8' },
|
||||
{ 7, "777", '7' },
|
||||
{ 6, "666", '6' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 4, "444", '4' },
|
||||
{ 3, "333", '3' },
|
||||
{ 2, "222", '2' },
|
||||
{ 2, "222", '2' },
|
||||
{ 1, "111", '1' },
|
||||
{ 0, "000", '0' },
|
||||
};
|
||||
test_bin_heap_item_t item_popped;
|
||||
size_t item_size;
|
||||
|
||||
// we gonna build a max heap
|
||||
err = tos_bin_heap_create(&test_bin_heap_00, test_bin_heap_pool_00, TEST_BIN_HEAP_ITEM_CNT, sizeof(test_bin_heap_item_t), test_bin_heap_max_cmp_dummy);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_push(&test_bin_heap_00, &items[i], sizeof(test_bin_heap_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_full(&test_bin_heap_00));
|
||||
|
||||
err = tos_bin_heap_push(&test_bin_heap_00, &items[0], sizeof(test_bin_heap_item_t));
|
||||
ASSERT_EQ(err, K_ERR_BIN_HEAP_FULL);
|
||||
|
||||
ASSERT(tos_bin_heap_is_full(&test_bin_heap_00));
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_pop(&test_bin_heap_00, &item_popped, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(test_bin_heap_item_t));
|
||||
ASSERT_EQ(item_popped.a, items_should[i].a);
|
||||
ASSERT_EQ(strcmp(item_popped.b, items_should[i].b), 0);
|
||||
ASSERT_EQ(item_popped.c, items_should[i].c);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_empty(&test_bin_heap_00));
|
||||
|
||||
err = tos_bin_heap_pop(&test_bin_heap_00, &item_popped, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_BIN_HEAP_EMPTY);
|
||||
|
||||
ASSERT(tos_bin_heap_is_empty(&test_bin_heap_00));
|
||||
|
||||
err = tos_bin_heap_destroy(&test_bin_heap_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_binary_flush(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
test_bin_heap_item_t items[TEST_BIN_HEAP_ITEM_CNT] = {
|
||||
{ 2, "222", '2' },
|
||||
{ 4, "444", '4' },
|
||||
{ 1, "111", '1' },
|
||||
{ 7, "777", '7' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 2, "222", '2' },
|
||||
{ 0, "000", '0' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 5, "555", '5' },
|
||||
{ 12, "ccc", 'c' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 3, "333", '3' },
|
||||
{ 6, "666", '6' },
|
||||
{ 8, "888", '8' },
|
||||
};
|
||||
test_bin_heap_item_t item_popped;
|
||||
size_t item_size;
|
||||
|
||||
// we gonna build a max heap
|
||||
err = tos_bin_heap_create(&test_bin_heap_00, test_bin_heap_pool_00, TEST_BIN_HEAP_ITEM_CNT, sizeof(test_bin_heap_item_t), test_bin_heap_max_cmp_dummy);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_BIN_HEAP_ITEM_CNT; ++i) {
|
||||
err = tos_bin_heap_push(&test_bin_heap_00, &items[i], sizeof(test_bin_heap_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_bin_heap_is_full(&test_bin_heap_00));
|
||||
|
||||
err = tos_bin_heap_flush(&test_bin_heap_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT(tos_bin_heap_is_empty(&test_bin_heap_00));
|
||||
|
||||
err = tos_bin_heap_pop(&test_bin_heap_00, &item_popped, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_BIN_HEAP_EMPTY);
|
||||
|
||||
err = tos_bin_heap_push(&test_bin_heap_00, &item_popped, sizeof(test_bin_heap_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_bin_heap_destroy(&test_bin_heap_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suit_binary_heap)
|
||||
{
|
||||
RUN_TEST(test_tos_binary_heap_create);
|
||||
RUN_TEST(test_tos_binary_heap_destroy);
|
||||
RUN_TEST(test_tos_binary_heap_min_push);
|
||||
RUN_TEST(test_tos_binary_heap_max_push);
|
||||
RUN_TEST(test_tos_binary_heap_min_int_push);
|
||||
RUN_TEST(test_tos_binary_heap_max_int_push);
|
||||
RUN_TEST(test_tos_binary_heap_push_limit);
|
||||
RUN_TEST(test_tos_binary_flush);
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
SUITE(suit_fifo);
|
||||
SUITE(suit_char_fifo);
|
||||
|
||||
k_fifo_t test_fifo_00;
|
||||
k_fifo_t test_fifo_01;
|
||||
k_fifo_t test_fifo_02;
|
||||
k_chr_fifo_t test_fifo_00;
|
||||
k_chr_fifo_t test_fifo_01;
|
||||
k_chr_fifo_t test_fifo_02;
|
||||
|
||||
uint8_t fifo_buffer_00[FIFO_BUFFER_SIZE];
|
||||
uint8_t fifo_buffer_01[FIFO_BUFFER_SIZE];
|
||||
@@ -18,22 +18,22 @@ TEST test_tos_fifo_create(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
err = tos_fifo_create(&test_fifo_00, fifo_buffer_00, sizeof(fifo_buffer_00));
|
||||
err = tos_chr_fifo_create(&test_fifo_00, fifo_buffer_00, sizeof(fifo_buffer_00));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_fifo_create(&test_fifo_01, fifo_buffer_01, sizeof(fifo_buffer_01));
|
||||
err = tos_chr_fifo_create(&test_fifo_01, fifo_buffer_01, sizeof(fifo_buffer_01));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_fifo_create(&test_fifo_02, fifo_buffer_02, sizeof(fifo_buffer_02));
|
||||
err = tos_chr_fifo_create(&test_fifo_02, fifo_buffer_02, sizeof(fifo_buffer_02));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_fifo_destroy(&test_fifo_00);
|
||||
err = tos_chr_fifo_destroy(&test_fifo_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_fifo_destroy(&test_fifo_01);
|
||||
err = tos_chr_fifo_destroy(&test_fifo_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_fifo_destroy(&test_fifo_02);
|
||||
err = tos_chr_fifo_destroy(&test_fifo_02);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
@@ -44,11 +44,11 @@ TEST test_tos_fifo_destory(void)
|
||||
k_err_t err;
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
err = tos_fifo_destroy(&test_fifo_00);
|
||||
err = tos_chr_fifo_destroy(&test_fifo_00);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_INVALID);
|
||||
#endif
|
||||
|
||||
err = tos_fifo_destroy(K_NULL);
|
||||
err = tos_chr_fifo_destroy(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
PASS();
|
||||
@@ -60,27 +60,27 @@ TEST test_tos_fifo_char_push(void)
|
||||
int i = 0;
|
||||
uint8_t data;
|
||||
|
||||
err = tos_fifo_create(&test_fifo_00, fifo_buffer_00, sizeof(fifo_buffer_00));
|
||||
err = tos_chr_fifo_create(&test_fifo_00, fifo_buffer_00, sizeof(fifo_buffer_00));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < FIFO_BUFFER_SIZE; ++i) {
|
||||
err = tos_fifo_push(&test_fifo_00, 'a' + i);
|
||||
err = tos_chr_fifo_push(&test_fifo_00, 'a' + i);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
err = tos_fifo_push(&test_fifo_00, 'z');
|
||||
ASSERT_EQ(err, K_ERR_FIFO_FULL);
|
||||
err = tos_chr_fifo_push(&test_fifo_00, 'z');
|
||||
ASSERT_EQ(err, K_ERR_RING_Q_FULL);
|
||||
|
||||
for (i = 0; i < FIFO_BUFFER_SIZE; ++i) {
|
||||
err = tos_fifo_pop(&test_fifo_00, &data);
|
||||
err = tos_chr_fifo_pop(&test_fifo_00, &data);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(data, 'a' + i);
|
||||
}
|
||||
|
||||
err = tos_fifo_pop(&test_fifo_00, &data);
|
||||
ASSERT_EQ(err, K_ERR_FIFO_EMPTY);
|
||||
err = tos_chr_fifo_pop(&test_fifo_00, &data);
|
||||
ASSERT_EQ(err, K_ERR_RING_Q_EMPTY);
|
||||
|
||||
err = tos_fifo_destroy(&test_fifo_00);
|
||||
err = tos_chr_fifo_destroy(&test_fifo_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
@@ -94,27 +94,27 @@ TEST test_tos_fifo_stream_push(void)
|
||||
uint8_t stream_dummy[1] = { 'z' };
|
||||
uint8_t stream_pop[FIFO_BUFFER_SIZE];
|
||||
|
||||
err = tos_fifo_create(&test_fifo_00, fifo_buffer_00, sizeof(fifo_buffer_00));
|
||||
err = tos_chr_fifo_create(&test_fifo_00, fifo_buffer_00, sizeof(fifo_buffer_00));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
count = tos_fifo_push_stream(&test_fifo_00, &stream[0], FIFO_BUFFER_SIZE);
|
||||
count = tos_chr_fifo_push_stream(&test_fifo_00, &stream[0], FIFO_BUFFER_SIZE);
|
||||
ASSERT_EQ(count, FIFO_BUFFER_SIZE);
|
||||
|
||||
count = tos_fifo_push_stream(&test_fifo_00, &stream_dummy[0], 1);
|
||||
count = tos_chr_fifo_push_stream(&test_fifo_00, &stream_dummy[0], 1);
|
||||
ASSERT_EQ(count, 0);
|
||||
ASSERT_EQ(tos_fifo_is_full(&test_fifo_00), K_TRUE);
|
||||
ASSERT_EQ(tos_chr_fifo_is_full(&test_fifo_00), K_TRUE);
|
||||
|
||||
count = tos_fifo_pop_stream(&test_fifo_00, &stream_pop[0], FIFO_BUFFER_SIZE);
|
||||
count = tos_chr_fifo_pop_stream(&test_fifo_00, &stream_pop[0], FIFO_BUFFER_SIZE);
|
||||
ASSERT_EQ(count, FIFO_BUFFER_SIZE);
|
||||
|
||||
count = tos_fifo_pop_stream(&test_fifo_00, &stream_pop[0], 1);
|
||||
count = tos_chr_fifo_pop_stream(&test_fifo_00, &stream_pop[0], 1);
|
||||
ASSERT_EQ(count, 0);
|
||||
ASSERT_EQ(tos_fifo_is_empty(&test_fifo_00), K_TRUE);
|
||||
ASSERT_EQ(tos_chr_fifo_is_empty(&test_fifo_00), K_TRUE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suit_fifo)
|
||||
SUITE(suit_char_fifo)
|
||||
{
|
||||
RUN_TEST(test_tos_fifo_create);
|
||||
RUN_TEST(test_tos_fifo_destory);
|
404
test/suit_mail_queue.c
Normal file
404
test/suit_mail_queue.c
Normal file
@@ -0,0 +1,404 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
SUITE(suit_mail_queue);
|
||||
|
||||
k_mail_q_t test_mail_q_00;
|
||||
k_mail_q_t test_mail_q_01;
|
||||
k_mail_q_t test_mail_q_02;
|
||||
|
||||
#define TEST_MAIL_Q_MAIL_CNT 5
|
||||
uint8_t test_mail_q_pool_00[sizeof(test_mail_t) * TEST_MAIL_Q_MAIL_CNT];
|
||||
uint8_t test_mail_q_pool_01[sizeof(test_mail_t) * TEST_MAIL_Q_MAIL_CNT];
|
||||
uint8_t test_mail_q_pool_02[sizeof(test_mail_t) * TEST_MAIL_Q_MAIL_CNT];
|
||||
|
||||
static void test_mail_queue_pend_task_entry(void *arg)
|
||||
{
|
||||
k_err_t err;
|
||||
k_mail_q_t *mail_q;
|
||||
test_mail_t mail;
|
||||
size_t mail_size;
|
||||
|
||||
mail_q = arg ? (k_mail_q_t *)arg : K_NULL;
|
||||
while (K_TRUE) {
|
||||
test_context_set(TEST_CONTEXT_00);
|
||||
err = tos_mail_q_pend(mail_q, &mail, &mail_size, TOS_TIME_FOREVER);
|
||||
test_context_set(TEST_CONTEXT_01);
|
||||
test_err_set(err);
|
||||
if (err == K_ERR_NONE) {
|
||||
test_mail_set(&mail, mail_size);
|
||||
}
|
||||
|
||||
if (err == K_ERR_PEND_DESTROY) {
|
||||
tos_task_delay(TOS_TIME_FOREVER - 1);
|
||||
}
|
||||
|
||||
if (test_task_hook) {
|
||||
test_task_hook();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_mail_queue_pend_timed_task_entry(void *arg)
|
||||
{
|
||||
k_err_t err;
|
||||
k_mail_q_t *mail_q;
|
||||
test_mail_t mail;
|
||||
size_t mail_size;
|
||||
|
||||
mail_q = arg ? (k_mail_q_t *)arg : K_NULL;
|
||||
|
||||
while (K_TRUE) {
|
||||
test_context_set(TEST_CONTEXT_00);
|
||||
err = tos_mail_q_pend(mail_q, &mail, &mail_size, (k_tick_t)2000u);
|
||||
test_context_set(TEST_CONTEXT_01);
|
||||
test_err_set(err);
|
||||
if (err == K_ERR_NONE) {
|
||||
test_mail_set(&mail, mail_size);
|
||||
}
|
||||
|
||||
if (err == K_ERR_PEND_DESTROY) {
|
||||
tos_task_delay(TOS_TIME_FOREVER - 1);
|
||||
}
|
||||
|
||||
if (test_task_hook) {
|
||||
test_task_hook();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST test_tos_mail_queue_create(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
err = tos_mail_q_create(&test_mail_q_00, test_mail_q_pool_00, TEST_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_create(&test_mail_q_01, test_mail_q_pool_01, TEST_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_create(&test_mail_q_02, test_mail_q_pool_02, TEST_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_destroy(&test_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_destroy(&test_mail_q_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_destroy(&test_mail_q_02);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_mail_queue_destroy(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
err = tos_mail_q_destroy(&test_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_INVALID);
|
||||
#endif
|
||||
|
||||
err = tos_mail_q_destroy(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_mail_queue_pend(void)
|
||||
{
|
||||
k_err_t err;
|
||||
test_mail_t mail = {
|
||||
0xDEADBEEF,
|
||||
"test_mail",
|
||||
'T',
|
||||
};
|
||||
|
||||
test_mail_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_mail_q_create(&test_mail_q_00, test_mail_q_pool_00, TEST_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task
|
||||
err = tos_task_create(&test_task_00, "test_task", test_mail_queue_pend_task_entry,
|
||||
(void *)(&test_mail_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 0);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
|
||||
tos_mail_q_post(&test_mail_q_00, &mail, sizeof(test_mail_t));
|
||||
|
||||
ASSERT_EQ(test_count, 1);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
|
||||
ASSERT_EQ(test_mail.a, mail.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail.c);
|
||||
|
||||
tos_mail_q_destroy(&test_mail_q_00);
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_DESTROY);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_mail_queue_pend_timed(void)
|
||||
{
|
||||
k_err_t err;
|
||||
k_tick_t begin;
|
||||
test_mail_t mail = {
|
||||
0xDEADBEEF,
|
||||
"test_mail",
|
||||
'T',
|
||||
};
|
||||
|
||||
test_mail_reset();
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_mail_q_create(&test_mail_q_00, test_mail_q_pool_00, TEST_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_00, "test_task", test_mail_queue_pend_timed_task_entry,
|
||||
(void *)(&test_mail_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// test_task_00 has a higher priority, so it will get running after the task create immediately
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
|
||||
begin = tos_systick_get();
|
||||
while (tos_systick_get() - begin < (k_tick_t)(2000u + 20u)) {
|
||||
tos_task_yield();
|
||||
}
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 1);
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_TIMEOUT);
|
||||
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 2);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_mail.a, mail.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail.c);
|
||||
|
||||
err = tos_mail_q_destroy(&test_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_DESTROY);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_mail_queue_post_all(void)
|
||||
{
|
||||
k_err_t err;
|
||||
test_mail_t mail = {
|
||||
0xDEADBEEF,
|
||||
"test_mail",
|
||||
'T',
|
||||
};
|
||||
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_mail_q_create(&test_mail_q_00, test_mail_q_pool_00, TEST_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_mail_queue_pend_task_entry,
|
||||
(void *)(&test_mail_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_01, "test_task_01", test_mail_queue_pend_task_entry,
|
||||
(void *)(&test_mail_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_01, sizeof(test_task_stack_01),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_02, "test_task_02", test_mail_queue_pend_task_entry,
|
||||
(void *)(&test_mail_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_02, sizeof(test_task_stack_02),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 0);
|
||||
|
||||
err = tos_mail_q_post_all(&test_mail_q_00, &mail, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 3);
|
||||
ASSERT_EQ(test_mail.a, mail.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail.c);
|
||||
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 4);
|
||||
ASSERT_EQ(test_mail.a, mail.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail.c);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_task_destroy(&test_task_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_task_destroy(&test_task_02);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_destroy(&test_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_mail_queue_flush(void)
|
||||
{
|
||||
k_err_t err;
|
||||
test_mail_t mail0 = {
|
||||
0xDEADBEE0,
|
||||
"test_mail0",
|
||||
'T',
|
||||
};
|
||||
test_mail_t mail1 = {
|
||||
0xDEADBEE1,
|
||||
"test_mail1",
|
||||
'U',
|
||||
};
|
||||
test_mail_t mail2 = {
|
||||
0xDEADBEE2,
|
||||
"test_mail2",
|
||||
'V',
|
||||
};
|
||||
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_mail_q_create(&test_mail_q_00, test_mail_q_pool_00, TEST_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a lower priority than current task(numerically bigger)
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_mail_queue_pend_task_entry,
|
||||
(void *)(&test_mail_q_00), k_curr_task->prio + 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail0, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail1, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail2, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// we have post three mail, but we flush them, test_task_00 should not receive any message
|
||||
err = tos_mail_q_flush(&test_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
tos_task_delay(500);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 0);
|
||||
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail0, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail1, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
tos_task_delay(500);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_count, 2);
|
||||
|
||||
// test_task_00 is pending, this post will send mail0 to test_task_00
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail0, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail1, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_post(&test_mail_q_00, &mail2, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// mail1/mail2 has not been received yet, queue flush will discard these two message
|
||||
err = tos_mail_q_flush(&test_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
tos_task_delay(500);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_count, 3);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_mail_q_destroy(&test_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suit_mail_queue)
|
||||
{
|
||||
RUN_TEST(test_tos_mail_queue_create);
|
||||
RUN_TEST(test_tos_mail_queue_destroy);
|
||||
RUN_TEST(test_tos_mail_queue_pend);
|
||||
RUN_TEST(test_tos_mail_queue_pend_timed);
|
||||
RUN_TEST(test_tos_mail_queue_post_all);
|
||||
RUN_TEST(test_tos_mail_queue_flush);
|
||||
}
|
||||
|
@@ -5,27 +5,31 @@
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
SUITE(suit_queue);
|
||||
SUITE(suit_message_queue);
|
||||
|
||||
k_queue_t test_queue_00;
|
||||
k_queue_t test_queue_01;
|
||||
k_queue_t test_queue_02;
|
||||
k_msg_q_t test_msg_q_00;
|
||||
k_msg_q_t test_msg_q_01;
|
||||
k_msg_q_t test_msg_q_02;
|
||||
|
||||
static void test_queue_pend_task_entry(void *arg)
|
||||
#define TEST_MESSAGE_Q_MSG_CNT 5
|
||||
uint8_t test_msg_q_pool_00[sizeof(void *) * TEST_MESSAGE_Q_MSG_CNT];
|
||||
uint8_t test_msg_q_pool_01[sizeof(void *) * TEST_MESSAGE_Q_MSG_CNT];
|
||||
uint8_t test_msg_q_pool_02[sizeof(void *) * TEST_MESSAGE_Q_MSG_CNT];
|
||||
|
||||
static void test_message_queue_pend_task_entry(void *arg)
|
||||
{
|
||||
k_err_t err;
|
||||
k_queue_t *queue;
|
||||
void *msg_addr;
|
||||
size_t msg_size;
|
||||
k_msg_q_t *msg_q;
|
||||
void *msg;
|
||||
|
||||
queue = arg ? (k_queue_t *)arg : K_NULL;
|
||||
msg_q = arg ? (k_msg_q_t *)arg : K_NULL;
|
||||
while (K_TRUE) {
|
||||
test_context_set(TEST_CONTEXT_00);
|
||||
err = tos_queue_pend(queue, &msg_addr, &msg_size, TOS_TIME_FOREVER);
|
||||
err = tos_msg_q_pend(msg_q, &msg, TOS_TIME_FOREVER);
|
||||
test_context_set(TEST_CONTEXT_01);
|
||||
test_err_set(err);
|
||||
if (err == K_ERR_NONE) {
|
||||
test_msg_set(msg_addr, msg_size);
|
||||
test_msg_set(msg);
|
||||
}
|
||||
|
||||
if (err == K_ERR_PEND_DESTROY) {
|
||||
@@ -38,22 +42,21 @@ static void test_queue_pend_task_entry(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
static void test_queue_pend_timed_task_entry(void *arg)
|
||||
static void test_message_queue_pend_timed_task_entry(void *arg)
|
||||
{
|
||||
k_err_t err;
|
||||
k_queue_t *queue;
|
||||
void *msg_addr;
|
||||
size_t msg_size;
|
||||
k_msg_q_t *msg_q;
|
||||
void *msg;
|
||||
|
||||
queue = arg ? (k_queue_t *)arg : K_NULL;
|
||||
msg_q = arg ? (k_msg_q_t *)arg : K_NULL;
|
||||
|
||||
while (K_TRUE) {
|
||||
test_context_set(TEST_CONTEXT_00);
|
||||
err = tos_queue_pend(queue, &msg_addr, &msg_size, (k_tick_t)2000u);
|
||||
err = tos_msg_q_pend(msg_q, &msg, (k_tick_t)2000u);
|
||||
test_context_set(TEST_CONTEXT_01);
|
||||
test_err_set(err);
|
||||
if (err == K_ERR_NONE) {
|
||||
test_msg_set(msg_addr, msg_size);
|
||||
test_msg_set(msg);
|
||||
}
|
||||
|
||||
if (err == K_ERR_PEND_DESTROY) {
|
||||
@@ -66,62 +69,62 @@ static void test_queue_pend_timed_task_entry(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
TEST test_tos_queue_create(void)
|
||||
TEST test_tos_message_queue_create(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
err = tos_queue_create(&test_queue_00);
|
||||
err = tos_msg_q_create(&test_msg_q_00, test_msg_q_pool_00, TEST_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_create(&test_queue_01);
|
||||
err = tos_msg_q_create(&test_msg_q_01, test_msg_q_pool_01, TEST_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_create(&test_queue_02);
|
||||
err = tos_msg_q_create(&test_msg_q_02, test_msg_q_pool_02, TEST_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_destroy(&test_queue_00);
|
||||
err = tos_msg_q_destroy(&test_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_destroy(&test_queue_01);
|
||||
err = tos_msg_q_destroy(&test_msg_q_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_destroy(&test_queue_02);
|
||||
err = tos_msg_q_destroy(&test_msg_q_02);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_queue_destroy(void)
|
||||
TEST test_tos_message_queue_destroy(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
err = tos_queue_destroy(&test_queue_00);
|
||||
err = tos_msg_q_destroy(&test_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_INVALID);
|
||||
#endif
|
||||
|
||||
err = tos_queue_destroy(K_NULL);
|
||||
err = tos_msg_q_destroy(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_queue_pend(void)
|
||||
TEST test_tos_message_queue_pend(void)
|
||||
{
|
||||
k_err_t err;
|
||||
uint32_t msg;
|
||||
void *msg = (void *)0xDEADBEEF;
|
||||
|
||||
test_msg_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_queue_create(&test_queue_00);
|
||||
err = tos_msg_q_create(&test_msg_q_00, test_msg_q_pool_00, TEST_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task
|
||||
err = tos_task_create(&test_task_00, "test_task", test_queue_pend_task_entry,
|
||||
(void *)(&test_queue_00), k_curr_task->prio - 1,
|
||||
err = tos_task_create(&test_task_00, "test_task", test_message_queue_pend_task_entry,
|
||||
(void *)(&test_msg_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
@@ -129,16 +132,15 @@ TEST test_tos_queue_pend(void)
|
||||
ASSERT_EQ(test_count, 0);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
|
||||
tos_queue_post(&test_queue_00, (void *)&msg, sizeof(uint32_t));
|
||||
tos_msg_q_post(&test_msg_q_00, msg);
|
||||
|
||||
ASSERT_EQ(test_count, 1);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
|
||||
ASSERT_EQ(test_msg_addr, (void *)&msg);
|
||||
ASSERT_EQ(test_msg_size, sizeof(uint32_t));
|
||||
ASSERT_EQ(test_msg, msg);
|
||||
|
||||
tos_queue_destroy(&test_queue_00);
|
||||
tos_msg_q_destroy(&test_msg_q_00);
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_DESTROY);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
|
||||
@@ -148,11 +150,11 @@ TEST test_tos_queue_pend(void)
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_queue_pend_timed(void)
|
||||
TEST test_tos_message_queue_pend_timed(void)
|
||||
{
|
||||
k_err_t err;
|
||||
k_tick_t begin;
|
||||
uint32_t msg;
|
||||
void *msg = (void *)0xDEADBEEF;
|
||||
|
||||
test_msg_reset();
|
||||
test_err_reset();
|
||||
@@ -160,12 +162,12 @@ TEST test_tos_queue_pend_timed(void)
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_queue_create(&test_queue_00);
|
||||
err = tos_msg_q_create(&test_msg_q_00, test_msg_q_pool_00, TEST_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_00, "test_task", test_queue_pend_timed_task_entry,
|
||||
(void *)(&test_queue_00), k_curr_task->prio - 1,
|
||||
err = tos_task_create(&test_task_00, "test_task", test_message_queue_pend_timed_task_entry,
|
||||
(void *)(&test_msg_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
@@ -182,20 +184,18 @@ TEST test_tos_queue_pend_timed(void)
|
||||
ASSERT_EQ(test_count, 1);
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_TIMEOUT);
|
||||
|
||||
ASSERT_EQ(test_msg_addr, K_NULL);
|
||||
ASSERT_EQ(test_msg_size, 0);
|
||||
ASSERT_EQ(test_msg, K_NULL);
|
||||
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 2);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_msg_addr, (void *)&msg);
|
||||
ASSERT_EQ(test_msg_size, sizeof(uint32_t));
|
||||
ASSERT_EQ(test_msg, msg);
|
||||
|
||||
err = tos_queue_destroy(&test_queue_00);
|
||||
err = tos_msg_q_destroy(&test_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
@@ -209,51 +209,53 @@ TEST test_tos_queue_pend_timed(void)
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_queue_post_all(void)
|
||||
TEST test_tos_message_queue_post_all(void)
|
||||
{
|
||||
k_err_t err;
|
||||
uint32_t msg;
|
||||
void *msg = (void *)0xDEADBEEF;
|
||||
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_queue_create(&test_queue_00);
|
||||
err = tos_msg_q_create(&test_msg_q_00, test_msg_q_pool_00, TEST_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_queue_pend_task_entry,
|
||||
(void *)(&test_queue_00), k_curr_task->prio - 1,
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_message_queue_pend_task_entry,
|
||||
(void *)(&test_msg_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_01, "test_task_01", test_queue_pend_task_entry,
|
||||
(void *)(&test_queue_00), k_curr_task->prio - 1,
|
||||
err = tos_task_create(&test_task_01, "test_task_01", test_message_queue_pend_task_entry,
|
||||
(void *)(&test_msg_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_01, sizeof(test_task_stack_01),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_02, "test_task_02", test_queue_pend_task_entry,
|
||||
(void *)(&test_queue_00), k_curr_task->prio - 1,
|
||||
err = tos_task_create(&test_task_02, "test_task_02", test_message_queue_pend_task_entry,
|
||||
(void *)(&test_msg_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_02, sizeof(test_task_stack_02),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 0);
|
||||
|
||||
err = tos_queue_post_all(&test_queue_00, (void *)&msg, sizeof(uint32_t));
|
||||
err = tos_msg_q_post_all(&test_msg_q_00, msg);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 3);
|
||||
ASSERT_EQ(test_msg, msg);
|
||||
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 4);
|
||||
ASSERT_EQ(test_msg, msg);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
@@ -264,7 +266,7 @@ TEST test_tos_queue_post_all(void)
|
||||
err = tos_task_destroy(&test_task_02);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_destroy(&test_queue_00);
|
||||
err = tos_msg_q_destroy(&test_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
@@ -272,37 +274,37 @@ TEST test_tos_queue_post_all(void)
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_queue_flush(void)
|
||||
TEST test_tos_message_queue_flush(void)
|
||||
{
|
||||
k_err_t err;
|
||||
uint32_t msg0, msg1, msg2;
|
||||
void *msg0 = (void *)0xDEADBEE0, *msg1 = (void *)0xDEADBEE1, *msg2 = (void *)0xDEADBEE2;
|
||||
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_queue_create(&test_queue_00);
|
||||
err = tos_msg_q_create(&test_msg_q_00, test_msg_q_pool_00, TEST_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a lower priority than current task(numerically bigger)
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_queue_pend_task_entry,
|
||||
(void *)(&test_queue_00), k_curr_task->prio + 1,
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_message_queue_pend_task_entry,
|
||||
(void *)(&test_msg_q_00), k_curr_task->prio + 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg0, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg1, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg1);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg2, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg2);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// we have post three msg, but we flush them, test_task_00 should not receive any message
|
||||
err = tos_queue_flush(&test_queue_00);
|
||||
err = tos_msg_q_flush(&test_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
@@ -311,10 +313,10 @@ TEST test_tos_queue_flush(void)
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 0);
|
||||
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg0, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg1, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg1);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
@@ -325,17 +327,17 @@ TEST test_tos_queue_flush(void)
|
||||
ASSERT_EQ(test_count, 2);
|
||||
|
||||
// test_task_00 is pending, this post will send msg0 to test_task_00
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg0, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg1, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg1);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_post(&test_queue_00, (void *)&msg2, sizeof(uint32_t));
|
||||
err = tos_msg_q_post(&test_msg_q_00, msg2);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// msg1/msg2 has not been received yet, queue flush will discard these two message
|
||||
err = tos_queue_flush(&test_queue_00);
|
||||
err = tos_msg_q_flush(&test_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
@@ -348,7 +350,7 @@ TEST test_tos_queue_flush(void)
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_queue_destroy(&test_queue_00);
|
||||
err = tos_msg_q_destroy(&test_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
@@ -356,13 +358,13 @@ TEST test_tos_queue_flush(void)
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suit_queue)
|
||||
SUITE(suit_message_queue)
|
||||
{
|
||||
RUN_TEST(test_tos_queue_create);
|
||||
RUN_TEST(test_tos_queue_destroy);
|
||||
RUN_TEST(test_tos_queue_pend);
|
||||
RUN_TEST(test_tos_queue_pend_timed);
|
||||
RUN_TEST(test_tos_queue_post_all);
|
||||
RUN_TEST(test_tos_queue_flush);
|
||||
RUN_TEST(test_tos_message_queue_create);
|
||||
RUN_TEST(test_tos_message_queue_destroy);
|
||||
RUN_TEST(test_tos_message_queue_pend);
|
||||
RUN_TEST(test_tos_message_queue_pend_timed);
|
||||
RUN_TEST(test_tos_message_queue_post_all);
|
||||
RUN_TEST(test_tos_message_queue_flush);
|
||||
}
|
||||
|
@@ -1,207 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
SUITE(suit_msg_queue);
|
||||
|
||||
k_msg_queue_t test_msg_queue_00;
|
||||
k_msg_queue_t test_msg_queue_01;
|
||||
k_msg_queue_t test_msg_queue_02;
|
||||
|
||||
TEST test_tos_msg_queue_create(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
err = tos_msg_queue_create(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_msg_queue_create(&test_msg_queue_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_msg_queue_create(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
err = tos_msg_queue_destroy(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_msg_queue_destroy(&test_msg_queue_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_msg_queue_destroy(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
err = tos_msg_queue_destroy(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_INVALID);
|
||||
#endif
|
||||
|
||||
err = tos_msg_queue_destroy(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_msg_queue_fifo(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
uint32_t msgs[3] = { 1, 2, 3 };
|
||||
void *msg_received = K_NULL;
|
||||
size_t msg_size = 0;
|
||||
|
||||
err = tos_msg_queue_create(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT(TOS_CFG_MSG_POOL_SIZE >= 3);
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
err = tos_msg_queue_put(&test_msg_queue_00, (void *)(&msgs[i]), sizeof(uint32_t), TOS_OPT_MSG_PUT_FIFO);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
err = tos_msg_queue_get(&test_msg_queue_00, (void **)&msg_received, &msg_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(msg_size, sizeof(uint32_t));
|
||||
ASSERT_EQ(msg_received, &msgs[i]);
|
||||
}
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_msg_queue_lifo(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
uint32_t msgs[3] = { 1, 2, 3 };
|
||||
void *msg_received = K_NULL;
|
||||
size_t msg_size = 0;
|
||||
|
||||
err = tos_msg_queue_create(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT(TOS_CFG_MSG_POOL_SIZE >= 3);
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
err = tos_msg_queue_put(&test_msg_queue_00, (void *)(&msgs[i]), sizeof(uint32_t), TOS_OPT_MSG_PUT_LIFO);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
err = tos_msg_queue_get(&test_msg_queue_00, (void **)&msg_received, &msg_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(msg_size, sizeof(uint32_t));
|
||||
ASSERT_EQ(msg_received, &msgs[2 - i]);
|
||||
}
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_msg_queue_fifo_limit(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
uint32_t msg_send;
|
||||
void *msg_received = K_NULL;
|
||||
size_t msg_size = 0;
|
||||
|
||||
err = tos_msg_queue_create(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (; i < TOS_CFG_MSG_POOL_SIZE; ++i) {
|
||||
err = tos_msg_queue_put(&test_msg_queue_00, (void *)(&msg_send), sizeof(uint32_t), TOS_OPT_MSG_PUT_FIFO);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
err = tos_msg_queue_put(&test_msg_queue_00, (void *)(&msg_send), sizeof(uint32_t), TOS_OPT_MSG_PUT_FIFO);
|
||||
ASSERT_EQ(err, K_ERR_MSG_QUEUE_FULL);
|
||||
|
||||
for (i = 0; i < TOS_CFG_MSG_POOL_SIZE; ++i) {
|
||||
err = tos_msg_queue_get(&test_msg_queue_00, (void **)&msg_received, &msg_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
err = tos_msg_queue_get(&test_msg_queue_00, (void **)&msg_received, &msg_size);
|
||||
ASSERT_EQ(err, K_ERR_MSG_QUEUE_EMPTY);
|
||||
|
||||
err = tos_msg_queue_destroy(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_msg_queue_lifo_limit(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
uint32_t msg_send;
|
||||
void *msg_received = K_NULL;
|
||||
size_t msg_size = 0;
|
||||
|
||||
err = tos_msg_queue_create(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (; i < TOS_CFG_MSG_POOL_SIZE; ++i) {
|
||||
err = tos_msg_queue_put(&test_msg_queue_00, (void *)(&msg_send), sizeof(uint32_t), TOS_OPT_MSG_PUT_LIFO);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
err = tos_msg_queue_put(&test_msg_queue_00, (void *)(&msg_send), sizeof(uint32_t), TOS_OPT_MSG_PUT_LIFO);
|
||||
ASSERT_EQ(err, K_ERR_MSG_QUEUE_FULL);
|
||||
|
||||
for (i = 0; i < TOS_CFG_MSG_POOL_SIZE; ++i) {
|
||||
err = tos_msg_queue_get(&test_msg_queue_00, (void **)&msg_received, &msg_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
err = tos_msg_queue_get(&test_msg_queue_00, (void **)&msg_received, &msg_size);
|
||||
ASSERT_EQ(err, K_ERR_MSG_QUEUE_EMPTY);
|
||||
|
||||
err = tos_msg_queue_destroy(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_msg_queue_flush(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
uint32_t msgs[3] = { 1, 2, 3 };
|
||||
void *msg_received = K_NULL;
|
||||
size_t msg_size = 0;
|
||||
|
||||
err = tos_msg_queue_create(&test_msg_queue_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT(TOS_CFG_MSG_POOL_SIZE >= 3);
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
err = tos_msg_queue_put(&test_msg_queue_00, (void *)(&msgs[i]), sizeof(uint32_t), TOS_OPT_MSG_PUT_FIFO);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
tos_msg_queue_flush(&test_msg_queue_00);
|
||||
|
||||
err = tos_msg_queue_get(&test_msg_queue_00, (void **)&msg_received, &msg_size);
|
||||
ASSERT_EQ(err, K_ERR_MSG_QUEUE_EMPTY);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suit_msg_queue)
|
||||
{
|
||||
RUN_TEST(test_tos_msg_queue_create);
|
||||
RUN_TEST(test_tos_msg_queue_destroy);
|
||||
RUN_TEST(test_tos_msg_queue_fifo);
|
||||
RUN_TEST(test_tos_msg_queue_lifo);
|
||||
RUN_TEST(test_tos_msg_queue_fifo_limit);
|
||||
RUN_TEST(test_tos_msg_queue_lifo_limit);
|
||||
RUN_TEST(test_tos_msg_queue_flush);
|
||||
}
|
||||
|
422
test/suit_priority_mail_queue.c
Normal file
422
test/suit_priority_mail_queue.c
Normal file
@@ -0,0 +1,422 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
SUITE(suit_priority_mail_queue);
|
||||
|
||||
k_prio_mail_q_t test_prio_mail_q_00;
|
||||
k_prio_mail_q_t test_prio_mail_q_01;
|
||||
k_prio_mail_q_t test_prio_mail_q_02;
|
||||
|
||||
#define TEST_PRIO_MAIL_Q_MAIL_CNT 5
|
||||
uint8_t test_prio_mail_q_pool_00[sizeof(test_mail_t) * TEST_PRIO_MAIL_Q_MAIL_CNT];
|
||||
uint8_t test_prio_mail_q_pool_01[sizeof(test_mail_t) * TEST_PRIO_MAIL_Q_MAIL_CNT];
|
||||
uint8_t test_prio_mail_q_pool_02[sizeof(test_mail_t) * TEST_PRIO_MAIL_Q_MAIL_CNT];
|
||||
|
||||
static void test_prio_mail_queue_pend_task_entry(void *arg)
|
||||
{
|
||||
k_err_t err;
|
||||
k_prio_mail_q_t *mail_q;
|
||||
test_mail_t mail;
|
||||
size_t mail_size;
|
||||
|
||||
mail_q = arg ? (k_prio_mail_q_t *)arg : K_NULL;
|
||||
while (K_TRUE) {
|
||||
test_context_set(TEST_CONTEXT_00);
|
||||
err = tos_prio_mail_q_pend(mail_q, &mail, &mail_size, TOS_TIME_FOREVER);
|
||||
test_context_set(TEST_CONTEXT_01);
|
||||
test_err_set(err);
|
||||
if (err == K_ERR_NONE) {
|
||||
test_mail_set(&mail, mail_size);
|
||||
tos_task_yield(); // yeild to test main
|
||||
}
|
||||
|
||||
if (err == K_ERR_PEND_DESTROY) {
|
||||
tos_task_delay(TOS_TIME_FOREVER - 1);
|
||||
}
|
||||
|
||||
if (test_task_hook) {
|
||||
test_task_hook();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_prio_mail_queue_pend_timed_task_entry(void *arg)
|
||||
{
|
||||
k_err_t err;
|
||||
k_prio_mail_q_t *mail_q;
|
||||
test_mail_t mail;
|
||||
size_t mail_size;
|
||||
|
||||
mail_q = arg ? (k_prio_mail_q_t *)arg : K_NULL;
|
||||
|
||||
while (K_TRUE) {
|
||||
test_context_set(TEST_CONTEXT_00);
|
||||
err = tos_prio_mail_q_pend(mail_q, &mail, &mail_size, (k_tick_t)2000u);
|
||||
test_context_set(TEST_CONTEXT_01);
|
||||
test_err_set(err);
|
||||
if (err == K_ERR_NONE) {
|
||||
test_mail_set(&mail, mail_size);
|
||||
}
|
||||
|
||||
if (err == K_ERR_PEND_DESTROY) {
|
||||
tos_task_delay(TOS_TIME_FOREVER - 1);
|
||||
}
|
||||
|
||||
if (test_task_hook) {
|
||||
test_task_hook();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST test_tos_prio_mail_queue_create(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
err = tos_prio_mail_q_create(&test_prio_mail_q_00, test_prio_mail_q_pool_00, TEST_PRIO_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_create(&test_prio_mail_q_01, test_prio_mail_q_pool_01, TEST_PRIO_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_create(&test_prio_mail_q_02, test_prio_mail_q_pool_02, TEST_PRIO_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_destroy(&test_prio_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_destroy(&test_prio_mail_q_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_destroy(&test_prio_mail_q_02);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_prio_mail_queue_destroy(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
err = tos_prio_mail_q_destroy(&test_prio_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_INVALID);
|
||||
#endif
|
||||
|
||||
err = tos_prio_mail_q_destroy(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_prio_mail_queue_pend(void)
|
||||
{
|
||||
k_err_t err;
|
||||
test_mail_t mail0 = {
|
||||
0xDEAD0000,
|
||||
"test_mail0",
|
||||
'T',
|
||||
};
|
||||
test_mail_t mail1 = {
|
||||
0xDEAD1111,
|
||||
"test_mail1",
|
||||
'U',
|
||||
};
|
||||
test_mail_t mail2 = {
|
||||
0xDEAD2222,
|
||||
"test_mail2",
|
||||
'V',
|
||||
};
|
||||
|
||||
test_mail_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_prio_mail_q_create(&test_prio_mail_q_00, test_prio_mail_q_pool_00, TEST_PRIO_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with the same priority than current task
|
||||
err = tos_task_create(&test_task_00, "test_task", test_prio_mail_queue_pend_task_entry,
|
||||
(void *)(&test_prio_mail_q_00), k_curr_task->prio,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 0);
|
||||
ASSERT(test_context != TEST_CONTEXT_00);
|
||||
|
||||
// we post mail2, mail1, mail0 with the certain priority, the test_task should receive mail according the priority
|
||||
tos_prio_mail_q_post(&test_prio_mail_q_00, &mail2, sizeof(test_mail_t), 2);
|
||||
tos_prio_mail_q_post(&test_prio_mail_q_00, &mail1, sizeof(test_mail_t), 1);
|
||||
tos_prio_mail_q_post(&test_prio_mail_q_00, &mail0, sizeof(test_mail_t), 0);
|
||||
|
||||
tos_task_yield(); // yeild to test_task
|
||||
|
||||
ASSERT_EQ(test_count, 0);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
|
||||
ASSERT_EQ(test_mail.a, mail0.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail0.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail0.c);
|
||||
tos_task_yield(); // yeild to test_task
|
||||
|
||||
ASSERT_EQ(test_count, 1);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
|
||||
ASSERT_EQ(test_mail.a, mail1.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail1.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail1.c);
|
||||
tos_task_yield(); // yeild to test_task
|
||||
|
||||
ASSERT_EQ(test_mail.a, mail2.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail2.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail2.c);
|
||||
tos_task_yield(); // yeild to test_task
|
||||
|
||||
tos_prio_mail_q_destroy(&test_prio_mail_q_00);
|
||||
tos_task_yield(); // yeild to test_task
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_DESTROY);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_prio_mail_queue_pend_timed(void)
|
||||
{
|
||||
k_err_t err;
|
||||
k_tick_t begin;
|
||||
test_mail_t mail = {
|
||||
0xDEADBEEF,
|
||||
"test_mail",
|
||||
'T',
|
||||
};
|
||||
|
||||
test_mail_reset();
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_prio_mail_q_create(&test_prio_mail_q_00, test_prio_mail_q_pool_00, TEST_PRIO_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_00, "test_task", test_prio_mail_queue_pend_timed_task_entry,
|
||||
(void *)(&test_prio_mail_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// test_task_00 has a higher priority, so it will get running after the task create immediately
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
|
||||
begin = tos_systick_get();
|
||||
while (tos_systick_get() - begin < (k_tick_t)(2000u + 20u)) {
|
||||
tos_task_yield();
|
||||
}
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 1);
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_TIMEOUT);
|
||||
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 2);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_mail.a, mail.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail.c);
|
||||
|
||||
err = tos_prio_mail_q_destroy(&test_prio_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_DESTROY);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_prio_mail_queue_post_all(void)
|
||||
{
|
||||
k_err_t err;
|
||||
test_mail_t mail = {
|
||||
0xDEADBEEF,
|
||||
"test_mail",
|
||||
'T',
|
||||
};
|
||||
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_prio_mail_q_create(&test_prio_mail_q_00, test_prio_mail_q_pool_00, TEST_PRIO_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_prio_mail_queue_pend_task_entry,
|
||||
(void *)(&test_prio_mail_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_01, "test_task_01", test_prio_mail_queue_pend_task_entry,
|
||||
(void *)(&test_prio_mail_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_01, sizeof(test_task_stack_01),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_02, "test_task_02", test_prio_mail_queue_pend_task_entry,
|
||||
(void *)(&test_prio_mail_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_02, sizeof(test_task_stack_02),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 0);
|
||||
|
||||
err = tos_prio_mail_q_post_all(&test_prio_mail_q_00, &mail, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 3);
|
||||
ASSERT_EQ(test_mail.a, mail.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail.c);
|
||||
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 4);
|
||||
ASSERT_EQ(test_mail.a, mail.a);
|
||||
ASSERT_EQ(strcmp(test_mail.b, mail.b), 0);
|
||||
ASSERT_EQ(test_mail.c, mail.c);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_task_destroy(&test_task_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_task_destroy(&test_task_02);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_destroy(&test_prio_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_prio_mail_queue_flush(void)
|
||||
{
|
||||
k_err_t err;
|
||||
void *mail0 = (void *)0xDEADBEE0, *mail1 = (void *)0xDEADBEE1, *mail2 = (void *)0xDEADBEE2;
|
||||
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_prio_mail_q_create(&test_prio_mail_q_00, test_prio_mail_q_pool_00, TEST_PRIO_MAIL_Q_MAIL_CNT, sizeof(test_mail_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a lower priority than current task(numerically bigger)
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_prio_mail_queue_pend_task_entry,
|
||||
(void *)(&test_prio_mail_q_00), k_curr_task->prio + 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail0, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail1, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail2, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// we have post three mail, but we flush them, test_task_00 should not receive any message
|
||||
err = tos_prio_mail_q_flush(&test_prio_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
tos_task_delay(500);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 0);
|
||||
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail0, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail1, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
tos_task_delay(500);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_count, 2);
|
||||
|
||||
// test_task_00 is pending, this post will send mail0 to test_task_00
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail0, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail1, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_post(&test_prio_mail_q_00, &mail2, sizeof(test_mail_t), 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// mail1/mail2 has not been received yet, queue flush will discard these two message
|
||||
err = tos_prio_mail_q_flush(&test_prio_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
tos_task_delay(500);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_count, 3);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_mail_q_destroy(&test_prio_mail_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suit_priority_mail_queue)
|
||||
{
|
||||
RUN_TEST(test_tos_prio_mail_queue_create);
|
||||
RUN_TEST(test_tos_prio_mail_queue_destroy);
|
||||
RUN_TEST(test_tos_prio_mail_queue_pend);
|
||||
RUN_TEST(test_tos_prio_mail_queue_pend_timed);
|
||||
RUN_TEST(test_tos_prio_mail_queue_post_all);
|
||||
RUN_TEST(test_tos_prio_mail_queue_flush);
|
||||
}
|
||||
|
392
test/suit_priority_message_queue.c
Normal file
392
test/suit_priority_message_queue.c
Normal file
@@ -0,0 +1,392 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
SUITE(suit_priority_message_queue);
|
||||
|
||||
k_prio_msg_q_t test_prio_msg_q_00;
|
||||
k_prio_msg_q_t test_prio_msg_q_01;
|
||||
k_prio_msg_q_t test_prio_msg_q_02;
|
||||
|
||||
#define TEST_PRIO_MESSAGE_Q_MSG_CNT 5
|
||||
uint8_t test_prio_msg_q_pool_00[sizeof(void *) * TEST_PRIO_MESSAGE_Q_MSG_CNT];
|
||||
uint8_t test_prio_msg_q_pool_01[sizeof(void *) * TEST_PRIO_MESSAGE_Q_MSG_CNT];
|
||||
uint8_t test_prio_msg_q_pool_02[sizeof(void *) * TEST_PRIO_MESSAGE_Q_MSG_CNT];
|
||||
|
||||
static void test_priority_message_queue_pend_task_entry(void *arg)
|
||||
{
|
||||
k_err_t err;
|
||||
k_prio_msg_q_t *prio_msg_q;
|
||||
void *msg;
|
||||
|
||||
prio_msg_q = arg ? (k_prio_msg_q_t *)arg : K_NULL;
|
||||
while (K_TRUE) {
|
||||
test_context_set(TEST_CONTEXT_00);
|
||||
err = tos_prio_msg_q_pend(prio_msg_q, &msg, TOS_TIME_FOREVER);
|
||||
test_context_set(TEST_CONTEXT_01);
|
||||
test_err_set(err);
|
||||
if (err == K_ERR_NONE) {
|
||||
test_msg_set(msg);
|
||||
tos_task_yield(); // yield to test main task
|
||||
}
|
||||
|
||||
if (err == K_ERR_PEND_DESTROY) {
|
||||
tos_task_delay(TOS_TIME_FOREVER - 1);
|
||||
}
|
||||
|
||||
if (test_task_hook) {
|
||||
test_task_hook();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_priority_message_queue_pend_timed_task_entry(void *arg)
|
||||
{
|
||||
k_err_t err;
|
||||
k_prio_msg_q_t *prio_msg_q;
|
||||
void *msg;
|
||||
|
||||
prio_msg_q = arg ? (k_prio_msg_q_t *)arg : K_NULL;
|
||||
|
||||
while (K_TRUE) {
|
||||
test_context_set(TEST_CONTEXT_00);
|
||||
err = tos_prio_msg_q_pend(prio_msg_q, &msg, (k_tick_t)2000u);
|
||||
test_context_set(TEST_CONTEXT_01);
|
||||
test_err_set(err);
|
||||
if (err == K_ERR_NONE) {
|
||||
test_msg_set(msg);
|
||||
}
|
||||
|
||||
if (err == K_ERR_PEND_DESTROY) {
|
||||
tos_task_delay(TOS_TIME_FOREVER - 1);
|
||||
}
|
||||
|
||||
if (test_task_hook) {
|
||||
test_task_hook();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST test_tos_priority_message_queue_create(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
err = tos_prio_msg_q_create(&test_prio_msg_q_00, test_prio_msg_q_pool_00, TEST_PRIO_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_create(&test_prio_msg_q_01, test_prio_msg_q_pool_01, TEST_PRIO_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_create(&test_prio_msg_q_02, test_prio_msg_q_pool_02, TEST_PRIO_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_destroy(&test_prio_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_destroy(&test_prio_msg_q_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_destroy(&test_prio_msg_q_02);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_message_queue_destroy(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
err = tos_prio_msg_q_destroy(&test_prio_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_INVALID);
|
||||
#endif
|
||||
|
||||
err = tos_prio_msg_q_destroy(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_message_queue_pend(void)
|
||||
{
|
||||
k_err_t err;
|
||||
void *msg0 = (void *)0xDEAD0000, *msg1 = (void *)0xDEAD1111, *msg2 = (void *)0xDEAD2222;
|
||||
|
||||
test_msg_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_prio_msg_q_create(&test_prio_msg_q_00, test_prio_msg_q_pool_00, TEST_PRIO_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with the same priority than current task
|
||||
err = tos_task_create(&test_task_00, "test_task", test_priority_message_queue_pend_task_entry,
|
||||
(void *)(&test_prio_msg_q_00), k_curr_task->prio,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 0);
|
||||
ASSERT(test_context != TEST_CONTEXT_00); // test_task is not running yet
|
||||
|
||||
// we post msg2, msg1, msg0 with the certain priority, the test_task should receive message according the priority
|
||||
tos_prio_msg_q_post(&test_prio_msg_q_00, msg2, 2);
|
||||
tos_prio_msg_q_post(&test_prio_msg_q_00, msg1, 1);
|
||||
tos_prio_msg_q_post(&test_prio_msg_q_00, msg0, 0);
|
||||
|
||||
tos_task_yield(); // yeild to test_task
|
||||
|
||||
ASSERT_EQ(test_count, 0);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
|
||||
ASSERT_EQ(test_msg, msg0);
|
||||
tos_task_yield(); // yeild to test_task
|
||||
|
||||
ASSERT_EQ(test_count, 1);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
|
||||
ASSERT_EQ(test_msg, msg1);
|
||||
tos_task_yield(); // yeild to test_task
|
||||
|
||||
ASSERT_EQ(test_count, 2);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
|
||||
ASSERT_EQ(test_msg, msg2);
|
||||
tos_task_yield(); // yeild to test_task
|
||||
|
||||
tos_prio_msg_q_destroy(&test_prio_msg_q_00);
|
||||
tos_task_yield(); // yeild to test_task
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_DESTROY);
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_message_queue_pend_timed(void)
|
||||
{
|
||||
k_err_t err;
|
||||
k_tick_t begin;
|
||||
void *msg = (void *)0xDEADBEEF;
|
||||
|
||||
test_msg_reset();
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_prio_msg_q_create(&test_prio_msg_q_00, test_prio_msg_q_pool_00, TEST_PRIO_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_00, "test_task", test_priority_message_queue_pend_timed_task_entry,
|
||||
(void *)(&test_prio_msg_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// test_task_00 has a higher priority, so it will get running after the task create immediately
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
|
||||
begin = tos_systick_get();
|
||||
while (tos_systick_get() - begin < (k_tick_t)(2000u + 20u)) {
|
||||
tos_task_yield();
|
||||
}
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 1);
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_TIMEOUT);
|
||||
|
||||
ASSERT_EQ(test_msg, K_NULL);
|
||||
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 2);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_msg, msg);
|
||||
|
||||
err = tos_prio_msg_q_destroy(&test_prio_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_01);
|
||||
ASSERT_EQ(test_err, K_ERR_PEND_DESTROY);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_message_queue_post_all(void)
|
||||
{
|
||||
k_err_t err;
|
||||
void *msg = (void *)0xDEADBEEF;
|
||||
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_prio_msg_q_create(&test_prio_msg_q_00, test_prio_msg_q_pool_00, TEST_PRIO_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_priority_message_queue_pend_task_entry,
|
||||
(void *)(&test_prio_msg_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_01, "test_task_01", test_priority_message_queue_pend_task_entry,
|
||||
(void *)(&test_prio_msg_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_01, sizeof(test_task_stack_01),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a higher priority than current task(numerically smaller)
|
||||
err = tos_task_create(&test_task_02, "test_task_02", test_priority_message_queue_pend_task_entry,
|
||||
(void *)(&test_prio_msg_q_00), k_curr_task->prio - 1,
|
||||
test_task_stack_02, sizeof(test_task_stack_02),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 0);
|
||||
|
||||
err = tos_prio_msg_q_post_all(&test_prio_msg_q_00, msg, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 3);
|
||||
ASSERT_EQ(test_msg, msg);
|
||||
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT_EQ(test_count, 4);
|
||||
ASSERT_EQ(test_msg, msg);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_task_destroy(&test_task_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_task_destroy(&test_task_02);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_destroy(&test_prio_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_message_queue_flush(void)
|
||||
{
|
||||
k_err_t err;
|
||||
void *msg0 = (void *)0xDEADBEE0, *msg1 = (void *)0xDEADBEE1, *msg2 = (void *)0xDEADBEE2;
|
||||
|
||||
test_err_reset();
|
||||
test_context_reset();
|
||||
test_count_reset();
|
||||
test_task_hook_set(test_count_inc);
|
||||
|
||||
err = tos_prio_msg_q_create(&test_prio_msg_q_00, test_prio_msg_q_pool_00, TEST_PRIO_MESSAGE_Q_MSG_CNT);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// create a test task with a lower priority than current task(numerically bigger)
|
||||
err = tos_task_create(&test_task_00, "test_task_00", test_priority_message_queue_pend_task_entry,
|
||||
(void *)(&test_prio_msg_q_00), k_curr_task->prio + 1,
|
||||
test_task_stack_00, sizeof(test_task_stack_00),
|
||||
0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg0, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg1, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg2, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// we have post three msg, but we flush them, test_task_00 should not receive any message
|
||||
err = tos_prio_msg_q_flush(&test_prio_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
tos_task_delay(500);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_count, 0);
|
||||
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg0, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg1, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
tos_task_delay(500);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_count, 2);
|
||||
|
||||
// test_task_00 is pending, this post will send msg0 to test_task_00
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg0, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg1, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_post(&test_prio_msg_q_00, msg2, 0);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// msg1/msg2 has not been received yet, queue flush will discard these two message
|
||||
err = tos_prio_msg_q_flush(&test_prio_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
// yeild cpu to test_task_00
|
||||
tos_task_delay(500);
|
||||
|
||||
ASSERT_EQ(test_context, TEST_CONTEXT_00);
|
||||
ASSERT_EQ(test_err, K_ERR_NONE);
|
||||
ASSERT_EQ(test_count, 3);
|
||||
|
||||
err = tos_task_destroy(&test_task_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_msg_q_destroy(&test_prio_msg_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
test_task_hook_reset();
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suit_priority_message_queue)
|
||||
{
|
||||
RUN_TEST(test_tos_priority_message_queue_create);
|
||||
RUN_TEST(test_tos_priority_message_queue_destroy);
|
||||
RUN_TEST(test_tos_priority_message_queue_pend);
|
||||
RUN_TEST(test_tos_priority_message_queue_pend_timed);
|
||||
RUN_TEST(test_tos_priority_message_queue_post_all);
|
||||
RUN_TEST(test_tos_priority_message_queue_flush);
|
||||
}
|
||||
|
350
test/suit_priority_queue.c
Normal file
350
test/suit_priority_queue.c
Normal file
@@ -0,0 +1,350 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
SUITE(suit_priority_queue);
|
||||
|
||||
k_prio_q_t test_prio_q_00;
|
||||
k_prio_q_t test_prio_q_01;
|
||||
|
||||
#define TEST_PRIO_Q_ITEM_CNT 16
|
||||
uint8_t test_prio_q_pool_00[sizeof(test_prio_q_item_t) * TEST_PRIO_Q_ITEM_CNT];
|
||||
uint8_t test_prio_q_pool_01[sizeof(test_prio_q_item_t) * TEST_PRIO_Q_ITEM_CNT];
|
||||
uint8_t test_prio_q_int_pool_00[sizeof(int) * TEST_PRIO_Q_ITEM_CNT];
|
||||
|
||||
uint8_t test_prio_q_mgr_array_00[TOS_PRIO_Q_MGR_ARRAY_SIZE(TEST_PRIO_Q_ITEM_CNT)];
|
||||
uint8_t test_prio_q_mgr_array_01[TOS_PRIO_Q_MGR_ARRAY_SIZE(TEST_PRIO_Q_ITEM_CNT)];
|
||||
|
||||
TEST test_tos_priority_queue_create(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
err = tos_prio_q_create(&test_prio_q_00, K_NULL, test_prio_q_pool_00, TEST_PRIO_Q_ITEM_CNT, sizeof(test_prio_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
err = tos_prio_q_create(K_NULL, test_prio_q_mgr_array_00, test_prio_q_pool_00, TEST_PRIO_Q_ITEM_CNT, sizeof(test_prio_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
err = tos_prio_q_create(&test_prio_q_00, test_prio_q_mgr_array_00, test_prio_q_pool_00, TEST_PRIO_Q_ITEM_CNT, sizeof(test_prio_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_q_create(&test_prio_q_01, test_prio_q_mgr_array_01, test_prio_q_pool_01, TEST_PRIO_Q_ITEM_CNT, sizeof(test_prio_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_q_destroy(&test_prio_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_q_destroy(&test_prio_q_01);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_queue_destroy(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
err = tos_prio_q_destroy(&test_prio_q_00);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_INVALID);
|
||||
#endif
|
||||
|
||||
err = tos_prio_q_destroy(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_queue_enqueue(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
k_prio_t prio;
|
||||
test_prio_q_item_t items[TEST_PRIO_Q_ITEM_CNT] = {
|
||||
{ 2, "222", '2' },
|
||||
{ 4, "444", '4' },
|
||||
{ 1, "111", '1' },
|
||||
{ 7, "777", '7' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 2, "222", '2' },
|
||||
{ 0, "000", '0' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 5, "555", '5' },
|
||||
{ 12, "ccc", 'c' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 3, "333", '3' },
|
||||
{ 6, "666", '6' },
|
||||
{ 8, "888", '8' },
|
||||
};
|
||||
test_prio_q_item_t items_should[TEST_PRIO_Q_ITEM_CNT] = {
|
||||
{ 0, "000", '0' },
|
||||
{ 1, "111", '1' },
|
||||
{ 2, "222", '2' },
|
||||
{ 2, "222", '2' },
|
||||
{ 3, "333", '3' },
|
||||
{ 4, "444", '4' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 6, "666", '6' },
|
||||
{ 7, "777", '7' },
|
||||
{ 8, "888", '8' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 12, "ccc", 'c' },
|
||||
};
|
||||
test_prio_q_item_t item_dequeued;
|
||||
size_t item_size;
|
||||
|
||||
// yes, our priority queue has a min heap inside(priority, numerically bigger, actually smaller)
|
||||
err = tos_prio_q_create(&test_prio_q_00, test_prio_q_mgr_array_00, test_prio_q_pool_00, TEST_PRIO_Q_ITEM_CNT, sizeof(test_prio_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_PRIO_Q_ITEM_CNT; ++i) {
|
||||
// we enqueue the item with the domain "a" as the priority
|
||||
err = tos_prio_q_enqueue(&test_prio_q_00, &items[i], sizeof(test_prio_q_item_t), items[i].a);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_prio_q_is_full(&test_prio_q_00));
|
||||
|
||||
for (i = 0; i < TEST_PRIO_Q_ITEM_CNT; ++i) {
|
||||
err = tos_prio_q_dequeue(&test_prio_q_00, &item_dequeued, &item_size, &prio);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(test_prio_q_item_t));
|
||||
ASSERT_EQ(prio, item_dequeued.a);
|
||||
ASSERT_EQ(item_dequeued.a, items_should[i].a);
|
||||
ASSERT_EQ(strcmp(item_dequeued.b, items_should[i].b), 0);
|
||||
ASSERT_EQ(item_dequeued.c, items_should[i].c);
|
||||
}
|
||||
|
||||
ASSERT(tos_prio_q_is_empty(&test_prio_q_00));
|
||||
|
||||
err = tos_prio_q_destroy(&test_prio_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_queue_int_enqueue(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
k_prio_t prio;
|
||||
int items[TEST_PRIO_Q_ITEM_CNT] = {
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
7,
|
||||
5,
|
||||
5,
|
||||
2,
|
||||
0,
|
||||
9,
|
||||
10,
|
||||
5,
|
||||
12,
|
||||
11,
|
||||
3,
|
||||
6,
|
||||
8,
|
||||
};
|
||||
int items_should[TEST_PRIO_Q_ITEM_CNT] = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
};
|
||||
int item_dequeued;
|
||||
size_t item_size;
|
||||
|
||||
// yes, our priority queue has a min heap inside(priority, numerically bigger, actually smaller)
|
||||
err = tos_prio_q_create(&test_prio_q_00, test_prio_q_mgr_array_00, test_prio_q_int_pool_00, TEST_PRIO_Q_ITEM_CNT, sizeof(int));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_PRIO_Q_ITEM_CNT; ++i) {
|
||||
// we enqueue the item with the value of item as the priority
|
||||
err = tos_prio_q_enqueue(&test_prio_q_00, &items[i], sizeof(int), items[i]);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_prio_q_is_full(&test_prio_q_00));
|
||||
|
||||
for (i = 0; i < TEST_PRIO_Q_ITEM_CNT; ++i) {
|
||||
err = tos_prio_q_dequeue(&test_prio_q_00, &item_dequeued, &item_size, &prio);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(int));
|
||||
ASSERT_EQ(prio, item_dequeued);
|
||||
ASSERT_EQ(item_dequeued, items_should[i]);
|
||||
}
|
||||
|
||||
ASSERT(tos_prio_q_is_empty(&test_prio_q_00));
|
||||
|
||||
err = tos_prio_q_destroy(&test_prio_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_queue_enqueue_limit(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
k_prio_t prio;
|
||||
test_prio_q_item_t items[TEST_PRIO_Q_ITEM_CNT] = {
|
||||
{ 2, "222", '2' },
|
||||
{ 4, "444", '4' },
|
||||
{ 1, "111", '1' },
|
||||
{ 7, "777", '7' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 2, "222", '2' },
|
||||
{ 0, "000", '0' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 5, "555", '5' },
|
||||
{ 12, "ccc", 'c' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 3, "333", '3' },
|
||||
{ 6, "666", '6' },
|
||||
{ 8, "888", '8' },
|
||||
};
|
||||
test_prio_q_item_t items_should[TEST_PRIO_Q_ITEM_CNT] = {
|
||||
{ 0, "000", '0' },
|
||||
{ 1, "111", '1' },
|
||||
{ 2, "222", '2' },
|
||||
{ 2, "222", '2' },
|
||||
{ 3, "333", '3' },
|
||||
{ 4, "444", '4' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 6, "666", '6' },
|
||||
{ 7, "777", '7' },
|
||||
{ 8, "888", '8' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 12, "ccc", 'c' },
|
||||
};
|
||||
test_prio_q_item_t item_dequeued;
|
||||
size_t item_size;
|
||||
|
||||
err = tos_prio_q_create(&test_prio_q_00, test_prio_q_mgr_array_00, test_prio_q_pool_00, TEST_PRIO_Q_ITEM_CNT, sizeof(test_prio_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_PRIO_Q_ITEM_CNT; ++i) {
|
||||
err = tos_prio_q_enqueue(&test_prio_q_00, &items[i], sizeof(test_prio_q_item_t), items[i].a);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_prio_q_is_full(&test_prio_q_00));
|
||||
|
||||
err = tos_prio_q_enqueue(&test_prio_q_00, &items[0], sizeof(test_prio_q_item_t), items[0].a);
|
||||
ASSERT_EQ(err, K_ERR_PRIO_Q_FULL);
|
||||
|
||||
ASSERT(tos_prio_q_is_full(&test_prio_q_00));
|
||||
|
||||
for (i = 0; i < TEST_PRIO_Q_ITEM_CNT; ++i) {
|
||||
err = tos_prio_q_dequeue(&test_prio_q_00, &item_dequeued, &item_size, &prio);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(test_prio_q_item_t));
|
||||
ASSERT_EQ(item_dequeued.a, items_should[i].a);
|
||||
ASSERT_EQ(strcmp(item_dequeued.b, items_should[i].b), 0);
|
||||
ASSERT_EQ(item_dequeued.c, items_should[i].c);
|
||||
}
|
||||
|
||||
ASSERT(tos_prio_q_is_empty(&test_prio_q_00));
|
||||
|
||||
err = tos_prio_q_dequeue(&test_prio_q_00, &item_dequeued, &item_size, &prio);
|
||||
ASSERT_EQ(err, K_ERR_PRIO_Q_EMPTY);
|
||||
|
||||
ASSERT(tos_prio_q_is_empty(&test_prio_q_00));
|
||||
|
||||
err = tos_prio_q_destroy(&test_prio_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_priority_queue_flush(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
k_prio_t prio;
|
||||
test_prio_q_item_t items[TEST_PRIO_Q_ITEM_CNT] = {
|
||||
{ 2, "222", '2' },
|
||||
{ 4, "444", '4' },
|
||||
{ 1, "111", '1' },
|
||||
{ 7, "777", '7' },
|
||||
{ 5, "555", '5' },
|
||||
{ 5, "555", '5' },
|
||||
{ 2, "222", '2' },
|
||||
{ 0, "000", '0' },
|
||||
{ 9, "999", '9' },
|
||||
{ 10, "aaa", 'a' },
|
||||
{ 5, "555", '5' },
|
||||
{ 12, "ccc", 'c' },
|
||||
{ 11, "bbb", 'b' },
|
||||
{ 3, "333", '3' },
|
||||
{ 6, "666", '6' },
|
||||
{ 8, "888", '8' },
|
||||
};
|
||||
test_prio_q_item_t item_dequeued;
|
||||
size_t item_size;
|
||||
|
||||
err = tos_prio_q_create(&test_prio_q_00, test_prio_q_mgr_array_00, test_prio_q_pool_00, TEST_PRIO_Q_ITEM_CNT, sizeof(test_prio_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_PRIO_Q_ITEM_CNT; ++i) {
|
||||
err = tos_prio_q_enqueue(&test_prio_q_00, &items[i], sizeof(test_prio_q_item_t), items[i].a);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_prio_q_is_full(&test_prio_q_00));
|
||||
|
||||
err = tos_prio_q_flush(&test_prio_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT(tos_prio_q_is_empty(&test_prio_q_00));
|
||||
|
||||
err = tos_prio_q_dequeue(&test_prio_q_00, &item_dequeued, &item_size, &prio);
|
||||
ASSERT_EQ(err, K_ERR_PRIO_Q_EMPTY);
|
||||
|
||||
err = tos_prio_q_enqueue(&test_prio_q_00, &items[0], sizeof(test_prio_q_item_t), items[0].a);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_prio_q_destroy(&test_prio_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suit_priority_queue)
|
||||
{
|
||||
RUN_TEST(test_tos_priority_queue_create);
|
||||
RUN_TEST(test_tos_priority_queue_destroy);
|
||||
RUN_TEST(test_tos_priority_queue_enqueue);
|
||||
RUN_TEST(test_tos_priority_queue_int_enqueue);
|
||||
RUN_TEST(test_tos_priority_queue_enqueue_limit);
|
||||
RUN_TEST(test_tos_priority_queue_flush);
|
||||
}
|
||||
|
273
test/suit_ring_queue.c
Normal file
273
test/suit_ring_queue.c
Normal file
@@ -0,0 +1,273 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
SUITE(suit_ring_queue);
|
||||
|
||||
k_ring_q_t test_ring_q_00;
|
||||
|
||||
#define TEST_RING_Q_U8_ITEM_CNT 5
|
||||
#define TEST_RING_Q_U8_ITEM_SIZE sizeof(uint8_t)
|
||||
uint8_t test_ring_q_u8_pool_00[TEST_RING_Q_U8_ITEM_CNT * TEST_RING_Q_U8_ITEM_SIZE];
|
||||
|
||||
typedef struct test_ring_q_item_st {
|
||||
int a;
|
||||
char *b;
|
||||
char c;
|
||||
} ring_q_item_t;
|
||||
|
||||
#define TEST_RING_Q_STRUCT_ITEM_CNT 5
|
||||
#define TEST_RING_Q_STRUCT_ITEM_SIZE sizeof(ring_q_item_t)
|
||||
uint8_t test_ring_q_struct_pool_00[TEST_RING_Q_STRUCT_ITEM_CNT * TEST_RING_Q_STRUCT_ITEM_SIZE];
|
||||
|
||||
TEST test_tos_ring_queue_create(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
err = tos_ring_q_create(&test_ring_q_00, test_ring_q_u8_pool_00, TEST_RING_Q_U8_ITEM_CNT, TEST_RING_Q_U8_ITEM_SIZE);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_ring_q_create(K_NULL, test_ring_q_u8_pool_00, TEST_RING_Q_U8_ITEM_CNT, TEST_RING_Q_U8_ITEM_SIZE);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
err = tos_ring_q_create(&test_ring_q_00, test_ring_q_u8_pool_00, TEST_RING_Q_U8_ITEM_CNT, TEST_RING_Q_U8_ITEM_SIZE);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_ring_q_destroy(&test_ring_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_ring_queue_destroy(void)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
err = tos_ring_q_destroy(&test_ring_q_00);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_INVALID);
|
||||
#endif
|
||||
|
||||
err = tos_ring_q_destroy(K_NULL);
|
||||
ASSERT_EQ(err, K_ERR_OBJ_PTR_NULL);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_ring_queue_u8_enqueue(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
uint8_t items[TEST_RING_Q_U8_ITEM_CNT] = { 1, 2, 3, 4, 5 };
|
||||
uint8_t item_dequeued;
|
||||
size_t item_size;
|
||||
|
||||
err = tos_ring_q_create(&test_ring_q_00, test_ring_q_u8_pool_00, TEST_RING_Q_U8_ITEM_CNT, TEST_RING_Q_U8_ITEM_SIZE);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_RING_Q_U8_ITEM_CNT; ++i) {
|
||||
err = tos_ring_q_enqueue(&test_ring_q_00, &items[i], sizeof(uint8_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_ring_q_is_full(&test_ring_q_00));
|
||||
|
||||
for (i = 0; i < TEST_RING_Q_U8_ITEM_CNT; ++i) {
|
||||
err = tos_ring_q_dequeue(&test_ring_q_00, &item_dequeued, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(uint8_t));
|
||||
ASSERT_EQ(item_dequeued, items[i]);
|
||||
}
|
||||
|
||||
ASSERT(tos_ring_q_is_empty(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_destroy(&test_ring_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_ring_queue_u8_enqueue_limit(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
uint8_t items[TEST_RING_Q_U8_ITEM_CNT] = { 1, 2, 3, 4, 5 };
|
||||
uint8_t item_dequeued;
|
||||
size_t item_size;
|
||||
|
||||
err = tos_ring_q_create(&test_ring_q_00, test_ring_q_u8_pool_00, TEST_RING_Q_U8_ITEM_CNT, TEST_RING_Q_U8_ITEM_SIZE);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_RING_Q_U8_ITEM_CNT; ++i) {
|
||||
err = tos_ring_q_enqueue(&test_ring_q_00, &items[i], sizeof(uint8_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_ring_q_is_full(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_enqueue(&test_ring_q_00, &items[0], sizeof(uint8_t));
|
||||
ASSERT_EQ(err, K_ERR_RING_Q_FULL);
|
||||
|
||||
ASSERT(tos_ring_q_is_full(&test_ring_q_00));
|
||||
|
||||
for (i = 0; i < TEST_RING_Q_U8_ITEM_CNT; ++i) {
|
||||
err = tos_ring_q_dequeue(&test_ring_q_00, &item_dequeued, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(uint8_t));
|
||||
ASSERT_EQ(item_dequeued, items[i]);
|
||||
}
|
||||
|
||||
ASSERT(tos_ring_q_is_empty(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_dequeue(&test_ring_q_00, &item_dequeued, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_RING_Q_EMPTY);
|
||||
|
||||
ASSERT(tos_ring_q_is_empty(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_destroy(&test_ring_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_ring_queue_struct_enqueue(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
ring_q_item_t items[TEST_RING_Q_STRUCT_ITEM_CNT] = {
|
||||
{ 1, "111", '1' },
|
||||
{ 2, "222", '2' },
|
||||
{ 3, "333", '3' },
|
||||
{ 4, "444", '4' },
|
||||
{ 5, "555", '5' },
|
||||
};
|
||||
ring_q_item_t item_dequeued;
|
||||
size_t item_size;
|
||||
|
||||
err = tos_ring_q_create(&test_ring_q_00, test_ring_q_struct_pool_00, TEST_RING_Q_STRUCT_ITEM_CNT, TEST_RING_Q_STRUCT_ITEM_SIZE);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_RING_Q_STRUCT_ITEM_CNT; ++i) {
|
||||
err = tos_ring_q_enqueue(&test_ring_q_00, &items[i], sizeof(ring_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_ring_q_is_full(&test_ring_q_00));
|
||||
|
||||
for (i = 0; i < TEST_RING_Q_STRUCT_ITEM_CNT; ++i) {
|
||||
err = tos_ring_q_dequeue(&test_ring_q_00, &item_dequeued, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(ring_q_item_t));
|
||||
ASSERT_EQ(item_dequeued.a, items[i].a);
|
||||
ASSERT_EQ(strcmp(item_dequeued.b, items[i].b), 0);
|
||||
ASSERT_EQ(item_dequeued.c, items[i].c);
|
||||
}
|
||||
|
||||
ASSERT(tos_ring_q_is_empty(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_destroy(&test_ring_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_ring_queue_struct_enqueue_limit(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
ring_q_item_t items[TEST_RING_Q_STRUCT_ITEM_CNT] = {
|
||||
{ 1, "111", '1' },
|
||||
{ 2, "222", '2' },
|
||||
{ 3, "333", '3' },
|
||||
{ 4, "444", '4' },
|
||||
{ 5, "555", '5' },
|
||||
};
|
||||
ring_q_item_t item_dequeued;
|
||||
size_t item_size;
|
||||
|
||||
err = tos_ring_q_create(&test_ring_q_00, test_ring_q_struct_pool_00, TEST_RING_Q_STRUCT_ITEM_CNT, TEST_RING_Q_STRUCT_ITEM_SIZE);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_RING_Q_STRUCT_ITEM_CNT; ++i) {
|
||||
err = tos_ring_q_enqueue(&test_ring_q_00, &items[i], sizeof(ring_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_ring_q_is_full(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_enqueue(&test_ring_q_00, &items[0], sizeof(ring_q_item_t));
|
||||
ASSERT_EQ(err, K_ERR_RING_Q_FULL);
|
||||
|
||||
ASSERT(tos_ring_q_is_full(&test_ring_q_00));
|
||||
|
||||
for (i = 0; i < TEST_RING_Q_STRUCT_ITEM_CNT; ++i) {
|
||||
err = tos_ring_q_dequeue(&test_ring_q_00, &item_dequeued, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
ASSERT_EQ(item_size, sizeof(ring_q_item_t));
|
||||
ASSERT_EQ(item_dequeued.a, items[i].a);
|
||||
ASSERT_EQ(strcmp(item_dequeued.b, items[i].b), 0);
|
||||
ASSERT_EQ(item_dequeued.c, items[i].c);
|
||||
}
|
||||
|
||||
ASSERT(tos_ring_q_is_empty(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_dequeue(&test_ring_q_00, &item_dequeued, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_RING_Q_EMPTY);
|
||||
|
||||
ASSERT(tos_ring_q_is_empty(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_destroy(&test_ring_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_tos_ring_queue_flush(void)
|
||||
{
|
||||
k_err_t err;
|
||||
int i = 0;
|
||||
uint8_t items[TEST_RING_Q_U8_ITEM_CNT] = { 1, 2, 3, 4, 5 };
|
||||
uint8_t item_dequeued;
|
||||
size_t item_size;
|
||||
|
||||
err = tos_ring_q_create(&test_ring_q_00, test_ring_q_u8_pool_00, TEST_RING_Q_U8_ITEM_CNT, TEST_RING_Q_U8_ITEM_SIZE);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
for (i = 0; i < TEST_RING_Q_U8_ITEM_CNT; ++i) {
|
||||
err = tos_ring_q_enqueue(&test_ring_q_00, &items[0], sizeof(uint8_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
}
|
||||
|
||||
ASSERT(tos_ring_q_is_full(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_flush(&test_ring_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
ASSERT(tos_ring_q_is_empty(&test_ring_q_00));
|
||||
|
||||
err = tos_ring_q_dequeue(&test_ring_q_00, &item_dequeued, &item_size);
|
||||
ASSERT_EQ(err, K_ERR_RING_Q_EMPTY);
|
||||
|
||||
err = tos_ring_q_enqueue(&test_ring_q_00, &items[0], sizeof(uint8_t));
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
err = tos_ring_q_destroy(&test_ring_q_00);
|
||||
ASSERT_EQ(err, K_ERR_NONE);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suit_ring_queue)
|
||||
{
|
||||
RUN_TEST(test_tos_ring_queue_create);
|
||||
RUN_TEST(test_tos_ring_queue_destroy);
|
||||
RUN_TEST(test_tos_ring_queue_u8_enqueue);
|
||||
RUN_TEST(test_tos_ring_queue_u8_enqueue_limit);
|
||||
RUN_TEST(test_tos_ring_queue_struct_enqueue);
|
||||
RUN_TEST(test_tos_ring_queue_struct_enqueue_limit);
|
||||
RUN_TEST(test_tos_ring_queue_flush);
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@
|
||||
#include "test/test.h"
|
||||
#include "greatest/greatest.h"
|
||||
|
||||
#if TOS_CFG_ROUND_ROBIN_EN > 0u
|
||||
|
||||
SUITE(suit_robin);
|
||||
|
||||
static const k_timeslice_t test_robin_timeslice_00 = 10;
|
||||
@@ -72,3 +74,5 @@ SUITE(suit_robin)
|
||||
RUN_TEST(test_robin);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -8,31 +8,44 @@
|
||||
SUITE_EXTERN(suit_task);
|
||||
SUITE_EXTERN(suit_mutex);
|
||||
SUITE_EXTERN(suit_sem);
|
||||
SUITE_EXTERN(suit_queue);
|
||||
SUITE_EXTERN(suit_event);
|
||||
SUITE_EXTERN(suit_msg_queue);
|
||||
SUITE_EXTERN(suit_ring_queue);
|
||||
SUITE_EXTERN(suit_char_fifo);
|
||||
SUITE_EXTERN(suit_message_queue);
|
||||
SUITE_EXTERN(suit_mail_queue);
|
||||
SUITE_EXTERN(suit_binary_heap);
|
||||
SUITE_EXTERN(suit_priority_queue);
|
||||
SUITE_EXTERN(suit_priority_message_queue);
|
||||
SUITE_EXTERN(suit_priority_mail_queue);
|
||||
SUITE_EXTERN(suit_mmblk);
|
||||
SUITE_EXTERN(suit_fifo);
|
||||
SUITE_EXTERN(suit_robin);
|
||||
SUITE_EXTERN(suit_timer);
|
||||
|
||||
|
||||
GREATEST_MAIN_DEFS();
|
||||
GREATEST_MAIN_DEFS();
|
||||
|
||||
int application_entry(void *arg)
|
||||
{
|
||||
GREATEST_MAIN_BEGIN();
|
||||
|
||||
#if TOS_CFG_ROUND_ROBIN_EN > 0u
|
||||
RUN_SUITE(suit_robin);
|
||||
#else
|
||||
RUN_SUITE(suit_task);
|
||||
RUN_SUITE(suit_mmblk);
|
||||
RUN_SUITE(suit_timer);
|
||||
RUN_SUITE(suit_mutex);
|
||||
RUN_SUITE(suit_sem);
|
||||
RUN_SUITE(suit_queue);
|
||||
RUN_SUITE(suit_event);
|
||||
RUN_SUITE(suit_msg_queue);
|
||||
RUN_SUITE(suit_mmblk);
|
||||
RUN_SUITE(suit_fifo);
|
||||
RUN_SUITE(suit_robin);
|
||||
RUN_SUITE(suit_timer);
|
||||
RUN_SUITE(suit_ring_queue);
|
||||
RUN_SUITE(suit_char_fifo);
|
||||
RUN_SUITE(suit_message_queue);
|
||||
RUN_SUITE(suit_mail_queue);
|
||||
RUN_SUITE(suit_binary_heap);
|
||||
RUN_SUITE(suit_priority_queue);
|
||||
RUN_SUITE(suit_priority_message_queue);
|
||||
RUN_SUITE(suit_priority_mail_queue);
|
||||
#endif
|
||||
|
||||
GREATEST_MAIN_END();
|
||||
}
|
||||
|
@@ -8,9 +8,10 @@ k_err_t test_err = K_ERR_NONE;
|
||||
|
||||
test_context_t test_context = TEST_CONTEXT_NONE;
|
||||
|
||||
void *test_msg_addr = K_NULL;
|
||||
void *test_msg = K_NULL;
|
||||
|
||||
size_t test_msg_size = 0;
|
||||
test_mail_t test_mail;
|
||||
size_t test_mail_size = 0;
|
||||
|
||||
k_event_flag_t test_event_match = 0;
|
||||
|
||||
@@ -26,14 +27,25 @@ void test_event_set(k_event_flag_t event_match)
|
||||
|
||||
void test_msg_reset(void)
|
||||
{
|
||||
test_msg_addr = K_NULL;
|
||||
test_msg_size = 0;
|
||||
test_msg = K_NULL;
|
||||
}
|
||||
|
||||
void test_msg_set(void *msg_addr, size_t msg_size)
|
||||
void test_msg_set(void *msg)
|
||||
{
|
||||
test_msg_addr = msg_addr;
|
||||
test_msg_size = msg_size;
|
||||
test_msg = msg;
|
||||
}
|
||||
|
||||
void test_mail_reset(void)
|
||||
{
|
||||
test_mail.a = 0;
|
||||
test_mail.b = K_NULL;
|
||||
test_mail.c = 'X';
|
||||
}
|
||||
|
||||
void test_mail_set(void *mail, size_t mail_size)
|
||||
{
|
||||
memcpy(&test_mail, mail, sizeof(test_mail_t));
|
||||
test_mail_size = mail_size;
|
||||
}
|
||||
|
||||
void test_err_reset(void)
|
||||
|
Reference in New Issue
Block a user