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
diff --git a/tests/it_q/it_q_test.c b/tests/it_q/it_q_test.c
index 28e32d8..9545183 100644
--- a/tests/it_q/it_q_test.c
+++ b/tests/it_q/it_q_test.c
@@ -68,6 +68,48 @@
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 @@
{
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 7f102c6..91ba0ce 100644
--- a/tests/it_q/it_q_test.ok
+++ b/tests/it_q/it_q_test.ok
@@ -9,6 +9,11 @@
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