[e2e] c++-ify core e2e test fixtures (#32550)

A step toward #14016.

---------

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/32605/head
Craig Tiller 2 years ago committed by GitHub
parent 0003c320f4
commit 62bb99d163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      CMakeLists.txt
  2. 26
      build_autogenerated.yaml
  3. 7
      gRPC-Core.podspec
  4. 2
      src/core/ext/filters/client_channel/http_proxy.cc
  5. 4
      src/core/lib/iomgr/endpoint_pair.h
  6. 4
      src/core/lib/iomgr/endpoint_pair_posix.cc
  7. 2
      src/core/lib/iomgr/endpoint_pair_windows.cc
  8. 109
      src/objective-c/tests/CronetTests/CoreCronetEnd2EndTests.mm
  9. 4
      templates/test/core/end2end/end2end_defs.include
  10. 7
      test/core/bad_client/bad_client.cc
  11. 21
      test/core/bad_client/tests/duplicate_header.cc
  12. 10
      test/core/bad_client/tests/head_of_line_blocking.cc
  13. 12
      test/core/bad_client/tests/server_registered_method.cc
  14. 9
      test/core/bad_client/tests/simple_request.cc
  15. 8
      test/core/bad_ssl/bad_ssl_test.cc
  16. 49
      test/core/end2end/BUILD
  17. 11
      test/core/end2end/connection_refused_test.cc
  18. 4
      test/core/end2end/cq_verifier.h
  19. 26
      test/core/end2end/dualstack_socket_test.cc
  20. 6
      test/core/end2end/end2end_test_utils.cc
  21. 188
      test/core/end2end/end2end_tests.cc
  22. 107
      test/core/end2end/end2end_tests.h
  23. 103
      test/core/end2end/fixtures/h2_census.cc
  24. 106
      test/core/end2end/fixtures/h2_compress.cc
  25. 112
      test/core/end2end/fixtures/h2_fakesec.cc
  26. 86
      test/core/end2end/fixtures/h2_fd.cc
  27. 72
      test/core/end2end/fixtures/h2_full+pipe.cc
  28. 72
      test/core/end2end/fixtures/h2_full+trace.cc
  29. 71
      test/core/end2end/fixtures/h2_full.cc
  30. 78
      test/core/end2end/fixtures/h2_full_no_retry.cc
  31. 126
      test/core/end2end/fixtures/h2_http_proxy.cc
  32. 84
      test/core/end2end/fixtures/h2_insecure.cc
  33. 43
      test/core/end2end/fixtures/h2_local_abstract_uds_percent_encoded.cc
  34. 37
      test/core/end2end/fixtures/h2_local_ipv4.cc
  35. 37
      test/core/end2end/fixtures/h2_local_ipv6.cc
  36. 43
      test/core/end2end/fixtures/h2_local_uds.cc
  37. 43
      test/core/end2end/fixtures/h2_local_uds_percent_encoded.cc
  38. 181
      test/core/end2end/fixtures/h2_oauth2_common.h
  39. 244
      test/core/end2end/fixtures/h2_oauth2_tls12.cc
  40. 244
      test/core/end2end/fixtures/h2_oauth2_tls13.cc
  41. 126
      test/core/end2end/fixtures/h2_proxy.cc
  42. 129
      test/core/end2end/fixtures/h2_sockpair+trace.cc
  43. 129
      test/core/end2end/fixtures/h2_sockpair.cc
  44. 148
      test/core/end2end/fixtures/h2_sockpair_1byte.cc
  45. 142
      test/core/end2end/fixtures/h2_sockpair_with_minstack.cc
  46. 139
      test/core/end2end/fixtures/h2_ssl_cred_reload_fixture.h
  47. 196
      test/core/end2end/fixtures/h2_ssl_cred_reload_tls12.cc
  48. 197
      test/core/end2end/fixtures/h2_ssl_cred_reload_tls13.cc
  49. 246
      test/core/end2end/fixtures/h2_ssl_proxy.cc
  50. 169
      test/core/end2end/fixtures/h2_ssl_tls12.cc
  51. 170
      test/core/end2end/fixtures/h2_ssl_tls13.cc
  52. 110
      test/core/end2end/fixtures/h2_ssl_tls_common.h
  53. 37
      test/core/end2end/fixtures/h2_tls_certwatch_async_tls1_3.cc
  54. 37
      test/core/end2end/fixtures/h2_tls_certwatch_sync_tls1_2.cc
  55. 375
      test/core/end2end/fixtures/h2_tls_common.h
  56. 37
      test/core/end2end/fixtures/h2_tls_simple.cc
  57. 37
      test/core/end2end/fixtures/h2_tls_static_async_tls1_3.cc
  58. 80
      test/core/end2end/fixtures/h2_uds.cc
  59. 82
      test/core/end2end/fixtures/h2_uds_abstract.cc
  60. 60
      test/core/end2end/fixtures/inproc.cc
  61. 37
      test/core/end2end/fixtures/inproc_fixture.h
  62. 84
      test/core/end2end/fixtures/local_util.cc
  63. 25
      test/core/end2end/fixtures/local_util.h
  64. 91
      test/core/end2end/fixtures/secure_fixture.h
  65. 108
      test/core/end2end/fixtures/sockpair_fixture.h
  66. 2
      test/core/end2end/generate_tests.bzl
  67. 74
      test/core/end2end/goaway_server_test.cc
  68. 308
      test/core/end2end/h2_ssl_cert_test.cc
  69. 25
      test/core/end2end/h2_ssl_session_reuse_test.cc
  70. 505
      test/core/end2end/inproc_callback_test.cc
  71. 143
      test/core/end2end/invalid_call_argument_test.cc
  72. 11
      test/core/end2end/no_server_test.cc
  73. 90
      test/core/end2end/tests/authority_not_supported.cc
  74. 94
      test/core/end2end/tests/bad_hostname.cc
  75. 197
      test/core/end2end/tests/bad_ping.cc
  76. 111
      test/core/end2end/tests/binary_metadata.cc
  77. 157
      test/core/end2end/tests/call_creds.cc
  78. 108
      test/core/end2end/tests/call_host_override.cc
  79. 102
      test/core/end2end/tests/cancel_after_accept.cc
  80. 107
      test/core/end2end/tests/cancel_after_client_done.cc
  81. 91
      test/core/end2end/tests/cancel_after_invoke.cc
  82. 117
      test/core/end2end/tests/cancel_after_round_trip.cc
  83. 88
      test/core/end2end/tests/cancel_before_invoke.cc
  84. 82
      test/core/end2end/tests/cancel_in_a_vacuum.cc
  85. 98
      test/core/end2end/tests/cancel_with_status.cc
  86. 143
      test/core/end2end/tests/channelz.cc
  87. 130
      test/core/end2end/tests/client_streaming.cc
  88. 201
      test/core/end2end/tests/compressed_payload.cc
  89. 104
      test/core/end2end/tests/connectivity.cc
  90. 104
      test/core/end2end/tests/default_host.cc
  91. 102
      test/core/end2end/tests/disappearing_server.cc
  92. 94
      test/core/end2end/tests/empty_batch.cc
  93. 97
      test/core/end2end/tests/filter_causes_close.cc
  94. 103
      test/core/end2end/tests/filter_context.cc
  95. 163
      test/core/end2end/tests/filter_init_fails.cc
  96. 103
      test/core/end2end/tests/filter_latency.cc
  97. 105
      test/core/end2end/tests/filter_status_code.cc
  98. 109
      test/core/end2end/tests/filtered_metadata.cc
  99. 102
      test/core/end2end/tests/graceful_server_shutdown.cc
  100. 221
      test/core/end2end/tests/grpc_authz.cc
  101. Some files were not shown because too many files have changed in this diff Show More

31
CMakeLists.txt generated

@ -785,7 +785,6 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_c fd_conservation_posix_test)
endif()
add_dependencies(buildtests_c goaway_server_test)
add_dependencies(buildtests_c inproc_callback_test)
add_dependencies(buildtests_c invalid_call_argument_test)
add_dependencies(buildtests_c multiple_server_queues_test)
add_dependencies(buildtests_c no_server_test)
@ -5216,36 +5215,6 @@ target_link_libraries(goaway_server_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(inproc_callback_test
test/core/end2end/fixtures/local_util.cc
test/core/end2end/inproc_callback_test.cc
)
target_compile_features(inproc_callback_test PUBLIC cxx_std_14)
target_include_directories(inproc_callback_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(inproc_callback_test
${_gRPC_BASELIB_LIBRARIES}
${_gRPC_ZLIB_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)

@ -20,9 +20,16 @@ libs:
- test/core/end2end/cq_verifier.h
- test/core/end2end/data/ssl_test_data.h
- test/core/end2end/end2end_tests.h
- test/core/end2end/fixtures/h2_oauth2_common.h
- test/core/end2end/fixtures/h2_ssl_cred_reload_fixture.h
- test/core/end2end/fixtures/h2_ssl_tls_common.h
- test/core/end2end/fixtures/h2_tls_common.h
- test/core/end2end/fixtures/http_proxy_fixture.h
- test/core/end2end/fixtures/inproc_fixture.h
- test/core/end2end/fixtures/local_util.h
- test/core/end2end/fixtures/proxy.h
- test/core/end2end/fixtures/secure_fixture.h
- test/core/end2end/fixtures/sockpair_fixture.h
- test/core/end2end/tests/cancel_test_helpers.h
- test/core/util/test_lb_policies.h
src:
@ -4305,18 +4312,6 @@ targets:
- test/core/end2end/goaway_server_test.cc
deps:
- grpc_test_util
- name: inproc_callback_test
build: test
language: c
headers:
- test/core/end2end/end2end_tests.h
- test/core/end2end/fixtures/local_util.h
src:
- test/core/end2end/fixtures/local_util.cc
- test/core/end2end/inproc_callback_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: invalid_call_argument_test
build: test
language: c
@ -8460,7 +8455,14 @@ targets:
- test/core/end2end/cq_verifier.h
- test/core/end2end/data/ssl_test_data.h
- test/core/end2end/end2end_tests.h
- test/core/end2end/fixtures/h2_oauth2_common.h
- test/core/end2end/fixtures/h2_ssl_cred_reload_fixture.h
- test/core/end2end/fixtures/h2_ssl_tls_common.h
- test/core/end2end/fixtures/h2_tls_common.h
- test/core/end2end/fixtures/inproc_fixture.h
- test/core/end2end/fixtures/local_util.h
- test/core/end2end/fixtures/secure_fixture.h
- test/core/end2end/fixtures/sockpair_fixture.h
src:
- test/core/end2end/cq_verifier.cc
- test/core/end2end/data/client_certs.cc

7
gRPC-Core.podspec generated

@ -2808,12 +2808,19 @@ Pod::Spec.new do |s|
'test/core/end2end/end2end_test_utils.cc',
'test/core/end2end/end2end_tests.cc',
'test/core/end2end/end2end_tests.h',
'test/core/end2end/fixtures/h2_oauth2_common.h',
'test/core/end2end/fixtures/h2_ssl_cred_reload_fixture.h',
'test/core/end2end/fixtures/h2_ssl_tls_common.h',
'test/core/end2end/fixtures/h2_tls_common.h',
'test/core/end2end/fixtures/http_proxy_fixture.cc',
'test/core/end2end/fixtures/http_proxy_fixture.h',
'test/core/end2end/fixtures/inproc_fixture.h',
'test/core/end2end/fixtures/local_util.cc',
'test/core/end2end/fixtures/local_util.h',
'test/core/end2end/fixtures/proxy.cc',
'test/core/end2end/fixtures/proxy.h',
'test/core/end2end/fixtures/secure_fixture.h',
'test/core/end2end/fixtures/sockpair_fixture.h',
'test/core/end2end/tests/authority_not_supported.cc',
'test/core/end2end/tests/bad_hostname.cc',
'test/core/end2end/tests/bad_ping.cc',

@ -76,7 +76,7 @@ absl::optional<std::string> GetHttpProxyServer(
if (!uri_str.has_value()) uri_str = GetEnv("https_proxy");
if (!uri_str.has_value()) uri_str = GetEnv("http_proxy");
if (!uri_str.has_value()) return absl::nullopt;
// an emtpy value means "don't use proxy"
// an empty value means "don't use proxy"
if (uri_str->empty()) return absl::nullopt;
uri = URI::Parse(*uri_str);
if (!uri.ok() || uri->authority().empty()) {

@ -28,7 +28,7 @@ struct grpc_endpoint_pair {
grpc_endpoint* server;
};
grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char* name,
grpc_channel_args* args);
grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(
const char* name, const grpc_channel_args* args);
#endif // GRPC_SRC_CORE_LIB_IOMGR_ENDPOINT_PAIR_H

@ -55,8 +55,8 @@ static void create_sockets(int sv[2]) {
GPR_ASSERT(grpc_set_socket_no_sigpipe_if_possible(sv[1]) == absl::OkStatus());
}
grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char* name,
grpc_channel_args* args) {
grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(
const char* name, const grpc_channel_args* args) {
int sv[2];
grpc_endpoint_pair p;
create_sockets(sv);

@ -80,7 +80,7 @@ static void create_sockets(SOCKET sv[2]) {
}
grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(
const char*, grpc_channel_args* /* channel_args */) {
const char*, const grpc_channel_args* /* channel_args */) {
SOCKET sv[2];
grpc_endpoint_pair p;
create_sockets(sv);

@ -44,6 +44,7 @@
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@ -52,100 +53,44 @@
#import "../ConfigureCronet.h"
struct fullstack_secure_fixture_data {
std::string localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args *client_args, const grpc_channel_args *server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data *ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("127.0.0.1", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(NULL);
return f;
}
static void process_auth_failure(void *state, grpc_auth_context *ctx, const grpc_metadata *md,
size_t md_count, grpc_process_auth_metadata_done_cb cb,
void *user_data) {
GPR_ASSERT(state == NULL);
cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL);
GPR_ASSERT(state == nullptr);
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static void cronet_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
const grpc_channel_args *client_args,
stream_engine *cronetEngine) {
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
f->client =
grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr.c_str(), client_args, NULL);
GPR_ASSERT(f->client != NULL);
}
static void chttp2_init_server_secure_fullstack(grpc_end2end_test_fixture *f,
const grpc_channel_args *server_args,
grpc_server_credentials *server_creds) {
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
if (f->server) {
grpc_server_destroy(f->server);
class CronetFixture final : public SecureFixture {
private:
grpc_channel_credentials *MakeClientCreds(const grpc_core::ChannelArgs &args) override {
grpc_core::Crash("unreachable");
}
f->server = grpc_server_create(server_args, NULL);
grpc_server_register_completion_queue(f->server, f->cq, NULL);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(), server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
delete ffd;
}
static void cronet_init_client_simple_ssl_secure_fullstack(grpc_end2end_test_fixture *f,
const grpc_channel_args *client_args) {
grpc_core::ExecCtx exec_ctx;
stream_engine *cronetEngine = [Cronet getGlobalEngine];
const grpc_channel_args *new_client_args = grpc_channel_args_copy(client_args);
cronet_init_client_secure_fullstack(f, new_client_args, cronetEngine);
grpc_channel_args_destroy(new_client_args);
}
static int fail_server_auth_check(const grpc_channel_args *server_args) {
size_t i;
if (server_args == NULL) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) == 0) {
return 1;
grpc_server_credentials *MakeServerCreds(const grpc_core::ChannelArgs &args) override {
grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key, test_server1_cert};
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(nullptr, &pem_cert_key_pair, 1, 0, nullptr);
if (args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr, nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
return ssl_creds;
}
return 0;
}
static void chttp2_init_server_simple_ssl_secure_fullstack(grpc_end2end_test_fixture *f,
const grpc_channel_args *server_args) {
grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key, test_server1_cert};
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
if (fail_server_auth_check(server_args)) {
grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
grpc_channel *MakeClient(const grpc_core::ChannelArgs &args) override {
stream_engine *cronetEngine = [Cronet getGlobalEngine];
return grpc_cronet_secure_channel_create(cronetEngine, localaddr().c_str(), args.ToC().get(),
nullptr);
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
};
/* All test configurations */
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/simple_ssl_fullstack",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS, nullptr,
chttp2_create_fixture_secure_fullstack, cronet_init_client_simple_ssl_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack, chttp2_tear_down_secure_fullstack},
[](const grpc_core::ChannelArgs & /*client_args*/,
const grpc_core::ChannelArgs & /*server_args*/) {
return std::make_unique<CronetFixture>();
}},
};
static char *roots_filename;
@ -170,8 +115,8 @@ static char *roots_filename;
/* Set the SSL roots env var. */
roots_file = gpr_tmpfile("chttp2_simple_ssl_fullstack_test", &roots_filename);
GPR_ASSERT(roots_filename != NULL);
GPR_ASSERT(roots_file != NULL);
GPR_ASSERT(roots_filename != nullptr);
GPR_ASSERT(roots_file != nullptr);
GPR_ASSERT(fwrite(test_root_cert, 1, roots_size, roots_file) == roots_size);
fclose(roots_file);
GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path, roots_filename);

@ -34,7 +34,7 @@
static bool g_pre_init_called = false;
% for test in tests:
extern void ${test}(grpc_end2end_test_config config);
extern void ${test}(const CoreTestConfiguration& config);
extern void ${test}_pre_init(void);
% endfor
@ -48,7 +48,7 @@ void grpc_end2end_tests_pre_init(void) {
// NOLINTNEXTLINE(readability-function-size)
void grpc_end2end_tests(int argc, char **argv,
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
int i;
GPR_ASSERT(g_pre_init_called);

@ -319,8 +319,6 @@ bool rst_stream_client_validator(grpc_slice_buffer* incoming, void* /*arg*/) {
return success;
}
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
void server_verifier_request_call(grpc_server* server,
grpc_completion_queue* cq,
void* /*registered_method*/) {
@ -334,9 +332,10 @@ void server_verifier_request_call(grpc_server* server,
grpc_metadata_array_init(&request_metadata_recv);
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq, tag(101));
&request_metadata_recv, cq, cq,
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost"));

@ -16,7 +16,6 @@
//
//
#include <stdint.h>
#include <string.h>
#include <grpc/grpc.h>
@ -52,8 +51,6 @@
"\x00\x00\x20\x00\x00\x00\x00\x00\x01" \
"\x00\x00\x00\x00"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
grpc_call_error error;
@ -70,9 +67,10 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq,
grpc_metadata_array_init(&request_metadata_recv);
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq, tag(101));
&request_metadata_recv, cq, cq,
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost"));
@ -90,11 +88,12 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), grpc_core::CqVerifier::AnyStatus());
cqv.Expect(grpc_core::CqVerifier::tag(102),
grpc_core::CqVerifier::AnyStatus());
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -112,11 +111,11 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(103),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(103), true);
cqv.Expect(grpc_core::CqVerifier::tag(103), true);
cqv.Verify();
grpc_metadata_array_destroy(&request_metadata_recv);

@ -71,8 +71,6 @@ static const char prefix[] =
"\x01\x00\x00\x27\x10"
"";
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void verifier(grpc_server* server, grpc_completion_queue* cq,
void* registered_method) {
grpc_call_error error;
@ -84,11 +82,11 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq,
grpc_metadata_array_init(&request_metadata_recv);
error = grpc_server_request_registered_call(server, registered_method, &s,
&deadline, &request_metadata_recv,
&payload, cq, cq, tag(101));
error = grpc_server_request_registered_call(
server, registered_method, &s, &deadline, &request_metadata_recv,
&payload, cq, cq, grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
GPR_ASSERT(payload != nullptr);

@ -16,8 +16,6 @@
//
//
#include <stdint.h>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/support/log.h>
@ -43,8 +41,6 @@
"\x10\x02te\x08trailers" \
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void verifier_succeeds(grpc_server* server, grpc_completion_queue* cq,
void* registered_method) {
grpc_call_error error;
@ -56,11 +52,11 @@ static void verifier_succeeds(grpc_server* server, grpc_completion_queue* cq,
grpc_metadata_array_init(&request_metadata_recv);
error = grpc_server_request_registered_call(server, registered_method, &s,
&deadline, &request_metadata_recv,
&payload, cq, cq, tag(101));
error = grpc_server_request_registered_call(
server, registered_method, &s, &deadline, &request_metadata_recv,
&payload, cq, cq, grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
GPR_ASSERT(payload != nullptr);

@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdint.h>
#include <grpc/grpc.h>
#include <grpc/slice.h>
#include <grpc/support/log.h>
@ -83,8 +81,6 @@
"\x10\x0cgrpc-timeout\x02" \
"5S"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
grpc_call_error error;
@ -97,9 +93,10 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq,
grpc_metadata_array_init(&request_metadata_recv);
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq, tag(101));
&request_metadata_recv, cq, cq,
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost"));

@ -16,7 +16,6 @@
//
//
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@ -40,8 +39,6 @@
#include "test/core/util/subprocess.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void run_test(const char* target, size_t nops) {
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
@ -101,10 +98,11 @@ static void run_test(const char* target, size_t nops) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, nops, tag(1), nullptr);
error = grpc_call_start_batch(c, ops, nops, grpc_core::CqVerifier::tag(1),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status != GRPC_STATUS_OK);

@ -100,16 +100,44 @@ grpc_cc_library(
)
grpc_cc_library(
name = "local_util",
name = "fixture_support",
srcs = ["fixtures/local_util.cc"],
hdrs = [
"end2end_tests.h",
"fixtures/h2_oauth2_common.h",
"fixtures/h2_ssl_cred_reload_fixture.h",
"fixtures/h2_ssl_tls_common.h",
"fixtures/h2_tls_common.h",
"fixtures/inproc_fixture.h",
"fixtures/local_util.h",
"fixtures/secure_fixture.h",
"fixtures/sockpair_fixture.h",
],
external_deps = [
"absl/status",
"absl/status:statusor",
"absl/strings",
],
language = "C++",
deps = [
"//:config",
"//:exec_ctx",
"//:gpr",
"//:grpc",
"//:grpc_public_hdrs",
"//:grpc_security_base",
"//:grpc_transport_chttp2",
"//:ref_counted_ptr",
"//src/core:channel_args",
"//src/core:channel_args_preconditioning",
"//src/core:channel_stack_type",
"//src/core:error",
"//src/core:grpc_ssl_credentials",
"//src/core:grpc_tls_credentials",
"//src/core:grpc_transport_inproc",
"//src/core:slice",
"//src/core:transport_fwd",
"//test/core/util:grpc_test_util",
],
)
@ -200,22 +228,6 @@ grpc_cc_test(
],
)
grpc_cc_test(
name = "inproc_callback_test",
srcs = ["inproc_callback_test.cc"],
external_deps = ["absl/strings:str_format"],
language = "C++",
uses_event_engine = False,
uses_polling = False,
deps = [
"local_util",
"//:gpr",
"//:grpc_public_hdrs",
"//src/core:grpc_transport_inproc",
"//test/core/util:grpc_test_util",
],
)
grpc_cc_test(
name = "invalid_call_argument_test",
srcs = ["invalid_call_argument_test.cc"],
@ -270,9 +282,8 @@ grpc_cc_test(
language = "C++",
deps = [
"cq_verifier",
"local_util",
"fixture_support",
"ssl_test_data",
"//:exec_ctx",
"//:gpr",
"//:grpc",
"//:grpc_public_hdrs",

@ -16,7 +16,6 @@
//
//
#include <stdint.h>
#include <string.h>
#include <string>
@ -36,8 +35,6 @@
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void run_test(bool wait_for_ready, bool use_service_config) {
grpc_channel* chan;
grpc_call* call;
@ -107,11 +104,11 @@ static void run_test(bool wait_for_ready, bool use_service_config) {
op->flags = 0;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops,
(size_t)(op - ops), tag(1),
nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(call, ops, (size_t)(op - ops),
grpc_core::CqVerifier::tag(1), nullptr));
// verify that all tags get completed
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
if (wait_for_ready) {

@ -19,6 +19,8 @@
#ifndef GRPC_TEST_CORE_END2END_CQ_VERIFIER_H
#define GRPC_TEST_CORE_END2END_CQ_VERIFIER_H
#include <stdint.h>
#include <string>
#include <vector>
@ -73,6 +75,8 @@ class CqVerifier {
std::string ToString() const;
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
private:
struct Expectation {
SourceLocation location;

@ -16,8 +16,6 @@
//
//
#include <stdint.h>
#include <algorithm>
#include <initializer_list>
#include <memory>
@ -62,8 +60,6 @@
// This test exercises IPv4, IPv6, and dualstack sockets in various ways.
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
@ -200,16 +196,17 @@ void test_connect(const char* server_host, const char* client_host, int port,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
if (expect_ok) {
// Check for a successful request.
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq, tag(101));
&request_metadata_recv, cq, cq,
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -230,11 +227,11 @@ void test_connect(const char* server_host, const char* client_host, int port,
op->flags = 0;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
tag(102), nullptr);
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
peer = grpc_call_get_peer(c);
@ -251,7 +248,7 @@ void test_connect(const char* server_host, const char* client_host, int port,
grpc_call_unref(s);
} else {
// Check for a failed connection.
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
gpr_log(GPR_INFO, "status: %d (expected: %d)", status,
@ -265,12 +262,13 @@ void test_connect(const char* server_host, const char* client_host, int port,
grpc_channel_destroy(client);
// Destroy server.
grpc_server_shutdown_and_notify(server, cq, tag(1000));
grpc_server_shutdown_and_notify(server, cq, grpc_core::CqVerifier::tag(1000));
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
} while (ev.type != GRPC_OP_COMPLETE ||
ev.tag != grpc_core::CqVerifier::tag(1000));
grpc_server_destroy(server);
grpc_completion_queue_shutdown(cq);

@ -22,7 +22,7 @@
#include "test/core/end2end/end2end_tests.h"
const char* get_host_override_string(const char* str,
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
if (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER) {
return str;
} else {
@ -31,7 +31,7 @@ const char* get_host_override_string(const char* str,
}
const grpc_slice* get_host_override_slice(const char* str,
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* r = get_host_override_string(str, config);
if (r != nullptr) {
static grpc_slice ret;
@ -42,7 +42,7 @@ const grpc_slice* get_host_override_slice(const char* str,
}
void validate_host_override_string(const char* pattern, grpc_slice str,
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
if (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER) {
GPR_ASSERT(0 == grpc_slice_str_cmp(str, pattern));
}

@ -32,191 +32,191 @@
static bool g_pre_init_called = false;
extern void authority_not_supported(grpc_end2end_test_config config);
extern void authority_not_supported(const CoreTestConfiguration& config);
extern void authority_not_supported_pre_init(void);
extern void bad_hostname(grpc_end2end_test_config config);
extern void bad_hostname(const CoreTestConfiguration& config);
extern void bad_hostname_pre_init(void);
extern void bad_ping(grpc_end2end_test_config config);
extern void bad_ping(const CoreTestConfiguration& config);
extern void bad_ping_pre_init(void);
extern void binary_metadata(grpc_end2end_test_config config);
extern void binary_metadata(const CoreTestConfiguration& config);
extern void binary_metadata_pre_init(void);
extern void call_creds(grpc_end2end_test_config config);
extern void call_creds(const CoreTestConfiguration& config);
extern void call_creds_pre_init(void);
extern void call_host_override(grpc_end2end_test_config config);
extern void call_host_override(const CoreTestConfiguration& config);
extern void call_host_override_pre_init(void);
extern void cancel_after_accept(grpc_end2end_test_config config);
extern void cancel_after_accept(const CoreTestConfiguration& config);
extern void cancel_after_accept_pre_init(void);
extern void cancel_after_client_done(grpc_end2end_test_config config);
extern void cancel_after_client_done(const CoreTestConfiguration& config);
extern void cancel_after_client_done_pre_init(void);
extern void cancel_after_invoke(grpc_end2end_test_config config);
extern void cancel_after_invoke(const CoreTestConfiguration& config);
extern void cancel_after_invoke_pre_init(void);
extern void cancel_after_round_trip(grpc_end2end_test_config config);
extern void cancel_after_round_trip(const CoreTestConfiguration& config);
extern void cancel_after_round_trip_pre_init(void);
extern void cancel_before_invoke(grpc_end2end_test_config config);
extern void cancel_before_invoke(const CoreTestConfiguration& config);
extern void cancel_before_invoke_pre_init(void);
extern void cancel_in_a_vacuum(grpc_end2end_test_config config);
extern void cancel_in_a_vacuum(const CoreTestConfiguration& config);
extern void cancel_in_a_vacuum_pre_init(void);
extern void cancel_with_status(grpc_end2end_test_config config);
extern void cancel_with_status(const CoreTestConfiguration& config);
extern void cancel_with_status_pre_init(void);
extern void channelz(grpc_end2end_test_config config);
extern void channelz(const CoreTestConfiguration& config);
extern void channelz_pre_init(void);
extern void client_streaming(grpc_end2end_test_config config);
extern void client_streaming(const CoreTestConfiguration& config);
extern void client_streaming_pre_init(void);
extern void compressed_payload(grpc_end2end_test_config config);
extern void compressed_payload(const CoreTestConfiguration& config);
extern void compressed_payload_pre_init(void);
extern void connectivity(grpc_end2end_test_config config);
extern void connectivity(const CoreTestConfiguration& config);
extern void connectivity_pre_init(void);
extern void default_host(grpc_end2end_test_config config);
extern void default_host(const CoreTestConfiguration& config);
extern void default_host_pre_init(void);
extern void disappearing_server(grpc_end2end_test_config config);
extern void disappearing_server(const CoreTestConfiguration& config);
extern void disappearing_server_pre_init(void);
extern void empty_batch(grpc_end2end_test_config config);
extern void empty_batch(const CoreTestConfiguration& config);
extern void empty_batch_pre_init(void);
extern void filter_causes_close(grpc_end2end_test_config config);
extern void filter_causes_close(const CoreTestConfiguration& config);
extern void filter_causes_close_pre_init(void);
extern void filter_context(grpc_end2end_test_config config);
extern void filter_context(const CoreTestConfiguration& config);
extern void filter_context_pre_init(void);
extern void filter_init_fails(grpc_end2end_test_config config);
extern void filter_init_fails(const CoreTestConfiguration& config);
extern void filter_init_fails_pre_init(void);
extern void filter_latency(grpc_end2end_test_config config);
extern void filter_latency(const CoreTestConfiguration& config);
extern void filter_latency_pre_init(void);
extern void filter_status_code(grpc_end2end_test_config config);
extern void filter_status_code(const CoreTestConfiguration& config);
extern void filter_status_code_pre_init(void);
extern void filtered_metadata(grpc_end2end_test_config config);
extern void filtered_metadata(const CoreTestConfiguration& config);
extern void filtered_metadata_pre_init(void);
extern void graceful_server_shutdown(grpc_end2end_test_config config);
extern void graceful_server_shutdown(const CoreTestConfiguration& config);
extern void graceful_server_shutdown_pre_init(void);
extern void grpc_authz(grpc_end2end_test_config config);
extern void grpc_authz(const CoreTestConfiguration& config);
extern void grpc_authz_pre_init(void);
extern void high_initial_seqno(grpc_end2end_test_config config);
extern void high_initial_seqno(const CoreTestConfiguration& config);
extern void high_initial_seqno_pre_init(void);
extern void hpack_size(grpc_end2end_test_config config);
extern void hpack_size(const CoreTestConfiguration& config);
extern void hpack_size_pre_init(void);
extern void invoke_large_request(grpc_end2end_test_config config);
extern void invoke_large_request(const CoreTestConfiguration& config);
extern void invoke_large_request_pre_init(void);
extern void keepalive_timeout(grpc_end2end_test_config config);
extern void keepalive_timeout(const CoreTestConfiguration& config);
extern void keepalive_timeout_pre_init(void);
extern void large_metadata(grpc_end2end_test_config config);
extern void large_metadata(const CoreTestConfiguration& config);
extern void large_metadata_pre_init(void);
extern void max_concurrent_streams(grpc_end2end_test_config config);
extern void max_concurrent_streams(const CoreTestConfiguration& config);
extern void max_concurrent_streams_pre_init(void);
extern void max_connection_age(grpc_end2end_test_config config);
extern void max_connection_age(const CoreTestConfiguration& config);
extern void max_connection_age_pre_init(void);
extern void max_connection_idle(grpc_end2end_test_config config);
extern void max_connection_idle(const CoreTestConfiguration& config);
extern void max_connection_idle_pre_init(void);
extern void max_message_length(grpc_end2end_test_config config);
extern void max_message_length(const CoreTestConfiguration& config);
extern void max_message_length_pre_init(void);
extern void negative_deadline(grpc_end2end_test_config config);
extern void negative_deadline(const CoreTestConfiguration& config);
extern void negative_deadline_pre_init(void);
extern void no_logging(grpc_end2end_test_config config);
extern void no_logging(const CoreTestConfiguration& config);
extern void no_logging_pre_init(void);
extern void no_op(grpc_end2end_test_config config);
extern void no_op(const CoreTestConfiguration& config);
extern void no_op_pre_init(void);
extern void payload(grpc_end2end_test_config config);
extern void payload(const CoreTestConfiguration& config);
extern void payload_pre_init(void);
extern void ping(grpc_end2end_test_config config);
extern void ping(const CoreTestConfiguration& config);
extern void ping_pre_init(void);
extern void ping_pong_streaming(grpc_end2end_test_config config);
extern void ping_pong_streaming(const CoreTestConfiguration& config);
extern void ping_pong_streaming_pre_init(void);
extern void proxy_auth(grpc_end2end_test_config config);
extern void proxy_auth(const CoreTestConfiguration& config);
extern void proxy_auth_pre_init(void);
extern void registered_call(grpc_end2end_test_config config);
extern void registered_call(const CoreTestConfiguration& config);
extern void registered_call_pre_init(void);
extern void request_with_flags(grpc_end2end_test_config config);
extern void request_with_flags(const CoreTestConfiguration& config);
extern void request_with_flags_pre_init(void);
extern void request_with_payload(grpc_end2end_test_config config);
extern void request_with_payload(const CoreTestConfiguration& config);
extern void request_with_payload_pre_init(void);
extern void resource_quota_server(grpc_end2end_test_config config);
extern void resource_quota_server(const CoreTestConfiguration& config);
extern void resource_quota_server_pre_init(void);
extern void retry(grpc_end2end_test_config config);
extern void retry(const CoreTestConfiguration& config);
extern void retry_pre_init(void);
extern void retry_cancel_after_first_attempt_starts(grpc_end2end_test_config config);
extern void retry_cancel_after_first_attempt_starts(const CoreTestConfiguration& config);
extern void retry_cancel_after_first_attempt_starts_pre_init(void);
extern void retry_cancel_during_delay(grpc_end2end_test_config config);
extern void retry_cancel_during_delay(const CoreTestConfiguration& config);
extern void retry_cancel_during_delay_pre_init(void);
extern void retry_cancel_with_multiple_send_batches(grpc_end2end_test_config config);
extern void retry_cancel_with_multiple_send_batches(const CoreTestConfiguration& config);
extern void retry_cancel_with_multiple_send_batches_pre_init(void);
extern void retry_cancellation(grpc_end2end_test_config config);
extern void retry_cancellation(const CoreTestConfiguration& config);
extern void retry_cancellation_pre_init(void);
extern void retry_disabled(grpc_end2end_test_config config);
extern void retry_disabled(const CoreTestConfiguration& config);
extern void retry_disabled_pre_init(void);
extern void retry_exceeds_buffer_size_in_delay(grpc_end2end_test_config config);
extern void retry_exceeds_buffer_size_in_delay(const CoreTestConfiguration& config);
extern void retry_exceeds_buffer_size_in_delay_pre_init(void);
extern void retry_exceeds_buffer_size_in_initial_batch(grpc_end2end_test_config config);
extern void retry_exceeds_buffer_size_in_initial_batch(const CoreTestConfiguration& config);
extern void retry_exceeds_buffer_size_in_initial_batch_pre_init(void);
extern void retry_exceeds_buffer_size_in_subsequent_batch(grpc_end2end_test_config config);
extern void retry_exceeds_buffer_size_in_subsequent_batch(const CoreTestConfiguration& config);
extern void retry_exceeds_buffer_size_in_subsequent_batch_pre_init(void);
extern void retry_lb_drop(grpc_end2end_test_config config);
extern void retry_lb_drop(const CoreTestConfiguration& config);
extern void retry_lb_drop_pre_init(void);
extern void retry_lb_fail(grpc_end2end_test_config config);
extern void retry_lb_fail(const CoreTestConfiguration& config);
extern void retry_lb_fail_pre_init(void);
extern void retry_non_retriable_status(grpc_end2end_test_config config);
extern void retry_non_retriable_status(const CoreTestConfiguration& config);
extern void retry_non_retriable_status_pre_init(void);
extern void retry_non_retriable_status_before_recv_trailing_metadata_started(grpc_end2end_test_config config);
extern void retry_non_retriable_status_before_recv_trailing_metadata_started(const CoreTestConfiguration& config);
extern void retry_non_retriable_status_before_recv_trailing_metadata_started_pre_init(void);
extern void retry_per_attempt_recv_timeout(grpc_end2end_test_config config);
extern void retry_per_attempt_recv_timeout(const CoreTestConfiguration& config);
extern void retry_per_attempt_recv_timeout_pre_init(void);
extern void retry_per_attempt_recv_timeout_on_last_attempt(grpc_end2end_test_config config);
extern void retry_per_attempt_recv_timeout_on_last_attempt(const CoreTestConfiguration& config);
extern void retry_per_attempt_recv_timeout_on_last_attempt_pre_init(void);
extern void retry_recv_initial_metadata(grpc_end2end_test_config config);
extern void retry_recv_initial_metadata(const CoreTestConfiguration& config);
extern void retry_recv_initial_metadata_pre_init(void);
extern void retry_recv_message(grpc_end2end_test_config config);
extern void retry_recv_message(const CoreTestConfiguration& config);
extern void retry_recv_message_pre_init(void);
extern void retry_recv_message_replay(grpc_end2end_test_config config);
extern void retry_recv_message_replay(const CoreTestConfiguration& config);
extern void retry_recv_message_replay_pre_init(void);
extern void retry_recv_trailing_metadata_error(grpc_end2end_test_config config);
extern void retry_recv_trailing_metadata_error(const CoreTestConfiguration& config);
extern void retry_recv_trailing_metadata_error_pre_init(void);
extern void retry_send_initial_metadata_refs(grpc_end2end_test_config config);
extern void retry_send_initial_metadata_refs(const CoreTestConfiguration& config);
extern void retry_send_initial_metadata_refs_pre_init(void);
extern void retry_send_op_fails(grpc_end2end_test_config config);
extern void retry_send_op_fails(const CoreTestConfiguration& config);
extern void retry_send_op_fails_pre_init(void);
extern void retry_send_recv_batch(grpc_end2end_test_config config);
extern void retry_send_recv_batch(const CoreTestConfiguration& config);
extern void retry_send_recv_batch_pre_init(void);
extern void retry_server_pushback_delay(grpc_end2end_test_config config);
extern void retry_server_pushback_delay(const CoreTestConfiguration& config);
extern void retry_server_pushback_delay_pre_init(void);
extern void retry_server_pushback_disabled(grpc_end2end_test_config config);
extern void retry_server_pushback_disabled(const CoreTestConfiguration& config);
extern void retry_server_pushback_disabled_pre_init(void);
extern void retry_streaming(grpc_end2end_test_config config);
extern void retry_streaming(const CoreTestConfiguration& config);
extern void retry_streaming_pre_init(void);
extern void retry_streaming_after_commit(grpc_end2end_test_config config);
extern void retry_streaming_after_commit(const CoreTestConfiguration& config);
extern void retry_streaming_after_commit_pre_init(void);
extern void retry_streaming_succeeds_before_replay_finished(grpc_end2end_test_config config);
extern void retry_streaming_succeeds_before_replay_finished(const CoreTestConfiguration& config);
extern void retry_streaming_succeeds_before_replay_finished_pre_init(void);
extern void retry_throttled(grpc_end2end_test_config config);
extern void retry_throttled(const CoreTestConfiguration& config);
extern void retry_throttled_pre_init(void);
extern void retry_too_many_attempts(grpc_end2end_test_config config);
extern void retry_too_many_attempts(const CoreTestConfiguration& config);
extern void retry_too_many_attempts_pre_init(void);
extern void retry_transparent_goaway(grpc_end2end_test_config config);
extern void retry_transparent_goaway(const CoreTestConfiguration& config);
extern void retry_transparent_goaway_pre_init(void);
extern void retry_transparent_max_concurrent_streams(grpc_end2end_test_config config);
extern void retry_transparent_max_concurrent_streams(const CoreTestConfiguration& config);
extern void retry_transparent_max_concurrent_streams_pre_init(void);
extern void retry_transparent_not_sent_on_wire(grpc_end2end_test_config config);
extern void retry_transparent_not_sent_on_wire(const CoreTestConfiguration& config);
extern void retry_transparent_not_sent_on_wire_pre_init(void);
extern void retry_unref_before_finish(grpc_end2end_test_config config);
extern void retry_unref_before_finish(const CoreTestConfiguration& config);
extern void retry_unref_before_finish_pre_init(void);
extern void retry_unref_before_recv(grpc_end2end_test_config config);
extern void retry_unref_before_recv(const CoreTestConfiguration& config);
extern void retry_unref_before_recv_pre_init(void);
extern void server_finishes_request(grpc_end2end_test_config config);
extern void server_finishes_request(const CoreTestConfiguration& config);
extern void server_finishes_request_pre_init(void);
extern void server_streaming(grpc_end2end_test_config config);
extern void server_streaming(const CoreTestConfiguration& config);
extern void server_streaming_pre_init(void);
extern void shutdown_finishes_calls(grpc_end2end_test_config config);
extern void shutdown_finishes_calls(const CoreTestConfiguration& config);
extern void shutdown_finishes_calls_pre_init(void);
extern void shutdown_finishes_tags(grpc_end2end_test_config config);
extern void shutdown_finishes_tags(const CoreTestConfiguration& config);
extern void shutdown_finishes_tags_pre_init(void);
extern void simple_delayed_request(grpc_end2end_test_config config);
extern void simple_delayed_request(const CoreTestConfiguration& config);
extern void simple_delayed_request_pre_init(void);
extern void simple_metadata(grpc_end2end_test_config config);
extern void simple_metadata(const CoreTestConfiguration& config);
extern void simple_metadata_pre_init(void);
extern void simple_request(grpc_end2end_test_config config);
extern void simple_request(const CoreTestConfiguration& config);
extern void simple_request_pre_init(void);
extern void streaming_error_response(grpc_end2end_test_config config);
extern void streaming_error_response(const CoreTestConfiguration& config);
extern void streaming_error_response_pre_init(void);
extern void trailing_metadata(grpc_end2end_test_config config);
extern void trailing_metadata(const CoreTestConfiguration& config);
extern void trailing_metadata_pre_init(void);
extern void write_buffering(grpc_end2end_test_config config);
extern void write_buffering(const CoreTestConfiguration& config);
extern void write_buffering_pre_init(void);
extern void write_buffering_at_end(grpc_end2end_test_config config);
extern void write_buffering_at_end(const CoreTestConfiguration& config);
extern void write_buffering_at_end_pre_init(void);
void grpc_end2end_tests_pre_init(void) {
@ -319,7 +319,7 @@ void grpc_end2end_tests_pre_init(void) {
// NOLINTNEXTLINE(readability-function-size)
void grpc_end2end_tests(int argc, char **argv,
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
int i;
GPR_ASSERT(g_pre_init_called);

@ -21,11 +21,15 @@
#include <stdint.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/slice.h>
#include <grpc/support/log.h>
typedef struct grpc_end2end_test_fixture grpc_end2end_test_fixture;
typedef struct grpc_end2end_test_config grpc_end2end_test_config;
#include "src/core/lib/channel/channel_args.h"
#include "test/core/util/test_config.h"
// Test feature flags.
#define FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION 1
@ -44,14 +48,76 @@ typedef struct grpc_end2end_test_config grpc_end2end_test_config;
#define FAIL_AUTH_CHECK_SERVER_ARG_NAME "fail_auth_check"
struct grpc_end2end_test_fixture {
grpc_completion_queue* cq;
grpc_server* server;
grpc_channel* client;
void* fixture_data;
class CoreTestFixture {
public:
virtual ~CoreTestFixture() {
ShutdownServer();
ShutdownClient();
grpc_completion_queue_shutdown(cq());
DrainCq();
grpc_completion_queue_destroy(cq());
}
grpc_completion_queue* cq() { return cq_; }
grpc_server* server() { return server_; }
grpc_channel* client() { return client_; }
void InitServer(const grpc_core::ChannelArgs& args) {
if (server_ != nullptr) ShutdownServer();
server_ = MakeServer(args);
GPR_ASSERT(server_ != nullptr);
}
void InitClient(const grpc_core::ChannelArgs& args) {
if (client_ != nullptr) ShutdownClient();
client_ = MakeClient(args);
GPR_ASSERT(client_ != nullptr);
}
void ShutdownServer() {
if (server_ == nullptr) return;
grpc_server_shutdown_and_notify(server_, cq_, server_);
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq_, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != server_);
DestroyServer();
}
void DestroyServer() {
if (server_ == nullptr) return;
grpc_server_destroy(server_);
server_ = nullptr;
}
void ShutdownClient() {
if (client_ == nullptr) return;
grpc_channel_destroy(client_);
client_ = nullptr;
}
protected:
void SetServer(grpc_server* server);
void SetClient(grpc_channel* client);
private:
virtual grpc_server* MakeServer(const grpc_core::ChannelArgs& args) = 0;
virtual grpc_channel* MakeClient(const grpc_core::ChannelArgs& args) = 0;
void DrainCq() {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq_, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
}
grpc_completion_queue* cq_ = grpc_completion_queue_create_for_next(nullptr);
grpc_server* server_ = nullptr;
grpc_channel* client_ = nullptr;
};
struct grpc_end2end_test_config {
struct CoreTestConfiguration {
// A descriptive name for this test fixture.
const char* name;
@ -59,31 +125,28 @@ struct grpc_end2end_test_config {
uint32_t feature_mask;
// If the call host is setup by the fixture (for example, via the
// GRPC_SSL_TARGET_NAME_OVERRIDE_ARG channel arg), which value should the test
// expect to find in call_details.host
// GRPC_SSL_TARGET_NAME_OVERRIDE_ARG channel arg), which value should the
// test expect to find in call_details.host
const char* overridden_call_host;
grpc_end2end_test_fixture (*create_fixture)(
const grpc_channel_args* client_args,
const grpc_channel_args* server_args);
void (*init_client)(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args);
void (*init_server)(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args);
void (*tear_down_data)(grpc_end2end_test_fixture* f);
std::function<std::unique_ptr<CoreTestFixture>(
const grpc_core::ChannelArgs& client_args,
const grpc_core::ChannelArgs& server_args)>
create_fixture;
};
void grpc_end2end_tests_pre_init(void);
void grpc_end2end_tests(int argc, char** argv, grpc_end2end_test_config config);
void grpc_end2end_tests(int argc, char** argv,
const CoreTestConfiguration& config);
const char* get_host_override_string(const char* str,
grpc_end2end_test_config config);
const CoreTestConfiguration& config);
// Returns a pointer to a statically allocated slice: future invocations
// overwrite past invocations, not threadsafe, etc...
const grpc_slice* get_host_override_slice(const char* str,
grpc_end2end_test_config config);
const CoreTestConfiguration& config);
void validate_host_override_string(const char* pattern, grpc_slice str,
grpc_end2end_test_config config);
const CoreTestConfiguration& config);
#endif // GRPC_TEST_CORE_END2END_END2END_TESTS_H

@ -18,6 +18,8 @@
#include <string.h>
#include <functional>
#include <memory>
#include <string>
#include <grpc/grpc.h>
@ -26,91 +28,46 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
struct fullstack_fixture_data {
std::string localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = new fullstack_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_arg make_census_enable_arg(void) {
grpc_arg arg;
arg.type = GRPC_ARG_INTEGER;
arg.key = const_cast<char*>(GRPC_ARG_ENABLE_CENSUS);
arg.value.integer = 1;
return arg;
}
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_arg arg = make_census_enable_arg();
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
client_args = grpc_channel_args_copy_and_add(client_args, &arg, 1);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client);
{
grpc_core::ExecCtx exec_ctx;
grpc_channel_args_destroy(client_args);
class CensusFixture : public CoreTestFixture {
private:
grpc_server* MakeServer(const grpc_core::ChannelArgs& args) override {
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
auto* server = grpc_server_create(
args.Set(GRPC_ARG_ENABLE_CENSUS, true).ToC().get(), nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
GPR_ASSERT(
grpc_server_add_http2_port(server, localaddr_.c_str(), server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(server);
return server;
}
grpc_channel_credentials_release(creds);
}
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_arg arg = make_census_enable_arg();
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
if (f->server) {
grpc_server_destroy(f->server);
grpc_channel* MakeClient(const grpc_core::ChannelArgs& args) override {
auto* creds = grpc_insecure_credentials_create();
auto* client =
grpc_channel_create(localaddr_.c_str(), creds,
args.Set(GRPC_ARG_ENABLE_CENSUS, true).ToC().get());
grpc_channel_credentials_release(creds);
return client;
}
server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1);
f->server = grpc_server_create(server_args, nullptr);
{
grpc_core::ExecCtx exec_ctx;
grpc_channel_args_destroy(server_args);
}
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
delete ffd;
}
const std::string localaddr_ =
grpc_core::JoinHostPort("localhost", grpc_pick_unused_port_or_die());
};
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack+census",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
nullptr,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<CensusFixture>();
}},
};
int main(int argc, char** argv) {

@ -18,6 +18,8 @@
#include <string.h>
#include <functional>
#include <memory>
#include <string>
#include <grpc/compression.h>
@ -27,86 +29,54 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
struct fullstack_compression_fixture_data {
std::string localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_compression(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_compression_fixture_data* ffd =
new fullstack_compression_fixture_data();
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
memset(&f, 0, sizeof(f));
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
void chttp2_init_client_fullstack_compression(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
fullstack_compression_fixture_data* ffd =
static_cast<fullstack_compression_fixture_data*>(f->fixture_data);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(
ffd->localaddr.c_str(), creds,
grpc_core::ChannelArgs::FromC(client_args)
.SetIfUnset(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM,
GRPC_COMPRESS_GZIP)
.ToC()
.get());
grpc_channel_credentials_release(creds);
}
void chttp2_init_server_fullstack_compression(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
fullstack_compression_fixture_data* ffd =
static_cast<fullstack_compression_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
class CompressionFixture : public CoreTestFixture {
private:
grpc_server* MakeServer(const grpc_core::ChannelArgs& args) override {
auto* server = grpc_server_create(
args.SetIfUnset(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM,
GRPC_COMPRESS_GZIP)
.ToC()
.get(),
nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(
grpc_server_add_http2_port(server, localaddr_.c_str(), server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(server);
return server;
}
grpc_channel* MakeClient(const grpc_core::ChannelArgs& args) override {
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
auto* client = grpc_channel_create(
localaddr_.c_str(), creds,
args.SetIfUnset(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM,
GRPC_COMPRESS_GZIP)
.ToC()
.get());
grpc_channel_credentials_release(creds);
return client;
}
f->server = grpc_server_create(
grpc_core::ChannelArgs::FromC(server_args)
.SetIfUnset(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM,
GRPC_COMPRESS_GZIP)
.ToC()
.get(),
nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) {
grpc_core::ExecCtx exec_ctx;
fullstack_compression_fixture_data* ffd =
static_cast<fullstack_compression_fixture_data*>(f->fixture_data);
delete ffd;
}
std::string localaddr_ =
grpc_core::JoinHostPort("localhost", grpc_pick_unused_port_or_die());
};
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack_compression",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack_compression,
chttp2_init_client_fullstack_compression,
chttp2_init_server_fullstack_compression,
chttp2_tear_down_fullstack_compression},
nullptr,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<CompressionFixture>();
}},
};
int main(int argc, char** argv) {

@ -18,38 +18,20 @@
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/test_config.h"
struct fullstack_secure_fixture_data {
std::string localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
@ -59,83 +41,37 @@ static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
class FakesecFixture : public SecureFixture {
private:
grpc_channel_credentials* MakeClientCreds(
const grpc_core::ChannelArgs&) override {
return grpc_fake_transport_security_credentials_create();
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
delete ffd;
}
static void chttp2_init_client_fake_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_channel_credentials* fake_ts_creds =
grpc_fake_transport_security_credentials_create();
chttp2_init_client_secure_fullstack(f, client_args, fake_ts_creds);
}
static int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
grpc_server_credentials* MakeServerCreds(
const grpc_core::ChannelArgs& args) override {
grpc_server_credentials* fake_ts_creds =
grpc_fake_transport_security_server_credentials_create();
if (args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(fake_ts_creds,
processor);
}
return fake_ts_creds;
}
return 0;
}
static void chttp2_init_server_fake_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_server_credentials* fake_ts_creds =
grpc_fake_transport_security_server_credentials_create();
if (fail_server_auth_check(server_args)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(fake_ts_creds,
processor);
}
chttp2_init_server_secure_fullstack(f, server_args, fake_ts_creds);
}
};
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fake_secure_fullstack",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS_LEVEL_INSECURE,
nullptr, chttp2_create_fixture_secure_fullstack,
chttp2_init_client_fake_secure_fullstack,
chttp2_init_server_fake_secure_fullstack,
chttp2_tear_down_secure_fullstack},
};
nullptr, [](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<FakesecFixture>();
}}};
int main(int argc, char** argv) {
size_t i;

@ -16,8 +16,12 @@
//
//
#include <functional>
#include <memory>
#include "absl/status/status.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/port.h"
@ -30,7 +34,6 @@
#include <grpc/grpc.h>
#include <grpc/grpc_posix.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/iomgr/exec_ctx.h"
@ -39,10 +42,6 @@
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
typedef struct {
int fd_pair[2];
} sp_fixture_data;
static void create_sockets(int sv[2]) {
int flags;
grpc_create_socketpair_if_unix(sv);
@ -54,58 +53,39 @@ static void create_sockets(int sv[2]) {
GPR_ASSERT(grpc_set_socket_no_sigpipe_if_possible(sv[1]) == absl::OkStatus());
}
static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
sp_fixture_data* fixture_data =
static_cast<sp_fixture_data*>(gpr_malloc(sizeof(*fixture_data)));
grpc_end2end_test_fixture f;
memset(&f, 0, sizeof(f));
f.fixture_data = fixture_data;
f.cq = grpc_completion_queue_create_for_next(nullptr);
create_sockets(fixture_data->fd_pair);
return f;
}
static void chttp2_init_client_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_core::ExecCtx exec_ctx;
sp_fixture_data* sfd = static_cast<sp_fixture_data*>(f->fixture_data);
GPR_ASSERT(!f->client);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create_from_fd("fixture_client", sfd->fd_pair[0],
creds, client_args);
grpc_channel_credentials_release(creds);
GPR_ASSERT(f->client);
}
static void chttp2_init_server_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_core::ExecCtx exec_ctx;
sp_fixture_data* sfd = static_cast<sp_fixture_data*>(f->fixture_data);
GPR_ASSERT(!f->server);
f->server = grpc_server_create(server_args, nullptr);
GPR_ASSERT(f->server);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_start(f->server);
grpc_server_credentials* creds = grpc_insecure_server_credentials_create();
grpc_server_add_channel_from_fd(f->server, sfd->fd_pair[1], creds);
grpc_server_credentials_release(creds);
}
class FdFixture : public CoreTestFixture {
public:
FdFixture() { create_sockets(fd_pair_); }
private:
grpc_server* MakeServer(const grpc_core::ChannelArgs& args) override {
grpc_core::ExecCtx exec_ctx;
auto* server = grpc_server_create(args.ToC().get(), nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
grpc_server_start(server);
grpc_server_credentials* creds = grpc_insecure_server_credentials_create();
grpc_server_add_channel_from_fd(server, fd_pair_[1], creds);
grpc_server_credentials_release(creds);
return server;
}
grpc_channel* MakeClient(const grpc_core::ChannelArgs& args) override {
grpc_core::ExecCtx exec_ctx;
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
auto* client = grpc_channel_create_from_fd("fixture_client", fd_pair_[0],
creds, args.ToC().get());
grpc_channel_credentials_release(creds);
return client;
}
static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) {
gpr_free(f->fixture_data);
}
int fd_pair_[2];
};
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fd", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, nullptr,
chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<FdFixture>();
}},
};
int main(int argc, char** argv) {

@ -16,10 +16,12 @@
//
//
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/port.h"
// This test requires posix wakeup fds
@ -27,76 +29,22 @@
#include <string.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/test_config.h"
struct fullstack_fixture_data {
std::string localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = new fullstack_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
grpc_channel_credentials_release(creds);
GPR_ASSERT(f->client);
}
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
delete ffd;
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
nullptr,
[](const grpc_core::ChannelArgs& /*client_args*/,
const grpc_core::ChannelArgs& /*server_args*/) {
return std::make_unique<InsecureFixture>();
}},
};
int main(int argc, char** argv) {

@ -18,89 +18,37 @@
#include <grpc/support/port_platform.h>
#include <string.h>
#include <grpc/grpc.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/port.h" // IWYU pragma: keep
#ifdef GRPC_POSIX_SOCKET
#include <unistd.h>
#endif
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/test_config.h"
struct fullstack_fixture_data {
std::string localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = new fullstack_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
grpc_channel_credentials_release(creds);
GPR_ASSERT(f->client);
}
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
delete ffd;
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
nullptr,
[](const grpc_core::ChannelArgs& /*client_args*/,
const grpc_core::ChannelArgs& /*server_args*/) {
return std::make_unique<InsecureFixture>();
}},
};
int main(int argc, char** argv) {

@ -18,78 +18,27 @@
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/test_config.h"
struct fullstack_fixture_data {
std::string localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = new fullstack_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
grpc_channel_credentials_release(creds);
GPR_ASSERT(f->client);
}
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
delete ffd;
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
nullptr,
[](const grpc_core::ChannelArgs& /*client_args*/,
const grpc_core::ChannelArgs& /*server_args*/) {
return std::make_unique<InsecureFixture>();
}},
};
int main(int argc, char** argv) {

@ -18,83 +18,35 @@
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/host_port.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/test_config.h"
struct fullstack_fixture_data {
std::string localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = new fullstack_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
grpc_arg no_retry = grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_ENABLE_RETRIES), 0);
client_args = grpc_channel_args_copy_and_add(client_args, &no_retry, 1);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
grpc_channel_args_destroy(client_args);
grpc_channel_credentials_release(creds);
GPR_ASSERT(f->client);
}
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
class NoRetryFixture : public InsecureFixture {
private:
grpc_core::ChannelArgs MutateClientArgs(
grpc_core::ChannelArgs args) override {
return args.Set(GRPC_ARG_ENABLE_RETRIES, false);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
delete ffd;
}
};
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
nullptr,
[](const grpc_core::ChannelArgs& /*client_args*/,
const grpc_core::ChannelArgs& /*server_args*/) {
return std::make_unique<NoRetryFixture>();
}},
};
int main(int argc, char** argv) {

@ -18,10 +18,13 @@
#include <string.h>
#include <functional>
#include <initializer_list>
#include <memory>
#include <string>
#include "absl/strings/str_format.h"
#include "absl/types/optional.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
@ -34,88 +37,69 @@
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
struct fullstack_fixture_data {
~fullstack_fixture_data() { grpc_end2end_http_proxy_destroy(proxy); }
std::string server_addr;
grpc_end2end_http_proxy* proxy = nullptr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
const grpc_channel_args* client_args,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
memset(&f, 0, sizeof(f));
fullstack_fixture_data* ffd = new fullstack_fixture_data();
const int server_port = grpc_pick_unused_port_or_die();
ffd->server_addr = grpc_core::JoinHostPort("localhost", server_port);
// Passing client_args to proxy_create for the case of checking for proxy auth
//
ffd->proxy = grpc_end2end_http_proxy_create(client_args);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
class HttpProxyFilter : public CoreTestFixture {
public:
explicit HttpProxyFilter(const grpc_core::ChannelArgs& client_args)
: proxy_(grpc_end2end_http_proxy_create(client_args.ToC().get())) {}
~HttpProxyFilter() override {
// Need to shut down the proxy users before closing the proxy (otherwise we
// become stuck).
ShutdownClient();
ShutdownServer();
grpc_end2end_http_proxy_destroy(proxy_);
}
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
// If testing for proxy auth, add credentials to proxy uri
const char* proxy_auth_str = grpc_channel_args_find_string(
client_args, GRPC_ARG_HTTP_PROXY_AUTH_CREDS);
std::string proxy_uri;
if (proxy_auth_str == nullptr) {
proxy_uri = absl::StrFormat(
"http://%s", grpc_end2end_http_proxy_get_proxy_name(ffd->proxy));
} else {
proxy_uri =
absl::StrFormat("http://%s@%s", proxy_auth_str,
grpc_end2end_http_proxy_get_proxy_name(ffd->proxy));
private:
grpc_server* MakeServer(const grpc_core::ChannelArgs& args) override {
auto* server = grpc_server_create(args.ToC().get(), nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(
grpc_server_add_http2_port(server, server_addr_.c_str(), server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(server);
return server;
}
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(ffd->server_addr.c_str(), creds,
grpc_core::ChannelArgs::FromC(client_args)
.Set(GRPC_ARG_HTTP_PROXY, proxy_uri)
.ToC()
.get());
grpc_channel_credentials_release(creds);
GPR_ASSERT(f->client);
}
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
grpc_channel* MakeClient(const grpc_core::ChannelArgs& args) override {
// If testing for proxy auth, add credentials to proxy uri
absl::optional<std::string> proxy_auth_str =
args.GetOwnedString(GRPC_ARG_HTTP_PROXY_AUTH_CREDS);
std::string proxy_uri;
if (!proxy_auth_str.has_value()) {
proxy_uri = absl::StrFormat(
"http://%s", grpc_end2end_http_proxy_get_proxy_name(proxy_));
} else {
proxy_uri =
absl::StrFormat("http://%s@%s", proxy_auth_str->c_str(),
grpc_end2end_http_proxy_get_proxy_name(proxy_));
}
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
auto* client = grpc_channel_create(
server_addr_.c_str(), creds,
args.Set(GRPC_ARG_HTTP_PROXY, proxy_uri).ToC().get());
grpc_channel_credentials_release(creds);
GPR_ASSERT(client);
return client;
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->server_addr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
delete ffd;
}
std::string server_addr_ =
grpc_core::JoinHostPort("localhost", grpc_pick_unused_port_or_die());
grpc_end2end_http_proxy* proxy_;
};
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
nullptr,
[](const grpc_core::ChannelArgs& client_args,
const grpc_core::ChannelArgs&) {
return std::make_unique<HttpProxyFilter>(client_args);
}},
};
int main(int argc, char** argv) {

@ -18,7 +18,8 @@
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
@ -26,42 +27,12 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/host_port.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/test_config.h"
namespace {
struct Chttp2InsecureFullstackFixtureData {
std::string localaddr;
};
grpc_end2end_test_fixture Chttp2CreateFixtureInsecureFullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
Chttp2InsecureFullstackFixtureData* ffd =
new Chttp2InsecureFullstackFixtureData();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
void Chttp2InitClientInsecureFullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
Chttp2InsecureFullstackFixtureData* ffd =
static_cast<Chttp2InsecureFullstackFixtureData*>(f->fixture_data);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
grpc_channel_credentials_release(creds);
GPR_ASSERT(f->client);
}
void ProcessAuthFailure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/, size_t /*md_count*/,
grpc_process_auth_metadata_done_cb cb,
@ -70,46 +41,31 @@ void ProcessAuthFailure(void* state, grpc_auth_context* /*ctx*/,
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
void Chttp2InitServerInsecureFullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
Chttp2InsecureFullstackFixtureData* ffd =
static_cast<Chttp2InsecureFullstackFixtureData*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
if (grpc_channel_args_find(server_args, FAIL_AUTH_CHECK_SERVER_ARG_NAME) !=
nullptr) {
grpc_auth_metadata_processor processor = {ProcessAuthFailure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(server_creds,
processor);
class InsecureCredsFixture : public InsecureFixture {
private:
grpc_server_credentials* MakeServerCreds(
const grpc_core::ChannelArgs& args) override {
auto* creds = grpc_insecure_server_credentials_create();
if (args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)) {
grpc_auth_metadata_processor processor = {ProcessAuthFailure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(creds, processor);
}
return creds;
}
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void Chttp2TearDownInsecureFullstack(grpc_end2end_test_fixture* f) {
Chttp2InsecureFullstackFixtureData* ffd =
static_cast<Chttp2InsecureFullstackFixtureData*>(f->fixture_data);
delete ffd;
}
};
// All test configurations
grpc_end2end_test_config configs[] = {
CoreTestConfiguration configs[] = {
{"chttp2/insecure_fullstack",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS_LEVEL_INSECURE,
nullptr, Chttp2CreateFixtureInsecureFullstack,
Chttp2InitClientInsecureFullstack, Chttp2InitServerInsecureFullstack,
Chttp2TearDownInsecureFullstack},
nullptr,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<InsecureCredsFixture>();
}},
};
} // namespace

@ -16,8 +16,9 @@
#include <unistd.h>
#include <atomic>
#include <functional>
#include <initializer_list>
#include <string>
#include <memory>
#include "absl/strings/str_format.h"
@ -25,45 +26,31 @@
#include <grpc/grpc_security_constants.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/local_util.h"
#include "test/core/util/test_config.h"
static std::atomic<int> unique{0};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_uds(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f =
grpc_end2end_local_chttp2_create_fixture_fullstack();
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
->localaddr = absl::StrFormat(
"unix-abstract:grpc_fullstack_test.%%00.%d.%" PRId64 ".%" PRId32 ".%d",
getpid(), now.tv_sec, now.tv_nsec, ++unique);
return f;
}
static void chttp2_init_client_fullstack_uds(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_client_fullstack(f, client_args, UDS);
}
static void chttp2_init_server_fullstack_uds(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_server_fullstack(f, client_args, UDS);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack_local_abstract_uds_percent_encoded",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS,
nullptr, chttp2_create_fixture_fullstack_uds,
chttp2_init_client_fullstack_uds, chttp2_init_server_fullstack_uds,
grpc_end2end_local_chttp2_tear_down_fullstack}};
nullptr,
[](const grpc_core::ChannelArgs& /*client_args*/,
const grpc_core::ChannelArgs& /*server_args*/) {
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
return std::make_unique<LocalTestFixture>(
absl::StrFormat("unix-abstract:grpc_fullstack_test.%%00.%d.%" PRId64
".%" PRId32 ".%d",
getpid(), now.tv_sec, now.tv_nsec,
unique.fetch_add(1, std::memory_order_relaxed)),
UDS);
}}};
int main(int argc, char** argv) {
size_t i;

@ -18,48 +18,33 @@
#include <unistd.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security_constants.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/host_port.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/local_util.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_ipv4(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f =
grpc_end2end_local_chttp2_create_fixture_fullstack();
int port = grpc_pick_unused_port_or_die();
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
->localaddr = grpc_core::JoinHostPort("127.0.0.1", port);
return f;
}
static void chttp2_init_client_fullstack_ipv4(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_client_fullstack(f, client_args, LOCAL_TCP);
}
static void chttp2_init_server_fullstack_ipv4(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_server_fullstack(f, client_args, LOCAL_TCP);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack_local_ipv4",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS,
nullptr, chttp2_create_fixture_fullstack_ipv4,
chttp2_init_client_fullstack_ipv4, chttp2_init_server_fullstack_ipv4,
grpc_end2end_local_chttp2_tear_down_fullstack}};
nullptr,
[](const grpc_core::ChannelArgs& /*client_args*/,
const grpc_core::ChannelArgs& /*server_args*/) {
int port = grpc_pick_unused_port_or_die();
return std::make_unique<LocalTestFixture>(
grpc_core::JoinHostPort("127.0.0.1", port), LOCAL_TCP);
}}};
int main(int argc, char** argv) {
size_t i;

@ -18,48 +18,33 @@
#include <unistd.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security_constants.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/host_port.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/local_util.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_ipv6(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f =
grpc_end2end_local_chttp2_create_fixture_fullstack();
int port = grpc_pick_unused_port_or_die();
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
->localaddr = grpc_core::JoinHostPort("[::1]", port);
return f;
}
static void chttp2_init_client_fullstack_ipv6(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_client_fullstack(f, client_args, LOCAL_TCP);
}
static void chttp2_init_server_fullstack_ipv6(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_server_fullstack(f, client_args, LOCAL_TCP);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack_local_ipv6",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS,
nullptr, chttp2_create_fixture_fullstack_ipv6,
chttp2_init_client_fullstack_ipv6, chttp2_init_server_fullstack_ipv6,
grpc_end2end_local_chttp2_tear_down_fullstack}};
nullptr,
[](const grpc_core::ChannelArgs& /*client_args*/,
const grpc_core::ChannelArgs& /*server_args*/) {
int port = grpc_pick_unused_port_or_die();
return std::make_unique<LocalTestFixture>(
grpc_core::JoinHostPort("[::1]", port), LOCAL_TCP);
}}};
int main(int argc, char** argv) {
size_t i;

@ -20,8 +20,9 @@
#include <unistd.h>
#include <atomic>
#include <functional>
#include <initializer_list>
#include <string>
#include <memory>
#include "absl/strings/str_format.h"
@ -29,45 +30,31 @@
#include <grpc/grpc_security_constants.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/local_util.h"
#include "test/core/util/test_config.h"
static std::atomic<int> unique{1};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_uds(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f =
grpc_end2end_local_chttp2_create_fixture_fullstack();
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
->localaddr = absl::StrFormat(
"unix:/tmp/grpc_fullstack_test.%d.%" PRId64 ".%" PRId32 ".%d", getpid(),
now.tv_sec, now.tv_nsec, unique++);
return f;
}
static void chttp2_init_client_fullstack_uds(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_client_fullstack(f, client_args, UDS);
}
static void chttp2_init_server_fullstack_uds(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_server_fullstack(f, client_args, UDS);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack_local_uds",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS,
nullptr, chttp2_create_fixture_fullstack_uds,
chttp2_init_client_fullstack_uds, chttp2_init_server_fullstack_uds,
grpc_end2end_local_chttp2_tear_down_fullstack}};
nullptr,
[](const grpc_core::ChannelArgs& /*client_args*/,
const grpc_core::ChannelArgs& /*server_args*/) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
return std::make_unique<LocalTestFixture>(
absl::StrFormat("unix:/tmp/grpc_fullstack_test.%d.%" PRId64
".%" PRId32 ".%d",
getpid(), now.tv_sec, now.tv_nsec,
unique.fetch_add(1, std::memory_order_relaxed)),
UDS);
}}};
int main(int argc, char** argv) {
size_t i;

@ -20,8 +20,9 @@
#include <unistd.h>
#include <atomic>
#include <functional>
#include <initializer_list>
#include <string>
#include <memory>
#include "absl/strings/str_format.h"
@ -29,45 +30,31 @@
#include <grpc/grpc_security_constants.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/local_util.h"
#include "test/core/util/test_config.h"
static std::atomic<int> unique{1};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_uds(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f =
grpc_end2end_local_chttp2_create_fixture_fullstack();
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
->localaddr = absl::StrFormat(
"unix:/tmp/grpc_fullstack_test.%%25.%d.%" PRId64 ".%" PRId32 ".%d",
getpid(), now.tv_sec, now.tv_nsec, unique++);
return f;
}
static void chttp2_init_client_fullstack_uds(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_client_fullstack(f, client_args, UDS);
}
static void chttp2_init_server_fullstack_uds(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_end2end_local_chttp2_init_server_fullstack(f, client_args, UDS);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack_local_uds_percent_encoded",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS,
nullptr, chttp2_create_fixture_fullstack_uds,
chttp2_init_client_fullstack_uds, chttp2_init_server_fullstack_uds,
grpc_end2end_local_chttp2_tear_down_fullstack}};
nullptr,
[](const grpc_core::ChannelArgs& /*client_args*/,
const grpc_core::ChannelArgs& /*server_args*/) {
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
return std::make_unique<LocalTestFixture>(
absl::StrFormat("unix:/tmp/grpc_fullstack_test.%%25.%d.%" PRId64
".%" PRId32 ".%d",
getpid(), now.tv_sec, now.tv_nsec,
unique.fetch_add(1, std::memory_order_relaxed)),
UDS);
}}};
int main(int argc, char** argv) {
size_t i;

@ -0,0 +1,181 @@
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_TEST_CORE_END2END_FIXTURES_H2_OAUTH2_COMMON_H
#define GRPC_TEST_CORE_END2END_FIXTURES_H2_OAUTH2_COMMON_H
#include <string.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
class Oauth2Fixture : public SecureFixture {
public:
explicit Oauth2Fixture(grpc_tls_version tls_version)
: tls_version_(tls_version) {}
static const char* CaCertPath() { return "src/core/tsi/test_creds/ca.pem"; }
static const char* ServerCertPath() {
return "src/core/tsi/test_creds/server1.pem";
}
static const char* ServerKeyPath() {
return "src/core/tsi/test_creds/server1.key";
}
private:
struct TestProcessorState {};
static const char* oauth2_md() { return "Bearer aaslkfjs424535asdf"; }
static const char* client_identity_property_name() { return "smurf_name"; }
static const char* client_identity() { return "Brainy Smurf"; }
static const grpc_metadata* find_metadata(const grpc_metadata* md,
size_t md_count, const char* key,
const char* value) {
size_t i;
for (i = 0; i < md_count; i++) {
if (grpc_slice_str_cmp(md[i].key, key) == 0 &&
grpc_slice_str_cmp(md[i].value, value) == 0) {
return &md[i];
}
}
return nullptr;
}
static void process_oauth2_success(void*, grpc_auth_context* ctx,
const grpc_metadata* md, size_t md_count,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
const grpc_metadata* oauth2 =
find_metadata(md, md_count, "authorization", oauth2_md());
GPR_ASSERT(oauth2 != nullptr);
grpc_auth_context_add_cstring_property(ctx, client_identity_property_name(),
client_identity());
GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(
ctx, client_identity_property_name()) == 1);
cb(user_data, oauth2, 1, nullptr, 0, GRPC_STATUS_OK, nullptr);
}
static void process_oauth2_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* md, size_t md_count,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
const grpc_metadata* oauth2 =
find_metadata(md, md_count, "authorization", oauth2_md());
GPR_ASSERT(state != nullptr);
GPR_ASSERT(oauth2 != nullptr);
cb(user_data, oauth2, 1, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static grpc_auth_metadata_processor test_processor_create(bool failing) {
auto* s = new TestProcessorState;
grpc_auth_metadata_processor result;
result.state = s;
result.destroy = [](void* p) {
delete static_cast<TestProcessorState*>(p);
};
if (failing) {
result.process = process_oauth2_failure;
} else {
result.process = process_oauth2_success;
}
return result;
}
grpc_core::ChannelArgs MutateClientArgs(
grpc_core::ChannelArgs args) override {
return args.Set(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, "foo.test.google.fr");
}
grpc_channel_credentials* MakeClientCreds(
const grpc_core::ChannelArgs&) override {
grpc_slice ca_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(CaCertPath(), 1, &ca_slice)));
const char* test_root_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(ca_slice);
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr, nullptr);
if (ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_credentials* creds =
reinterpret_cast<grpc_ssl_credentials*>(ssl_creds);
creds->set_min_tls_version(tls_version_);
creds->set_max_tls_version(tls_version_);
}
grpc_call_credentials* oauth2_creds =
grpc_md_only_test_credentials_create("authorization", oauth2_md());
grpc_channel_credentials* ssl_oauth2_creds =
grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds,
nullptr);
grpc_channel_credentials_release(ssl_creds);
grpc_call_credentials_release(oauth2_creds);
grpc_slice_unref(ca_slice);
return ssl_oauth2_creds;
}
grpc_server_credentials* MakeServerCreds(
const grpc_core::ChannelArgs& args) override {
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(ServerCertPath(), 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(ServerKeyPath(), 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
if (ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_server_credentials* creds =
reinterpret_cast<grpc_ssl_server_credentials*>(ssl_creds);
creds->set_min_tls_version(tls_version_);
creds->set_max_tls_version(tls_version_);
}
grpc_server_credentials_set_auth_metadata_processor(
ssl_creds,
test_processor_create(args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)));
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
return ssl_creds;
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
GPR_ASSERT(state == nullptr);
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
grpc_tls_version tls_version_;
};
#endif // GRPC_TEST_CORE_END2END_FIXTURES_H2_OAUTH2_COMMON_H

@ -17,258 +17,30 @@
//
#include <stdio.h>
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/h2_oauth2_common.h"
#include "test/core/util/test_config.h"
#define CA_CERT_PATH "src/core/tsi/test_creds/ca.pem"
#define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem"
#define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key"
static const char oauth2_md[] = "Bearer aaslkfjs424535asdf";
static const char* client_identity_property_name = "smurf_name";
static const char* client_identity = "Brainy Smurf";
struct fullstack_secure_fixture_data {
std::string localaddr;
grpc_tls_version tls_version;
};
static const grpc_metadata* find_metadata(const grpc_metadata* md,
size_t md_count, const char* key,
const char* value) {
size_t i;
for (i = 0; i < md_count; i++) {
if (grpc_slice_str_cmp(md[i].key, key) == 0 &&
grpc_slice_str_cmp(md[i].value, value) == 0) {
return &md[i];
}
}
return nullptr;
}
typedef struct {
size_t pseudo_refcount;
} test_processor_state;
static void process_oauth2_success(void* state, grpc_auth_context* ctx,
const grpc_metadata* md, size_t md_count,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
const grpc_metadata* oauth2 =
find_metadata(md, md_count, "authorization", oauth2_md);
test_processor_state* s;
GPR_ASSERT(state != nullptr);
s = static_cast<test_processor_state*>(state);
GPR_ASSERT(s->pseudo_refcount == 1);
GPR_ASSERT(oauth2 != nullptr);
grpc_auth_context_add_cstring_property(ctx, client_identity_property_name,
client_identity);
GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(
ctx, client_identity_property_name) == 1);
cb(user_data, oauth2, 1, nullptr, 0, GRPC_STATUS_OK, nullptr);
}
static void process_oauth2_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* md, size_t md_count,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
const grpc_metadata* oauth2 =
find_metadata(md, md_count, "authorization", oauth2_md);
test_processor_state* s;
GPR_ASSERT(state != nullptr);
s = static_cast<test_processor_state*>(state);
GPR_ASSERT(s->pseudo_refcount == 1);
GPR_ASSERT(oauth2 != nullptr);
cb(user_data, oauth2, 1, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/, grpc_tls_version tls_version) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
ffd->tls_version = tls_version;
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack_tls1_2(
const grpc_channel_args* client_args,
const grpc_channel_args* server_args) {
return chttp2_create_fixture_secure_fullstack(client_args, server_args,
grpc_tls_version::TLS1_2);
}
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
delete ffd;
}
static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_core::ExecCtx exec_ctx;
grpc_slice ca_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(CA_CERT_PATH, 1, &ca_slice)));
const char* test_root_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(ca_slice);
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_credentials* creds =
reinterpret_cast<grpc_ssl_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_call_credentials* oauth2_creds =
grpc_md_only_test_credentials_create("authorization", oauth2_md);
grpc_channel_credentials* ssl_oauth2_creds =
grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds,
nullptr);
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_oauth2_creds);
grpc_channel_args_destroy(new_client_args);
grpc_channel_credentials_release(ssl_creds);
grpc_call_credentials_release(oauth2_creds);
grpc_slice_unref(ca_slice);
}
static int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
}
}
return 0;
}
static void processor_destroy(void* state) {
test_processor_state* s = static_cast<test_processor_state*>(state);
GPR_ASSERT((s->pseudo_refcount--) == 1);
gpr_free(s);
}
static grpc_auth_metadata_processor test_processor_create(int failing) {
test_processor_state* s =
static_cast<test_processor_state*>(gpr_malloc(sizeof(*s)));
grpc_auth_metadata_processor result;
s->pseudo_refcount = 1;
result.state = s;
result.destroy = processor_destroy;
if (failing) {
result.process = process_oauth2_failure;
} else {
result.process = process_oauth2_success;
}
return result;
}
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_server_credentials* creds =
reinterpret_cast<grpc_ssl_server_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_server_credentials_set_auth_metadata_processor(
ssl_creds, test_processor_create(fail_server_auth_check(server_args)));
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/simple_ssl_with_oauth2_fullstack_tls1_2",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
"foo.test.google.fr", chttp2_create_fixture_secure_fullstack_tls1_2,
chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack,
chttp2_tear_down_secure_fullstack},
};
"foo.test.google.fr",
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<Oauth2Fixture>(grpc_tls_version::TLS1_2);
}}};
int main(int argc, char** argv) {
size_t i;

@ -17,259 +17,31 @@
//
#include <stdio.h>
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/h2_oauth2_common.h"
#include "test/core/util/test_config.h"
#define CA_CERT_PATH "src/core/tsi/test_creds/ca.pem"
#define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem"
#define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key"
static const char oauth2_md[] = "Bearer aaslkfjs424535asdf";
static const char* client_identity_property_name = "smurf_name";
static const char* client_identity = "Brainy Smurf";
struct fullstack_secure_fixture_data {
std::string localaddr;
grpc_tls_version tls_version;
};
static const grpc_metadata* find_metadata(const grpc_metadata* md,
size_t md_count, const char* key,
const char* value) {
size_t i;
for (i = 0; i < md_count; i++) {
if (grpc_slice_str_cmp(md[i].key, key) == 0 &&
grpc_slice_str_cmp(md[i].value, value) == 0) {
return &md[i];
}
}
return nullptr;
}
typedef struct {
size_t pseudo_refcount;
} test_processor_state;
static void process_oauth2_success(void* state, grpc_auth_context* ctx,
const grpc_metadata* md, size_t md_count,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
const grpc_metadata* oauth2 =
find_metadata(md, md_count, "authorization", oauth2_md);
test_processor_state* s;
GPR_ASSERT(state != nullptr);
s = static_cast<test_processor_state*>(state);
GPR_ASSERT(s->pseudo_refcount == 1);
GPR_ASSERT(oauth2 != nullptr);
grpc_auth_context_add_cstring_property(ctx, client_identity_property_name,
client_identity);
GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(
ctx, client_identity_property_name) == 1);
cb(user_data, oauth2, 1, nullptr, 0, GRPC_STATUS_OK, nullptr);
}
static void process_oauth2_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* md, size_t md_count,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
const grpc_metadata* oauth2 =
find_metadata(md, md_count, "authorization", oauth2_md);
test_processor_state* s;
GPR_ASSERT(state != nullptr);
s = static_cast<test_processor_state*>(state);
GPR_ASSERT(s->pseudo_refcount == 1);
GPR_ASSERT(oauth2 != nullptr);
cb(user_data, oauth2, 1, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/, grpc_tls_version tls_version) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
ffd->tls_version = tls_version;
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack_tls1_3(
const grpc_channel_args* client_args,
const grpc_channel_args* server_args) {
return chttp2_create_fixture_secure_fullstack(client_args, server_args,
grpc_tls_version::TLS1_3);
}
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
delete ffd;
}
static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_core::ExecCtx exec_ctx;
grpc_slice ca_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(CA_CERT_PATH, 1, &ca_slice)));
const char* test_root_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(ca_slice);
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_credentials* creds =
reinterpret_cast<grpc_ssl_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_call_credentials* oauth2_creds =
grpc_md_only_test_credentials_create("authorization", oauth2_md);
grpc_channel_credentials* ssl_oauth2_creds =
grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds,
nullptr);
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_oauth2_creds);
grpc_channel_args_destroy(new_client_args);
grpc_channel_credentials_release(ssl_creds);
grpc_call_credentials_release(oauth2_creds);
grpc_slice_unref(ca_slice);
}
static int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
}
}
return 0;
}
static void processor_destroy(void* state) {
test_processor_state* s = static_cast<test_processor_state*>(state);
GPR_ASSERT((s->pseudo_refcount--) == 1);
gpr_free(s);
}
static grpc_auth_metadata_processor test_processor_create(int failing) {
test_processor_state* s =
static_cast<test_processor_state*>(gpr_malloc(sizeof(*s)));
grpc_auth_metadata_processor result;
s->pseudo_refcount = 1;
result.state = s;
result.destroy = processor_destroy;
if (failing) {
result.process = process_oauth2_failure;
} else {
result.process = process_oauth2_success;
}
return result;
}
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_server_credentials* creds =
reinterpret_cast<grpc_ssl_server_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_server_credentials_set_auth_metadata_processor(
ssl_creds, test_processor_create(fail_server_auth_check(server_args)));
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/simple_ssl_with_oauth2_fullstack_tls1_3",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_DOES_NOT_SUPPORT_CLIENT_HANDSHAKE_COMPLETE_FIRST,
"foo.test.google.fr", chttp2_create_fixture_secure_fullstack_tls1_3,
chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack,
chttp2_tear_down_secure_fullstack},
};
"foo.test.google.fr",
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<Oauth2Fixture>(grpc_tls_version::TLS1_3);
}}};
int main(int argc, char** argv) {
size_t i;

@ -18,100 +18,82 @@
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/proxy.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_fixture_data {
grpc_end2end_proxy* proxy;
} fullstack_fixture_data;
class ProxyFixture : public CoreTestFixture {
public:
ProxyFixture(const grpc_core::ChannelArgs& client_args,
const grpc_core::ChannelArgs& server_args)
: proxy_(grpc_end2end_proxy_create(&proxy_def_, client_args.ToC().get(),
server_args.ToC().get())) {}
~ProxyFixture() override { grpc_end2end_proxy_destroy(proxy_); }
static grpc_server* create_proxy_server(const char* port,
private:
static grpc_server* CreateProxyServer(const char* port,
const grpc_channel_args* server_args) {
grpc_server* s = grpc_server_create(server_args, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(s, port, server_creds));
grpc_server_credentials_release(server_creds);
return s;
}
grpc_server* s = grpc_server_create(server_args, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(s, port, server_creds));
grpc_server_credentials_release(server_creds);
return s;
}
static grpc_channel* create_proxy_client(const char* target,
static grpc_channel* CreateProxyClient(const char* target,
const grpc_channel_args* client_args) {
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
grpc_channel* channel = grpc_channel_create(target, creds, client_args);
grpc_channel_credentials_release(creds);
return channel;
}
static const grpc_end2end_proxy_def proxy_def = {create_proxy_server,
create_proxy_client};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
const grpc_channel_args* client_args,
const grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
gpr_malloc(sizeof(fullstack_fixture_data)));
memset(&f, 0, sizeof(f));
ffd->proxy = grpc_end2end_proxy_create(&proxy_def, client_args, server_args);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(
grpc_end2end_proxy_get_client_target(ffd->proxy), creds, client_args);
grpc_channel_credentials_release(creds);
GPR_ASSERT(f->client);
}
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
grpc_channel* channel = grpc_channel_create(target, creds, client_args);
grpc_channel_credentials_release(creds);
return channel;
}
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
grpc_server* MakeServer(const grpc_core::ChannelArgs& args) override {
auto* server = grpc_server_create(args.ToC().get(), nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(
server, grpc_end2end_proxy_get_server_port(proxy_), server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(server);
return server;
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(
f->server, grpc_end2end_proxy_get_server_port(ffd->proxy), server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_end2end_proxy_destroy(ffd->proxy);
gpr_free(ffd);
}
grpc_channel* MakeClient(const grpc_core::ChannelArgs& args) override {
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
auto* client = grpc_channel_create(
grpc_end2end_proxy_get_client_target(proxy_), creds, args.ToC().get());
grpc_channel_credentials_release(creds);
GPR_ASSERT(client);
return client;
}
const grpc_end2end_proxy_def proxy_def_ = {CreateProxyServer,
CreateProxyClient};
grpc_end2end_proxy* proxy_;
};
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack+proxy",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_REQUEST_PROXYING |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
nullptr,
[](const grpc_core::ChannelArgs& client_args,
const grpc_core::ChannelArgs& server_args) {
return std::make_unique<ProxyFixture>(client_args, server_args);
}},
};
int main(int argc, char** argv) {

@ -16,145 +16,30 @@
//
//
#include <string.h>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_args_preconditioning.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/port.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/surface/server.h"
#include "src/core/lib/transport/transport.h"
#include "src/core/lib/transport/transport_fwd.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/sockpair_fixture.h"
#include "test/core/util/test_config.h"
#ifdef GRPC_POSIX_SOCKET
#include <unistd.h>
#endif
// chttp2 transport that is immediately available (used for testing
// connected_channel without a client_channel
struct custom_fixture_data {
grpc_endpoint_pair ep;
};
static void server_setup_transport(void* ts, grpc_transport* transport) {
grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts);
grpc_core::ExecCtx exec_ctx;
custom_fixture_data* fixture_data =
static_cast<custom_fixture_data*>(f->fixture_data);
grpc_endpoint_add_to_pollset(fixture_data->ep.server, grpc_cq_pollset(f->cq));
grpc_core::Server* core_server = grpc_core::Server::FromC(f->server);
grpc_error_handle error = core_server->SetupTransport(
transport, nullptr, core_server->channel_args(), nullptr);
if (error.ok()) {
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
grpc_transport_destroy(transport);
}
}
typedef struct {
grpc_end2end_test_fixture* f;
const grpc_channel_args* client_args;
} sp_client_setup;
static void client_setup_transport(void* ts, grpc_transport* transport) {
sp_client_setup* cs = static_cast<sp_client_setup*>(ts);
auto args = grpc_core::ChannelArgs::FromC(cs->client_args)
.Set(GRPC_ARG_DEFAULT_AUTHORITY, "test-authority");
auto channel = grpc_core::Channel::Create(
"socketpair-target", args, GRPC_CLIENT_DIRECT_CHANNEL, transport);
if (channel.ok()) {
cs->f->client = channel->release()->c_ptr();
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
cs->f->client = grpc_lame_client_channel_create(
nullptr, static_cast<grpc_status_code>(channel.status().code()),
"lame channel");
grpc_transport_destroy(transport);
}
}
static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
custom_fixture_data* fixture_data = static_cast<custom_fixture_data*>(
gpr_malloc(sizeof(custom_fixture_data)));
grpc_end2end_test_fixture f;
memset(&f, 0, sizeof(f));
f.fixture_data = fixture_data;
f.cq = grpc_completion_queue_create_for_next(nullptr);
fixture_data->ep = grpc_iomgr_create_endpoint_pair("fixture", nullptr);
return f;
}
static void chttp2_init_client_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_core::ExecCtx exec_ctx;
auto* fixture_data = static_cast<custom_fixture_data*>(f->fixture_data);
grpc_transport* transport;
sp_client_setup cs;
cs.client_args = client_args;
cs.f = f;
auto client_channel_args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(client_args);
transport = grpc_create_chttp2_transport(client_channel_args,
fixture_data->ep.client, true);
client_setup_transport(&cs, transport);
GPR_ASSERT(f->client);
}
static void chttp2_init_server_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_core::ExecCtx exec_ctx;
auto* fixture_data = static_cast<custom_fixture_data*>(f->fixture_data);
grpc_transport* transport;
GPR_ASSERT(!f->server);
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_start(f->server);
auto server_channel_args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(server_args);
transport = grpc_create_chttp2_transport(server_channel_args,
fixture_data->ep.server, false);
server_setup_transport(f, transport);
}
static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) {
grpc_core::ExecCtx exec_ctx;
gpr_free(f->fixture_data);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/socketpair", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, nullptr,
chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<SockpairFixture>(grpc_core::ChannelArgs());
}},
};
int main(int argc, char** argv) {

@ -18,137 +18,22 @@
#include <string.h>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_args_preconditioning.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/surface/server.h"
#include "src/core/lib/transport/transport.h"
#include "src/core/lib/transport/transport_fwd.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/sockpair_fixture.h"
#include "test/core/util/test_config.h"
// chttp2 transport that is immediately available (used for testing
// connected_channel without a client_channel
struct custom_fixture_data {
grpc_endpoint_pair ep;
};
static void server_setup_transport(void* ts, grpc_transport* transport) {
grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts);
grpc_core::ExecCtx exec_ctx;
custom_fixture_data* fixture_data =
static_cast<custom_fixture_data*>(f->fixture_data);
grpc_endpoint_add_to_pollset(fixture_data->ep.server, grpc_cq_pollset(f->cq));
grpc_core::Server* core_server = grpc_core::Server::FromC(f->server);
grpc_error_handle error = core_server->SetupTransport(
transport, nullptr, core_server->channel_args(), nullptr);
if (error.ok()) {
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
grpc_transport_destroy(transport);
}
}
typedef struct {
grpc_end2end_test_fixture* f;
const grpc_channel_args* client_args;
} sp_client_setup;
static void client_setup_transport(void* ts, grpc_transport* transport) {
sp_client_setup* cs = static_cast<sp_client_setup*>(ts);
auto args = grpc_core::ChannelArgs::FromC(cs->client_args)
.Set(GRPC_ARG_DEFAULT_AUTHORITY, "test-authority");
auto channel = grpc_core::Channel::Create(
"socketpair-target", args, GRPC_CLIENT_DIRECT_CHANNEL, transport);
if (channel.ok()) {
cs->f->client = channel->release()->c_ptr();
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
cs->f->client = grpc_lame_client_channel_create(
nullptr, static_cast<grpc_status_code>(channel.status().code()),
"lame channel");
grpc_transport_destroy(transport);
}
}
static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
custom_fixture_data* fixture_data = static_cast<custom_fixture_data*>(
gpr_malloc(sizeof(custom_fixture_data)));
grpc_end2end_test_fixture f;
memset(&f, 0, sizeof(f));
f.fixture_data = fixture_data;
f.cq = grpc_completion_queue_create_for_next(nullptr);
fixture_data->ep = grpc_iomgr_create_endpoint_pair("fixture", nullptr);
return f;
}
static void chttp2_init_client_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_core::ExecCtx exec_ctx;
auto* fixture_data = static_cast<custom_fixture_data*>(f->fixture_data);
grpc_transport* transport;
sp_client_setup cs;
auto client_channel_args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(client_args);
cs.client_args = client_channel_args.ToC().release();
cs.f = f;
transport = grpc_create_chttp2_transport(client_channel_args,
fixture_data->ep.client, true);
client_setup_transport(&cs, transport);
grpc_channel_args_destroy(cs.client_args);
GPR_ASSERT(f->client);
}
static void chttp2_init_server_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_core::ExecCtx exec_ctx;
auto* fixture_data = static_cast<custom_fixture_data*>(f->fixture_data);
grpc_transport* transport;
GPR_ASSERT(!f->server);
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_start(f->server);
auto server_channel_args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(server_args);
transport = grpc_create_chttp2_transport(server_channel_args,
fixture_data->ep.server, false);
server_setup_transport(f, transport);
}
static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) {
grpc_core::ExecCtx exec_ctx;
gpr_free(f->fixture_data);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/socketpair", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, nullptr,
chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<SockpairFixture>(grpc_core::ChannelArgs());
}},
};
int main(int argc, char** argv) {

@ -18,150 +18,26 @@
#include <string.h>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_args_preconditioning.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/surface/server.h"
#include "src/core/lib/transport/transport.h"
#include "src/core/lib/transport/transport_fwd.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/sockpair_fixture.h"
#include "test/core/util/test_config.h"
// chttp2 transport that is immediately available (used for testing
// connected_channel without a client_channel
struct custom_fixture_data {
grpc_endpoint_pair ep;
};
static void server_setup_transport(void* ts, grpc_transport* transport) {
grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts);
grpc_core::ExecCtx exec_ctx;
custom_fixture_data* fixture_data =
static_cast<custom_fixture_data*>(f->fixture_data);
grpc_endpoint_add_to_pollset(fixture_data->ep.server, grpc_cq_pollset(f->cq));
grpc_core::Server* core_server = grpc_core::Server::FromC(f->server);
grpc_error_handle error = core_server->SetupTransport(
transport, nullptr, core_server->channel_args(), nullptr);
if (error.ok()) {
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
grpc_transport_destroy(transport);
}
}
typedef struct {
grpc_end2end_test_fixture* f;
const grpc_channel_args* client_args;
} sp_client_setup;
static void client_setup_transport(void* ts, grpc_transport* transport) {
sp_client_setup* cs = static_cast<sp_client_setup*>(ts);
auto args = grpc_core::ChannelArgs::FromC(cs->client_args)
.Set(GRPC_ARG_DEFAULT_AUTHORITY, "test-authority");
auto channel = grpc_core::Channel::Create(
"socketpair-target", args, GRPC_CLIENT_DIRECT_CHANNEL, transport);
if (channel.ok()) {
cs->f->client = channel->release()->c_ptr();
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
cs->f->client = grpc_lame_client_channel_create(
nullptr, static_cast<grpc_status_code>(channel.status().code()),
"lame channel");
grpc_transport_destroy(transport);
}
}
static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
custom_fixture_data* fixture_data = static_cast<custom_fixture_data*>(
gpr_malloc(sizeof(custom_fixture_data)));
grpc_end2end_test_fixture f;
memset(&f, 0, sizeof(f));
f.fixture_data = fixture_data;
f.cq = grpc_completion_queue_create_for_next(nullptr);
grpc_arg a[3];
a[0].key = const_cast<char*>(GRPC_ARG_TCP_READ_CHUNK_SIZE);
a[0].type = GRPC_ARG_INTEGER;
a[0].value.integer = 1;
a[1].key = const_cast<char*>(GRPC_ARG_TCP_MIN_READ_CHUNK_SIZE);
a[1].type = GRPC_ARG_INTEGER;
a[1].value.integer = 1;
a[2].key = const_cast<char*>(GRPC_ARG_TCP_MAX_READ_CHUNK_SIZE);
a[2].type = GRPC_ARG_INTEGER;
a[2].value.integer = 1;
grpc_channel_args args = {GPR_ARRAY_SIZE(a), a};
fixture_data->ep = grpc_iomgr_create_endpoint_pair("fixture", &args);
return f;
}
static void chttp2_init_client_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_core::ExecCtx exec_ctx;
auto* fixture_data = static_cast<custom_fixture_data*>(f->fixture_data);
grpc_transport* transport;
sp_client_setup cs;
auto client_channel_args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(client_args);
cs.client_args = client_channel_args.ToC().release();
cs.f = f;
transport = grpc_create_chttp2_transport(client_channel_args,
fixture_data->ep.client, true);
client_setup_transport(&cs, transport);
grpc_channel_args_destroy(cs.client_args);
GPR_ASSERT(f->client);
}
static void chttp2_init_server_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_core::ExecCtx exec_ctx;
auto* fixture_data = static_cast<custom_fixture_data*>(f->fixture_data);
grpc_transport* transport;
GPR_ASSERT(!f->server);
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_start(f->server);
auto server_channel_args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(server_args);
transport = grpc_create_chttp2_transport(server_channel_args,
fixture_data->ep.server, false);
server_setup_transport(f, transport);
}
static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) {
grpc_core::ExecCtx exec_ctx;
gpr_free(f->fixture_data);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
{"chttp2/socketpair_one_byte_at_a_time",
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, nullptr,
chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
static CoreTestConfiguration configs[] = {
{"chttp2/socketpair", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, nullptr,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<SockpairFixture>(
grpc_core::ChannelArgs()
.Set(GRPC_ARG_TCP_READ_CHUNK_SIZE, 1)
.Set(GRPC_ARG_TCP_MIN_READ_CHUNK_SIZE, 1)
.Set(GRPC_ARG_TCP_MAX_READ_CHUNK_SIZE, 1));
}},
};
int main(int argc, char** argv) {

@ -18,143 +18,41 @@
#include <string.h>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_args_preconditioning.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/surface/server.h"
#include "src/core/lib/transport/transport.h"
#include "src/core/lib/transport/transport_fwd.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/sockpair_fixture.h"
#include "test/core/util/test_config.h"
// chttp2 transport that is immediately available (used for testing
// connected_channel without a client_channel)
class SockpairWithMinstackFixture : public SockpairFixture {
public:
using SockpairFixture::SockpairFixture;
struct custom_fixture_data {
grpc_endpoint_pair ep;
};
static void server_setup_transport(void* ts, grpc_transport* transport) {
grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts);
grpc_core::ExecCtx exec_ctx;
custom_fixture_data* fixture_data =
static_cast<custom_fixture_data*>(f->fixture_data);
grpc_endpoint_add_to_pollset(fixture_data->ep.server, grpc_cq_pollset(f->cq));
grpc_core::Server* core_server = grpc_core::Server::FromC(f->server);
grpc_error_handle error = core_server->SetupTransport(
transport, nullptr, core_server->channel_args(), nullptr);
if (error == absl::OkStatus()) {
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
grpc_transport_destroy(transport);
private:
grpc_core::ChannelArgs MutateClientArgs(
grpc_core::ChannelArgs args) override {
return args.Set(GRPC_ARG_MINIMAL_STACK, true);
}
}
typedef struct {
grpc_end2end_test_fixture* f;
const grpc_channel_args* client_args;
} sp_client_setup;
static void client_setup_transport(void* ts, grpc_transport* transport) {
sp_client_setup* cs = static_cast<sp_client_setup*>(ts);
auto args = grpc_core::ChannelArgs::FromC(cs->client_args)
.Set(GRPC_ARG_MINIMAL_STACK, true)
.Set(GRPC_ARG_DEFAULT_AUTHORITY, "test-authority");
auto channel = grpc_core::Channel::Create(
"socketpair-target", args, GRPC_CLIENT_DIRECT_CHANNEL, transport);
if (channel.ok()) {
cs->f->client = channel->release()->c_ptr();
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
cs->f->client = grpc_lame_client_channel_create(
nullptr, static_cast<grpc_status_code>(channel.status().code()),
"lame channel");
grpc_transport_destroy(transport);
grpc_core::ChannelArgs MutateServerArgs(
grpc_core::ChannelArgs args) override {
return args.Set(GRPC_ARG_MINIMAL_STACK, true);
}
}
static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
custom_fixture_data* fixture_data = static_cast<custom_fixture_data*>(
gpr_malloc(sizeof(custom_fixture_data)));
grpc_end2end_test_fixture f;
memset(&f, 0, sizeof(f));
f.fixture_data = fixture_data;
f.cq = grpc_completion_queue_create_for_next(nullptr);
fixture_data->ep = grpc_iomgr_create_endpoint_pair("fixture", nullptr);
return f;
}
static void chttp2_init_client_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_core::ExecCtx exec_ctx;
auto* fixture_data = static_cast<custom_fixture_data*>(f->fixture_data);
grpc_transport* transport;
sp_client_setup cs;
auto final_client_args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(client_args)
.Set(GRPC_ARG_MINIMAL_STACK, true);
auto c_client_args = final_client_args.ToC();
cs.client_args = c_client_args.get();
cs.f = f;
transport = grpc_create_chttp2_transport(final_client_args,
fixture_data->ep.client, true);
client_setup_transport(&cs, transport);
GPR_ASSERT(f->client);
}
static void chttp2_init_server_socketpair(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_core::ExecCtx exec_ctx;
auto* fixture_data = static_cast<custom_fixture_data*>(f->fixture_data);
grpc_transport* transport;
GPR_ASSERT(!f->server);
f->server = grpc_server_create(grpc_core::ChannelArgs::FromC(server_args)
.Set(GRPC_ARG_MINIMAL_STACK, true)
.ToC()
.get(),
nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_start(f->server);
transport = grpc_create_chttp2_transport(
grpc_core::Server::FromC(f->server)->channel_args(),
fixture_data->ep.server, false);
server_setup_transport(f, transport);
}
static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) {
grpc_core::ExecCtx exec_ctx;
gpr_free(f->fixture_data);
}
};
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/socketpair+minstack",
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_DOES_NOT_SUPPORT_DEADLINES,
nullptr, chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
nullptr,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<SockpairWithMinstackFixture>(
grpc_core::ChannelArgs());
}},
};
int main(int argc, char** argv) {

@ -0,0 +1,139 @@
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_TEST_CORE_END2END_FIXTURES_H2_SSL_CRED_RELOAD_FIXTURE_H
#define GRPC_TEST_CORE_END2END_FIXTURES_H2_SSL_CRED_RELOAD_FIXTURE_H
#include <stddef.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
class SslCredReloadFixture : public SecureFixture {
public:
explicit SslCredReloadFixture(grpc_tls_version tls_version)
: tls_version_(tls_version) {}
static const char* CaCertPath() { return "src/core/tsi/test_creds/ca.pem"; }
static const char* CertPath() {
return "src/core/tsi/test_creds/server1.pem";
}
static const char* KeyPath() { return "src/core/tsi/test_creds/server1.key"; }
private:
grpc_core::ChannelArgs MutateClientArgs(
grpc_core::ChannelArgs args) override {
return args.Set(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, "foo.test.google.fr");
}
grpc_channel_credentials* MakeClientCreds(
const grpc_core::ChannelArgs&) override {
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
if (ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_credentials* creds =
reinterpret_cast<grpc_ssl_credentials*>(ssl_creds);
creds->set_min_tls_version(tls_version_);
creds->set_max_tls_version(tls_version_);
}
return ssl_creds;
}
grpc_server_credentials* MakeServerCreds(
const grpc_core::ChannelArgs& args) override {
server_credential_reloaded_ = false;
grpc_ssl_server_credentials_options* options =
grpc_ssl_server_credentials_create_options_using_config_fetcher(
GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE,
ssl_server_certificate_config_callback, this);
grpc_server_credentials* ssl_creds =
grpc_ssl_server_credentials_create_with_options(options);
if (ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_server_credentials* creds =
reinterpret_cast<grpc_ssl_server_credentials*>(ssl_creds);
creds->set_min_tls_version(tls_version_);
creds->set_max_tls_version(tls_version_);
}
if (args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
return ssl_creds;
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
GPR_ASSERT(state == nullptr);
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
grpc_ssl_certificate_config_reload_status SslServerCertificateConfigCallback(
grpc_ssl_server_certificate_config** config) {
if (config == nullptr) {
return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_FAIL;
}
if (!server_credential_reloaded_) {
grpc_slice ca_slice, cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(CaCertPath(), 1, &ca_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(CertPath(), 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(KeyPath(), 1, &key_slice)));
const char* ca_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(ca_slice);
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
*config = grpc_ssl_server_certificate_config_create(
ca_cert, &pem_key_cert_pair, 1);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
grpc_slice_unref(ca_slice);
server_credential_reloaded_ = true;
return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW;
} else {
return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED;
}
}
static grpc_ssl_certificate_config_reload_status
ssl_server_certificate_config_callback(
void* user_data, grpc_ssl_server_certificate_config** config) {
return static_cast<SslCredReloadFixture*>(user_data)
->SslServerCertificateConfigCallback(config);
}
grpc_tls_version tls_version_;
bool server_credential_reloaded_ = false;
};
#endif // GRPC_TEST_CORE_END2END_FIXTURES_H2_SSL_CRED_RELOAD_FIXTURE_H

@ -18,208 +18,31 @@
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/h2_ssl_cred_reload_fixture.h"
#include "test/core/util/test_config.h"
#define CA_CERT_PATH "src/core/tsi/test_creds/ca.pem"
#define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem"
#define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key"
struct fullstack_secure_fixture_data {
std::string localaddr;
grpc_tls_version tls_version;
bool server_credential_reloaded = false;
};
static grpc_ssl_certificate_config_reload_status
ssl_server_certificate_config_callback(
void* user_data, grpc_ssl_server_certificate_config** config) {
if (config == nullptr) {
return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_FAIL;
}
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(user_data);
if (!ffd->server_credential_reloaded) {
grpc_slice ca_slice, cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(CA_CERT_PATH, 1, &ca_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* ca_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(ca_slice);
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
*config = grpc_ssl_server_certificate_config_create(ca_cert,
&pem_key_cert_pair, 1);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
grpc_slice_unref(ca_slice);
ffd->server_credential_reloaded = true;
return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW;
} else {
return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED;
}
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/, grpc_tls_version tls_version) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
ffd->tls_version = tls_version;
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack_tls1_2(
const grpc_channel_args* client_args,
const grpc_channel_args* server_args) {
return chttp2_create_fixture_secure_fullstack(client_args, server_args,
grpc_tls_version::TLS1_2);
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
GPR_ASSERT(state == nullptr);
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
ffd->server_credential_reloaded = false;
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
delete ffd;
}
static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_credentials* creds =
reinterpret_cast<grpc_ssl_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds);
grpc_channel_args_destroy(new_client_args);
}
static int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
}
}
return 0;
}
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_ssl_server_credentials_options* options =
grpc_ssl_server_credentials_create_options_using_config_fetcher(
GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE,
ssl_server_certificate_config_callback, f->fixture_data);
grpc_server_credentials* ssl_creds =
grpc_ssl_server_credentials_create_with_options(options);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_server_credentials* creds =
reinterpret_cast<grpc_ssl_server_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
if (fail_server_auth_check(server_args)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/simple_ssl_fullstack_tls1_2",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
"foo.test.google.fr", chttp2_create_fixture_secure_fullstack_tls1_2,
chttp2_init_client_simple_ssl_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack,
chttp2_tear_down_secure_fullstack},
"foo.test.google.fr",
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<SslCredReloadFixture>(TLS1_2);
}},
};
int main(int argc, char** argv) {
@ -227,7 +50,8 @@ int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
grpc_end2end_tests_pre_init();
GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path, CA_CERT_PATH);
GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path,
SslCredReloadFixture::CaCertPath());
grpc_init();

