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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "apr_thread_proc.h"
21 #include "apr_errno.h"
22 #include "apr_general.h"
24 #include "apr_strings.h"
28 static int run_basic_test(apr_pool_t *context)
30 apr_procattr_t *attr1 = NULL;
31 apr_procattr_t *attr2 = NULL;
38 fprintf(stdout, "Creating children to run network tests.......\n");
39 s1 = apr_procattr_create(&attr1, context);
40 s2 = apr_procattr_create(&attr2, context);
42 if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) {
43 fprintf(stderr, "Problem creating proc attrs\n");
47 args[0] = apr_pstrdup(context, "server");
49 s1 = apr_proc_create(&proc1, "./server", args, NULL, attr1, context);
51 /* Sleep for 5 seconds to ensure the server is setup before we begin */
53 args[0] = apr_pstrdup(context, "client");
54 s2 = apr_proc_create(&proc2, "./client", args, NULL, attr2, context);
56 if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) {
57 fprintf(stderr, "Problem spawning new process\n");
61 while ((s1 = apr_proc_wait(&proc1, NULL, NULL, APR_NOWAIT)) == APR_CHILD_NOTDONE &&
62 (s2 = apr_proc_wait(&proc2, NULL, NULL, APR_NOWAIT)) == APR_CHILD_NOTDONE) {
66 if (s1 == APR_SUCCESS) {
67 apr_proc_kill(&proc2, SIGTERM);
68 while (apr_proc_wait(&proc2, NULL, NULL, APR_WAIT) == APR_CHILD_NOTDONE);
71 apr_proc_kill(&proc1, SIGTERM);
72 while (apr_proc_wait(&proc1, NULL, NULL, APR_WAIT) == APR_CHILD_NOTDONE);
74 fprintf(stdout, "Network test completed.\n");
79 static int run_sendfile(apr_pool_t *context, int number)
81 apr_procattr_t *attr1 = NULL;
82 apr_procattr_t *attr2 = NULL;
89 fprintf(stdout, "Creating children to run network tests.......\n");
90 s1 = apr_procattr_create(&attr1, context);
91 s2 = apr_procattr_create(&attr2, context);
93 if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) {
94 fprintf(stderr, "Problem creating proc attrs\n");
98 args[0] = apr_pstrdup(context, "sendfile");
99 args[1] = apr_pstrdup(context, "server");
101 s1 = apr_proc_create(&proc1, "./sendfile", args, NULL, attr1, context);
103 /* Sleep for 5 seconds to ensure the server is setup before we begin */
105 args[1] = apr_pstrdup(context, "client");
108 args[2] = apr_pstrdup(context, "blocking");
112 args[2] = apr_pstrdup(context, "nonblocking");
116 args[2] = apr_pstrdup(context, "timeout");
121 s2 = apr_proc_create(&proc2, "./sendfile", args, NULL, attr2, context);
123 if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) {
124 fprintf(stderr, "Problem spawning new process\n");
128 while ((s1 = apr_proc_wait(&proc1, NULL, NULL, APR_NOWAIT)) == APR_CHILD_NOTDONE &&
129 (s2 = apr_proc_wait(&proc2, NULL, NULL, APR_NOWAIT)) == APR_CHILD_NOTDONE) {
133 if (s1 == APR_SUCCESS) {
134 apr_proc_kill(&proc2, SIGTERM);
135 while (apr_proc_wait(&proc2, NULL, NULL, APR_WAIT) == APR_CHILD_NOTDONE);
138 apr_proc_kill(&proc1, SIGTERM);
139 while (apr_proc_wait(&proc1, NULL, NULL, APR_WAIT) == APR_CHILD_NOTDONE);
141 fprintf(stdout, "Network test completed.\n");
146 int main(int argc, char *argv[])
148 apr_pool_t *context = NULL;
150 fprintf(stdout, "Initializing.........");
151 if (apr_initialize() != APR_SUCCESS) {
152 fprintf(stderr, "Something went wrong\n");
155 fprintf(stdout, "OK\n");
156 atexit(apr_terminate);
158 fprintf(stdout, "Creating context.......");
159 if (apr_pool_create(&context, NULL) != APR_SUCCESS) {
160 fprintf(stderr, "Could not create context\n");
163 fprintf(stdout, "OK\n");
165 fprintf(stdout, "This test relies on the process test working. Please\n");
166 fprintf(stdout, "run that test first, and only run this test when it\n");
167 fprintf(stdout, "completes successfully. Alternatively, you could run\n");
168 fprintf(stdout, "server and client by yourself.\n");
169 run_basic_test(context);
170 run_sendfile(context, 0);
171 run_sendfile(context, 1);
172 run_sendfile(context, 2);