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:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user