~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/test/testthread.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#include "apr_thread_proc.h"
 
18
#include "apr_errno.h"
 
19
#include "apr_general.h"
 
20
#include "errno.h"
 
21
#include "apr_time.h"
 
22
#include "testutil.h"
 
23
 
 
24
#if APR_HAS_THREADS
 
25
 
 
26
static apr_thread_mutex_t *thread_lock;
 
27
static apr_thread_once_t *control = NULL;
 
28
static int x = 0;
 
29
static int value = 0;
 
30
 
 
31
static apr_thread_t *t1;
 
32
static apr_thread_t *t2;
 
33
static apr_thread_t *t3;
 
34
static apr_thread_t *t4;
 
35
 
 
36
/* just some made up number to check on later */
 
37
static apr_status_t exit_ret_val = 123;
 
38
 
 
39
static void init_func(void)
 
40
{
 
41
    value++;
 
42
}
 
43
 
 
44
static void * APR_THREAD_FUNC thread_func1(apr_thread_t *thd, void *data)
 
45
{
 
46
    int i;
 
47
 
 
48
    apr_thread_once(control, init_func);
 
49
 
 
50
    for (i = 0; i < 10000; i++) {
 
51
        apr_thread_mutex_lock(thread_lock);
 
52
        x++;
 
53
        apr_thread_mutex_unlock(thread_lock);
 
54
    }
 
55
    apr_thread_exit(thd, exit_ret_val);
 
56
    return NULL;
 
57
 
58
 
 
59
static void thread_init(abts_case *tc, void *data)
 
60
{
 
61
    apr_status_t rv;
 
62
 
 
63
    rv = apr_thread_once_init(&control, p);
 
64
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 
65
 
 
66
    rv = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_DEFAULT, p); 
 
67
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 
68
}
 
69
 
 
70
static void create_threads(abts_case *tc, void *data)
 
71
{
 
72
    apr_status_t rv;
 
73
 
 
74
    rv = apr_thread_create(&t1, NULL, thread_func1, NULL, p);
 
75
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 
76
    rv = apr_thread_create(&t2, NULL, thread_func1, NULL, p);
 
77
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 
78
    rv = apr_thread_create(&t3, NULL, thread_func1, NULL, p);
 
79
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 
80
    rv = apr_thread_create(&t4, NULL, thread_func1, NULL, p);
 
81
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 
82
}
 
83
 
 
84
static void join_threads(abts_case *tc, void *data)
 
85
{
 
86
    apr_status_t s;
 
87
 
 
88
    apr_thread_join(&s, t1);
 
89
    ABTS_INT_EQUAL(tc, exit_ret_val, s);
 
90
    apr_thread_join(&s, t2);
 
91
    ABTS_INT_EQUAL(tc, exit_ret_val, s);
 
92
    apr_thread_join(&s, t3);
 
93
    ABTS_INT_EQUAL(tc, exit_ret_val, s);
 
94
    apr_thread_join(&s, t4);
 
95
    ABTS_INT_EQUAL(tc, exit_ret_val, s);
 
96
}
 
97
 
 
98
static void check_locks(abts_case *tc, void *data)
 
99
{
 
100
    ABTS_INT_EQUAL(tc, 40000, x);
 
101
}
 
102
 
 
103
static void check_thread_once(abts_case *tc, void *data)
 
104
{
 
105
    ABTS_INT_EQUAL(tc, 1, value);
 
106
}
 
107
 
 
108
#else
 
109
 
 
110
static void threads_not_impl(abts_case *tc, void *data)
 
111
{
 
112
    ABTS_NOT_IMPL(tc, "Threads not implemented on this platform");
 
113
}
 
114
 
 
115
#endif
 
116
 
 
117
abts_suite *testthread(abts_suite *suite)
 
118
{
 
119
    suite = ADD_SUITE(suite)
 
120
 
 
121
#if !APR_HAS_THREADS
 
122
    abts_run_test(suite, threads_not_impl, NULL);
 
123
#else
 
124
    abts_run_test(suite, thread_init, NULL);
 
125
    abts_run_test(suite, create_threads, NULL);
 
126
    abts_run_test(suite, join_threads, NULL);
 
127
    abts_run_test(suite, check_locks, NULL);
 
128
    abts_run_test(suite, check_thread_once, NULL);
 
129
#endif
 
130
 
 
131
    return suite;
 
132
}
 
133