diff mbox

[API-NEXT,3/3] validation: rwlock: add tests for new trylock rwlock and rwlock_recursive apis

Message ID 1457045968-31405-3-git-send-email-bill.fischofer@linaro.org
State Superseded
Headers show

Commit Message

Bill Fischofer March 3, 2016, 10:59 p.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 test/validation/lock/lock.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
diff mbox

Patch

diff --git a/test/validation/lock/lock.c b/test/validation/lock/lock.c
index f1f6d69..071d5b6 100644
--- a/test/validation/lock/lock.c
+++ b/test/validation/lock/lock.c
@@ -254,17 +254,33 @@  static void *ticketlock_api_tests(void *arg UNUSED)
 
 static void rwlock_api_test(odp_rwlock_t *rw_lock)
 {
+	int rc;
+
 	odp_rwlock_init(rw_lock);
 	/* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 0); */
 
 	odp_rwlock_read_lock(rw_lock);
+
+	rc = odp_rwlock_read_trylock(rw_lock);
+	CU_ASSERT(rc == 0);
+	rc = odp_rwlock_write_trylock(rw_lock);
+	CU_ASSERT(rc == 0);
+
 	odp_rwlock_read_unlock(rw_lock);
 
+	rc = odp_rwlock_read_trylock(rw_lock);
+	if (rc == 1)
+		odp_rwlock_read_unlock(rw_lock);
+
 	odp_rwlock_write_lock(rw_lock);
 	/* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 1); */
 
 	odp_rwlock_write_unlock(rw_lock);
 	/* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 0); */
+
+	rc = odp_rwlock_write_trylock(rw_lock);
+	if (rc == 1)
+		odp_rwlock_write_unlock(rw_lock);
 }
 
 static void *rwlock_api_tests(void *arg UNUSED)
@@ -288,21 +304,33 @@  static void *rwlock_api_tests(void *arg UNUSED)
 
 static void rwlock_recursive_api_test(odp_rwlock_recursive_t *rw_lock)
 {
+	int rc;
+
 	odp_rwlock_recursive_init(rw_lock);
 	/* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 0); */
 
 	odp_rwlock_recursive_read_lock(rw_lock);
 	odp_rwlock_recursive_read_lock(rw_lock);
+	rc = odp_rwlock_recursive_read_trylock(rw_lock);
+	CU_ASSERT(rc == 1);
+	rc = odp_rwlock_recursive_write_trylock(rw_lock);
+	CU_ASSERT(rc == 0);
 
 	odp_rwlock_recursive_read_unlock(rw_lock);
 	odp_rwlock_recursive_read_unlock(rw_lock);
+	odp_rwlock_recursive_read_unlock(rw_lock);
 
 	odp_rwlock_recursive_write_lock(rw_lock);
 	odp_rwlock_recursive_write_lock(rw_lock);
 	/* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 1); */
+	rc = odp_rwlock_recursive_read_trylock(rw_lock);
+	CU_ASSERT(rc == 0);
+	rc = odp_rwlock_recursive_write_trylock(rw_lock);
+	CU_ASSERT(rc == 1);
 
 	odp_rwlock_recursive_write_unlock(rw_lock);
 	odp_rwlock_recursive_write_unlock(rw_lock);
+	odp_rwlock_recursive_write_unlock(rw_lock);
 	/* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 0); */
 }