@ -18,217 +18,40 @@
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/h2_ssl_cred_reload_fixture.h"
#include "test/core/util/test_config.h"
#define CA_CERT_PATH "src/core/tsi/test_creds/ca.pem"
#define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem"
#define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key"
struct fullstack_secure_fixture_data {
std::string localaddr;
grpc_tls_version tls_version;
bool server_credential_reloaded = false;
};
static grpc_ssl_certificate_config_reload_status
ssl_server_certificate_config_callback(
void* user_data, grpc_ssl_server_certificate_config** config) {
if (config == nullptr) {
return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_FAIL;
}
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(user_data);
if (!ffd->server_credential_reloaded) {
grpc_slice ca_slice, cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(CA_CERT_PATH, 1, &ca_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* ca_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(ca_slice);
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
*config = grpc_ssl_server_certificate_config_create(ca_cert,
&pem_key_cert_pair, 1);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
grpc_slice_unref(ca_slice);
ffd->server_credential_reloaded = true;
return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW;
} else {
return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED;
}
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/, grpc_tls_version tls_version) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
ffd->tls_version = tls_version;
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack_tls1_3(
const grpc_channel_args* client_args,
const grpc_channel_args* server_args) {
return chttp2_create_fixture_secure_fullstack(client_args, server_args,
grpc_tls_version::TLS1_3);
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
GPR_ASSERT(state == nullptr);
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
ffd->server_credential_reloaded = false;
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
delete ffd;
}
static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_credentials* creds =
reinterpret_cast<grpc_ssl_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds);
grpc_channel_args_destroy(new_client_args);
}
static int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
}
}
return 0;
}
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_ssl_server_credentials_options* options =
grpc_ssl_server_credentials_create_options_using_config_fetcher(
GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE,
ssl_server_certificate_config_callback, f->fixture_data);
grpc_server_credentials* ssl_creds =
grpc_ssl_server_credentials_create_with_options(options);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_server_credentials* creds =
reinterpret_cast<grpc_ssl_server_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
if (fail_server_auth_check(server_args)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/simple_ssl_fullstack_tls1_3",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_DOES_NOT_SUPPORT_CLIENT_HANDSHAKE_COMPLETE_FIRST,
"foo.test.google.fr", chttp2_create_fixture_secure_fullstack_tls1_3,
chttp2_init_client_simple_ssl_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack,
chttp2_tear_down_secure_fullstack},
};
"foo.test.google.fr",
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<SslCredReloadFixture>(TLS1_3);
}}};
int main(int argc, char** argv) {
size_t i;
grpc::testing::TestEnvironment env(&argc, argv);
grpc_end2end_tests_pre_init();
GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path, CA_CERT_PATH);
GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path,
SslCredReloadFixture::CaCertPath());
grpc_init();

