diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2023-12-09 03:43:45 +0700 |
---|---|---|
committer | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2023-12-09 15:23:09 +0700 |
commit | 09c8bfce07da81d91f0872aaaf4c40a109c90691 (patch) | |
tree | e406d153d64deaaf94dac5074c370b42d933c788 | |
parent | 74b31acb5df8470476ca1a169abb1a88fae9a7b5 (diff) |
tests/it_q: add tc_enqueue/dequeue testcase
This patch is adding a simple testcase, which does the following:
* enqueue up to the limit (12 items),
* dequeue up to the limit (12 items).
Everything works as expected, unless you attempt to dequeue from
an empty queue: the test binary segfaults. The problem is explained
and fixed in a subsequent patch.
Change-Id: Ie0edbf00e656fbe231952bdbccfd37d143e8b2b1
Related: CID#336557
-rw-r--r-- | tests/it_q/it_q_test.c | 43 | ||||
-rw-r--r-- | tests/it_q/it_q_test.ok | 5 |
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/it_q/it_q_test.c b/tests/it_q/it_q_test.c index 28e32d89..9545183a 100644 --- a/tests/it_q/it_q_test.c +++ b/tests/it_q/it_q_test.c @@ -68,6 +68,48 @@ static void tc_queue_length(void) osmo_it_q_destroy(q1); } +static void tc_enqueue_dequeue(void) +{ + const unsigned int qlen = 12; + struct it_q_test1 *item; + struct osmo_it_q *q1; + int rc; + + ENTER_TC; + + printf("allocating q1\n"); + q1 = osmo_it_q_alloc(OTC_GLOBAL, "q1", 12, NULL, NULL); + OSMO_ASSERT(q1); + +#if 0 + printf("try dequeueing from an empty queue\n"); + osmo_it_q_dequeue(q1, &item, list); + OSMO_ASSERT(item == NULL); +#endif + + printf("adding queue entries up to the limit\n"); + for (unsigned int i = 0; i < qlen; i++) { + item = talloc_zero(OTC_GLOBAL, struct it_q_test1); + rc = osmo_it_q_enqueue(q1, item, list); + OSMO_ASSERT(rc == 0); + } + + printf("removing queue entries up to the limit\n"); + for (unsigned int i = 0; i < qlen; i++) { + osmo_it_q_dequeue(q1, &item, list); + OSMO_ASSERT(item != NULL); + talloc_free(item); + } + +#if 0 + printf("try dequeueing from an empty queue\n"); + osmo_it_q_dequeue(q1, &item, list); + OSMO_ASSERT(item == NULL); +#endif + + osmo_it_q_destroy(q1); +} + static int g_read_cb_count; static void q_read_cb(struct osmo_it_q *q, struct llist_head *item) @@ -115,6 +157,7 @@ int main(int argc, char **argv) { tc_alloc(); tc_queue_length(); + tc_enqueue_dequeue(); tc_eventfd(); return 0; } diff --git a/tests/it_q/it_q_test.ok b/tests/it_q/it_q_test.ok index 7f102c61..91ba0cec 100644 --- a/tests/it_q/it_q_test.ok +++ b/tests/it_q/it_q_test.ok @@ -9,6 +9,11 @@ allocating q1 adding queue entries up to the limit attempting to add more than the limit +== Entering test case tc_enqueue_dequeue +allocating q1 +adding queue entries up to the limit +removing queue entries up to the limit + == Entering test case tc_eventfd allocating q1 adding 30 queue entries up to the limit |