add a set of dyn(create / destroy) interface

1. tos_ring_q_create_dyn
2. tos_chr_fifo_create_dyn
3. tos_msg_q_create_dyn
4. tos_mail_q_create_dyn
5. tos_bin_heap_create_dyn
6. tos_prio_q_create_dyn
7. tos_prio_msg_q_create_dyn
8. tos_prio_mail_q_create_dyn
This commit is contained in:
daishengdong
2019-10-29 16:57:43 +08:00
parent 3615aaf3f4
commit c411ed1eec
92 changed files with 1800 additions and 86333 deletions

View File

@@ -257,6 +257,77 @@ TEST test_tos_binary_heap_max_push(void)
PASS();
}
TEST test_tos_binary_heap_max_push_dyn(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_dyn(&test_bin_heap_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_dyn(&test_bin_heap_00);
ASSERT_EQ(err, K_ERR_NONE);
PASS();
}
TEST test_tos_binary_heap_min_int_push(void)
{
k_err_t err;
@@ -395,6 +466,75 @@ TEST test_tos_binary_heap_max_int_push(void)
PASS();
}
TEST test_tos_binary_heap_max_int_push_dyn(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_dyn(&test_bin_heap_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_dyn(&test_bin_heap_00);
ASSERT_EQ(err, K_ERR_NONE);
PASS();
}
TEST test_tos_binary_heap_push_limit(void)
{
k_err_t err;
@@ -535,8 +675,10 @@ SUITE(suit_binary_heap)
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_max_push_dyn);
RUN_TEST(test_tos_binary_heap_min_int_push);
RUN_TEST(test_tos_binary_heap_max_int_push);
RUN_TEST(test_tos_binary_heap_max_int_push_dyn);
RUN_TEST(test_tos_binary_heap_push_limit);
RUN_TEST(test_tos_binary_flush);
}

View File

@@ -86,6 +86,38 @@ TEST test_tos_fifo_char_push(void)
PASS();
}
TEST test_tos_fifo_char_push_dyn(void)
{
k_err_t err;
int i = 0;
uint8_t data;
err = tos_chr_fifo_create_dyn(&test_fifo_00, sizeof(fifo_buffer_00));
ASSERT_EQ(err, K_ERR_NONE);
for (i = 0; i < FIFO_BUFFER_SIZE; ++i) {
err = tos_chr_fifo_push(&test_fifo_00, 'a' + i);
ASSERT_EQ(err, K_ERR_NONE);
}
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_chr_fifo_pop(&test_fifo_00, &data);
ASSERT_EQ(err, K_ERR_NONE);
ASSERT_EQ(data, 'a' + i);
}
err = tos_chr_fifo_pop(&test_fifo_00, &data);
ASSERT_EQ(err, K_ERR_RING_Q_EMPTY);
err = tos_chr_fifo_destroy_dyn(&test_fifo_00);
ASSERT_EQ(err, K_ERR_NONE);
PASS();
}
TEST test_tos_fifo_stream_push(void)
{
k_err_t err;
@@ -119,6 +151,7 @@ SUITE(suit_char_fifo)
RUN_TEST(test_tos_fifo_create);
RUN_TEST(test_tos_fifo_destory);
RUN_TEST(test_tos_fifo_char_push);
RUN_TEST(test_tos_fifo_char_push_dyn);
RUN_TEST(test_tos_fifo_stream_push);
}

View File

@@ -158,6 +158,53 @@ TEST test_tos_mail_queue_pend(void)
PASS();
}
TEST test_tos_mail_queue_pend_dyn(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_dyn(&test_mail_q_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_dyn(&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;
@@ -397,6 +444,7 @@ 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_dyn);
RUN_TEST(test_tos_mail_queue_pend_timed);
RUN_TEST(test_tos_mail_queue_post_all);
RUN_TEST(test_tos_mail_queue_flush);

View File

@@ -150,6 +150,47 @@ TEST test_tos_message_queue_pend(void)
PASS();
}
TEST test_tos_message_queue_pend_dyn(void)
{
k_err_t err;
void *msg = (void *)0xDEADBEEF;
test_msg_reset();
test_context_reset();
test_count_reset();
test_task_hook_set(test_count_inc);
err = tos_msg_q_create_dyn(&test_msg_q_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_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);
ASSERT_EQ(test_count, 0);
ASSERT_EQ(test_context, TEST_CONTEXT_00);
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, msg);
tos_msg_q_destroy_dyn(&test_msg_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_message_queue_pend_timed(void)
{
k_err_t err;
@@ -363,6 +404,7 @@ SUITE(suit_message_queue)
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_dyn);
RUN_TEST(test_tos_message_queue_pend_timed);
RUN_TEST(test_tos_message_queue_post_all);
RUN_TEST(test_tos_message_queue_flush);

View File

@@ -190,6 +190,84 @@ TEST test_tos_prio_mail_queue_pend(void)
PASS();
}
TEST test_tos_prio_mail_queue_pend_dyn(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_dyn(&test_prio_mail_q_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_dyn(&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;
@@ -415,6 +493,7 @@ 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_dyn);
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);

View File

@@ -172,6 +172,68 @@ TEST test_tos_priority_message_queue_pend(void)
PASS();
}
TEST test_tos_priority_message_queue_pend_dyn(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_dyn(&test_prio_msg_q_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_dyn(&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;
@@ -385,6 +447,7 @@ 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_dyn);
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);

View File

@@ -132,6 +132,80 @@ TEST test_tos_priority_queue_enqueue(void)
PASS();
}
TEST test_tos_priority_queue_enqueue_dyn(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_dyn(&test_prio_q_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_dyn(&test_prio_q_00);
ASSERT_EQ(err, K_ERR_NONE);
PASS();
}
TEST test_tos_priority_queue_int_enqueue(void)
{
k_err_t err;
@@ -204,6 +278,78 @@ TEST test_tos_priority_queue_int_enqueue(void)
PASS();
}
TEST test_tos_priority_queue_int_enqueue_dyn(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_dyn(&test_prio_q_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_dyn(&test_prio_q_00);
ASSERT_EQ(err, K_ERR_NONE);
PASS();
}
TEST test_tos_priority_queue_enqueue_limit(void)
{
k_err_t err;
@@ -343,7 +489,9 @@ 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_enqueue_dyn);
RUN_TEST(test_tos_priority_queue_int_enqueue);
RUN_TEST(test_tos_priority_queue_int_enqueue_dyn);
RUN_TEST(test_tos_priority_queue_enqueue_limit);
RUN_TEST(test_tos_priority_queue_flush);
}

View File

@@ -90,6 +90,39 @@ TEST test_tos_ring_queue_u8_enqueue(void)
PASS();
}
TEST test_tos_ring_queue_u8_enqueue_dyn(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_dyn(&test_ring_q_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_dyn(&test_ring_q_00);
ASSERT_EQ(err, K_ERR_NONE);
PASS();
}
TEST test_tos_ring_queue_u8_enqueue_limit(void)
{
k_err_t err;
@@ -174,6 +207,48 @@ TEST test_tos_ring_queue_struct_enqueue(void)
PASS();
}
TEST test_tos_ring_queue_struct_enqueue_dyn(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_dyn(&test_ring_q_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_dyn(&test_ring_q_00);
ASSERT_EQ(err, K_ERR_NONE);
PASS();
}
TEST test_tos_ring_queue_struct_enqueue_limit(void)
{
k_err_t err;
@@ -265,8 +340,10 @@ 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_dyn);
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_dyn);
RUN_TEST(test_tos_ring_queue_struct_enqueue_limit);
RUN_TEST(test_tos_ring_queue_flush);
}