diff mbox series

[v1,2/2] test: lock: expand rwlock tests

Message ID 1493935208-7891-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v1,1/2] linux-generic: rwlock: fix odp_rwlock_read_trylock() | expand

Commit Message

Github ODP bot May 4, 2017, 10 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Expand testsuite for rwlocks:
 - always verify _trylock return code
 - always unlock after successful _trylock return
 - try calling _trylock when holding write lock

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 19 (lumag:fix-rwlock)
 ** https://github.com/Linaro/odp/pull/19
 ** Patch: https://github.com/Linaro/odp/pull/19.patch
 ** Base sha: 79ba737a404d2833ad33d8f84ed6ce82c9a8c18e
 ** Merge commit sha: 8448157882fac03287253bf54c19284b6d52246e
 **/
 test/common_plat/validation/api/lock/lock.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/test/common_plat/validation/api/lock/lock.c b/test/common_plat/validation/api/lock/lock.c
index bd9a2aa..f8a1d8c 100644
--- a/test/common_plat/validation/api/lock/lock.c
+++ b/test/common_plat/validation/api/lock/lock.c
@@ -257,7 +257,7 @@  static int ticketlock_api_tests(void *arg UNUSED)
 
 static void rwlock_api_test(odp_rwlock_t *rw_lock)
 {
-	int rc;
+	int rc = 0;
 
 	odp_rwlock_init(rw_lock);
 	/* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 0); */
@@ -265,23 +265,40 @@  static void rwlock_api_test(odp_rwlock_t *rw_lock)
 	odp_rwlock_read_lock(rw_lock);
 
 	rc = odp_rwlock_read_trylock(rw_lock);
-	CU_ASSERT(rc == 0);
+	CU_ASSERT(rc != 0);
+	if (rc == 1)
+		odp_rwlock_read_unlock(rw_lock);
+
 	rc = odp_rwlock_write_trylock(rw_lock);
 	CU_ASSERT(rc == 0);
+	if (rc == 1)
+		odp_rwlock_write_unlock(rw_lock);
 
 	odp_rwlock_read_unlock(rw_lock);
 
 	rc = odp_rwlock_read_trylock(rw_lock);
+	CU_ASSERT(rc != 0);
 	if (rc == 1)
 		odp_rwlock_read_unlock(rw_lock);
 
 	odp_rwlock_write_lock(rw_lock);
 	/* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 1); */
 
+	rc = odp_rwlock_read_trylock(rw_lock);
+	CU_ASSERT(rc == 0);
+	if (rc == 1)
+		odp_rwlock_read_unlock(rw_lock);
+
+	rc = odp_rwlock_write_trylock(rw_lock);
+	CU_ASSERT(rc == 0);
+	if (rc == 1)
+		odp_rwlock_write_unlock(rw_lock);
+
 	odp_rwlock_write_unlock(rw_lock);
 	/* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 0); */
 
 	rc = odp_rwlock_write_trylock(rw_lock);
+	CU_ASSERT(rc != 0);
 	if (rc == 1)
 		odp_rwlock_write_unlock(rw_lock);
 }