Apache HTTPD
testrmm.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. 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_shm.h"
18#include "apr_rmm.h"
19#include "apr_errno.h"
20#include "apr_general.h"
21#include "apr_lib.h"
22#include "apr_strings.h"
23#include "apr_time.h"
24#include "abts.h"
25#include "testutil.h"
26
27#if APR_HAS_SHARED_MEMORY
28
29#define FRAG_SIZE 80
30#define FRAG_COUNT 10
31#define SHARED_SIZE (apr_size_t)(FRAG_SIZE * FRAG_COUNT * sizeof(char*))
32
33static void test_rmm(abts_case *tc, void *data)
34{
35 apr_status_t rv;
41 int i;
42 void *entity;
43
44 rv = apr_pool_create(&pool, p);
46
47 /* We're going to want 10 blocks of data from our target rmm. */
51
52 if (rv != APR_SUCCESS)
53 return;
54
57
58 if (rv != APR_SUCCESS)
59 return;
60
61 /* Creating each fragment of size fragsize */
64 for (i = 0; i < FRAG_COUNT; i++) {
66 }
67
68 /* Checking for out of memory allocation */
70 ABTS_TRUE(tc, !off2);
71
72 /* Checking each fragment for address alignment */
73 for (i = 0; i < FRAG_COUNT; i++) {
74 char *c = apr_rmm_addr_get(rmm, off[i]);
76
77 ABTS_TRUE(tc, !!off[i]);
78 ABTS_TRUE(tc, !(sc & 7));
79 }
80
81 /* Setting each fragment to a unique value */
82 for (i = 0; i < FRAG_COUNT; i++) {
83 int j;
84 char **c = apr_rmm_addr_get(rmm, off[i]);
85 for (j = 0; j < FRAG_SIZE; j++, c++) {
86 *c = apr_itoa(pool, i + j);
87 }
88 }
89
90 /* Checking each fragment for its unique value */
91 for (i = 0; i < FRAG_COUNT; i++) {
92 int j;
93 char **c = apr_rmm_addr_get(rmm, off[i]);
94 for (j = 0; j < FRAG_SIZE; j++, c++) {
95 char *d = apr_itoa(pool, i + j);
96 ABTS_STR_EQUAL(tc, d, *c);
97 }
98 }
99
100 /* Freeing each fragment */
101 for (i = 0; i < FRAG_COUNT; i++) {
102 rv = apr_rmm_free(rmm, off[i]);
104 }
105
106 /* Creating one large segment */
108
109 /* Setting large segment */
110 for (i = 0; i < FRAG_COUNT * FRAG_SIZE; i++) {
111 char **c = apr_rmm_addr_get(rmm, off[0]);
112 c[i] = apr_itoa(pool, i);
113 }
114
115 /* Freeing large segment */
116 rv = apr_rmm_free(rmm, off[0]);
118
119 /* Creating each fragment of size fragsize */
120 for (i = 0; i < FRAG_COUNT; i++) {
122 }
123
124 /* Freeing each fragment backwards */
125 for (i = FRAG_COUNT - 1; i >= 0; i--) {
126 rv = apr_rmm_free(rmm, off[i]);
128 }
129
130 /* Creating one large segment (again) */
132
133 /* Freeing large segment */
134 rv = apr_rmm_free(rmm, off[0]);
136
137 /* Checking realloc */
138 off[0] = apr_rmm_calloc(rmm, SHARED_SIZE - 100);
139 off[1] = apr_rmm_calloc(rmm, 100);
140 ABTS_TRUE(tc, !!off[0]);
141 ABTS_TRUE(tc, !!off[1]);
142
144 rv = apr_rmm_free(rmm, off[0]);
146
147 {
148 unsigned char *c = entity;
149
150 /* Fill in the region; the first half with zereos, which will
151 * likely catch the apr_rmm_realloc offset calculation bug by
152 * making it think the old region was zero length. */
153 for (i = 0; i < 100; i++) {
154 c[i] = (i < 50) ? 0 : i;
155 }
156 }
157
158 /* now we can realloc off[1] and get many more bytes */
160 ABTS_TRUE(tc, !!off[0]);
161
162 {
163 unsigned char *c = apr_rmm_addr_get(rmm, off[0]);
164
165 /* fill in the region */
166 for (i = 0; i < 100; i++) {
167 ABTS_TRUE(tc, c[i] == (i < 50 ? 0 : i));
168 }
169 }
170
171 rv = apr_rmm_destroy(rmm);
173
174 rv = apr_shm_destroy(shm);
176
178}
179
180#endif /* APR_HAS_SHARED_MEMORY */
181
183{
184 suite = ADD_SUITE(suite);
185
186#if APR_HAS_SHARED_MEMORY
187 abts_run_test(suite, test_rmm, NULL);
188#endif
189
190 return suite;
191}
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ABTS_TRUE(a, b)
Definition abts.h:127
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
APR Error Codes.
APR Miscellaneous library routines.
APR general purpose library routines.
APR-UTIL Relocatable Memory Management Routines.
APR Shared Memory Routines.
apr_size_t const unsigned char unsigned int unsigned int d
Definition apr_siphash.h:72
APR Strings library.
APR Time Library.
apr_size_t apr_rmm_off_t
Definition apr_rmm.h:43
void * entity
Definition apr_rmm.h:95
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
apr_vformatter_buff_t * c
Definition apr_lib.h:175
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
apr_shm_t * shm
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
abts_suite * testrmm(abts_suite *suite)
Definition testrmm.c:182
#define SHARED_SIZE
Definition testshm.h:35