Apache HTTPD
testpipe.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 <stdlib.h>
18
19#include "testutil.h"
20#include "apr_file_io.h"
21#include "apr_errno.h"
22#include "apr_general.h"
23#include "apr_lib.h"
24#include "apr_thread_proc.h"
25#include "apr_strings.h"
26
29
30static void create_pipe(abts_case *tc, void *data)
31{
32 apr_status_t rv;
33
38}
39
40static void close_pipe(abts_case *tc, void *data)
41{
42 apr_status_t rv;
43 apr_size_t nbytes = 256;
44 char buf[256];
45
49
52}
53
54static void set_timeout(abts_case *tc, void *data)
55{
56 apr_status_t rv;
58
63
66 ABTS_ASSERT(tc, "Timeout mismatch, expected -1", timeout == -1);
67
70
73 ABTS_ASSERT(tc, "Timeout mismatch, expected 1 second",
75}
76
77static void read_write(abts_case *tc, void *data)
78{
79 apr_status_t rv;
80 char *buf;
82
83 nbytes = strlen("this is a test");
84 buf = (char *)apr_palloc(p, nbytes + 1);
85
90
93
94 if (!rv) {
97 ABTS_SIZE_EQUAL(tc, 0, nbytes);
98 }
99}
100
101static void read_write_notimeout(abts_case *tc, void *data)
102{
103 apr_status_t rv;
104 char *buf = "this is a test";
105 char *input;
107
108 nbytes = strlen("this is a test");
109
114
116 ABTS_SIZE_EQUAL(tc, strlen("this is a test"), nbytes);
118
119 nbytes = 256;
120 input = apr_pcalloc(p, nbytes + 1);
123 ABTS_SIZE_EQUAL(tc, strlen("this is a test"), nbytes);
124 ABTS_STR_EQUAL(tc, "this is a test", input);
125}
126
127static void test_pipe_writefull(abts_case *tc, void *data)
128{
129 int iterations = 1000;
130 int i;
131 int bytes_per_iteration = 8000;
132 char *buf = (char *)calloc(bytes_per_iteration, 1);
133 char responsebuf[128];
135 int bytes_processed;
136 apr_proc_t proc = {0};
137 apr_procattr_t *procattr;
138 const char *args[2];
139 apr_status_t rv;
141
142 rv = apr_procattr_create(&procattr, p);
144
148
150 APR_ASSERT_SUCCESS(tc, "Couldn't set copy environment", rv);
151
152 rv = apr_procattr_error_check_set(procattr, 1);
154
155 args[0] = "readchild" EXTENSION;
156 args[1] = NULL;
157 rv = apr_proc_create(&proc, TESTBINPATH "readchild" EXTENSION, args, NULL, procattr, p);
159
162
165
166 i = iterations;
167 do {
170 } while (--i);
171
172 free(buf);
173
174 rv = apr_file_close(proc.in);
176
177 nbytes = sizeof(responsebuf);
182
183 ABTS_ASSERT(tc, "wait for child process",
185
186 ABTS_ASSERT(tc, "child terminated normally", why == APR_PROC_EXIT);
187}
188
190{
191 suite = ADD_SUITE(suite)
192
202
203 return suite;
204}
205
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ABTS_SIZE_EQUAL(a, b, c)
Definition abts.h:121
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_PTR_NOTNULL(a, b)
Definition abts.h:125
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_ASSERT(a, b, c)
Definition abts.h:130
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
#define EXTENSION
Definition testutil.h:43
#define TESTBINPATH
Definition testutil.h:35
#define APR_ASSERT_SUCCESS(tc, ctxt, rv)
Definition testutil.h:58
APR Error Codes.
APR File I/O Handling.
APR Miscellaneous library routines.
APR general purpose library routines.
APR Strings library.
APR Thread and Process Library.
const unsigned char * buf
Definition util_md5.h:50
#define APR_CHILD_DONE
Definition apr_errno.h:446
#define APR_STATUS_IS_TIMEUP(s)
Definition apr_errno.h:534
#define APR_STATUS_IS_EBADF(s)
Definition apr_errno.h:1264
apr_size_t size
const char * input
Definition apr_cstr.h:93
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void apr_size_t * nbytes
void * data
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
apr_proc_t * proc
#define APR_WRITE_BLOCK
const char const char *const * args
apr_exit_why_e
#define APR_CHILD_BLOCK
@ APR_WAIT
@ APR_PROC_EXIT
@ APR_PROGRAM_ENV
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
#define apr_time_from_sec(sec)
Definition apr_time.h:78
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
apr_file_t * in
apr_file_t * out
static void create_pipe(abts_case *tc, void *data)
Definition testpipe.c:30
static apr_file_t * writep
Definition testpipe.c:28
abts_suite * testpipe(abts_suite *suite)
Definition testpipe.c:189
static void read_write(abts_case *tc, void *data)
Definition testpipe.c:77
static void close_pipe(abts_case *tc, void *data)
Definition testpipe.c:40
static void read_write_notimeout(abts_case *tc, void *data)
Definition testpipe.c:101
static void set_timeout(abts_case *tc, void *data)
Definition testpipe.c:54
static void test_pipe_writefull(abts_case *tc, void *data)
Definition testpipe.c:127
static apr_file_t * readp
Definition testpipe.c:27
IN ULONG IN INT timeout
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray