aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/security
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-02-19 16:22:44 -0800
committerGravatar Craig Tiller <ctiller@google.com>2016-02-19 16:22:44 -0800
commita8be91b3153fc75a425718799130172357507dd3 (patch)
tree94a9b0e1936ff743805c0876aa7de97b6ca4d14e /test/core/security
parent3633ce48a9ec540c9608d2a7e773d4e1113bb1e1 (diff)
Provide an interface firewall between pollset and its implementations
Starting to allow for >1 implementation of pollset within a binary. Do so without requiring an extra allocation for completion queues (which we could not tolerate).
Diffstat (limited to 'test/core/security')
-rw-r--r--test/core/security/oauth2_utils.c25
-rw-r--r--test/core/security/print_google_default_creds_token.c32
-rw-r--r--test/core/security/secure_endpoint_test.c28
-rw-r--r--test/core/security/verify_jwt.c31
4 files changed, 69 insertions, 47 deletions
diff --git a/test/core/security/oauth2_utils.c b/test/core/security/oauth2_utils.c
index 4dd595df95..3280eac801 100644
--- a/test/core/security/oauth2_utils.c
+++ b/test/core/security/oauth2_utils.c
@@ -45,7 +45,8 @@
#include "src/core/security/credentials.h"
typedef struct {
- grpc_pollset pollset;
+ gpr_mu mu;
+ grpc_pollset *pollset;
int is_done;
char *token;
} oauth2_request;
@@ -66,11 +67,11 @@ static void on_oauth2_response(grpc_exec_ctx *exec_ctx, void *user_data,
GPR_SLICE_LENGTH(token_slice));
token[GPR_SLICE_LENGTH(token_slice)] = '\0';
}
- gpr_mu_lock(GRPC_POLLSET_MU(&request->pollset));
+ gpr_mu_lock(&request->mu);
request->is_done = 1;
request->token = token;
- grpc_pollset_kick(&request->pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&request->pollset));
+ grpc_pollset_kick(request->pollset, NULL);
+ gpr_mu_unlock(&request->mu);
}
static void do_nothing(grpc_exec_ctx *exec_ctx, void *unused, bool success) {}
@@ -82,28 +83,30 @@ char *grpc_test_fetch_oauth2_token_with_credentials(
grpc_closure do_nothing_closure;
grpc_auth_metadata_context null_ctx = {"", "", NULL, NULL};
- grpc_pollset_init(&request.pollset);
+ request.pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(request.pollset, &request.mu);
request.is_done = 0;
grpc_closure_init(&do_nothing_closure, do_nothing, NULL);
- grpc_call_credentials_get_request_metadata(&exec_ctx, creds, &request.pollset,
+ grpc_call_credentials_get_request_metadata(&exec_ctx, creds, request.pollset,
null_ctx, on_oauth2_response,
&request);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&request.pollset));
+ gpr_mu_lock(&request.mu);
while (!request.is_done) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, &request.pollset, &worker,
+ grpc_pollset_work(&exec_ctx, request.pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC),
gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&request.pollset));
+ gpr_mu_unlock(&request.mu);
- grpc_pollset_shutdown(&exec_ctx, &request.pollset, &do_nothing_closure);
+ grpc_pollset_shutdown(&exec_ctx, request.pollset, &do_nothing_closure);
grpc_exec_ctx_finish(&exec_ctx);
- grpc_pollset_destroy(&request.pollset);
+ grpc_pollset_destroy(request.pollset);
+ gpr_free(request.pollset);
return request.token;
}
diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c
index fcbbe334f4..cd4e990f45 100644
--- a/test/core/security/print_google_default_creds_token.c
+++ b/test/core/security/print_google_default_creds_token.c
@@ -34,8 +34,6 @@
#include <stdio.h>
#include <string.h>
-#include "src/core/security/credentials.h"
-#include "src/core/support/string.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
@@ -44,8 +42,12 @@
#include <grpc/support/slice.h>
#include <grpc/support/sync.h>
+#include "src/core/security/credentials.h"
+#include "src/core/support/string.h"
+
typedef struct {
- grpc_pollset pollset;
+ gpr_mu mu;
+ grpc_pollset *pollset;
int is_done;
} synchronizer;
@@ -62,10 +64,10 @@ static void on_metadata_response(grpc_exec_ctx *exec_ctx, void *user_data,
printf("\nGot token: %s\n\n", token);
gpr_free(token);
}
- gpr_mu_lock(GRPC_POLLSET_MU(&sync->pollset));
+ gpr_mu_lock(&sync->mu);
sync->is_done = 1;
- grpc_pollset_kick(&sync->pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&sync->pollset));
+ grpc_pollset_kick(sync->pollset, NULL);
+ gpr_mu_unlock(&sync->mu);
}
int main(int argc, char **argv) {
@@ -91,26 +93,30 @@ int main(int argc, char **argv) {
goto end;
}
- grpc_pollset_init(&sync.pollset);
+ sync.pollset = gpr_malloc(grpc_pollset_size());
+ gpr_mu_init(&sync.mu);
+ grpc_pollset_init(sync.pollset, &sync.mu);
sync.is_done = 0;
grpc_call_credentials_get_request_metadata(
&exec_ctx, ((grpc_composite_channel_credentials *)creds)->call_creds,
- &sync.pollset, context, on_metadata_response, &sync);
+ sync.pollset, context, on_metadata_response, &sync);
- gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset));
+ gpr_mu_lock(&sync.mu);
while (!sync.is_done) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, &sync.pollset, &worker,
+ grpc_pollset_work(&exec_ctx, sync.pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC),
gpr_inf_future(GPR_CLOCK_MONOTONIC));
- gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset));
+ gpr_mu_unlock(&sync.mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset));
+ gpr_mu_lock(&sync.mu);
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset));
+ gpr_mu_unlock(&sync.mu);
grpc_channel_credentials_release(creds);
+ gpr_free(sync.pollset);
+ gpr_mu_destroy(&sync.mu);
end:
gpr_cmdline_destroy(cl);
diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c
index fb4bd30e2d..61543ada43 100644
--- a/test/core/security/secure_endpoint_test.c
+++ b/test/core/security/secure_endpoint_test.c
@@ -36,16 +36,17 @@
#include <fcntl.h>
#include <sys/types.h>
-#include "src/core/security/secure_endpoint.h"
-#include "src/core/iomgr/endpoint_pair.h"
-#include "src/core/iomgr/iomgr.h"
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-#include "test/core/util/test_config.h"
+#include "src/core/iomgr/endpoint_pair.h"
+#include "src/core/iomgr/iomgr.h"
+#include "src/core/security/secure_endpoint.h"
#include "src/core/tsi/fake_transport_security.h"
+#include "test/core/util/test_config.h"
-static grpc_pollset g_pollset;
+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, gpr_slice *leftover_slices, size_t leftover_nslices) {
@@ -56,8 +57,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
grpc_endpoint_pair tcp;
tcp = grpc_iomgr_create_endpoint_pair("fixture", slice_size);
- grpc_endpoint_add_to_pollset(&exec_ctx, tcp.client, &g_pollset);
- grpc_endpoint_add_to_pollset(&exec_ctx, tcp.server, &g_pollset);
+ grpc_endpoint_add_to_pollset(&exec_ctx, tcp.client, g_pollset);
+ grpc_endpoint_add_to_pollset(&exec_ctx, tcp.server, g_pollset);
if (leftover_nslices == 0) {
f.client_ep =
@@ -181,13 +182,18 @@ int main(int argc, char **argv) {
grpc_test_init(argc, argv);
grpc_init();
- grpc_pollset_init(&g_pollset);
- grpc_endpoint_tests(configs[0], &g_pollset);
+ g_pollset = gpr_malloc(grpc_pollset_size());
+ gpr_mu_init(&g_mu);
+ grpc_pollset_init(g_pollset, &g_mu);
+ grpc_endpoint_tests(configs[0], g_pollset, &g_mu);
test_leftover(configs[1], 1);
- grpc_closure_init(&destroyed, destroy_pollset, &g_pollset);
- grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed);
+ grpc_closure_init(&destroyed, destroy_pollset, g_pollset);
+ grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);
grpc_exec_ctx_finish(&exec_ctx);
grpc_shutdown();
+ gpr_free(g_pollset);
+ gpr_mu_destroy(&g_mu);
+
return 0;
}
diff --git a/test/core/security/verify_jwt.c b/test/core/security/verify_jwt.c
index c9071fa08b..f22b076171 100644
--- a/test/core/security/verify_jwt.c
+++ b/test/core/security/verify_jwt.c
@@ -34,7 +34,6 @@
#include <stdio.h>
#include <string.h>
-#include "src/core/security/jwt_verifier.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
@@ -43,8 +42,11 @@
#include <grpc/support/slice.h>
#include <grpc/support/sync.h>
+#include "src/core/security/jwt_verifier.h"
+
typedef struct {
- grpc_pollset pollset;
+ grpc_pollset *pollset;
+ gpr_mu mu;
int is_done;
int success;
} synchronizer;
@@ -77,10 +79,10 @@ static void on_jwt_verification_done(void *user_data,
grpc_jwt_verifier_status_to_string(status));
}
- gpr_mu_lock(GRPC_POLLSET_MU(&sync->pollset));
+ gpr_mu_lock(&sync->mu);
sync->is_done = 1;
- grpc_pollset_kick(&sync->pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&sync->pollset));
+ grpc_pollset_kick(sync->pollset, NULL);
+ gpr_mu_unlock(&sync->mu);
}
int main(int argc, char **argv) {
@@ -103,23 +105,28 @@ int main(int argc, char **argv) {
grpc_init();
- grpc_pollset_init(&sync.pollset);
+ sync.pollset = gpr_malloc(grpc_pollset_size());
+ gpr_mu_init(&sync.mu);
+ grpc_pollset_init(sync.pollset, &sync.mu);
sync.is_done = 0;
- grpc_jwt_verifier_verify(&exec_ctx, verifier, &sync.pollset, jwt, aud,
+ grpc_jwt_verifier_verify(&exec_ctx, verifier, sync.pollset, jwt, aud,
on_jwt_verification_done, &sync);
- gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset));
+ gpr_mu_lock(&sync.mu);
while (!sync.is_done) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, &sync.pollset, &worker,
+ grpc_pollset_work(&exec_ctx, sync.pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC),
gpr_inf_future(GPR_CLOCK_MONOTONIC));
- gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset));
+ gpr_mu_unlock(&sync.mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset));
+ gpr_mu_lock(&sync.mu);
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset));
+ gpr_mu_unlock(&sync.mu);
+
+ gpr_mu_destroy(&sync.mu);
+ gpr_free(sync.pollset);
grpc_jwt_verifier_destroy(verifier);
gpr_cmdline_destroy(cl);