aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/bad_client/bad_client.c5
-rwxr-xr-xtest/core/bad_client/gen_build_yaml.py1
-rw-r--r--test/core/client_channel/lb_policies_test.c (renamed from test/core/client_config/lb_policies_test.c)4
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_connectivity_test.c (renamed from test/core/client_config/resolvers/dns_resolver_connectivity_test.c)7
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_test.c (renamed from test/core/client_config/resolvers/dns_resolver_test.c)2
-rw-r--r--test/core/client_channel/resolvers/sockaddr_resolver_test.c (renamed from test/core/client_config/resolvers/sockaddr_resolver_test.c)16
-rw-r--r--test/core/client_channel/set_initial_connect_string_test.c (renamed from test/core/client_config/set_initial_connect_string_test.c)22
-rw-r--r--test/core/client_channel/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 (renamed from test/core/client_config/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342)0
-rw-r--r--test/core/client_channel/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 (renamed from test/core/client_config/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342)0
-rw-r--r--test/core/client_channel/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 (renamed from test/core/client_config/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11)0
-rw-r--r--test/core/client_channel/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f (renamed from test/core/client_config/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f)0
-rw-r--r--test/core/client_channel/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 (renamed from test/core/client_config/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118)0
-rw-r--r--test/core/client_channel/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc (renamed from test/core/client_config/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc)0
-rw-r--r--test/core/client_channel/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f (renamed from test/core/client_config/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f)0
-rw-r--r--test/core/client_channel/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 (renamed from test/core/client_config/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80)0
-rw-r--r--test/core/client_channel/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 (renamed from test/core/client_config/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971)0
-rw-r--r--test/core/client_channel/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc (renamed from test/core/client_config/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc)0
-rw-r--r--test/core/client_channel/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 (renamed from test/core/client_config/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1)0
-rw-r--r--test/core/client_channel/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf (renamed from test/core/client_config/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf)0
-rw-r--r--test/core/client_channel/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce (renamed from test/core/client_config/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce)0
-rw-r--r--test/core/client_channel/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 (renamed from test/core/client_config/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327)0
-rw-r--r--test/core/client_channel/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c (renamed from test/core/client_config/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c)0
-rw-r--r--test/core/client_channel/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc (renamed from test/core/client_config/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc)0
-rw-r--r--test/core/client_channel/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c (renamed from test/core/client_config/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c)0
-rw-r--r--test/core/client_channel/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 (renamed from test/core/client_config/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1)0
-rw-r--r--test/core/client_channel/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab (renamed from test/core/client_config/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab)0
-rw-r--r--test/core/client_channel/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 (renamed from test/core/client_config/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822)0
-rw-r--r--test/core/client_channel/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb (renamed from test/core/client_config/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb)0
-rw-r--r--test/core/client_channel/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 (renamed from test/core/client_config/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8)0
-rw-r--r--test/core/client_channel/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a (renamed from test/core/client_config/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a)0
-rw-r--r--test/core/client_channel/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb (renamed from test/core/client_config/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb)0
-rw-r--r--test/core/client_channel/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 (renamed from test/core/client_config/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58)0
-rw-r--r--test/core/client_channel/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 (renamed from test/core/client_config/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6)0
-rw-r--r--test/core/client_channel/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 (renamed from test/core/client_config/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1)0
-rw-r--r--test/core/client_channel/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb (renamed from test/core/client_config/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb)0
-rw-r--r--test/core/client_channel/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d (renamed from test/core/client_config/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d)0
-rw-r--r--test/core/client_channel/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 (renamed from test/core/client_config/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266)0
-rw-r--r--test/core/client_channel/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb (renamed from test/core/client_config/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb)0
-rw-r--r--test/core/client_channel/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 (renamed from test/core/client_config/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4)0
-rw-r--r--test/core/client_channel/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb (renamed from test/core/client_config/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb)0
-rw-r--r--test/core/client_channel/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 (renamed from test/core/client_config/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8)0
-rw-r--r--test/core/client_channel/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b (renamed from test/core/client_config/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b)0
-rw-r--r--test/core/client_channel/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 (renamed from test/core/client_config/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6)0
-rw-r--r--test/core/client_channel/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de (renamed from test/core/client_config/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de)0
-rw-r--r--test/core/client_channel/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d (renamed from test/core/client_config/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d)0
-rw-r--r--test/core/client_channel/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 (renamed from test/core/client_config/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38)0
-rw-r--r--test/core/client_channel/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 (renamed from test/core/client_config/uri_corpus/aba1472880406a318ce207ee79815b7acf087757)0
-rw-r--r--test/core/client_channel/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 (renamed from test/core/client_config/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2)0
-rw-r--r--test/core/client_channel/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd (renamed from test/core/client_config/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd)0
-rw-r--r--test/core/client_channel/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 (renamed from test/core/client_config/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4)0
-rw-r--r--test/core/client_channel/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 (renamed from test/core/client_config/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807)0
-rw-r--r--test/core/client_channel/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d (renamed from test/core/client_config/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d)0
-rw-r--r--test/core/client_channel/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 (renamed from test/core/client_config/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9)0
-rw-r--r--test/core/client_channel/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 (renamed from test/core/client_config/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245)0
-rw-r--r--test/core/client_channel/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c (renamed from test/core/client_config/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c)0
-rw-r--r--test/core/client_channel/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca (renamed from test/core/client_config/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca)0
-rw-r--r--test/core/client_channel/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a (renamed from test/core/client_config/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a)0
-rw-r--r--test/core/client_channel/uri_corpus/dns.txt (renamed from test/core/client_config/uri_corpus/dns.txt)0
-rw-r--r--test/core/client_channel/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd (renamed from test/core/client_config/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd)0
-rw-r--r--test/core/client_channel/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 (renamed from test/core/client_config/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71)0
-rw-r--r--test/core/client_channel/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee (renamed from test/core/client_config/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee)0
-rw-r--r--test/core/client_channel/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 (renamed from test/core/client_config/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2)0
-rw-r--r--test/core/client_channel/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 (renamed from test/core/client_config/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3)0
-rw-r--r--test/core/client_channel/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 (renamed from test/core/client_config/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67)0
-rw-r--r--test/core/client_channel/uri_corpus/f97598cff03306af3c70400608fec47268b5075d (renamed from test/core/client_config/uri_corpus/f97598cff03306af3c70400608fec47268b5075d)0
-rw-r--r--test/core/client_channel/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 (renamed from test/core/client_config/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101)0
-rw-r--r--test/core/client_channel/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 (renamed from test/core/client_config/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4)0
-rw-r--r--test/core/client_channel/uri_corpus/ipv4.txt (renamed from test/core/client_config/uri_corpus/ipv4.txt)0
-rw-r--r--test/core/client_channel/uri_corpus/ipv6.txt (renamed from test/core/client_config/uri_corpus/ipv6.txt)0
-rw-r--r--test/core/client_channel/uri_corpus/unix.txt (renamed from test/core/client_config/uri_corpus/unix.txt)0
-rw-r--r--test/core/client_channel/uri_fuzzer_test.c (renamed from test/core/client_config/uri_fuzzer_test.c)2
-rw-r--r--test/core/client_channel/uri_parser_test.c (renamed from test/core/client_config/uri_parser_test.c)2
-rw-r--r--test/core/end2end/bad_server_response_test.c8
-rw-r--r--test/core/end2end/cq_verifier_internal.h47
-rw-r--r--test/core/end2end/cq_verifier_native.c74
-rw-r--r--test/core/end2end/cq_verifier_uv.c112
-rw-r--r--test/core/end2end/dualstack_socket_test.c11
-rw-r--r--test/core/end2end/end2end_nosec_tests.c8
-rw-r--r--test/core/end2end/end2end_tests.c8
-rw-r--r--test/core/end2end/fake_resolver.c53
-rw-r--r--test/core/end2end/fixtures/h2_census.c2
-rw-r--r--test/core/end2end/fixtures/h2_compress.c2
-rw-r--r--test/core/end2end/fixtures/h2_fake_resolver.c2
-rw-r--r--test/core/end2end/fixtures/h2_fd.c11
-rw-r--r--test/core/end2end/fixtures/h2_full+pipe.c13
-rw-r--r--test/core/end2end/fixtures/h2_full+trace.c9
-rw-r--r--test/core/end2end/fixtures/h2_full.c2
-rw-r--r--test/core/end2end/fixtures/h2_http_proxy.c2
-rw-r--r--test/core/end2end/fixtures/h2_load_reporting.c2
-rw-r--r--test/core/end2end/fixtures/h2_proxy.c2
-rw-r--r--test/core/end2end/fixtures/h2_sockpair+trace.c13
-rw-r--r--test/core/end2end/fixtures/h2_sockpair.c6
-rw-r--r--test/core/end2end/fixtures/h2_sockpair_1byte.c6
-rw-r--r--test/core/end2end/fixtures/h2_uds.c2
-rw-r--r--test/core/end2end/fixtures/http_proxy.c27
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer.c18
-rw-r--r--test/core/end2end/fuzzers/client_fuzzer.c6
-rw-r--r--test/core/end2end/fuzzers/hpack.dictionary4
-rw-r--r--test/core/end2end/fuzzers/server_fuzzer.c6
-rwxr-xr-xtest/core/end2end/gen_build_yaml.py56
-rw-r--r--test/core/end2end/tests/max_message_length.c1
-rw-r--r--test/core/end2end/tests/network_status_change.c1
-rw-r--r--test/core/end2end/tests/resource_quota_server.c359
-rw-r--r--test/core/handshake/client_ssl.c311
-rw-r--r--test/core/handshake/server_ssl.c270
-rw-r--r--test/core/http/httpcli_test.c11
-rw-r--r--test/core/http/httpscli_test.c11
-rw-r--r--test/core/internal_api_canaries/iomgr.c1
-rw-r--r--test/core/iomgr/endpoint_pair_test.c6
-rw-r--r--test/core/iomgr/ev_epoll_linux_test.c8
-rw-r--r--test/core/iomgr/fd_conservation_posix_test.c6
-rw-r--r--test/core/iomgr/fd_posix_test.c11
-rw-r--r--test/core/iomgr/resolve_address_test.c1
-rw-r--r--test/core/iomgr/resource_quota_test.c749
-rw-r--r--test/core/iomgr/sockaddr_utils_test.c162
-rw-r--r--test/core/iomgr/socket_utils_test.c12
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c39
-rw-r--r--test/core/iomgr/tcp_posix_test.c47
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c92
-rw-r--r--test/core/iomgr/timer_heap_test.c11
-rw-r--r--test/core/iomgr/udp_server_test.c58
-rw-r--r--test/core/iomgr/wakeup_fd_cv_test.c10
-rw-r--r--test/core/security/credentials_test.c17
-rw-r--r--test/core/security/secure_endpoint_test.c5
-rw-r--r--test/core/surface/channel_create_test.c2
-rw-r--r--test/core/surface/concurrent_connectivity_test.c20
-rw-r--r--test/core/surface/secure_channel_create_test.c2
-rw-r--r--test/core/transport/chttp2/alpn_test.c19
-rw-r--r--test/core/util/mock_endpoint.c41
-rw-r--r--test/core/util/mock_endpoint.h3
-rw-r--r--test/core/util/passthru_endpoint.c34
-rw-r--r--test/core/util/passthru_endpoint.h3
-rw-r--r--test/core/util/port_posix.c6
-rw-r--r--test/core/util/port_server_client.c20
-rw-r--r--test/core/util/port_uv.c117
-rw-r--r--test/core/util/port_windows.c8
-rw-r--r--test/core/util/test_tcp_server.c21
-rw-r--r--test/cpp/codegen/compiler_test_golden8
-rw-r--r--test/cpp/end2end/async_end2end_test.cc5
-rw-r--r--test/cpp/end2end/end2end_test.cc41
-rw-r--r--test/cpp/end2end/hybrid_end2end_test.cc157
-rw-r--r--test/cpp/grpclb/grpclb_test.cc2
-rw-r--r--test/cpp/interop/interop_test.cc27
-rw-r--r--test/cpp/interop/stress_test.cc79
-rw-r--r--test/cpp/qps/client.h57
-rw-r--r--test/cpp/qps/client_async.cc11
-rw-r--r--test/cpp/qps/client_sync.cc7
-rw-r--r--test/cpp/qps/driver.cc31
-rw-r--r--test/cpp/qps/report.cc6
-rw-r--r--test/cpp/qps/server_async.cc6
-rw-r--r--test/cpp/qps/server_sync.cc6
151 files changed, 3134 insertions, 377 deletions
diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c
index be88d4a69a..a9638500b7 100644
--- a/test/core/bad_client/bad_client.c
+++ b/test/core/bad_client/bad_client.c
@@ -114,7 +114,10 @@ void grpc_run_bad_client_test(
grpc_init();
/* Create endpoints */
- sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536);
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("bad_client_test");
+ sfd = grpc_iomgr_create_endpoint_pair("fixture", resource_quota, 65536);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
/* Create server, completion events */
a.server = grpc_server_create(NULL, NULL);
diff --git a/test/core/bad_client/gen_build_yaml.py b/test/core/bad_client/gen_build_yaml.py
index fb86525b1a..32ab3f2137 100755
--- a/test/core/bad_client/gen_build_yaml.py
+++ b/test/core/bad_client/gen_build_yaml.py
@@ -83,6 +83,7 @@ def main():
'secure': 'no',
'src': ['test/core/bad_client/tests/%s.c' % t],
'vs_proj_dir': 'test',
+ 'exclude_iomgrs': ['uv'],
'deps': [
'bad_client_test',
'grpc_test_util_unsecure',
diff --git a/test/core/client_config/lb_policies_test.c b/test/core/client_channel/lb_policies_test.c
index fafff7bd69..844db5e6cb 100644
--- a/test/core/client_config/lb_policies_test.c
+++ b/test/core/client_channel/lb_policies_test.c
@@ -41,8 +41,8 @@
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
-#include "src/core/ext/client_config/client_channel.h"
-#include "src/core/ext/client_config/lb_policy_registry.h"
+#include "src/core/ext/client_channel/client_channel.h"
+#include "src/core/ext/client_channel/lb_policy_registry.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/support/string.h"
#include "src/core/lib/surface/channel.h"
diff --git a/test/core/client_config/resolvers/dns_resolver_connectivity_test.c b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
index d3b961959d..ffa167a0e7 100644
--- a/test/core/client_config/resolvers/dns_resolver_connectivity_test.c
+++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
@@ -36,7 +36,8 @@
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
-#include "src/core/ext/client_config/resolver_registry.h"
+#include "src/core/ext/client_channel/resolver_registry.h"
+#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/timer.h"
#include "test/core/util/test_config.h"
@@ -103,7 +104,7 @@ int main(int argc, char **argv) {
grpc_resolver *resolver = create_resolver("dns:test");
- grpc_resolver_result *result = (grpc_resolver_result *)1;
+ grpc_channel_args *result = (grpc_channel_args *)1;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_event ev1;
@@ -122,7 +123,7 @@ int main(int argc, char **argv) {
GPR_ASSERT(wait_loop(30, &ev2));
GPR_ASSERT(result != NULL);
- grpc_resolver_result_unref(&exec_ctx, result);
+ grpc_channel_args_destroy(result);
GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test");
grpc_exec_ctx_finish(&exec_ctx);
diff --git a/test/core/client_config/resolvers/dns_resolver_test.c b/test/core/client_channel/resolvers/dns_resolver_test.c
index c3f4cb1244..41a9125431 100644
--- a/test/core/client_config/resolvers/dns_resolver_test.c
+++ b/test/core/client_channel/resolvers/dns_resolver_test.c
@@ -35,7 +35,7 @@
#include <grpc/support/log.h>
-#include "src/core/ext/client_config/resolver_registry.h"
+#include "src/core/ext/client_channel/resolver_registry.h"
#include "test/core/util/test_config.h"
static void test_succeeds(grpc_resolver_factory *factory, const char *string) {
diff --git a/test/core/client_config/resolvers/sockaddr_resolver_test.c b/test/core/client_channel/resolvers/sockaddr_resolver_test.c
index b5d96efa1d..ebf311ab83 100644
--- a/test/core/client_config/resolvers/sockaddr_resolver_test.c
+++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.c
@@ -37,22 +37,24 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include "src/core/ext/client_config/resolver_registry.h"
-#include "src/core/ext/client_config/resolver_result.h"
+#include "src/core/ext/client_channel/resolver_registry.h"
+#include "src/core/lib/channel/channel_args.h"
#include "test/core/util/test_config.h"
typedef struct on_resolution_arg {
char *expected_server_name;
- grpc_resolver_result *resolver_result;
+ grpc_channel_args *resolver_result;
} on_resolution_arg;
void on_resolution_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
on_resolution_arg *res = arg;
- const char *server_name =
- grpc_resolver_result_get_server_name(res->resolver_result);
- GPR_ASSERT(strcmp(res->expected_server_name, server_name) == 0);
- grpc_resolver_result_unref(exec_ctx, res->resolver_result);
+ const grpc_arg *channel_arg =
+ grpc_channel_args_find(res->resolver_result, GRPC_ARG_SERVER_NAME);
+ GPR_ASSERT(channel_arg != NULL);
+ GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING);
+ GPR_ASSERT(strcmp(res->expected_server_name, channel_arg->value.string) == 0);
+ grpc_channel_args_destroy(res->resolver_result);
}
static void test_succeeds(grpc_resolver_factory *factory, const char *string) {
diff --git a/test/core/client_config/set_initial_connect_string_test.c b/test/core/client_channel/set_initial_connect_string_test.c
index 1b51424f7e..379f30fb9f 100644
--- a/test/core/client_config/set_initial_connect_string_test.c
+++ b/test/core/client_channel/set_initial_connect_string_test.c
@@ -30,6 +30,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
+
+/* With the addition of a libuv endpoint, sockaddr.h now includes uv.h when
+ using that endpoint. Because of various transitive includes in uv.h,
+ including windows.h on Windows, uv.h must be included before other system
+ headers. Therefore, sockaddr.h must always be included first */
+#include "src/core/lib/iomgr/sockaddr.h"
+
#include <string.h>
#include <grpc/grpc.h>
@@ -39,7 +46,7 @@
#include <grpc/support/slice.h>
#include <grpc/support/thd.h>
-#include "src/core/ext/client_config/initial_connect_string.h"
+#include "src/core/ext/client_channel/initial_connect_string.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "src/core/lib/support/string.h"
@@ -93,15 +100,14 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
grpc_endpoint_read(exec_ctx, tcp, &state.temp_incoming_buffer, &on_read);
}
-static void set_magic_initial_string(struct sockaddr **addr, size_t *addr_len,
+static void set_magic_initial_string(grpc_resolved_address **addr,
gpr_slice *connect_string) {
GPR_ASSERT(addr);
- GPR_ASSERT(addr_len);
+ GPR_ASSERT((*addr)->len);
*connect_string = gpr_slice_from_copied_string(magic_connect_string);
}
-static void reset_addr_and_set_magic_string(struct sockaddr **addr,
- size_t *addr_len,
+static void reset_addr_and_set_magic_string(grpc_resolved_address **addr,
gpr_slice *connect_string) {
struct sockaddr_in target;
*connect_string = gpr_slice_from_copied_string(magic_connect_string);
@@ -109,9 +115,9 @@ static void reset_addr_and_set_magic_string(struct sockaddr **addr,
target.sin_family = AF_INET;
target.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
target.sin_port = htons((uint16_t)server_port);
- *addr_len = sizeof(target);
- *addr = (struct sockaddr *)gpr_malloc(sizeof(target));
- memcpy(*addr, &target, sizeof(target));
+ (*addr)->len = sizeof(target);
+ *addr = (grpc_resolved_address *)gpr_malloc(sizeof(grpc_resolved_address));
+ memcpy((*addr)->addr, &target, sizeof(target));
}
static gpr_timespec n_sec_deadline(int seconds) {
diff --git a/test/core/client_config/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 b/test/core/client_channel/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342
index a85e7a8c21..a85e7a8c21 100644
--- a/test/core/client_config/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342
+++ b/test/core/client_channel/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342
diff --git a/test/core/client_config/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 b/test/core/client_channel/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342
index 597a6db294..597a6db294 100644
--- a/test/core/client_config/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342
+++ b/test/core/client_channel/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342
diff --git a/test/core/client_config/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 b/test/core/client_channel/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11
index d56b8fc6c8..d56b8fc6c8 100644
--- a/test/core/client_config/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11
+++ b/test/core/client_channel/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11
diff --git a/test/core/client_config/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f b/test/core/client_channel/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f
index 5b913f1bb8..5b913f1bb8 100644
--- a/test/core/client_config/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f
+++ b/test/core/client_channel/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f
diff --git a/test/core/client_config/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 b/test/core/client_channel/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118
index 76f157cda5..76f157cda5 100644
--- a/test/core/client_config/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118
+++ b/test/core/client_channel/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118
diff --git a/test/core/client_config/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc b/test/core/client_channel/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc
index 3936e8964c..3936e8964c 100644
--- a/test/core/client_config/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc
+++ b/test/core/client_channel/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc
diff --git a/test/core/client_config/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f b/test/core/client_channel/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f
index a94c4cf58d..a94c4cf58d 100644
--- a/test/core/client_config/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f
+++ b/test/core/client_channel/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f
diff --git a/test/core/client_config/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 b/test/core/client_channel/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80
index 875ac2a4f9..875ac2a4f9 100644
--- a/test/core/client_config/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80
+++ b/test/core/client_channel/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80
diff --git a/test/core/client_config/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 b/test/core/client_channel/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971
index 59469af528..59469af528 100644
--- a/test/core/client_config/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971
+++ b/test/core/client_channel/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971
diff --git a/test/core/client_config/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc b/test/core/client_channel/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc
index 2f902351bd..2f902351bd 100644
--- a/test/core/client_config/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc
+++ b/test/core/client_channel/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc
diff --git a/test/core/client_config/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 b/test/core/client_channel/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1
index 4bdc3f60c0..4bdc3f60c0 100644
--- a/test/core/client_config/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1
+++ b/test/core/client_channel/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1
diff --git a/test/core/client_config/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf b/test/core/client_channel/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf
index fb7665d0cc..fb7665d0cc 100644
--- a/test/core/client_config/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf
+++ b/test/core/client_channel/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf
diff --git a/test/core/client_config/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce b/test/core/client_channel/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce
index 6c1e22fa32..6c1e22fa32 100644
--- a/test/core/client_config/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce
+++ b/test/core/client_channel/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce
diff --git a/test/core/client_config/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 b/test/core/client_channel/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327
index 694d51dc9a..694d51dc9a 100644
--- a/test/core/client_config/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327
+++ b/test/core/client_channel/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327
diff --git a/test/core/client_config/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c b/test/core/client_channel/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c
index af80f07d19..af80f07d19 100644
--- a/test/core/client_config/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c
+++ b/test/core/client_channel/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c
diff --git a/test/core/client_config/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc b/test/core/client_channel/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc
index 725b2086c5..725b2086c5 100644
--- a/test/core/client_config/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc
+++ b/test/core/client_channel/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc
diff --git a/test/core/client_config/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c b/test/core/client_channel/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c
index 7f0f2ea6ea..7f0f2ea6ea 100644
--- a/test/core/client_config/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c
+++ b/test/core/client_channel/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c
diff --git a/test/core/client_config/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 b/test/core/client_channel/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1
index 23d52e19a8..23d52e19a8 100644
--- a/test/core/client_config/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1
+++ b/test/core/client_channel/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1
diff --git a/test/core/client_config/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab b/test/core/client_channel/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab
index f975f97059..f975f97059 100644
--- a/test/core/client_config/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab
+++ b/test/core/client_channel/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab
diff --git a/test/core/client_config/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 b/test/core/client_channel/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822
index d5fb7ba274..d5fb7ba274 100644
--- a/test/core/client_config/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822
+++ b/test/core/client_channel/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822
diff --git a/test/core/client_config/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb b/test/core/client_channel/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb
index 1860e1c5b4..1860e1c5b4 100644
--- a/test/core/client_config/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb
+++ b/test/core/client_channel/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb
diff --git a/test/core/client_config/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 b/test/core/client_channel/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8
index 1dc4931ac6..1dc4931ac6 100644
--- a/test/core/client_config/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8
+++ b/test/core/client_channel/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8
diff --git a/test/core/client_config/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a b/test/core/client_channel/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a
index 7b9532914e..7b9532914e 100644
--- a/test/core/client_config/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a
+++ b/test/core/client_channel/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a
diff --git a/test/core/client_config/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb b/test/core/client_channel/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb
index 4eaca39265..4eaca39265 100644
--- a/test/core/client_config/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb
+++ b/test/core/client_channel/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb
diff --git a/test/core/client_config/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 b/test/core/client_channel/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58
index fe908d213a..fe908d213a 100644
--- a/test/core/client_config/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58
+++ b/test/core/client_channel/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58
diff --git a/test/core/client_config/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 b/test/core/client_channel/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6
index 57cbd72dbc..57cbd72dbc 100644
--- a/test/core/client_config/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6
+++ b/test/core/client_channel/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6
diff --git a/test/core/client_config/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 b/test/core/client_channel/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1
index e13cf5a8e6..e13cf5a8e6 100644
--- a/test/core/client_config/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1
+++ b/test/core/client_channel/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1
diff --git a/test/core/client_config/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb b/test/core/client_channel/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb
index 0e7f44caf2..0e7f44caf2 100644
--- a/test/core/client_config/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb
+++ b/test/core/client_channel/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb
diff --git a/test/core/client_config/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d b/test/core/client_channel/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d
index 679f13e307..679f13e307 100644
--- a/test/core/client_config/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d
+++ b/test/core/client_channel/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d
diff --git a/test/core/client_config/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 b/test/core/client_channel/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266
index 58ecc7e2af..58ecc7e2af 100644
--- a/test/core/client_config/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266
+++ b/test/core/client_channel/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266
diff --git a/test/core/client_config/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb b/test/core/client_channel/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb
index ffd807b39e..ffd807b39e 100644
--- a/test/core/client_config/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb
+++ b/test/core/client_channel/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb
diff --git a/test/core/client_config/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 b/test/core/client_channel/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4
index 8ad79f9eb9..8ad79f9eb9 100644
--- a/test/core/client_config/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4
+++ b/test/core/client_channel/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4
diff --git a/test/core/client_config/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb b/test/core/client_channel/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb
index efb392b7d9..efb392b7d9 100644
--- a/test/core/client_config/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb
+++ b/test/core/client_channel/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb
diff --git a/test/core/client_config/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 b/test/core/client_channel/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8
index 7155222547..7155222547 100644
--- a/test/core/client_config/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8
+++ b/test/core/client_channel/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8
diff --git a/test/core/client_config/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b b/test/core/client_channel/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b
index 4061e02189..4061e02189 100644
--- a/test/core/client_config/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b
+++ b/test/core/client_channel/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b
diff --git a/test/core/client_config/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 b/test/core/client_channel/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6
index facb11c5ed..facb11c5ed 100644
--- a/test/core/client_config/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6
+++ b/test/core/client_channel/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6
diff --git a/test/core/client_config/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de b/test/core/client_channel/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de
index 736e63e7e7..736e63e7e7 100644
--- a/test/core/client_config/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de
+++ b/test/core/client_channel/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de
diff --git a/test/core/client_config/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d b/test/core/client_channel/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d
index dff2f8920d..dff2f8920d 100644
--- a/test/core/client_config/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d
+++ b/test/core/client_channel/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d
diff --git a/test/core/client_config/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 b/test/core/client_channel/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38
index 13a115481d..13a115481d 100644
--- a/test/core/client_config/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38
+++ b/test/core/client_channel/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38
diff --git a/test/core/client_config/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 b/test/core/client_channel/uri_corpus/aba1472880406a318ce207ee79815b7acf087757
index b7e7e970f8..b7e7e970f8 100644
--- a/test/core/client_config/uri_corpus/aba1472880406a318ce207ee79815b7acf087757
+++ b/test/core/client_channel/uri_corpus/aba1472880406a318ce207ee79815b7acf087757
diff --git a/test/core/client_config/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 b/test/core/client_channel/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2
index fe019fc409..fe019fc409 100644
--- a/test/core/client_config/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2
+++ b/test/core/client_channel/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2
diff --git a/test/core/client_config/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd b/test/core/client_channel/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd
index 6e12167b52..6e12167b52 100644
--- a/test/core/client_config/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd
+++ b/test/core/client_channel/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd
diff --git a/test/core/client_config/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 b/test/core/client_channel/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4
index 119b0808c9..119b0808c9 100644
--- a/test/core/client_config/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4
+++ b/test/core/client_channel/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4
diff --git a/test/core/client_config/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 b/test/core/client_channel/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807
index 01db5d8aa4..01db5d8aa4 100644
--- a/test/core/client_config/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807
+++ b/test/core/client_channel/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807
diff --git a/test/core/client_config/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d b/test/core/client_channel/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d
index 2ccb535449..2ccb535449 100644
--- a/test/core/client_config/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d
+++ b/test/core/client_channel/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d
diff --git a/test/core/client_config/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 b/test/core/client_channel/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9
index f3c0404be7..f3c0404be7 100644
--- a/test/core/client_config/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9
+++ b/test/core/client_channel/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9
diff --git a/test/core/client_config/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 b/test/core/client_channel/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245
index b5655220d7..b5655220d7 100644
--- a/test/core/client_config/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245
+++ b/test/core/client_channel/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245
diff --git a/test/core/client_config/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c b/test/core/client_channel/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c
index a7656724f5..a7656724f5 100644
--- a/test/core/client_config/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c
+++ b/test/core/client_channel/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c
diff --git a/test/core/client_config/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca b/test/core/client_channel/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca
index d658fb8ee0..d658fb8ee0 100644
--- a/test/core/client_config/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca
+++ b/test/core/client_channel/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca
diff --git a/test/core/client_config/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a b/test/core/client_channel/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a
index 6d37b5fd45..6d37b5fd45 100644
--- a/test/core/client_config/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a
+++ b/test/core/client_channel/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a
diff --git a/test/core/client_config/uri_corpus/dns.txt b/test/core/client_channel/uri_corpus/dns.txt
index 577e1054e4..577e1054e4 100644
--- a/test/core/client_config/uri_corpus/dns.txt
+++ b/test/core/client_channel/uri_corpus/dns.txt
diff --git a/test/core/client_config/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd b/test/core/client_channel/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd
index 497bfd37ee..497bfd37ee 100644
--- a/test/core/client_config/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd
+++ b/test/core/client_channel/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd
diff --git a/test/core/client_config/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 b/test/core/client_channel/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71
index 52f5a2382a..52f5a2382a 100644
--- a/test/core/client_config/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71
+++ b/test/core/client_channel/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71
diff --git a/test/core/client_config/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee b/test/core/client_channel/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee
index c3c93fed6a..c3c93fed6a 100644
--- a/test/core/client_config/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee
+++ b/test/core/client_channel/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee
diff --git a/test/core/client_config/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 b/test/core/client_channel/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2
index 45065e2f00..45065e2f00 100644
--- a/test/core/client_config/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2
+++ b/test/core/client_channel/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2
diff --git a/test/core/client_config/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 b/test/core/client_channel/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3
index 02151c8b6a..02151c8b6a 100644
--- a/test/core/client_config/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3
+++ b/test/core/client_channel/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3
diff --git a/test/core/client_config/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 b/test/core/client_channel/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67
index 8034e133d7..8034e133d7 100644
--- a/test/core/client_config/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67
+++ b/test/core/client_channel/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67
diff --git a/test/core/client_config/uri_corpus/f97598cff03306af3c70400608fec47268b5075d b/test/core/client_channel/uri_corpus/f97598cff03306af3c70400608fec47268b5075d
index 240946dbaa..240946dbaa 100644
--- a/test/core/client_config/uri_corpus/f97598cff03306af3c70400608fec47268b5075d
+++ b/test/core/client_channel/uri_corpus/f97598cff03306af3c70400608fec47268b5075d
diff --git a/test/core/client_config/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 b/test/core/client_channel/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101
index d089a59346..d089a59346 100644
--- a/test/core/client_config/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101
+++ b/test/core/client_channel/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101
diff --git a/test/core/client_config/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 b/test/core/client_channel/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4
index 66eefbcc14..66eefbcc14 100644
--- a/test/core/client_config/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4
+++ b/test/core/client_channel/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4
diff --git a/test/core/client_config/uri_corpus/ipv4.txt b/test/core/client_channel/uri_corpus/ipv4.txt
index fe29486b6e..fe29486b6e 100644
--- a/test/core/client_config/uri_corpus/ipv4.txt
+++ b/test/core/client_channel/uri_corpus/ipv4.txt
diff --git a/test/core/client_config/uri_corpus/ipv6.txt b/test/core/client_channel/uri_corpus/ipv6.txt
index 7b6932be00..7b6932be00 100644
--- a/test/core/client_config/uri_corpus/ipv6.txt
+++ b/test/core/client_channel/uri_corpus/ipv6.txt
diff --git a/test/core/client_config/uri_corpus/unix.txt b/test/core/client_channel/uri_corpus/unix.txt
index 7a0997ec9a..7a0997ec9a 100644
--- a/test/core/client_config/uri_corpus/unix.txt
+++ b/test/core/client_channel/uri_corpus/unix.txt
diff --git a/test/core/client_config/uri_fuzzer_test.c b/test/core/client_channel/uri_fuzzer_test.c
index f297140559..d2e3fb40ea 100644
--- a/test/core/client_config/uri_fuzzer_test.c
+++ b/test/core/client_channel/uri_fuzzer_test.c
@@ -37,7 +37,7 @@
#include <grpc/support/alloc.h>
-#include "src/core/ext/client_config/uri_parser.h"
+#include "src/core/ext/client_channel/uri_parser.h"
bool squelch = true;
bool leak_check = true;
diff --git a/test/core/client_config/uri_parser_test.c b/test/core/client_channel/uri_parser_test.c
index 323e8b6f70..5f32d3270c 100644
--- a/test/core/client_config/uri_parser_test.c
+++ b/test/core/client_channel/uri_parser_test.c
@@ -31,7 +31,7 @@
*
*/
-#include "src/core/ext/client_config/uri_parser.h"
+#include "src/core/ext/client_channel/uri_parser.h"
#include <string.h>
diff --git a/test/core/end2end/bad_server_response_test.c b/test/core/end2end/bad_server_response_test.c
index 5ed0eb64d2..9a3e1301f9 100644
--- a/test/core/end2end/bad_server_response_test.c
+++ b/test/core/end2end/bad_server_response_test.c
@@ -30,6 +30,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
+
+/* With the addition of a libuv endpoint, sockaddr.h now includes uv.h when
+ using that endpoint. Because of various transitive includes in uv.h,
+ including windows.h on Windows, uv.h must be included before other system
+ headers. Therefore, sockaddr.h must always be included first */
+#include "src/core/lib/iomgr/sockaddr.h"
+
#include <string.h>
#include <grpc/grpc.h>
@@ -40,7 +47,6 @@
#include <grpc/support/thd.h>
// #include "src/core/ext/transport/chttp2/transport/internal.h"
-#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/support/string.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/port.h"
diff --git a/test/core/end2end/cq_verifier_internal.h b/test/core/end2end/cq_verifier_internal.h
new file mode 100644
index 0000000000..1549608469
--- /dev/null
+++ b/test/core/end2end/cq_verifier_internal.h
@@ -0,0 +1,47 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPC_TEST_CORE_END2END_CQ_VERIFIER_INTERNAL_H
+#define GRPC_TEST_CORE_END2END_CQ_VERIFIER_INTERNAL_H
+
+#include "test/core/end2end/cq_verifier.h"
+
+typedef struct expectation expectation;
+
+expectation *cq_verifier_get_first_expectation(cq_verifier *v);
+
+void cq_verifier_set_first_expectation(cq_verifier *v, expectation *e);
+
+grpc_event cq_verifier_next_event(cq_verifier *v, int timeout_seconds);
+
+#endif /* GRPC_TEST_CORE_END2END_CQ_VERIFIER_INTERNAL_H */
diff --git a/test/core/end2end/cq_verifier_native.c b/test/core/end2end/cq_verifier_native.c
new file mode 100644
index 0000000000..b1fcb4beed
--- /dev/null
+++ b/test/core/end2end/cq_verifier_native.c
@@ -0,0 +1,74 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* This check is for testing only. */
+#ifndef GRPC_UV
+
+#include "test/core/end2end/cq_verifier_internal.h"
+
+/* the verifier itself */
+struct cq_verifier {
+ /* bound completion queue */
+ grpc_completion_queue *cq;
+ /* start of expectation list */
+ expectation *first_expectation;
+ uv_timer_t timer;
+};
+
+cq_verifier *cq_verifier_create(grpc_completion_queue *cq) {
+ cq_verifier *v = gpr_malloc(sizeof(cq_verifier));
+ v->cq = cq;
+ cq_verifier_set_first_expectation(v, NULL);
+ return v;
+}
+
+void cq_verifier_destroy(cq_verifier *v) {
+ cq_verify(v);
+ gpr_free(v);
+}
+
+expectation *cq_verifier_get_first_expectation(cq_verifier *v) {
+ return v->first_expectation;
+}
+
+void cq_verifier_set_first_expectation(cq_verifier *v, expectation *e) {
+ v->first_expectation = e;
+}
+
+grpc_event cq_verifier_next_event(cq_verifier *v, int timeout_seconds) {
+ const gpr_timespec deadline =
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(timeout_seconds);
+ return grpc_completion_queue_next(v->cq, deadline, NULL);
+}
+
+#endif /* GRPC_UV */
diff --git a/test/core/end2end/cq_verifier_uv.c b/test/core/end2end/cq_verifier_uv.c
new file mode 100644
index 0000000000..2b5a2ca495
--- /dev/null
+++ b/test/core/end2end/cq_verifier_uv.c
@@ -0,0 +1,112 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc/support/port_platform.h>
+
+#ifdef GRPC_UV
+
+#include <uv.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+
+#include "test/core/end2end/cq_verifier_internal.h"
+
+typedef enum timer_state {
+ TIMER_STARTED,
+ TIMER_TRIGGERED,
+ TIMER_CLOSED
+} timer_state;
+
+/* the verifier itself */
+struct cq_verifier {
+ /* bound completion queue */
+ grpc_completion_queue *cq;
+ /* start of expectation list */
+ expectation *first_expectation;
+ uv_timer_t timer;
+};
+
+cq_verifier *cq_verifier_create(grpc_completion_queue *cq) {
+ cq_verifier *v = gpr_malloc(sizeof(cq_verifier));
+ v->cq = cq;
+ v->first_expectation = NULL;
+ uv_timer_init(uv_default_loop(), &v->timer);
+ v->timer.data = (void *)TIMER_STARTED;
+ return v;
+}
+
+static void timer_close_cb(uv_handle_t *handle) {
+ handle->data = (void *)TIMER_CLOSED;
+}
+
+void cq_verifier_destroy(cq_verifier *v) {
+ cq_verify(v);
+ uv_close((uv_handle_t *)&v->timer, timer_close_cb);
+ while ((timer_state)v->timer.data != TIMER_CLOSED) {
+ uv_run(uv_default_loop(), UV_RUN_NOWAIT);
+ }
+ gpr_free(v);
+}
+
+expectation *cq_verifier_get_first_expectation(cq_verifier *v) {
+ return v->first_expectation;
+}
+
+void cq_verifier_set_first_expectation(cq_verifier *v, expectation *e) {
+ v->first_expectation = e;
+}
+
+static void timer_run_cb(uv_timer_t *timer) {
+ timer->data = (void *)TIMER_TRIGGERED;
+}
+
+grpc_event cq_verifier_next_event(cq_verifier *v, int timeout_seconds) {
+ uint64_t timeout_ms =
+ timeout_seconds < 0 ? 0 : (uint64_t)timeout_seconds * 1000;
+ grpc_event ev;
+ v->timer.data = (void *)TIMER_STARTED;
+ uv_timer_start(&v->timer, timer_run_cb, timeout_ms, 0);
+ ev = grpc_completion_queue_next(v->cq, gpr_inf_past(GPR_CLOCK_MONOTONIC),
+ NULL);
+ // Stop the loop if the timer goes off or we get a non-timeout event
+ while (((timer_state)v->timer.data != TIMER_TRIGGERED) &&
+ ev.type == GRPC_QUEUE_TIMEOUT) {
+ uv_run(uv_default_loop(), UV_RUN_ONCE);
+ ev = grpc_completion_queue_next(v->cq, gpr_inf_past(GPR_CLOCK_MONOTONIC),
+ NULL);
+ }
+ return ev;
+}
+
+#endif /* GRPC_UV */
diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c
index cb07ca535b..f427202a7b 100644
--- a/test/core/end2end/dualstack_socket_test.c
+++ b/test/core/end2end/dualstack_socket_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include <string.h>
#include <grpc/grpc.h>
@@ -353,3 +358,9 @@ int main(int argc, char **argv) {
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/end2end/end2end_nosec_tests.c b/test/core/end2end/end2end_nosec_tests.c
index a630262197..caaa97c215 100644
--- a/test/core/end2end/end2end_nosec_tests.c
+++ b/test/core/end2end/end2end_nosec_tests.c
@@ -111,6 +111,8 @@ extern void request_with_flags(grpc_end2end_test_config config);
extern void request_with_flags_pre_init(void);
extern void request_with_payload(grpc_end2end_test_config config);
extern void request_with_payload_pre_init(void);
+extern void resource_quota_server(grpc_end2end_test_config config);
+extern void resource_quota_server_pre_init(void);
extern void server_finishes_request(grpc_end2end_test_config config);
extern void server_finishes_request_pre_init(void);
extern void shutdown_finishes_calls(grpc_end2end_test_config config);
@@ -167,6 +169,7 @@ void grpc_end2end_tests_pre_init(void) {
registered_call_pre_init();
request_with_flags_pre_init();
request_with_payload_pre_init();
+ resource_quota_server_pre_init();
server_finishes_request_pre_init();
shutdown_finishes_calls_pre_init();
shutdown_finishes_tags_pre_init();
@@ -219,6 +222,7 @@ void grpc_end2end_tests(int argc, char **argv,
registered_call(config);
request_with_flags(config);
request_with_payload(config);
+ resource_quota_server(config);
server_finishes_request(config);
shutdown_finishes_calls(config);
shutdown_finishes_tags(config);
@@ -368,6 +372,10 @@ void grpc_end2end_tests(int argc, char **argv,
request_with_payload(config);
continue;
}
+ if (0 == strcmp("resource_quota_server", argv[i])) {
+ resource_quota_server(config);
+ continue;
+ }
if (0 == strcmp("server_finishes_request", argv[i])) {
server_finishes_request(config);
continue;
diff --git a/test/core/end2end/end2end_tests.c b/test/core/end2end/end2end_tests.c
index 925872a71f..6d17e686e6 100644
--- a/test/core/end2end/end2end_tests.c
+++ b/test/core/end2end/end2end_tests.c
@@ -113,6 +113,8 @@ extern void request_with_flags(grpc_end2end_test_config config);
extern void request_with_flags_pre_init(void);
extern void request_with_payload(grpc_end2end_test_config config);
extern void request_with_payload_pre_init(void);
+extern void resource_quota_server(grpc_end2end_test_config config);
+extern void resource_quota_server_pre_init(void);
extern void server_finishes_request(grpc_end2end_test_config config);
extern void server_finishes_request_pre_init(void);
extern void shutdown_finishes_calls(grpc_end2end_test_config config);
@@ -170,6 +172,7 @@ void grpc_end2end_tests_pre_init(void) {
registered_call_pre_init();
request_with_flags_pre_init();
request_with_payload_pre_init();
+ resource_quota_server_pre_init();
server_finishes_request_pre_init();
shutdown_finishes_calls_pre_init();
shutdown_finishes_tags_pre_init();
@@ -223,6 +226,7 @@ void grpc_end2end_tests(int argc, char **argv,
registered_call(config);
request_with_flags(config);
request_with_payload(config);
+ resource_quota_server(config);
server_finishes_request(config);
shutdown_finishes_calls(config);
shutdown_finishes_tags(config);
@@ -376,6 +380,10 @@ void grpc_end2end_tests(int argc, char **argv,
request_with_payload(config);
continue;
}
+ if (0 == strcmp("resource_quota_server", argv[i])) {
+ resource_quota_server(config);
+ continue;
+ }
if (0 == strcmp("server_finishes_request", argv[i])) {
server_finishes_request(config);
continue;
diff --git a/test/core/end2end/fake_resolver.c b/test/core/end2end/fake_resolver.c
index 32dc9e2711..a2343cb709 100644
--- a/test/core/end2end/fake_resolver.c
+++ b/test/core/end2end/fake_resolver.c
@@ -42,13 +42,14 @@
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h>
-#include "src/core/ext/client_config/method_config.h"
-#include "src/core/ext/client_config/parse_address.h"
-#include "src/core/ext/client_config/resolver_registry.h"
+#include "src/core/ext/client_channel/lb_policy_factory.h"
+#include "src/core/ext/client_channel/parse_address.h"
+#include "src/core/ext/client_channel/resolver_registry.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/unix_sockets_posix.h"
#include "src/core/lib/support/string.h"
+#include "src/core/lib/transport/method_config.h"
//
// fake_resolver
@@ -59,7 +60,7 @@ typedef struct {
grpc_resolver base;
// passed-in parameters
- char* target_name; // the path component of the uri passed in
+ grpc_channel_args* channel_args;
grpc_lb_addresses* addresses;
char* lb_policy_name;
grpc_method_config_table* method_config_table;
@@ -71,14 +72,14 @@ typedef struct {
// pending next completion, or NULL
grpc_closure* next_completion;
// target result address for next completion
- grpc_resolver_result** target_result;
+ grpc_channel_args** target_result;
} fake_resolver;
static void fake_resolver_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) {
fake_resolver* r = (fake_resolver*)gr;
gpr_mu_destroy(&r->mu);
- gpr_free(r->target_name);
- grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */);
+ grpc_channel_args_destroy(r->channel_args);
+ grpc_lb_addresses_destroy(r->addresses);
gpr_free(r->lb_policy_name);
grpc_method_config_table_unref(r->method_config_table);
gpr_free(r);
@@ -100,16 +101,21 @@ static void fake_resolver_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx,
fake_resolver* r) {
if (r->next_completion != NULL && !r->published) {
r->published = true;
- grpc_channel_args* lb_policy_args = NULL;
+ grpc_arg new_args[3];
+ size_t num_args = 0;
+ new_args[num_args++] = grpc_lb_addresses_create_channel_arg(r->addresses);
if (r->method_config_table != NULL) {
- const grpc_arg arg =
+ new_args[num_args++] =
grpc_method_config_table_create_channel_arg(r->method_config_table);
- lb_policy_args = grpc_channel_args_copy_and_add(NULL /* src */, &arg, 1);
}
- *r->target_result = grpc_resolver_result_create(
- r->target_name,
- grpc_lb_addresses_copy(r->addresses, NULL /* user_data_copy */),
- r->lb_policy_name, lb_policy_args);
+ if (r->lb_policy_name != NULL) {
+ new_args[num_args].type = GRPC_ARG_STRING;
+ new_args[num_args].key = GRPC_ARG_LB_POLICY_NAME;
+ new_args[num_args].value.string = r->lb_policy_name;
+ ++num_args;
+ }
+ *r->target_result =
+ grpc_channel_args_copy_and_add(r->channel_args, new_args, num_args);
grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL);
r->next_completion = NULL;
}
@@ -125,7 +131,7 @@ static void fake_resolver_channel_saw_error(grpc_exec_ctx* exec_ctx,
}
static void fake_resolver_next(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver,
- grpc_resolver_result** target_result,
+ grpc_channel_args** target_result,
grpc_closure* on_complete) {
fake_resolver* r = (fake_resolver*)resolver;
gpr_mu_lock(&r->mu);
@@ -168,16 +174,14 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory,
gpr_slice_buffer path_parts;
gpr_slice_buffer_init(&path_parts);
gpr_slice_split(path_slice, ",", &path_parts);
- grpc_lb_addresses* addresses = grpc_lb_addresses_create(path_parts.count);
+ grpc_lb_addresses* addresses =
+ grpc_lb_addresses_create(path_parts.count, NULL /* user_data_vtable */);
bool errors_found = false;
for (size_t i = 0; i < addresses->num_addresses; i++) {
grpc_uri ith_uri = *args->uri;
char* part_str = gpr_dump_slice(path_parts.slices[i], GPR_DUMP_ASCII);
ith_uri.path = part_str;
- if (!parse_ipv4(
- &ith_uri,
- (struct sockaddr_storage*)(&addresses->addresses[i].address.addr),
- &addresses->addresses[i].address.len)) {
+ if (!parse_ipv4(&ith_uri, &addresses->addresses[i].address)) {
errors_found = true;
}
gpr_free(part_str);
@@ -187,7 +191,7 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory,
gpr_slice_buffer_destroy(&path_parts);
gpr_slice_unref(path_slice);
if (errors_found) {
- grpc_lb_addresses_destroy(addresses, NULL /* user_data_destroy */);
+ grpc_lb_addresses_destroy(addresses);
return NULL;
}
// Construct method config table.
@@ -232,7 +236,12 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory,
// Instantiate resolver.
fake_resolver* r = gpr_malloc(sizeof(fake_resolver));
memset(r, 0, sizeof(*r));
- r->target_name = gpr_strdup(args->uri->path);
+ grpc_arg server_name_arg;
+ server_name_arg.type = GRPC_ARG_STRING;
+ server_name_arg.key = GRPC_ARG_SERVER_NAME;
+ server_name_arg.value.string = args->uri->path;
+ r->channel_args =
+ grpc_channel_args_copy_and_add(args->args, &server_name_arg, 1);
r->addresses = addresses;
r->lb_policy_name =
gpr_strdup(grpc_uri_get_query_arg(args->uri, "lb_policy"));
diff --git a/test/core/end2end/fixtures/h2_census.c b/test/core/end2end/fixtures/h2_census.c
index 36c2d24329..c2e1acf57f 100644
--- a/test/core/end2end/fixtures/h2_census.c
+++ b/test/core/end2end/fixtures/h2_census.c
@@ -41,7 +41,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
diff --git a/test/core/end2end/fixtures/h2_compress.c b/test/core/end2end/fixtures/h2_compress.c
index 0e84588517..94a198f380 100644
--- a/test/core/end2end/fixtures/h2_compress.c
+++ b/test/core/end2end/fixtures/h2_compress.c
@@ -41,7 +41,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
diff --git a/test/core/end2end/fixtures/h2_fake_resolver.c b/test/core/end2end/fixtures/h2_fake_resolver.c
index 89debddb04..429f3c95f9 100644
--- a/test/core/end2end/fixtures/h2_fake_resolver.c
+++ b/test/core/end2end/fixtures/h2_fake_resolver.c
@@ -41,7 +41,7 @@
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/channel/http_server_filter.h"
diff --git a/test/core/end2end/fixtures/h2_fd.c b/test/core/end2end/fixtures/h2_fd.c
index 5a58fe34cd..2dfa54fb6b 100644
--- a/test/core/end2end/fixtures/h2_fd.c
+++ b/test/core/end2end/fixtures/h2_fd.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "test/core/end2end/end2end_tests.h"
#include <fcntl.h>
@@ -129,3 +134,9 @@ int main(int argc, char **argv) {
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/end2end/fixtures/h2_full+pipe.c b/test/core/end2end/fixtures/h2_full+pipe.c
index 359af1aaf8..e0026a7940 100644
--- a/test/core/end2end/fixtures/h2_full+pipe.c
+++ b/test/core/end2end/fixtures/h2_full+pipe.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test requires posix wakeup fds
+#ifdef GRPC_POSIX_WAKEUP_FD
+
#include "test/core/end2end/end2end_tests.h"
#include <string.h>
@@ -41,7 +46,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/channel/http_server_filter.h"
@@ -121,3 +126,9 @@ int main(int argc, char **argv) {
return 0;
}
+
+#else /* GRPC_POSIX_WAKEUP_FD */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_WAKEUP_FD */
diff --git a/test/core/end2end/fixtures/h2_full+trace.c b/test/core/end2end/fixtures/h2_full+trace.c
index ac997b05ab..eadc62d963 100644
--- a/test/core/end2end/fixtures/h2_full+trace.c
+++ b/test/core/end2end/fixtures/h2_full+trace.c
@@ -31,9 +31,14 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
#include "test/core/end2end/end2end_tests.h"
#include <string.h>
+#ifdef GRPC_POSIX_SOCKET
+#include <unistd.h>
+#endif
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
@@ -41,7 +46,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/channel/http_server_filter.h"
@@ -111,7 +116,7 @@ int main(int argc, char **argv) {
code paths in trace.c to be taken */
gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
-#ifdef GPR_POSIX_SOCKET
+#ifdef GRPC_POSIX_SOCKET
g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10.0 : 1.0;
#else
g_fixture_slowdown_factor = 10.0;
diff --git a/test/core/end2end/fixtures/h2_full.c b/test/core/end2end/fixtures/h2_full.c
index a72ab3aedd..182ce23a51 100644
--- a/test/core/end2end/fixtures/h2_full.c
+++ b/test/core/end2end/fixtures/h2_full.c
@@ -41,7 +41,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/channel/http_server_filter.h"
diff --git a/test/core/end2end/fixtures/h2_http_proxy.c b/test/core/end2end/fixtures/h2_http_proxy.c
index f616da9ed5..2acc06f549 100644
--- a/test/core/end2end/fixtures/h2_http_proxy.c
+++ b/test/core/end2end/fixtures/h2_http_proxy.c
@@ -42,7 +42,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/channel/http_server_filter.h"
diff --git a/test/core/end2end/fixtures/h2_load_reporting.c b/test/core/end2end/fixtures/h2_load_reporting.c
index fc4db27e3c..0957666a44 100644
--- a/test/core/end2end/fixtures/h2_load_reporting.c
+++ b/test/core/end2end/fixtures/h2_load_reporting.c
@@ -41,7 +41,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/load_reporting/load_reporting.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
diff --git a/test/core/end2end/fixtures/h2_proxy.c b/test/core/end2end/fixtures/h2_proxy.c
index ea1da2abc1..2671e0abde 100644
--- a/test/core/end2end/fixtures/h2_proxy.c
+++ b/test/core/end2end/fixtures/h2_proxy.c
@@ -41,7 +41,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/channel/http_server_filter.h"
diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.c b/test/core/end2end/fixtures/h2_sockpair+trace.c
index 1ca1185309..a358edf321 100644
--- a/test/core/end2end/fixtures/h2_sockpair+trace.c
+++ b/test/core/end2end/fixtures/h2_sockpair+trace.c
@@ -31,16 +31,21 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
#include "test/core/end2end/end2end_tests.h"
#include <string.h>
+#ifdef GRPC_POSIX_SOCKET
+#include <unistd.h>
+#endif
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/compress_filter.h"
#include "src/core/lib/channel/connected_channel.h"
@@ -91,7 +96,9 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
f.fixture_data = sfd;
f.cq = grpc_completion_queue_create(NULL);
- *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536);
+ grpc_resource_quota *resource_quota = grpc_resource_quota_create("fixture");
+ *sfd = grpc_iomgr_create_endpoint_pair("fixture", resource_quota, 65536);
+ grpc_resource_quota_unref(resource_quota);
return f;
}
@@ -148,7 +155,7 @@ int main(int argc, char **argv) {
/* force tracing on, with a value to force many
code paths in trace.c to be taken */
gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
-#ifdef GPR_POSIX_SOCKET
+#ifdef GRPC_POSIX_SOCKET
g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10.0 : 1.0;
#else
g_fixture_slowdown_factor = 10.0;
diff --git a/test/core/end2end/fixtures/h2_sockpair.c b/test/core/end2end/fixtures/h2_sockpair.c
index 265491b56d..8f7083af59 100644
--- a/test/core/end2end/fixtures/h2_sockpair.c
+++ b/test/core/end2end/fixtures/h2_sockpair.c
@@ -40,7 +40,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/compress_filter.h"
#include "src/core/lib/channel/connected_channel.h"
@@ -90,7 +90,9 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
f.fixture_data = sfd;
f.cq = grpc_completion_queue_create(NULL);
- *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536);
+ grpc_resource_quota *resource_quota = grpc_resource_quota_create("fixture");
+ *sfd = grpc_iomgr_create_endpoint_pair("fixture", resource_quota, 65536);
+ grpc_resource_quota_unref(resource_quota);
return f;
}
diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.c b/test/core/end2end/fixtures/h2_sockpair_1byte.c
index 647585d46c..b3d9924c12 100644
--- a/test/core/end2end/fixtures/h2_sockpair_1byte.c
+++ b/test/core/end2end/fixtures/h2_sockpair_1byte.c
@@ -40,7 +40,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/compress_filter.h"
#include "src/core/lib/channel/connected_channel.h"
@@ -90,7 +90,9 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
f.fixture_data = sfd;
f.cq = grpc_completion_queue_create(NULL);
- *sfd = grpc_iomgr_create_endpoint_pair("fixture", 1);
+ grpc_resource_quota *resource_quota = grpc_resource_quota_create("fixture");
+ *sfd = grpc_iomgr_create_endpoint_pair("fixture", resource_quota, 1);
+ grpc_resource_quota_unref(resource_quota);
return f;
}
diff --git a/test/core/end2end/fixtures/h2_uds.c b/test/core/end2end/fixtures/h2_uds.c
index e280bb8c29..888d6c0a10 100644
--- a/test/core/end2end/fixtures/h2_uds.c
+++ b/test/core/end2end/fixtures/h2_uds.c
@@ -44,7 +44,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/channel/http_server_filter.h"
diff --git a/test/core/end2end/fixtures/http_proxy.c b/test/core/end2end/fixtures/http_proxy.c
index 22533b9694..630f47ef0e 100644
--- a/test/core/end2end/fixtures/http_proxy.c
+++ b/test/core/end2end/fixtures/http_proxy.c
@@ -33,6 +33,8 @@
#include "test/core/end2end/fixtures/http_proxy.h"
+#include "src/core/lib/iomgr/sockaddr.h"
+
#include <string.h>
#include <grpc/support/alloc.h>
@@ -357,9 +359,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg,
const gpr_timespec deadline = gpr_time_add(
gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(10, GPR_TIMESPAN));
grpc_tcp_client_connect(exec_ctx, &conn->on_server_connect_done,
- &conn->server_endpoint, conn->pollset_set,
- (struct sockaddr*)&resolved_addresses->addrs[0].addr,
- resolved_addresses->addrs[0].len, deadline);
+ &conn->server_endpoint, conn->pollset_set, NULL,
+ &resolved_addresses->addrs[0], deadline);
grpc_resolved_addresses_destroy(resolved_addresses);
}
@@ -417,7 +418,8 @@ static void thread_main(void* arg) {
grpc_exec_ctx_finish(&exec_ctx);
}
-grpc_end2end_http_proxy* grpc_end2end_http_proxy_create() {
+grpc_end2end_http_proxy* grpc_end2end_http_proxy_create(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_end2end_http_proxy* proxy = gpr_malloc(sizeof(*proxy));
memset(proxy, 0, sizeof(*proxy));
// Construct proxy address.
@@ -426,23 +428,22 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create() {
gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name);
// Create TCP server.
proxy->channel_args = grpc_channel_args_copy(NULL);
- grpc_error* error =
- grpc_tcp_server_create(NULL, proxy->channel_args, &proxy->server);
+ grpc_error* error = grpc_tcp_server_create(
+ &exec_ctx, NULL, proxy->channel_args, &proxy->server);
GPR_ASSERT(error == GRPC_ERROR_NONE);
// Bind to port.
- struct sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- grpc_sockaddr_set_port((struct sockaddr*)&addr, proxy_port);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ addr->sin_family = AF_INET;
+ grpc_sockaddr_set_port(&resolved_addr, proxy_port);
int port;
- error = grpc_tcp_server_add_port(proxy->server, (struct sockaddr*)&addr,
- sizeof(addr), &port);
+ error = grpc_tcp_server_add_port(proxy->server, &resolved_addr, &port);
GPR_ASSERT(error == GRPC_ERROR_NONE);
GPR_ASSERT(port == proxy_port);
// Start server.
proxy->pollset = gpr_malloc(grpc_pollset_size());
grpc_pollset_init(proxy->pollset, &proxy->mu);
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_tcp_server_start(&exec_ctx, proxy->server, &proxy->pollset, 1, on_accept,
proxy);
grpc_exec_ctx_finish(&exec_ctx);
diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c
index 96ea82d95e..659f5cf5cb 100644
--- a/test/core/end2end/fuzzers/api_fuzzer.c
+++ b/test/core/end2end/fuzzers/api_fuzzer.c
@@ -173,6 +173,7 @@ static bool is_eof(input_stream *inp) { return inp->cur == inp->end; }
static gpr_timespec g_now;
static grpc_server *g_server;
static grpc_channel *g_channel;
+static grpc_resource_quota *g_resource_quota;
extern gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type);
@@ -231,8 +232,8 @@ void my_resolve_address(grpc_exec_ctx *exec_ctx, const char *addr,
// defined in tcp_client_posix.c
extern void (*grpc_tcp_client_connect_impl)(
grpc_exec_ctx *exec_ctx, grpc_closure *closure, grpc_endpoint **ep,
- grpc_pollset_set *interested_parties, const struct sockaddr *addr,
- size_t addr_len, gpr_timespec deadline);
+ grpc_pollset_set *interested_parties, const grpc_channel_args *channel_args,
+ const grpc_resolved_address *addr, gpr_timespec deadline);
static void sched_connect(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
grpc_endpoint **ep, gpr_timespec deadline);
@@ -252,7 +253,7 @@ static void do_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
} else if (g_server != NULL) {
grpc_endpoint *client;
grpc_endpoint *server;
- grpc_passthru_endpoint_create(&client, &server);
+ grpc_passthru_endpoint_create(&client, &server, g_resource_quota);
*fc->ep = client;
grpc_transport *transport =
@@ -289,7 +290,8 @@ static void sched_connect(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
static void my_tcp_client_connect(grpc_exec_ctx *exec_ctx,
grpc_closure *closure, grpc_endpoint **ep,
grpc_pollset_set *interested_parties,
- const struct sockaddr *addr, size_t addr_len,
+ const grpc_channel_args *channel_args,
+ const grpc_resolved_address *addr,
gpr_timespec deadline) {
sched_connect(exec_ctx, closure, ep, deadline);
}
@@ -520,6 +522,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
int pending_pings = 0;
g_active_call = new_call(NULL, ROOT);
+ g_resource_quota = grpc_resource_quota_create("api_fuzzer");
grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
@@ -939,6 +942,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
}
break;
}
+ // resize the buffer pool
+ case 21: {
+ grpc_resource_quota_resize(g_resource_quota, read_uint22(&inp));
+ break;
+ }
}
}
@@ -954,6 +962,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
.type == GRPC_QUEUE_SHUTDOWN);
grpc_completion_queue_destroy(cq);
+ grpc_resource_quota_unref(g_resource_quota);
+
grpc_shutdown();
return 0;
}
diff --git a/test/core/end2end/fuzzers/client_fuzzer.c b/test/core/end2end/fuzzers/client_fuzzer.c
index 00e650a30b..d104fe55e5 100644
--- a/test/core/end2end/fuzzers/client_fuzzer.c
+++ b/test/core/end2end/fuzzers/client_fuzzer.c
@@ -58,7 +58,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_init();
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_endpoint *mock_endpoint = grpc_mock_endpoint_create(discard_write);
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("client_fuzzer");
+ grpc_endpoint *mock_endpoint =
+ grpc_mock_endpoint_create(discard_write, resource_quota);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
grpc_transport *transport =
diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary
index 181bbe845e..12db0ff024 100644
--- a/test/core/end2end/fuzzers/hpack.dictionary
+++ b/test/core/end2end/fuzzers/hpack.dictionary
@@ -63,7 +63,7 @@
"\x08if-range"
"\x13if-unmodified-since"
"\x0Dlast-modified"
-"\x07lb-cost"
+"\x0Blb-cost-bin"
"\x08lb-token"
"\x04link"
"\x08location"
@@ -138,7 +138,7 @@
"\x00\x08if-range\x00"
"\x00\x13if-unmodified-since\x00"
"\x00\x0Dlast-modified\x00"
-"\x00\x07lb-cost\x00"
+"\x00\x0Blb-cost-bin\x00"
"\x00\x08lb-token\x00"
"\x00\x04link\x00"
"\x00\x08location\x00"
diff --git a/test/core/end2end/fuzzers/server_fuzzer.c b/test/core/end2end/fuzzers/server_fuzzer.c
index 79eaad70c5..ae4c8e658d 100644
--- a/test/core/end2end/fuzzers/server_fuzzer.c
+++ b/test/core/end2end/fuzzers/server_fuzzer.c
@@ -56,7 +56,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_init();
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_endpoint *mock_endpoint = grpc_mock_endpoint_create(discard_write);
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("server_fuzzer");
+ grpc_endpoint *mock_endpoint =
+ grpc_mock_endpoint_create(discard_write, resource_quota);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
grpc_mock_endpoint_put_read(
&exec_ctx, mock_endpoint,
gpr_slice_from_copied_buffer((const char *)data, size));
diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py
index d3d6f5e9ce..bdb3874c21 100755
--- a/test/core/end2end/gen_build_yaml.py
+++ b/test/core/end2end/gen_build_yaml.py
@@ -39,19 +39,20 @@ import hashlib
FixtureOptions = collections.namedtuple(
'FixtureOptions',
- 'fullstack includes_proxy dns_resolver secure platforms ci_mac tracing exclude_configs')
+ 'fullstack includes_proxy dns_resolver secure platforms ci_mac tracing exclude_configs exclude_iomgrs large_writes')
default_unsecure_fixture_options = FixtureOptions(
- True, False, True, False, ['windows', 'linux', 'mac', 'posix'], True, False, [])
+ True, False, True, False, ['windows', 'linux', 'mac', 'posix'], True, False, [], [], True)
socketpair_unsecure_fixture_options = default_unsecure_fixture_options._replace(fullstack=False, dns_resolver=False)
default_secure_fixture_options = default_unsecure_fixture_options._replace(secure=True)
-uds_fixture_options = default_unsecure_fixture_options._replace(dns_resolver=False, platforms=['linux', 'mac', 'posix'])
+uds_fixture_options = default_unsecure_fixture_options._replace(dns_resolver=False, platforms=['linux', 'mac', 'posix'], exclude_iomgrs=['uv'])
fd_unsecure_fixture_options = default_unsecure_fixture_options._replace(
- dns_resolver=False, fullstack=False, platforms=['linux', 'mac', 'posix'])
+ dns_resolver=False, fullstack=False, platforms=['linux', 'mac', 'posix'], exclude_iomgrs=['uv'])
# maps fixture name to whether it requires the security library
END2END_FIXTURES = {
'h2_compress': default_unsecure_fixture_options,
+
'h2_census': default_unsecure_fixture_options,
'h2_load_reporting': default_unsecure_fixture_options,
'h2_fakesec': default_secure_fixture_options._replace(ci_mac=False),
@@ -59,28 +60,32 @@ END2END_FIXTURES = {
'h2_fd': fd_unsecure_fixture_options,
'h2_full': default_unsecure_fixture_options,
'h2_full+pipe': default_unsecure_fixture_options._replace(
- platforms=['linux']),
+ platforms=['linux'], exclude_iomgrs=['uv']),
'h2_full+trace': default_unsecure_fixture_options._replace(tracing=True),
- 'h2_http_proxy': default_unsecure_fixture_options._replace(ci_mac=False),
- 'h2_oauth2': default_secure_fixture_options._replace(ci_mac=False),
- 'h2_proxy': default_unsecure_fixture_options._replace(includes_proxy=True,
- ci_mac=False),
+ 'h2_http_proxy': default_unsecure_fixture_options._replace(
+ ci_mac=False, exclude_iomgrs=['uv']),
+ 'h2_oauth2': default_secure_fixture_options._replace(
+ ci_mac=False, exclude_iomgrs=['uv']),
+ 'h2_proxy': default_unsecure_fixture_options._replace(
+ includes_proxy=True, ci_mac=False, exclude_iomgrs=['uv']),
'h2_sockpair_1byte': socketpair_unsecure_fixture_options._replace(
- ci_mac=False, exclude_configs=['msan']),
- 'h2_sockpair': socketpair_unsecure_fixture_options._replace(ci_mac=False),
+ ci_mac=False, exclude_configs=['msan'], large_writes=False,
+ exclude_iomgrs=['uv']),
+ 'h2_sockpair': socketpair_unsecure_fixture_options._replace(
+ ci_mac=False, exclude_iomgrs=['uv']),
'h2_sockpair+trace': socketpair_unsecure_fixture_options._replace(
- ci_mac=False, tracing=True),
+ ci_mac=False, tracing=True, large_writes=False, exclude_iomgrs=['uv']),
'h2_ssl': default_secure_fixture_options,
'h2_ssl_cert': default_secure_fixture_options,
- 'h2_ssl_proxy': default_secure_fixture_options._replace(includes_proxy=True,
- ci_mac=False),
+ 'h2_ssl_proxy': default_secure_fixture_options._replace(
+ includes_proxy=True, ci_mac=False, exclude_iomgrs=['uv']),
'h2_uds': uds_fixture_options,
}
TestOptions = collections.namedtuple(
'TestOptions',
- 'needs_fullstack needs_dns proxyable secure traceable cpu_cost')
-default_test_options = TestOptions(False, False, True, False, True, 1.0)
+ 'needs_fullstack needs_dns proxyable secure traceable cpu_cost exclude_iomgrs large_writes flaky')
+default_test_options = TestOptions(False, False, True, False, True, 1.0, [], False, False)
connectivity_test_options = default_test_options._replace(needs_fullstack=True)
LOWCPU = 0.1
@@ -89,6 +94,8 @@ LOWCPU = 0.1
END2END_TESTS = {
'bad_hostname': default_test_options,
'binary_metadata': default_test_options,
+ 'resource_quota_server': default_test_options._replace(large_writes=True,
+ proxyable=False),
'call_creds': default_test_options._replace(secure=True),
'cancel_after_accept': default_test_options._replace(cpu_cost=LOWCPU),
'cancel_after_client_done': default_test_options,
@@ -97,11 +104,11 @@ END2END_TESTS = {
'cancel_in_a_vacuum': default_test_options._replace(cpu_cost=LOWCPU),
'cancel_with_status': default_test_options._replace(cpu_cost=LOWCPU),
'compressed_payload': default_test_options._replace(proxyable=False),
- 'connectivity': connectivity_test_options._replace(proxyable=False,
- cpu_cost=LOWCPU),
+ 'connectivity': connectivity_test_options._replace(
+ proxyable=False, cpu_cost=LOWCPU, exclude_iomgrs=['uv']),
'default_host': default_test_options._replace(needs_fullstack=True,
needs_dns=True),
- 'disappearing_server': connectivity_test_options,
+ 'disappearing_server': connectivity_test_options._replace(flaky=True),
'empty_batch': default_test_options,
'filter_causes_close': default_test_options,
'filter_call_init_fails': default_test_options,
@@ -151,6 +158,9 @@ def compatible(f, t):
if not END2END_TESTS[t].traceable:
if END2END_FIXTURES[f].tracing:
return False
+ if END2END_TESTS[t].large_writes:
+ if not END2END_FIXTURES[f].large_writes:
+ return False
return True
@@ -247,11 +257,13 @@ def main():
'name': '%s_test' % f,
'args': [t],
'exclude_configs': END2END_FIXTURES[f].exclude_configs,
+ 'exclude_iomgrs': list(set(END2END_FIXTURES[f].exclude_iomgrs) |
+ set(END2END_TESTS[t].exclude_iomgrs)),
'platforms': END2END_FIXTURES[f].platforms,
'ci_platforms': (END2END_FIXTURES[f].platforms
if END2END_FIXTURES[f].ci_mac else without(
END2END_FIXTURES[f].platforms, 'mac')),
- 'flaky': False,
+ 'flaky': END2END_TESTS[t].flaky,
'language': 'c',
'cpu_cost': END2END_TESTS[t].cpu_cost,
}
@@ -262,11 +274,13 @@ def main():
'name': '%s_nosec_test' % f,
'args': [t],
'exclude_configs': END2END_FIXTURES[f].exclude_configs,
+ 'exclude_iomgrs': list(set(END2END_FIXTURES[f].exclude_iomgrs) |
+ set(END2END_TESTS[t].exclude_iomgrs)),
'platforms': END2END_FIXTURES[f].platforms,
'ci_platforms': (END2END_FIXTURES[f].platforms
if END2END_FIXTURES[f].ci_mac else without(
END2END_FIXTURES[f].platforms, 'mac')),
- 'flaky': False,
+ 'flaky': END2END_TESTS[t].flaky,
'language': 'c',
'cpu_cost': END2END_TESTS[t].cpu_cost,
}
diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c
index e698987a0a..449a581d23 100644
--- a/test/core/end2end/tests/max_message_length.c
+++ b/test/core/end2end/tests/max_message_length.c
@@ -402,7 +402,6 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config,
GPR_ASSERT(0 == strcmp(call_details.method, "/service/method"));
GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr:1234"));
- GPR_ASSERT(was_cancelled == 0);
GPR_ASSERT(status == GRPC_STATUS_INVALID_ARGUMENT);
GPR_ASSERT(strcmp(details,
diff --git a/test/core/end2end/tests/network_status_change.c b/test/core/end2end/tests/network_status_change.c
index 8d6b8f8784..fa711bb0b6 100644
--- a/test/core/end2end/tests/network_status_change.c
+++ b/test/core/end2end/tests/network_status_change.c
@@ -213,7 +213,6 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) {
GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE);
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr"));
- GPR_ASSERT(was_cancelled == 0);
gpr_free(details);
grpc_metadata_array_destroy(&initial_metadata_recv);
diff --git a/test/core/end2end/tests/resource_quota_server.c b/test/core/end2end/tests/resource_quota_server.c
new file mode 100644
index 0000000000..76374d16a5
--- /dev/null
+++ b/test/core/end2end/tests/resource_quota_server.c
@@ -0,0 +1,359 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+static void *tag(intptr_t t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_server(&f, server_args);
+ config.init_client(&f, client_args, NULL);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event ev;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time(), NULL);
+ } while (ev.type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000));
+ GPR_ASSERT(grpc_completion_queue_pluck(
+ f->cq, tag(1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL)
+ .type == GRPC_OP_COMPLETE);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->cq);
+ drain_cq(f->cq);
+ grpc_completion_queue_destroy(f->cq);
+}
+
+/* Creates and returns a gpr_slice containing random alphanumeric characters. */
+static gpr_slice generate_random_slice() {
+ size_t i;
+ static const char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890";
+ char output[1024 * 1024];
+ for (i = 0; i < GPR_ARRAY_SIZE(output) - 1; ++i) {
+ output[i] = chars[rand() % (int)(sizeof(chars) - 1)];
+ }
+ output[GPR_ARRAY_SIZE(output) - 1] = '\0';
+ return gpr_slice_from_copied_string(output);
+}
+
+void resource_quota_server(grpc_end2end_test_config config) {
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("test_server");
+ grpc_resource_quota_resize(resource_quota, 5 * 1024 * 1024);
+
+#define NUM_CALLS 100
+#define CLIENT_BASE_TAG 1000
+#define SERVER_START_BASE_TAG 2000
+#define SERVER_RECV_BASE_TAG 3000
+#define SERVER_END_BASE_TAG 4000
+
+ grpc_arg arg;
+ arg.key = GRPC_ARG_RESOURCE_QUOTA;
+ arg.type = GRPC_ARG_POINTER;
+ arg.value.pointer.p = resource_quota;
+ arg.value.pointer.vtable = grpc_resource_quota_arg_vtable();
+ grpc_channel_args args = {1, &arg};
+
+ grpc_end2end_test_fixture f =
+ begin_test(config, "resource_quota_server", NULL, &args);
+
+ /* Create large request and response bodies. These are big enough to require
+ * multiple round trips to deliver to the peer, and their exact contents of
+ * will be verified on completion. */
+ gpr_slice request_payload_slice = generate_random_slice();
+
+ grpc_call *client_calls[NUM_CALLS];
+ grpc_call *server_calls[NUM_CALLS];
+ grpc_metadata_array initial_metadata_recv[NUM_CALLS];
+ grpc_metadata_array trailing_metadata_recv[NUM_CALLS];
+ grpc_metadata_array request_metadata_recv[NUM_CALLS];
+ grpc_call_details call_details[NUM_CALLS];
+ grpc_status_code status[NUM_CALLS];
+ char *details[NUM_CALLS];
+ size_t details_capacity[NUM_CALLS];
+ grpc_byte_buffer *request_payload_recv[NUM_CALLS];
+ int was_cancelled[NUM_CALLS];
+ grpc_call_error error;
+ int pending_client_calls = 0;
+ int pending_server_start_calls = 0;
+ int pending_server_recv_calls = 0;
+ int pending_server_end_calls = 0;
+ int cancelled_calls_on_client = 0;
+ int cancelled_calls_on_server = 0;
+
+ grpc_byte_buffer *request_payload =
+ grpc_raw_byte_buffer_create(&request_payload_slice, 1);
+
+ grpc_op ops[6];
+ grpc_op *op;
+
+ for (int i = 0; i < NUM_CALLS; i++) {
+ grpc_metadata_array_init(&initial_metadata_recv[i]);
+ grpc_metadata_array_init(&trailing_metadata_recv[i]);
+ grpc_metadata_array_init(&request_metadata_recv[i]);
+ grpc_call_details_init(&call_details[i]);
+ details[i] = NULL;
+ details_capacity[i] = 0;
+ request_payload_recv[i] = NULL;
+ was_cancelled[i] = 0;
+ }
+
+ for (int i = 0; i < NUM_CALLS; i++) {
+ error = grpc_server_request_call(
+ f.server, &server_calls[i], &call_details[i], &request_metadata_recv[i],
+ f.cq, f.cq, tag(SERVER_START_BASE_TAG + i));
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ pending_server_start_calls++;
+ }
+
+ for (int i = 0; i < NUM_CALLS; i++) {
+ client_calls[i] = grpc_channel_create_call(
+ f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo",
+ "foo.test.google.fr", n_seconds_time(60), NULL);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv[i];
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata =
+ &trailing_metadata_recv[i];
+ op->data.recv_status_on_client.status = &status[i];
+ op->data.recv_status_on_client.status_details = &details[i];
+ op->data.recv_status_on_client.status_details_capacity =
+ &details_capacity[i];
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ error = grpc_call_start_batch(client_calls[i], ops, (size_t)(op - ops),
+ tag(CLIENT_BASE_TAG + i), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ pending_client_calls++;
+ }
+
+ while (pending_client_calls + pending_server_recv_calls +
+ pending_server_end_calls >
+ 0) {
+ grpc_event ev = grpc_completion_queue_next(f.cq, n_seconds_time(10), NULL);
+ GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
+
+ int ev_tag = (int)(intptr_t)ev.tag;
+ if (ev_tag < CLIENT_BASE_TAG) {
+ abort(); /* illegal tag */
+ } else if (ev_tag < SERVER_START_BASE_TAG) {
+ /* client call finished */
+ int call_id = ev_tag - CLIENT_BASE_TAG;
+ GPR_ASSERT(call_id >= 0);
+ GPR_ASSERT(call_id < NUM_CALLS);
+ switch (status[call_id]) {
+ case GRPC_STATUS_RESOURCE_EXHAUSTED:
+ cancelled_calls_on_client++;
+ break;
+ case GRPC_STATUS_OK:
+ break;
+ default:
+ gpr_log(GPR_ERROR, "Unexpected status code: %d", status[call_id]);
+ abort();
+ }
+ GPR_ASSERT(pending_client_calls > 0);
+
+ grpc_metadata_array_destroy(&initial_metadata_recv[call_id]);
+ grpc_metadata_array_destroy(&trailing_metadata_recv[call_id]);
+ grpc_call_destroy(client_calls[call_id]);
+ gpr_free(details[call_id]);
+
+ pending_client_calls--;
+ } else if (ev_tag < SERVER_RECV_BASE_TAG) {
+ /* new incoming call to the server */
+ int call_id = ev_tag - SERVER_START_BASE_TAG;
+ GPR_ASSERT(call_id >= 0);
+ GPR_ASSERT(call_id < NUM_CALLS);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv[call_id];
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ error =
+ grpc_call_start_batch(server_calls[call_id], ops, (size_t)(op - ops),
+ tag(SERVER_RECV_BASE_TAG + call_id), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ GPR_ASSERT(pending_server_start_calls > 0);
+ pending_server_start_calls--;
+ pending_server_recv_calls++;
+
+ grpc_call_details_destroy(&call_details[call_id]);
+ grpc_metadata_array_destroy(&request_metadata_recv[call_id]);
+ } else if (ev_tag < SERVER_END_BASE_TAG) {
+ /* finished read on the server */
+ int call_id = ev_tag - SERVER_RECV_BASE_TAG;
+ GPR_ASSERT(call_id >= 0);
+ GPR_ASSERT(call_id < NUM_CALLS);
+
+ if (ev.success) {
+ if (request_payload_recv[call_id] != NULL) {
+ grpc_byte_buffer_destroy(request_payload_recv[call_id]);
+ request_payload_recv[call_id] = NULL;
+ }
+ } else {
+ GPR_ASSERT(request_payload_recv[call_id] == NULL);
+ }
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled[call_id];
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_OK;
+ op->data.send_status_from_server.status_details = "xyz";
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ error =
+ grpc_call_start_batch(server_calls[call_id], ops, (size_t)(op - ops),
+ tag(SERVER_END_BASE_TAG + call_id), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ GPR_ASSERT(pending_server_recv_calls > 0);
+ pending_server_recv_calls--;
+ pending_server_end_calls++;
+ } else {
+ int call_id = ev_tag - SERVER_END_BASE_TAG;
+ GPR_ASSERT(call_id >= 0);
+ GPR_ASSERT(call_id < NUM_CALLS);
+
+ if (was_cancelled[call_id]) {
+ cancelled_calls_on_server++;
+ }
+ GPR_ASSERT(pending_server_end_calls > 0);
+ pending_server_end_calls--;
+
+ grpc_call_destroy(server_calls[call_id]);
+ }
+ }
+
+ gpr_log(
+ GPR_INFO,
+ "Done. %d total calls: %d cancelled at server, %d cancelled at client.",
+ NUM_CALLS, cancelled_calls_on_server, cancelled_calls_on_client);
+
+ /* The call may be cancelled after the server has sent its status but before
+ * the client has received it. This means that we should see strictly more
+ * failures on the client than on the server. */
+ GPR_ASSERT(cancelled_calls_on_client >= cancelled_calls_on_server);
+ /* However, we shouldn't see radically more... 0.9 is a guessed bound on what
+ * we'd want that ratio to be... to at least trigger some investigation should
+ * that ratio become much higher. */
+ GPR_ASSERT(cancelled_calls_on_server >= 0.9 * cancelled_calls_on_client);
+
+ grpc_byte_buffer_destroy(request_payload);
+ gpr_slice_unref(request_payload_slice);
+ grpc_resource_quota_unref(resource_quota);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void resource_quota_server_pre_init(void) {}
diff --git a/test/core/handshake/client_ssl.c b/test/core/handshake/client_ssl.c
new file mode 100644
index 0000000000..ee90f0b0bc
--- /dev/null
+++ b/test/core/handshake/client_ssl.c
@@ -0,0 +1,311 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <arpa/inet.h>
+#include <openssl/err.h>
+#include <openssl/ssl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include <grpc/grpc.h>
+#include <grpc/grpc_security.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+#include <grpc/support/thd.h>
+#include "src/core/lib/iomgr/load_file.h"
+#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
+
+#define SSL_CERT_PATH "src/core/lib/tsi/test_creds/server1.pem"
+#define SSL_KEY_PATH "src/core/lib/tsi/test_creds/server1.key"
+#define SSL_CA_PATH "src/core/lib/tsi/test_creds/ca.pem"
+
+// Arguments for TLS server thread.
+typedef struct {
+ int socket;
+ char *alpn_preferred;
+} server_args;
+
+// From https://wiki.openssl.org/index.php/Simple_TLS_Server.
+static int create_socket(int port) {
+ int s;
+ struct sockaddr_in addr;
+
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons((uint16_t)port);
+ addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0) {
+ perror("Unable to create socket");
+ return -1;
+ }
+
+ if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ perror("Unable to bind");
+ gpr_log(GPR_ERROR, "Unable to bind to %d", port);
+ close(s);
+ return -1;
+ }
+
+ if (listen(s, 1) < 0) {
+ perror("Unable to listen");
+ close(s);
+ return -1;
+ }
+
+ return s;
+}
+
+// Server callback during ALPN negotiation. See man page for
+// SSL_CTX_set_alpn_select_cb.
+static int alpn_select_cb(SSL *ssl, const uint8_t **out, uint8_t *out_len,
+ const uint8_t *in, unsigned in_len, void *arg) {
+ const uint8_t *alpn_preferred = (const uint8_t *)arg;
+
+ *out = alpn_preferred;
+ *out_len = (uint8_t)strlen((char *)alpn_preferred);
+
+ // Validate that the ALPN list includes "h2" and "grpc-exp", that "grpc-exp"
+ // precedes "h2".
+ bool grpc_exp_seen = false;
+ bool h2_seen = false;
+ const char *inp = (const char *)in;
+ for (int i = 0; i < (int)in_len; ++i) {
+ const size_t length = (size_t)*inp++;
+ if (length == strlen("grpc-exp") && strncmp(inp, "grpc-exp", length) == 0) {
+ grpc_exp_seen = true;
+ GPR_ASSERT(!h2_seen);
+ }
+ if (length == strlen("h2") && strncmp(inp, "h2", length) == 0) {
+ h2_seen = true;
+ GPR_ASSERT(grpc_exp_seen);
+ }
+ inp += length;
+ }
+
+ GPR_ASSERT(grpc_exp_seen);
+ GPR_ASSERT(h2_seen);
+
+ return SSL_TLSEXT_ERR_OK;
+}
+
+// Minimal TLS server. This is largely based on the example at
+// https://wiki.openssl.org/index.php/Simple_TLS_Server and the gRPC core
+// internals in src/core/lib/tsi/ssl_transport_security.c.
+static void server_thread(void *arg) {
+ const server_args *args = (server_args *)arg;
+
+ SSL_load_error_strings();
+ OpenSSL_add_ssl_algorithms();
+
+ const SSL_METHOD *method = TLSv1_2_server_method();
+ SSL_CTX *ctx = SSL_CTX_new(method);
+ if (!ctx) {
+ perror("Unable to create SSL context");
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+
+ // Load key pair.
+ if (SSL_CTX_use_certificate_file(ctx, SSL_CERT_PATH, SSL_FILETYPE_PEM) < 0) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (SSL_CTX_use_PrivateKey_file(ctx, SSL_KEY_PATH, SSL_FILETYPE_PEM) < 0) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+
+ // Set the cipher list to match the one expressed in
+ // src/core/lib/tsi/ssl_transport_security.c.
+ const char *cipher_list =
+ "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-"
+ "SHA384:ECDHE-RSA-AES256-GCM-SHA384";
+ if (!SSL_CTX_set_cipher_list(ctx, cipher_list)) {
+ ERR_print_errors_fp(stderr);
+ gpr_log(GPR_ERROR, "Couldn't set server cipher list.");
+ abort();
+ }
+
+ // Register the ALPN selection callback.
+ SSL_CTX_set_alpn_select_cb(ctx, alpn_select_cb, args->alpn_preferred);
+
+ // bind/listen/accept at TCP layer.
+ const int sock = args->socket;
+ gpr_log(GPR_INFO, "Server listening");
+ struct sockaddr_in addr;
+ socklen_t len = sizeof(addr);
+ const int client = accept(sock, (struct sockaddr *)&addr, &len);
+ if (client < 0) {
+ perror("Unable to accept");
+ abort();
+ }
+
+ // Establish a SSL* and accept at SSL layer.
+ SSL *ssl = SSL_new(ctx);
+ GPR_ASSERT(ssl);
+ SSL_set_fd(ssl, client);
+ if (SSL_accept(ssl) <= 0) {
+ ERR_print_errors_fp(stderr);
+ gpr_log(GPR_ERROR, "Handshake failed.");
+ } else {
+ gpr_log(GPR_INFO, "Handshake successful.");
+ }
+
+ // Wait until the client drops its connection.
+ char buf;
+ while (SSL_read(ssl, &buf, sizeof(buf)) > 0)
+ ;
+
+ SSL_free(ssl);
+ close(client);
+ close(sock);
+ SSL_CTX_free(ctx);
+ EVP_cleanup();
+}
+
+// This test launches a minimal TLS server on a separate thread and then
+// establishes a TLS handshake via the core library to the server. The TLS
+// server validates ALPN aspects of the handshake and supplies the protocol
+// specified in the server_alpn_preferred argument to the client.
+static bool client_ssl_test(char *server_alpn_preferred) {
+ bool success = true;
+
+ grpc_init();
+
+ // Find a port we can bind to. Retries added to handle flakes in port server
+ // and port picking.
+ int port = -1;
+ int server_socket = -1;
+ int socket_retries = 10;
+ while (server_socket == -1 && socket_retries-- > 0) {
+ port = grpc_pick_unused_port_or_die();
+ server_socket = create_socket(port);
+ if (server_socket == -1) {
+ sleep(1);
+ }
+ }
+ GPR_ASSERT(server_socket > 0);
+
+ // Launch the TLS server thread.
+ gpr_thd_options thdopt = gpr_thd_options_default();
+ gpr_thd_id thdid;
+ gpr_thd_options_set_joinable(&thdopt);
+ server_args args = {.socket = server_socket,
+ .alpn_preferred = server_alpn_preferred};
+ GPR_ASSERT(gpr_thd_new(&thdid, server_thread, &args, &thdopt));
+
+ // Load key pair and establish client SSL credentials.
+ grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
+ gpr_slice ca_slice, cert_slice, key_slice;
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
+ grpc_load_file(SSL_CA_PATH, 1, &ca_slice)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
+ grpc_load_file(SSL_CERT_PATH, 1, &cert_slice)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
+ grpc_load_file(SSL_KEY_PATH, 1, &key_slice)));
+ const char *ca_cert = (const char *)GPR_SLICE_START_PTR(ca_slice);
+ pem_key_cert_pair.private_key = (const char *)GPR_SLICE_START_PTR(key_slice);
+ pem_key_cert_pair.cert_chain = (const char *)GPR_SLICE_START_PTR(cert_slice);
+ grpc_channel_credentials *ssl_creds =
+ grpc_ssl_credentials_create(ca_cert, &pem_key_cert_pair, NULL);
+
+ // Establish a channel pointing at the TLS server. Since the gRPC runtime is
+ // lazy, this won't necessarily establish a connection yet.
+ char *target;
+ gpr_asprintf(&target, "127.0.0.1:%d", port);
+ grpc_arg ssl_name_override = {GRPC_ARG_STRING,
+ GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
+ {"foo.test.google.fr"}};
+ grpc_channel_args grpc_args;
+ grpc_args.num_args = 1;
+ grpc_args.args = &ssl_name_override;
+ grpc_channel *channel =
+ grpc_secure_channel_create(ssl_creds, target, &grpc_args, NULL);
+ GPR_ASSERT(channel);
+ gpr_free(target);
+
+ // Initially the channel will be idle, the
+ // grpc_channel_check_connectivity_state triggers an attempt to connect.
+ GPR_ASSERT(grpc_channel_check_connectivity_state(
+ channel, 1 /* try_to_connect */) == GRPC_CHANNEL_IDLE);
+
+ // Wait a bounded number of times for the channel to be ready. When the
+ // channel is ready, the initial TLS handshake will have successfully
+ // completed and we know that the client's ALPN list satisfied the server.
+ int retries = 10;
+ grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
+ grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
+ while (state != GRPC_CHANNEL_READY && retries-- > 0) {
+ grpc_channel_watch_connectivity_state(
+ channel, state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), cq, NULL);
+ gpr_timespec cq_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5);
+ grpc_event ev = grpc_completion_queue_next(cq, cq_deadline, NULL);
+ GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
+ state =
+ grpc_channel_check_connectivity_state(channel, 0 /* try_to_connect */);
+ }
+ grpc_completion_queue_destroy(cq);
+ if (retries < 0) {
+ success = false;
+ }
+
+ grpc_channel_destroy(channel);
+ grpc_channel_credentials_release(ssl_creds);
+ gpr_slice_unref(cert_slice);
+ gpr_slice_unref(key_slice);
+ gpr_slice_unref(ca_slice);
+
+ gpr_thd_join(thdid);
+
+ grpc_shutdown();
+
+ return success;
+}
+
+int main(int argc, char *argv[]) {
+ // Handshake succeeeds when the server has grpc-exp as the ALPN preference.
+ GPR_ASSERT(client_ssl_test("grpc-exp"));
+ // Handshake succeeeds when the server has h2 as the ALPN preference. This
+ // covers legacy gRPC servers which don't support grpc-exp.
+ GPR_ASSERT(client_ssl_test("h2"));
+ // Handshake fails when the server uses a fake protocol as its ALPN
+ // preference. This validates the client is correctly validating ALPN returns
+ // and sanity checks the client_ssl_test.
+ GPR_ASSERT(!client_ssl_test("foo"));
+ return 0;
+}
diff --git a/test/core/handshake/server_ssl.c b/test/core/handshake/server_ssl.c
new file mode 100644
index 0000000000..3e89f8e265
--- /dev/null
+++ b/test/core/handshake/server_ssl.c
@@ -0,0 +1,270 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <arpa/inet.h>
+#include <openssl/err.h>
+#include <openssl/ssl.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include <grpc/grpc.h>
+#include <grpc/grpc_security.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+#include <grpc/support/sync.h>
+#include <grpc/support/thd.h>
+#include "src/core/lib/iomgr/load_file.h"
+#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
+
+#define SSL_CERT_PATH "src/core/lib/tsi/test_creds/server1.pem"
+#define SSL_KEY_PATH "src/core/lib/tsi/test_creds/server1.key"
+#define SSL_CA_PATH "src/core/lib/tsi/test_creds/ca.pem"
+
+// Handshake completed signal to server thread.
+static gpr_event client_handshake_complete;
+
+static int create_socket(int port) {
+ int s;
+ struct sockaddr_in addr;
+
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons((uint16_t)port);
+ addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0) {
+ perror("Unable to create socket");
+ return -1;
+ }
+
+ if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ perror("Unable to connect");
+ return -1;
+ }
+
+ return s;
+}
+
+// Simple gRPC server. This listens until client_handshake_complete occurs.
+static void server_thread(void *arg) {
+ const int port = *(int *)arg;
+
+ // Load key pair and establish server SSL credentials.
+ grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
+ gpr_slice ca_slice, cert_slice, key_slice;
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
+ grpc_load_file(SSL_CA_PATH, 1, &ca_slice)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
+ grpc_load_file(SSL_CERT_PATH, 1, &cert_slice)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
+ grpc_load_file(SSL_KEY_PATH, 1, &key_slice)));
+ const char *ca_cert = (const char *)GPR_SLICE_START_PTR(ca_slice);
+ pem_key_cert_pair.private_key = (const char *)GPR_SLICE_START_PTR(key_slice);
+ pem_key_cert_pair.cert_chain = (const char *)GPR_SLICE_START_PTR(cert_slice);
+ grpc_server_credentials *ssl_creds = grpc_ssl_server_credentials_create(
+ ca_cert, &pem_key_cert_pair, 1, 0, NULL);
+
+ // Start server listening on local port.
+ char *addr;
+ gpr_asprintf(&addr, "127.0.0.1:%d", port);
+ grpc_server *server = grpc_server_create(NULL, NULL);
+ GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, ssl_creds));
+ free(addr);
+
+ grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
+
+ grpc_server_register_completion_queue(server, cq, NULL);
+ grpc_server_start(server);
+
+ // Wait a bounded number of time until client_handshake_complete is set,
+ // sleeping between polls.
+ int retries = 10;
+ while (!gpr_event_get(&client_handshake_complete) && retries-- > 0) {
+ const gpr_timespec cq_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1);
+ grpc_event ev = grpc_completion_queue_next(cq, cq_deadline, NULL);
+ GPR_ASSERT(ev.type == GRPC_QUEUE_TIMEOUT);
+ }
+
+ gpr_log(GPR_INFO, "Shutting down server");
+ grpc_server_shutdown_and_notify(server, cq, NULL);
+ grpc_completion_queue_shutdown(cq);
+
+ const gpr_timespec cq_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5);
+ grpc_event ev = grpc_completion_queue_next(cq, cq_deadline, NULL);
+ GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
+
+ grpc_server_destroy(server);
+ grpc_completion_queue_destroy(cq);
+ grpc_server_credentials_release(ssl_creds);
+ gpr_slice_unref(cert_slice);
+ gpr_slice_unref(key_slice);
+ gpr_slice_unref(ca_slice);
+}
+
+// This test launches a gRPC server on a separate thread and then establishes a
+// TLS handshake via a minimal TLS client. The TLS client has configurable (via
+// alpn_list) ALPN settings and can probe at the supported ALPN preferences
+// using this (via alpn_expected).
+static bool server_ssl_test(const char *alpn_list[], unsigned int alpn_list_len,
+ const char *alpn_expected) {
+ bool success = true;
+
+ grpc_init();
+ int port = grpc_pick_unused_port_or_die();
+ gpr_event_init(&client_handshake_complete);
+
+ // Launch the gRPC server thread.
+ gpr_thd_options thdopt = gpr_thd_options_default();
+ gpr_thd_id thdid;
+ gpr_thd_options_set_joinable(&thdopt);
+ GPR_ASSERT(gpr_thd_new(&thdid, server_thread, &port, &thdopt));
+
+ SSL_load_error_strings();
+ OpenSSL_add_ssl_algorithms();
+
+ const SSL_METHOD *method = TLSv1_2_client_method();
+ SSL_CTX *ctx = SSL_CTX_new(method);
+ if (!ctx) {
+ perror("Unable to create SSL context");
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+
+ // Load key pair.
+ if (SSL_CTX_use_certificate_file(ctx, SSL_CERT_PATH, SSL_FILETYPE_PEM) < 0) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (SSL_CTX_use_PrivateKey_file(ctx, SSL_KEY_PATH, SSL_FILETYPE_PEM) < 0) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+
+ // Set the cipher list to match the one expressed in
+ // src/core/lib/tsi/ssl_transport_security.c.
+ const char *cipher_list =
+ "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-"
+ "SHA384:ECDHE-RSA-AES256-GCM-SHA384";
+ if (!SSL_CTX_set_cipher_list(ctx, cipher_list)) {
+ ERR_print_errors_fp(stderr);
+ gpr_log(GPR_ERROR, "Couldn't set server cipher list.");
+ abort();
+ }
+
+ // Configure ALPN list the client will send to the server. This must match the
+ // wire format, see documentation for SSL_CTX_set_alpn_protos.
+ unsigned int alpn_protos_len = alpn_list_len;
+ for (unsigned int i = 0; i < alpn_list_len; ++i) {
+ alpn_protos_len += (unsigned int)strlen(alpn_list[i]);
+ }
+ unsigned char *alpn_protos = gpr_malloc(alpn_protos_len);
+ unsigned char *p = alpn_protos;
+ for (unsigned int i = 0; i < alpn_list_len; ++i) {
+ const uint8_t len = (uint8_t)strlen(alpn_list[i]);
+ *p++ = len;
+ memcpy(p, alpn_list[i], len);
+ p += len;
+ }
+ GPR_ASSERT(SSL_CTX_set_alpn_protos(ctx, alpn_protos, alpn_protos_len) == 0);
+
+ // Try and connect to server. We allow a bounded number of retries as we might
+ // be racing with the server setup on its separate thread.
+ int retries = 10;
+ int sock = -1;
+ while (sock == -1 && retries-- > 0) {
+ sock = create_socket(port);
+ if (sock < 0) {
+ sleep(1);
+ }
+ }
+ GPR_ASSERT(sock > 0);
+ gpr_log(GPR_INFO, "Connected to server on port %d", port);
+
+ // Establish a SSL* and connect at SSL layer.
+ SSL *ssl = SSL_new(ctx);
+ GPR_ASSERT(ssl);
+ SSL_set_fd(ssl, sock);
+ if (SSL_connect(ssl) <= 0) {
+ ERR_print_errors_fp(stderr);
+ gpr_log(GPR_ERROR, "Handshake failed.");
+ success = false;
+ } else {
+ gpr_log(GPR_INFO, "Handshake successful.");
+ // Validate ALPN preferred by server matches alpn_expected.
+ const unsigned char *alpn_selected;
+ unsigned int alpn_selected_len;
+ SSL_get0_alpn_selected(ssl, &alpn_selected, &alpn_selected_len);
+ if (strlen(alpn_expected) != alpn_selected_len ||
+ strncmp((const char *)alpn_selected, alpn_expected,
+ alpn_selected_len) != 0) {
+ gpr_log(GPR_ERROR, "Unexpected ALPN protocol preference");
+ success = false;
+ }
+ }
+ gpr_event_set(&client_handshake_complete, &client_handshake_complete);
+
+ SSL_free(ssl);
+ gpr_free(alpn_protos);
+ SSL_CTX_free(ctx);
+ EVP_cleanup();
+ close(sock);
+
+ gpr_thd_join(thdid);
+
+ grpc_shutdown();
+
+ return success;
+}
+
+int main(int argc, char *argv[]) {
+ // Handshake succeeeds when the client supplies the standard ALPN list.
+ const char *full_alpn_list[] = {"grpc-exp", "h2"};
+ GPR_ASSERT(server_ssl_test(full_alpn_list, 2, "grpc-exp"));
+ // Handshake succeeeds when the client supplies only h2 as the ALPN list. This
+ // covers legacy gRPC clients which don't support grpc-exp.
+ const char *h2_only_alpn_list[] = {"h2"};
+ GPR_ASSERT(server_ssl_test(h2_only_alpn_list, 1, "h2"));
+ // Handshake succeeds when the client supplies superfluous ALPN entries and
+ // also when h2 precedes gprc-exp.
+ const char *extra_alpn_list[] = {"foo", "h2", "bar", "grpc-exp"};
+ GPR_ASSERT(server_ssl_test(extra_alpn_list, 4, "h2"));
+ // Handshake fails when the client uses a fake protocol as its only ALPN
+ // preference. This validates the server is correctly validating ALPN
+ // and sanity checks the server_ssl_test.
+ const char *fake_alpn_list[] = {"foo"};
+ GPR_ASSERT(!server_ssl_test(fake_alpn_list, 1, "foo"));
+ return 0;
+}
diff --git a/test/core/http/httpcli_test.c b/test/core/http/httpcli_test.c
index 38b32a3867..3e312c1dde 100644
--- a/test/core/http/httpcli_test.c
+++ b/test/core/http/httpcli_test.c
@@ -89,8 +89,11 @@ static void test_get(int port) {
grpc_http_response response;
memset(&response, 0, sizeof(response));
- grpc_httpcli_get(&exec_ctx, &g_context, &g_pops, &req, n_seconds_time(15),
+ grpc_resource_quota *resource_quota = grpc_resource_quota_create("test_get");
+ grpc_httpcli_get(&exec_ctx, &g_context, &g_pops, resource_quota, &req,
+ n_seconds_time(15),
grpc_closure_create(on_finish, &response), &response);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
gpr_mu_lock(g_mu);
while (!g_done) {
grpc_pollset_worker *worker = NULL;
@@ -126,9 +129,11 @@ static void test_post(int port) {
grpc_http_response response;
memset(&response, 0, sizeof(response));
- grpc_httpcli_post(&exec_ctx, &g_context, &g_pops, &req, "hello", 5,
- n_seconds_time(15),
+ grpc_resource_quota *resource_quota = grpc_resource_quota_create("test_post");
+ grpc_httpcli_post(&exec_ctx, &g_context, &g_pops, resource_quota, &req,
+ "hello", 5, n_seconds_time(15),
grpc_closure_create(on_finish, &response), &response);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
gpr_mu_lock(g_mu);
while (!g_done) {
grpc_pollset_worker *worker = NULL;
diff --git a/test/core/http/httpscli_test.c b/test/core/http/httpscli_test.c
index 359e557689..d06035149e 100644
--- a/test/core/http/httpscli_test.c
+++ b/test/core/http/httpscli_test.c
@@ -90,8 +90,11 @@ static void test_get(int port) {
grpc_http_response response;
memset(&response, 0, sizeof(response));
- grpc_httpcli_get(&exec_ctx, &g_context, &g_pops, &req, n_seconds_time(15),
+ grpc_resource_quota *resource_quota = grpc_resource_quota_create("test_get");
+ grpc_httpcli_get(&exec_ctx, &g_context, &g_pops, resource_quota, &req,
+ n_seconds_time(15),
grpc_closure_create(on_finish, &response), &response);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
gpr_mu_lock(g_mu);
while (!g_done) {
grpc_pollset_worker *worker = NULL;
@@ -128,9 +131,11 @@ static void test_post(int port) {
grpc_http_response response;
memset(&response, 0, sizeof(response));
- grpc_httpcli_post(&exec_ctx, &g_context, &g_pops, &req, "hello", 5,
- n_seconds_time(15),
+ grpc_resource_quota *resource_quota = grpc_resource_quota_create("test_post");
+ grpc_httpcli_post(&exec_ctx, &g_context, &g_pops, resource_quota, &req,
+ "hello", 5, n_seconds_time(15),
grpc_closure_create(on_finish, &response), &response);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
gpr_mu_lock(g_mu);
while (!g_done) {
grpc_pollset_worker *worker = NULL;
diff --git a/test/core/internal_api_canaries/iomgr.c b/test/core/internal_api_canaries/iomgr.c
index 27d630623e..f1efa87a69 100644
--- a/test/core/internal_api_canaries/iomgr.c
+++ b/test/core/internal_api_canaries/iomgr.c
@@ -84,6 +84,7 @@ static void test_code(void) {
grpc_endpoint_add_to_pollset_set,
grpc_endpoint_shutdown,
grpc_endpoint_destroy,
+ grpc_endpoint_get_resource_user,
grpc_endpoint_get_peer};
endpoint.vtable = &vtable;
diff --git a/test/core/iomgr/endpoint_pair_test.c b/test/core/iomgr/endpoint_pair_test.c
index 99b86b6213..2a257a7cea 100644
--- a/test/core/iomgr/endpoint_pair_test.c
+++ b/test/core/iomgr/endpoint_pair_test.c
@@ -49,7 +49,11 @@ static grpc_endpoint_test_fixture create_fixture_endpoint_pair(
size_t slice_size) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_endpoint_test_fixture f;
- grpc_endpoint_pair p = grpc_iomgr_create_endpoint_pair("test", slice_size);
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("endpoint_pair_test");
+ grpc_endpoint_pair p =
+ grpc_iomgr_create_endpoint_pair("test", resource_quota, slice_size);
+ grpc_resource_quota_unref(resource_quota);
f.client_ep = p.client;
f.server_ep = p.server;
diff --git a/test/core/iomgr/ev_epoll_linux_test.c b/test/core/iomgr/ev_epoll_linux_test.c
index 2547dc9871..564b05d7f4 100644
--- a/test/core/iomgr/ev_epoll_linux_test.c
+++ b/test/core/iomgr/ev_epoll_linux_test.c
@@ -30,10 +30,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-#include <grpc/support/port_platform.h>
+#include "src/core/lib/iomgr/port.h"
/* This test only relevant on linux systems where epoll() is available */
-#ifdef GPR_LINUX_EPOLL
+#ifdef GRPC_LINUX_EPOLL
#include "src/core/lib/iomgr/ev_epoll_linux.h"
#include "src/core/lib/iomgr/ev_posix.h"
@@ -239,6 +239,6 @@ int main(int argc, char **argv) {
grpc_iomgr_shutdown();
return 0;
}
-#else /* defined(GPR_LINUX_EPOLL) */
+#else /* defined(GRPC_LINUX_EPOLL) */
int main(int argc, char **argv) { return 0; }
-#endif /* !defined(GPR_LINUX_EPOLL) */
+#endif /* !defined(GRPC_LINUX_EPOLL) */
diff --git a/test/core/iomgr/fd_conservation_posix_test.c b/test/core/iomgr/fd_conservation_posix_test.c
index bbb3f46497..652b37eb6f 100644
--- a/test/core/iomgr/fd_conservation_posix_test.c
+++ b/test/core/iomgr/fd_conservation_posix_test.c
@@ -52,15 +52,19 @@ int main(int argc, char **argv) {
of descriptors */
rlim.rlim_cur = rlim.rlim_max = 10;
GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim));
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("fd_conservation_posix_test");
for (i = 0; i < 100; i++) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- p = grpc_iomgr_create_endpoint_pair("test", 1);
+ p = grpc_iomgr_create_endpoint_pair("test", resource_quota, 1);
grpc_endpoint_destroy(&exec_ctx, p.client);
grpc_endpoint_destroy(&exec_ctx, p.server);
grpc_exec_ctx_finish(&exec_ctx);
}
+ grpc_resource_quota_unref(resource_quota);
+
grpc_iomgr_shutdown();
return 0;
}
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index 62dc24d85a..6166699fe6 100644
--- a/test/core/iomgr/fd_posix_test.c
+++ b/test/core/iomgr/fd_posix_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/ev_posix.h"
#include <ctype.h>
@@ -548,3 +553,9 @@ int main(int argc, char **argv) {
grpc_iomgr_shutdown();
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c
index 4417d96043..2dd0d88b3f 100644
--- a/test/core/iomgr/resolve_address_test.c
+++ b/test/core/iomgr/resolve_address_test.c
@@ -36,6 +36,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/iomgr/executor.h"
+#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"
static gpr_timespec test_deadline(void) {
diff --git a/test/core/iomgr/resource_quota_test.c b/test/core/iomgr/resource_quota_test.c
new file mode 100644
index 0000000000..34dee1aee1
--- /dev/null
+++ b/test/core/iomgr/resource_quota_test.c
@@ -0,0 +1,749 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "src/core/lib/iomgr/resource_quota.h"
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+
+#include "test/core/util/test_config.h"
+
+static void inc_int_cb(grpc_exec_ctx *exec_ctx, void *a, grpc_error *error) {
+ ++*(int *)a;
+}
+
+static void set_bool_cb(grpc_exec_ctx *exec_ctx, void *a, grpc_error *error) {
+ *(bool *)a = true;
+}
+grpc_closure *set_bool(bool *p) { return grpc_closure_create(set_bool_cb, p); }
+
+typedef struct {
+ size_t size;
+ grpc_resource_user *resource_user;
+ grpc_closure *then;
+} reclaimer_args;
+static void reclaimer_cb(grpc_exec_ctx *exec_ctx, void *args,
+ grpc_error *error) {
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
+ reclaimer_args *a = args;
+ grpc_resource_user_free(exec_ctx, a->resource_user, a->size);
+ grpc_resource_user_finish_reclamation(exec_ctx, a->resource_user);
+ grpc_closure_run(exec_ctx, a->then, GRPC_ERROR_NONE);
+ gpr_free(a);
+}
+grpc_closure *make_reclaimer(grpc_resource_user *resource_user, size_t size,
+ grpc_closure *then) {
+ reclaimer_args *a = gpr_malloc(sizeof(*a));
+ a->size = size;
+ a->resource_user = resource_user;
+ a->then = then;
+ return grpc_closure_create(reclaimer_cb, a);
+}
+
+static void unused_reclaimer_cb(grpc_exec_ctx *exec_ctx, void *arg,
+ grpc_error *error) {
+ GPR_ASSERT(error == GRPC_ERROR_CANCELLED);
+ grpc_closure_run(exec_ctx, arg, GRPC_ERROR_NONE);
+}
+grpc_closure *make_unused_reclaimer(grpc_closure *then) {
+ return grpc_closure_create(unused_reclaimer_cb, then);
+}
+
+static void destroy_user(grpc_resource_user *usr) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ bool done = false;
+ grpc_resource_user_shutdown(&exec_ctx, usr, set_bool(&done));
+ grpc_exec_ctx_flush(&exec_ctx);
+ GPR_ASSERT(done);
+ grpc_resource_user_destroy(&exec_ctx, usr);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+static void test_no_op(void) {
+ gpr_log(GPR_INFO, "** test_no_op **");
+ grpc_resource_quota_unref(grpc_resource_quota_create("test_no_op"));
+}
+
+static void test_resize_then_destroy(void) {
+ gpr_log(GPR_INFO, "** test_resize_then_destroy **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_resize_then_destroy");
+ grpc_resource_quota_resize(q, 1024 * 1024);
+ grpc_resource_quota_unref(q);
+}
+
+static void test_resource_user_no_op(void) {
+ gpr_log(GPR_INFO, "** test_resource_user_no_op **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_resource_user_no_op");
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+}
+
+static void test_instant_alloc_then_free(void) {
+ gpr_log(GPR_INFO, "** test_instant_alloc_then_free **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_instant_alloc_then_free");
+ grpc_resource_quota_resize(q, 1024 * 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, NULL);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+}
+
+static void test_instant_alloc_free_pair(void) {
+ gpr_log(GPR_INFO, "** test_instant_alloc_free_pair **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_instant_alloc_free_pair");
+ grpc_resource_quota_resize(q, 1024 * 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, NULL);
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+}
+
+static void test_simple_async_alloc(void) {
+ gpr_log(GPR_INFO, "** test_simple_async_alloc **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_simple_async_alloc");
+ grpc_resource_quota_resize(q, 1024 * 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+}
+
+static void test_async_alloc_blocked_by_size(void) {
+ gpr_log(GPR_INFO, "** test_async_alloc_blocked_by_size **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_async_alloc_blocked_by_size");
+ grpc_resource_quota_resize(q, 1);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ bool done = false;
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!done);
+ }
+ grpc_resource_quota_resize(q, 1024);
+ GPR_ASSERT(done);
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+}
+
+static void test_scavenge(void) {
+ gpr_log(GPR_INFO, "** test_scavenge **");
+ grpc_resource_quota *q = grpc_resource_quota_create("test_scavenge");
+ grpc_resource_quota_resize(q, 1024);
+ grpc_resource_user usr1;
+ grpc_resource_user usr2;
+ grpc_resource_user_init(&usr1, q, "usr1");
+ grpc_resource_user_init(&usr2, q, "usr2");
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr1, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr1, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr2, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr2, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr1);
+ destroy_user(&usr2);
+}
+
+static void test_scavenge_blocked(void) {
+ gpr_log(GPR_INFO, "** test_scavenge_blocked **");
+ grpc_resource_quota *q = grpc_resource_quota_create("test_scavenge_blocked");
+ grpc_resource_quota_resize(q, 1024);
+ grpc_resource_user usr1;
+ grpc_resource_user usr2;
+ grpc_resource_user_init(&usr1, q, "usr1");
+ grpc_resource_user_init(&usr2, q, "usr2");
+ bool done;
+ {
+ done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr1, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ {
+ done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr2, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr1, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr2, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr1);
+ destroy_user(&usr2);
+}
+
+static void test_blocked_until_scheduled_reclaim(void) {
+ gpr_log(GPR_INFO, "** test_blocked_until_scheduled_reclaim **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_blocked_until_scheduled_reclaim");
+ grpc_resource_quota_resize(q, 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ bool reclaim_done = false;
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, false,
+ make_reclaimer(&usr, 1024, set_bool(&reclaim_done)));
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(reclaim_done);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+}
+
+static void test_blocked_until_scheduled_reclaim_and_scavenge(void) {
+ gpr_log(GPR_INFO, "** test_blocked_until_scheduled_reclaim_and_scavenge **");
+ grpc_resource_quota *q = grpc_resource_quota_create(
+ "test_blocked_until_scheduled_reclaim_and_scavenge");
+ grpc_resource_quota_resize(q, 1024);
+ grpc_resource_user usr1;
+ grpc_resource_user usr2;
+ grpc_resource_user_init(&usr1, q, "usr1");
+ grpc_resource_user_init(&usr2, q, "usr2");
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr1, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ bool reclaim_done = false;
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr1, false,
+ make_reclaimer(&usr1, 1024, set_bool(&reclaim_done)));
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr2, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(reclaim_done);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr2, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr1);
+ destroy_user(&usr2);
+}
+
+static void test_blocked_until_scheduled_destructive_reclaim(void) {
+ gpr_log(GPR_INFO, "** test_blocked_until_scheduled_destructive_reclaim **");
+ grpc_resource_quota *q = grpc_resource_quota_create(
+ "test_blocked_until_scheduled_destructive_reclaim");
+ grpc_resource_quota_resize(q, 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ bool reclaim_done = false;
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, true,
+ make_reclaimer(&usr, 1024, set_bool(&reclaim_done)));
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(reclaim_done);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+}
+
+static void test_unused_reclaim_is_cancelled(void) {
+ gpr_log(GPR_INFO, "** test_unused_reclaim_is_cancelled **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_unused_reclaim_is_cancelled");
+ grpc_resource_quota_resize(q, 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ bool benign_done = false;
+ bool destructive_done = false;
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, false, make_unused_reclaimer(set_bool(&benign_done)));
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, true,
+ make_unused_reclaimer(set_bool(&destructive_done)));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!benign_done);
+ GPR_ASSERT(!destructive_done);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+ GPR_ASSERT(benign_done);
+ GPR_ASSERT(destructive_done);
+}
+
+static void test_benign_reclaim_is_preferred(void) {
+ gpr_log(GPR_INFO, "** test_benign_reclaim_is_preferred **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_benign_reclaim_is_preferred");
+ grpc_resource_quota_resize(q, 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ bool benign_done = false;
+ bool destructive_done = false;
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, false,
+ make_reclaimer(&usr, 1024, set_bool(&benign_done)));
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, true,
+ make_unused_reclaimer(set_bool(&destructive_done)));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!benign_done);
+ GPR_ASSERT(!destructive_done);
+ }
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(benign_done);
+ GPR_ASSERT(!destructive_done);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+ GPR_ASSERT(benign_done);
+ GPR_ASSERT(destructive_done);
+}
+
+static void test_multiple_reclaims_can_be_triggered(void) {
+ gpr_log(GPR_INFO, "** test_multiple_reclaims_can_be_triggered **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_multiple_reclaims_can_be_triggered");
+ grpc_resource_quota_resize(q, 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ bool benign_done = false;
+ bool destructive_done = false;
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, false,
+ make_reclaimer(&usr, 512, set_bool(&benign_done)));
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, true,
+ make_reclaimer(&usr, 512, set_bool(&destructive_done)));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!benign_done);
+ GPR_ASSERT(!destructive_done);
+ }
+ {
+ bool done = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(benign_done);
+ GPR_ASSERT(destructive_done);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ grpc_resource_quota_unref(q);
+ destroy_user(&usr);
+ GPR_ASSERT(benign_done);
+ GPR_ASSERT(destructive_done);
+}
+
+static void test_resource_user_stays_allocated_until_memory_released(void) {
+ gpr_log(GPR_INFO,
+ "** test_resource_user_stays_allocated_until_memory_released **");
+ grpc_resource_quota *q = grpc_resource_quota_create(
+ "test_resource_user_stays_allocated_until_memory_released");
+ grpc_resource_quota_resize(q, 1024 * 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ bool done = false;
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, NULL);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_quota_unref(q);
+ grpc_resource_user_shutdown(&exec_ctx, &usr, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_destroy(&exec_ctx, &usr);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+}
+
+static void
+test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released(
+ void) {
+ gpr_log(GPR_INFO,
+ "** "
+ "test_resource_user_stays_allocated_and_reclaimers_unrun_until_"
+ "memory_released **");
+ grpc_resource_quota *q = grpc_resource_quota_create(
+ "test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_"
+ "released");
+ grpc_resource_quota_resize(q, 1024);
+ for (int i = 0; i < 10; i++) {
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ bool done = false;
+ bool reclaimer_cancelled = false;
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, false,
+ make_unused_reclaimer(set_bool(&reclaimer_cancelled)));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!reclaimer_cancelled);
+ }
+ {
+ bool allocated = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&allocated));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(allocated);
+ GPR_ASSERT(!reclaimer_cancelled);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_shutdown(&exec_ctx, &usr, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!done);
+ GPR_ASSERT(!reclaimer_cancelled);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+ GPR_ASSERT(reclaimer_cancelled);
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_destroy(&exec_ctx, &usr);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ }
+ grpc_resource_quota_unref(q);
+}
+
+static void test_reclaimers_can_be_posted_repeatedly(void) {
+ gpr_log(GPR_INFO, "** test_reclaimers_can_be_posted_repeatedly **");
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_reclaimers_can_be_posted_repeatedly");
+ grpc_resource_quota_resize(q, 1024);
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+ {
+ bool allocated = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&allocated));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(allocated);
+ }
+ for (int i = 0; i < 10; i++) {
+ bool reclaimer_done = false;
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_post_reclaimer(
+ &exec_ctx, &usr, false,
+ make_reclaimer(&usr, 1024, set_bool(&reclaimer_done)));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!reclaimer_done);
+ }
+ {
+ bool allocated = false;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&allocated));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(allocated);
+ GPR_ASSERT(reclaimer_done);
+ }
+ }
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_free(&exec_ctx, &usr, 1024);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ destroy_user(&usr);
+ grpc_resource_quota_unref(q);
+}
+
+static void test_one_slice(void) {
+ gpr_log(GPR_INFO, "** test_one_slice **");
+
+ grpc_resource_quota *q = grpc_resource_quota_create("test_one_slice");
+ grpc_resource_quota_resize(q, 1024);
+
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+
+ grpc_resource_user_slice_allocator alloc;
+ int num_allocs = 0;
+ grpc_resource_user_slice_allocator_init(&alloc, &usr, inc_int_cb,
+ &num_allocs);
+
+ gpr_slice_buffer buffer;
+ gpr_slice_buffer_init(&buffer);
+
+ {
+ const int start_allocs = num_allocs;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer);
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(num_allocs == start_allocs + 1);
+ }
+
+ gpr_slice_buffer_destroy(&buffer);
+ destroy_user(&usr);
+ grpc_resource_quota_unref(q);
+}
+
+static void test_one_slice_deleted_late(void) {
+ gpr_log(GPR_INFO, "** test_one_slice_deleted_late **");
+
+ grpc_resource_quota *q =
+ grpc_resource_quota_create("test_one_slice_deleted_late");
+ grpc_resource_quota_resize(q, 1024);
+
+ grpc_resource_user usr;
+ grpc_resource_user_init(&usr, q, "usr");
+
+ grpc_resource_user_slice_allocator alloc;
+ int num_allocs = 0;
+ grpc_resource_user_slice_allocator_init(&alloc, &usr, inc_int_cb,
+ &num_allocs);
+
+ gpr_slice_buffer buffer;
+ gpr_slice_buffer_init(&buffer);
+
+ {
+ const int start_allocs = num_allocs;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer);
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(num_allocs == start_allocs + 1);
+ }
+
+ bool done = false;
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_shutdown(&exec_ctx, &usr, set_bool(&done));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(!done);
+ }
+
+ grpc_resource_quota_unref(q);
+ gpr_slice_buffer_destroy(&buffer);
+ GPR_ASSERT(done);
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resource_user_destroy(&exec_ctx, &usr);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+ test_no_op();
+ test_resize_then_destroy();
+ test_resource_user_no_op();
+ test_instant_alloc_then_free();
+ test_instant_alloc_free_pair();
+ test_simple_async_alloc();
+ test_async_alloc_blocked_by_size();
+ test_scavenge();
+ test_scavenge_blocked();
+ test_blocked_until_scheduled_reclaim();
+ test_blocked_until_scheduled_reclaim_and_scavenge();
+ test_blocked_until_scheduled_destructive_reclaim();
+ test_unused_reclaim_is_cancelled();
+ test_benign_reclaim_is_preferred();
+ test_multiple_reclaims_can_be_triggered();
+ test_resource_user_stays_allocated_until_memory_released();
+ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released();
+ test_reclaimers_can_be_posted_repeatedly();
+ test_one_slice();
+ test_one_slice_deleted_late();
+ grpc_shutdown();
+ return 0;
+}
diff --git a/test/core/iomgr/sockaddr_utils_test.c b/test/core/iomgr/sockaddr_utils_test.c
index a330314443..8569c697fe 100644
--- a/test/core/iomgr/sockaddr_utils_test.c
+++ b/test/core/iomgr/sockaddr_utils_test.c
@@ -31,6 +31,11 @@
*
*/
+/* With the addition of a libuv endpoint, sockaddr.h now includes uv.h when
+ using that endpoint. Because of various transitive includes in uv.h,
+ including windows.h on Windows, uv.h must be included before other system
+ headers. Therefore, sockaddr.h must always be included first */
+#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include <errno.h>
@@ -41,24 +46,28 @@
#include <grpc/support/port_platform.h>
#include "test/core/util/test_config.h"
-static struct sockaddr_in make_addr4(const uint8_t *data, size_t data_len) {
- struct sockaddr_in addr4;
- memset(&addr4, 0, sizeof(addr4));
- addr4.sin_family = AF_INET;
- GPR_ASSERT(data_len == sizeof(addr4.sin_addr.s_addr));
- memcpy(&addr4.sin_addr.s_addr, data, data_len);
- addr4.sin_port = htons(12345);
- return addr4;
+static grpc_resolved_address make_addr4(const uint8_t *data, size_t data_len) {
+ grpc_resolved_address resolved_addr4;
+ struct sockaddr_in *addr4 = (struct sockaddr_in *)resolved_addr4.addr;
+ memset(&resolved_addr4, 0, sizeof(resolved_addr4));
+ addr4->sin_family = AF_INET;
+ GPR_ASSERT(data_len == sizeof(addr4->sin_addr.s_addr));
+ memcpy(&addr4->sin_addr.s_addr, data, data_len);
+ addr4->sin_port = htons(12345);
+ resolved_addr4.len = sizeof(struct sockaddr_in);
+ return resolved_addr4;
}
-static struct sockaddr_in6 make_addr6(const uint8_t *data, size_t data_len) {
- struct sockaddr_in6 addr6;
- memset(&addr6, 0, sizeof(addr6));
- addr6.sin6_family = AF_INET6;
- GPR_ASSERT(data_len == sizeof(addr6.sin6_addr.s6_addr));
- memcpy(&addr6.sin6_addr.s6_addr, data, data_len);
- addr6.sin6_port = htons(12345);
- return addr6;
+static grpc_resolved_address make_addr6(const uint8_t *data, size_t data_len) {
+ grpc_resolved_address resolved_addr6;
+ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)resolved_addr6.addr;
+ memset(&resolved_addr6, 0, sizeof(resolved_addr6));
+ addr6->sin6_family = AF_INET6;
+ GPR_ASSERT(data_len == sizeof(addr6->sin6_addr.s6_addr));
+ memcpy(&addr6->sin6_addr.s6_addr, data, data_len);
+ addr6->sin6_port = htons(12345);
+ resolved_addr6.len = sizeof(struct sockaddr_in6);
+ return resolved_addr6;
}
static const uint8_t kMapped[] = {0, 0, 0, 0, 0, 0, 0, 0,
@@ -72,102 +81,96 @@ static const uint8_t kIPv6[] = {0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1};
static void test_sockaddr_is_v4mapped(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr_in output4;
- struct sockaddr_in expect4;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address output4;
+ grpc_resolved_address expect4;
gpr_log(GPR_INFO, "%s", "test_sockaddr_is_v4mapped");
/* v4mapped input should succeed. */
input6 = make_addr6(kMapped, sizeof(kMapped));
- GPR_ASSERT(grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, NULL));
- GPR_ASSERT(
- grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, &output4));
+ GPR_ASSERT(grpc_sockaddr_is_v4mapped(&input6, NULL));
+ GPR_ASSERT(grpc_sockaddr_is_v4mapped(&input6, &output4));
expect4 = make_addr4(kIPv4, sizeof(kIPv4));
GPR_ASSERT(memcmp(&expect4, &output4, sizeof(expect4)) == 0);
/* Non-v4mapped input should fail. */
input6 = make_addr6(kNotQuiteMapped, sizeof(kNotQuiteMapped));
- GPR_ASSERT(
- !grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, NULL));
- GPR_ASSERT(
- !grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, &output4));
+ GPR_ASSERT(!grpc_sockaddr_is_v4mapped(&input6, NULL));
+ GPR_ASSERT(!grpc_sockaddr_is_v4mapped(&input6, &output4));
/* Output is unchanged. */
GPR_ASSERT(memcmp(&expect4, &output4, sizeof(expect4)) == 0);
/* Plain IPv4 input should also fail. */
input4 = make_addr4(kIPv4, sizeof(kIPv4));
- GPR_ASSERT(
- !grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input4, NULL));
+ GPR_ASSERT(!grpc_sockaddr_is_v4mapped(&input4, NULL));
}
static void test_sockaddr_to_v4mapped(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr_in6 output6;
- struct sockaddr_in6 expect6;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address output6;
+ grpc_resolved_address expect6;
gpr_log(GPR_INFO, "%s", "test_sockaddr_to_v4mapped");
/* IPv4 input should succeed. */
input4 = make_addr4(kIPv4, sizeof(kIPv4));
- GPR_ASSERT(
- grpc_sockaddr_to_v4mapped((const struct sockaddr *)&input4, &output6));
+ GPR_ASSERT(grpc_sockaddr_to_v4mapped(&input4, &output6));
expect6 = make_addr6(kMapped, sizeof(kMapped));
GPR_ASSERT(memcmp(&expect6, &output6, sizeof(output6)) == 0);
/* IPv6 input should fail. */
input6 = make_addr6(kIPv6, sizeof(kIPv6));
- GPR_ASSERT(
- !grpc_sockaddr_to_v4mapped((const struct sockaddr *)&input6, &output6));
+ GPR_ASSERT(!grpc_sockaddr_to_v4mapped(&input6, &output6));
/* Output is unchanged. */
GPR_ASSERT(memcmp(&expect6, &output6, sizeof(output6)) == 0);
/* Already-v4mapped input should also fail. */
input6 = make_addr6(kMapped, sizeof(kMapped));
- GPR_ASSERT(
- !grpc_sockaddr_to_v4mapped((const struct sockaddr *)&input6, &output6));
+ GPR_ASSERT(!grpc_sockaddr_to_v4mapped(&input6, &output6));
}
static void test_sockaddr_is_wildcard(void) {
- struct sockaddr_in wild4;
- struct sockaddr_in6 wild6;
- struct sockaddr_in6 wild_mapped;
- struct sockaddr dummy;
+ grpc_resolved_address wild4;
+ grpc_resolved_address wild6;
+ grpc_resolved_address wild_mapped;
+ grpc_resolved_address dummy;
+ struct sockaddr_in *wild4_addr;
+ struct sockaddr_in6 *wild6_addr;
+ struct sockaddr_in6 *wild_mapped_addr;
int port;
gpr_log(GPR_INFO, "%s", "test_sockaddr_is_wildcard");
/* Generate wildcards. */
grpc_sockaddr_make_wildcards(555, &wild4, &wild6);
- GPR_ASSERT(
- grpc_sockaddr_to_v4mapped((const struct sockaddr *)&wild4, &wild_mapped));
+ GPR_ASSERT(grpc_sockaddr_to_v4mapped(&wild4, &wild_mapped));
/* Test 0.0.0.0:555 */
port = -1;
- GPR_ASSERT(grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild4, &port));
+ GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild4, &port));
GPR_ASSERT(port == 555);
- memset(&wild4.sin_addr.s_addr, 0xbd, 1);
- GPR_ASSERT(
- !grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild4, &port));
+ wild4_addr = (struct sockaddr_in *)&wild4.addr;
+ memset(&wild4_addr->sin_addr.s_addr, 0xbd, 1);
+ GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild4, &port));
/* Test [::]:555 */
port = -1;
- GPR_ASSERT(grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild6, &port));
+ GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild6, &port));
GPR_ASSERT(port == 555);
- memset(&wild6.sin6_addr.s6_addr, 0xbd, 1);
- GPR_ASSERT(
- !grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild6, &port));
+ wild6_addr = (struct sockaddr_in6 *)&wild6.addr;
+ memset(&wild6_addr->sin6_addr.s6_addr, 0xbd, 1);
+ GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild6, &port));
/* Test [::ffff:0.0.0.0]:555 */
port = -1;
- GPR_ASSERT(
- grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild_mapped, &port));
+ GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild_mapped, &port));
GPR_ASSERT(port == 555);
- memset(&wild_mapped.sin6_addr.s6_addr, 0xbd, 1);
- GPR_ASSERT(
- !grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild_mapped, &port));
+ wild_mapped_addr = (struct sockaddr_in6 *)&wild_mapped.addr;
+ memset(&wild_mapped_addr->sin6_addr.s6_addr, 0xbd, 1);
+ GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild_mapped, &port));
/* Test AF_UNSPEC. */
port = -1;
@@ -176,12 +179,12 @@ static void test_sockaddr_is_wildcard(void) {
GPR_ASSERT(port == -1);
}
-static void expect_sockaddr_str(const char *expected, void *addr,
- int normalize) {
+static void expect_sockaddr_str(const char *expected,
+ grpc_resolved_address *addr, int normalize) {
int result;
char *str;
gpr_log(GPR_INFO, " expect_sockaddr_str(%s)", expected);
- result = grpc_sockaddr_to_string(&str, (struct sockaddr *)addr, normalize);
+ result = grpc_sockaddr_to_string(&str, addr, normalize);
GPR_ASSERT(str != NULL);
GPR_ASSERT(result >= 0);
GPR_ASSERT((size_t)result == strlen(str));
@@ -189,19 +192,21 @@ static void expect_sockaddr_str(const char *expected, void *addr,
gpr_free(str);
}
-static void expect_sockaddr_uri(const char *expected, void *addr) {
+static void expect_sockaddr_uri(const char *expected,
+ grpc_resolved_address *addr) {
char *str;
gpr_log(GPR_INFO, " expect_sockaddr_uri(%s)", expected);
- str = grpc_sockaddr_to_uri((struct sockaddr *)addr);
+ str = grpc_sockaddr_to_uri(addr);
GPR_ASSERT(str != NULL);
GPR_ASSERT(strcmp(expected, str) == 0);
gpr_free(str);
}
static void test_sockaddr_to_string(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr dummy;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address dummy;
+ struct sockaddr *dummy_addr;
gpr_log(GPR_INFO, "%s", "test_sockaddr_to_string");
@@ -228,7 +233,8 @@ static void test_sockaddr_to_string(void) {
expect_sockaddr_uri("ipv6:[::fffe:c000:263]:12345", &input6);
memset(&dummy, 0, sizeof(dummy));
- dummy.sa_family = 123;
+ dummy_addr = (struct sockaddr *)dummy.addr;
+ dummy_addr->sa_family = 123;
expect_sockaddr_str("(sockaddr family=123)", &dummy, 0);
expect_sockaddr_str("(sockaddr family=123)", &dummy, 1);
GPR_ASSERT(grpc_sockaddr_to_uri(&dummy) == NULL);
@@ -237,24 +243,26 @@ static void test_sockaddr_to_string(void) {
}
static void test_sockaddr_set_get_port(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr dummy;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address dummy;
+ struct sockaddr *dummy_addr;
gpr_log(GPR_DEBUG, "test_sockaddr_set_get_port");
input4 = make_addr4(kIPv4, sizeof(kIPv4));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input4) == 12345);
- GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr *)&input4, 54321));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input4) == 54321);
+ GPR_ASSERT(grpc_sockaddr_get_port(&input4) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port(&input4, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port(&input4) == 54321);
input6 = make_addr6(kIPv6, sizeof(kIPv6));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input6) == 12345);
- GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr *)&input6, 54321));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input6) == 54321);
+ GPR_ASSERT(grpc_sockaddr_get_port(&input6) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port(&input6, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port(&input6) == 54321);
memset(&dummy, 0, sizeof(dummy));
- dummy.sa_family = 123;
+ dummy_addr = (struct sockaddr *)dummy.addr;
+ dummy_addr->sa_family = 123;
GPR_ASSERT(grpc_sockaddr_get_port(&dummy) == 0);
GPR_ASSERT(grpc_sockaddr_set_port(&dummy, 1234) == 0);
}
diff --git a/test/core/iomgr/socket_utils_test.c b/test/core/iomgr/socket_utils_test.c
index 297531c44d..67bc914c15 100644
--- a/test/core/iomgr/socket_utils_test.c
+++ b/test/core/iomgr/socket_utils_test.c
@@ -31,7 +31,11 @@
*
*/
-#include <grpc/support/port_platform.h>
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/socket_utils_posix.h"
#include <errno.h>
@@ -68,3 +72,9 @@ int main(int argc, char **argv) {
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index d0c1047423..5fab826fb7 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -85,8 +85,8 @@ static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
}
void test_succeeds(void) {
- struct sockaddr_in addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
int svr_fd;
int r;
int connections_complete_before;
@@ -95,13 +95,15 @@ void test_succeeds(void) {
gpr_log(GPR_DEBUG, "test_succeeds");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
/* create a dummy server */
svr_fd = socket(AF_INET, SOCK_STREAM, 0);
GPR_ASSERT(svr_fd >= 0);
- GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr *)&addr, addr_len));
+ GPR_ASSERT(
+ 0 == bind(svr_fd, (struct sockaddr *)addr, (socklen_t)resolved_addr.len));
GPR_ASSERT(0 == listen(svr_fd, 1));
gpr_mu_lock(g_mu);
@@ -109,16 +111,17 @@ void test_succeeds(void) {
gpr_mu_unlock(g_mu);
/* connect to it */
- GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0);
+ GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)addr,
+ (socklen_t *)&resolved_addr.len) == 0);
grpc_closure_init(&done, must_succeed, NULL);
- grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set,
- (struct sockaddr *)&addr, addr_len,
- gpr_inf_future(GPR_CLOCK_REALTIME));
+ grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, NULL,
+ &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
/* await the connection */
do {
- addr_len = sizeof(addr);
- r = accept(svr_fd, (struct sockaddr *)&addr, &addr_len);
+ resolved_addr.len = sizeof(addr);
+ r = accept(svr_fd, (struct sockaddr *)addr,
+ (socklen_t *)&resolved_addr.len);
} while (r == -1 && errno == EINTR);
GPR_ASSERT(r >= 0);
close(r);
@@ -143,16 +146,17 @@ void test_succeeds(void) {
}
void test_fails(void) {
- struct sockaddr_in addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
int connections_complete_before;
grpc_closure done;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_fails");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
gpr_mu_lock(g_mu);
connections_complete_before = g_connections_complete;
@@ -160,9 +164,8 @@ void test_fails(void) {
/* connect to a broken address */
grpc_closure_init(&done, must_fail, NULL);
- grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set,
- (struct sockaddr *)&addr, addr_len,
- gpr_inf_future(GPR_CLOCK_REALTIME));
+ grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, NULL,
+ &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c
index 42614567ca..29f12a5afb 100644
--- a/test/core/iomgr/tcp_posix_test.c
+++ b/test/core/iomgr/tcp_posix_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/tcp_posix.h"
#include <errno.h>
@@ -176,7 +181,10 @@ static void read_test(size_t num_bytes, size_t slice_size) {
create_sockets(sv);
- ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size, "test");
+ grpc_resource_quota *resource_quota = grpc_resource_quota_create("read_test");
+ ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), resource_quota,
+ slice_size, "test");
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset);
written_bytes = fill_socket_partial(sv[0], num_bytes);
@@ -223,8 +231,11 @@ static void large_read_test(size_t slice_size) {
create_sockets(sv);
- ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), slice_size,
- "test");
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("large_read_test");
+ ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), resource_quota,
+ slice_size, "test");
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset);
written_bytes = fill_socket(sv[0]);
@@ -359,8 +370,11 @@ static void write_test(size_t num_bytes, size_t slice_size) {
create_sockets(sv);
- ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"),
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("write_test");
+ ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), resource_quota,
GRPC_TCP_DEFAULT_READ_SLICE_SIZE, "test");
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset);
state.ep = ep;
@@ -423,8 +437,12 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
create_sockets(sv);
- ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size, "test");
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("release_fd_test");
+ ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), resource_quota,
+ slice_size, "test");
GPR_ASSERT(grpc_tcp_fd(ep) == sv[1] && sv[1] >= 0);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset);
written_bytes = fill_socket_partial(sv[0], num_bytes);
@@ -445,8 +463,10 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
"pollset_work",
grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ gpr_log(GPR_DEBUG, "wakeup: read=%" PRIdPTR " target=%" PRIdPTR,
+ state.read_bytes, state.target_read_bytes);
gpr_mu_unlock(g_mu);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
}
GPR_ASSERT(state.read_bytes == state.target_read_bytes);
@@ -454,6 +474,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
gpr_slice_buffer_destroy(&state.incoming);
grpc_tcp_destroy_and_release_fd(&exec_ctx, ep, &fd, &fd_released_cb);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
while (!fd_released_done) {
grpc_pollset_worker *worker = NULL;
@@ -461,6 +482,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
"pollset_work",
grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ gpr_log(GPR_DEBUG, "wakeup: fd_released_done=%d", fd_released_done);
}
gpr_mu_unlock(g_mu);
GPR_ASSERT(fd_released_done == 1);
@@ -506,10 +528,13 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair(
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
create_sockets(sv);
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("tcp_posix_test_socketpair");
f.client_ep = grpc_tcp_create(grpc_fd_create(sv[0], "fixture:client"),
- slice_size, "test");
+ resource_quota, slice_size, "test");
f.server_ep = grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"),
- slice_size, "test");
+ resource_quota, slice_size, "test");
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset);
grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset);
@@ -544,3 +569,9 @@ int main(int argc, char **argv) {
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 5791f562e1..1b8a39c1be 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/tcp_server.h"
#include <errno.h>
@@ -46,6 +51,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/iomgr/iomgr.h"
+#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@@ -132,7 +138,8 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
static void test_no_op(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_tcp_server *s;
- GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
+ GPR_ASSERT(GRPC_ERROR_NONE ==
+ grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s));
grpc_tcp_server_unref(&exec_ctx, s);
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -140,7 +147,8 @@ static void test_no_op(void) {
static void test_no_op_with_start(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_tcp_server *s;
- GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
+ GPR_ASSERT(GRPC_ERROR_NONE ==
+ grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s));
LOG_TEST("test_no_op_with_start");
grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL);
grpc_tcp_server_unref(&exec_ctx, s);
@@ -149,16 +157,19 @@ static void test_no_op_with_start(void) {
static void test_no_op_with_port(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_tcp_server *s;
- GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
+ GPR_ASSERT(GRPC_ERROR_NONE ==
+ grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s));
LOG_TEST("test_no_op_with_port");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
int port;
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
- &port) == GRPC_ERROR_NONE &&
+ GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr, &port) ==
+ GRPC_ERROR_NONE &&
port > 0);
grpc_tcp_server_unref(&exec_ctx, s);
@@ -167,16 +178,19 @@ static void test_no_op_with_port(void) {
static void test_no_op_with_port_and_start(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_tcp_server *s;
- GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
+ GPR_ASSERT(GRPC_ERROR_NONE ==
+ grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s));
LOG_TEST("test_no_op_with_port_and_start");
int port;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
- &port) == GRPC_ERROR_NONE &&
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
+ GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr, &port) ==
+ GRPC_ERROR_NONE &&
port > 0);
grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL);
@@ -221,33 +235,37 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote,
the same port should be tested. */
static void test_connect(unsigned n) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_storage addr;
- struct sockaddr_storage addr1;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ grpc_resolved_address resolved_addr1;
+ struct sockaddr_storage *addr = (struct sockaddr_storage *)resolved_addr.addr;
+ struct sockaddr_storage *addr1 =
+ (struct sockaddr_storage *)resolved_addr1.addr;
unsigned svr_fd_count;
int svr_port;
unsigned svr1_fd_count;
int svr1_port;
grpc_tcp_server *s;
- GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
+ GPR_ASSERT(GRPC_ERROR_NONE ==
+ grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s));
unsigned i;
server_weak_ref weak_ref;
server_weak_ref_init(&weak_ref);
LOG_TEST("test_connect");
gpr_log(GPR_INFO, "clients=%d", n);
- memset(&addr, 0, sizeof(addr));
- memset(&addr1, 0, sizeof(addr1));
- addr.ss_family = addr1.ss_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ memset(&resolved_addr1, 0, sizeof(resolved_addr1));
+ resolved_addr.len = sizeof(struct sockaddr_storage);
+ resolved_addr1.len = sizeof(struct sockaddr_storage);
+ addr->ss_family = addr1->ss_family = AF_INET;
GPR_ASSERT(GRPC_ERROR_NONE ==
- grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len,
- &svr_port));
+ grpc_tcp_server_add_port(s, &resolved_addr, &svr_port));
GPR_ASSERT(svr_port > 0);
/* Cannot use wildcard (port==0), because add_port() will try to reuse the
same port as a previous add_port(). */
svr1_port = grpc_pick_unused_port_or_die();
- grpc_sockaddr_set_port((struct sockaddr *)&addr1, svr1_port);
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr1, addr_len,
- &svr_port) == GRPC_ERROR_NONE &&
+ grpc_sockaddr_set_port(&resolved_addr1, svr1_port);
+ GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr1, &svr_port) ==
+ GRPC_ERROR_NONE &&
svr_port == svr1_port);
/* Bad port_index. */
@@ -268,16 +286,18 @@ static void test_connect(unsigned n) {
int fd = grpc_tcp_server_port_fd(s, 0, i);
GPR_ASSERT(fd >= 0);
if (i == 0) {
- GPR_ASSERT(getsockname(fd, (struct sockaddr *)&addr, &addr_len) == 0);
- GPR_ASSERT(addr_len <= sizeof(addr));
+ GPR_ASSERT(getsockname(fd, (struct sockaddr *)addr,
+ (socklen_t *)&resolved_addr.len) == 0);
+ GPR_ASSERT(resolved_addr.len <= sizeof(*addr));
}
}
for (i = 0; i < svr1_fd_count; ++i) {
int fd = grpc_tcp_server_port_fd(s, 1, i);
GPR_ASSERT(fd >= 0);
if (i == 0) {
- GPR_ASSERT(getsockname(fd, (struct sockaddr *)&addr1, &addr_len) == 0);
- GPR_ASSERT(addr_len <= sizeof(addr1));
+ GPR_ASSERT(getsockname(fd, (struct sockaddr *)addr1,
+ (socklen_t *)&resolved_addr1.len) == 0);
+ GPR_ASSERT(resolved_addr1.len <= sizeof(*addr1));
}
}
@@ -287,7 +307,8 @@ static void test_connect(unsigned n) {
on_connect_result result;
int svr_fd;
on_connect_result_init(&result);
- tcp_connect(&exec_ctx, (struct sockaddr *)&addr, addr_len, &result);
+ tcp_connect(&exec_ctx, (struct sockaddr *)addr,
+ (socklen_t)resolved_addr.len, &result);
GPR_ASSERT(result.server_fd >= 0);
svr_fd = result.server_fd;
GPR_ASSERT(grpc_tcp_server_port_fd(s, result.port_index, result.fd_index) ==
@@ -301,7 +322,8 @@ static void test_connect(unsigned n) {
grpc_tcp_server_unref(&exec_ctx, result.server);
on_connect_result_init(&result);
- tcp_connect(&exec_ctx, (struct sockaddr *)&addr1, addr_len, &result);
+ tcp_connect(&exec_ctx, (struct sockaddr *)addr1,
+ (socklen_t)resolved_addr1.len, &result);
GPR_ASSERT(result.server_fd >= 0);
GPR_ASSERT(result.server_fd != svr_fd);
GPR_ASSERT(grpc_tcp_server_port_fd(s, result.port_index, result.fd_index) ==
@@ -350,3 +372,9 @@ int main(int argc, char **argv) {
gpr_free(g_pollset);
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/timer_heap_test.c b/test/core/iomgr/timer_heap_test.c
index d1cb0047f2..410d972313 100644
--- a/test/core/iomgr/timer_heap_test.c
+++ b/test/core/iomgr/timer_heap_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test only works with the generic timer implementation
+#ifdef GRPC_TIMER_USE_GENERIC
+
#include "src/core/lib/iomgr/timer_heap.h"
#include <stdlib.h>
@@ -315,3 +320,9 @@ int main(int argc, char **argv) {
return 0;
}
+
+#else /* GRPC_TIMER_USE_GENERIC */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_TIMER_USE_GENERIC */
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index 71d2fb5bd4..9bea229466 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/udp_server.h"
#include <netinet/in.h>
@@ -98,14 +103,16 @@ static void test_no_op_with_start(void) {
static void test_no_op_with_port(void) {
g_number_of_orphan_calls = 0;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_udp_server *s = grpc_udp_server_create();
LOG_TEST("test_no_op_with_port");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
- on_read, on_fd_orphaned));
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
+ GPR_ASSERT(
+ grpc_udp_server_add_port(s, &resolved_addr, on_read, on_fd_orphaned));
grpc_udp_server_destroy(&exec_ctx, s, NULL);
grpc_exec_ctx_finish(&exec_ctx);
@@ -117,14 +124,16 @@ static void test_no_op_with_port(void) {
static void test_no_op_with_port_and_start(void) {
g_number_of_orphan_calls = 0;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_udp_server *s = grpc_udp_server_create();
LOG_TEST("test_no_op_with_port_and_start");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
- on_read, on_fd_orphaned));
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
+ GPR_ASSERT(
+ grpc_udp_server_add_port(s, &resolved_addr, on_read, on_fd_orphaned));
grpc_udp_server_start(&exec_ctx, s, NULL, 0, NULL);
@@ -138,8 +147,8 @@ static void test_no_op_with_port_and_start(void) {
static void test_receive(int number_of_clients) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_storage addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_storage *addr = (struct sockaddr_storage *)resolved_addr.addr;
int clifd, svrfd;
grpc_udp_server *s = grpc_udp_server_create();
int i;
@@ -152,15 +161,17 @@ static void test_receive(int number_of_clients) {
g_number_of_bytes_read = 0;
g_number_of_orphan_calls = 0;
- memset(&addr, 0, sizeof(addr));
- addr.ss_family = AF_INET;
- GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, addr_len,
- on_read, on_fd_orphaned));
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_storage);
+ addr->ss_family = AF_INET;
+ GPR_ASSERT(
+ grpc_udp_server_add_port(s, &resolved_addr, on_read, on_fd_orphaned));
svrfd = grpc_udp_server_get_fd(s, 0);
GPR_ASSERT(svrfd >= 0);
- GPR_ASSERT(getsockname(svrfd, (struct sockaddr *)&addr, &addr_len) == 0);
- GPR_ASSERT(addr_len <= sizeof(addr));
+ GPR_ASSERT(getsockname(svrfd, (struct sockaddr *)addr,
+ (socklen_t *)&resolved_addr.len) == 0);
+ GPR_ASSERT(resolved_addr.len <= sizeof(struct sockaddr_storage));
pollsets[0] = g_pollset;
grpc_udp_server_start(&exec_ctx, s, pollsets, 1, NULL);
@@ -172,9 +183,10 @@ static void test_receive(int number_of_clients) {
number_of_reads_before = g_number_of_reads;
/* Create a socket, send a packet to the UDP server. */
- clifd = socket(addr.ss_family, SOCK_DGRAM, 0);
+ clifd = socket(addr->ss_family, SOCK_DGRAM, 0);
GPR_ASSERT(clifd >= 0);
- GPR_ASSERT(connect(clifd, (struct sockaddr *)&addr, addr_len) == 0);
+ GPR_ASSERT(connect(clifd, (struct sockaddr *)addr,
+ (socklen_t)resolved_addr.len) == 0);
GPR_ASSERT(5 == write(clifd, "hello", 5));
while (g_number_of_reads == number_of_reads_before &&
gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
@@ -229,3 +241,9 @@ int main(int argc, char **argv) {
grpc_iomgr_shutdown();
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/wakeup_fd_cv_test.c b/test/core/iomgr/wakeup_fd_cv_test.c
index 952985ed7e..82452d2157 100644
--- a/test/core/iomgr/wakeup_fd_cv_test.c
+++ b/test/core/iomgr/wakeup_fd_cv_test.c
@@ -31,6 +31,10 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_POSIX_SOCKET
+
#include <pthread.h>
#include <grpc/support/log.h>
@@ -238,3 +242,9 @@ int main(int argc, char **argv) {
grpc_iomgr_platform_shutdown();
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c
index 2f8ffe4da6..b74baa33f1 100644
--- a/test/core/security/credentials_test.c
+++ b/test/core/security/credentials_test.c
@@ -1125,28 +1125,19 @@ static void test_metadata_plugin_failure(void) {
}
static void test_get_well_known_google_credentials_file_path(void) {
-#ifdef GPR_POSIX_FILE
char *path;
- char *old_home = gpr_getenv("HOME");
- gpr_setenv("HOME", "/tmp");
+ char *home = gpr_getenv("HOME");
path = grpc_get_well_known_google_credentials_file_path();
GPR_ASSERT(path != NULL);
- GPR_ASSERT(0 == strcmp("/tmp/.config/" GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY
- "/" GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE,
- path));
gpr_free(path);
#if defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV)
unsetenv("HOME");
path = grpc_get_well_known_google_credentials_file_path();
GPR_ASSERT(path == NULL);
-#endif /* GPR_POSIX_ENV || GPR_LINUX_ENV */
- gpr_setenv("HOME", old_home);
- gpr_free(old_home);
-#else /* GPR_POSIX_FILE */
- char *path = grpc_get_well_known_google_credentials_file_path();
- GPR_ASSERT(path != NULL);
+ gpr_setenv("HOME", home);
gpr_free(path);
-#endif
+#endif /* GPR_POSIX_ENV || GPR_LINUX_ENV */
+ gpr_free(home);
}
static void test_channel_creds_duplicate_without_call_creds(void) {
diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c
index 1d2bf73bb1..2262fde98d 100644
--- a/test/core/security/secure_endpoint_test.c
+++ b/test/core/security/secure_endpoint_test.c
@@ -56,7 +56,10 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
grpc_endpoint_test_fixture f;
grpc_endpoint_pair tcp;
- tcp = grpc_iomgr_create_endpoint_pair("fixture", slice_size);
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("secure_endpoint_test");
+ tcp = grpc_iomgr_create_endpoint_pair("fixture", resource_quota, slice_size);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
grpc_endpoint_add_to_pollset(&exec_ctx, tcp.client, g_pollset);
grpc_endpoint_add_to_pollset(&exec_ctx, tcp.server, g_pollset);
diff --git a/test/core/surface/channel_create_test.c b/test/core/surface/channel_create_test.c
index 580eb303f6..ad7970aab9 100644
--- a/test/core/surface/channel_create_test.c
+++ b/test/core/surface/channel_create_test.c
@@ -33,7 +33,7 @@
#include <grpc/grpc.h>
#include <grpc/support/log.h>
-#include "src/core/ext/client_config/resolver_registry.h"
+#include "src/core/ext/client_channel/resolver_registry.h"
#include "test/core/util/test_config.h"
void test_unknown_scheme_target(void) {
diff --git a/test/core/surface/concurrent_connectivity_test.c b/test/core/surface/concurrent_connectivity_test.c
index f7567f350d..f9f4675454 100644
--- a/test/core/surface/concurrent_connectivity_test.c
+++ b/test/core/surface/concurrent_connectivity_test.c
@@ -31,6 +31,12 @@
*
*/
+/* With the addition of a libuv endpoint, sockaddr.h now includes uv.h when
+ using that endpoint. Because of various transitive includes in uv.h,
+ including windows.h on Windows, uv.h must be included before other system
+ headers. Therefore, sockaddr.h must always be included first */
+#include "src/core/lib/iomgr/sockaddr.h"
+
#include <memory.h>
#include <stdio.h>
@@ -42,6 +48,7 @@
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr.h"
+#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/iomgr/tcp_server.h"
@@ -109,16 +116,15 @@ void bad_server_thread(void *vargs) {
struct server_thread_args *args = (struct server_thread_args *)vargs;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_storage addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_storage *addr = (struct sockaddr_storage *)resolved_addr.addr;
int port;
grpc_tcp_server *s;
- grpc_error *error = grpc_tcp_server_create(NULL, NULL, &s);
+ grpc_error *error = grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s);
GPR_ASSERT(error == GRPC_ERROR_NONE);
- memset(&addr, 0, sizeof(addr));
- addr.ss_family = AF_INET;
- error =
- grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len, &port);
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ addr->ss_family = AF_INET;
+ error = grpc_tcp_server_add_port(s, &resolved_addr, &port);
GPR_ASSERT(GRPC_LOG_IF_ERROR("grpc_tcp_server_add_port", error));
GPR_ASSERT(port > 0);
gpr_asprintf(&args->addr, "localhost:%d", port);
diff --git a/test/core/surface/secure_channel_create_test.c b/test/core/surface/secure_channel_create_test.c
index f8a9a64211..444ebdc093 100644
--- a/test/core/surface/secure_channel_create_test.c
+++ b/test/core/surface/secure_channel_create_test.c
@@ -36,7 +36,7 @@
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
-#include "src/core/ext/client_config/resolver_registry.h"
+#include "src/core/ext/client_channel/resolver_registry.h"
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "src/core/lib/security/transport/security_connector.h"
#include "src/core/lib/surface/channel.h"
diff --git a/test/core/transport/chttp2/alpn_test.c b/test/core/transport/chttp2/alpn_test.c
index 48064ec9b3..cde891cd5d 100644
--- a/test/core/transport/chttp2/alpn_test.c
+++ b/test/core/transport/chttp2/alpn_test.c
@@ -38,6 +38,7 @@
static void test_alpn_success(void) {
GPR_ASSERT(grpc_chttp2_is_alpn_version_supported("h2", 2));
+ GPR_ASSERT(grpc_chttp2_is_alpn_version_supported("grpc-exp", 8));
}
static void test_alpn_failure(void) {
@@ -45,9 +46,27 @@ static void test_alpn_failure(void) {
GPR_ASSERT(!grpc_chttp2_is_alpn_version_supported("h1-15", 5));
}
+// First index in ALPN supported version list of a given protocol. Returns a
+// value one beyond the last valid element index if not found.
+static size_t alpn_version_index(const char *version, size_t size) {
+ size_t i;
+ for (i = 0; i < grpc_chttp2_num_alpn_versions(); ++i) {
+ if (!strncmp(version, grpc_chttp2_get_alpn_version_index(i), size)) {
+ return i;
+ }
+ }
+ return i;
+}
+
+static void test_alpn_grpc_before_h2(void) {
+ // grpc-exp is preferred over h2.
+ GPR_ASSERT(alpn_version_index("grpc-exp", 8) < alpn_version_index("h2", 2));
+}
+
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
test_alpn_success();
test_alpn_failure();
+ test_alpn_grpc_before_h2();
return 0;
}
diff --git a/test/core/util/mock_endpoint.c b/test/core/util/mock_endpoint.c
index 13e0e918fb..2b041a4484 100644
--- a/test/core/util/mock_endpoint.c
+++ b/test/core/util/mock_endpoint.c
@@ -33,16 +33,20 @@
#include "test/core/util/mock_endpoint.h"
+#include <inttypes.h>
+
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
typedef struct grpc_mock_endpoint {
grpc_endpoint base;
gpr_mu mu;
+ int refs;
void (*on_write)(gpr_slice slice);
gpr_slice_buffer read_buffer;
gpr_slice_buffer *on_read_out;
grpc_closure *on_read;
+ grpc_resource_user resource_user;
} grpc_mock_endpoint;
static void me_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
@@ -74,6 +78,24 @@ static void me_add_to_pollset(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
static void me_add_to_pollset_set(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
grpc_pollset_set *pollset) {}
+static void unref(grpc_exec_ctx *exec_ctx, grpc_mock_endpoint *m) {
+ gpr_mu_lock(&m->mu);
+ if (0 == --m->refs) {
+ gpr_mu_unlock(&m->mu);
+ gpr_slice_buffer_destroy(&m->read_buffer);
+ grpc_resource_user_destroy(exec_ctx, &m->resource_user);
+ gpr_free(m);
+ } else {
+ gpr_mu_unlock(&m->mu);
+ }
+}
+
+static void me_finish_shutdown(grpc_exec_ctx *exec_ctx, void *me,
+ grpc_error *error) {
+ grpc_mock_endpoint *m = me;
+ unref(exec_ctx, m);
+}
+
static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep;
gpr_mu_lock(&m->mu);
@@ -82,19 +104,25 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
GRPC_ERROR_CREATE("Endpoint Shutdown"), NULL);
m->on_read = NULL;
}
+ grpc_resource_user_shutdown(exec_ctx, &m->resource_user,
+ grpc_closure_create(me_finish_shutdown, m));
gpr_mu_unlock(&m->mu);
}
static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep;
- gpr_slice_buffer_destroy(&m->read_buffer);
- gpr_free(m);
+ unref(exec_ctx, m);
}
static char *me_get_peer(grpc_endpoint *ep) {
return gpr_strdup("fake:mock_endpoint");
}
+static grpc_resource_user *me_get_resource_user(grpc_endpoint *ep) {
+ grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep;
+ return &m->resource_user;
+}
+
static grpc_workqueue *me_get_workqueue(grpc_endpoint *ep) { return NULL; }
static const grpc_endpoint_vtable vtable = {
@@ -105,12 +133,19 @@ static const grpc_endpoint_vtable vtable = {
me_add_to_pollset_set,
me_shutdown,
me_destroy,
+ me_get_resource_user,
me_get_peer,
};
-grpc_endpoint *grpc_mock_endpoint_create(void (*on_write)(gpr_slice slice)) {
+grpc_endpoint *grpc_mock_endpoint_create(void (*on_write)(gpr_slice slice),
+ grpc_resource_quota *resource_quota) {
grpc_mock_endpoint *m = gpr_malloc(sizeof(*m));
m->base.vtable = &vtable;
+ m->refs = 2;
+ char *name;
+ gpr_asprintf(&name, "mock_endpoint_%" PRIxPTR, (intptr_t)m);
+ grpc_resource_user_init(&m->resource_user, resource_quota, name);
+ gpr_free(name);
gpr_slice_buffer_init(&m->read_buffer);
gpr_mu_init(&m->mu);
m->on_write = on_write;
diff --git a/test/core/util/mock_endpoint.h b/test/core/util/mock_endpoint.h
index 051af9866b..b3a464ca01 100644
--- a/test/core/util/mock_endpoint.h
+++ b/test/core/util/mock_endpoint.h
@@ -36,7 +36,8 @@
#include "src/core/lib/iomgr/endpoint.h"
-grpc_endpoint *grpc_mock_endpoint_create(void (*on_write)(gpr_slice slice));
+grpc_endpoint *grpc_mock_endpoint_create(void (*on_write)(gpr_slice slice),
+ grpc_resource_quota *resource_quota);
void grpc_mock_endpoint_put_read(grpc_exec_ctx *exec_ctx,
grpc_endpoint *mock_endpoint, gpr_slice slice);
diff --git a/test/core/util/passthru_endpoint.c b/test/core/util/passthru_endpoint.c
index 7ed9e97bd6..ee6ef7da60 100644
--- a/test/core/util/passthru_endpoint.c
+++ b/test/core/util/passthru_endpoint.c
@@ -33,6 +33,8 @@
#include "test/core/util/passthru_endpoint.h"
+#include <inttypes.h>
+
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
@@ -44,6 +46,7 @@ typedef struct {
gpr_slice_buffer read_buffer;
gpr_slice_buffer *on_read_out;
grpc_closure *on_read;
+ grpc_resource_user resource_user;
} half;
struct passthru_endpoint {
@@ -122,7 +125,8 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
gpr_mu_unlock(&m->parent->mu);
}
-static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
+static void me_really_destroy(grpc_exec_ctx *exec_ctx, void *ep,
+ grpc_error *error) {
passthru_endpoint *p = ((half *)ep)->parent;
gpr_mu_lock(&p->mu);
if (0 == --p->halves) {
@@ -136,12 +140,23 @@ static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
}
}
+static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
+ half *m = (half *)ep;
+ grpc_resource_user_shutdown(exec_ctx, &m->resource_user,
+ grpc_closure_create(me_really_destroy, m));
+}
+
static char *me_get_peer(grpc_endpoint *ep) {
return gpr_strdup("fake:mock_endpoint");
}
static grpc_workqueue *me_get_workqueue(grpc_endpoint *ep) { return NULL; }
+static grpc_resource_user *me_get_resource_user(grpc_endpoint *ep) {
+ half *m = (half *)ep;
+ return &m->resource_user;
+}
+
static const grpc_endpoint_vtable vtable = {
me_read,
me_write,
@@ -150,23 +165,32 @@ static const grpc_endpoint_vtable vtable = {
me_add_to_pollset_set,
me_shutdown,
me_destroy,
+ me_get_resource_user,
me_get_peer,
};
-static void half_init(half *m, passthru_endpoint *parent) {
+static void half_init(half *m, passthru_endpoint *parent,
+ grpc_resource_quota *resource_quota,
+ const char *half_name) {
m->base.vtable = &vtable;
m->parent = parent;
gpr_slice_buffer_init(&m->read_buffer);
m->on_read = NULL;
+ char *name;
+ gpr_asprintf(&name, "passthru_endpoint_%s_%" PRIxPTR, half_name,
+ (intptr_t)parent);
+ grpc_resource_user_init(&m->resource_user, resource_quota, name);
+ gpr_free(name);
}
void grpc_passthru_endpoint_create(grpc_endpoint **client,
- grpc_endpoint **server) {
+ grpc_endpoint **server,
+ grpc_resource_quota *resource_quota) {
passthru_endpoint *m = gpr_malloc(sizeof(*m));
m->halves = 2;
m->shutdown = 0;
- half_init(&m->client, m);
- half_init(&m->server, m);
+ half_init(&m->client, m, resource_quota, "client");
+ half_init(&m->server, m, resource_quota, "server");
gpr_mu_init(&m->mu);
*client = &m->client.base;
*server = &m->server.base;
diff --git a/test/core/util/passthru_endpoint.h b/test/core/util/passthru_endpoint.h
index aa1d3a1763..b81ac5571c 100644
--- a/test/core/util/passthru_endpoint.h
+++ b/test/core/util/passthru_endpoint.h
@@ -37,6 +37,7 @@
#include "src/core/lib/iomgr/endpoint.h"
void grpc_passthru_endpoint_create(grpc_endpoint **client,
- grpc_endpoint **server);
+ grpc_endpoint **server,
+ grpc_resource_quota *resource_quota);
#endif
diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c
index 265e0acee1..60537b4946 100644
--- a/test/core/util/port_posix.c
+++ b/test/core/util/port_posix.c
@@ -31,9 +31,9 @@
*
*/
-#include <grpc/support/port_platform.h>
+#include "src/core/lib/iomgr/port.h"
#include "test/core/util/test_config.h"
-#if defined(GPR_POSIX_SOCKET) && defined(GRPC_TEST_PICK_PORT)
+#if defined(GRPC_POSIX_SOCKET) && defined(GRPC_TEST_PICK_PORT)
#include "test/core/util/port.h"
@@ -237,4 +237,4 @@ int grpc_pick_unused_port_or_die(void) {
void grpc_recycle_unused_port(int port) { GPR_ASSERT(free_chosen_port(port)); }
-#endif /* GPR_POSIX_SOCKET && GRPC_TEST_PICK_PORT */
+#endif /* GRPC_POSIX_SOCKET && GRPC_TEST_PICK_PORT */
diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c
index a5c8c49650..b2342feeb4 100644
--- a/test/core/util/port_server_client.c
+++ b/test/core/util/port_server_client.c
@@ -99,9 +99,12 @@ void grpc_free_port_using_server(char *server, int port) {
req.http.path = path;
grpc_httpcli_context_init(&context);
- grpc_httpcli_get(&exec_ctx, &context, &pr.pops, &req,
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("port_server_client/free");
+ grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req,
GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10),
grpc_closure_create(freed_port_from_server, &pr), &rsp);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
gpr_mu_lock(pr.mu);
while (!pr.done) {
grpc_pollset_worker *worker = NULL;
@@ -167,10 +170,13 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
req.http.path = "/get";
grpc_http_response_destroy(&pr->response);
memset(&pr->response, 0, sizeof(pr->response));
- grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pops, &req,
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("port_server_client/pick_retry");
+ grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pops, resource_quota, &req,
GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10),
grpc_closure_create(got_port_from_server, pr),
&pr->response);
+ grpc_resource_quota_internal_unref(exec_ctx, resource_quota);
return;
}
GPR_ASSERT(response);
@@ -211,9 +217,13 @@ int grpc_pick_port_using_server(char *server) {
req.http.path = "/get";
grpc_httpcli_context_init(&context);
- grpc_httpcli_get(
- &exec_ctx, &context, &pr.pops, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10),
- grpc_closure_create(got_port_from_server, &pr), &pr.response);
+ grpc_resource_quota *resource_quota =
+ grpc_resource_quota_create("port_server_client/pick");
+ grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req,
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10),
+ grpc_closure_create(got_port_from_server, &pr),
+ &pr.response);
+ grpc_resource_quota_internal_unref(&exec_ctx, resource_quota);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(pr.mu);
while (pr.port == -1) {
diff --git a/test/core/util/port_uv.c b/test/core/util/port_uv.c
new file mode 100644
index 0000000000..0c9c0d87d6
--- /dev/null
+++ b/test/core/util/port_uv.c
@@ -0,0 +1,117 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "src/core/lib/iomgr/port.h"
+#include "test/core/util/test_config.h"
+#if defined(GRPC_UV) && defined(GRPC_TEST_PICK_PORT)
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+
+#include "src/core/lib/support/env.h"
+#include "test/core/util/port.h"
+#include "test/core/util/port_server_client.h"
+
+// Almost everything in this file has been copied from port_posix.c
+
+static int *chosen_ports = NULL;
+static size_t num_chosen_ports = 0;
+
+static int free_chosen_port(int port) {
+ size_t i;
+ int found = 0;
+ size_t found_at = 0;
+ char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
+ /* Find the port and erase it from the list, then tell the server it can be
+ freed. */
+ for (i = 0; i < num_chosen_ports; i++) {
+ if (chosen_ports[i] == port) {
+ GPR_ASSERT(found == 0);
+ found = 1;
+ found_at = i;
+ }
+ }
+ if (found) {
+ chosen_ports[found_at] = chosen_ports[num_chosen_ports - 1];
+ num_chosen_ports--;
+ if (env) {
+ grpc_free_port_using_server(env, port);
+ }
+ }
+ gpr_free(env);
+ return found;
+}
+
+static void free_chosen_ports(void) {
+ char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
+ if (env != NULL) {
+ size_t i;
+ for (i = 0; i < num_chosen_ports; i++) {
+ grpc_free_port_using_server(env, chosen_ports[i]);
+ }
+ gpr_free(env);
+ }
+
+ gpr_free(chosen_ports);
+}
+
+static void chose_port(int port) {
+ if (chosen_ports == NULL) {
+ atexit(free_chosen_ports);
+ }
+ num_chosen_ports++;
+ chosen_ports = gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports);
+ chosen_ports[num_chosen_ports - 1] = port;
+}
+
+int grpc_pick_unused_port(void) {
+ // Currently only works with the port server
+ char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
+ GPR_ASSERT(env);
+ int port = grpc_pick_port_using_server(env);
+ gpr_free(env);
+ if (port != 0) {
+ chose_port(port);
+ }
+ return port;
+}
+
+int grpc_pick_unused_port_or_die(void) {
+ int port = grpc_pick_unused_port();
+ GPR_ASSERT(port > 0);
+ return port;
+}
+
+void grpc_recycle_unused_port(int port) { GPR_ASSERT(free_chosen_port(port)); }
+
+#endif /* GRPC_UV && GRPC_TEST_PICK_PORT */
diff --git a/test/core/util/port_windows.c b/test/core/util/port_windows.c
index 9023719675..0c50a46644 100644
--- a/test/core/util/port_windows.c
+++ b/test/core/util/port_windows.c
@@ -31,9 +31,11 @@
*
*/
-#include <grpc/support/port_platform.h>
+#include "src/core/lib/iomgr/port.h"
#include "test/core/util/test_config.h"
-#if defined(GPR_WINSOCK_SOCKET) && defined(GRPC_TEST_PICK_PORT)
+#if defined(GRPC_WINSOCK_SOCKET) && defined(GRPC_TEST_PICK_PORT)
+
+#include "src/core/lib/iomgr/sockaddr.h"
#include "test/core/util/port.h"
@@ -242,4 +244,4 @@ int grpc_pick_unused_port_or_die(void) {
void grpc_recycle_unused_port(int port) { GPR_ASSERT(free_chosen_port(port)); }
-#endif /* GPR_WINSOCK_SOCKET && GRPC_TEST_PICK_PORT */
+#endif /* GRPC_WINSOCK_SOCKET && GRPC_TEST_PICK_PORT */
diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c
index 8a0b3932d8..16df91d968 100644
--- a/test/core/util/test_tcp_server.c
+++ b/test/core/util/test_tcp_server.c
@@ -31,6 +31,8 @@
*
*/
+#include "src/core/lib/iomgr/sockaddr.h"
+
#include "test/core/util/test_tcp_server.h"
#include <grpc/grpc.h>
@@ -41,7 +43,7 @@
#include <grpc/support/time.h>
#include <string.h>
#include "src/core/lib/iomgr/endpoint.h"
-#include "src/core/lib/iomgr/sockaddr.h"
+#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/tcp_server.h"
#include "test/core/util/port.h"
@@ -64,19 +66,20 @@ void test_tcp_server_init(test_tcp_server *server,
}
void test_tcp_server_start(test_tcp_server *server, int port) {
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
int port_added;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- addr.sin_family = AF_INET;
- addr.sin_port = htons((uint16_t)port);
- memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
+ addr->sin_family = AF_INET;
+ addr->sin_port = htons((uint16_t)port);
+ memset(&addr->sin_addr, 0, sizeof(addr->sin_addr));
- grpc_error *error = grpc_tcp_server_create(&server->shutdown_complete, NULL,
- &server->tcp_server);
+ grpc_error *error = grpc_tcp_server_create(
+ &exec_ctx, &server->shutdown_complete, NULL, &server->tcp_server);
GPR_ASSERT(error == GRPC_ERROR_NONE);
- error = grpc_tcp_server_add_port(server->tcp_server, &addr, sizeof(addr),
- &port_added);
+ error =
+ grpc_tcp_server_add_port(server->tcp_server, &resolved_addr, &port_added);
GPR_ASSERT(error == GRPC_ERROR_NONE);
GPR_ASSERT(port_added == port);
diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden
index 7b0fd6ce80..5f0e824655 100644
--- a/test/cpp/codegen/compiler_test_golden
+++ b/test/cpp/codegen/compiler_test_golden
@@ -213,7 +213,7 @@ class ServiceA GRPC_FINAL {
void BaseClassMustBeDerivedFromService(const Service *service) {}
public:
WithStreamedUnaryMethod_MethodA1() {
- ::grpc::Service::MarkMethodStreamedUnary(0,
+ ::grpc::Service::MarkMethodStreamed(0,
new ::grpc::StreamedUnaryHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithStreamedUnaryMethod_MethodA1<BaseClass>::StreamedMethodA1, this, std::placeholders::_1, std::placeholders::_2)));
}
~WithStreamedUnaryMethod_MethodA1() GRPC_OVERRIDE {
@@ -228,6 +228,8 @@ class ServiceA GRPC_FINAL {
virtual ::grpc::Status StreamedMethodA1(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_unary_streamer) = 0;
};
typedef WithStreamedUnaryMethod_MethodA1<Service > StreamedUnaryService;
+ typedef Service SplitStreamedService;
+ typedef WithStreamedUnaryMethod_MethodA1<Service > StreamedService;
};
// ServiceB leading comment 1
@@ -312,7 +314,7 @@ class ServiceB GRPC_FINAL {
void BaseClassMustBeDerivedFromService(const Service *service) {}
public:
WithStreamedUnaryMethod_MethodB1() {
- ::grpc::Service::MarkMethodStreamedUnary(0,
+ ::grpc::Service::MarkMethodStreamed(0,
new ::grpc::StreamedUnaryHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithStreamedUnaryMethod_MethodB1<BaseClass>::StreamedMethodB1, this, std::placeholders::_1, std::placeholders::_2)));
}
~WithStreamedUnaryMethod_MethodB1() GRPC_OVERRIDE {
@@ -327,6 +329,8 @@ class ServiceB GRPC_FINAL {
virtual ::grpc::Status StreamedMethodB1(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_unary_streamer) = 0;
};
typedef WithStreamedUnaryMethod_MethodB1<Service > StreamedUnaryService;
+ typedef Service SplitStreamedService;
+ typedef WithStreamedUnaryMethod_MethodB1<Service > StreamedService;
};
// ServiceB trailing comment 1
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index a9b7c8f8d3..823f0bd035 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -47,6 +47,7 @@
#include <grpc/support/tls.h>
#include <gtest/gtest.h>
+#include "src/core/lib/iomgr/port.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"
@@ -54,7 +55,7 @@
#include "test/cpp/util/string_ref_helper.h"
#include "test/cpp/util/test_credentials_provider.h"
-#ifdef GPR_POSIX_SOCKET
+#ifdef GRPC_POSIX_SOCKET
#include "src/core/lib/iomgr/ev_posix.h"
#endif
@@ -73,7 +74,7 @@ namespace {
void* tag(int i) { return (void*)(intptr_t)i; }
int detag(void* p) { return static_cast<int>(reinterpret_cast<intptr_t>(p)); }
-#ifdef GPR_POSIX_SOCKET
+#ifdef GRPC_POSIX_SOCKET
static int maybe_assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds,
int timeout) {
if (gpr_tls_get(&g_is_async_end2end_test)) {
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index b1d3ce92f6..feadabd865 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -37,6 +37,7 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
+#include <grpc++/resource_quota.h>
#include <grpc++/security/auth_metadata_processor.h>
#include <grpc++/security/credentials.h>
#include <grpc++/security/server_credentials.h>
@@ -240,6 +241,7 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> {
server_address_ << "127.0.0.1:" << port;
// Setup server
ServerBuilder builder;
+ ConfigureServerBuilder(&builder);
auto server_creds = GetServerCredentials(GetParam().credentials_type);
if (GetParam().credentials_type != kInsecureCredentialsType) {
server_creds->SetAuthMetadataProcessor(processor);
@@ -247,13 +249,16 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> {
builder.AddListeningPort(server_address_.str(), server_creds);
builder.RegisterService(&service_);
builder.RegisterService("foo.test.youtube.com", &special_service_);
- builder.SetMaxMessageSize(
- kMaxMessageSize_); // For testing max message size.
builder.RegisterService(&dup_pkg_service_);
server_ = builder.BuildAndStart();
is_server_started_ = true;
}
+ virtual void ConfigureServerBuilder(ServerBuilder* builder) {
+ builder->SetMaxMessageSize(
+ kMaxMessageSize_); // For testing max message size.
+ }
+
void ResetChannel() {
if (!is_server_started_) {
StartServer(std::shared_ptr<AuthMetadataProcessor>());
@@ -636,7 +641,7 @@ TEST_P(End2endTest, SimpleRpcWithCustomeUserAgentPrefix) {
auto iter = trailing_metadata.find("user-agent");
EXPECT_TRUE(iter != trailing_metadata.end());
grpc::string expected_prefix = user_agent_prefix_ + " grpc-c++/";
- EXPECT_TRUE(iter->second.starts_with(expected_prefix));
+ EXPECT_TRUE(iter->second.starts_with(expected_prefix)) << iter->second;
}
TEST_P(End2endTest, MultipleRpcsWithVariedBinaryMetadataValue) {
@@ -1476,6 +1481,32 @@ TEST_P(SecureEnd2endTest, ClientAuthContext) {
}
}
+class ResourceQuotaEnd2endTest : public End2endTest {
+ public:
+ ResourceQuotaEnd2endTest()
+ : server_resource_quota_("server_resource_quota") {}
+
+ virtual void ConfigureServerBuilder(ServerBuilder* builder) GRPC_OVERRIDE {
+ builder->SetResourceQuota(server_resource_quota_);
+ }
+
+ private:
+ ResourceQuota server_resource_quota_;
+};
+
+TEST_P(ResourceQuotaEnd2endTest, SimpleRequest) {
+ ResetStub();
+
+ EchoRequest request;
+ EchoResponse response;
+ request.set_message("Hello");
+
+ ClientContext context;
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(response.message(), request.message());
+ EXPECT_TRUE(s.ok());
+}
+
std::vector<TestScenario> CreateTestScenarios(bool use_proxy,
bool test_insecure,
bool test_secure) {
@@ -1513,6 +1544,10 @@ INSTANTIATE_TEST_CASE_P(SecureEnd2end, SecureEnd2endTest,
::testing::ValuesIn(CreateTestScenarios(false, false,
true)));
+INSTANTIATE_TEST_CASE_P(ResourceQuotaEnd2end, ResourceQuotaEnd2endTest,
+ ::testing::ValuesIn(CreateTestScenarios(false, true,
+ true)));
+
} // namespace
} // namespace testing
} // namespace grpc
diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc
index 8cd2e66347..76a5732f33 100644
--- a/test/cpp/end2end/hybrid_end2end_test.cc
+++ b/test/cpp/end2end/hybrid_end2end_test.cc
@@ -320,6 +320,29 @@ class HybridEnd2endTest : public ::testing::Test {
EXPECT_TRUE(s.ok());
}
+ void SendSimpleServerStreamingToDupService() {
+ std::shared_ptr<Channel> channel =
+ CreateChannel(server_address_.str(), InsecureChannelCredentials());
+ auto stub = grpc::testing::duplicate::EchoTestService::NewStub(channel);
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ context.set_wait_for_ready(true);
+ request.set_message("hello");
+
+ auto stream = stub->ResponseStream(&context, request);
+ EXPECT_TRUE(stream->Read(&response));
+ EXPECT_EQ(response.message(), request.message() + "0_dup");
+ EXPECT_TRUE(stream->Read(&response));
+ EXPECT_EQ(response.message(), request.message() + "1_dup");
+ EXPECT_TRUE(stream->Read(&response));
+ EXPECT_EQ(response.message(), request.message() + "2_dup");
+ EXPECT_FALSE(stream->Read(&response));
+
+ Status s = stream->Finish();
+ EXPECT_TRUE(s.ok());
+ }
+
void SendBidiStreaming() {
EchoRequest request;
EchoResponse response;
@@ -498,6 +521,140 @@ TEST_F(HybridEnd2endTest,
request_stream_handler_thread.join();
}
+// Add a second service with one sync split server streaming method.
+class SplitResponseStreamDupPkg
+ : public duplicate::EchoTestService::
+ WithSplitStreamingMethod_ResponseStream<TestServiceImplDupPkg> {
+ public:
+ Status StreamedResponseStream(
+ ServerContext* context,
+ ServerSplitStreamer<EchoRequest, EchoResponse>* stream) GRPC_OVERRIDE {
+ EchoRequest req;
+ EchoResponse resp;
+ uint32_t next_msg_sz;
+ stream->NextMessageSize(&next_msg_sz);
+ gpr_log(GPR_INFO, "Split Streamed Next Message Size is %u", next_msg_sz);
+ GPR_ASSERT(stream->Read(&req));
+ for (int i = 0; i < kNumResponseStreamsMsgs; i++) {
+ resp.set_message(req.message() + grpc::to_string(i) + "_dup");
+ GPR_ASSERT(stream->Write(resp));
+ }
+ return Status::OK;
+ }
+};
+
+TEST_F(HybridEnd2endTest,
+ AsyncRequestStreamResponseStream_SyncSplitStreamedDupService) {
+ typedef EchoTestService::WithAsyncMethod_RequestStream<
+ EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>>
+ SType;
+ SType service;
+ SplitResponseStreamDupPkg dup_service;
+ SetUpServer(&service, &dup_service, nullptr, 8192);
+ ResetStub();
+ std::thread response_stream_handler_thread(HandleServerStreaming<SType>,
+ &service, cqs_[0].get());
+ std::thread request_stream_handler_thread(HandleClientStreaming<SType>,
+ &service, cqs_[1].get());
+ TestAllMethods();
+ SendSimpleServerStreamingToDupService();
+ response_stream_handler_thread.join();
+ request_stream_handler_thread.join();
+}
+
+// Add a second service that is fully split server streamed
+class FullySplitStreamedDupPkg
+ : public duplicate::EchoTestService::SplitStreamedService {
+ public:
+ Status StreamedResponseStream(
+ ServerContext* context,
+ ServerSplitStreamer<EchoRequest, EchoResponse>* stream) GRPC_OVERRIDE {
+ EchoRequest req;
+ EchoResponse resp;
+ uint32_t next_msg_sz;
+ stream->NextMessageSize(&next_msg_sz);
+ gpr_log(GPR_INFO, "Split Streamed Next Message Size is %u", next_msg_sz);
+ GPR_ASSERT(stream->Read(&req));
+ for (int i = 0; i < kNumResponseStreamsMsgs; i++) {
+ resp.set_message(req.message() + grpc::to_string(i) + "_dup");
+ GPR_ASSERT(stream->Write(resp));
+ }
+ return Status::OK;
+ }
+};
+
+TEST_F(HybridEnd2endTest,
+ AsyncRequestStreamResponseStream_FullySplitStreamedDupService) {
+ typedef EchoTestService::WithAsyncMethod_RequestStream<
+ EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>>
+ SType;
+ SType service;
+ FullySplitStreamedDupPkg dup_service;
+ SetUpServer(&service, &dup_service, nullptr, 8192);
+ ResetStub();
+ std::thread response_stream_handler_thread(HandleServerStreaming<SType>,
+ &service, cqs_[0].get());
+ std::thread request_stream_handler_thread(HandleClientStreaming<SType>,
+ &service, cqs_[1].get());
+ TestAllMethods();
+ SendSimpleServerStreamingToDupService();
+ response_stream_handler_thread.join();
+ request_stream_handler_thread.join();
+}
+
+// Add a second service that is fully server streamed
+class FullyStreamedDupPkg : public duplicate::EchoTestService::StreamedService {
+ public:
+ Status StreamedEcho(ServerContext* context,
+ ServerUnaryStreamer<EchoRequest, EchoResponse>* stream)
+ GRPC_OVERRIDE {
+ EchoRequest req;
+ EchoResponse resp;
+ uint32_t next_msg_sz;
+ stream->NextMessageSize(&next_msg_sz);
+ gpr_log(GPR_INFO, "Streamed Unary Next Message Size is %u", next_msg_sz);
+ GPR_ASSERT(stream->Read(&req));
+ resp.set_message(req.message() + "_dup");
+ GPR_ASSERT(stream->Write(resp));
+ return Status::OK;
+ }
+ Status StreamedResponseStream(
+ ServerContext* context,
+ ServerSplitStreamer<EchoRequest, EchoResponse>* stream) GRPC_OVERRIDE {
+ EchoRequest req;
+ EchoResponse resp;
+ uint32_t next_msg_sz;
+ stream->NextMessageSize(&next_msg_sz);
+ gpr_log(GPR_INFO, "Split Streamed Next Message Size is %u", next_msg_sz);
+ GPR_ASSERT(stream->Read(&req));
+ for (int i = 0; i < kNumResponseStreamsMsgs; i++) {
+ resp.set_message(req.message() + grpc::to_string(i) + "_dup");
+ GPR_ASSERT(stream->Write(resp));
+ }
+ return Status::OK;
+ }
+};
+
+TEST_F(HybridEnd2endTest,
+ AsyncRequestStreamResponseStream_FullyStreamedDupService) {
+ typedef EchoTestService::WithAsyncMethod_RequestStream<
+ EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>>
+ SType;
+ SType service;
+ FullyStreamedDupPkg dup_service;
+ SetUpServer(&service, &dup_service, nullptr, 8192);
+ ResetStub();
+ std::thread response_stream_handler_thread(HandleServerStreaming<SType>,
+ &service, cqs_[0].get());
+ std::thread request_stream_handler_thread(HandleClientStreaming<SType>,
+ &service, cqs_[1].get());
+ TestAllMethods();
+ SendEchoToDupService();
+ SendSimpleServerStreamingToDupService();
+ response_stream_handler_thread.join();
+ request_stream_handler_thread.join();
+}
+
// Add a second service with one async method.
TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_AsyncDupService) {
typedef EchoTestService::WithAsyncMethod_RequestStream<
diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc
index 80f2fa4f4d..b6056f9ae4 100644
--- a/test/cpp/grpclb/grpclb_test.cc
+++ b/test/cpp/grpclb/grpclb_test.cc
@@ -51,7 +51,7 @@
#include <grpc++/impl/codegen/config.h>
extern "C" {
-#include "src/core/ext/client_config/client_channel.h"
+#include "src/core/ext/client_channel/client_channel.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/support/string.h"
diff --git a/test/cpp/interop/interop_test.cc b/test/cpp/interop/interop_test.cc
index 8e71a2bb29..c066598d36 100644
--- a/test/cpp/interop/interop_test.cc
+++ b/test/cpp/interop/interop_test.cc
@@ -44,17 +44,21 @@
#include <sys/wait.h>
#include <unistd.h>
+#include <gflags/gflags.h>
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "test/core/util/port.h"
+#include "test/cpp/util/test_config.h"
extern "C" {
#include "src/core/lib/iomgr/socket_utils_posix.h"
#include "src/core/lib/support/string.h"
}
+DEFINE_string(extra_server_flags, "", "Extra flags to pass to server.");
+
int test_client(const char* root, const char* host, int port) {
int status;
pid_t cli;
@@ -80,6 +84,7 @@ int test_client(const char* root, const char* host, int port) {
}
int main(int argc, char** argv) {
+ grpc::testing::InitTest(&argc, &argv, true);
char* me = argv[0];
char* lslash = strrchr(me, '/');
char root[1024];
@@ -105,15 +110,19 @@ int main(int argc, char** argv) {
/* start the server */
svr = fork();
if (svr == 0) {
- char* binary_path;
- char* port_arg;
- gpr_asprintf(&binary_path, "%s/interop_server", root);
- gpr_asprintf(&port_arg, "--port=%d", port);
-
- execl(binary_path, binary_path, port_arg, NULL);
-
- gpr_free(binary_path);
- gpr_free(port_arg);
+ const size_t num_args = 3 + !FLAGS_extra_server_flags.empty();
+ char** args = (char**)gpr_malloc(sizeof(char*) * num_args);
+ memset(args, 0, sizeof(char*) * num_args);
+ gpr_asprintf(&args[0], "%s/interop_server", root);
+ gpr_asprintf(&args[1], "--port=%d", port);
+ if (!FLAGS_extra_server_flags.empty()) {
+ args[2] = gpr_strdup(FLAGS_extra_server_flags.c_str());
+ }
+ execv(args[0], args);
+ for (size_t i = 0; i < num_args - 1; ++i) {
+ gpr_free(args[i]);
+ }
+ gpr_free(args);
return 1;
}
/* wait a little */
diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc
index 5647cb5531..46d09b7f28 100644
--- a/test/cpp/interop/stress_test.cc
+++ b/test/cpp/interop/stress_test.cc
@@ -46,6 +46,7 @@
#include "src/proto/grpc/testing/metrics.grpc.pb.h"
#include "src/proto/grpc/testing/metrics.pb.h"
+#include "test/cpp/interop/client_helper.h"
#include "test/cpp/interop/interop_client.h"
#include "test/cpp/interop/stress_interop_client.h"
#include "test/cpp/util/metrics_server.h"
@@ -68,7 +69,8 @@ DEFINE_int32(test_duration_secs, -1,
DEFINE_string(server_addresses, "localhost:8080",
"The list of server"
- " addresses in the format:\n"
+ "addresses. This option is ignored if either\n"
+ "server_port or server_host is specified. The format is: \n"
" \"<name_1>:<port_1>,<name_2>:<port_1>...<name_N>:<port_N>\"\n"
" Note: <name> can be servername or IP address.");
@@ -79,6 +81,34 @@ DEFINE_int32(num_stubs_per_channel, 1,
"indicates the max number of parallel RPC calls on each channel "
"at any given time.");
+DEFINE_string(test_case, "",
+ "Configure different test cases. Valid options are:\n\n"
+ "all : all test cases;\n"
+ "cancel_after_begin : cancel stream after starting it;\n"
+ "cancel_after_first_response: cancel on first response;\n"
+ "client_compressed_streaming : compressed request streaming with "
+ "client_compressed_unary : single compressed request;\n"
+ "client_streaming : request streaming with single response;\n"
+ "compute_engine_creds: large_unary with compute engine auth;\n"
+ "custom_metadata: server will echo custom metadata;\n"
+ "empty_stream : bi-di stream with no request/response;\n"
+ "empty_unary : empty (zero bytes) request and response;\n"
+ "half_duplex : half-duplex streaming;\n"
+ "jwt_token_creds: large_unary with JWT token auth;\n"
+ "large_unary : single request and (large) response;\n"
+ "oauth2_auth_token: raw oauth2 access token auth;\n"
+ "per_rpc_creds: raw oauth2 access token on a single rpc;\n"
+ "ping_pong : full-duplex streaming;\n"
+ "response streaming;\n"
+ "server_compressed_streaming : single request with compressed "
+ "server_compressed_unary : single compressed response;\n"
+ "server_streaming : single request with response streaming;\n"
+ "slow_consumer : single request with response streaming with "
+ "slow client consumer;\n"
+ "status_code_and_message: verify status code & message;\n"
+ "timeout_on_sleeping_server: deadline exceeds on stream;\n"
+ "unimplemented_method: client calls an unimplemented_method;\n");
+
// TODO(sreek): Add more test cases here in future
DEFINE_string(test_cases, "",
"List of test cases to call along with the"
@@ -115,6 +145,17 @@ DEFINE_bool(do_not_abort_on_transient_failures, true,
"If set to 'true', abort() is not called in case of transient "
"failures like temporary connection failures.");
+// Options from client.cc (for compatibility with interop test).
+// TODO(sreek): Consolidate overlapping options
+DEFINE_bool(use_tls, false, "Whether to use tls.");
+DEFINE_bool(use_test_ca, false, "False to use SSL roots for google");
+DEFINE_int32(server_port, 0, "Server port.");
+DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
+DEFINE_string(server_host_override, "foo.test.google.fr",
+ "Override the server host which is sent in HTTP header");
+DEFINE_string(service_account_key_file, "",
+ "Path to service account json key file.");
+
using grpc::testing::kTestCaseList;
using grpc::testing::MetricsService;
using grpc::testing::MetricsServiceImpl;
@@ -200,6 +241,8 @@ bool ParseTestCasesString(const grpc::string& test_cases,
void LogParameterInfo(const std::vector<grpc::string>& addresses,
const std::vector<std::pair<TestCaseType, int>>& tests) {
gpr_log(GPR_INFO, "server_addresses: %s", FLAGS_server_addresses.c_str());
+ gpr_log(GPR_INFO, "server_host: %s", FLAGS_server_host.c_str());
+ gpr_log(GPR_INFO, "server_port: %d", FLAGS_server_port);
gpr_log(GPR_INFO, "test_cases : %s", FLAGS_test_cases.c_str());
gpr_log(GPR_INFO, "sleep_duration_ms: %d", FLAGS_sleep_duration_ms);
gpr_log(GPR_INFO, "test_duration_secs: %d", FLAGS_test_duration_secs);
@@ -243,11 +286,24 @@ int main(int argc, char** argv) {
// Parse the server addresses
std::vector<grpc::string> server_addresses;
- ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses);
+ if (FLAGS_server_port != 0) {
+ // We are using interop_client style cmdline options.
+ const int host_port_buf_size = 1024;
+ char host_port[host_port_buf_size];
+ snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(),
+ FLAGS_server_port);
+ std::string host_port_str(host_port);
+ ParseCommaDelimitedString(host_port_str, server_addresses);
+ } else {
+ ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses);
+ }
// Parse test cases and weights
if (FLAGS_test_cases.length() == 0) {
- gpr_log(GPR_ERROR, "Not running tests. The 'test_cases' string is empty");
+ // We are using interop_client style test_case option
+ FLAGS_test_cases = FLAGS_test_case + ":100";
+ } else if (FLAGS_test_case != "") {
+ gpr_log(GPR_ERROR, "specify --test_case or --test_cases but not both.");
return 1;
}
@@ -283,9 +339,14 @@ int main(int argc, char** argv) {
// Create channel(s) for each server
for (int channel_idx = 0; channel_idx < FLAGS_num_channels_per_server;
channel_idx++) {
- // TODO (sreek). This won't work for tests that require Authentication
- std::shared_ptr<grpc::Channel> channel(
- grpc::CreateChannel(*it, grpc::InsecureChannelCredentials()));
+ gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(),
+ channel_idx);
+ std::shared_ptr<grpc::Channel> channel;
+ if (FLAGS_use_tls) {
+ channel = grpc::testing::CreateChannelForTestCase(FLAGS_test_case);
+ } else {
+ channel = grpc::CreateChannel(*it, grpc::InsecureChannelCredentials());
+ }
// Create stub(s) for each channel
for (int stub_idx = 0; stub_idx < FLAGS_num_stubs_per_channel;
@@ -311,8 +372,10 @@ int main(int argc, char** argv) {
}
// Start metrics server before waiting for the stress test threads
- std::unique_ptr<grpc::Server> metrics_server =
- metrics_service.StartServer(FLAGS_metrics_port);
+ if (FLAGS_metrics_port > 0) {
+ std::unique_ptr<grpc::Server> metrics_server =
+ metrics_service.StartServer(FLAGS_metrics_port);
+ }
// Wait for the stress test threads to complete
for (auto it = test_threads.begin(); it != test_threads.end(); it++) {
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h
index 5fb87b2782..9983c8a7b0 100644
--- a/test/cpp/qps/client.h
+++ b/test/cpp/qps/client.h
@@ -36,6 +36,7 @@
#include <condition_variable>
#include <mutex>
+#include <unordered_map>
#include <vector>
#include <grpc++/channel.h>
@@ -114,19 +115,37 @@ class ClientRequestCreator<ByteBuffer> {
class HistogramEntry GRPC_FINAL {
public:
- HistogramEntry() : used_(false) {}
- bool used() const { return used_; }
+ HistogramEntry() : value_used_(false), status_used_(false) {}
+ bool value_used() const { return value_used_; }
double value() const { return value_; }
void set_value(double v) {
- used_ = true;
+ value_used_ = true;
value_ = v;
}
+ bool status_used() const { return status_used_; }
+ int status() const { return status_; }
+ void set_status(int status) {
+ status_used_ = true;
+ status_ = status;
+ }
private:
- bool used_;
+ bool value_used_;
double value_;
+ bool status_used_;
+ int status_;
};
+typedef std::unordered_map<int, int64_t> StatusHistogram;
+
+inline void MergeStatusHistogram(const StatusHistogram& from,
+ StatusHistogram* to) {
+ for (StatusHistogram::const_iterator it = from.begin(); it != from.end();
+ ++it) {
+ (*to)[it->first] += it->second;
+ }
+}
+
class Client {
public:
Client()
@@ -139,6 +158,7 @@ class Client {
ClientStats Mark(bool reset) {
Histogram latencies;
+ StatusHistogram statuses;
UsageTimer::Result timer_result;
MaybeStartRequests();
@@ -146,27 +166,36 @@ class Client {
// avoid std::vector for old compilers that expect a copy constructor
if (reset) {
Histogram* to_merge = new Histogram[threads_.size()];
+ StatusHistogram* to_merge_status = new StatusHistogram[threads_.size()];
+
for (size_t i = 0; i < threads_.size(); i++) {
- threads_[i]->BeginSwap(&to_merge[i]);
+ threads_[i]->BeginSwap(&to_merge[i], &to_merge_status[i]);
}
std::unique_ptr<UsageTimer> timer(new UsageTimer);
timer_.swap(timer);
for (size_t i = 0; i < threads_.size(); i++) {
- threads_[i]->EndSwap();
latencies.Merge(to_merge[i]);
+ MergeStatusHistogram(to_merge_status[i], &statuses);
}
delete[] to_merge;
+ delete[] to_merge_status;
timer_result = timer->Mark();
} else {
// merge snapshots of each thread histogram
for (size_t i = 0; i < threads_.size(); i++) {
- threads_[i]->MergeStatsInto(&latencies);
+ threads_[i]->MergeStatsInto(&latencies, &statuses);
}
timer_result = timer_->Mark();
}
ClientStats stats;
latencies.FillProto(stats.mutable_latencies());
+ for (StatusHistogram::const_iterator it = statuses.begin();
+ it != statuses.end(); ++it) {
+ RequestResultCount* rrc = stats.add_request_results();
+ rrc->set_status_code(it->first);
+ rrc->set_count(it->second);
+ }
stats.set_time_elapsed(timer_result.wall);
stats.set_time_system(timer_result.system);
stats.set_time_user(timer_result.user);
@@ -258,16 +287,16 @@ class Client {
~Thread() { impl_.join(); }
- void BeginSwap(Histogram* n) {
+ void BeginSwap(Histogram* n, StatusHistogram* s) {
std::lock_guard<std::mutex> g(mu_);
n->Swap(&histogram_);
+ s->swap(statuses_);
}
- void EndSwap() {}
-
- void MergeStatsInto(Histogram* hist) {
+ void MergeStatsInto(Histogram* hist, StatusHistogram* s) {
std::unique_lock<std::mutex> g(mu_);
hist->Merge(histogram_);
+ MergeStatusHistogram(statuses_, s);
}
private:
@@ -288,9 +317,12 @@ class Client {
const bool thread_still_ok = client_->ThreadFunc(&entry, idx_);
// lock, update histogram if needed and see if we're done
std::lock_guard<std::mutex> g(mu_);
- if (entry.used()) {
+ if (entry.value_used()) {
histogram_.Add(entry.value());
}
+ if (entry.status_used()) {
+ statuses_[entry.status()]++;
+ }
if (!thread_still_ok) {
gpr_log(GPR_ERROR, "Finishing client thread due to RPC error");
}
@@ -304,6 +336,7 @@ class Client {
std::mutex mu_;
Histogram histogram_;
+ StatusHistogram statuses_;
Client* client_;
const size_t idx_;
std::thread impl_;
diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc
index 081114859c..4d36a6ba42 100644
--- a/test/cpp/qps/client_async.cc
+++ b/test/cpp/qps/client_async.cc
@@ -83,7 +83,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&,
CompletionQueue*)>
start_req,
- std::function<void(grpc::Status, ResponseType*)> on_done)
+ std::function<void(grpc::Status, ResponseType*, HistogramEntry*)> on_done)
: context_(),
stub_(stub),
cq_(nullptr),
@@ -113,7 +113,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
return true;
case State::RESP_DONE:
entry->set_value((UsageTimer::Now() - start_) * 1e9);
- callback_(status_, &response_);
+ callback_(status_, &response_, entry);
next_state_ = State::INVALID;
return false;
default:
@@ -135,7 +135,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
ResponseType response_;
enum State { INVALID, READY, RESP_DONE };
State next_state_;
- std::function<void(grpc::Status, ResponseType*)> callback_;
+ std::function<void(grpc::Status, ResponseType*, HistogramEntry*)> callback_;
std::function<gpr_timespec()> next_issue_;
std::function<std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>(
BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&,
@@ -290,7 +290,10 @@ class AsyncUnaryClient GRPC_FINAL
~AsyncUnaryClient() GRPC_OVERRIDE {}
private:
- static void CheckDone(grpc::Status s, SimpleResponse* response) {}
+ static void CheckDone(grpc::Status s, SimpleResponse* response,
+ HistogramEntry* entry) {
+ entry->set_status(s.error_code());
+ }
static std::unique_ptr<grpc::ClientAsyncResponseReader<SimpleResponse>>
StartReq(BenchmarkService::Stub* stub, grpc::ClientContext* ctx,
const SimpleRequest& request, CompletionQueue* cq) {
diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc
index 0ccf4e270b..f61e80d76b 100644
--- a/test/cpp/qps/client_sync.cc
+++ b/test/cpp/qps/client_sync.cc
@@ -130,11 +130,8 @@ class SynchronousUnaryClient GRPC_FINAL : public SynchronousClient {
grpc::Status s =
stub->UnaryCall(&context, request_, &responses_[thread_idx]);
entry->set_value((UsageTimer::Now() - start) * 1e9);
- if (!s.ok()) {
- gpr_log(GPR_ERROR, "RPC error: %d: %s", s.error_code(),
- s.error_message().c_str());
- }
- return s.ok();
+ entry->set_status(s.error_code());
+ return true;
}
};
diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc
index 6c675e3483..a440341ccf 100644
--- a/test/cpp/qps/driver.cc
+++ b/test/cpp/qps/driver.cc
@@ -132,7 +132,8 @@ static void postprocess_scenario_result(ScenarioResult* result) {
Histogram histogram;
histogram.MergeProto(result->latencies());
- auto qps = histogram.Count() / average(result->client_stats(), WallTime);
+ auto time_estimate = average(result->client_stats(), WallTime);
+ auto qps = histogram.Count() / time_estimate;
auto qps_per_server_core = qps / sum(result->server_cores(), Cores);
result->mutable_summary()->set_qps(qps);
@@ -157,6 +158,23 @@ static void postprocess_scenario_result(ScenarioResult* result) {
result->mutable_summary()->set_server_user_time(server_user_time);
result->mutable_summary()->set_client_system_time(client_system_time);
result->mutable_summary()->set_client_user_time(client_user_time);
+
+ if (result->request_results_size() > 0) {
+ int64_t successes = 0;
+ int64_t failures = 0;
+ for (int i = 0; i < result->request_results_size(); i++) {
+ RequestResultCount rrc = result->request_results(i);
+ if (rrc.status_code() == 0) {
+ successes += rrc.count();
+ } else {
+ failures += rrc.count();
+ }
+ }
+ result->mutable_summary()->set_successful_requests_per_second(
+ successes / time_estimate);
+ result->mutable_summary()->set_failed_requests_per_second(failures /
+ time_estimate);
+ }
}
// Namespace for classes and functions used only in RunScenario
@@ -444,6 +462,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Finish a run
std::unique_ptr<ScenarioResult> result(new ScenarioResult);
Histogram merged_latencies;
+ std::unordered_map<int, int64_t> merged_statuses;
gpr_log(GPR_INFO, "Finishing clients");
for (size_t i = 0; i < num_clients; i++) {
@@ -462,6 +481,10 @@ std::unique_ptr<ScenarioResult> RunScenario(
gpr_log(GPR_INFO, "Received final status from client %zu", i);
const auto& stats = client_status.stats();
merged_latencies.MergeProto(stats.latencies());
+ for (int i = 0; i < stats.request_results_size(); i++) {
+ merged_statuses[stats.request_results(i).status_code()] +=
+ stats.request_results(i).count();
+ }
result->add_client_stats()->CopyFrom(stats);
// That final status should be the last message on the client stream
GPR_ASSERT(!client->stream->Read(&client_status));
@@ -481,6 +504,12 @@ std::unique_ptr<ScenarioResult> RunScenario(
delete[] clients;
merged_latencies.FillProto(result->mutable_latencies());
+ for (std::unordered_map<int, int64_t>::iterator it = merged_statuses.begin();
+ it != merged_statuses.end(); ++it) {
+ RequestResultCount* rrc = result->add_request_results();
+ rrc->set_status_code(it->first);
+ rrc->set_count(it->second);
+ }
gpr_log(GPR_INFO, "Finishing servers");
for (size_t i = 0; i < num_servers; i++) {
diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc
index 2ec7d8676c..41617e968a 100644
--- a/test/cpp/qps/report.cc
+++ b/test/cpp/qps/report.cc
@@ -73,6 +73,12 @@ void CompositeReporter::ReportTimes(const ScenarioResult& result) {
void GprLogReporter::ReportQPS(const ScenarioResult& result) {
gpr_log(GPR_INFO, "QPS: %.1f", result.summary().qps());
+ if (result.summary().failed_requests_per_second() > 0) {
+ gpr_log(GPR_INFO, "failed requests/second: %.1f",
+ result.summary().failed_requests_per_second());
+ gpr_log(GPR_INFO, "successful requests/second: %.1f",
+ result.summary().successful_requests_per_second());
+ }
}
void GprLogReporter::ReportQPSPerCore(const ScenarioResult& result) {
diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc
index 2fcc64819b..bc4c896d83 100644
--- a/test/cpp/qps/server_async.cc
+++ b/test/cpp/qps/server_async.cc
@@ -38,6 +38,7 @@
#include <thread>
#include <grpc++/generic/async_generic_service.h>
+#include <grpc++/resource_quota.h>
#include <grpc++/security/server_credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
@@ -95,6 +96,11 @@ class AsyncQpsServerTest GRPC_FINAL : public grpc::testing::Server {
srv_cqs_.emplace_back(builder.AddCompletionQueue());
}
+ if (config.resource_quota_size() > 0) {
+ builder.SetResourceQuota(ResourceQuota("AsyncQpsServerTest")
+ .Resize(config.resource_quota_size()));
+ }
+
server_ = builder.BuildAndStart();
using namespace std::placeholders;
diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc
index 0caed0ab49..07f48e2644 100644
--- a/test/cpp/qps/server_sync.cc
+++ b/test/cpp/qps/server_sync.cc
@@ -31,6 +31,7 @@
*
*/
+#include <grpc++/resource_quota.h>
#include <grpc++/security/server_credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
@@ -91,6 +92,11 @@ class SynchronousServer GRPC_FINAL : public grpc::testing::Server {
Server::CreateServerCredentials(config));
gpr_free(server_address);
+ if (config.resource_quota_size() > 0) {
+ builder.SetResourceQuota(ResourceQuota("AsyncQpsServerTest")
+ .Resize(config.resource_quota_size()));
+ }
+
builder.RegisterService(&service_);
impl_ = builder.BuildAndStart();