aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/security
diff options
context:
space:
mode:
authorGravatar jiangtaoli2016 <jiangtao@google.com>2017-09-06 12:45:43 -0700
committerGravatar jiangtaoli2016 <jiangtao@google.com>2017-09-06 12:45:43 -0700
commit627691fd26d5876582a2270a100a426f1031cc3b (patch)
tree06fc3af10e08be814f98f7d2d8abfaea80e810ed /test/core/security
parent9c519434be0ee80fcf66b433fc8c053ce9ac383b (diff)
Fake zero-copy frame protector
Diffstat (limited to 'test/core/security')
-rw-r--r--test/core/security/secure_endpoint_test.c59
1 files changed, 49 insertions, 10 deletions
diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c
index 7ecd947e1f..2145d55da7 100644
--- a/test/core/security/secure_endpoint_test.c
+++ b/test/core/security/secure_endpoint_test.c
@@ -36,12 +36,17 @@ static gpr_mu *g_mu;
static grpc_pollset *g_pollset;
static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
- size_t slice_size, grpc_slice *leftover_slices, size_t leftover_nslices) {
+ size_t slice_size, grpc_slice *leftover_slices, size_t leftover_nslices,
+ bool use_zero_copy_protector) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
tsi_frame_protector *fake_read_protector =
tsi_create_fake_frame_protector(NULL);
tsi_frame_protector *fake_write_protector =
tsi_create_fake_frame_protector(NULL);
+ tsi_zero_copy_grpc_protector *fake_read_zero_copy_protector =
+ tsi_create_fake_zero_copy_grpc_protector(NULL);
+ tsi_zero_copy_grpc_protector *fake_write_zero_copy_protector =
+ tsi_create_fake_zero_copy_grpc_protector(NULL);
grpc_endpoint_test_fixture f;
grpc_endpoint_pair tcp;
@@ -55,7 +60,11 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
if (leftover_nslices == 0) {
f.client_ep =
- grpc_secure_endpoint_create(fake_read_protector, tcp.client, NULL, 0);
+ use_zero_copy_protector
+ ? grpc_secure_endpoint_create(NULL, fake_read_zero_copy_protector,
+ tcp.client, NULL, 0)
+ : grpc_secure_endpoint_create(fake_read_protector, NULL, tcp.client,
+ NULL, 0);
} else {
unsigned i;
tsi_result result;
@@ -96,31 +105,53 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
} while (still_pending_size > 0);
encrypted_leftover = grpc_slice_from_copied_buffer(
(const char *)encrypted_buffer, total_buffer_size - buffer_size);
- f.client_ep = grpc_secure_endpoint_create(fake_read_protector, tcp.client,
- &encrypted_leftover, 1);
+ f.client_ep =
+ use_zero_copy_protector
+ ? grpc_secure_endpoint_create(NULL, fake_read_zero_copy_protector,
+ tcp.client, &encrypted_leftover, 1)
+ : grpc_secure_endpoint_create(fake_read_protector, NULL, tcp.client,
+ &encrypted_leftover, 1);
grpc_slice_unref(encrypted_leftover);
gpr_free(encrypted_buffer);
}
f.server_ep =
- grpc_secure_endpoint_create(fake_write_protector, tcp.server, NULL, 0);
+ use_zero_copy_protector
+ ? grpc_secure_endpoint_create(NULL, fake_write_zero_copy_protector,
+ tcp.server, NULL, 0)
+ : grpc_secure_endpoint_create(fake_write_protector, NULL, tcp.server,
+ NULL, 0);
grpc_exec_ctx_finish(&exec_ctx);
return f;
}
static grpc_endpoint_test_fixture
secure_endpoint_create_fixture_tcp_socketpair_noleftover(size_t slice_size) {
- return secure_endpoint_create_fixture_tcp_socketpair(slice_size, NULL, 0);
+ return secure_endpoint_create_fixture_tcp_socketpair(slice_size, NULL, 0,
+ false);
+}
+
+static grpc_endpoint_test_fixture
+secure_endpoint_create_fixture_tcp_socketpair_noleftover_zero_copy(
+ size_t slice_size) {
+ return secure_endpoint_create_fixture_tcp_socketpair(slice_size, NULL, 0,
+ true);
}
static grpc_endpoint_test_fixture
secure_endpoint_create_fixture_tcp_socketpair_leftover(size_t slice_size) {
grpc_slice s =
grpc_slice_from_copied_string("hello world 12345678900987654321");
- grpc_endpoint_test_fixture f;
+ return secure_endpoint_create_fixture_tcp_socketpair(slice_size, &s, 1,
+ false);
+}
- f = secure_endpoint_create_fixture_tcp_socketpair(slice_size, &s, 1);
- return f;
+static grpc_endpoint_test_fixture
+secure_endpoint_create_fixture_tcp_socketpair_leftover_zero_copy(
+ size_t slice_size) {
+ grpc_slice s =
+ grpc_slice_from_copied_string("hello world 12345678900987654321");
+ return secure_endpoint_create_fixture_tcp_socketpair(slice_size, &s, 1, true);
}
static void clean_up(void) {}
@@ -128,8 +159,14 @@ static void clean_up(void) {}
static grpc_endpoint_test_config configs[] = {
{"secure_ep/tcp_socketpair",
secure_endpoint_create_fixture_tcp_socketpair_noleftover, clean_up},
+ {"secure_ep/tcp_socketpair_zero_copy",
+ secure_endpoint_create_fixture_tcp_socketpair_noleftover_zero_copy,
+ clean_up},
{"secure_ep/tcp_socketpair_leftover",
secure_endpoint_create_fixture_tcp_socketpair_leftover, clean_up},
+ {"secure_ep/tcp_socketpair_leftover_zero_copy",
+ secure_endpoint_create_fixture_tcp_socketpair_leftover_zero_copy,
+ clean_up},
};
static void inc_call_ctr(grpc_exec_ctx *exec_ctx, void *arg,
@@ -184,7 +221,9 @@ int main(int argc, char **argv) {
g_pollset = gpr_zalloc(grpc_pollset_size());
grpc_pollset_init(g_pollset, &g_mu);
grpc_endpoint_tests(configs[0], g_pollset, g_mu);
- test_leftover(configs[1], 1);
+ grpc_endpoint_tests(configs[1], g_pollset, g_mu);
+ test_leftover(configs[2], 1);
+ test_leftover(configs[3], 1);
GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset,
grpc_schedule_on_exec_ctx);
grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);