bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / test / testoc.c
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 "test_apr.h"
18 #include "apr_thread_proc.h"
19 #include "apr_errno.h"
20 #include "apr_general.h"
21 #include "apr_lib.h"
22 #include "apr_strings.h"
23
24 #if APR_HAS_OTHER_CHILD
25
26 /* XXX I'm sure there has to be a better way to do this ... */
27 #ifdef WIN32
28 #define EXTENSION ".exe"
29 #elif NETWARE
30 #define EXTENSION ".nlm"
31 #else
32 #define EXTENSION
33 #endif
34
35 static char reasonstr[256];
36
37 static void ocmaint(int reason, void *data, int status)
38 {
39     switch (reason) {
40     case APR_OC_REASON_DEATH:
41         apr_cpystrn(reasonstr, "APR_OC_REASON_DEATH", 
42                     strlen("APR_OC_REASON_DEATH") + 1);
43         break;
44     case APR_OC_REASON_LOST:
45         apr_cpystrn(reasonstr, "APR_OC_REASON_LOST", 
46                     strlen("APR_OC_REASON_LOST") + 1);
47         break;
48     case APR_OC_REASON_UNWRITABLE:
49         apr_cpystrn(reasonstr, "APR_OC_REASON_UNWRITEABLE", 
50                     strlen("APR_OC_REASON_UNWRITEABLE") + 1);
51         break;
52     case APR_OC_REASON_RESTART:
53         apr_cpystrn(reasonstr, "APR_OC_REASON_RESTART", 
54                     strlen("APR_OC_REASON_RESTART") + 1);
55         break;
56     }
57 }
58
59 #ifndef SIGKILL
60 #define SIGKILL 1
61 #endif
62
63 /* It would be great if we could stress this stuff more, and make the test
64  * more granular.
65  */
66 static void test_child_kill(CuTest *tc)
67 {
68     apr_file_t *std = NULL;
69     apr_proc_t newproc;
70     apr_procattr_t *procattr = NULL;
71     const char *args[3];
72     apr_status_t rv;
73
74     args[0] = apr_pstrdup(p, "occhild" EXTENSION);
75     args[1] = apr_pstrdup(p, "-X");
76     args[2] = NULL;
77
78     rv = apr_procattr_create(&procattr, p);
79     CuAssertIntEquals(tc, APR_SUCCESS, rv);
80
81     rv = apr_procattr_io_set(procattr, APR_FULL_BLOCK, APR_NO_PIPE, 
82                              APR_NO_PIPE);
83     CuAssertIntEquals(tc, APR_SUCCESS, rv);
84
85     rv = apr_proc_create(&newproc, "./occhild" EXTENSION, args, NULL, procattr, p);
86     CuAssertIntEquals(tc, APR_SUCCESS, rv);
87     CuAssertPtrNotNull(tc, newproc.in);
88     CuAssertPtrEquals(tc, NULL, newproc.out);
89     CuAssertPtrEquals(tc, NULL, newproc.err);
90
91     std = newproc.in;
92
93     apr_proc_other_child_register(&newproc, ocmaint, NULL, std, p);
94
95     apr_sleep(apr_time_from_sec(1));
96     rv = apr_proc_kill(&newproc, SIGKILL);
97     CuAssertIntEquals(tc, APR_SUCCESS, rv);
98     
99     /* allow time for things to settle... */
100     apr_sleep(apr_time_from_sec(3));
101     
102     apr_proc_other_child_check();
103     CuAssertStrEquals(tc, "APR_OC_REASON_DEATH", reasonstr);
104 }    
105 #else
106
107 static void oc_not_impl(CuTest *tc)
108 {
109     CuNotImpl(tc, "Other child logic not implemented on this platform");
110 }
111 #endif
112
113 CuSuite *testoc(void)
114 {
115     CuSuite *suite = CuSuiteNew("Other Child");
116
117 #if !APR_HAS_OTHER_CHILD
118     SUITE_ADD_TEST(suite, oc_not_impl);
119 #else
120
121     SUITE_ADD_TEST(suite, test_child_kill); 
122
123 #endif
124     return suite;
125 }
126