@ -18,11 +18,13 @@
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
@ -39,72 +41,6 @@
#define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem"
#define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key"
typedef struct fullstack_secure_fixture_data {
grpc_end2end_proxy* proxy;
} fullstack_secure_fixture_data;
static grpc_server* create_proxy_server(const char* port,
const grpc_channel_args* server_args) {
grpc_server* s = grpc_server_create(server_args, nullptr);
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
GPR_ASSERT(grpc_server_add_http2_port(s, port, ssl_creds));
grpc_server_credentials_release(ssl_creds);
return s;
}
static grpc_channel* create_proxy_client(const char* target,
const grpc_channel_args* client_args) {
grpc_channel* channel;
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
channel = grpc_channel_create(target, ssl_creds, new_client_args);
grpc_channel_credentials_release(ssl_creds);
{
grpc_core::ExecCtx exec_ctx;
grpc_channel_args_destroy(new_client_args);
}
return channel;
}
static const grpc_end2end_proxy_def proxy_def = {create_proxy_server,
create_proxy_client};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args* client_args,
const grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
memset(&f, 0, sizeof(f));
ffd->proxy = grpc_end2end_proxy_create(&proxy_def, client_args, server_args);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
@ -114,106 +50,118 @@ static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(
grpc_end2end_proxy_get_client_target(ffd->proxy), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
class SslProxyFixture : public CoreTestFixture {
public:
SslProxyFixture(const grpc_core::ChannelArgs& client_args,
const grpc_core::ChannelArgs& server_args)
: proxy_(grpc_end2end_proxy_create(&proxy_def_, client_args.ToC().get(),
server_args.ToC().get())) {}
~SslProxyFixture() override { grpc_end2end_proxy_destroy(proxy_); }
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
private:
static grpc_server* CreateProxyServer(const char* port,
const grpc_channel_args* server_args) {
grpc_server* s = grpc_server_create(server_args, nullptr);
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
GPR_ASSERT(grpc_server_add_http2_port(s, port, ssl_creds));
grpc_server_credentials_release(ssl_creds);
return s;
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(
f->server, grpc_end2end_proxy_get_server_port(ffd->proxy), server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
grpc_end2end_proxy_destroy(ffd->proxy);
gpr_free(ffd);
}
static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds);
{
grpc_core::ExecCtx exec_ctx;
grpc_channel_args_destroy(new_client_args);
static grpc_channel* CreateProxyClient(const char* target,
const grpc_channel_args* client_args) {
grpc_channel* channel;
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
channel = grpc_channel_create(target, ssl_creds, new_client_args);
grpc_channel_credentials_release(ssl_creds);
{
grpc_core::ExecCtx exec_ctx;
grpc_channel_args_destroy(new_client_args);
}
return channel;
}
}
static int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
grpc_server* MakeServer(const grpc_core::ChannelArgs& args) override {
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
if (args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
auto* server = grpc_server_create(args.ToC().get(), nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
GPR_ASSERT(grpc_server_add_http2_port(
server, grpc_end2end_proxy_get_server_port(proxy_), ssl_creds));
grpc_server_credentials_release(ssl_creds);
grpc_server_start(server);
return server;
}
return 0;
}
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
if (fail_server_auth_check(server_args)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
grpc_channel* MakeClient(const grpc_core::ChannelArgs& args) override {
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
auto* client = grpc_channel_create(
grpc_end2end_proxy_get_client_target(proxy_), ssl_creds,
args.Set(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, "foo.test.google.fr")
.ToC()
.get());
GPR_ASSERT(client != nullptr);
grpc_channel_credentials_release(ssl_creds);
return client;
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
const grpc_end2end_proxy_def proxy_def_ = {CreateProxyServer,
CreateProxyClient};
grpc_end2end_proxy* proxy_;
};
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/simple_ssl_fullstack",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_REQUEST_PROXYING |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
"foo.test.google.fr", chttp2_create_fixture_secure_fullstack,
chttp2_init_client_simple_ssl_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack,
chttp2_tear_down_secure_fullstack},
"foo.test.google.fr",
[](const grpc_core::ChannelArgs& client_args,
const grpc_core::ChannelArgs& server_args) {
return std::make_unique<SslProxyFixture>(client_args, server_args);
}},
};
int main(int argc, char** argv) {

@ -18,187 +18,38 @@
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/h2_ssl_tls_common.h"
#include "test/core/util/test_config.h"
#define CA_CERT_PATH "src/core/tsi/test_creds/ca.pem"
#define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem"
#define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key"
struct fullstack_secure_fixture_data {
std::string localaddr;
grpc_tls_version tls_version;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/, grpc_tls_version tls_version) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
ffd->tls_version = tls_version;
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack_tls1_2(
const grpc_channel_args* client_args,
const grpc_channel_args* server_args) {
return chttp2_create_fixture_secure_fullstack(client_args, server_args,
grpc_tls_version::TLS1_2);
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
GPR_ASSERT(state == nullptr);
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
delete ffd;
}
static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_credentials* creds =
reinterpret_cast<grpc_ssl_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds);
grpc_channel_args_destroy(new_client_args);
}
static int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
}
}
return 0;
}
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_server_credentials* creds =
reinterpret_cast<grpc_ssl_server_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
if (fail_server_auth_check(server_args)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/simple_ssl_fullstack_tls1_2",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
"foo.test.google.fr", chttp2_create_fixture_secure_fullstack_tls1_2,
chttp2_init_client_simple_ssl_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack,
chttp2_tear_down_secure_fullstack},
"foo.test.google.fr",
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<SslTlsFixture>(grpc_tls_version::TLS1_2);
}},
};
int main(int argc, char** argv) {
size_t i;
grpc::testing::TestEnvironment env(&argc, argv);
grpc_end2end_tests_pre_init();
GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path, CA_CERT_PATH);
GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path,
SslTlsFixture::CaCertPath());
grpc_init();

