diff mbox series

[v1,1/3] validation: sched: add order_unlock_lock test

Message ID 1518703206-19713-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v1,1/3] validation: sched: add order_unlock_lock test | expand

Commit Message

Github ODP bot Feb. 15, 2018, 2 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Added simple ordered lock test, so that new ordered_unlock_lock
function is tested at least on single thread.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 484 (psavol:master-missing-validation)
 ** https://github.com/Linaro/odp/pull/484
 ** Patch: https://github.com/Linaro/odp/pull/484.patch
 ** Base sha: 41b3fa2cd994a7ef68290a07dcde5564e4640847
 ** Merge commit sha: 595ea205e4c4680f6a9a674fbe637dcab24b038e
 **/
 test/validation/api/scheduler/scheduler.c | 71 +++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
diff mbox series

Patch

diff --git a/test/validation/api/scheduler/scheduler.c b/test/validation/api/scheduler/scheduler.c
index 2c0d44100..0be6ce3f8 100644
--- a/test/validation/api/scheduler/scheduler.c
+++ b/test/validation/api/scheduler/scheduler.c
@@ -1336,6 +1336,76 @@  void scheduler_test_pause_resume(void)
 	CU_ASSERT(ret == 0);
 }
 
+/* Basic, single threaded ordered lock API testing */
+static void scheduler_test_ordered_lock(void)
+{
+	odp_queue_t queue;
+	odp_buffer_t buf;
+	odp_event_t ev;
+	odp_queue_t from;
+	int i;
+	int ret;
+	uint32_t lock_count;
+
+	queue = odp_queue_lookup("sched_0_0_o");
+	CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID);
+	CU_ASSERT_FATAL(odp_queue_type(queue) == ODP_QUEUE_TYPE_SCHED);
+	CU_ASSERT_FATAL(odp_queue_sched_type(queue) == ODP_SCHED_SYNC_ORDERED);
+
+	lock_count = odp_queue_lock_count(queue);
+
+	if (lock_count == 0) {
+		printf("  NO ORDERED LOCKS. Ordered locks not tested.\n");
+		return;
+	}
+
+	pool = odp_pool_lookup(MSG_POOL_NAME);
+	CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
+
+	for (i = 0; i < BUFS_PER_QUEUE; i++) {
+		buf = odp_buffer_alloc(pool);
+		CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID);
+		ev = odp_buffer_to_event(buf);
+		ret = odp_queue_enq(queue, ev);
+		CU_ASSERT(ret == 0);
+
+		if (ret)
+			odp_buffer_free(buf);
+	}
+
+	for (i = 0; i < BUFS_PER_QUEUE / 2; i++) {
+		from = ODP_QUEUE_INVALID;
+		ev = odp_schedule(&from, ODP_SCHED_WAIT);
+		CU_ASSERT_FATAL(ev != ODP_EVENT_INVALID);
+		CU_ASSERT(from == queue);
+		buf = odp_buffer_from_event(ev);
+		odp_schedule_order_lock(0);
+		odp_schedule_order_unlock(0);
+		odp_buffer_free(buf);
+	}
+
+	if (lock_count < 2) {
+		printf("  ONLY ONE ORDERED LOCK. Unlock_lock not tested.\n");
+		return;
+	}
+
+	for (i = 0; i < BUFS_PER_QUEUE / 2; i++) {
+		from = ODP_QUEUE_INVALID;
+		ev = odp_schedule(&from, ODP_SCHED_WAIT);
+		CU_ASSERT_FATAL(ev != ODP_EVENT_INVALID);
+		CU_ASSERT(from == queue);
+		buf = odp_buffer_from_event(ev);
+		odp_schedule_order_lock(0);
+		odp_schedule_order_unlock_lock(0, 1);
+		odp_schedule_order_unlock(1);
+		odp_buffer_free(buf);
+	}
+
+	ret = exit_schedule_loop();
+
+	CU_ASSERT(ret == 0);
+}
+
 static int create_queues(void)
 {
 	int i, j, prios, rc;
@@ -1618,6 +1688,7 @@  odp_testinfo_t scheduler_suite[] = {
 	ODP_TEST_INFO(scheduler_test_queue_destroy),
 	ODP_TEST_INFO(scheduler_test_groups),
 	ODP_TEST_INFO(scheduler_test_pause_resume),
+	ODP_TEST_INFO(scheduler_test_ordered_lock),
 	ODP_TEST_INFO(scheduler_test_parallel),
 	ODP_TEST_INFO(scheduler_test_atomic),
 	ODP_TEST_INFO(scheduler_test_ordered),