~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/tests/libsvn_subr/root-pools-test.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * root-pools-test.c -- test the svn_root_pools__* API
 
3
 *
 
4
 * ====================================================================
 
5
 *    Licensed to the Apache Software Foundation (ASF) under one
 
6
 *    or more contributor license agreements.  See the NOTICE file
 
7
 *    distributed with this work for additional information
 
8
 *    regarding copyright ownership.  The ASF licenses this file
 
9
 *    to you under the Apache License, Version 2.0 (the
 
10
 *    "License"); you may not use this file except in compliance
 
11
 *    with the License.  You may obtain a copy of the License at
 
12
 *
 
13
 *      http://www.apache.org/licenses/LICENSE-2.0
 
14
 *
 
15
 *    Unless required by applicable law or agreed to in writing,
 
16
 *    software distributed under the License is distributed on an
 
17
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
18
 *    KIND, either express or implied.  See the License for the
 
19
 *    specific language governing permissions and limitations
 
20
 *    under the License.
 
21
 * ====================================================================
 
22
 */
 
23
 
 
24
#include <apr_pools.h>
 
25
#include <apr_thread_proc.h>
 
26
#include <apr_thread_cond.h>
 
27
 
 
28
#include "private/svn_atomic.h"
 
29
#include "private/svn_subr_private.h"
 
30
 
 
31
#include "../svn_test.h"
 
32
 
 
33
/* do a few allocations of various sizes from POOL */
 
34
static void
 
35
do_some_allocations(apr_pool_t *pool)
 
36
{
 
37
  int i;
 
38
  apr_size_t fib = 1, fib1 = 0, fib2 = 0;
 
39
  for (i = 0; i < 25; ++i)      /* fib(25) = 75025 */
 
40
    {
 
41
      apr_pcalloc(pool, fib1);
 
42
      fib2 = fib1;
 
43
      fib1 = fib;
 
44
      fib += fib2;
 
45
    }
 
46
}
 
47
 
 
48
/* allocate, use and recycle a pool from POOLs a few times */
 
49
static void
 
50
use_root_pool(svn_root_pools__t *pools)
 
51
{
 
52
  int i;
 
53
  for (i = 0; i < 1000; ++i)
 
54
    {
 
55
      apr_pool_t *pool = svn_root_pools__acquire_pool(pools);
 
56
      do_some_allocations(pool);
 
57
      svn_root_pools__release_pool(pool, pools);
 
58
    }
 
59
}
 
60
 
 
61
#if APR_HAS_THREADS
 
62
static void *
 
63
APR_THREAD_FUNC thread_func(apr_thread_t *tid, void *data)
 
64
{
 
65
  /* give all threads a good chance to get started by the scheduler */
 
66
  apr_thread_yield();
 
67
 
 
68
  use_root_pool(data);
 
69
  apr_thread_exit(tid, APR_SUCCESS);
 
70
 
 
71
  return NULL;
 
72
}
 
73
#endif
 
74
 
 
75
static svn_error_t *
 
76
test_root_pool(apr_pool_t *pool)
 
77
{
 
78
  svn_root_pools__t *pools;
 
79
  SVN_ERR(svn_root_pools__create(&pools));
 
80
  use_root_pool(pools);
 
81
 
 
82
  return SVN_NO_ERROR;
 
83
}
 
84
 
 
85
#define APR_ERR(expr)                           \
 
86
  do {                                          \
 
87
    apr_status_t status = (expr);               \
 
88
    if (status)                                 \
 
89
      return svn_error_wrap_apr(status, NULL);  \
 
90
  } while (0)
 
91
 
 
92
static svn_error_t *
 
93
test_root_pool_concurrency(apr_pool_t *pool)
 
94
{
 
95
#if APR_HAS_THREADS
 
96
  /* The svn_root_pools__t container is supposed to be thread-safe.
 
97
     Do some multi-threaded access and hope that there are no segfaults.
 
98
   */
 
99
  enum { THREAD_COUNT = 10 };
 
100
  svn_root_pools__t *pools;
 
101
  apr_thread_t *threads[THREAD_COUNT];
 
102
  int i;
 
103
 
 
104
  SVN_ERR(svn_root_pools__create(&pools));
 
105
 
 
106
  for (i = 0; i < THREAD_COUNT; ++i)
 
107
    APR_ERR(apr_thread_create(&threads[i], NULL, thread_func, pools, pool));
 
108
 
 
109
  /* wait for the threads to finish */
 
110
  for (i = 0; i < THREAD_COUNT; ++i)
 
111
    {
 
112
      apr_status_t retval;
 
113
      APR_ERR(apr_thread_join(&retval, threads[i]));
 
114
      APR_ERR(retval);
 
115
    }
 
116
#endif
 
117
 
 
118
  return SVN_NO_ERROR;
 
119
}
 
120
 
 
121
 
 
122
/* The test table.  */
 
123
 
 
124
static int max_threads = 1;
 
125
 
 
126
static struct svn_test_descriptor_t test_funcs[] =
 
127
  {
 
128
    SVN_TEST_NULL,
 
129
    SVN_TEST_PASS2(test_root_pool,
 
130
                   "test root pool recycling"),
 
131
    SVN_TEST_SKIP2(test_root_pool_concurrency,
 
132
                   ! APR_HAS_THREADS,
 
133
                   "test concurrent root pool recycling"),
 
134
    SVN_TEST_NULL
 
135
  };
 
136
 
 
137
SVN_TEST_MAIN