@ -18,188 +18,38 @@
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/h2_ssl_tls_common.h"
#include "test/core/util/test_config.h"
#define CA_CERT_PATH "src/core/tsi/test_creds/ca.pem"
#define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem"
#define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key"
struct fullstack_secure_fixture_data {
std::string localaddr;
grpc_tls_version tls_version;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/, grpc_tls_version tls_version) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
ffd->tls_version = tls_version;
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack_tls1_3(
const grpc_channel_args* client_args,
const grpc_channel_args* server_args) {
return chttp2_create_fixture_secure_fullstack(client_args, server_args,
grpc_tls_version::TLS1_3);
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
GPR_ASSERT(state == nullptr);
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
delete ffd;
}
static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_credentials* creds =
reinterpret_cast<grpc_ssl_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds);
grpc_channel_args_destroy(new_client_args);
}
static int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
}
}
return 0;
}
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
if (f != nullptr && ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_server_credentials* creds =
reinterpret_cast<grpc_ssl_server_credentials*>(ssl_creds);
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
creds->set_min_tls_version(ffd->tls_version);
creds->set_max_tls_version(ffd->tls_version);
}
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
if (fail_server_auth_check(server_args)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/simple_ssl_fullstack_tls1_3",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER |
FEATURE_MASK_DOES_NOT_SUPPORT_CLIENT_HANDSHAKE_COMPLETE_FIRST,
"foo.test.google.fr", chttp2_create_fixture_secure_fullstack_tls1_3,
chttp2_init_client_simple_ssl_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack,
chttp2_tear_down_secure_fullstack},
};
"foo.test.google.fr",
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<SslTlsFixture>(grpc_tls_version::TLS1_3);
}}};
int main(int argc, char** argv) {
size_t i;
grpc::testing::TestEnvironment env(&argc, argv);
grpc_end2end_tests_pre_init();
GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path, CA_CERT_PATH);
GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path,
SslTlsFixture::CaCertPath());
grpc_init();

@ -0,0 +1,110 @@
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_TEST_CORE_END2END_FIXTURES_H2_SSL_TLS_COMMON_H
#define GRPC_TEST_CORE_END2END_FIXTURES_H2_SSL_TLS_COMMON_H
#include <string.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
class SslTlsFixture : public SecureFixture {
public:
explicit SslTlsFixture(grpc_tls_version tls_version)
: tls_version_(tls_version) {}
static const char* CaCertPath() { return "src/core/tsi/test_creds/ca.pem"; }
static const char* ServerCertPath() {
return "src/core/tsi/test_creds/server1.pem";
}
static const char* ServerKeyPath() {
return "src/core/tsi/test_creds/server1.key";
}
private:
grpc_core::ChannelArgs MutateClientArgs(
grpc_core::ChannelArgs args) override {
return args.Set(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, "foo.test.google.fr");
}
grpc_channel_credentials* MakeClientCreds(
const grpc_core::ChannelArgs&) override {
grpc_channel_credentials* ssl_creds =
grpc_ssl_credentials_create(nullptr, nullptr, nullptr, nullptr);
if (ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_credentials* creds =
reinterpret_cast<grpc_ssl_credentials*>(ssl_creds);
creds->set_min_tls_version(tls_version_);
creds->set_max_tls_version(tls_version_);
}
return ssl_creds;
}
grpc_server_credentials* MakeServerCreds(
const grpc_core::ChannelArgs& args) override {
grpc_slice cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(ServerCertPath(), 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(ServerKeyPath(), 1, &key_slice)));
const char* server_cert =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice);
const char* server_key =
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice);
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {server_key, server_cert};
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create(
nullptr, &pem_key_cert_pair, 1, 0, nullptr);
if (ssl_creds != nullptr) {
// Set the min and max TLS version.
grpc_ssl_server_credentials* creds =
reinterpret_cast<grpc_ssl_server_credentials*>(ssl_creds);
creds->set_min_tls_version(tls_version_);
creds->set_max_tls_version(tls_version_);
}
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
if (args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
return ssl_creds;
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
grpc_process_auth_metadata_done_cb cb,
void* user_data) {
GPR_ASSERT(state == nullptr);
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
grpc_tls_version tls_version_;
};
#endif // GRPC_TEST_CORE_END2END_FIXTURES_H2_SSL_TLS_COMMON_H

