| 1 |
/* |
| 2 |
* Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MPL-2.0 |
| 5 |
* |
| 6 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 7 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 |
* file, you can obtain one at https://mozilla.org/MPL/2.0/. |
| 9 |
* |
| 10 |
* See the COPYRIGHT file distributed with this work for additional |
| 11 |
* information regarding copyright ownership. |
| 12 |
*/ |
| 13 |
|
| 14 |
#include <inttypes.h> |
| 15 |
#include <sched.h> /* IWYU pragma: keep */ |
| 16 |
#include <setjmp.h> |
| 17 |
#include <signal.h> |
| 18 |
#include <stdarg.h> |
| 19 |
#include <stdlib.h> |
| 20 |
#include <unistd.h> |
| 21 |
|
| 22 |
/* |
| 23 |
* As a workaround, include an OpenSSL header file before including cmocka.h, |
| 24 |
* because OpenSSL 3.1.0 uses __attribute__(malloc), conflicting with a |
| 25 |
* redefined malloc in cmocka.h. |
| 26 |
*/ |
| 27 |
#include <openssl/err.h> |
| 28 |
|
| 29 |
#define UNIT_TESTING |
| 30 |
#include <cmocka.h> |
| 31 |
|
| 32 |
#include <isc/loop.h> |
| 33 |
#include <isc/nonce.h> |
| 34 |
#include <isc/os.h> |
| 35 |
#include <isc/quota.h> |
| 36 |
#include <isc/refcount.h> |
| 37 |
#include <isc/sockaddr.h> |
| 38 |
#include <isc/thread.h> |
| 39 |
#include <isc/util.h> |
| 40 |
#include <isc/uv.h> |
| 41 |
|
| 42 |
#include "uv_wrap.h" |
| 43 |
#define KEEP_BEFORE |
| 44 |
|
| 45 |
#include "netmgr/tcp.c" |
| 46 |
#include "netmgr_common.h" |
| 47 |
|
| 48 |
#include <tests/isc.h> |
| 49 |
|
| 50 |
/* TCP */ |
| 51 |
ISC_LOOP_TEST_IMPL(tcp_noop) { |
| 52 |
stream_noop(arg); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
ISC_LOOP_TEST_IMPL(tcp_noresponse) { |
| 57 |
stream_noresponse(arg); |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
ISC_LOOP_TEST_IMPL(tcp_shutdownconnect) { |
| 62 |
stream_shutdownconnect(arg); |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
ISC_LOOP_TEST_IMPL(tcp_shutdownread) { |
| 67 |
stream_shutdownread(arg); |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
ISC_LOOP_TEST_IMPL(tcp_timeout_recovery) { |
| 72 |
stream_timeout_recovery(arg); |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
ISC_LOOP_TEST_IMPL(tcp_recv_one) { |
| 77 |
stream_recv_one(arg); |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
ISC_LOOP_TEST_IMPL(tcp_recv_two) { |
| 82 |
stream_recv_two(arg); |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
ISC_LOOP_TEST_IMPL(tcp_recv_send) { |
| 87 |
stream_recv_send(arg); |
| 88 |
return; |
| 89 |
} |
| 90 |
|
| 91 |
ISC_LOOP_TEST_IMPL(tcp_recv_send_sendback) { |
| 92 |
allow_send_back = true; |
| 93 |
stream_recv_send(arg); |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
/* TCP Quota */ |
| 98 |
|
| 99 |
ISC_LOOP_TEST_IMPL(tcp_recv_one_quota) { |
| 100 |
atomic_store(&check_listener_quota, true); |
| 101 |
stream_recv_one(arg); |
| 102 |
return; |
| 103 |
} |
| 104 |
|
| 105 |
ISC_LOOP_TEST_IMPL(tcp_recv_two_quota) { |
| 106 |
atomic_store(&check_listener_quota, true); |
| 107 |
stream_recv_two(arg); |
| 108 |
return; |
| 109 |
} |
| 110 |
|
| 111 |
ISC_LOOP_TEST_IMPL(tcp_recv_send_quota) { |
| 112 |
atomic_store(&check_listener_quota, true); |
| 113 |
stream_recv_send(arg); |
| 114 |
} |
| 115 |
|
| 116 |
ISC_LOOP_TEST_IMPL(tcp_recv_send_quota_sendback) { |
| 117 |
atomic_store(&check_listener_quota, true); |
| 118 |
allow_send_back = true; |
| 119 |
stream_recv_send(arg); |
| 120 |
} |
| 121 |
|
| 122 |
ISC_TEST_LIST_START |
| 123 |
|
| 124 |
/* TCP */ |
| 125 |
ISC_TEST_ENTRY_CUSTOM(tcp_noop, stream_noop_setup, stream_noop_teardown) |
| 126 |
ISC_TEST_ENTRY_CUSTOM(tcp_noresponse, stream_noresponse_setup, |
| 127 |
stream_noresponse_teardown) |
| 128 |
ISC_TEST_ENTRY_CUSTOM(tcp_shutdownconnect, stream_shutdownconnect_setup, |
| 129 |
stream_shutdownconnect_teardown) |
| 130 |
ISC_TEST_ENTRY_CUSTOM(tcp_shutdownread, stream_shutdownread_setup, |
| 131 |
stream_shutdownread_teardown) |
| 132 |
ISC_TEST_ENTRY_CUSTOM(tcp_timeout_recovery, stream_timeout_recovery_setup, |
| 133 |
stream_timeout_recovery_teardown) |
| 134 |
ISC_TEST_ENTRY_CUSTOM(tcp_recv_one, stream_recv_one_setup, |
| 135 |
stream_recv_one_teardown) |
| 136 |
ISC_TEST_ENTRY_CUSTOM(tcp_recv_two, stream_recv_two_setup, |
| 137 |
stream_recv_two_teardown) |
| 138 |
ISC_TEST_ENTRY_CUSTOM(tcp_recv_send, stream_recv_send_setup, |
| 139 |
stream_recv_send_teardown) |
| 140 |
ISC_TEST_ENTRY_CUSTOM(tcp_recv_send_sendback, stream_recv_send_setup, |
| 141 |
stream_recv_send_teardown) |
| 142 |
|
| 143 |
/* TCP Quota */ |
| 144 |
ISC_TEST_ENTRY_CUSTOM(tcp_recv_one_quota, stream_recv_one_setup, |
| 145 |
stream_recv_one_teardown) |
| 146 |
ISC_TEST_ENTRY_CUSTOM(tcp_recv_two_quota, stream_recv_two_setup, |
| 147 |
stream_recv_two_teardown) |
| 148 |
ISC_TEST_ENTRY_CUSTOM(tcp_recv_send_quota, stream_recv_send_setup, |
| 149 |
stream_recv_send_teardown) |
| 150 |
ISC_TEST_ENTRY_CUSTOM(tcp_recv_send_quota_sendback, stream_recv_send_setup, |
| 151 |
stream_recv_send_teardown) |
| 152 |
|
| 153 |
ISC_TEST_LIST_END |
| 154 |
|
| 155 |
static int |
| 156 |
tcp_setup(void **state ISC_ATTR_UNUSED) { |
| 157 |
stream_port = TCP_TEST_PORT; |
| 158 |
stream_use_TLS = false; |
| 159 |
stream = true; |
| 160 |
|
| 161 |
return 0; |
| 162 |
} |
| 163 |
|
| 164 |
ISC_TEST_MAIN_CUSTOM(tcp_setup, NULL) |