You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by iv...@apache.org on 2022/09/12 17:00:36 UTC

svn commit: r1904029 - in /apr/apr/branches/1.7.x: ./ test/testlock.c

Author: ivan
Date: Mon Sep 12 17:00:36 2022
New Revision: 1904029

URL: http://svn.apache.org/viewvc?rev=1904029&view=rev
Log:
On 1.7.x: Merge r1902119, r1902122, r1902223 from 1.8.x branch:
   - Add simple tests for nested and unnested thread mutexes.
   - Add test for WAIT_ABANDONED handling for win32 mutexes.

Modified:
    apr/apr/branches/1.7.x/   (props changed)
    apr/apr/branches/1.7.x/test/testlock.c

Propchange: apr/apr/branches/1.7.x/
------------------------------------------------------------------------------
  Merged /apr/apr/branches/1.8.x:r1902119,1902122,1902223
  Merged /apr/apr/trunk:r1860190,1866300,1866712

Modified: apr/apr/branches/1.7.x/test/testlock.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.7.x/test/testlock.c?rev=1904029&r1=1904028&r2=1904029&view=diff
==============================================================================
--- apr/apr/branches/1.7.x/test/testlock.c (original)
+++ apr/apr/branches/1.7.x/test/testlock.c Mon Sep 12 17:00:36 2022
@@ -428,6 +428,95 @@ static void test_timeoutmutex(abts_case
 }
 #endif
 
+static void test_thread_nestedmutex(abts_case *tc, void *data)
+{
+    apr_thread_mutex_t *m;
+    apr_status_t rv;
+
+    rv = apr_thread_mutex_create(&m, APR_THREAD_MUTEX_NESTED, p);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+    ABTS_PTR_NOTNULL(tc, m);
+
+    rv = apr_thread_mutex_lock(m);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    rv = apr_thread_mutex_trylock(m);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+    if (rv == APR_SUCCESS)
+    {
+        rv = apr_thread_mutex_unlock(m);
+        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+    }
+
+    rv = apr_thread_mutex_unlock(m);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+}
+
+static void test_thread_unnestedmutex(abts_case *tc, void *data)
+{
+    apr_thread_mutex_t *m;
+    apr_status_t rv;
+
+    rv = apr_thread_mutex_create(&m, APR_THREAD_MUTEX_UNNESTED, p);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+    ABTS_PTR_NOTNULL(tc, m);
+
+    rv = apr_thread_mutex_lock(m);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    rv = apr_thread_mutex_trylock(m);
+    ABTS_INT_EQUAL(tc, APR_EBUSY, rv);
+    if (rv == APR_SUCCESS)
+    {
+        rv = apr_thread_mutex_unlock(m);
+        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+    }
+
+    rv = apr_thread_mutex_unlock(m);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+}
+
+#ifdef WIN32
+static void *APR_THREAD_FUNC
+thread_win32_abandoned_mutex_function(apr_thread_t *thd, void *data)
+{
+    apr_thread_mutex_t *mutex = data;
+    apr_status_t rv;
+
+    rv = apr_thread_mutex_lock(mutex);
+
+    /* exit from thread without unlocking mutex. */
+    apr_thread_exit(thd, rv);
+
+    return NULL;
+}
+
+static void test_win32_abandoned_mutex(abts_case *tc, void *data)
+{
+    apr_status_t rv;
+    apr_thread_t *thread;
+    apr_thread_mutex_t *mutex;
+
+    /* Create timed mutex: APR will create Win32 mutex object in this case. */
+    rv = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_TIMED, p);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    rv = apr_thread_create(&thread, NULL, thread_win32_abandoned_mutex_function,
+                           mutex, p);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    apr_thread_join(&rv, thread);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    rv = apr_thread_mutex_trylock(mutex);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    rv = apr_thread_mutex_unlock (mutex);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+}
+
+#endif
+
 #endif /* !APR_HAS_THREADS */
 
 #if !APR_HAS_THREADS
@@ -449,12 +538,17 @@ abts_suite *testlock(abts_suite *suite)
 #if APR_HAS_TIMEDLOCKS
     abts_run_test(suite, test_thread_timedmutex, NULL);
 #endif
+    abts_run_test(suite, test_thread_nestedmutex, NULL);
+    abts_run_test(suite, test_thread_unnestedmutex, NULL);
     abts_run_test(suite, test_thread_rwlock, NULL);
     abts_run_test(suite, test_cond, NULL);
     abts_run_test(suite, test_timeoutcond, NULL);
 #if APR_HAS_TIMEDLOCKS
     abts_run_test(suite, test_timeoutmutex, NULL);
 #endif
+#ifdef WIN32
+    abts_run_test(suite, test_win32_abandoned_mutex, NULL);
+#endif
 #endif
 
     return suite;