@ -16,48 +16,31 @@
//
//
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/h2_tls_common.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
static grpc_end2end_test_fixture
chttp2_create_fixture_async_verifier_cert_watcher(const grpc_channel_args*,
const grpc_channel_args*) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
SetTlsVersion(ffd, SecurityPrimitives::TlsVersion::V_13);
SetCertificateProvider(ffd, SecurityPrimitives::ProviderType::FILE_PROVIDER);
SetCertificateVerifier(
ffd, SecurityPrimitives::VerifierType::EXTERNAL_ASYNC_VERIFIER);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_config config = {
static CoreTestConfiguration config = {
// client: certificate watcher provider + async external verifier
// server: certificate watcher provider + async external verifier
// extra: TLS 1.3
"chttp2/cert_watcher_provider_async_verifier_tls1_3",
kH2TLSFeatureMask,
"foo.test.google.fr",
chttp2_create_fixture_async_verifier_cert_watcher,
chttp2_init_client,
chttp2_init_server,
chttp2_tear_down_secure_fullstack,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<TlsFixture>(
SecurityPrimitives::TlsVersion::V_13,
SecurityPrimitives::ProviderType::FILE_PROVIDER,
SecurityPrimitives::VerifierType::EXTERNAL_ASYNC_VERIFIER);
},
};
int main(int argc, char** argv) {

@ -16,48 +16,31 @@
//
//
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/h2_tls_common.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
static grpc_end2end_test_fixture
chttp2_create_fixture_hostname_verifier_cert_watcher(const grpc_channel_args*,
const grpc_channel_args*) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
SetTlsVersion(ffd, SecurityPrimitives::TlsVersion::V_12);
SetCertificateProvider(ffd, SecurityPrimitives::ProviderType::FILE_PROVIDER);
SetCertificateVerifier(ffd,
SecurityPrimitives::VerifierType::HOSTNAME_VERIFIER);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_config config = {
static CoreTestConfiguration config = {
// client: certificate watcher provider + hostname verifier
// server: certificate watcher provider + sync external verifier
// extra: TLS 1.2
"chttp2/cert_watcher_provider_sync_verifier_tls1_2",
kH2TLSFeatureMask,
"foo.test.google.fr",
chttp2_create_fixture_hostname_verifier_cert_watcher,
chttp2_init_client,
chttp2_init_server,
chttp2_tear_down_secure_fullstack,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<TlsFixture>(
SecurityPrimitives::TlsVersion::V_12,
SecurityPrimitives::ProviderType::FILE_PROVIDER,
SecurityPrimitives::VerifierType::HOSTNAME_VERIFIER);
},
};
int main(int argc, char** argv) {

@ -39,6 +39,7 @@
#include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h"
#include "src/core/lib/slice/slice_internal.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/tls_utils.h"
// For normal TLS connections.
@ -56,120 +57,6 @@ struct SecurityPrimitives {
enum TlsVersion { V_12 = 0, V_13 = 1 } tls_version;
};
struct fullstack_secure_fixture_data {
~fullstack_secure_fixture_data() {
grpc_tls_certificate_provider_release(client_provider);
grpc_tls_certificate_provider_release(server_provider);
grpc_tls_certificate_verifier_release(client_verifier);
grpc_tls_certificate_verifier_release(server_verifier);
}
std::string localaddr;
grpc_tls_version tls_version;
grpc_tls_certificate_provider* client_provider = nullptr;
grpc_tls_certificate_provider* server_provider = nullptr;
grpc_tls_certificate_verifier* client_verifier = nullptr;
grpc_tls_certificate_verifier* server_verifier = nullptr;
bool check_call_host = true;
};
inline void SetTlsVersion(fullstack_secure_fixture_data* ffd,
SecurityPrimitives::TlsVersion tls_version) {
switch (tls_version) {
case SecurityPrimitives::TlsVersion::V_12: {
ffd->tls_version = grpc_tls_version::TLS1_2;
break;
}
case SecurityPrimitives::TlsVersion::V_13: {
ffd->tls_version = grpc_tls_version::TLS1_3;
break;
}
}
}
inline void SetCertificateProvider(
fullstack_secure_fixture_data* ffd,
SecurityPrimitives::ProviderType provider_type) {
switch (provider_type) {
case SecurityPrimitives::ProviderType::STATIC_PROVIDER: {
grpc_slice root_slice, cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(CA_CERT_PATH, 1, &root_slice)));
std::string root_cert =
std::string(grpc_core::StringViewFromSlice(root_slice));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
std::string identity_cert =
std::string(grpc_core::StringViewFromSlice(cert_slice));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
std::string private_key =
std::string(grpc_core::StringViewFromSlice(key_slice));
grpc_tls_identity_pairs* client_pairs = grpc_tls_identity_pairs_create();
grpc_tls_identity_pairs_add_pair(client_pairs, private_key.c_str(),
identity_cert.c_str());
ffd->client_provider = grpc_tls_certificate_provider_static_data_create(
root_cert.c_str(), client_pairs);
grpc_tls_identity_pairs* server_pairs = grpc_tls_identity_pairs_create();
grpc_tls_identity_pairs_add_pair(server_pairs, private_key.c_str(),
identity_cert.c_str());
ffd->server_provider = grpc_tls_certificate_provider_static_data_create(
root_cert.c_str(), server_pairs);
grpc_slice_unref(root_slice);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
break;
}
case SecurityPrimitives::ProviderType::FILE_PROVIDER: {
ffd->client_provider = grpc_tls_certificate_provider_file_watcher_create(
SERVER_KEY_PATH, SERVER_CERT_PATH, CA_CERT_PATH, 1);
ffd->server_provider = grpc_tls_certificate_provider_file_watcher_create(
SERVER_KEY_PATH, SERVER_CERT_PATH, CA_CERT_PATH, 1);
break;
}
}
}
inline void SetCertificateVerifier(
fullstack_secure_fixture_data* ffd,
SecurityPrimitives::VerifierType verifier_type) {
switch (verifier_type) {
case SecurityPrimitives::VerifierType::EXTERNAL_SYNC_VERIFIER: {
auto* client_sync_verifier =
new grpc_core::testing::SyncExternalVerifier(true);
ffd->client_verifier = grpc_tls_certificate_verifier_external_create(
client_sync_verifier->base());
auto* server_sync_verifier =
new grpc_core::testing::SyncExternalVerifier(true);
ffd->server_verifier = grpc_tls_certificate_verifier_external_create(
server_sync_verifier->base());
ffd->check_call_host = false;
break;
}
case SecurityPrimitives::VerifierType::EXTERNAL_ASYNC_VERIFIER: {
auto* client_async_verifier =
new grpc_core::testing::AsyncExternalVerifier(true);
ffd->client_verifier = grpc_tls_certificate_verifier_external_create(
client_async_verifier->base());
auto* server_async_verifier =
new grpc_core::testing::AsyncExternalVerifier(true);
ffd->server_verifier = grpc_tls_certificate_verifier_external_create(
server_async_verifier->base());
ffd->check_call_host = false;
break;
}
case SecurityPrimitives::VerifierType::HOSTNAME_VERIFIER: {
ffd->client_verifier = grpc_tls_certificate_verifier_host_name_create();
// Hostname verifier couldn't be applied to the server side, so we will
// use sync external verifier here.
auto* server_async_verifier =
new grpc_core::testing::AsyncExternalVerifier(true);
ffd->server_verifier = grpc_tls_certificate_verifier_external_create(
server_async_verifier->base());
break;
}
}
}
inline void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
@ -179,119 +66,167 @@ inline void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
inline void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
inline void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
class TlsFixture : public SecureFixture {
public:
TlsFixture(SecurityPrimitives::TlsVersion tls_version,
SecurityPrimitives::ProviderType provider_type,
SecurityPrimitives::VerifierType verifier_type) {
switch (tls_version) {
case SecurityPrimitives::TlsVersion::V_12: {
tls_version_ = grpc_tls_version::TLS1_2;
break;
}
case SecurityPrimitives::TlsVersion::V_13: {
tls_version_ = grpc_tls_version::TLS1_3;
break;
}
}
switch (provider_type) {
case SecurityPrimitives::ProviderType::STATIC_PROVIDER: {
grpc_slice root_slice, cert_slice, key_slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(CA_CERT_PATH, 1, &root_slice)));
std::string root_cert =
std::string(grpc_core::StringViewFromSlice(root_slice));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice)));
std::string identity_cert =
std::string(grpc_core::StringViewFromSlice(cert_slice));
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(SERVER_KEY_PATH, 1, &key_slice)));
std::string private_key =
std::string(grpc_core::StringViewFromSlice(key_slice));
grpc_tls_identity_pairs* client_pairs =
grpc_tls_identity_pairs_create();
grpc_tls_identity_pairs_add_pair(client_pairs, private_key.c_str(),
identity_cert.c_str());
client_provider_ = grpc_tls_certificate_provider_static_data_create(
root_cert.c_str(), client_pairs);
grpc_tls_identity_pairs* server_pairs =
grpc_tls_identity_pairs_create();
grpc_tls_identity_pairs_add_pair(server_pairs, private_key.c_str(),
identity_cert.c_str());
server_provider_ = grpc_tls_certificate_provider_static_data_create(
root_cert.c_str(), server_pairs);
grpc_slice_unref(root_slice);
grpc_slice_unref(cert_slice);
grpc_slice_unref(key_slice);
break;
}
case SecurityPrimitives::ProviderType::FILE_PROVIDER: {
client_provider_ = grpc_tls_certificate_provider_file_watcher_create(
SERVER_KEY_PATH, SERVER_CERT_PATH, CA_CERT_PATH, 1);
server_provider_ = grpc_tls_certificate_provider_file_watcher_create(
SERVER_KEY_PATH, SERVER_CERT_PATH, CA_CERT_PATH, 1);
break;
}
}
switch (verifier_type) {
case SecurityPrimitives::VerifierType::EXTERNAL_SYNC_VERIFIER: {
auto* client_sync_verifier =
new grpc_core::testing::SyncExternalVerifier(true);
client_verifier_ = grpc_tls_certificate_verifier_external_create(
client_sync_verifier->base());
auto* server_sync_verifier =
new grpc_core::testing::SyncExternalVerifier(true);
server_verifier_ = grpc_tls_certificate_verifier_external_create(
server_sync_verifier->base());
check_call_host_ = false;
break;
}
case SecurityPrimitives::VerifierType::EXTERNAL_ASYNC_VERIFIER: {
auto* client_async_verifier =
new grpc_core::testing::AsyncExternalVerifier(true);
client_verifier_ = grpc_tls_certificate_verifier_external_create(
client_async_verifier->base());
auto* server_async_verifier =
new grpc_core::testing::AsyncExternalVerifier(true);
server_verifier_ = grpc_tls_certificate_verifier_external_create(
server_async_verifier->base());
check_call_host_ = false;
break;
}
case SecurityPrimitives::VerifierType::HOSTNAME_VERIFIER: {
client_verifier_ = grpc_tls_certificate_verifier_host_name_create();
// Hostname verifier couldn't be applied to the server side, so we will
// use sync external verifier here.
auto* server_async_verifier =
new grpc_core::testing::AsyncExternalVerifier(true);
server_verifier_ = grpc_tls_certificate_verifier_external_create(
server_async_verifier->base());
break;
}
}
}
~TlsFixture() override {
grpc_tls_certificate_provider_release(client_provider_);
grpc_tls_certificate_provider_release(server_provider_);
grpc_tls_certificate_verifier_release(client_verifier_);
grpc_tls_certificate_verifier_release(server_verifier_);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
inline void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
delete ffd;
}
// Create a TLS channel credential.
inline grpc_channel_credentials* create_tls_channel_credentials(
fullstack_secure_fixture_data* ffd) {
grpc_tls_credentials_options* options = grpc_tls_credentials_options_create();
grpc_tls_credentials_options_set_verify_server_cert(
options, 1 /* = verify server certs */);
options->set_min_tls_version(ffd->tls_version);
options->set_max_tls_version(ffd->tls_version);
// Set credential provider.
grpc_tls_credentials_options_set_certificate_provider(options,
ffd->client_provider);
grpc_tls_credentials_options_watch_root_certs(options);
grpc_tls_credentials_options_watch_identity_key_cert_pairs(options);
// Set credential verifier.
grpc_tls_credentials_options_set_certificate_verifier(options,
ffd->client_verifier);
grpc_tls_credentials_options_set_check_call_host(options,
ffd->check_call_host);
// Create TLS channel credentials.
grpc_channel_credentials* creds = grpc_tls_credentials_create(options);
return creds;
}
// Create a TLS server credential.
inline grpc_server_credentials* create_tls_server_credentials(
fullstack_secure_fixture_data* ffd) {
grpc_tls_credentials_options* options = grpc_tls_credentials_options_create();
options->set_min_tls_version(ffd->tls_version);
options->set_max_tls_version(ffd->tls_version);
// Set credential provider.
grpc_tls_credentials_options_set_certificate_provider(options,
ffd->server_provider);
grpc_tls_credentials_options_watch_root_certs(options);
grpc_tls_credentials_options_watch_identity_key_cert_pairs(options);
// Set client certificate request type.
grpc_tls_credentials_options_set_cert_request_type(
options, GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
// Set credential verifier.
grpc_tls_credentials_options_set_certificate_verifier(options,
ffd->server_verifier);
grpc_server_credentials* creds = grpc_tls_server_credentials_create(options);
return creds;
}
private:
grpc_core::ChannelArgs MutateClientArgs(
grpc_core::ChannelArgs args) override {
return args.Set(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, "foo.test.google.fr");
}
inline void chttp2_init_client(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
grpc_channel_credentials* ssl_creds = create_tls_channel_credentials(
static_cast<fullstack_secure_fixture_data*>(f->fixture_data));
grpc_arg ssl_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr")}};
const grpc_channel_args* new_client_args =
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1);
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds);
grpc_channel_args_destroy(new_client_args);
}
grpc_channel_credentials* MakeClientCreds(
const grpc_core::ChannelArgs&) override {
grpc_tls_credentials_options* options =
grpc_tls_credentials_options_create();
grpc_tls_credentials_options_set_verify_server_cert(
options, 1 /* = verify server certs */);
options->set_min_tls_version(tls_version_);
options->set_max_tls_version(tls_version_);
// Set credential provider.
grpc_tls_credentials_options_set_certificate_provider(options,
client_provider_);
grpc_tls_credentials_options_watch_root_certs(options);
grpc_tls_credentials_options_watch_identity_key_cert_pairs(options);
// Set credential verifier.
grpc_tls_credentials_options_set_certificate_verifier(options,
client_verifier_);
grpc_tls_credentials_options_set_check_call_host(options, check_call_host_);
// Create TLS channel credentials.
grpc_channel_credentials* creds = grpc_tls_credentials_create(options);
return creds;
}
inline int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
grpc_server_credentials* MakeServerCreds(
const grpc_core::ChannelArgs& args) override {
grpc_tls_credentials_options* options =
grpc_tls_credentials_options_create();
options->set_min_tls_version(tls_version_);
options->set_max_tls_version(tls_version_);
// Set credential provider.
grpc_tls_credentials_options_set_certificate_provider(options,
server_provider_);
grpc_tls_credentials_options_watch_root_certs(options);
grpc_tls_credentials_options_watch_identity_key_cert_pairs(options);
// Set client certificate request type.
grpc_tls_credentials_options_set_cert_request_type(
options, GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
// Set credential verifier.
grpc_tls_credentials_options_set_certificate_verifier(options,
server_verifier_);
grpc_server_credentials* creds =
grpc_tls_server_credentials_create(options);
if (args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(creds, processor);
}
return creds;
}
return 0;
}
inline void chttp2_init_server(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
grpc_server_credentials* ssl_creds = create_tls_server_credentials(
static_cast<fullstack_secure_fixture_data*>(f->fixture_data));
if (fail_server_auth_check(server_args)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
grpc_tls_version tls_version_;
grpc_tls_certificate_provider* client_provider_ = nullptr;
grpc_tls_certificate_provider* server_provider_ = nullptr;
grpc_tls_certificate_verifier* client_verifier_ = nullptr;
grpc_tls_certificate_verifier* server_verifier_ = nullptr;
bool check_call_host_ = true;
};
static const uint32_t kH2TLSFeatureMask =
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |

@ -16,48 +16,31 @@
//
//
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/h2_tls_common.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
static grpc_end2end_test_fixture chttp2_create_fixture_simple_fullstack(
const grpc_channel_args*, const grpc_channel_args*) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
SetTlsVersion(ffd, SecurityPrimitives::TlsVersion::V_12);
SetCertificateProvider(ffd,
SecurityPrimitives::ProviderType::STATIC_PROVIDER);
SetCertificateVerifier(
ffd, SecurityPrimitives::VerifierType::EXTERNAL_SYNC_VERIFIER);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_config config = {
static CoreTestConfiguration config = {
// client: static data provider + sync external verifier
// server: static data provider + sync external verifier
// extra: TLS 1.2
"chttp2/simple_ssl_fullstack",
kH2TLSFeatureMask,
"foo.test.google.fr",
chttp2_create_fixture_simple_fullstack,
chttp2_init_client,
chttp2_init_server,
chttp2_tear_down_secure_fullstack,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<TlsFixture>(
SecurityPrimitives::TlsVersion::V_12,
SecurityPrimitives::ProviderType::STATIC_PROVIDER,
SecurityPrimitives::VerifierType::EXTERNAL_SYNC_VERIFIER);
},
};
int main(int argc, char** argv) {

@ -16,48 +16,31 @@
//
//
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/h2_tls_common.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
static grpc_end2end_test_fixture chttp2_create_fixture_async_verifier(
const grpc_channel_args*, const grpc_channel_args*) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
SetTlsVersion(ffd, SecurityPrimitives::TlsVersion::V_13);
SetCertificateProvider(ffd,
SecurityPrimitives::ProviderType::STATIC_PROVIDER);
SetCertificateVerifier(
ffd, SecurityPrimitives::VerifierType::EXTERNAL_ASYNC_VERIFIER);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_config config = {
static CoreTestConfiguration config = {
// client: static data provider + async external verifier
// server: static data provider + async external verifier
// extra: TLS 1.3
"chttp2/static_provider_async_verifier_tls1_3",
kH2TLSFeatureMask,
"foo.test.google.fr",
chttp2_create_fixture_async_verifier,
chttp2_init_client,
chttp2_init_server,
chttp2_tear_down_secure_fullstack,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<TlsFixture>(
SecurityPrimitives::TlsVersion::V_13,
SecurityPrimitives::ProviderType::STATIC_PROVIDER,
SecurityPrimitives::VerifierType::EXTERNAL_ASYNC_VERIFIER);
},
};
int main(int argc, char** argv) {

@ -17,93 +17,39 @@
//
#include <inttypes.h>
#include <string.h>
#include <unistd.h>
#include <atomic>
#include <functional>
#include <initializer_list>
#include <string>
#include <utility>
#include <memory>
#include "absl/strings/str_format.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/test_config.h"
struct fullstack_fixture_data {
std::string localaddr;
};
static std::atomic<int> unique{1};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_base(
std::string addr) {
fullstack_fixture_data* ffd = new fullstack_fixture_data;
ffd->localaddr = std::move(addr);
grpc_end2end_test_fixture f;
memset(&f, 0, sizeof(f));
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
const std::string localaddr = absl::StrFormat(
"unix:/tmp/grpc_fullstack_test.%d.%" PRId64 ".%" PRId32 ".%d", getpid(),
now.tv_sec, now.tv_nsec, unique++);
return chttp2_create_fixture_fullstack_base(localaddr);
}
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
grpc_channel_credentials_release(creds);
}
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
delete ffd;
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack_uds",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
nullptr,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
return std::make_unique<InsecureFixture>(absl::StrFormat(
"unix:/tmp/grpc_fullstack_test.%d.%" PRId64 ".%" PRId32 ".%d",
getpid(), now.tv_sec, now.tv_nsec,
unique.fetch_add(1, std::memory_order_relaxed)));
}},
};
int main(int argc, char** argv) {

@ -17,95 +17,39 @@
//
#include <inttypes.h>
#include <string.h>
#include <unistd.h>
#include <atomic>
#include <functional>
#include <initializer_list>
#include <string>
#include <utility>
#include <memory>
#include "absl/strings/str_format.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/test_config.h"
struct fullstack_fixture_data {
std::string localaddr;
};
static std::atomic<int> unique{1};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_base(
std::string addr) {
fullstack_fixture_data* ffd = new fullstack_fixture_data;
ffd->localaddr = std::move(addr);
grpc_end2end_test_fixture f;
memset(&f, 0, sizeof(f));
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static grpc_end2end_test_fixture
chttp2_create_fixture_fullstack_abstract_namespace(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
const std::string localaddr = absl::StrFormat(
"unix-abstract:grpc_fullstack_test.%d.%" PRId64 ".%" PRId32 ".%d",
getpid(), now.tv_sec, now.tv_nsec, unique++);
return chttp2_create_fixture_fullstack_base(localaddr);
}
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
grpc_channel_credentials_release(creds);
}
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_credentials* server_creds =
grpc_insecure_server_credentials_create();
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
delete ffd;
}
// All test configurations
static grpc_end2end_test_config configs[] = {
static CoreTestConfiguration configs[] = {
{"chttp2/fullstack_uds_abstract_namespace",
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr, chttp2_create_fixture_fullstack_abstract_namespace,
chttp2_init_client_fullstack, chttp2_init_server_fullstack,
chttp2_tear_down_fullstack},
nullptr,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
return std::make_unique<InsecureFixture>(absl::StrFormat(
"unix-abstract:grpc_fullstack_test.%d.%" PRId64 ".%" PRId32 ".%d",
getpid(), now.tv_sec, now.tv_nsec,
unique.fetch_add(1, std::memory_order_relaxed)));
}},
};
int main(int argc, char** argv) {

@ -18,59 +18,25 @@
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/ext/transport/inproc/inproc_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/inproc_fixture.h"
#include "test/core/util/test_config.h"
typedef struct inproc_fixture_data {
bool phony; // reserved for future expansion. Struct can't be empty
} inproc_fixture_data;
static grpc_end2end_test_fixture inproc_create_fixture(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>(
gpr_malloc(sizeof(inproc_fixture_data)));
memset(&f, 0, sizeof(f));
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
void inproc_init_client(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
f->client = grpc_inproc_channel_create(f->server, client_args, nullptr);
GPR_ASSERT(f->client);
}
void inproc_init_server(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_start(f->server);
}
void inproc_tear_down(grpc_end2end_test_fixture* f) {
inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>(f->fixture_data);
gpr_free(ffd);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
{"inproc", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, nullptr,
inproc_create_fixture, inproc_init_client, inproc_init_server,
inproc_tear_down},
};
static CoreTestConfiguration configs[] = {{
"inproc",
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
nullptr,
[](const grpc_core::ChannelArgs&, const grpc_core::ChannelArgs&) {
return std::make_unique<InprocFixture>();
},
}};
int main(int argc, char** argv) {
size_t i;

@ -0,0 +1,37 @@
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_TEST_CORE_END2END_FIXTURES_INPROC_FIXTURE_H
#define GRPC_TEST_CORE_END2END_FIXTURES_INPROC_FIXTURE_H
#include <grpc/grpc.h>
#include "src/core/ext/transport/inproc/inproc_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
class InprocFixture : public CoreTestFixture {
private:
grpc_server* MakeServer(const grpc_core::ChannelArgs& args) override {
auto* server = grpc_server_create(args.ToC().get(), nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
grpc_server_start(server);
return server;
}
grpc_channel* MakeClient(const grpc_core::ChannelArgs& args) override {
return grpc_inproc_channel_create(server(), args.ToC().get(), nullptr);
}
};
#endif // GRPC_TEST_CORE_END2END_FIXTURES_INPROC_FIXTURE_H

@ -20,48 +20,12 @@
#include <string.h>
#include <utility>
#include <grpc/grpc_security.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
grpc_end2end_test_fixture grpc_end2end_local_chttp2_create_fixture_fullstack() {
grpc_end2end_test_fixture f;
grpc_end2end_local_fullstack_fixture_data* ffd =
new grpc_end2end_local_fullstack_fixture_data();
memset(&f, 0, sizeof(f));
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
void grpc_end2end_local_chttp2_init_client_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_local_connect_type type) {
grpc_channel_credentials* creds = grpc_local_credentials_create(type);
grpc_end2end_local_fullstack_fixture_data* ffd =
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
//
// Check if server should fail auth check. If it is true, a different metadata
// processor will be installed that always fails in processing client's
// metadata.
//
static bool fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return false;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return true;
}
}
return false;
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
@ -71,31 +35,33 @@ static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
void grpc_end2end_local_chttp2_init_server_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_local_connect_type type) {
grpc_server_credentials* creds = grpc_local_server_credentials_create(type);
grpc_end2end_local_fullstack_fixture_data* ffd =
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
if (fail_server_auth_check(server_args)) {
LocalTestFixture::LocalTestFixture(std::string localaddr,
grpc_local_connect_type type)
: localaddr_(std::move(localaddr)), type_(type) {}
grpc_server* LocalTestFixture::MakeServer(const grpc_core::ChannelArgs& args) {
grpc_server_credentials* server_creds =
grpc_local_server_credentials_create(type_);
auto* server = grpc_server_create(args.ToC().get(), nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
if (args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(creds, processor);
grpc_server_credentials_set_auth_metadata_processor(server_creds,
processor);
}
GPR_ASSERT(
grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(), creds));
grpc_server_credentials_release(creds);
grpc_server_start(f->server);
grpc_server_add_http2_port(server, localaddr_.c_str(), server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(server);
return server;
}
void grpc_end2end_local_chttp2_tear_down_fullstack(
grpc_end2end_test_fixture* f) {
grpc_end2end_local_fullstack_fixture_data* ffd =
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f->fixture_data);
delete ffd;
grpc_channel* LocalTestFixture::MakeClient(const grpc_core::ChannelArgs& args) {
grpc_channel_credentials* creds = grpc_local_credentials_create(type_);
auto* client =
grpc_channel_create(localaddr_.c_str(), creds, args.ToC().get());
GPR_ASSERT(client != nullptr);
grpc_channel_credentials_release(creds);
return client;
}

@ -24,24 +24,19 @@
#include <grpc/grpc.h>
#include <grpc/grpc_security_constants.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/end2end_tests.h"
struct grpc_end2end_local_fullstack_fixture_data {
std::string localaddr;
};
// Utility functions shared by h2_local tests.
grpc_end2end_test_fixture grpc_end2end_local_chttp2_create_fixture_fullstack();
class LocalTestFixture final : public CoreTestFixture {
public:
LocalTestFixture(std::string localaddr, grpc_local_connect_type type);
void grpc_end2end_local_chttp2_init_client_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_local_connect_type type);
private:
grpc_server* MakeServer(const grpc_core::ChannelArgs& args) override;
grpc_channel* MakeClient(const grpc_core::ChannelArgs& args) override;
void grpc_end2end_local_chttp2_init_server_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_local_connect_type type);
void grpc_end2end_local_chttp2_tear_down_fullstack(
grpc_end2end_test_fixture* f);
std::string localaddr_;
grpc_local_connect_type type_;
};
#endif // GRPC_TEST_CORE_END2END_FIXTURES_LOCAL_UTIL_H

@ -0,0 +1,91 @@
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_TEST_CORE_END2END_FIXTURES_SECURE_FIXTURE_H
#define GRPC_TEST_CORE_END2END_FIXTURES_SECURE_FIXTURE_H
#include <string>
#include <utility>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/host_port.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
// Base class for a fixture that just needs to select cred types (or mutate
// client/server channel args).
class SecureFixture : public CoreTestFixture {
public:
explicit SecureFixture(std::string localaddr = grpc_core::JoinHostPort(
"localhost", grpc_pick_unused_port_or_die()))
: localaddr_(std::move(localaddr)) {}
protected:
const std::string& localaddr() const { return localaddr_; }
private:
virtual grpc_channel_credentials* MakeClientCreds(
const grpc_core::ChannelArgs& args) = 0;
virtual grpc_server_credentials* MakeServerCreds(
const grpc_core::ChannelArgs& args) = 0;
virtual grpc_core::ChannelArgs MutateClientArgs(grpc_core::ChannelArgs args) {
return args;
}
virtual grpc_core::ChannelArgs MutateServerArgs(grpc_core::ChannelArgs args) {
return args;
}
grpc_server* MakeServer(const grpc_core::ChannelArgs& in_args) override {
auto args = MutateServerArgs(in_args);
auto* creds = MakeServerCreds(args);
auto* server = grpc_server_create(args.ToC().get(), nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
GPR_ASSERT(grpc_server_add_http2_port(server, localaddr_.c_str(), creds));
grpc_server_credentials_release(creds);
grpc_server_start(server);
return server;
}
grpc_channel* MakeClient(const grpc_core::ChannelArgs& in_args) override {
auto args = MutateClientArgs(in_args);
auto* creds = MakeClientCreds(args);
auto* client =
grpc_channel_create(localaddr_.c_str(), creds, args.ToC().get());
GPR_ASSERT(client != nullptr);
grpc_channel_credentials_release(creds);
return client;
}
std::string localaddr_;
};
// Fixture that uses insecure credentials.
class InsecureFixture : public SecureFixture {
public:
using SecureFixture::SecureFixture;
private:
grpc_channel_credentials* MakeClientCreds(
const grpc_core::ChannelArgs&) override {
return grpc_insecure_credentials_create();
}
grpc_server_credentials* MakeServerCreds(
const grpc_core::ChannelArgs&) override {
return grpc_insecure_server_credentials_create();
}
};
#endif // GRPC_TEST_CORE_END2END_FIXTURES_SECURE_FIXTURE_H

@ -0,0 +1,108 @@
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_TEST_CORE_END2END_FIXTURES_SOCKPAIR_FIXTURE_H
#define GRPC_TEST_CORE_END2END_FIXTURES_SOCKPAIR_FIXTURE_H
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include <grpc/grpc.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_args_preconditioning.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/surface/server.h"
#include "src/core/lib/transport/transport.h"
#include "src/core/lib/transport/transport_fwd.h"
#include "test/core/end2end/end2end_tests.h"
class SockpairFixture : public CoreTestFixture {
public:
explicit SockpairFixture(const grpc_core::ChannelArgs& ep_args)
: ep_(grpc_iomgr_create_endpoint_pair("fixture", ep_args.ToC().get())) {}
private:
virtual grpc_core::ChannelArgs MutateClientArgs(grpc_core::ChannelArgs args) {
return args;
}
virtual grpc_core::ChannelArgs MutateServerArgs(grpc_core::ChannelArgs args) {
return args;
}
grpc_server* MakeServer(const grpc_core::ChannelArgs& in_args) override {
auto args = MutateServerArgs(in_args);
grpc_core::ExecCtx exec_ctx;
grpc_transport* transport;
auto* server = grpc_server_create(args.ToC().get(), nullptr);
grpc_server_register_completion_queue(server, cq(), nullptr);
grpc_server_start(server);
auto server_channel_args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(args.ToC().get());
transport =
grpc_create_chttp2_transport(server_channel_args, ep_.server, false);
grpc_endpoint_add_to_pollset(ep_.server, grpc_cq_pollset(cq()));
grpc_core::Server* core_server = grpc_core::Server::FromC(server);
grpc_error_handle error = core_server->SetupTransport(
transport, nullptr, core_server->channel_args(), nullptr);
if (error.ok()) {
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
grpc_transport_destroy(transport);
}
return server;
}
grpc_channel* MakeClient(const grpc_core::ChannelArgs& in_args) override {
grpc_core::ExecCtx exec_ctx;
auto args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(
MutateClientArgs(in_args)
.Set(GRPC_ARG_DEFAULT_AUTHORITY, "test-authority")
.ToC()
.get());
grpc_transport* transport;
transport = grpc_create_chttp2_transport(args, ep_.client, true);
auto channel = grpc_core::Channel::Create(
"socketpair-target", args, GRPC_CLIENT_DIRECT_CHANNEL, transport);
grpc_channel* client;
if (channel.ok()) {
client = channel->release()->c_ptr();
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
} else {
client = grpc_lame_client_channel_create(
nullptr, static_cast<grpc_status_code>(channel.status().code()),
"lame channel");
grpc_transport_destroy(transport);
}
GPR_ASSERT(client);
return client;
}
grpc_endpoint_pair ep_;
};
#endif // GRPC_TEST_CORE_END2END_FIXTURES_SOCKPAIR_FIXTURE_H

@ -449,7 +449,7 @@ def grpc_end2end_tests():
":ssl_test_data",
":http_proxy",
":proxy",
":local_util",
":fixture_support",
"//test/core/util:test_lb_policies",
"//:grpc_authorization_provider",
"//:grpc_http_filters",

@ -60,8 +60,6 @@
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static gpr_mu g_mu;
static int g_resolve_port = -1;
@ -283,9 +281,9 @@ int main(int argc, char** argv) {
op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call1, ops,
(size_t)(op - ops),
tag(0x101), nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(call1, ops, (size_t)(op - ops),
grpc_core::CqVerifier::tag(0x101), nullptr));
// and receive status to probe termination
memset(ops, 0, sizeof(ops));
op = ops;
@ -296,9 +294,9 @@ int main(int argc, char** argv) {
op->flags = 0;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call1, ops,
(size_t)(op - ops),
tag(0x102), nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(call1, ops, (size_t)(op - ops),
grpc_core::CqVerifier::tag(0x102), nullptr));
// bring a server up on the first port
grpc_server* server1 = grpc_server_create(nullptr, nullptr);
@ -314,20 +312,21 @@ int main(int argc, char** argv) {
grpc_call* server_call1;
GPR_ASSERT(GRPC_CALL_OK ==
grpc_server_request_call(server1, &server_call1, &request_details1,
&request_metadata1, cq, cq, tag(0x301)));
&request_metadata1, cq, cq,
grpc_core::CqVerifier::tag(0x301)));
set_resolve_port(port1);
// first call should now start
cqv.Expect(tag(0x101), true);
cqv.Expect(tag(0x301), true);
cqv.Expect(grpc_core::CqVerifier::tag(0x101), true);
cqv.Expect(grpc_core::CqVerifier::tag(0x301), true);
cqv.Verify();
GPR_ASSERT(GRPC_CHANNEL_READY ==
grpc_channel_check_connectivity_state(chan, 0));
grpc_channel_watch_connectivity_state(chan, GRPC_CHANNEL_READY,
gpr_inf_future(GPR_CLOCK_REALTIME), cq,
tag(0x9999));
grpc_core::CqVerifier::tag(0x9999));
// listen for close on the server call to probe for finishing
memset(ops, 0, sizeof(ops));
@ -336,15 +335,16 @@ int main(int argc, char** argv) {
op->data.recv_close_on_server.cancelled = &was_cancelled1;
op->flags = 0;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(server_call1, ops,
(size_t)(op - ops),
tag(0x302), nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(server_call1, ops, (size_t)(op - ops),
grpc_core::CqVerifier::tag(0x302), nullptr));
// shutdown first server:
// we should see a connectivity change and then nothing
set_resolve_port(-1);
grpc_server_shutdown_and_notify(server1, cq, tag(0xdead1));
cqv.Expect(tag(0x9999), true);
grpc_server_shutdown_and_notify(server1, cq,
grpc_core::CqVerifier::tag(0xdead1));
cqv.Expect(grpc_core::CqVerifier::tag(0x9999), true);
cqv.Verify();
cqv.VerifyEmpty();
@ -361,9 +361,9 @@ int main(int argc, char** argv) {
op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call2, ops,
(size_t)(op - ops),
tag(0x201), nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(call2, ops, (size_t)(op - ops),
grpc_core::CqVerifier::tag(0x201), nullptr));
// and receive status to probe termination
memset(ops, 0, sizeof(ops));
op = ops;
@ -374,9 +374,9 @@ int main(int argc, char** argv) {
op->flags = 0;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call2, ops,
(size_t)(op - ops),
tag(0x202), nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(call2, ops, (size_t)(op - ops),
grpc_core::CqVerifier::tag(0x202), nullptr));
// and bring up second server
set_resolve_port(port2);
@ -393,11 +393,12 @@ int main(int argc, char** argv) {
grpc_call* server_call2;
GPR_ASSERT(GRPC_CALL_OK ==
grpc_server_request_call(server2, &server_call2, &request_details2,
&request_metadata2, cq, cq, tag(0x401)));
&request_metadata2, cq, cq,
grpc_core::CqVerifier::tag(0x401)));
// second call should now start
cqv.Expect(tag(0x201), true);
cqv.Expect(tag(0x401), true);
cqv.Expect(grpc_core::CqVerifier::tag(0x201), true);
cqv.Expect(grpc_core::CqVerifier::tag(0x401), true);
cqv.Verify();
// listen for close on the server call to probe for finishing
@ -407,24 +408,25 @@ int main(int argc, char** argv) {
op->data.recv_close_on_server.cancelled = &was_cancelled2;
op->flags = 0;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(server_call2, ops,
(size_t)(op - ops),
tag(0x402), nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(server_call2, ops, (size_t)(op - ops),
grpc_core::CqVerifier::tag(0x402), nullptr));
// shutdown second server: we should see nothing
grpc_server_shutdown_and_notify(server2, cq, tag(0xdead2));
grpc_server_shutdown_and_notify(server2, cq,
grpc_core::CqVerifier::tag(0xdead2));
cqv.VerifyEmpty();
grpc_call_cancel(call1, nullptr);
grpc_call_cancel(call2, nullptr);
// now everything else should finish
cqv.Expect(tag(0x102), true);
cqv.Expect(tag(0x202), true);
cqv.Expect(tag(0x302), true);
cqv.Expect(tag(0x402), true);
cqv.Expect(tag(0xdead1), true);
cqv.Expect(tag(0xdead2), true);
cqv.Expect(grpc_core::CqVerifier::tag(0x102), true);
cqv.Expect(grpc_core::CqVerifier::tag(0x202), true);
cqv.Expect(grpc_core::CqVerifier::tag(0x302), true);
cqv.Expect(grpc_core::CqVerifier::tag(0x402), true);
cqv.Expect(grpc_core::CqVerifier::tag(0xdead1), true);
cqv.Expect(grpc_core::CqVerifier::tag(0xdead2), true);
cqv.Verify();
grpc_call_unref(call1);

@ -16,10 +16,11 @@
//
//
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <functional>
#include <memory>
#include <string>
#include <openssl/crypto.h>
@ -39,13 +40,11 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/security/security_connector/ssl_utils_config.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/port.h"
#include "test/core/end2end/fixtures/secure_fixture.h"
#include "test/core/util/test_config.h"
static std::string test_server1_key_id;
@ -53,25 +52,6 @@ static std::string test_server1_key_id;
namespace grpc {
namespace testing {
struct fullstack_secure_fixture_data {
std::string localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd = new fullstack_secure_fixture_data();
memset(&f, 0, sizeof(f));
ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
return f;
}
static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
const grpc_metadata* /*md*/,
size_t /*md_count*/,
@ -81,157 +61,100 @@ static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr);
}
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* client_args,
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype;
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture* f, const grpc_channel_args* server_args,
grpc_server_credentials* server_creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
class TestFixture : public SecureFixture {
public:
TestFixture(grpc_ssl_client_certificate_request_type request_type,
certtype cert_type)
: request_type_(request_type), cert_type_(cert_type) {}
static auto MakeFactory(grpc_ssl_client_certificate_request_type request_type,
certtype cert_type) {
return [request_type, cert_type](const grpc_core::ChannelArgs&,
const grpc_core::ChannelArgs&) {
return std::make_unique<TestFixture>(request_type, cert_type);
};
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
delete ffd;
}
static int fail_server_auth_check(const grpc_channel_args* server_args) {
size_t i;
if (server_args == nullptr) return 0;
for (i = 0; i < server_args->num_args; i++) {
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
0) {
return 1;
}
private:
grpc_core::ChannelArgs MutateClientArgs(
grpc_core::ChannelArgs args) override {
return args.Set(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, "foo.test.google.fr");
}
return 0;
}
#define SERVER_INIT_NAME(REQUEST_TYPE) \
chttp2_init_server_simple_ssl_secure_fullstack_##REQUEST_TYPE
#define SERVER_INIT(REQUEST_TYPE) \
static void SERVER_INIT_NAME(REQUEST_TYPE)( \
grpc_end2end_test_fixture * f, const grpc_channel_args* server_args) { \
grpc_ssl_pem_key_cert_pair pem_cert_key_pair; \
if (!test_server1_key_id.empty()) { \
pem_cert_key_pair.private_key = test_server1_key_id.c_str(); \
pem_cert_key_pair.cert_chain = test_server1_cert; \
} else { \
pem_cert_key_pair.private_key = test_server1_key; \
pem_cert_key_pair.cert_chain = test_server1_cert; \
} \
grpc_server_credentials* ssl_creds = \
grpc_ssl_server_credentials_create_ex( \
test_root_cert, &pem_cert_key_pair, 1, REQUEST_TYPE, NULL); \
if (fail_server_auth_check(server_args)) { \
grpc_auth_metadata_processor processor = {process_auth_failure, NULL, \
NULL}; \
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, \
processor); \
} \
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds); \
grpc_server_credentials* MakeServerCreds(
const grpc_core::ChannelArgs& args) override {
grpc_ssl_pem_key_cert_pair pem_cert_key_pair;
if (!test_server1_key_id.empty()) {
pem_cert_key_pair.private_key = test_server1_key_id.c_str();
pem_cert_key_pair.cert_chain = test_server1_cert;
} else {
pem_cert_key_pair.private_key = test_server1_key;
pem_cert_key_pair.cert_chain = test_server1_cert;
}
grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create_ex(
test_root_cert, &pem_cert_key_pair, 1, request_type_, nullptr);
if (args.Contains(FAIL_AUTH_CHECK_SERVER_ARG_NAME)) {
grpc_auth_metadata_processor processor = {process_auth_failure, nullptr,
nullptr};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
return ssl_creds;
}
SERVER_INIT(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE)
SERVER_INIT(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY)
SERVER_INIT(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY)
SERVER_INIT(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY)
SERVER_INIT(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY)
#define CLIENT_INIT_NAME(cert_type) \
chttp2_init_client_simple_ssl_secure_fullstack_##cert_type
typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype;
#define CLIENT_INIT(cert_type) \
static void CLIENT_INIT_NAME(cert_type)( \
grpc_end2end_test_fixture * f, const grpc_channel_args* client_args) { \
grpc_channel_credentials* ssl_creds = NULL; \
grpc_ssl_pem_key_cert_pair self_signed_client_key_cert_pair = { \
test_self_signed_client_key, test_self_signed_client_cert}; \
grpc_ssl_pem_key_cert_pair signed_client_key_cert_pair = { \
test_signed_client_key, test_signed_client_cert}; \
grpc_ssl_pem_key_cert_pair bad_client_key_cert_pair = { \
test_self_signed_client_key, test_signed_client_cert}; \
grpc_ssl_pem_key_cert_pair* key_cert_pair = NULL; \
switch (cert_type) { \
case SELF_SIGNED: \
key_cert_pair = &self_signed_client_key_cert_pair; \
break; \
case SIGNED: \
key_cert_pair = &signed_client_key_cert_pair; \
break; \
case BAD_CERT_PAIR: \
key_cert_pair = &bad_client_key_cert_pair; \
break; \
default: \
break; \
} \
ssl_creds = grpc_ssl_credentials_create(test_root_cert, key_cert_pair, \
NULL, NULL); \
grpc_arg ssl_name_override = { \
GRPC_ARG_STRING, \
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG), \
{const_cast<char*>("foo.test.google.fr")}}; \
grpc_channel_args* new_client_args = \
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); \
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); \
{ \
grpc_core::ExecCtx exec_ctx; \
grpc_channel_args_destroy(new_client_args); \
} \
grpc_channel_credentials* MakeClientCreds(
const grpc_core::ChannelArgs&) override {
grpc_ssl_pem_key_cert_pair self_signed_client_key_cert_pair = {
test_self_signed_client_key, test_self_signed_client_cert};
grpc_ssl_pem_key_cert_pair signed_client_key_cert_pair = {
test_signed_client_key, test_signed_client_cert};
grpc_ssl_pem_key_cert_pair bad_client_key_cert_pair = {
test_self_signed_client_key, test_signed_client_cert};
grpc_ssl_pem_key_cert_pair* key_cert_pair = nullptr;
switch (cert_type_) {
case SELF_SIGNED:
key_cert_pair = &self_signed_client_key_cert_pair;
break;
case SIGNED:
key_cert_pair = &signed_client_key_cert_pair;
break;
case BAD_CERT_PAIR:
key_cert_pair = &bad_client_key_cert_pair;
break;
default:
break;
}
return grpc_ssl_credentials_create(test_root_cert, key_cert_pair, nullptr,
nullptr);
}
CLIENT_INIT(NONE)
CLIENT_INIT(SELF_SIGNED)
CLIENT_INIT(SIGNED)
CLIENT_INIT(BAD_CERT_PAIR)
grpc_ssl_client_certificate_request_type request_type_;
certtype cert_type_;
};
#define TEST_NAME(enum_name, cert_type, result) \
"chttp2/ssl_" #enum_name "_" #cert_type "_" #result "_"
typedef enum { SUCCESS, FAIL } test_result;
#define SSL_TEST(request_type, cert_type, result) \
{ \
{TEST_NAME(request_type, cert_type, result), \
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | \
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS | \
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL, \
"foo.test.google.fr", \
chttp2_create_fixture_secure_fullstack, \
CLIENT_INIT_NAME(cert_type), \
SERVER_INIT_NAME(request_type), \
chttp2_tear_down_secure_fullstack}, \
result \
#define SSL_TEST(request_type, cert_type, result) \
{ \
{TEST_NAME(request_type, cert_type, result), \
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | \
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS | \
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL, \
"foo.test.google.fr", TestFixture::MakeFactory(request_type, cert_type)}, \
result \
}
// All test configurations
typedef struct grpc_end2end_test_config_wrapper {
grpc_end2end_test_config config;
struct CoreTestConfigWrapper {
CoreTestConfiguration config;
test_result result;
} grpc_end2end_test_config_wrapper;
};
static grpc_end2end_test_config_wrapper configs[] = {
static CoreTestConfigWrapper configs[] = {
SSL_TEST(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, NONE, SUCCESS),
SSL_TEST(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, SELF_SIGNED, SUCCESS),
SSL_TEST(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, SIGNED, SUCCESS),
@ -271,57 +194,19 @@ static grpc_end2end_test_config_wrapper configs[] = {
BAD_CERT_PAIR, FAIL),
};
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
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(), nullptr);
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
}
// Shuts down the server.
// Side effect - Also shuts down and drains the completion queue.
static void shutdown_server(grpc_end2end_test_fixture* f) {
if (!f->server) return;
grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000));
grpc_completion_queue_shutdown(f->cq);
drain_cq(f->cq);
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
static void end_test(grpc_end2end_test_fixture* f) {
shutdown_client(f);
shutdown_server(f);
grpc_completion_queue_destroy(f->cq);
}
static void simple_request_body(grpc_end2end_test_fixture f,
static void simple_request_body(CoreTestFixture* f,
test_result expected_result) {
grpc_call* c;
gpr_timespec deadline = five_seconds_time();
grpc_core::CqVerifier cqv(f.cq);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_call_error error;
grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234");
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), &host,
deadline, nullptr);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
&host, deadline, nullptr);
GPR_ASSERT(c);
memset(ops, 0, sizeof(ops));
@ -331,37 +216,34 @@ static void simple_request_body(grpc_end2end_test_fixture f,
op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), expected_result == SUCCESS);
cqv.Expect(grpc_core::CqVerifier::tag(1), expected_result == SUCCESS);
cqv.Verify();
grpc_call_unref(c);
}
class H2SslCertTest
: public ::testing::TestWithParam<grpc_end2end_test_config_wrapper> {
class H2SslCertTest : public ::testing::TestWithParam<CoreTestConfigWrapper> {
protected:
H2SslCertTest() {
gpr_log(GPR_INFO, "SSL_CERT_tests/%s", GetParam().config.name);
}
void SetUp() override {
fixture_ = GetParam().config.create_fixture(nullptr, nullptr);
GetParam().config.init_server(&fixture_, nullptr);
GetParam().config.init_client(&fixture_, nullptr);
}
void TearDown() override {
end_test(&fixture_);
GetParam().config.tear_down_data(&fixture_);
fixture_ = GetParam().config.create_fixture(grpc_core::ChannelArgs(),
grpc_core::ChannelArgs());
fixture_->InitServer(grpc_core::ChannelArgs());
fixture_->InitClient(grpc_core::ChannelArgs());
}
void TearDown() override { fixture_.reset(); }
grpc_end2end_test_fixture fixture_;
std::unique_ptr<CoreTestFixture> fixture_;
};
TEST_P(H2SslCertTest, SimpleRequestBody) {
simple_request_body(fixture_, GetParam().result);
simple_request_body(fixture_.get(), GetParam().result);
}
#ifndef OPENSSL_IS_BORINGSSL
@ -370,7 +252,7 @@ TEST_P(H2SslCertTest, SimpleRequestBodyUseEngine) {
test_server1_key_id.clear();
test_server1_key_id.append("engine:libengine_passthrough:");
test_server1_key_id.append(test_server1_key);
simple_request_body(fixture_, GetParam().result);
simple_request_body(fixture_.get(), GetParam().result);
}
#endif
#endif

@ -16,7 +16,6 @@
//
//
#include <stdint.h>
#include <string.h>
#include <string>
@ -54,8 +53,6 @@ namespace grpc {
namespace testing {
namespace {
void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
gpr_timespec five_seconds_time() { return grpc_timeout_seconds_to_deadline(5); }
grpc_server* server_create(grpc_completion_queue* cq, const char* server_addr) {
@ -186,15 +183,16 @@ void do_round_trip(grpc_completion_queue* cq, grpc_server* server,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
grpc_call* s;
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq, tag(101));
&request_metadata_recv, cq, cq,
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
grpc_auth_context* auth = grpc_call_auth_context(s);
@ -227,12 +225,12 @@ void do_round_trip(grpc_completion_queue* cq, grpc_server* server,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(103),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(103), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(103), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
grpc_metadata_array_destroy(&initial_metadata_recv);
@ -273,12 +271,13 @@ TEST(H2SessionReuseTest, SingleReuse) {
cq, grpc_timeout_milliseconds_to_deadline(100), nullptr)
.type == GRPC_QUEUE_TIMEOUT);
grpc_server_shutdown_and_notify(server, cq, tag(1000));
grpc_server_shutdown_and_notify(server, cq, grpc_core::CqVerifier::tag(1000));
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
} while (ev.type != GRPC_OP_COMPLETE ||
ev.tag != grpc_core::CqVerifier::tag(1000));
grpc_server_destroy(server);
grpc_completion_queue_shutdown(cq);

@ -1,505 +0,0 @@
//
//
// Copyright 2018 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#include <inttypes.h>
#include <string.h>
#include <initializer_list>
#include "absl/strings/str_format.h"
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/ext/transport/inproc/inproc_transport.h"
#include "src/core/lib/gprpp/crash.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
typedef struct inproc_fixture_data {
bool phony; // reserved for future expansion. Struct can't be empty
} inproc_fixture_data;
namespace {
template <typename F>
class CQDeletingCallback : public grpc_completion_queue_functor {
public:
explicit CQDeletingCallback(F f) : func_(f) {
functor_run = &CQDeletingCallback::Run;
inlineable = false;
}
~CQDeletingCallback() {}
static void Run(grpc_completion_queue_functor* cb, int ok) {
auto* callback = static_cast<CQDeletingCallback*>(cb);
callback->func_(static_cast<bool>(ok));
delete callback;
}
private:
F func_;
};
template <typename F>
grpc_completion_queue_functor* NewDeletingCallback(F f) {
return new CQDeletingCallback<F>(f);
}
class ShutdownCallback : public grpc_completion_queue_functor {
public:
ShutdownCallback() : done_(false) {
functor_run = &ShutdownCallback::StaticRun;
inlineable = false;
gpr_mu_init(&mu_);
gpr_cv_init(&cv_);
}
~ShutdownCallback() {
gpr_mu_destroy(&mu_);
gpr_cv_destroy(&cv_);
}
static void StaticRun(grpc_completion_queue_functor* cb, int ok) {
auto* callback = static_cast<ShutdownCallback*>(cb);
callback->Run(static_cast<bool>(ok));
}
void Run(bool /*ok*/) {
gpr_log(GPR_DEBUG, "CQ shutdown notification invoked");
gpr_mu_lock(&mu_);
done_ = true;
gpr_cv_broadcast(&cv_);
gpr_mu_unlock(&mu_);
}
// The Wait function waits for a specified amount of
// time for the completion of the shutdown and returns
// whether it was successfully shut down
bool Wait(gpr_timespec deadline) {
gpr_mu_lock(&mu_);
while (!done_ && !gpr_cv_wait(&cv_, &mu_, deadline)) {
}
bool ret = done_;
gpr_mu_unlock(&mu_);
return ret;
}
private:
bool done_;
gpr_mu mu_;
gpr_cv cv_;
};
ShutdownCallback* g_shutdown_callback;
} // namespace
// The following global structure is the tag collection. It holds
// all information related to tags expected and tags received
// during the execution, with each callback setting a tag.
// The tag sets are implemented and checked using arrays and
// linear lookups (rather than maps) so that this test doesn't
// need the C++ standard library.
static gpr_mu tags_mu;
static gpr_cv tags_cv;
const size_t kAvailableTags = 4;
bool tags[kAvailableTags];
bool tags_valid[kAvailableTags];
bool tags_expected[kAvailableTags];
bool tags_needed[kAvailableTags];
// Mark that a tag is expected; this function must be executed in the
// main thread only while there are no other threads altering the
// expectation set (e.g., by calling expect_tag or verify_tags)
static void expect_tag(intptr_t tag, bool ok) {
size_t idx = static_cast<size_t>(tag);
GPR_ASSERT(idx < kAvailableTags);
tags_needed[idx] = true;
tags_expected[idx] = ok;
}
// Check that the expected tags have reached, within a certain
// deadline. This must also be executed only on the main thread while
// there are no other threads altering the expectation set (e.g., by
// calling expect_tag or verify_tags). The tag verifier doesn't have
// to drive the CQ at all (unlike the next-based end2end tests)
// because the tags will get set when the callbacks are executed,
// which happens when a particular batch related to a callback is
// complete.
static void verify_tags(gpr_timespec deadline) {
bool done = false;
gpr_mu_lock(&tags_mu);
while (!done) {
done = gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), deadline) > 0;
for (size_t i = 0; i < kAvailableTags; i++) {
if (tags_needed[i]) {
if (tags_valid[i]) {
gpr_log(GPR_DEBUG, "Verifying tag %d", static_cast<int>(i));
if (tags[i] != tags_expected[i]) {
grpc_core::Crash(absl::StrFormat(
"Got wrong result (%d instead of %d) for tag %d", tags[i],
tags_expected[i], static_cast<int>(i)));
}
tags_valid[i] = false;
tags_needed[i] = false;
} else if (done) {
grpc_core::Crash(
absl::StrFormat("Didn't get tag %d", static_cast<int>(i)));
}
}
}
bool empty = true;
for (size_t i = 0; i < kAvailableTags; i++) {
if (tags_needed[i]) {
empty = false;
}
}
done = done || empty;
if (done) {
for (size_t i = 0; i < kAvailableTags; i++) {
if (tags_valid[i]) {
grpc_core::Crash(
absl::StrFormat("Got unexpected tag %d and result %d",
static_cast<int>(i), tags[i]));
}
tags_valid[i] = false;
}
} else {
gpr_cv_wait(&tags_cv, &tags_mu, deadline);
}
}
gpr_mu_unlock(&tags_mu);
}
// This function creates a callback functor that emits the
// desired tag into the global tag set
static grpc_completion_queue_functor* tag(intptr_t t) {
auto func = [t](bool ok) {
gpr_mu_lock(&tags_mu);
gpr_log(GPR_DEBUG, "Completing operation %" PRIdPTR, t);
bool was_empty = true;
for (size_t i = 0; i < kAvailableTags; i++) {
if (tags_valid[i]) {
was_empty = false;
}
}
size_t idx = static_cast<size_t>(t);
tags[idx] = ok;
tags_valid[idx] = true;
if (was_empty) {
gpr_cv_signal(&tags_cv);
}
gpr_mu_unlock(&tags_mu);
};
auto cb = NewDeletingCallback(func);
return cb;
}
static grpc_end2end_test_fixture inproc_create_fixture(
const grpc_channel_args* /*client_args*/,
const grpc_channel_args* /*server_args*/) {
grpc_end2end_test_fixture f;
inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>(
gpr_malloc(sizeof(inproc_fixture_data)));
memset(&f, 0, sizeof(f));
f.fixture_data = ffd;
g_shutdown_callback = new ShutdownCallback();
f.cq =
grpc_completion_queue_create_for_callback(g_shutdown_callback, nullptr);
return f;
}
void inproc_init_client(grpc_end2end_test_fixture* f,
const grpc_channel_args* client_args) {
f->client = grpc_inproc_channel_create(f->server, client_args, nullptr);
GPR_ASSERT(f->client);
}
void inproc_init_server(grpc_end2end_test_fixture* f,
const grpc_channel_args* server_args) {
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
grpc_server_start(f->server);
}
void inproc_tear_down(grpc_end2end_test_fixture* f) {
inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>(f->fixture_data);
gpr_free(ffd);
}
static grpc_end2end_test_fixture begin_test(
grpc_end2end_test_config config, const char* test_name,
const grpc_channel_args* client_args,
const grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
gpr_log(GPR_INFO, "Running test: %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);
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now() { return n_seconds_from_now(5); }
static void drain_cq(grpc_completion_queue* /*cq*/) {
// Wait for the shutdown callback to arrive, or fail the test
GPR_ASSERT(g_shutdown_callback->Wait(five_seconds_from_now()));
gpr_log(GPR_DEBUG, "CQ shutdown wait complete");
delete g_shutdown_callback;
}
static void shutdown_server(grpc_end2end_test_fixture* f) {
if (!f->server) return;
grpc_server_shutdown_and_notify(f->server, f->cq, tag(1));
expect_tag(1, true);
verify_tags(five_seconds_from_now());
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void simple_request_body(grpc_end2end_test_config /* config */,
grpc_end2end_test_fixture f) {
grpc_call* c;
grpc_call* s;
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
grpc_metadata_array trailing_metadata_recv;
grpc_metadata_array request_metadata_recv;
grpc_call_details call_details;
grpc_status_code status;
const char* error_string;
grpc_call_error error;
grpc_slice details;
int was_cancelled = 2;
char* peer;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
GPR_ASSERT(c);
peer = grpc_call_get_peer(c);
GPR_ASSERT(peer != nullptr);
gpr_log(GPR_DEBUG, "client_peer_before_call=%s", peer);
gpr_free(peer);
grpc_metadata_array_init(&initial_metadata_recv);
grpc_metadata_array_init(&trailing_metadata_recv);
grpc_metadata_array_init(&request_metadata_recv);
grpc_call_details_init(&call_details);
// Create a basic client unary request batch (no payload)
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 = nullptr;
op++;
op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_INITIAL_METADATA;
op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
op->data.recv_status_on_client.status = &status;
op->data.recv_status_on_client.status_details = &details;
op->data.recv_status_on_client.error_string = &error_string;
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
// Register a call at the server-side to match the incoming client call
error = grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(2));
GPR_ASSERT(GRPC_CALL_OK == error);
// We expect that the server call creation callback (and no others) will
// execute now since no other batch should be complete.
expect_tag(2, true);
verify_tags(deadline);
peer = grpc_call_get_peer(s);
GPR_ASSERT(peer != nullptr);
gpr_log(GPR_DEBUG, "server_peer=%s", peer);
gpr_free(peer);
peer = grpc_call_get_peer(c);
GPR_ASSERT(peer != nullptr);
gpr_log(GPR_DEBUG, "client_peer=%s", peer);
gpr_free(peer);
// Create the server response batch (no payload)
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 = nullptr;
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_UNIMPLEMENTED;
grpc_slice status_details = grpc_slice_from_static_string("xyz");
op->data.send_status_from_server.status_details = &status_details;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
op->data.recv_close_on_server.cancelled = &was_cancelled;
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(3),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
// Both the client request and server response batches should get complete
// now and we should see that their callbacks have been executed
expect_tag(3, true);
expect_tag(1, true);
verify_tags(deadline);
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz"));
// the following sanity check makes sure that the requested error string is
// correctly populated by the core. It looks for certain substrings that are
// not likely to change much. Some parts of the error, like time created,
// obviously are not checked.
GPR_ASSERT(nullptr != strstr(error_string, "xyz"));
GPR_ASSERT(nullptr != strstr(error_string, "Error received from peer"));
GPR_ASSERT(nullptr != strstr(error_string, "grpc_message"));
GPR_ASSERT(nullptr != strstr(error_string, "grpc_status"));
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo"));
GPR_ASSERT(was_cancelled == 0);
grpc_slice_unref(details);
gpr_free(static_cast<void*>(const_cast<char*>(error_string)));
grpc_metadata_array_destroy(&initial_metadata_recv);
grpc_metadata_array_destroy(&trailing_metadata_recv);
grpc_metadata_array_destroy(&request_metadata_recv);
grpc_call_details_destroy(&call_details);
grpc_call_unref(c);
grpc_call_unref(s);
}
static void test_invoke_simple_request(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
f = begin_test(config, "test_invoke_simple_request", nullptr, nullptr);
simple_request_body(config, f);
end_test(&f);
config.tear_down_data(&f);
}
static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
int i;
grpc_end2end_test_fixture f =
begin_test(config, "test_invoke_10_simple_requests", nullptr, nullptr);
for (i = 0; i < 10; i++) {
simple_request_body(config, f);
gpr_log(GPR_INFO, "Running test: Passed simple request %d", i);
}
end_test(&f);
config.tear_down_data(&f);
}
static void test_invoke_many_simple_requests(grpc_end2end_test_config config) {
int i;
const int many = 1000;
grpc_end2end_test_fixture f =
begin_test(config, "test_invoke_many_simple_requests", nullptr, nullptr);
gpr_timespec t1 = gpr_now(GPR_CLOCK_MONOTONIC);
for (i = 0; i < many; i++) {
simple_request_body(config, f);
}
double us =
gpr_timespec_to_micros(gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), t1)) /
many;
gpr_log(GPR_INFO, "Time per ping %f us", us);
end_test(&f);
config.tear_down_data(&f);
}
static void simple_request(grpc_end2end_test_config config) {
int i;
for (i = 0; i < 10; i++) {
test_invoke_simple_request(config);
}
test_invoke_10_simple_requests(config);
test_invoke_many_simple_requests(config);
}
static void simple_request_pre_init() {
gpr_mu_init(&tags_mu);
gpr_cv_init(&tags_cv);
}
// All test configurations
static grpc_end2end_test_config configs[] = {
{"inproc-callback", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, nullptr,
inproc_create_fixture, inproc_init_client, inproc_init_server,
inproc_tear_down},
};
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
grpc_init();
simple_request_pre_init();
simple_request(configs[0]);
grpc_shutdown();
return 0;
}

