diff options
author | Mark D. Roth <roth@google.com> | 2017-09-28 15:16:14 -0700 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2017-09-28 15:16:14 -0700 |
commit | 6456e494a8474f4d62594e98382678703dee9594 (patch) | |
tree | 3c9172bcbb75bdb5afee381f87ae7b4a1845d2f1 /test/core | |
parent | 61b26f97b04b4fec82d6b9ea110ad7743a0ab178 (diff) | |
parent | fde890e9053bf09eee6e727967cbdc472ff80f9f (diff) |
Merge remote-tracking branch 'upstream/master' into plugin_credentials_api_fix
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/bad_client/bad_client.c | 11 | ||||
-rw-r--r-- | test/core/bad_client/bad_client.h | 1 | ||||
-rw-r--r-- | test/core/bad_client/tests/window_overflow.c | 3 | ||||
-rw-r--r-- | test/core/iomgr/pollset_set_test.c | 6 | ||||
-rw-r--r-- | test/core/tsi/transport_security_test_lib.c | 29 | ||||
-rw-r--r-- | test/core/tsi/transport_security_test_lib.h | 19 |
6 files changed, 60 insertions, 9 deletions
diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c index 383d1240cb..fff0c793ed 100644 --- a/test/core/bad_client/bad_client.c +++ b/test/core/bad_client/bad_client.c @@ -134,9 +134,12 @@ void grpc_run_bad_client_test( grpc_endpoint_write(&exec_ctx, sfd.client, &outgoing, &done_write_closure); grpc_exec_ctx_finish(&exec_ctx); - /* Await completion */ - GPR_ASSERT( - gpr_event_wait(&a.done_write, grpc_timeout_seconds_to_deadline(5))); + /* Await completion, unless the request is large and write may not finish + * before the peer shuts down. */ + if (!(flags & GRPC_BAD_CLIENT_LARGE_REQUEST)) { + GPR_ASSERT( + gpr_event_wait(&a.done_write, grpc_timeout_seconds_to_deadline(5))); + } if (flags & GRPC_BAD_CLIENT_DISCONNECT) { grpc_endpoint_shutdown( @@ -186,6 +189,8 @@ void grpc_run_bad_client_test( grpc_exec_ctx_finish(&exec_ctx); } + GPR_ASSERT( + gpr_event_wait(&a.done_write, grpc_timeout_seconds_to_deadline(1))); shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); grpc_server_shutdown_and_notify(a.server, shutdown_cq, NULL); GPR_ASSERT(grpc_completion_queue_pluck( diff --git a/test/core/bad_client/bad_client.h b/test/core/bad_client/bad_client.h index 22f1a3abc7..a5b01f7f2c 100644 --- a/test/core/bad_client/bad_client.h +++ b/test/core/bad_client/bad_client.h @@ -37,6 +37,7 @@ typedef bool (*grpc_bad_client_client_stream_validator)( grpc_slice_buffer *incoming); #define GRPC_BAD_CLIENT_DISCONNECT 1 +#define GRPC_BAD_CLIENT_LARGE_REQUEST 2 /* Test runner. diff --git a/test/core/bad_client/tests/window_overflow.c b/test/core/bad_client/tests/window_overflow.c index 1f29bd32fb..18c647ad8a 100644 --- a/test/core/bad_client/tests/window_overflow.c +++ b/test/core/bad_client/tests/window_overflow.c @@ -90,7 +90,8 @@ int main(int argc, char **argv) { addbuf(message, sizeof(message)); } } - grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, 0); + grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, + GRPC_BAD_CLIENT_LARGE_REQUEST); gpr_free(g_buffer); return 0; diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c index 70efca8b16..5750ac0f4b 100644 --- a/test/core/iomgr/pollset_set_test.c +++ b/test/core/iomgr/pollset_set_test.c @@ -24,7 +24,6 @@ #include <string.h> #include <unistd.h> -#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/useful.h> @@ -434,7 +433,8 @@ int main(int argc, char **argv) { const char *poll_strategy = grpc_get_poll_strategy_name(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); - grpc_init(); + grpc_iomgr_init(&exec_ctx); + grpc_iomgr_start(&exec_ctx); if (poll_strategy != NULL && (strcmp(poll_strategy, "epoll") == 0 || @@ -449,8 +449,8 @@ int main(int argc, char **argv) { poll_strategy); } + grpc_iomgr_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); - grpc_shutdown(); return 0; } #else /* defined(GRPC_LINUX_EPOLL) */ diff --git a/test/core/tsi/transport_security_test_lib.c b/test/core/tsi/transport_security_test_lib.c index 7d66e110f2..329b2371bf 100644 --- a/test/core/tsi/transport_security_test_lib.c +++ b/test/core/tsi/transport_security_test_lib.c @@ -23,9 +23,26 @@ #include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include <grpc/support/thd.h> #include "src/core/lib/security/transport/tsi_error.h" #include "test/core/tsi/transport_security_test_lib.h" +static void notification_signal(tsi_test_fixture *fixture) { + gpr_mu_lock(&fixture->mu); + fixture->notified = true; + gpr_cv_signal(&fixture->cv); + gpr_mu_unlock(&fixture->mu); +} + +static void notification_wait(tsi_test_fixture *fixture) { + gpr_mu_lock(&fixture->mu); + while (!fixture->notified) { + gpr_cv_wait(&fixture->cv, &fixture->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); + } + fixture->notified = false; + gpr_mu_unlock(&fixture->mu); +} + typedef struct handshaker_args { tsi_test_fixture *fixture; unsigned char *handshake_buffer; @@ -273,9 +290,11 @@ grpc_error *on_handshake_next_done(tsi_result result, void *user_data, /* Read more data if we need to. */ if (result == TSI_INCOMPLETE_DATA) { GPR_ASSERT(bytes_to_send_size == 0); + notification_signal(fixture); return error; } if (result != TSI_OK) { + notification_signal(fixture); return grpc_set_tsi_error_result( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake failed"), result); } @@ -295,6 +314,7 @@ grpc_error *on_handshake_next_done(tsi_result result, void *user_data, if (handshaker_result != NULL) { maybe_append_unused_bytes(args); } + notification_signal(fixture); return error; } @@ -345,7 +365,11 @@ static void do_handshaker_next(handshaker_args *args) { if (result != TSI_ASYNC) { args->error = on_handshake_next_done(result, args, bytes_to_send, bytes_to_send_size, handshaker_result); + if (args->error != GRPC_ERROR_NONE) { + return; + } } + notification_wait(fixture); } void tsi_test_do_handshake(tsi_test_fixture *fixture) { @@ -532,6 +556,9 @@ void tsi_test_fixture_init(tsi_test_fixture *fixture) { fixture->bytes_read_from_server_channel = 0; fixture->test_unused_bytes = true; fixture->has_client_finished_first = false; + gpr_mu_init(&fixture->mu); + gpr_cv_init(&fixture->cv); + fixture->notified = false; } void tsi_test_fixture_destroy(tsi_test_fixture *fixture) { @@ -546,5 +573,7 @@ void tsi_test_fixture_destroy(tsi_test_fixture *fixture) { GPR_ASSERT(fixture->vtable != NULL); GPR_ASSERT(fixture->vtable->destruct != NULL); fixture->vtable->destruct(fixture); + gpr_mu_destroy(&fixture->mu); + gpr_cv_destroy(&fixture->cv); gpr_free(fixture); } diff --git a/test/core/tsi/transport_security_test_lib.h b/test/core/tsi/transport_security_test_lib.h index 8ae2024ee4..ed8ff856df 100644 --- a/test/core/tsi/transport_security_test_lib.h +++ b/test/core/tsi/transport_security_test_lib.h @@ -21,6 +21,10 @@ #include "src/core/tsi/transport_security_interface.h" +#ifdef __cplusplus +extern "C" { +#endif + #define TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE 32 #define TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE 128 #define TSI_TEST_SMALL_READ_BUFFER_ALLOCATED_SIZE 41 @@ -56,10 +60,10 @@ typedef struct tsi_test_fixture_vtable { void (*setup_handshakers)(tsi_test_fixture *fixture); void (*check_handshaker_peers)(tsi_test_fixture *fixture); void (*destruct)(tsi_test_fixture *fixture); -} tranport_security_test_vtable; +} tsi_test_fixture_vtable; struct tsi_test_fixture { - const struct tsi_test_fixture_vtable *vtable; + const tsi_test_fixture_vtable *vtable; /* client/server TSI handshaker used to perform TSI handshakes, and will get instantiated during the call to setup_handshakers. */ tsi_handshaker *client_handshaker; @@ -95,6 +99,13 @@ struct tsi_test_fixture { (https://github.com/grpc/grpc/issues/12164). */ bool test_unused_bytes; + /* These objects will be used coordinate client/server handshakers with TSI + thread to perform TSI handshakes in an asynchronous manner (for GTS TSI + implementations). + */ + gpr_cv cv; + gpr_mu mu; + bool notified; }; struct tsi_test_frame_protector_config { @@ -162,4 +173,8 @@ void tsi_test_do_handshake(tsi_test_fixture *fixture); the client and server switching its role. */ void tsi_test_do_round_trip(tsi_test_fixture *fixture); +#ifdef __cplusplus +} +#endif + #endif // GRPC_TEST_CORE_TSI_TRANSPORT_SECURITY_TEST_LIB_H_ |