aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/tsi
diff options
context:
space:
mode:
authorGravatar Yihua Zhang <yihuaz@google.com>2017-09-15 08:46:54 -0700
committerGravatar Yihua Zhang <yihuaz@google.com>2017-09-15 08:46:54 -0700
commit993fa31e669dcf8432e84c3c2a83b11bf9e68b5e (patch)
tree0bbbdfcc2e0c7d3be62a98c62905d54f98d15563 /test/core/tsi
parentc3aba91be94d336a27f945a644233bc244f22e2b (diff)
update tsi test library to support async tsi implementation
Diffstat (limited to 'test/core/tsi')
-rw-r--r--test/core/tsi/transport_security_test_lib.c29
-rw-r--r--test/core/tsi/transport_security_test_lib.h19
2 files changed, 46 insertions, 2 deletions
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_