@ -19,7 +19,6 @@
#include <grpc/support/port_platform.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <initializer_list>
@ -40,8 +39,6 @@
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
struct test_state {
int is_client;
grpc_channel* chan;
@ -111,16 +108,17 @@ static void prepare_test(int is_client) {
op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_server_request_call(g_state.server, &g_state.server_call,
&g_state.call_details,
&g_state.server_initial_metadata_recv,
g_state.cq, g_state.cq, tag(101)));
g_state.cqv->Expect(tag(101), true);
g_state.cqv->Expect(tag(1), true);
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_server_request_call(
g_state.server, &g_state.server_call, &g_state.call_details,
&g_state.server_initial_metadata_recv, g_state.cq,
g_state.cq, grpc_core::CqVerifier::tag(101)));
g_state.cqv->Expect(grpc_core::CqVerifier::tag(101), true);
g_state.cqv->Expect(grpc_core::CqVerifier::tag(1), true);
g_state.cqv->Verify();
}
}
@ -134,12 +132,14 @@ static void cleanup_test() {
if (!g_state.is_client) {
grpc_call_unref(g_state.server_call);
grpc_server_shutdown_and_notify(g_state.server, g_state.cq, tag(1000));
grpc_server_shutdown_and_notify(g_state.server, g_state.cq,
grpc_core::CqVerifier::tag(1000));
grpc_event ev;
do {
ev = grpc_completion_queue_next(
g_state.cq, grpc_timeout_seconds_to_deadline(5), nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
} while (ev.type != GRPC_OP_COMPLETE ||
ev.tag != grpc_core::CqVerifier::tag(1000));
grpc_server_destroy(g_state.server);
grpc_call_details_destroy(&g_state.call_details);
grpc_metadata_array_destroy(&g_state.server_initial_metadata_recv);
@ -157,7 +157,8 @@ static void test_non_null_reserved_on_start_batch() {
prepare_test(1);
GPR_ASSERT(GRPC_CALL_ERROR ==
grpc_call_start_batch(g_state.call, nullptr, 0, nullptr, tag(1)));
grpc_call_start_batch(g_state.call, nullptr, 0, nullptr,
grpc_core::CqVerifier::tag(1)));
cleanup_test();
}
@ -171,12 +172,12 @@ static void test_non_null_reserved_on_op() {
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
op->flags = 0;
op->reserved = tag(2);
op->reserved = grpc_core::CqVerifier::tag(2);
op++;
GPR_ASSERT(GRPC_CALL_ERROR ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -192,10 +193,11 @@ static void test_send_initial_metadata_more_than_once() {
op->flags = 0;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), nullptr));
g_state.cqv->Expect(tag(1), false);
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
g_state.cqv->Expect(grpc_core::CqVerifier::tag(1), false);
g_state.cqv->Verify();
op = g_state.ops;
@ -206,8 +208,8 @@ static void test_send_initial_metadata_more_than_once() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -225,8 +227,8 @@ static void test_too_many_metadata() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_METADATA ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -249,8 +251,8 @@ static void test_send_null_message() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_MESSAGE ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -275,14 +277,15 @@ static void test_send_messages_at_the_same_time() {
op->reserved = nullptr;
op++;
op->op = GRPC_OP_SEND_MESSAGE;
op->data.send_message.send_message = static_cast<grpc_byte_buffer*>(tag(2));
op->data.send_message.send_message =
static_cast<grpc_byte_buffer*>(grpc_core::CqVerifier::tag(2));
op->flags = 0;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
grpc_byte_buffer_destroy(request_payload);
cleanup_test();
}
@ -304,8 +307,8 @@ static void test_send_server_status_from_client() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_NOT_ON_CLIENT ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -321,10 +324,11 @@ static void test_receive_initial_metadata_twice_at_client() {
op->flags = 0;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), nullptr));
g_state.cqv->Expect(tag(1), false);
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
g_state.cqv->Expect(grpc_core::CqVerifier::tag(1), false);
g_state.cqv->Verify();
op = g_state.ops;
op->op = GRPC_OP_RECV_INITIAL_METADATA;
@ -335,8 +339,8 @@ static void test_receive_initial_metadata_twice_at_client() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -354,8 +358,8 @@ static void test_receive_message_with_invalid_flags() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_FLAGS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -378,8 +382,8 @@ static void test_receive_two_messages_at_the_same_time() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -397,8 +401,8 @@ static void test_recv_close_on_server_from_client() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_NOT_ON_CLIENT ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -417,10 +421,11 @@ static void test_recv_status_on_client_twice() {
op->flags = 0;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), nullptr));
g_state.cqv->Expect(tag(1), true);
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
g_state.cqv->Expect(grpc_core::CqVerifier::tag(1), true);
g_state.cqv->Verify();
op = g_state.ops;
@ -433,8 +438,8 @@ static void test_recv_status_on_client_twice() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -451,8 +456,8 @@ static void test_send_close_from_client_on_server() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_NOT_ON_SERVER ==
grpc_call_start_batch(g_state.server_call, g_state.ops,
(size_t)(op - g_state.ops), tag(2),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(2), nullptr));
cleanup_test();
}
@ -473,8 +478,8 @@ static void test_recv_status_on_client_from_server() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_NOT_ON_SERVER ==
grpc_call_start_batch(g_state.server_call, g_state.ops,
(size_t)(op - g_state.ops), tag(2),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(2), nullptr));
cleanup_test();
}
@ -495,8 +500,8 @@ static void test_send_status_from_server_with_invalid_flags() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_FLAGS ==
grpc_call_start_batch(g_state.server_call, g_state.ops,
(size_t)(op - g_state.ops), tag(2),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(2), nullptr));
cleanup_test();
}
@ -518,8 +523,8 @@ static void test_too_many_trailing_metadata() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_METADATA ==
grpc_call_start_batch(g_state.server_call, g_state.ops,
(size_t)(op - g_state.ops), tag(2),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(2), nullptr));
cleanup_test();
}
@ -547,8 +552,8 @@ static void test_send_server_status_twice() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.server_call, g_state.ops,
(size_t)(op - g_state.ops), tag(2),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(2), nullptr));
cleanup_test();
}
@ -566,8 +571,8 @@ static void test_recv_close_on_server_with_invalid_flags() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_FLAGS ==
grpc_call_start_batch(g_state.server_call, g_state.ops,
(size_t)(op - g_state.ops), tag(2),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(2), nullptr));
cleanup_test();
}
@ -590,8 +595,8 @@ static void test_recv_close_on_server_twice() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.server_call, g_state.ops,
(size_t)(op - g_state.ops), tag(2),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(2), nullptr));
cleanup_test();
}
@ -613,8 +618,8 @@ static void test_invalid_initial_metadata_reserved_key() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_METADATA ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
cleanup_test();
}
@ -636,8 +641,8 @@ static void test_multiple_ops_in_a_single_batch() {
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1),
nullptr));
(size_t)(op - g_state.ops),
grpc_core::CqVerifier::tag(1), nullptr));
}
cleanup_test();

