bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / test / testsockopt.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 "apr_network_io.h"
18 #include "apr_errno.h"
19 #include "apr_general.h"
20 #include "apr_lib.h"
21 #include "test_apr.h"
22
23 static apr_socket_t *sock = NULL;
24
25 static void create_socket(CuTest *tc)
26 {
27     apr_status_t rv;
28
29     rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, p);
30     CuAssertIntEquals(tc, APR_SUCCESS, rv);
31     CuAssertPtrNotNull(tc, sock);
32 }
33
34 static void set_keepalive(CuTest *tc)
35 {
36     apr_status_t rv;
37     apr_int32_t ck;
38
39     rv = apr_socket_opt_set(sock, APR_SO_KEEPALIVE, 1);
40     CuAssertIntEquals(tc, APR_SUCCESS, rv);
41
42     rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck);
43     CuAssertIntEquals(tc, APR_SUCCESS, rv);
44     CuAssertIntEquals(tc, 1, ck);
45 }
46
47 static void set_debug(CuTest *tc)
48 {
49     apr_status_t rv1, rv2;
50     apr_int32_t ck;
51     
52     /* On some platforms APR_SO_DEBUG can only be set as root; just test
53      * for get/set consistency of this option. */
54     rv1 = apr_socket_opt_set(sock, APR_SO_DEBUG, 1);
55     rv2 = apr_socket_opt_get(sock, APR_SO_DEBUG, &ck);
56     apr_assert_success(tc, "get SO_DEBUG option", rv2);
57     if (APR_STATUS_IS_SUCCESS(rv1)) {
58         CuAssertIntEquals(tc, 1, ck);
59     } else {
60         CuAssertIntEquals(tc, 0, ck);
61     }
62 }
63
64 static void remove_keepalive(CuTest *tc)
65 {
66     apr_status_t rv;
67     apr_int32_t ck;
68
69     rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck);
70     CuAssertIntEquals(tc, APR_SUCCESS, rv);
71     CuAssertIntEquals(tc, 1, ck);
72
73     rv = apr_socket_opt_set(sock, APR_SO_KEEPALIVE, 0);
74     CuAssertIntEquals(tc, APR_SUCCESS, rv);
75
76     rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck);
77     CuAssertIntEquals(tc, APR_SUCCESS, rv);
78     CuAssertIntEquals(tc, 0, ck);
79 }
80
81 static void corkable(CuTest *tc)
82 {
83 #if !APR_HAVE_CORKABLE_TCP
84     CuNotImpl(tc, "TCP isn't corkable");
85 #else
86     apr_status_t rv;
87     apr_int32_t ck;
88
89     rv = apr_socket_opt_set(sock, APR_TCP_NODELAY, 1);
90     CuAssertIntEquals(tc, APR_SUCCESS, rv);
91
92     rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
93     CuAssertIntEquals(tc, APR_SUCCESS, rv);
94     CuAssertIntEquals(tc, 1, ck);
95
96     rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 1);
97     CuAssertIntEquals(tc, APR_SUCCESS, rv);
98
99     rv = apr_socket_opt_get(sock, APR_TCP_NOPUSH, &ck);
100     CuAssertIntEquals(tc, APR_SUCCESS, rv);
101     CuAssertIntEquals(tc, 1, ck);
102
103     rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
104     CuAssertIntEquals(tc, APR_SUCCESS, rv);
105     CuAssertIntEquals(tc, 0, ck);
106
107     rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
108     CuAssertIntEquals(tc, APR_SUCCESS, rv);
109     
110     rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
111     CuAssertIntEquals(tc, APR_SUCCESS, rv);
112     CuAssertIntEquals(tc, 1, ck);
113 #endif
114 }
115
116 static void close_socket(CuTest *tc)
117 {
118     apr_status_t rv;
119
120     rv = apr_socket_close(sock);
121     CuAssertIntEquals(tc, APR_SUCCESS, rv);
122 }
123
124 CuSuite *testsockopt(void)
125 {
126     CuSuite *suite = CuSuiteNew("Socket Options");
127
128     SUITE_ADD_TEST(suite, create_socket);
129     SUITE_ADD_TEST(suite, set_keepalive);
130     SUITE_ADD_TEST(suite, set_debug);
131     SUITE_ADD_TEST(suite, remove_keepalive);
132     SUITE_ADD_TEST(suite, corkable);
133     SUITE_ADD_TEST(suite, close_socket);
134
135     return suite;
136 }
137