summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjerenkrantz <jerenkrantz@13f79535-47bb-0310-9956-ffa450edef68>2004-06-04 08:44:15 +0000
committerjerenkrantz <jerenkrantz@13f79535-47bb-0310-9956-ffa450edef68>2004-06-04 08:44:15 +0000
commit46cb884b233162c17962c1278f0c12b60c84d90c (patch)
tree6236288b403d01d51b7461fa722dd8c14c7861e7 /test
parent69a6fbd6b50b295c9dbe64bd4ba79b6e7645eb7a (diff)
downloadlibapr-46cb884b233162c17962c1278f0c12b60c84d90c.tar.gz
Various test suite improvements to actually test the global mutex code with all
of the available methods. abts.c: Properly strip prefix and .c extension (was broken if . character is in your path!); specify 'testfoo' rather than 'path/to/testfoo' now globalmutexchild.c: Pass along the mutex mechanism to the child via args[1]. testglobalmutex.c: Invoke test for every global mutex method available. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@65148 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/abts.c10
-rw-r--r--test/globalmutexchild.c13
-rw-r--r--test/testglobalmutex.c68
3 files changed, 77 insertions, 14 deletions
diff --git a/test/abts.c b/test/abts.c
index 602d12cf1..f4f69d53a 100644
--- a/test/abts.c
+++ b/test/abts.c
@@ -85,10 +85,11 @@ static void end_suite(abts_suite *suite)
}
}
-abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name)
+abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name_full)
{
sub_suite *subsuite;
char *p;
+ const char *suite_name;
curr_char = 0;
/* Only end the suite if we actually ran it */
@@ -100,7 +101,12 @@ abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name)
subsuite->num_test = 0;
subsuite->failed = 0;
subsuite->next = NULL;
- p = strchr(suite_name, '.');
+ /* suite_name_full is the complete path of the source code; strip out. */
+ suite_name = strrchr(suite_name_full, '/') + 1;
+ if (!suite_name) {
+ suite_name = suite_name_full;
+ }
+ p = strrchr(suite_name, '.');
if (p)
subsuite->name = memcpy(calloc(p - suite_name + 1, 1),
suite_name, p - suite_name);
diff --git a/test/globalmutexchild.c b/test/globalmutexchild.c
index 34ba178db..c4032bf41 100644
--- a/test/globalmutexchild.c
+++ b/test/globalmutexchild.c
@@ -29,13 +29,24 @@ int main(int argc, const char * const argv[])
{
apr_pool_t *p;
int i = 0;
+ apr_lockmech_e mech;
apr_global_mutex_t *global_lock;
+ apr_status_t rv;
apr_initialize();
atexit(apr_terminate);
apr_pool_create(&p, NULL);
- apr_global_mutex_create(&global_lock, LOCKNAME, APR_LOCK_DEFAULT, p);
+ if (argc >= 2) {
+ mech = (apr_lockmech_e)apr_strtoi64(argv[1], NULL, 0);
+ }
+ else {
+ mech = APR_LOCK_DEFAULT;
+ }
+ rv = apr_global_mutex_create(&global_lock, LOCKNAME, mech, p);
+ if (rv != APR_SUCCESS) {
+ exit(-rv);
+ }
apr_global_mutex_child_init(&global_lock, LOCKNAME, p);
while (1) {
diff --git a/test/testglobalmutex.c b/test/testglobalmutex.c
index 718e72953..08ebc39d6 100644
--- a/test/testglobalmutex.c
+++ b/test/testglobalmutex.c
@@ -19,10 +19,11 @@
#include "apr_errno.h"
#include "testutil.h"
-static void launch_child(abts_case *tc, apr_proc_t *proc, apr_pool_t *p)
+static void launch_child(abts_case *tc, apr_lockmech_e mech,
+ apr_proc_t *proc, apr_pool_t *p)
{
apr_procattr_t *procattr;
- const char *args[2];
+ const char *args[3];
apr_status_t rv;
rv = apr_procattr_create(&procattr, p);
@@ -36,7 +37,8 @@ static void launch_child(abts_case *tc, apr_proc_t *proc, apr_pool_t *p)
apr_assert_success(tc, "Couldn't set error check in procattr", rv);
args[0] = "globalmutexchild" EXTENSION;
- args[1] = NULL;
+ args[1] = (const char*)apr_itoa(p, (int)mech);
+ args[2] = NULL;
rv = apr_proc_create(proc, "./globalmutexchild" EXTENSION, args, NULL,
procattr, p);
apr_assert_success(tc, "Couldn't launch program", rv);
@@ -54,21 +56,20 @@ static int wait_child(abts_case *tc, apr_proc_t *proc)
return exitcode;
}
-static void test_exclusive(abts_case *tc, void *data)
+static void test_exclusive(abts_case *tc, void *data, apr_lockmech_e mech)
{
apr_proc_t p1, p2, p3, p4;
apr_status_t rv;
apr_global_mutex_t *global_lock;
int x = 0;
- rv = apr_global_mutex_create(&global_lock, LOCKNAME, APR_LOCK_DEFAULT, p);
+ rv = apr_global_mutex_create(&global_lock, LOCKNAME, mech, p);
apr_assert_success(tc, "Error creating mutex", rv);
-
- launch_child(tc, &p1, p);
- launch_child(tc, &p2, p);
- launch_child(tc, &p3, p);
- launch_child(tc, &p4, p);
+ launch_child(tc, mech, &p1, p);
+ launch_child(tc, mech, &p2, p);
+ launch_child(tc, mech, &p3, p);
+ launch_child(tc, mech, &p4, p);
x += wait_child(tc, &p1);
x += wait_child(tc, &p2);
@@ -78,11 +79,56 @@ static void test_exclusive(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, MAX_COUNTER, x);
}
+static void test_exclusive_default(abts_case *tc, void *data)
+{
+ test_exclusive(tc, data, APR_LOCK_DEFAULT);
+}
+
+static void test_exclusive_posixsem(abts_case *tc, void *data)
+{
+ test_exclusive(tc, data, APR_LOCK_POSIXSEM);
+}
+
+static void test_exclusive_sysvsem(abts_case *tc, void *data)
+{
+ test_exclusive(tc, data, APR_LOCK_SYSVSEM);
+}
+
+static void test_exclusive_proc_pthread(abts_case *tc, void *data)
+{
+ test_exclusive(tc, data, APR_LOCK_PROC_PTHREAD);
+}
+
+static void test_exclusive_fcntl(abts_case *tc, void *data)
+{
+ test_exclusive(tc, data, APR_LOCK_FCNTL);
+}
+
+static void test_exclusive_flock(abts_case *tc, void *data)
+{
+ test_exclusive(tc, data, APR_LOCK_FLOCK);
+}
+
abts_suite *testglobalmutex(abts_suite *suite)
{
suite = ADD_SUITE(suite)
- abts_run_test(suite, test_exclusive, NULL);
+ abts_run_test(suite, test_exclusive_default, NULL);
+#if APR_HAS_POSIXSEM_SERIALIZE
+ abts_run_test(suite, test_exclusive_posixsem, NULL);
+#endif
+#if APR_HAS_SYSVSEM_SERIALIZE
+ abts_run_test(suite, test_exclusive_sysvsem, NULL);
+#endif
+#if APR_HAS_PROC_PTHREAD_SERIALIZE
+ abts_run_test(suite, test_exclusive_proc_pthread, NULL);
+#endif
+#if APR_HAS_FCNTL_SERIALIZE
+ abts_run_test(suite, test_exclusive_fcntl, NULL);
+#endif
+#if APR_HAS_FLOCK_SERIALIZE
+ abts_run_test(suite, test_exclusive_flock, NULL);
+#endif
return suite;
}