@ -16,7 +16,6 @@
//
//
#include <stdint.h>
#include <string.h>
#include <grpc/grpc.h>
@ -33,8 +32,6 @@
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
void run_test(bool wait_for_ready) {
gpr_log(GPR_INFO, "TEST: wait_for_ready=%d", wait_for_ready);
@ -78,9 +75,9 @@ void run_test(bool wait_for_ready) {
op->flags = 0;
op->reserved = nullptr;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops,
(size_t)(op - ops), tag(1),
nullptr));
GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(call, ops, (size_t)(op - ops),
grpc_core::CqVerifier::tag(1), nullptr));
{
grpc_core::ExecCtx exec_ctx;
@ -88,7 +85,7 @@ void run_test(bool wait_for_ready) {
}
// verify that all tags get completed
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
gpr_log(GPR_INFO, "call status: %d", status);

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -27,68 +29,24 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Request/response with metadata and payload.
static void test_with_authority_header(grpc_end2end_test_config config) {
static void test_with_authority_header(const CoreTestConfiguration& config) {
grpc_call* c;
grpc_slice request_payload_slice =
grpc_slice_from_copied_string("hello world");
@ -100,9 +58,8 @@ static void test_with_authority_header(grpc_end2end_test_config config) {
{grpc_slice_from_static_string("key2"),
grpc_slice_from_static_string("val2"),
{{nullptr, nullptr, nullptr, nullptr}}}};
grpc_end2end_test_fixture f =
begin_test(config, "test_with_authority_header", nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "test_with_authority_header", nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -113,10 +70,10 @@ static void test_with_authority_header(grpc_end2end_test_config config) {
grpc_slice details;
grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr");
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), &host,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
&host, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -156,11 +113,11 @@ static void test_with_authority_header(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_CANCELLED);
@ -173,12 +130,9 @@ static void test_with_authority_header(grpc_end2end_test_config config) {
grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(response_payload_recv);
end_test(&f);
config.tear_down_data(&f);
}
void authority_not_supported(grpc_end2end_test_config config) {
void authority_not_supported(const CoreTestConfiguration& config) {
if (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER) {
return;
}

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
#include <grpc/slice.h>
@ -26,69 +28,25 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s", test_name, config.name);
f = config.create_fixture(client_args, server_args);
config.init_client(&f, client_args);
config.init_server(&f, server_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void simple_request_body(grpc_end2end_test_fixture f) {
static void simple_request_body(CoreTestFixture* f) {
grpc_call* c;
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -100,10 +58,10 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
grpc_slice details;
grpc_slice host = grpc_slice_from_static_string("slartibartfast.local");
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), &host,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
&host, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -134,11 +92,11 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_INTERNAL);
@ -152,16 +110,12 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
grpc_call_unref(c);
}
static void test_invoke_simple_request(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
f = begin_test(config, "test_invoke_simple_request", nullptr, nullptr);
simple_request_body(f);
end_test(&f);
config.tear_down_data(&f);
static void test_invoke_simple_request(const CoreTestConfiguration& config) {
auto f = begin_test(config, "test_invoke_simple_request", nullptr, nullptr);
simple_request_body(f.get());
}
void bad_hostname(grpc_end2end_test_config config) {
void bad_hostname(const CoreTestConfiguration& config) {
if (config.feature_mask & FEATURE_MASK_SUPPORTS_HOSTNAME_VERIFICATION) {
test_invoke_simple_request(config);
}

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
#include <grpc/slice.h>
@ -27,7 +29,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/surface/channel.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
@ -35,60 +37,23 @@
#define MAX_PING_STRIKES 2
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
}
static void shutdown_server(grpc_end2end_test_fixture* f) {
if (!f->server) return;
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Send more pings than server allows to trigger server's GOAWAY.
static void test_bad_ping(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f = config.create_fixture(nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
grpc_arg client_a[] = {
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA), 0),
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_HTTP2_BDP_PROBE), 0)};
grpc_arg server_a[] = {
grpc_channel_arg_integer_create(
const_cast<char*>(
GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS),
300000 /* 5 minutes */),
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_HTTP2_MAX_PING_STRIKES), MAX_PING_STRIKES),
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_HTTP2_BDP_PROBE), 0)};
grpc_channel_args client_args = {GPR_ARRAY_SIZE(client_a), client_a};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(server_a), server_a};
config.init_client(&f, &client_args);
config.init_server(&f, &server_args);
static void test_bad_ping(const CoreTestConfiguration& config) {
auto f =
config.create_fixture(grpc_core::ChannelArgs(), grpc_core::ChannelArgs());
grpc_core::CqVerifier cqv(f->cq());
auto client_args = grpc_core::ChannelArgs()
.Set(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, 0)
.Set(GRPC_ARG_HTTP2_BDP_PROBE, 0);
auto server_args =
grpc_core::ChannelArgs()
.Set(GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS,
grpc_core::Duration::Minutes(5).millis())
.Set(GRPC_ARG_HTTP2_MAX_PING_STRIKES, MAX_PING_STRIKES)
.Set(GRPC_ARG_HTTP2_BDP_PROBE, 0);
f->InitClient(client_args);
f->InitServer(server_args);
grpc_call* c;
grpc_call* s;
@ -104,9 +69,9 @@ static void test_bad_ping(grpc_end2end_test_config config) {
grpc_slice details;
int was_cancelled = 2;
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -138,15 +103,15 @@ static void test_bad_ping(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
// Send too many pings to the server to trigger the punishment:
@ -156,10 +121,11 @@ static void test_bad_ping(grpc_end2end_test_config config) {
// needed here.
int i;
for (i = 1; i <= MAX_PING_STRIKES + 2; i++) {
grpc_channel_ping(f.client, f.cq, tag(200 + i), nullptr);
cqv.Expect(tag(200 + i), true);
grpc_channel_ping(f->client(), f->cq(), grpc_core::CqVerifier::tag(200 + i),
nullptr);
cqv.Expect(grpc_core::CqVerifier::tag(200 + i), true);
if (i == MAX_PING_STRIKES + 2) {
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
}
cqv.Verify();
}
@ -184,15 +150,16 @@ static void test_bad_ping(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Verify();
grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead));
cqv.Expect(tag(0xdead), true);
grpc_server_shutdown_and_notify(f->server(), f->cq(),
grpc_core::CqVerifier::tag(0xdead));
cqv.Expect(grpc_core::CqVerifier::tag(0xdead), true);
cqv.Verify();
grpc_call_unref(s);
@ -209,37 +176,29 @@ static void test_bad_ping(grpc_end2end_test_config config) {
grpc_metadata_array_destroy(&request_metadata_recv);
grpc_call_details_destroy(&call_details);
grpc_call_unref(c);
end_test(&f);
config.tear_down_data(&f);
}
// Try sending more pings than server allows, but server should be fine because
// max_pings_without_data should limit pings sent out on wire.
static void test_pings_without_data(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f = config.create_fixture(nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
static void test_pings_without_data(const CoreTestConfiguration& config) {
auto f =
config.create_fixture(grpc_core::ChannelArgs(), grpc_core::ChannelArgs());
grpc_core::CqVerifier cqv(f->cq());
// Only allow MAX_PING_STRIKES pings without data (DATA/HEADERS/WINDOW_UPDATE)
// so that the transport will throttle the excess pings.
grpc_arg client_a[] = {
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA),
MAX_PING_STRIKES),
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_HTTP2_BDP_PROBE), 0)};
grpc_arg server_a[] = {
grpc_channel_arg_integer_create(
const_cast<char*>(
GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS),
300000 /* 5 minutes */),
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_HTTP2_MAX_PING_STRIKES), MAX_PING_STRIKES),
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_HTTP2_BDP_PROBE), 0)};
grpc_channel_args client_args = {GPR_ARRAY_SIZE(client_a), client_a};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(server_a), server_a};
config.init_client(&f, &client_args);
config.init_server(&f, &server_args);
auto client_args =
grpc_core::ChannelArgs()
.Set(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, MAX_PING_STRIKES)
.Set(GRPC_ARG_HTTP2_BDP_PROBE, 0);
auto server_args =
grpc_core::ChannelArgs()
.Set(GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS,
grpc_core::Duration::Minutes(5).millis())
.Set(GRPC_ARG_HTTP2_MAX_PING_STRIKES, MAX_PING_STRIKES)
.Set(GRPC_ARG_HTTP2_BDP_PROBE, 0);
f->InitClient(client_args);
f->InitServer(server_args);
grpc_call* c;
grpc_call* s;
@ -255,9 +214,9 @@ static void test_pings_without_data(grpc_end2end_test_config config) {
grpc_slice details;
int was_cancelled = 2;
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -289,15 +248,15 @@ static void test_pings_without_data(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
// Send too many pings to the server similar to the previous test case.
@ -305,9 +264,10 @@ static void test_pings_without_data(grpc_end2end_test_config config) {
// MAX_PING_STRIKES will actually be sent and the rpc will still succeed.
int i;
for (i = 1; i <= MAX_PING_STRIKES + 2; i++) {
grpc_channel_ping(f.client, f.cq, tag(200 + i), nullptr);
grpc_channel_ping(f->client(), f->cq(), grpc_core::CqVerifier::tag(200 + i),
nullptr);
if (i <= MAX_PING_STRIKES) {
cqv.Expect(tag(200 + i), true);
cqv.Expect(grpc_core::CqVerifier::tag(200 + i), true);
}
cqv.Verify();
}
@ -332,21 +292,22 @@ static void test_pings_without_data(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
// Client call should return.
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead));
cqv.Expect(tag(0xdead), true);
grpc_server_shutdown_and_notify(f->server(), f->cq(),
grpc_core::CqVerifier::tag(0xdead));
cqv.Expect(grpc_core::CqVerifier::tag(0xdead), true);
// Also expect the previously blocked pings to complete with an error
cqv.Expect(tag(200 + MAX_PING_STRIKES + 1), false);
cqv.Expect(tag(200 + MAX_PING_STRIKES + 2), false);
cqv.Expect(grpc_core::CqVerifier::tag(200 + MAX_PING_STRIKES + 1), false);
cqv.Expect(grpc_core::CqVerifier::tag(200 + MAX_PING_STRIKES + 2), false);
cqv.Verify();
@ -362,11 +323,9 @@ static void test_pings_without_data(grpc_end2end_test_config config) {
grpc_metadata_array_destroy(&request_metadata_recv);
grpc_call_details_destroy(&call_details);
grpc_call_unref(c);
end_test(&f);
config.tear_down_data(&f);
}
void bad_ping(grpc_end2end_test_config config) {
void bad_ping(const CoreTestConfiguration& config) {
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION);
test_bad_ping(config);
test_pings_without_data(config);

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -34,13 +36,9 @@
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s", test_name, config.name);
client_args =
const_cast<grpc_channel_args*>(grpc_core::CoreConfiguration::Get()
@ -54,59 +52,18 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
.PreconditionChannelArgs(server_args)
.ToC()
.release());
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
grpc_channel_args_destroy(client_args);
grpc_channel_args_destroy(server_args);
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Request/response with metadata and payload.
static void test_request_response_with_metadata_and_payload(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
grpc_call* c;
grpc_call* s;
grpc_slice request_payload_slice =
@ -135,10 +92,9 @@ static void test_request_response_with_metadata_and_payload(
grpc_slice_from_static_string(
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"),
{{nullptr, nullptr, nullptr, nullptr}}}};
grpc_end2end_test_fixture f =
begin_test(config, "test_request_response_with_metadata_and_payload",
nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "test_request_response_with_metadata_and_payload",
nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -152,10 +108,10 @@ static void test_request_response_with_metadata_and_payload(
grpc_slice details;
int was_cancelled = 2;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -197,15 +153,15 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -221,11 +177,11 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -263,12 +219,12 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(103),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(103), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(103), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_OK);
@ -322,12 +278,9 @@ static void test_request_response_with_metadata_and_payload(
grpc_byte_buffer_destroy(response_payload);
grpc_byte_buffer_destroy(request_payload_recv);
grpc_byte_buffer_destroy(response_payload_recv);
end_test(&f);
config.tear_down_data(&f);
}
void binary_metadata(grpc_end2end_test_config config) {
void binary_metadata(const CoreTestConfiguration& config) {
test_request_response_with_metadata_and_payload(config);
}

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
@ -28,6 +30,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
@ -44,76 +47,24 @@ static const char overridden_fake_md_value[] = "overridden_fake_value";
typedef enum { NONE, OVERRIDE, DESTROY, FAIL } override_mode;
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char* test_name,
bool use_secure_call_creds,
int fail_server_auth_check) {
grpc_end2end_test_fixture f;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
bool use_secure_call_creds, int fail_server_auth_check) {
gpr_log(GPR_INFO, "Running test: %s%s/%s", test_name,
use_secure_call_creds ? "_with_secure_call_creds"
: "_with_insecure_call_creds",
config.name);
f = config.create_fixture(nullptr, nullptr);
config.init_client(&f, nullptr);
auto f =
config.create_fixture(grpc_core::ChannelArgs(), grpc_core::ChannelArgs());
f->InitClient(grpc_core::ChannelArgs());
grpc_core::ChannelArgs server_args;
if (fail_server_auth_check) {
grpc_arg fail_auth_arg = {
GRPC_ARG_STRING,
const_cast<char*>(FAIL_AUTH_CHECK_SERVER_ARG_NAME),
{nullptr}};
grpc_channel_args args;
args.num_args = 1;
args.args = &fail_auth_arg;
config.init_server(&f, &args);
} else {
config.init_server(&f, nullptr);
server_args = server_args.Set(FAIL_AUTH_CHECK_SERVER_ARG_NAME, true);
}
f->InitServer(server_args);
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void print_auth_context(int is_client, const grpc_auth_context* ctx) {
const grpc_auth_property* p;
grpc_auth_property_iterator it;
@ -132,8 +83,8 @@ static void print_auth_context(int is_client, const grpc_auth_context* ctx) {
}
static void request_response_with_payload_and_call_creds(
const char* test_name, grpc_end2end_test_config config, override_mode mode,
bool use_secure_call_creds) {
const char* test_name, const CoreTestConfiguration& config,
override_mode mode, bool use_secure_call_creds) {
grpc_call* c = nullptr;
grpc_call* s = nullptr;
grpc_slice request_payload_slice =
@ -144,7 +95,7 @@ static void request_response_with_payload_and_call_creds(
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_byte_buffer* response_payload =
grpc_raw_byte_buffer_create(&response_payload_slice, 1);
grpc_end2end_test_fixture f;
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -161,13 +112,13 @@ static void request_response_with_payload_and_call_creds(
grpc_auth_context* server_auth_context = nullptr;
grpc_auth_context* client_auth_context = nullptr;
f = begin_test(config, test_name, use_secure_call_creds, 0);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, test_name, use_secure_call_creds, 0);
grpc_core::CqVerifier cqv(f->cq());
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
if (use_secure_call_creds) {
creds =
@ -239,22 +190,22 @@ static void request_response_with_payload_and_call_creds(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
if (mode == FAIL) {
// Expect the call to fail since the channel credentials did not satisfy the
// minimum security level requirements.
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_UNAUTHENTICATED);
} else {
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
server_auth_context = grpc_call_auth_context(s);
GPR_ASSERT(server_auth_context != nullptr);
@ -282,10 +233,10 @@ static void request_response_with_payload_and_call_creds(
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
tag(102), nullptr);
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -309,11 +260,11 @@ static void request_response_with_payload_and_call_creds(
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
tag(103), nullptr);
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(103), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(103), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_OK);
@ -388,46 +339,43 @@ static void request_response_with_payload_and_call_creds(
grpc_byte_buffer_destroy(response_payload);
grpc_byte_buffer_destroy(request_payload_recv);
grpc_byte_buffer_destroy(response_payload_recv);
end_test(&f);
config.tear_down_data(&f);
}
static void test_request_response_with_payload_and_call_creds(
grpc_end2end_test_config config, bool use_secure_call_creds) {
const CoreTestConfiguration& config, bool use_secure_call_creds) {
request_response_with_payload_and_call_creds(
"test_request_response_with_payload_and_call_creds", config, NONE,
use_secure_call_creds);
}
static void test_request_response_with_payload_and_overridden_call_creds(
grpc_end2end_test_config config, bool use_secure_call_creds) {
const CoreTestConfiguration& config, bool use_secure_call_creds) {
request_response_with_payload_and_call_creds(
"test_request_response_with_payload_and_overridden_call_creds", config,
OVERRIDE, use_secure_call_creds);
}
static void test_request_response_with_payload_and_deleted_call_creds(
grpc_end2end_test_config config, bool use_secure_call_creds) {
const CoreTestConfiguration& config, bool use_secure_call_creds) {
request_response_with_payload_and_call_creds(
"test_request_response_with_payload_and_deleted_call_creds", config,
DESTROY, use_secure_call_creds);
}
static void test_request_response_with_payload_fail_to_send_call_creds(
grpc_end2end_test_config config, bool use_secure_call_creds) {
const CoreTestConfiguration& config, bool use_secure_call_creds) {
request_response_with_payload_and_call_creds(
"test_request_response_with_payload_fail_to_send_call_creds", config,
FAIL, use_secure_call_creds);
}
static void test_request_with_server_rejecting_client_creds(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
grpc_op ops[6];
grpc_op* op;
grpc_call* c;
grpc_end2end_test_fixture f;
gpr_timespec deadline = five_seconds_from_now();
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
grpc_metadata_array initial_metadata_recv;
grpc_metadata_array trailing_metadata_recv;
grpc_metadata_array request_metadata_recv;
@ -442,13 +390,13 @@ static void test_request_with_server_rejecting_client_creds(
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_call_credentials* creds;
f = begin_test(config, "test_request_with_server_rejecting_client_creds",
false, 1);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "test_request_with_server_rejecting_client_creds",
false, 1);
grpc_core::CqVerifier cqv(f->cq());
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
creds = grpc_md_only_test_credentials_create(fake_md_key, fake_md_value);
@ -494,11 +442,11 @@ static void test_request_with_server_rejecting_client_creds(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(error == GRPC_CALL_OK);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_UNAUTHENTICATED);
@ -513,12 +461,9 @@ static void test_request_with_server_rejecting_client_creds(
grpc_slice_unref(details);
grpc_call_unref(c);
end_test(&f);
config.tear_down_data(&f);
}
void call_creds(grpc_end2end_test_config config) {
void call_creds(const CoreTestConfiguration& config) {
// Test fixtures that support call credentials with a minimum security level
// of GRPC_PRIVACY_AND_INTEGRITY
if (config.feature_mask & FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS) {

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
#include <grpc/slice.h>
@ -32,75 +34,24 @@
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s", test_name, config.name);
f = config.create_fixture(client_args, server_args);
grpc_arg fake_security_name_override = {
GRPC_ARG_STRING,
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
{const_cast<char*>("foo.test.google.fr:1234")}};
grpc_channel_args* new_client_args = grpc_channel_args_copy_and_add(
client_args, &fake_security_name_override, 1);
config.init_client(&f, new_client_args);
grpc_channel_args_destroy(new_client_args);
config.init_server(&f, server_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(
grpc_core::ChannelArgs::FromC(client_args)
.Set(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, "foo.test.google.fr:1234"));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void test_invoke_simple_request(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f =
begin_test(config, "test_invoke_simple_request", nullptr, nullptr);
static void test_invoke_simple_request(const CoreTestConfiguration& config) {
auto f = begin_test(config, "test_invoke_simple_request", nullptr, nullptr);
grpc_call* c;
grpc_call* s;
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -113,9 +64,9 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
int was_cancelled = 2;
char* peer;
gpr_timespec deadline = five_seconds_from_now();
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(
f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS, f->cq(),
grpc_slice_from_static_string("/foo"),
get_host_override_slice("foo.test.google.fr:1234", config), deadline,
nullptr);
@ -154,15 +105,15 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(error == GRPC_CALL_OK);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(error == GRPC_CALL_OK);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
peer = grpc_call_get_peer(s);
@ -194,12 +145,12 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(error == GRPC_CALL_OK);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
@ -217,12 +168,9 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
grpc_call_unref(c);
grpc_call_unref(s);
end_test(&f);
config.tear_down_data(&f);
}
void call_host_override(grpc_end2end_test_config config) {
void call_host_override(const CoreTestConfiguration& config) {
test_invoke_simple_request(config);
}

@ -16,9 +16,10 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <string>
#include <grpc/byte_buffer.h>
@ -37,68 +38,22 @@
#include "test/core/end2end/tests/cancel_test_helpers.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char* test_name,
cancellation_mode mode,
bool use_service_config,
grpc_channel_args* client_args,
grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
cancellation_mode mode, bool use_service_config,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "%s", std::string(80, '*').c_str());
gpr_log(GPR_INFO, "Running test: %s/%s/%s/%s", test_name, config.name,
mode.name, use_service_config ? "service_config" : "client_api");
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Cancel after accept, no payload
static void test_cancel_after_accept(grpc_end2end_test_config config,
static void test_cancel_after_accept(const CoreTestConfiguration& config,
cancellation_mode mode,
bool use_service_config) {
grpc_op ops[6];
@ -142,14 +97,15 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
args = grpc_channel_args_copy_and_add(args, &arg, 1);
}
grpc_end2end_test_fixture f = begin_test(config, "cancel_after_accept", mode,
use_service_config, args, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "cancel_after_accept", mode, use_service_config,
args, nullptr);
grpc_core::CqVerifier cqv(f->cq());
gpr_timespec deadline = use_service_config
? gpr_inf_future(GPR_CLOCK_MONOTONIC)
: five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
: grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(),
grpc_slice_from_static_string("/service/method"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
@ -188,14 +144,15 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error = grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(2));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(2));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(2), true);
cqv.Expect(grpc_core::CqVerifier::tag(2), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -220,14 +177,14 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(3),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(3), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr));
cqv.Expect(tag(3), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(3), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == mode.expect_status || status == GRPC_STATUS_INTERNAL);
@ -251,12 +208,9 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
grpc_core::ExecCtx exec_ctx;
grpc_channel_args_destroy(args);
}
end_test(&f);
config.tear_down_data(&f);
}
void cancel_after_accept(grpc_end2end_test_config config) {
void cancel_after_accept(const CoreTestConfiguration& config) {
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -27,81 +29,36 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/tests/cancel_test_helpers.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char* test_name,
cancellation_mode mode,
grpc_channel_args* client_args,
grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
cancellation_mode mode, grpc_channel_args* client_args,
grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s/%s", test_name, config.name,
mode.name);
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Cancel after accept with a writes closed, no payload
static void test_cancel_after_accept_and_writes_closed(
grpc_end2end_test_config config, cancellation_mode mode) {
const CoreTestConfiguration& config, cancellation_mode mode) {
grpc_op ops[6];
grpc_op* op;
grpc_call* c;
grpc_call* s;
grpc_end2end_test_fixture f =
begin_test(config, "test_cancel_after_accept_and_writes_closed", mode,
nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "test_cancel_after_accept_and_writes_closed",
mode, nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_metadata_array initial_metadata_recv;
grpc_metadata_array trailing_metadata_recv;
grpc_metadata_array request_metadata_recv;
@ -121,10 +78,10 @@ static void test_cancel_after_accept_and_writes_closed(
grpc_raw_byte_buffer_create(&response_payload_slice, 1);
int was_cancelled = 2;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -165,14 +122,15 @@ static void test_cancel_after_accept_and_writes_closed(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error = grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(2));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(2));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(2), true);
cqv.Expect(grpc_core::CqVerifier::tag(2), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -197,14 +155,14 @@ static void test_cancel_after_accept_and_writes_closed(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(3),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(3), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr));
cqv.Expect(tag(3), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(3), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == mode.expect_status || status == GRPC_STATUS_INTERNAL);
@ -223,12 +181,9 @@ static void test_cancel_after_accept_and_writes_closed(
grpc_call_unref(c);
grpc_call_unref(s);
end_test(&f);
config.tear_down_data(&f);
}
void cancel_after_client_done(grpc_end2end_test_config config) {
void cancel_after_client_done(const CoreTestConfiguration& config) {
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {

@ -20,6 +20,9 @@
#include <stdio.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -28,79 +31,35 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/tests/cancel_test_helpers.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char* test_name,
cancellation_mode mode,
size_t test_ops,
grpc_channel_args* client_args,
grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
cancellation_mode mode, size_t test_ops, grpc_channel_args* client_args,
grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s/%s [%" PRIdPTR " ops]", test_name,
config.name, mode.name, test_ops);
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev = grpc_completion_queue_next(
f->cq, grpc_timeout_seconds_to_deadline(5), nullptr);
GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
GPR_ASSERT(ev.tag == tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Cancel after invoke, no payload
static void test_cancel_after_invoke(grpc_end2end_test_config config,
static void test_cancel_after_invoke(const CoreTestConfiguration& config,
cancellation_mode mode, size_t test_ops) {
grpc_op ops[6];
grpc_op* op;
grpc_call* c;
grpc_end2end_test_fixture f = begin_test(config, "test_cancel_after_invoke",
mode, test_ops, nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "test_cancel_after_invoke", mode, test_ops,
nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_metadata_array initial_metadata_recv;
grpc_metadata_array trailing_metadata_recv;
grpc_metadata_array request_metadata_recv;
@ -114,10 +73,10 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config,
grpc_byte_buffer* request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -158,12 +117,13 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, test_ops, tag(1), nullptr);
error = grpc_call_start_batch(c, ops, test_ops, grpc_core::CqVerifier::tag(1),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr));
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == mode.expect_status || status == GRPC_STATUS_INTERNAL);
@ -178,12 +138,9 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config,
grpc_slice_unref(details);
grpc_call_unref(c);
end_test(&f);
config.tear_down_data(&f);
}
void cancel_after_invoke(grpc_end2end_test_config config) {
void cancel_after_invoke(const CoreTestConfiguration& config) {
unsigned i, j;
for (j = 3; j < 6; j++) {

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -35,67 +37,21 @@
#include "test/core/end2end/tests/cancel_test_helpers.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char* test_name,
cancellation_mode mode,
bool use_service_config,
grpc_channel_args* client_args,
grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
cancellation_mode mode, bool use_service_config,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s/%s/%s", test_name, config.name,
mode.name, use_service_config ? "service_config" : "client_api");
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Cancel after accept, no payload
static void test_cancel_after_round_trip(grpc_end2end_test_config config,
static void test_cancel_after_round_trip(const CoreTestConfiguration& config,
cancellation_mode mode,
bool use_service_config) {
grpc_op ops[6];
@ -140,15 +96,15 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config,
args = grpc_channel_args_copy_and_add(args, &arg, 1);
}
grpc_end2end_test_fixture f =
begin_test(config, "cancel_after_round_trip", mode, use_service_config,
args, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "cancel_after_round_trip", mode,
use_service_config, args, nullptr);
grpc_core::CqVerifier cqv(f->cq());
gpr_timespec deadline = use_service_config
? gpr_inf_future(GPR_CLOCK_MONOTONIC)
: five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
: grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(),
grpc_slice_from_static_string("/service/method"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
@ -180,15 +136,15 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -208,12 +164,12 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
grpc_byte_buffer_destroy(request_payload_recv);
@ -235,8 +191,8 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(2),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(2), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr));
@ -253,12 +209,12 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(103),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(2), true);
cqv.Expect(tag(103), true);
cqv.Expect(grpc_core::CqVerifier::tag(2), true);
cqv.Expect(grpc_core::CqVerifier::tag(103), true);
cqv.Verify();
GPR_ASSERT(status == mode.expect_status || status == GRPC_STATUS_INTERNAL);
@ -283,12 +239,9 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config,
grpc_core::ExecCtx exec_ctx;
grpc_channel_args_destroy(args);
}
end_test(&f);
config.tear_down_data(&f);
}
void cancel_after_round_trip(grpc_end2end_test_config config) {
void cancel_after_round_trip(const CoreTestConfiguration& config) {
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {

@ -20,6 +20,9 @@
#include <stdio.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -28,77 +31,32 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char* test_name,
size_t num_ops,
grpc_channel_args* client_args,
grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name, size_t num_ops,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s [%" PRIdPTR " ops]", test_name,
config.name, num_ops);
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Cancel before invoke
static void test_cancel_before_invoke(grpc_end2end_test_config config,
static void test_cancel_before_invoke(const CoreTestConfiguration& config,
size_t test_ops) {
grpc_op ops[6];
grpc_op* op;
grpc_call* c;
grpc_end2end_test_fixture f =
auto f =
begin_test(config, "cancel_before_invoke", test_ops, nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_metadata_array initial_metadata_recv;
grpc_metadata_array trailing_metadata_recv;
grpc_metadata_array request_metadata_recv;
@ -112,10 +70,10 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config,
grpc_byte_buffer* request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
GPR_ASSERT(GRPC_CALL_OK == grpc_call_cancel(c, nullptr));
@ -158,14 +116,15 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, test_ops, tag(1), nullptr);
error = grpc_call_start_batch(c, ops, test_ops, grpc_core::CqVerifier::tag(1),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
// Filter based stack tracks this as a failed op, promise based stack tracks
// it as a successful one with a failed request. The latter probably makes
// more sense, but since we can't tell from outside which case we have we
// accept either.
cqv.Expect(tag(1), grpc_core::CqVerifier::AnyStatus());
cqv.Expect(grpc_core::CqVerifier::tag(1), grpc_core::CqVerifier::AnyStatus());
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_CANCELLED);
@ -180,12 +139,9 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config,
grpc_slice_unref(details);
grpc_call_unref(c);
end_test(&f);
config.tear_down_data(&f);
}
void cancel_before_invoke(grpc_end2end_test_config config) {
void cancel_before_invoke(const CoreTestConfiguration& config) {
size_t i;
for (i = 1; i <= 6; i++) {
test_cancel_before_invoke(config, i);

@ -16,7 +16,8 @@
//
//
#include <stdint.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -24,91 +25,44 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/tests/cancel_test_helpers.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char* test_name,
cancellation_mode mode,
grpc_channel_args* client_args,
grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
cancellation_mode mode, grpc_channel_args* client_args,
grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s/%s", test_name, config.name,
mode.name);
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Cancel and do nothing
static void test_cancel_in_a_vacuum(grpc_end2end_test_config config,
static void test_cancel_in_a_vacuum(const CoreTestConfiguration& config,
cancellation_mode mode) {
grpc_call* c;
grpc_end2end_test_fixture f =
auto f =
begin_test(config, "test_cancel_in_a_vacuum", mode, nullptr, nullptr);
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr));
grpc_call_unref(c);
end_test(&f);
config.tear_down_data(&f);
}
void cancel_in_a_vacuum(grpc_end2end_test_config config) {
void cancel_in_a_vacuum(const CoreTestConfiguration& config) {
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {

@ -20,7 +20,8 @@
#include <stdio.h>
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -31,73 +32,27 @@
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
#include "src/core/lib/surface/event_string.h"
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char* test_name,
size_t num_ops,
grpc_channel_args* client_args,
grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name, size_t num_ops,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s [%" PRIdPTR " ops]", test_name,
config.name, num_ops);
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev = grpc_completion_queue_next(
f->cq, grpc_timeout_seconds_to_deadline(5), nullptr);
gpr_log(GPR_DEBUG, "shutdown event: %s", grpc_event_string(&ev).c_str());
GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
GPR_ASSERT(ev.tag == tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
static void end_test(grpc_end2end_test_fixture* f) {
shutdown_client(f);
shutdown_server(f);
grpc_completion_queue_shutdown(f->cq);
drain_cq(f->cq);
grpc_completion_queue_destroy(f->cq);
}
static void simple_request_body(grpc_end2end_test_config /*config*/,
grpc_end2end_test_fixture f, size_t num_ops) {
static void simple_request_body(const CoreTestConfiguration& /*config*/,
CoreTestFixture* f, size_t num_ops) {
grpc_call* c;
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -108,10 +63,10 @@ static void simple_request_body(grpc_end2end_test_config /*config*/,
gpr_log(GPR_DEBUG, "test with %" PRIuPTR " ops", num_ops);
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -141,7 +96,8 @@ static void simple_request_body(grpc_end2end_test_config /*config*/,
op->reserved = nullptr;
op++;
GPR_ASSERT(num_ops <= (size_t)(op - ops));
error = grpc_call_start_batch(c, ops, num_ops, tag(1), nullptr);
error = grpc_call_start_batch(c, ops, num_ops, grpc_core::CqVerifier::tag(1),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
char* dynamic_string = gpr_strdup("xyz");
@ -151,7 +107,7 @@ static void simple_request_body(grpc_end2end_test_config /*config*/,
// string, test this guarantee.
gpr_free(dynamic_string);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
@ -164,18 +120,14 @@ static void simple_request_body(grpc_end2end_test_config /*config*/,
grpc_call_unref(c);
}
static void test_invoke_simple_request(grpc_end2end_test_config config,
static void test_invoke_simple_request(const CoreTestConfiguration& config,
size_t num_ops) {
grpc_end2end_test_fixture f;
f = begin_test(config, "test_invoke_simple_request", num_ops, nullptr,
nullptr);
simple_request_body(config, f, num_ops);
end_test(&f);
config.tear_down_data(&f);
auto f = begin_test(config, "test_invoke_simple_request", num_ops, nullptr,
nullptr);
simple_request_body(config, f.get(), num_ops);
}
void cancel_with_status(grpc_end2end_test_config config) {
void cancel_with_status(const CoreTestConfiguration& config) {
size_t i;
for (i = 1; i <= 4; i++) {
test_invoke_simple_request(config, i);

@ -20,6 +20,8 @@
#include <string.h>
#include <functional>
#include <memory>
#include <string>
#include <grpc/grpc.h>
@ -37,68 +39,22 @@
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void run_one_request(grpc_end2end_test_config /*config*/,
grpc_end2end_test_fixture f,
bool request_is_success) {
static void run_one_request(const CoreTestConfiguration& /*config*/,
CoreTestFixture* f, bool request_is_success) {
grpc_call* c;
grpc_call* s;
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -110,10 +66,10 @@ static void run_one_request(grpc_end2end_test_config /*config*/,
grpc_slice details;
int was_cancelled = 2;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -145,15 +101,15 @@ static void run_one_request(grpc_end2end_test_config /*config*/,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -177,12 +133,12 @@ static void run_one_request(grpc_end2end_test_config /*config*/,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz"));
@ -198,9 +154,7 @@ static void run_one_request(grpc_end2end_test_config /*config*/,
grpc_call_unref(s);
}
static void test_channelz(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
static void test_channelz(const CoreTestConfiguration& config) {
grpc_arg arg[] = {
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE),
@ -209,13 +163,13 @@ static void test_channelz(grpc_end2end_test_config config) {
const_cast<char*>(GRPC_ARG_ENABLE_CHANNELZ), true)};
grpc_channel_args args = {GPR_ARRAY_SIZE(arg), arg};
f = begin_test(config, "test_channelz", &args, &args);
auto f = begin_test(config, "test_channelz", &args, &args);
grpc_core::channelz::ChannelNode* channelz_channel =
grpc_channel_get_channelz_node(f.client);
grpc_channel_get_channelz_node(f->client());
GPR_ASSERT(channelz_channel != nullptr);
grpc_core::channelz::ServerNode* channelz_server =
grpc_core::Server::FromC(f.server)->channelz_node();
grpc_core::Server::FromC(f->server())->channelz_node();
GPR_ASSERT(channelz_server != nullptr);
std::string json = channelz_channel->RenderJsonString();
@ -225,14 +179,14 @@ static void test_channelz(grpc_end2end_test_config config) {
GPR_ASSERT(json.find("\"callsSucceeded\"") == json.npos);
// one successful request
run_one_request(config, f, true);
run_one_request(config, f.get(), true);
json = channelz_channel->RenderJsonString();
GPR_ASSERT(json.find("\"callsStarted\":\"1\"") != json.npos);
GPR_ASSERT(json.find("\"callsSucceeded\":\"1\"") != json.npos);
// one failed request
run_one_request(config, f, false);
run_one_request(config, f.get(), false);
json = channelz_channel->RenderJsonString();
GPR_ASSERT(json.find("\"callsStarted\":\"2\"") != json.npos);
@ -254,14 +208,10 @@ static void test_channelz(grpc_end2end_test_config config) {
json = channelz_server->RenderServerSockets(0, 100);
GPR_ASSERT(json.find("\"end\":true") != json.npos);
end_test(&f);
config.tear_down_data(&f);
}
static void test_channelz_with_channel_trace(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
static void test_channelz_with_channel_trace(
const CoreTestConfiguration& config) {
grpc_arg arg[] = {
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE),
@ -270,16 +220,16 @@ static void test_channelz_with_channel_trace(grpc_end2end_test_config config) {
const_cast<char*>(GRPC_ARG_ENABLE_CHANNELZ), true)};
grpc_channel_args args = {GPR_ARRAY_SIZE(arg), arg};
f = begin_test(config, "test_channelz_with_channel_trace", &args, &args);
auto f = begin_test(config, "test_channelz_with_channel_trace", &args, &args);
grpc_core::channelz::ChannelNode* channelz_channel =
grpc_channel_get_channelz_node(f.client);
grpc_channel_get_channelz_node(f->client());
GPR_ASSERT(channelz_channel != nullptr);
grpc_core::channelz::ServerNode* channelz_server =
grpc_core::Server::FromC(f.server)->channelz_node();
grpc_core::Server::FromC(f->server())->channelz_node();
GPR_ASSERT(channelz_server != nullptr);
run_one_request(config, f, true);
run_one_request(config, f.get(), true);
std::string json = channelz_channel->RenderJsonString();
GPR_ASSERT(json.find("\"trace\"") != json.npos);
@ -290,14 +240,9 @@ static void test_channelz_with_channel_trace(grpc_end2end_test_config config) {
GPR_ASSERT(json.find("\"trace\"") != json.npos);
GPR_ASSERT(json.find("\"description\":\"Server created\"") != json.npos);
GPR_ASSERT(json.find("\"severity\":\"CT_INFO\"") != json.npos);
end_test(&f);
config.tear_down_data(&f);
}
static void test_channelz_disabled(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
static void test_channelz_disabled(const CoreTestConfiguration& config) {
grpc_arg arg[] = {
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE),
@ -306,18 +251,16 @@ static void test_channelz_disabled(grpc_end2end_test_config config) {
const_cast<char*>(GRPC_ARG_ENABLE_CHANNELZ), false)};
grpc_channel_args args = {GPR_ARRAY_SIZE(arg), arg};
f = begin_test(config, "test_channelz_disabled", &args, &args);
auto f = begin_test(config, "test_channelz_disabled", &args, &args);
grpc_core::channelz::ChannelNode* channelz_channel =
grpc_channel_get_channelz_node(f.client);
grpc_channel_get_channelz_node(f->client());
GPR_ASSERT(channelz_channel == nullptr);
// one successful request
run_one_request(config, f, true);
run_one_request(config, f.get(), true);
GPR_ASSERT(channelz_channel == nullptr);
end_test(&f);
config.tear_down_data(&f);
}
void channelz(grpc_end2end_test_config config) {
void channelz(const CoreTestConfiguration& config) {
test_channelz(config);
test_channelz_with_channel_trace(config);
test_channelz_disabled(config);

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -27,77 +29,32 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Client streaming test where the client sends a bunch of messages and the
// server reads them. After reading some messages, the server sends the status.
// Client writes fail after that due to the end of stream and the client
// subsequently requests and receives the status.
static void test_client_streaming(grpc_end2end_test_config config,
static void test_client_streaming(const CoreTestConfiguration& config,
int messages) {
grpc_end2end_test_fixture f =
begin_test(config, "test_client_streaming", nullptr, nullptr);
auto f = begin_test(config, "test_client_streaming", nullptr, nullptr);
grpc_call* c;
grpc_call* s;
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -113,10 +70,10 @@ static void test_client_streaming(grpc_end2end_test_config config,
grpc_slice request_payload_slice =
grpc_slice_from_copied_string("hello world");
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -136,15 +93,15 @@ static void test_client_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(100));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(100));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(100), true);
cqv.Expect(grpc_core::CqVerifier::tag(100), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -154,12 +111,12 @@ static void test_client_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(101),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(101), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
// Client writes bunch of messages and server reads them
@ -173,7 +130,7 @@ static void test_client_streaming(grpc_end2end_test_config config,
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
tag(103), nullptr);
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
grpc_byte_buffer_destroy(request_payload);
@ -185,10 +142,10 @@ static void test_client_streaming(grpc_end2end_test_config config,
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
tag(102), nullptr);
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(103), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(103), true);
cqv.Verify();
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
grpc_byte_buffer_destroy(request_payload_recv);
@ -205,10 +162,10 @@ static void test_client_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(104),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(104), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(104), true);
cqv.Expect(grpc_core::CqVerifier::tag(104), true);
cqv.Verify();
// Do an empty verify to make sure that the client receives the status
cqv.VerifyEmpty();
@ -222,11 +179,11 @@ static void test_client_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(103),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
grpc_byte_buffer_destroy(request_payload);
cqv.Expect(tag(103), false);
cqv.Expect(grpc_core::CqVerifier::tag(103), false);
cqv.Verify();
// Client sends close and requests status
@ -243,10 +200,10 @@ static void test_client_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(3),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(3), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(3), true);
cqv.Expect(grpc_core::CqVerifier::tag(3), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz"));
@ -261,12 +218,9 @@ static void test_client_streaming(grpc_end2end_test_config config,
grpc_metadata_array_destroy(&request_metadata_recv);
grpc_call_details_destroy(&call_details);
grpc_slice_unref(details);
end_test(&f);
config.tear_down_data(&f);
}
void client_streaming(grpc_end2end_test_config config) {
void client_streaming(const CoreTestConfiguration& config) {
for (int i = 0; i < 10; i++) {
test_client_streaming(config, i);
}

@ -19,7 +19,9 @@
#include <stdint.h>
#include <string.h>
#include <functional>
#include <initializer_list>
#include <memory>
#include <string>
#include "absl/strings/str_format.h"
@ -42,66 +44,22 @@
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(
grpc_end2end_test_config config, const char* test_name,
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
const grpc_channel_args* client_args, const grpc_channel_args* server_args,
bool decompress_in_core) {
grpc_end2end_test_fixture f;
gpr_log(GPR_INFO, "Running test: %s%s/%s", test_name,
decompress_in_core ? "" : "_with_decompression_disabled",
config.name);
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void request_for_disabled_algorithm(
grpc_end2end_test_config config, const char* test_name,
const CoreTestConfiguration& config, const char* test_name,
uint32_t send_flags_bitmask,
grpc_compression_algorithm algorithm_to_disable,
grpc_compression_algorithm requested_client_compression_algorithm,
@ -113,7 +71,7 @@ static void request_for_disabled_algorithm(
grpc_byte_buffer* request_payload;
grpc_core::ChannelArgs client_args;
grpc_core::ChannelArgs server_args;
grpc_end2end_test_fixture f;
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -150,14 +108,14 @@ static void request_for_disabled_algorithm(
server_args.Set(GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION, false);
}
f = begin_test(config, test_name, client_args.ToC().get(),
server_args.ToC().get(), decompress_in_core);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, test_name, client_args.ToC().get(),
server_args.ToC().get(), decompress_in_core);
grpc_core::CqVerifier cqv(f->cq());
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -165,9 +123,9 @@ static void request_for_disabled_algorithm(
grpc_metadata_array_init(&request_metadata_recv);
grpc_call_details_init(&call_details);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
memset(ops, 0, sizeof(ops));
@ -203,12 +161,12 @@ static void request_for_disabled_algorithm(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
op = ops;
@ -222,11 +180,11 @@ static void request_for_disabled_algorithm(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), false);
cqv.Expect(grpc_core::CqVerifier::tag(102), false);
op = ops;
op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
@ -234,11 +192,11 @@ static void request_for_disabled_algorithm(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(103),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(103), true);
cqv.Expect(grpc_core::CqVerifier::tag(103), true);
cqv.Verify();
// call was cancelled (closed) ...
@ -266,12 +224,10 @@ static void request_for_disabled_algorithm(
grpc_slice_unref(request_payload_slice);
grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(request_payload_recv);
end_test(&f);
config.tear_down_data(&f);
}
static void request_with_payload_template_inner(
grpc_end2end_test_config config, const char* test_name,
const CoreTestConfiguration& config, const char* test_name,
uint32_t client_send_flags_bitmask,
grpc_compression_algorithm default_client_channel_compression_algorithm,
grpc_compression_algorithm default_server_channel_compression_algorithm,
@ -286,7 +242,7 @@ static void request_with_payload_template_inner(
grpc_byte_buffer* request_payload = nullptr;
grpc_core::ChannelArgs client_args;
grpc_core::ChannelArgs server_args;
grpc_end2end_test_fixture f;
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -325,14 +281,14 @@ static void request_with_payload_template_inner(
server_args =
server_args.Set(GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION, false);
}
f = begin_test(config, test_name, client_args.ToC().get(),
server_args.ToC().get(), decompress_in_core);
grpc_core::CqVerifier cqv(f.cq);
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
auto f = begin_test(config, test_name, client_args.ToC().get(),
server_args.ToC().get(), decompress_in_core);
grpc_core::CqVerifier cqv(f->cq());
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -349,10 +305,10 @@ static void request_with_payload_template_inner(
op->flags = client_send_flags_bitmask;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(2),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(2), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(2), true);
cqv.Expect(grpc_core::CqVerifier::tag(2), true);
}
memset(ops, 0, sizeof(ops));
op = ops;
@ -378,15 +334,15 @@ static void request_with_payload_template_inner(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(100));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(100));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(100), true);
cqv.Expect(grpc_core::CqVerifier::tag(100), true);
cqv.Verify();
GPR_ASSERT(grpc_core::BitCount(
@ -418,8 +374,8 @@ static void request_with_payload_template_inner(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(101),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(101), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
for (int i = 0; i < 2; i++) {
response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1);
@ -434,9 +390,9 @@ static void request_with_payload_template_inner(
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
tag(2), nullptr);
grpc_core::CqVerifier::tag(2), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(2), true);
cqv.Expect(grpc_core::CqVerifier::tag(2), true);
}
memset(ops, 0, sizeof(ops));
@ -447,10 +403,10 @@ static void request_with_payload_template_inner(
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
tag(102), nullptr);
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Verify();
GPR_ASSERT(request_payload_recv->type == GRPC_BB_RAW);
@ -467,7 +423,7 @@ static void request_with_payload_template_inner(
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
tag(103), nullptr);
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
memset(ops, 0, sizeof(ops));
@ -477,12 +433,12 @@ static void request_with_payload_template_inner(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(3),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(3), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(103), true);
cqv.Expect(tag(3), true);
cqv.Expect(grpc_core::CqVerifier::tag(103), true);
cqv.Expect(grpc_core::CqVerifier::tag(3), true);
cqv.Verify();
GPR_ASSERT(response_payload_recv->type == GRPC_BB_RAW);
@ -513,8 +469,8 @@ static void request_with_payload_template_inner(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(4),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(4), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
memset(ops, 0, sizeof(ops));
@ -527,14 +483,14 @@ static void request_with_payload_template_inner(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(104),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(104), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(tag(4), true);
cqv.Expect(tag(101), true);
cqv.Expect(tag(104), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(4), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(104), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_OK);
@ -550,13 +506,10 @@ static void request_with_payload_template_inner(
grpc_call_unref(c);
grpc_call_unref(s);
end_test(&f);
config.tear_down_data(&f);
}
static void request_with_payload_template(
grpc_end2end_test_config config, const char* test_name,
const CoreTestConfiguration& config, const char* test_name,
uint32_t client_send_flags_bitmask,
grpc_compression_algorithm default_client_channel_compression_algorithm,
grpc_compression_algorithm default_server_channel_compression_algorithm,
@ -582,7 +535,7 @@ static void request_with_payload_template(
}
static void test_invoke_request_with_exceptionally_uncompressed_payload(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
request_with_payload_template(
config, "test_invoke_request_with_exceptionally_uncompressed_payload",
GRPC_WRITE_NO_COMPRESS, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP,
@ -591,7 +544,7 @@ static void test_invoke_request_with_exceptionally_uncompressed_payload(
}
static void test_invoke_request_with_uncompressed_payload(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
request_with_payload_template(
config, "test_invoke_request_with_uncompressed_payload", 0,
GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE,
@ -600,7 +553,7 @@ static void test_invoke_request_with_uncompressed_payload(
}
static void test_invoke_request_with_compressed_payload(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
request_with_payload_template(
config, "test_invoke_request_with_compressed_payload", 0,
GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP,
@ -609,7 +562,7 @@ static void test_invoke_request_with_compressed_payload(
}
static void test_invoke_request_with_send_message_before_initial_metadata(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
request_with_payload_template(
config, "test_invoke_request_with_compressed_payload", 0,
GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP,
@ -618,7 +571,7 @@ static void test_invoke_request_with_send_message_before_initial_metadata(
}
static void test_invoke_request_with_server_level(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
request_with_payload_template(
config, "test_invoke_request_with_server_level", 0, GRPC_COMPRESS_NONE,
GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE /* ignored */,
@ -626,7 +579,7 @@ static void test_invoke_request_with_server_level(
}
static void test_invoke_request_with_compressed_payload_md_override(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
grpc_metadata gzip_compression_override;
grpc_metadata identity_compression_override;
@ -666,7 +619,7 @@ static void test_invoke_request_with_compressed_payload_md_override(
}
static void test_invoke_request_with_disabled_algorithm(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
request_for_disabled_algorithm(config,
"test_invoke_request_with_disabled_algorithm",
0, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP,
@ -677,7 +630,7 @@ static void test_invoke_request_with_disabled_algorithm(
GRPC_STATUS_UNIMPLEMENTED, nullptr, true);
}
void compressed_payload(grpc_end2end_test_config config) {
void compressed_payload(const CoreTestConfiguration& config) {
test_invoke_request_with_exceptionally_uncompressed_payload(config);
test_invoke_request_with_uncompressed_payload(config);
test_invoke_request_with_compressed_payload(config);

@ -16,7 +16,8 @@
//
//
#include <stdint.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/support/log.h>
@ -30,8 +31,6 @@
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
typedef struct {
gpr_event started;
grpc_channel* channel;
@ -57,26 +56,26 @@ static void child_thread(void* arg) {
ev = grpc_completion_queue_next(ce->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC),
nullptr);
GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
GPR_ASSERT(ev.tag == tag(1));
GPR_ASSERT(ev.tag == grpc_core::CqVerifier::tag(1));
GPR_ASSERT(ev.success == 0);
}
static void test_connectivity(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f = config.create_fixture(nullptr, nullptr);
static void test_connectivity(const CoreTestConfiguration& config) {
auto f =
config.create_fixture(grpc_core::ChannelArgs(), grpc_core::ChannelArgs());
grpc_connectivity_state state;
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
child_events ce;
auto client_args = grpc_core::ChannelArgs()
.Set(GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS, 1000)
.Set(GRPC_ARG_MAX_RECONNECT_BACKOFF_MS, 1000)
.Set(GRPC_ARG_MIN_RECONNECT_BACKOFF_MS, 5000)
.ToC();
.Set(GRPC_ARG_MIN_RECONNECT_BACKOFF_MS, 5000);
config.init_client(&f, client_args.get());
f->InitClient(client_args);
ce.channel = f.client;
ce.cq = f.cq;
ce.channel = f->client();
ce.cq = f->cq();
gpr_event_init(&ce.started);
grpc_core::Thread thd("grpc_connectivity", child_thread, &ce);
thd.Start();
@ -84,49 +83,50 @@ static void test_connectivity(grpc_end2end_test_config config) {
gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC));
// channels should start life in IDLE, and stay there
GPR_ASSERT(grpc_channel_check_connectivity_state(f.client, 0) ==
GPR_ASSERT(grpc_channel_check_connectivity_state(f->client(), 0) ==
GRPC_CHANNEL_IDLE);
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100));
GPR_ASSERT(grpc_channel_check_connectivity_state(f.client, 0) ==
GPR_ASSERT(grpc_channel_check_connectivity_state(f->client(), 0) ==
GRPC_CHANNEL_IDLE);
// start watching for a change
gpr_log(GPR_DEBUG, "watching");
grpc_channel_watch_connectivity_state(
f.client, GRPC_CHANNEL_IDLE, gpr_now(GPR_CLOCK_MONOTONIC), f.cq, tag(1));
grpc_channel_watch_connectivity_state(f->client(), GRPC_CHANNEL_IDLE,
gpr_now(GPR_CLOCK_MONOTONIC), f->cq(),
grpc_core::CqVerifier::tag(1));
// eventually the child thread completion should trigger
thd.Join();
// check that we're still in idle, and start connecting
GPR_ASSERT(grpc_channel_check_connectivity_state(f.client, 1) ==
GPR_ASSERT(grpc_channel_check_connectivity_state(f->client(), 1) ==
GRPC_CHANNEL_IDLE);
// start watching for a change
grpc_channel_watch_connectivity_state(f.client, GRPC_CHANNEL_IDLE,
grpc_channel_watch_connectivity_state(f->client(), GRPC_CHANNEL_IDLE,
grpc_timeout_seconds_to_deadline(10),
f.cq, tag(2));
f->cq(), grpc_core::CqVerifier::tag(2));
// and now the watch should trigger
cqv.Expect(tag(2), true);
cqv.Expect(grpc_core::CqVerifier::tag(2), true);
cqv.Verify();
state = grpc_channel_check_connectivity_state(f.client, 0);
state = grpc_channel_check_connectivity_state(f->client(), 0);
GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE ||
state == GRPC_CHANNEL_CONNECTING);
// quickly followed by a transition to TRANSIENT_FAILURE
grpc_channel_watch_connectivity_state(f.client, GRPC_CHANNEL_CONNECTING,
grpc_channel_watch_connectivity_state(f->client(), GRPC_CHANNEL_CONNECTING,
grpc_timeout_seconds_to_deadline(10),
f.cq, tag(3));
cqv.Expect(tag(3), true);
f->cq(), grpc_core::CqVerifier::tag(3));
cqv.Expect(grpc_core::CqVerifier::tag(3), true);
cqv.Verify();
state = grpc_channel_check_connectivity_state(f.client, 0);
state = grpc_channel_check_connectivity_state(f->client(), 0);
GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE ||
state == GRPC_CHANNEL_CONNECTING);
gpr_log(GPR_DEBUG, "*** STARTING SERVER ***");
// now let's bring up a server to connect to
config.init_server(&f, nullptr);
f->InitServer(grpc_core::ChannelArgs());
gpr_log(GPR_DEBUG, "*** STARTED SERVER ***");
@ -134,10 +134,11 @@ static void test_connectivity(grpc_end2end_test_config config) {
// READY is reached
while (state != GRPC_CHANNEL_READY) {
grpc_channel_watch_connectivity_state(
f.client, state, grpc_timeout_seconds_to_deadline(10), f.cq, tag(4));
cqv.Expect(tag(4), true);
f->client(), state, grpc_timeout_seconds_to_deadline(10), f->cq(),
grpc_core::CqVerifier::tag(4));
cqv.Expect(grpc_core::CqVerifier::tag(4), true);
cqv.Verify(grpc_core::Duration::Seconds(20));
state = grpc_channel_check_connectivity_state(f.client, 0);
state = grpc_channel_check_connectivity_state(f->client(), 0);
GPR_ASSERT(state == GRPC_CHANNEL_READY ||
state == GRPC_CHANNEL_CONNECTING ||
state == GRPC_CHANNEL_TRANSIENT_FAILURE);
@ -147,29 +148,19 @@ static void test_connectivity(grpc_end2end_test_config config) {
// we should go immediately to TRANSIENT_FAILURE
gpr_log(GPR_DEBUG, "*** SHUTTING DOWN SERVER ***");
grpc_channel_watch_connectivity_state(f.client, GRPC_CHANNEL_READY,
grpc_channel_watch_connectivity_state(f->client(), GRPC_CHANNEL_READY,
grpc_timeout_seconds_to_deadline(10),
f.cq, tag(5));
f->cq(), grpc_core::CqVerifier::tag(5));
grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead));
grpc_server_shutdown_and_notify(f->server(), f->cq(),
grpc_core::CqVerifier::tag(0xdead));
cqv.Expect(tag(5), true);
cqv.Expect(tag(0xdead), true);
cqv.Expect(grpc_core::CqVerifier::tag(5), true);
cqv.Expect(grpc_core::CqVerifier::tag(0xdead), true);
cqv.Verify();
state = grpc_channel_check_connectivity_state(f.client, 0);
state = grpc_channel_check_connectivity_state(f->client(), 0);
GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE ||
state == GRPC_CHANNEL_CONNECTING || state == GRPC_CHANNEL_IDLE);
// cleanup server
grpc_server_destroy(f.server);
gpr_log(GPR_DEBUG, "*** SHUTDOWN SERVER ***");
grpc_channel_destroy(f.client);
grpc_completion_queue_shutdown(f.cq);
grpc_completion_queue_destroy(f.cq);
config.tear_down_data(&f);
}
static void cb_watch_connectivity(grpc_completion_queue_functor* functor,
@ -193,16 +184,17 @@ static void cb_shutdown(grpc_completion_queue_functor* functor,
}
static void test_watch_connectivity_cq_callback(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
CallbackContext cb_ctx(cb_watch_connectivity);
CallbackContext cb_shutdown_ctx(cb_shutdown);
grpc_completion_queue* cq;
grpc_end2end_test_fixture f = config.create_fixture(nullptr, nullptr);
auto f =
config.create_fixture(grpc_core::ChannelArgs(), grpc_core::ChannelArgs());
config.init_client(&f, nullptr);
f->InitClient(grpc_core::ChannelArgs());
// start connecting
grpc_channel_check_connectivity_state(f.client, 1);
grpc_channel_check_connectivity_state(f->client(), 1);
// create the cq callback
cq = grpc_completion_queue_create_for_callback(&cb_shutdown_ctx.functor,
@ -210,7 +202,7 @@ static void test_watch_connectivity_cq_callback(
// start watching for any change, cb is immediately called
// and no dead lock should be raised
grpc_channel_watch_connectivity_state(f.client, GRPC_CHANNEL_IDLE,
grpc_channel_watch_connectivity_state(f->client(), GRPC_CHANNEL_IDLE,
grpc_timeout_seconds_to_deadline(3), cq,
&cb_ctx.functor);
@ -224,18 +216,10 @@ static void test_watch_connectivity_cq_callback(
grpc_completion_queue_shutdown(cq);
gpr_event_wait(&cb_shutdown_ctx.finished,
gpr_inf_future(GPR_CLOCK_MONOTONIC));
// cleanup
grpc_channel_destroy(f.client);
grpc_completion_queue_destroy(cq);
// cq is not used in this test
grpc_completion_queue_destroy(f.cq);
config.tear_down_data(&f);
}
void connectivity(grpc_end2end_test_config config) {
void connectivity(const CoreTestConfiguration& config) {
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION);
test_connectivity(config);
test_watch_connectivity_cq_callback(config);

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
#include <grpc/slice.h>
@ -27,72 +29,27 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %s/%s", test_name, config.name);
f = config.create_fixture(client_args, server_args);
config.init_client(&f, client_args);
config.init_server(&f, server_args);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void test_invoke_simple_request(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f =
begin_test(config, "test_invoke_simple_request", nullptr, nullptr);
static void test_invoke_simple_request(const CoreTestConfiguration& config) {
auto f = begin_test(config, "test_invoke_simple_request", nullptr, nullptr);
grpc_call* c;
grpc_call* s;
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -105,10 +62,10 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
int was_cancelled = 2;
char* peer;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
peer = grpc_call_get_peer(c);
@ -144,15 +101,15 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(error == GRPC_CALL_OK);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(error == GRPC_CALL_OK);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
peer = grpc_call_get_peer(s);
@ -184,12 +141,12 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(error == GRPC_CALL_OK);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
@ -213,12 +170,9 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
grpc_call_unref(c);
grpc_call_unref(s);
end_test(&f);
config.tear_down_data(&f);
}
void default_host(grpc_end2end_test_config config) {
void default_host(const CoreTestConfiguration& config) {
test_invoke_simple_request(config);
}

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
#include <grpc/slice.h>
@ -26,51 +28,14 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
}
static void shutdown_server(grpc_end2end_test_fixture* f) {
if (!f->server) return;
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void do_request_and_shutdown_server(grpc_end2end_test_config /*config*/,
grpc_end2end_test_fixture* f,
grpc_core::CqVerifier& cqv) {
static void do_request_and_shutdown_server(
const CoreTestConfiguration& /*config*/, CoreTestFixture* f,
grpc_core::CqVerifier& cqv) {
grpc_call* c;
grpc_call* s;
grpc_op ops[6];
@ -84,9 +49,9 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config /*config*/,
grpc_slice details;
int was_cancelled = 2;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f->client, nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq, grpc_slice_from_static_string("/foo"),
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
@ -118,20 +83,21 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config /*config*/,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f->server, &s, &call_details,
&request_metadata_recv, f->cq, f->cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
// should be able to shut down the server early
// - and still complete the request
grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000));
grpc_server_shutdown_and_notify(f->server(), f->cq(),
grpc_core::CqVerifier::tag(1000));
memset(ops, 0, sizeof(ops));
op = ops;
@ -153,13 +119,13 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config /*config*/,
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(tag(1000), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1000), true);
cqv.Verify();
// Please refer https://github.com/grpc/grpc/issues/21221 for additional
// details.
@ -185,28 +151,26 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config /*config*/,
grpc_call_unref(s);
}
static void disappearing_server_test(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f = config.create_fixture(nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
static void disappearing_server_test(const CoreTestConfiguration& config) {
auto f =
config.create_fixture(grpc_core::ChannelArgs(), grpc_core::ChannelArgs());
grpc_core::CqVerifier cqv(f->cq());
gpr_log(GPR_INFO, "Running test: %s/%s", "disappearing_server_test",
config.name);
config.init_client(&f, nullptr);
config.init_server(&f, nullptr);
f->InitClient(grpc_core::ChannelArgs());
f->InitServer(grpc_core::ChannelArgs());
do_request_and_shutdown_server(config, &f, cqv);
do_request_and_shutdown_server(config, f.get(), cqv);
// now destroy and recreate the server
config.init_server(&f, nullptr);
do_request_and_shutdown_server(config, &f, cqv);
f->InitServer(grpc_core::ChannelArgs());
end_test(&f);
config.tear_down_data(&f);
do_request_and_shutdown_server(config, f.get(), cqv);
}
void disappearing_server(grpc_end2end_test_config config) {
void disappearing_server(const CoreTestConfiguration& config) {
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION);
#ifndef GPR_WINDOWS // b/148110727 for more details
disappearing_server_test(config);

@ -16,7 +16,8 @@
//
//
#include <stdint.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
@ -24,97 +25,50 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void empty_batch_body(grpc_end2end_test_config /*config*/,
grpc_end2end_test_fixture f) {
static void empty_batch_body(const CoreTestConfiguration& /*config*/,
CoreTestFixture* f) {
grpc_call* c;
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_call_error error;
grpc_op* op = nullptr;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
error = grpc_call_start_batch(c, op, 0, tag(1), nullptr);
error =
grpc_call_start_batch(c, op, 0, grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
grpc_call_unref(c);
}
static void test_invoke_empty_body(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
f = begin_test(config, "test_invoke_empty_body", nullptr, nullptr);
empty_batch_body(config, f);
end_test(&f);
config.tear_down_data(&f);
static void test_invoke_empty_body(const CoreTestConfiguration& config) {
auto f = begin_test(config, "test_invoke_empty_body", nullptr, nullptr);
empty_batch_body(config, f.get());
}
void empty_batch(grpc_end2end_test_config config) {
void empty_batch(const CoreTestConfiguration& config) {
test_invoke_empty_body(config);
}

@ -19,6 +19,9 @@
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include "absl/status/status.h"
#include <grpc/byte_buffer.h>
@ -29,6 +32,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_fwd.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h"
@ -43,73 +47,27 @@
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Simple request via a server filter that always closes the stream.
static void test_request(grpc_end2end_test_config config) {
static void test_request(const CoreTestConfiguration& config) {
grpc_call* c;
grpc_call* s;
grpc_slice request_payload_slice =
grpc_slice_from_copied_string("hello world");
grpc_byte_buffer* request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_end2end_test_fixture f =
begin_test(config, "filter_causes_close", nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "filter_causes_close", nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -121,10 +79,10 @@ static void test_request(grpc_end2end_test_config config) {
grpc_call_error error;
grpc_slice details;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -161,22 +119,24 @@ static void test_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_PERMISSION_DENIED);
GPR_ASSERT(0 ==
grpc_slice_str_cmp(details, "Failure that's not preventable."));
f->ShutdownServer();
grpc_slice_unref(details);
grpc_metadata_array_destroy(&initial_metadata_recv);
grpc_metadata_array_destroy(&trailing_metadata_recv);
@ -187,9 +147,6 @@ static void test_request(grpc_end2end_test_config config) {
grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(request_payload_recv);
end_test(&f);
config.tear_down_data(&f);
}
//******************************************************************************
@ -262,7 +219,7 @@ static const grpc_channel_filter test_filter = {
// Registration
//
void filter_causes_close(grpc_end2end_test_config config) {
void filter_causes_close(const CoreTestConfiguration& config) {
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);

@ -17,11 +17,12 @@
//
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <functional>
#include <initializer_list>
#include <memory>
#include <vector>
#include "absl/status/status.h"
@ -34,6 +35,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_fwd.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h"
@ -49,74 +51,28 @@
enum { TIMEOUT = 200000 };
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Simple request to test that filters see a consistent view of the
// call context.
static void test_request(grpc_end2end_test_config config) {
static void test_request(const CoreTestConfiguration& config) {
grpc_call* c;
grpc_call* s;
grpc_slice request_payload_slice =
grpc_slice_from_copied_string("hello world");
grpc_byte_buffer* request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_end2end_test_fixture f =
begin_test(config, "filter_context", nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "filter_context", nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -129,10 +85,10 @@ static void test_request(grpc_end2end_test_config config) {
grpc_slice details;
int was_cancelled = 2;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -169,16 +125,16 @@ static void test_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -201,12 +157,12 @@ static void test_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
@ -223,9 +179,6 @@ static void test_request(grpc_end2end_test_config config) {
grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(request_payload_recv);
end_test(&f);
config.tear_down_data(&f);
}
//******************************************************************************
@ -288,7 +241,7 @@ static const grpc_channel_filter test_filter = {
// Registration
//
void filter_context(grpc_end2end_test_config config) {
void filter_context(const CoreTestConfiguration& config) {
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);

@ -17,10 +17,11 @@
//
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <functional>
#include <memory>
#include <vector>
#include "absl/status/status.h"
@ -33,6 +34,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_fwd.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h"
@ -52,74 +54,28 @@ static bool g_enable_client_channel_filter = false;
static bool g_enable_client_subchannel_filter = false;
static bool g_channel_filter_init_failure = false;
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Simple request via a SERVER_CHANNEL filter that always fails to
// initialize the call.
static void test_server_channel_filter(grpc_end2end_test_config config) {
static void test_server_channel_filter(const CoreTestConfiguration& config) {
grpc_call* c;
grpc_call* s;
grpc_slice request_payload_slice =
grpc_slice_from_copied_string("hello world");
grpc_byte_buffer* request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_end2end_test_fixture f =
begin_test(config, "filter_init_fails", nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "filter_init_fails", nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -131,10 +87,10 @@ static void test_server_channel_filter(grpc_end2end_test_config config) {
grpc_call_error error;
grpc_slice details;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -171,16 +127,16 @@ static void test_server_channel_filter(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
if (g_channel_filter_init_failure) {
@ -195,6 +151,8 @@ static void test_server_channel_filter(grpc_end2end_test_config config) {
GPR_ASSERT(0 == grpc_slice_str_cmp(details, "access denied"));
}
f->ShutdownServer();
grpc_slice_unref(details);
grpc_metadata_array_destroy(&initial_metadata_recv);
grpc_metadata_array_destroy(&trailing_metadata_recv);
@ -205,23 +163,19 @@ static void test_server_channel_filter(grpc_end2end_test_config config) {
grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(request_payload_recv);
end_test(&f);
config.tear_down_data(&f);
}
// Simple request via a CLIENT_CHANNEL or CLIENT_DIRECT_CHANNEL filter
// that always fails to initialize the call.
static void test_client_channel_filter(grpc_end2end_test_config config) {
static void test_client_channel_filter(const CoreTestConfiguration& config) {
grpc_call* c;
grpc_slice request_payload_slice =
grpc_slice_from_copied_string("hello world");
grpc_byte_buffer* request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
gpr_timespec deadline = five_seconds_from_now();
grpc_end2end_test_fixture f =
begin_test(config, "filter_init_fails", nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
auto f = begin_test(config, "filter_init_fails", nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -233,9 +187,9 @@ static void test_client_channel_filter(grpc_end2end_test_config config) {
grpc_call_error error;
grpc_slice details;
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -272,11 +226,11 @@ static void test_client_channel_filter(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
if (g_channel_filter_init_failure) {
@ -286,6 +240,8 @@ static void test_client_channel_filter(grpc_end2end_test_config config) {
GPR_ASSERT(0 == grpc_slice_str_cmp(details, "access denied"));
}
f->ShutdownServer();
grpc_slice_unref(details);
grpc_metadata_array_destroy(&initial_metadata_recv);
grpc_metadata_array_destroy(&trailing_metadata_recv);
@ -296,23 +252,19 @@ static void test_client_channel_filter(grpc_end2end_test_config config) {
grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(request_payload_recv);
end_test(&f);
config.tear_down_data(&f);
}
// Simple request via a CLIENT_SUBCHANNEL filter that always fails to
// initialize the call.
static void test_client_subchannel_filter(grpc_end2end_test_config config) {
static void test_client_subchannel_filter(const CoreTestConfiguration& config) {
grpc_call* c;
grpc_slice request_payload_slice =
grpc_slice_from_copied_string("hello world");
grpc_byte_buffer* request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
gpr_timespec deadline = five_seconds_from_now();
grpc_end2end_test_fixture f =
begin_test(config, "filter_init_fails", nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
auto f = begin_test(config, "filter_init_fails", nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -324,9 +276,9 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) {
grpc_call_error error;
grpc_slice details;
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -364,11 +316,11 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) {
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
if (g_channel_filter_init_failure) {
@ -386,16 +338,16 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) {
grpc_slice_unref(details);
details = grpc_empty_slice();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(2),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(2), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(2), true);
cqv.Expect(grpc_core::CqVerifier::tag(2), true);
cqv.Verify();
if (g_channel_filter_init_failure) {
@ -415,9 +367,6 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) {
grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(request_payload_recv);
end_test(&f);
config.tear_down_data(&f);
}
//******************************************************************************
@ -460,7 +409,7 @@ static const grpc_channel_filter test_filter = {
// Registration
//
static void filter_init_fails_internal(grpc_end2end_test_config config) {
static void filter_init_fails_internal(const CoreTestConfiguration& config) {
gpr_log(GPR_INFO, "Testing SERVER_CHANNEL filter.");
g_enable_server_channel_filter = true;
test_server_channel_filter(config);
@ -485,7 +434,7 @@ static void filter_init_fails_internal(grpc_end2end_test_config config) {
}
}
void filter_init_fails(grpc_end2end_test_config config) {
void filter_init_fails(const CoreTestConfiguration& config) {
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
@ -512,7 +461,7 @@ void filter_init_fails(grpc_end2end_test_config config) {
register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
&g_enable_client_channel_filter);
},
[config] { filter_init_fails_internal(config); });
[&config] { filter_init_fails_internal(config); });
}
void filter_init_fails_pre_init(void) {}

@ -17,10 +17,11 @@
//
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <functional>
#include <memory>
#include <vector>
#include "absl/status/status.h"
@ -34,6 +35,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_fwd.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h"
@ -51,73 +53,27 @@ static gpr_mu g_mu;
static gpr_timespec g_client_latency;
static gpr_timespec g_server_latency;
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Simple request via a server filter that saves the reported latency value.
static void test_request(grpc_end2end_test_config config) {
static void test_request(const CoreTestConfiguration& config) {
grpc_call* c;
grpc_call* s;
grpc_slice request_payload_slice =
grpc_slice_from_copied_string("hello world");
grpc_byte_buffer* request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_end2end_test_fixture f =
begin_test(config, "filter_latency", nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "filter_latency", nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -136,10 +92,10 @@ static void test_request(grpc_end2end_test_config config) {
gpr_mu_unlock(&g_mu);
const gpr_timespec start_time = gpr_now(GPR_CLOCK_REALTIME);
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -176,16 +132,16 @@ static void test_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -208,12 +164,12 @@ static void test_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
@ -231,9 +187,6 @@ static void test_request(grpc_end2end_test_config config) {
grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(request_payload_recv);
end_test(&f);
config.tear_down_data(&f);
const gpr_timespec end_time = gpr_now(GPR_CLOCK_REALTIME);
const gpr_timespec max_latency = gpr_time_sub(end_time, start_time);
@ -307,7 +260,7 @@ static const grpc_channel_filter test_server_filter = {
// Registration
//
void filter_latency(grpc_end2end_test_config config) {
void filter_latency(const CoreTestConfiguration& config) {
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);

@ -25,10 +25,11 @@
//
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <functional>
#include <memory>
#include <vector>
#include "absl/status/status.h"
@ -41,6 +42,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_fwd.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h"
@ -65,72 +67,26 @@ static gpr_cv g_server_code_cv;
static grpc_status_code g_client_status_code;
static grpc_status_code g_server_status_code;
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Simple request via a server filter that saves the reported status code.
static void test_request(grpc_end2end_test_config config) {
static void test_request(const CoreTestConfiguration& config) {
g_client_code_recv = false;
g_server_code_recv = false;
grpc_call* c;
grpc_call* s;
grpc_end2end_test_fixture f =
begin_test(config, "filter_status_code", nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
auto f = begin_test(config, "filter_status_code", nullptr, nullptr);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -149,10 +105,10 @@ static void test_request(grpc_end2end_test_config config) {
g_server_status_code = GRPC_STATUS_OK;
gpr_mu_unlock(&g_mu);
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
gpr_mu_lock(&g_mu);
g_client_call_stack = grpc_call_get_call_stack(c);
@ -187,16 +143,16 @@ static void test_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
gpr_mu_lock(&g_mu);
@ -223,12 +179,12 @@ static void test_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
@ -243,9 +199,6 @@ static void test_request(grpc_end2end_test_config config) {
grpc_call_unref(s);
grpc_call_unref(c);
end_test(&f);
config.tear_down_data(&f);
// Perform checks after test tear-down
// Guards against the case that there's outstanding channel-related work on a
// call prior to verification
@ -367,7 +320,7 @@ static const grpc_channel_filter test_server_filter = {
// Registration
//
void filter_status_code(grpc_end2end_test_config config) {
void filter_status_code(const CoreTestConfiguration& config) {
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
@ -390,7 +343,7 @@ void filter_status_code(grpc_end2end_test_config config) {
register_stage(GRPC_CLIENT_DIRECT_CHANNEL, &test_client_filter);
register_stage(GRPC_SERVER_CHANNEL, &test_server_filter);
},
[config] { test_request(config); });
[&config] { test_request(config); });
}
void filter_status_code_pre_init(void) {

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
#include <grpc/slice.h>
@ -26,69 +28,25 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
// Request/response with metadata which should be filtered
static void test_request_response_with_metadata_to_be_filtered(
grpc_end2end_test_config config, const char* filtered_md_key,
const CoreTestConfiguration& config, const char* filtered_md_key,
const char* filter_md_value) {
grpc_call* c;
grpc_call* s;
@ -104,10 +62,10 @@ static void test_request_response_with_metadata_to_be_filtered(
{grpc_slice_from_static_string(filtered_md_key),
grpc_slice_from_static_string(filter_md_value),
{{nullptr, nullptr, nullptr, nullptr}}}};
grpc_end2end_test_fixture f =
auto f =
begin_test(config, "test_request_response_with_metadata_to_be_filtered",
nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -119,10 +77,10 @@ static void test_request_response_with_metadata_to_be_filtered(
grpc_slice details;
int was_cancelled = 2;
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -154,15 +112,15 @@ static void test_request_response_with_metadata_to_be_filtered(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -173,11 +131,11 @@ static void test_request_response_with_metadata_to_be_filtered(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -195,12 +153,12 @@ static void test_request_response_with_metadata_to_be_filtered(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(103),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(103), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(103), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(103), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(status == GRPC_STATUS_OK);
@ -222,12 +180,9 @@ static void test_request_response_with_metadata_to_be_filtered(
grpc_call_unref(c);
grpc_call_unref(s);
end_test(&f);
config.tear_down_data(&f);
}
void filtered_metadata(grpc_end2end_test_config config) {
void filtered_metadata(const CoreTestConfiguration& config) {
test_request_response_with_metadata_to_be_filtered(config, "content-length",
"45");
}

@ -16,9 +16,11 @@
//
//
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/propagation_bits.h>
#include <grpc/slice.h>
@ -26,68 +28,30 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
}
static void shutdown_server(grpc_end2end_test_fixture* f) {
if (!f->server) return;
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void test_early_server_shutdown_finishes_inflight_calls(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
grpc_call* c;
grpc_call* s;
grpc_end2end_test_fixture f =
auto f =
begin_test(config, "test_early_server_shutdown_finishes_inflight_calls",
nullptr, nullptr);
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
grpc_op ops[6];
grpc_op* op;
grpc_metadata_array initial_metadata_recv;
@ -99,10 +63,10 @@ static void test_early_server_shutdown_finishes_inflight_calls(
grpc_slice details;
int was_cancelled = 2;
gpr_timespec deadline = n_seconds_from_now(10);
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(10);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -134,19 +98,20 @@ static void test_early_server_shutdown_finishes_inflight_calls(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
// shutdown and destroy the server
grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead));
grpc_server_shutdown_and_notify(f->server(), f->cq(),
grpc_core::CqVerifier::tag(0xdead));
cqv.VerifyEmpty();
memset(ops, 0, sizeof(ops));
@ -169,13 +134,13 @@ static void test_early_server_shutdown_finishes_inflight_calls(
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(0xdead), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(0xdead), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
grpc_call_unref(s);
@ -191,12 +156,9 @@ static void test_early_server_shutdown_finishes_inflight_calls(
grpc_call_details_destroy(&call_details);
grpc_call_unref(c);
end_test(&f);
config.tear_down_data(&f);
}
void graceful_server_shutdown(grpc_end2end_test_config config) {
void graceful_server_shutdown(const CoreTestConfiguration& config) {
test_early_server_shutdown_finishes_inflight_calls(config);
}

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdint.h>
#include <string.h>
#include <functional>
#include <memory>
#include <string>
#include <utility>
@ -41,63 +41,19 @@
#include "test/core/util/test_config.h"
#include "test/core/util/tls_utils.h"
static void* tag(intptr_t t) { return reinterpret_cast<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;
static std::unique_ptr<CoreTestFixture> begin_test(
const CoreTestConfiguration& config, const char* test_name,
grpc_channel_args* client_args, grpc_channel_args* server_args) {
gpr_log(GPR_INFO, "%s", std::string(80, '*').c_str());
gpr_log(GPR_INFO, "Running test: %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);
auto f = config.create_fixture(grpc_core::ChannelArgs::FromC(client_args),
grpc_core::ChannelArgs::FromC(server_args));
f->InitServer(grpc_core::ChannelArgs::FromC(server_args));
f->InitClient(grpc_core::ChannelArgs::FromC(client_args));
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} 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));
grpc_event ev;
do {
ev = grpc_completion_queue_next(f->cq, five_seconds_from_now(), nullptr);
} while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
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);
}
static void test_allow_authorized_request(grpc_end2end_test_fixture f) {
static void test_allow_authorized_request(CoreTestFixture* f) {
grpc_call* c;
grpc_call* s;
grpc_op ops[6];
@ -112,12 +68,12 @@ static void test_allow_authorized_request(grpc_end2end_test_fixture f) {
grpc_slice details = grpc_empty_slice();
int was_cancelled = 2;
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -149,15 +105,15 @@ static void test_allow_authorized_request(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
error = grpc_server_request_call(f->server(), &s, &call_details,
&request_metadata_recv, f->cq(), f->cq(),
grpc_core::CqVerifier::tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(101), true);
cqv.Expect(grpc_core::CqVerifier::tag(101), true);
cqv.Verify();
memset(ops, 0, sizeof(ops));
@ -180,12 +136,12 @@ static void test_allow_authorized_request(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(102), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(102), true);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(102), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(GRPC_STATUS_OK == status);
GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz"));
@ -201,7 +157,7 @@ static void test_allow_authorized_request(grpc_end2end_test_fixture f) {
grpc_call_unref(s);
}
static void test_deny_unauthorized_request(grpc_end2end_test_fixture f) {
static void test_deny_unauthorized_request(CoreTestFixture* f) {
grpc_call* c;
grpc_op ops[6];
grpc_op* op;
@ -212,12 +168,12 @@ static void test_deny_unauthorized_request(grpc_end2end_test_fixture f) {
grpc_call_error error;
grpc_slice details = grpc_empty_slice();
grpc_core::CqVerifier cqv(f.cq);
grpc_core::CqVerifier cqv(f->cq());
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/foo"), nullptr,
deadline, nullptr);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
c = grpc_channel_create_call(f->client(), nullptr, GRPC_PROPAGATE_DEFAULTS,
f->cq(), grpc_slice_from_static_string("/foo"),
nullptr, deadline, nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@ -247,10 +203,10 @@ static void test_deny_unauthorized_request(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
grpc_core::CqVerifier::tag(1), nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
cqv.Expect(tag(1), true);
cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();
GPR_ASSERT(GRPC_STATUS_PERMISSION_DENIED == status);
@ -266,7 +222,7 @@ static void test_deny_unauthorized_request(grpc_end2end_test_fixture f) {
}
static void test_static_init_allow_authorized_request(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* authz_policy =
"{"
" \"name\": \"authz\","
@ -294,18 +250,14 @@ static void test_static_init_allow_authorized_request(
};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(args), args};
grpc_end2end_test_fixture f =
begin_test(config, "test_static_init_allow_authorized_request", nullptr,
&server_args);
auto f = begin_test(config, "test_static_init_allow_authorized_request",
nullptr, &server_args);
grpc_authorization_policy_provider_release(provider);
test_allow_authorized_request(f);
end_test(&f);
config.tear_down_data(&f);
test_allow_authorized_request(f.get());
}
static void test_static_init_deny_unauthorized_request(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* authz_policy =
"{"
" \"name\": \"authz\","
@ -343,18 +295,14 @@ static void test_static_init_deny_unauthorized_request(
};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(args), args};
grpc_end2end_test_fixture f =
begin_test(config, "test_static_init_deny_unauthorized_request", nullptr,
&server_args);
auto f = begin_test(config, "test_static_init_deny_unauthorized_request",
nullptr, &server_args);
grpc_authorization_policy_provider_release(provider);
test_deny_unauthorized_request(f);
end_test(&f);
config.tear_down_data(&f);
test_deny_unauthorized_request(f.get());
}
static void test_static_init_deny_request_no_match_in_policy(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* authz_policy =
"{"
" \"name\": \"authz\","
@ -382,18 +330,15 @@ static void test_static_init_deny_request_no_match_in_policy(
};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(args), args};
grpc_end2end_test_fixture f =
auto f =
begin_test(config, "test_static_init_deny_request_no_match_in_policy",
nullptr, &server_args);
grpc_authorization_policy_provider_release(provider);
test_deny_unauthorized_request(f);
end_test(&f);
config.tear_down_data(&f);
test_deny_unauthorized_request(f.get());
}
static void test_file_watcher_init_allow_authorized_request(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* authz_policy =
"{"
" \"name\": \"authz\","
@ -423,18 +368,14 @@ static void test_file_watcher_init_allow_authorized_request(
};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(args), args};
grpc_end2end_test_fixture f =
begin_test(config, "test_file_watcher_init_allow_authorized_request",
nullptr, &server_args);
auto f = begin_test(config, "test_file_watcher_init_allow_authorized_request",
nullptr, &server_args);
grpc_authorization_policy_provider_release(provider);
test_allow_authorized_request(f);
end_test(&f);
config.tear_down_data(&f);
test_allow_authorized_request(f.get());
}
static void test_file_watcher_init_deny_unauthorized_request(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* authz_policy =
"{"
" \"name\": \"authz\","
@ -474,18 +415,15 @@ static void test_file_watcher_init_deny_unauthorized_request(
};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(args), args};
grpc_end2end_test_fixture f =
auto f =
begin_test(config, "test_file_watcher_init_deny_unauthorized_request",
nullptr, &server_args);
grpc_authorization_policy_provider_release(provider);
test_deny_unauthorized_request(f);
end_test(&f);
config.tear_down_data(&f);
test_deny_unauthorized_request(f.get());
}
static void test_file_watcher_init_deny_request_no_match_in_policy(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* authz_policy =
"{"
" \"name\": \"authz\","
@ -515,18 +453,15 @@ static void test_file_watcher_init_deny_request_no_match_in_policy(
};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(args), args};
grpc_end2end_test_fixture f = begin_test(
config, "test_file_watcher_init_deny_request_no_match_in_policy", nullptr,
&server_args);
auto f = begin_test(config,
"test_file_watcher_init_deny_request_no_match_in_policy",
nullptr, &server_args);
grpc_authorization_policy_provider_release(provider);
test_deny_unauthorized_request(f);
end_test(&f);
config.tear_down_data(&f);
test_deny_unauthorized_request(f.get());
}
static void test_file_watcher_valid_policy_reload(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* authz_policy =
"{"
" \"name\": \"authz\","
@ -556,10 +491,10 @@ static void test_file_watcher_valid_policy_reload(
};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(args), args};
grpc_end2end_test_fixture f = begin_test(
config, "test_file_watcher_valid_policy_reload", nullptr, &server_args);
auto f = begin_test(config, "test_file_watcher_valid_policy_reload", nullptr,
&server_args);
grpc_authorization_policy_provider_release(provider);
test_allow_authorized_request(f);
test_allow_authorized_request(f.get());
gpr_event on_reload_done;
gpr_event_init(&on_reload_done);
std::function<void(bool contents_changed, absl::Status status)> callback =
@ -600,16 +535,13 @@ static void test_file_watcher_valid_policy_reload(
GPR_ASSERT(
reinterpret_cast<void*>(1) ==
gpr_event_wait(&on_reload_done, gpr_inf_future(GPR_CLOCK_MONOTONIC)));
test_deny_unauthorized_request(f);
test_deny_unauthorized_request(f.get());
dynamic_cast<grpc_core::FileWatcherAuthorizationPolicyProvider*>(provider)
->SetCallbackForTesting(nullptr);
end_test(&f);
config.tear_down_data(&f);
}
static void test_file_watcher_invalid_policy_skip_reload(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* authz_policy =
"{"
" \"name\": \"authz\","
@ -639,11 +571,10 @@ static void test_file_watcher_invalid_policy_skip_reload(
};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(args), args};
grpc_end2end_test_fixture f =
begin_test(config, "test_file_watcher_invalid_policy_skip_reload",
nullptr, &server_args);
auto f = begin_test(config, "test_file_watcher_invalid_policy_skip_reload",
nullptr, &server_args);
grpc_authorization_policy_provider_release(provider);
test_allow_authorized_request(f);
test_allow_authorized_request(f.get());
gpr_event on_reload_done;
gpr_event_init(&on_reload_done);
std::function<void(bool contents_changed, absl::Status status)> callback =
@ -662,16 +593,13 @@ static void test_file_watcher_invalid_policy_skip_reload(
GPR_ASSERT(
reinterpret_cast<void*>(1) ==
gpr_event_wait(&on_reload_done, gpr_inf_future(GPR_CLOCK_MONOTONIC)));
test_allow_authorized_request(f);
test_allow_authorized_request(f.get());
dynamic_cast<grpc_core::FileWatcherAuthorizationPolicyProvider*>(provider)
->SetCallbackForTesting(nullptr);
end_test(&f);
config.tear_down_data(&f);
}
static void test_file_watcher_recovers_from_failure(
grpc_end2end_test_config config) {
const CoreTestConfiguration& config) {
const char* authz_policy =
"{"
" \"name\": \"authz\","
@ -701,10 +629,10 @@ static void test_file_watcher_recovers_from_failure(
};
grpc_channel_args server_args = {GPR_ARRAY_SIZE(args), args};
grpc_end2end_test_fixture f = begin_test(
config, "test_file_watcher_recovers_from_failure", nullptr, &server_args);
auto f = begin_test(config, "test_file_watcher_recovers_from_failure",
nullptr, &server_args);
grpc_authorization_policy_provider_release(provider);
test_allow_authorized_request(f);
test_allow_authorized_request(f.get());
gpr_event on_first_reload_done;
gpr_event_init(&on_first_reload_done);
std::function<void(bool contents_changed, absl::Status status)> callback1 =
@ -723,7 +651,7 @@ static void test_file_watcher_recovers_from_failure(
GPR_ASSERT(reinterpret_cast<void*>(1) ==
gpr_event_wait(&on_first_reload_done,
gpr_inf_future(GPR_CLOCK_MONOTONIC)));
test_allow_authorized_request(f);
test_allow_authorized_request(f.get());
gpr_event on_second_reload_done;
gpr_event_init(&on_second_reload_done);
std::function<void(bool contents_changed, absl::Status status)> callback2 =
@ -765,15 +693,12 @@ static void test_file_watcher_recovers_from_failure(
GPR_ASSERT(reinterpret_cast<void*>(1) ==
gpr_event_wait(&on_second_reload_done,
gpr_inf_future(GPR_CLOCK_MONOTONIC)));
test_deny_unauthorized_request(f);
test_deny_unauthorized_request(f.get());
dynamic_cast<grpc_core::FileWatcherAuthorizationPolicyProvider*>(provider)
->SetCallbackForTesting(nullptr);
end_test(&f);
config.tear_down_data(&f);
}
void grpc_authz(grpc_end2end_test_config config) {
void grpc_authz(const CoreTestConfiguration& config) {
test_static_init_allow_authorized_request(config);
test_static_init_deny_unauthorized_request(config);
test_static_init_deny_request_no_match_in_policy(config);

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save