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

@@ -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);
}