aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/bad_ssl/bad_ssl_test.cc2
-rw-r--r--test/core/bad_ssl/server_common.cc2
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc44
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc67
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_test.cc34
-rw-r--r--test/core/client_channel/resolvers/fake_resolver_test.cc113
-rw-r--r--test/core/client_channel/resolvers/sockaddr_resolver_test.cc42
-rw-r--r--test/core/fling/client.cc2
-rw-r--r--test/core/fling/fling_stream_test.cc2
-rw-r--r--test/core/fling/fling_test.cc2
-rw-r--r--test/core/fling/server.cc2
-rw-r--r--test/core/gpr/BUILD10
-rw-r--r--test/core/gpr/tls_test.cc3
-rw-r--r--test/core/http/httpcli_test.cc3
-rw-r--r--test/core/http/httpscli_test.cc3
-rw-r--r--test/core/json/json_rewrite.cc2
-rw-r--r--test/core/memory_usage/client.cc3
-rw-r--r--test/core/memory_usage/memory_usage_test.cc2
-rw-r--r--test/core/memory_usage/server.cc2
-rw-r--r--test/core/network_benchmarks/low_level_ping_pong.cc2
-rw-r--r--test/core/security/BUILD3
-rw-r--r--test/core/security/create_jwt.cc3
-rw-r--r--test/core/security/fetch_oauth2.cc2
-rw-r--r--test/core/security/print_google_default_creds_token.cc2
-rw-r--r--test/core/security/verify_jwt.cc2
-rw-r--r--test/core/surface/channel_create_test.cc4
-rw-r--r--test/core/surface/public_headers_must_be_c89.c17
-rw-r--r--test/core/surface/secure_channel_create_test.cc4
-rw-r--r--test/core/util/BUILD15
-rw-r--r--test/core/util/cmdline.cc330
-rw-r--r--test/core/util/cmdline.h80
-rw-r--r--test/core/util/cmdline_test.cc (renamed from test/core/gpr/cmdline_test.cc)4
-rw-r--r--test/core/util/subprocess.h36
-rw-r--r--test/core/util/subprocess_posix.cc99
-rw-r--r--test/core/util/subprocess_windows.cc126
-rw-r--r--test/cpp/client/client_channel_stress_test.cc13
-rw-r--r--test/cpp/end2end/async_end2end_test.cc2
-rw-r--r--test/cpp/end2end/client_lb_end2end_test.cc30
-rw-r--r--test/cpp/end2end/grpclb_end2end_test.cc18
-rw-r--r--test/cpp/grpclb/grpclb_test.cc22
-rw-r--r--test/cpp/naming/resolver_component_test.cc30
-rw-r--r--test/cpp/util/BUILD2
-rw-r--r--test/cpp/util/subprocess.cc2
43 files changed, 916 insertions, 272 deletions
diff --git a/test/core/bad_ssl/bad_ssl_test.cc b/test/core/bad_ssl/bad_ssl_test.cc
index 8aec94fd99..e2ab22e014 100644
--- a/test/core/bad_ssl/bad_ssl_test.cc
+++ b/test/core/bad_ssl/bad_ssl_test.cc
@@ -24,13 +24,13 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include <grpc/support/subprocess.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/port.h"
+#include "test/core/util/subprocess.h"
#include "test/core/util/test_config.h"
static void* tag(intptr_t t) { return (void*)t; }
diff --git a/test/core/bad_ssl/server_common.cc b/test/core/bad_ssl/server_common.cc
index 08842b8350..809539aff3 100644
--- a/test/core/bad_ssl/server_common.cc
+++ b/test/core/bad_ssl/server_common.cc
@@ -16,11 +16,11 @@
*
*/
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include <signal.h>
#include "test/core/bad_ssl/server_common.h"
+#include "test/core/util/cmdline.h"
#include "test/core/util/test_config.h"
/* Common server implementation details for all servers in servers/.
diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc
index 18a795fbcb..8cafadf05a 100644
--- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc
+++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc
@@ -79,17 +79,17 @@ static grpc_ares_request* my_dns_lookup_ares(
return nullptr;
}
-static grpc_resolver* create_resolver(const char* name) {
- grpc_resolver_factory* factory = grpc_resolver_factory_lookup("dns");
+static grpc_core::OrphanablePtr<grpc_core::Resolver> create_resolver(
+ const char* name) {
+ grpc_core::ResolverFactory* factory =
+ grpc_core::ResolverRegistry::LookupResolverFactory("dns");
grpc_uri* uri = grpc_uri_parse(name, 0);
GPR_ASSERT(uri);
- grpc_resolver_args args;
- memset(&args, 0, sizeof(args));
+ grpc_core::ResolverArgs args;
args.uri = uri;
args.combiner = g_combiner;
- grpc_resolver* resolver =
- grpc_resolver_factory_create_resolver(factory, &args);
- grpc_resolver_factory_unref(factory);
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
+ factory->CreateResolver(args);
grpc_uri_destroy(uri);
return resolver;
}
@@ -112,7 +112,7 @@ static bool wait_loop(int deadline_seconds, gpr_event* ev) {
}
typedef struct next_args {
- grpc_resolver* resolver;
+ grpc_core::Resolver* resolver;
grpc_channel_args** result;
grpc_closure* on_complete;
} next_args;
@@ -120,21 +120,21 @@ typedef struct next_args {
static void call_resolver_next_now_lock_taken(void* arg,
grpc_error* error_unused) {
next_args* a = static_cast<next_args*>(arg);
- grpc_resolver_next_locked(a->resolver, a->result, a->on_complete);
+ a->resolver->NextLocked(a->result, a->on_complete);
gpr_free(a);
}
-static void call_resolver_next_after_locking(grpc_resolver* resolver,
+static void call_resolver_next_after_locking(grpc_core::Resolver* resolver,
grpc_channel_args** result,
- grpc_closure* on_complete) {
+ grpc_closure* on_complete,
+ grpc_combiner* combiner) {
next_args* a = static_cast<next_args*>(gpr_malloc(sizeof(*a)));
a->resolver = resolver;
a->result = result;
a->on_complete = on_complete;
- GRPC_CLOSURE_SCHED(
- GRPC_CLOSURE_CREATE(call_resolver_next_now_lock_taken, a,
- grpc_combiner_scheduler(resolver->combiner)),
- GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(call_resolver_next_now_lock_taken, a,
+ grpc_combiner_scheduler(combiner)),
+ GRPC_ERROR_NONE);
}
int main(int argc, char** argv) {
@@ -149,12 +149,14 @@ int main(int argc, char** argv) {
{
grpc_core::ExecCtx exec_ctx;
- grpc_resolver* resolver = create_resolver("dns:test");
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
+ create_resolver("dns:test");
gpr_event ev1;
gpr_event_init(&ev1);
call_resolver_next_after_locking(
- resolver, &result,
- GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx));
+ resolver.get(), &result,
+ GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx),
+ g_combiner);
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(wait_loop(5, &ev1));
GPR_ASSERT(result == nullptr);
@@ -162,14 +164,14 @@ int main(int argc, char** argv) {
gpr_event ev2;
gpr_event_init(&ev2);
call_resolver_next_after_locking(
- resolver, &result,
- GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx));
+ resolver.get(), &result,
+ GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx),
+ g_combiner);
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(wait_loop(30, &ev2));
GPR_ASSERT(result != nullptr);
grpc_channel_args_destroy(result);
- GRPC_RESOLVER_UNREF(resolver, "test");
GRPC_COMBINER_UNREF(g_combiner, "test");
}
diff --git a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc
index 64342b48c8..9402a605b3 100644
--- a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc
+++ b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc
@@ -23,6 +23,7 @@
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include "src/core/ext/filters/client_channel/resolver_registry.h"
#include "src/core/lib/channel/channel_args.h"
+#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "test/core/util/test_config.h"
@@ -131,13 +132,13 @@ static void poll_pollset_until_request_done(iomgr_args* args) {
gpr_event_set(&args->ev, (void*)1);
}
-typedef struct on_resolution_cb_arg {
- const char* uri_str;
- grpc_resolver* resolver;
- grpc_channel_args* result;
- grpc_millis delay_before_second_resolution;
- bool using_cares;
-} on_resolution_cb_arg;
+struct OnResolutionCallbackArg {
+ const char* uri_str = nullptr;
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver;
+ grpc_channel_args* result = nullptr;
+ grpc_millis delay_before_second_resolution = 0;
+ bool using_cares = false;
+};
// Counter for the number of times a resolution notification callback has been
// invoked.
@@ -147,7 +148,7 @@ static int g_on_resolution_invocations_count;
bool g_all_callbacks_invoked;
void on_third_resolution(void* arg, grpc_error* error) {
- on_resolution_cb_arg* cb_arg = static_cast<on_resolution_cb_arg*>(arg);
+ OnResolutionCallbackArg* cb_arg = static_cast<OnResolutionCallbackArg*>(arg);
GPR_ASSERT(error == GRPC_ERROR_NONE);
++g_on_resolution_invocations_count;
grpc_channel_args_destroy(cb_arg->result);
@@ -159,8 +160,7 @@ void on_third_resolution(void* arg, grpc_error* error) {
// period.
GPR_ASSERT(g_on_resolution_invocations_count == 3);
GPR_ASSERT(g_resolution_count == 2);
- grpc_resolver_shutdown_locked(cb_arg->resolver);
- GRPC_RESOLVER_UNREF(cb_arg->resolver, "on_third_resolution");
+ cb_arg->resolver.reset();
if (cb_arg->using_cares) {
gpr_atm_rel_store(&g_iomgr_args.done_atm, 1);
gpr_mu_lock(g_iomgr_args.mu);
@@ -168,12 +168,12 @@ void on_third_resolution(void* arg, grpc_error* error) {
grpc_pollset_kick(g_iomgr_args.pollset, nullptr));
gpr_mu_unlock(g_iomgr_args.mu);
}
- gpr_free(cb_arg);
+ grpc_core::Delete(cb_arg);
g_all_callbacks_invoked = true;
}
void on_second_resolution(void* arg, grpc_error* error) {
- on_resolution_cb_arg* cb_arg = static_cast<on_resolution_cb_arg*>(arg);
+ OnResolutionCallbackArg* cb_arg = static_cast<OnResolutionCallbackArg*>(arg);
++g_on_resolution_invocations_count;
grpc_channel_args_destroy(cb_arg->result);
@@ -187,11 +187,11 @@ void on_second_resolution(void* arg, grpc_error* error) {
GPR_ASSERT(g_resolution_count == 1);
grpc_core::ExecCtx::Get()->TestOnlySetNow(
cb_arg->delay_before_second_resolution * 2);
- grpc_resolver_next_locked(
- cb_arg->resolver, &cb_arg->result,
+ cb_arg->resolver->NextLocked(
+ &cb_arg->result,
GRPC_CLOSURE_CREATE(on_third_resolution, arg,
grpc_combiner_scheduler(g_combiner)));
- grpc_resolver_channel_saw_error_locked(cb_arg->resolver);
+ cb_arg->resolver->RequestReresolutionLocked();
if (cb_arg->using_cares) {
gpr_mu_lock(g_iomgr_args.mu);
GRPC_LOG_IF_ERROR("pollset_kick",
@@ -201,14 +201,14 @@ void on_second_resolution(void* arg, grpc_error* error) {
}
void on_first_resolution(void* arg, grpc_error* error) {
- on_resolution_cb_arg* cb_arg = static_cast<on_resolution_cb_arg*>(arg);
+ OnResolutionCallbackArg* cb_arg = static_cast<OnResolutionCallbackArg*>(arg);
++g_on_resolution_invocations_count;
grpc_channel_args_destroy(cb_arg->result);
- grpc_resolver_next_locked(
- cb_arg->resolver, &cb_arg->result,
+ cb_arg->resolver->NextLocked(
+ &cb_arg->result,
GRPC_CLOSURE_CREATE(on_second_resolution, arg,
grpc_combiner_scheduler(g_combiner)));
- grpc_resolver_channel_saw_error_locked(cb_arg->resolver);
+ cb_arg->resolver->RequestReresolutionLocked();
gpr_log(GPR_INFO,
"1st: g_on_resolution_invocations_count: %d, g_resolution_count: %d",
g_on_resolution_invocations_count, g_resolution_count);
@@ -225,15 +225,16 @@ void on_first_resolution(void* arg, grpc_error* error) {
}
static void start_test_under_combiner(void* arg, grpc_error* error) {
- on_resolution_cb_arg* res_cb_arg = static_cast<on_resolution_cb_arg*>(arg);
- grpc_resolver* resolver;
- grpc_resolver_factory* factory = grpc_resolver_factory_lookup("dns");
+ OnResolutionCallbackArg* res_cb_arg =
+ static_cast<OnResolutionCallbackArg*>(arg);
+
+ grpc_core::ResolverFactory* factory =
+ grpc_core::ResolverRegistry::LookupResolverFactory("dns");
grpc_uri* uri = grpc_uri_parse(res_cb_arg->uri_str, 0);
- grpc_resolver_args args;
gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", res_cb_arg->uri_str,
- factory->vtable->scheme);
- GPR_ASSERT(uri);
- memset(&args, 0, sizeof(args));
+ factory->scheme());
+ GPR_ASSERT(uri != nullptr);
+ grpc_core::ResolverArgs args;
args.uri = uri;
args.combiner = g_combiner;
g_on_resolution_invocations_count = 0;
@@ -248,25 +249,23 @@ static void start_test_under_combiner(void* arg, grpc_error* error) {
auto* cooldown_channel_args =
grpc_channel_args_copy_and_add(nullptr, &cooldown_arg, 1);
args.args = cooldown_channel_args;
- resolver = grpc_resolver_factory_create_resolver(factory, &args);
+ res_cb_arg->resolver = factory->CreateResolver(args);
grpc_channel_args_destroy(cooldown_channel_args);
- GPR_ASSERT(resolver != nullptr);
- res_cb_arg->resolver = resolver;
+ GPR_ASSERT(res_cb_arg->resolver != nullptr);
res_cb_arg->delay_before_second_resolution = kMinResolutionPeriodMs;
// First resolution, would incur in system-level resolution.
- grpc_resolver_next_locked(
- resolver, &res_cb_arg->result,
+ res_cb_arg->resolver->NextLocked(
+ &res_cb_arg->result,
GRPC_CLOSURE_CREATE(on_first_resolution, res_cb_arg,
grpc_combiner_scheduler(g_combiner)));
grpc_uri_destroy(uri);
- grpc_resolver_factory_unref(factory);
}
static void test_cooldown(bool using_cares) {
grpc_core::ExecCtx exec_ctx;
if (using_cares) iomgr_args_init(&g_iomgr_args);
- on_resolution_cb_arg* res_cb_arg =
- static_cast<on_resolution_cb_arg*>(gpr_zalloc(sizeof(*res_cb_arg)));
+ OnResolutionCallbackArg* res_cb_arg =
+ grpc_core::New<OnResolutionCallbackArg>();
res_cb_arg->uri_str = "dns:127.0.0.1";
res_cb_arg->using_cares = using_cares;
diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc
index 80667908ef..e3fba2838c 100644
--- a/test/core/client_channel/resolvers/dns_resolver_test.cc
+++ b/test/core/client_channel/resolvers/dns_resolver_test.cc
@@ -27,47 +27,46 @@
static grpc_combiner* g_combiner;
-static void test_succeeds(grpc_resolver_factory* factory, const char* string) {
+static void test_succeeds(grpc_core::ResolverFactory* factory,
+ const char* string) {
+ gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
+ factory->scheme());
grpc_core::ExecCtx exec_ctx;
grpc_uri* uri = grpc_uri_parse(string, 0);
- grpc_resolver_args args;
- grpc_resolver* resolver;
- gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
- factory->vtable->scheme);
GPR_ASSERT(uri);
- memset(&args, 0, sizeof(args));
+ grpc_core::ResolverArgs args;
args.uri = uri;
args.combiner = g_combiner;
- resolver = grpc_resolver_factory_create_resolver(factory, &args);
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
+ factory->CreateResolver(args);
GPR_ASSERT(resolver != nullptr);
- GRPC_RESOLVER_UNREF(resolver, "test_succeeds");
grpc_uri_destroy(uri);
}
-static void test_fails(grpc_resolver_factory* factory, const char* string) {
+static void test_fails(grpc_core::ResolverFactory* factory,
+ const char* string) {
+ gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string,
+ factory->scheme());
grpc_core::ExecCtx exec_ctx;
grpc_uri* uri = grpc_uri_parse(string, 0);
- grpc_resolver_args args;
- grpc_resolver* resolver;
- gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string,
- factory->vtable->scheme);
GPR_ASSERT(uri);
- memset(&args, 0, sizeof(args));
+ grpc_core::ResolverArgs args;
args.uri = uri;
args.combiner = g_combiner;
- resolver = grpc_resolver_factory_create_resolver(factory, &args);
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
+ factory->CreateResolver(args);
GPR_ASSERT(resolver == nullptr);
grpc_uri_destroy(uri);
}
int main(int argc, char** argv) {
- grpc_resolver_factory* dns;
grpc_test_init(argc, argv);
grpc_init();
g_combiner = grpc_combiner_create();
- dns = grpc_resolver_factory_lookup("dns");
+ grpc_core::ResolverFactory* dns =
+ grpc_core::ResolverRegistry::LookupResolverFactory("dns");
test_succeeds(dns, "dns:10.2.1.1");
test_succeeds(dns, "dns:10.2.1.1:1234");
@@ -78,7 +77,6 @@ int main(int argc, char** argv) {
test_fails(dns, "ipv4://8.8.8.8/8.8.8.8:8888");
}
- grpc_resolver_factory_unref(dns);
{
grpc_core::ExecCtx exec_ctx;
GRPC_COMBINER_UNREF(g_combiner, "test");
diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc
index 9c11c01021..03af8954e1 100644
--- a/test/core/client_channel/resolvers/fake_resolver_test.cc
+++ b/test/core/client_channel/resolvers/fake_resolver_test.cc
@@ -27,25 +27,26 @@
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/ext/filters/client_channel/resolver_registry.h"
#include "src/core/lib/channel/channel_args.h"
+#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "test/core/util/test_config.h"
-static grpc_resolver* build_fake_resolver(
+static grpc_core::OrphanablePtr<grpc_core::Resolver> build_fake_resolver(
grpc_combiner* combiner,
- grpc_fake_resolver_response_generator* response_generator) {
- grpc_resolver_factory* factory = grpc_resolver_factory_lookup("fake");
+ grpc_core::FakeResolverResponseGenerator* response_generator) {
+ grpc_core::ResolverFactory* factory =
+ grpc_core::ResolverRegistry::LookupResolverFactory("fake");
grpc_arg generator_arg =
- grpc_fake_resolver_response_generator_arg(response_generator);
- grpc_resolver_args args;
- memset(&args, 0, sizeof(args));
+ grpc_core::FakeResolverResponseGenerator::MakeChannelArg(
+ response_generator);
grpc_channel_args channel_args = {1, &generator_arg};
+ grpc_core::ResolverArgs args;
args.args = &channel_args;
args.combiner = combiner;
- grpc_resolver* resolver =
- grpc_resolver_factory_create_resolver(factory, &args);
- grpc_resolver_factory_unref(factory);
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
+ factory->CreateResolver(args);
return resolver;
}
@@ -57,10 +58,11 @@ typedef struct on_resolution_arg {
// Callback to check the resolution result is as expected.
void on_resolution_cb(void* arg, grpc_error* error) {
+ if (error != GRPC_ERROR_NONE) return;
on_resolution_arg* res = static_cast<on_resolution_arg*>(arg);
// We only check the addresses channel arg because that's the only one
// explicitly set by the test via
- // grpc_fake_resolver_response_generator_set_response.
+ // FakeResolverResponseGenerator::SetResponse().
const grpc_lb_addresses* actual_lb_addresses =
grpc_lb_addresses_find_channel_arg(res->resolver_result);
const grpc_lb_addresses* expected_lb_addresses =
@@ -115,27 +117,27 @@ static void test_fake_resolver() {
grpc_core::ExecCtx exec_ctx;
grpc_combiner* combiner = grpc_combiner_create();
// Create resolver.
- grpc_fake_resolver_response_generator* response_generator =
- grpc_fake_resolver_response_generator_create();
- grpc_resolver* resolver = build_fake_resolver(combiner, response_generator);
- GPR_ASSERT(resolver != nullptr);
+ grpc_core::RefCountedPtr<grpc_core::FakeResolverResponseGenerator>
+ response_generator =
+ grpc_core::MakeRefCounted<grpc_core::FakeResolverResponseGenerator>();
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
+ build_fake_resolver(combiner, response_generator.get());
+ GPR_ASSERT(resolver.get() != nullptr);
// Test 1: normal resolution.
- // next_results != NULL, results_upon_error == NULL, last_used_results ==
+ // next_results != NULL, reresolution_results == NULL, last_used_results ==
// NULL. Expected response is next_results.
grpc_channel_args* results = create_new_resolver_result();
on_resolution_arg on_res_arg = create_on_resolution_arg(results);
grpc_closure* on_resolution = GRPC_CLOSURE_CREATE(
on_resolution_cb, &on_res_arg, grpc_combiner_scheduler(combiner));
// Resolution won't be triggered until next_results is set.
- grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result,
- on_resolution);
- grpc_fake_resolver_response_generator_set_response(response_generator,
- results);
+ resolver->NextLocked(&on_res_arg.resolver_result, on_resolution);
+ response_generator->SetResponse(results);
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(gpr_event_wait(&on_res_arg.ev,
grpc_timeout_seconds_to_deadline(5)) != nullptr);
// Test 2: update resolution.
- // next_results != NULL, results_upon_error == NULL, last_used_results !=
+ // next_results != NULL, reresolution_results == NULL, last_used_results !=
// NULL. Expected response is next_results.
results = create_new_resolver_result();
grpc_channel_args* last_used_results = grpc_channel_args_copy(results);
@@ -143,61 +145,55 @@ static void test_fake_resolver() {
on_resolution = GRPC_CLOSURE_CREATE(on_resolution_cb, &on_res_arg,
grpc_combiner_scheduler(combiner));
// Resolution won't be triggered until next_results is set.
- grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result,
- on_resolution);
- grpc_fake_resolver_response_generator_set_response(response_generator,
- results);
+ resolver->NextLocked(&on_res_arg.resolver_result, on_resolution);
+ response_generator->SetResponse(results);
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(gpr_event_wait(&on_res_arg.ev,
grpc_timeout_seconds_to_deadline(5)) != nullptr);
// Test 3: fallback re-resolution.
- // next_results == NULL, results_upon_error == NULL, last_used_results !=
+ // next_results == NULL, reresolution_results == NULL, last_used_results !=
// NULL. Expected response is last_used_results.
on_res_arg = create_on_resolution_arg(last_used_results);
on_resolution = GRPC_CLOSURE_CREATE(on_resolution_cb, &on_res_arg,
grpc_combiner_scheduler(combiner));
- grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result,
- on_resolution);
+ resolver->NextLocked(&on_res_arg.resolver_result, on_resolution);
// Trigger a re-resolution.
- grpc_resolver_channel_saw_error_locked(resolver);
+ resolver->RequestReresolutionLocked();
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(gpr_event_wait(&on_res_arg.ev,
grpc_timeout_seconds_to_deadline(5)) != nullptr);
// Test 4: normal re-resolution.
- // next_results == NULL, results_upon_error != NULL, last_used_results !=
- // NULL. Expected response is results_upon_error.
- grpc_channel_args* results_upon_error = create_new_resolver_result();
+ // next_results == NULL, reresolution_results != NULL, last_used_results !=
+ // NULL. Expected response is reresolution_results.
+ grpc_channel_args* reresolution_results = create_new_resolver_result();
on_res_arg =
- create_on_resolution_arg(grpc_channel_args_copy(results_upon_error));
+ create_on_resolution_arg(grpc_channel_args_copy(reresolution_results));
on_resolution = GRPC_CLOSURE_CREATE(on_resolution_cb, &on_res_arg,
grpc_combiner_scheduler(combiner));
- grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result,
- on_resolution);
- // Set results_upon_error.
- grpc_fake_resolver_response_generator_set_response_upon_error(
- response_generator, results_upon_error);
+ resolver->NextLocked(&on_res_arg.resolver_result, on_resolution);
+ // Set reresolution_results.
+ response_generator->SetReresolutionResponse(reresolution_results);
// Flush here to guarantee that the response has been set.
grpc_core::ExecCtx::Get()->Flush();
// Trigger a re-resolution.
- grpc_resolver_channel_saw_error_locked(resolver);
+ resolver->RequestReresolutionLocked();
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(gpr_event_wait(&on_res_arg.ev,
grpc_timeout_seconds_to_deadline(5)) != nullptr);
// Test 5: repeat re-resolution.
- // next_results == NULL, results_upon_error != NULL, last_used_results !=
- // NULL. Expected response is results_upon_error.
- on_res_arg = create_on_resolution_arg(results_upon_error);
+ // next_results == NULL, reresolution_results != NULL, last_used_results !=
+ // NULL. Expected response is reresolution_results.
+ on_res_arg = create_on_resolution_arg(reresolution_results);
on_resolution = GRPC_CLOSURE_CREATE(on_resolution_cb, &on_res_arg,
grpc_combiner_scheduler(combiner));
- grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result,
- on_resolution);
+ resolver->NextLocked(&on_res_arg.resolver_result, on_resolution);
// Trigger a re-resolution.
- grpc_resolver_channel_saw_error_locked(resolver);
+ resolver->RequestReresolutionLocked();
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(gpr_event_wait(&on_res_arg.ev,
grpc_timeout_seconds_to_deadline(5)) != nullptr);
// Test 6: normal resolution.
- // next_results != NULL, results_upon_error != NULL, last_used_results !=
+ // next_results != NULL, reresolution_results != NULL, last_used_results !=
// NULL. Expected response is next_results.
results = create_new_resolver_result();
last_used_results = grpc_channel_args_copy(results);
@@ -205,28 +201,24 @@ static void test_fake_resolver() {
on_resolution = GRPC_CLOSURE_CREATE(on_resolution_cb, &on_res_arg,
grpc_combiner_scheduler(combiner));
// Resolution won't be triggered until next_results is set.
- grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result,
- on_resolution);
- grpc_fake_resolver_response_generator_set_response(response_generator,
- results);
+ resolver->NextLocked(&on_res_arg.resolver_result, on_resolution);
+ response_generator->SetResponse(results);
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(gpr_event_wait(&on_res_arg.ev,
grpc_timeout_seconds_to_deadline(5)) != nullptr);
// Test 7: fallback re-resolution.
- // next_results == NULL, results_upon_error == NULL, last_used_results !=
+ // next_results == NULL, reresolution_results == NULL, last_used_results !=
// NULL. Expected response is last_used_results.
on_res_arg = create_on_resolution_arg(last_used_results);
on_resolution = GRPC_CLOSURE_CREATE(on_resolution_cb, &on_res_arg,
grpc_combiner_scheduler(combiner));
- grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result,
- on_resolution);
- // Reset results_upon_error.
- grpc_fake_resolver_response_generator_set_response_upon_error(
- response_generator, nullptr);
- // Flush here to guarantee that results_upon_error has been reset.
+ resolver->NextLocked(&on_res_arg.resolver_result, on_resolution);
+ // Reset reresolution_results.
+ response_generator->SetReresolutionResponse(nullptr);
+ // Flush here to guarantee that reresolution_results has been reset.
grpc_core::ExecCtx::Get()->Flush();
// Trigger a re-resolution.
- grpc_resolver_channel_saw_error_locked(resolver);
+ resolver->RequestReresolutionLocked();
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(gpr_event_wait(&on_res_arg.ev,
grpc_timeout_seconds_to_deadline(5)) != nullptr);
@@ -234,16 +226,15 @@ static void test_fake_resolver() {
// Requesting a new resolution without setting the response shouldn't trigger
// the resolution callback.
memset(&on_res_arg, 0, sizeof(on_res_arg));
- grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result,
- on_resolution);
+ on_resolution = GRPC_CLOSURE_CREATE(on_resolution_cb, &on_res_arg,
+ grpc_combiner_scheduler(combiner));
+ resolver->NextLocked(&on_res_arg.resolver_result, on_resolution);
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(gpr_event_wait(&on_res_arg.ev,
grpc_timeout_milliseconds_to_deadline(100)) ==
nullptr);
// Clean up.
GRPC_COMBINER_UNREF(combiner, "test_fake_resolver");
- GRPC_RESOLVER_UNREF(resolver, "test_fake_resolver");
- grpc_fake_resolver_response_generator_unref(response_generator);
}
int main(int argc, char** argv) {
diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc
index 07ee133ee3..b9287c2468 100644
--- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc
+++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc
@@ -40,18 +40,18 @@ void on_resolution_cb(void* arg, grpc_error* error) {
grpc_channel_args_destroy(res->resolver_result);
}
-static void test_succeeds(grpc_resolver_factory* factory, const char* string) {
+static void test_succeeds(grpc_core::ResolverFactory* factory,
+ const char* string) {
+ gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
+ factory->scheme());
grpc_core::ExecCtx exec_ctx;
grpc_uri* uri = grpc_uri_parse(string, 0);
- grpc_resolver_args args;
- grpc_resolver* resolver;
- gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
- factory->vtable->scheme);
GPR_ASSERT(uri);
- memset(&args, 0, sizeof(args));
+ grpc_core::ResolverArgs args;
args.uri = uri;
args.combiner = g_combiner;
- resolver = grpc_resolver_factory_create_resolver(factory, &args);
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
+ factory->CreateResolver(args);
GPR_ASSERT(resolver != nullptr);
on_resolution_arg on_res_arg;
@@ -60,40 +60,39 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) {
grpc_closure* on_resolution = GRPC_CLOSURE_CREATE(
on_resolution_cb, &on_res_arg, grpc_schedule_on_exec_ctx);
- grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result,
- on_resolution);
- GRPC_RESOLVER_UNREF(resolver, "test_succeeds");
+ resolver->NextLocked(&on_res_arg.resolver_result, on_resolution);
grpc_uri_destroy(uri);
/* Flush ExecCtx to avoid stack-use-after-scope on on_res_arg which is
* accessed in the closure on_resolution_cb */
grpc_core::ExecCtx::Get()->Flush();
}
-static void test_fails(grpc_resolver_factory* factory, const char* string) {
+static void test_fails(grpc_core::ResolverFactory* factory,
+ const char* string) {
+ gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string,
+ factory->scheme());
grpc_core::ExecCtx exec_ctx;
grpc_uri* uri = grpc_uri_parse(string, 0);
- grpc_resolver_args args;
- grpc_resolver* resolver;
- gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string,
- factory->vtable->scheme);
GPR_ASSERT(uri);
- memset(&args, 0, sizeof(args));
+ grpc_core::ResolverArgs args;
args.uri = uri;
args.combiner = g_combiner;
- resolver = grpc_resolver_factory_create_resolver(factory, &args);
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
+ factory->CreateResolver(args);
GPR_ASSERT(resolver == nullptr);
grpc_uri_destroy(uri);
}
int main(int argc, char** argv) {
- grpc_resolver_factory *ipv4, *ipv6;
grpc_test_init(argc, argv);
grpc_init();
g_combiner = grpc_combiner_create();
- ipv4 = grpc_resolver_factory_lookup("ipv4");
- ipv6 = grpc_resolver_factory_lookup("ipv6");
+ grpc_core::ResolverFactory* ipv4 =
+ grpc_core::ResolverRegistry::LookupResolverFactory("ipv4");
+ grpc_core::ResolverFactory* ipv6 =
+ grpc_core::ResolverRegistry::LookupResolverFactory("ipv6");
test_fails(ipv4, "ipv4:10.2.1.1");
test_succeeds(ipv4, "ipv4:10.2.1.1:1234");
@@ -109,9 +108,6 @@ int main(int argc, char** argv) {
test_fails(ipv6, "ipv6:[::]:123456");
test_fails(ipv6, "ipv6:www.google.com");
- grpc_resolver_factory_unref(ipv4);
- grpc_resolver_factory_unref(ipv6);
-
{
grpc_core::ExecCtx exec_ctx;
GRPC_COMBINER_UNREF(g_combiner, "test");
diff --git a/test/core/fling/client.cc b/test/core/fling/client.cc
index c623d376f8..66810975fd 100644
--- a/test/core/fling/client.cc
+++ b/test/core/fling/client.cc
@@ -21,11 +21,11 @@
#include <stdio.h>
#include <string.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include <grpc/support/useful.h>
#include "src/core/lib/profiling/timers.h"
+#include "test/core/util/cmdline.h"
#include "test/core/util/grpc_profiler.h"
#include "test/core/util/histogram.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/fling/fling_stream_test.cc b/test/core/fling/fling_stream_test.cc
index 6b29486f22..d5fd7a8d46 100644
--- a/test/core/fling/fling_stream_test.cc
+++ b/test/core/fling/fling_stream_test.cc
@@ -21,11 +21,11 @@
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
-#include <grpc/support/subprocess.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "test/core/util/port.h"
+#include "test/core/util/subprocess.h"
int main(int argc, char** argv) {
char* me = argv[0];
diff --git a/test/core/fling/fling_test.cc b/test/core/fling/fling_test.cc
index ceb9851bc9..d95317b7e6 100644
--- a/test/core/fling/fling_test.cc
+++ b/test/core/fling/fling_test.cc
@@ -21,11 +21,11 @@
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
-#include <grpc/support/subprocess.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "test/core/util/port.h"
+#include "test/core/util/subprocess.h"
int main(int argc, const char** argv) {
const char* me = argv[0];
diff --git a/test/core/fling/server.cc b/test/core/fling/server.cc
index 328bd4edbd..b19a25a185 100644
--- a/test/core/fling/server.cc
+++ b/test/core/fling/server.cc
@@ -30,13 +30,13 @@
#endif
#include <grpc/support/alloc.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/profiling/timers.h"
#include "test/core/end2end/data/ssl_test_data.h"
+#include "test/core/util/cmdline.h"
#include "test/core/util/grpc_profiler.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/gpr/BUILD b/test/core/gpr/BUILD
index 1be1036d04..27fd9e180b 100644
--- a/test/core/gpr/BUILD
+++ b/test/core/gpr/BUILD
@@ -39,16 +39,6 @@ grpc_cc_test(
)
grpc_cc_test(
- name = "cmdline_test",
- srcs = ["cmdline_test.cc"],
- language = "C++",
- deps = [
- "//:gpr",
- "//test/core/util:gpr_test_util",
- ],
-)
-
-grpc_cc_test(
name = "cpu_test",
srcs = ["cpu_test.cc"],
language = "C++",
diff --git a/test/core/gpr/tls_test.cc b/test/core/gpr/tls_test.cc
index 743b10f090..1ef253ed6f 100644
--- a/test/core/gpr/tls_test.cc
+++ b/test/core/gpr/tls_test.cc
@@ -21,9 +21,10 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
-#include <grpc/support/tls.h>
#include <stdio.h>
#include <stdlib.h>
+
+#include "src/core/lib/gpr/tls.h"
#include "test/core/util/test_config.h"
#define NUM_THREADS 100
diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc
index 6ad0753f7e..3d892b939c 100644
--- a/test/core/http/httpcli_test.cc
+++ b/test/core/http/httpcli_test.cc
@@ -24,10 +24,11 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include <grpc/support/subprocess.h>
#include <grpc/support/sync.h>
+
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/port.h"
+#include "test/core/util/subprocess.h"
#include "test/core/util/test_config.h"
static int g_done = 0;
diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc
index 92193bb442..7e99ad4249 100644
--- a/test/core/http/httpscli_test.cc
+++ b/test/core/http/httpscli_test.cc
@@ -25,11 +25,12 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include <grpc/support/subprocess.h>
#include <grpc/support/sync.h>
+
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/port.h"
+#include "test/core/util/subprocess.h"
#include "test/core/util/test_config.h"
static int g_done = 0;
diff --git a/test/core/json/json_rewrite.cc b/test/core/json/json_rewrite.cc
index 6891a57f9f..0319d15024 100644
--- a/test/core/json/json_rewrite.cc
+++ b/test/core/json/json_rewrite.cc
@@ -20,11 +20,11 @@
#include <stdlib.h>
#include <grpc/support/alloc.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include "src/core/lib/json/json_reader.h"
#include "src/core/lib/json/json_writer.h"
+#include "test/core/util/cmdline.h"
typedef struct json_writer_userdata {
FILE* out;
diff --git a/test/core/memory_usage/client.cc b/test/core/memory_usage/client.cc
index ca841434aa..e8b3540f46 100644
--- a/test/core/memory_usage/client.cc
+++ b/test/core/memory_usage/client.cc
@@ -24,12 +24,13 @@
#include <grpc/byte_buffer.h>
#include <grpc/byte_buffer_reader.h>
#include <grpc/support/alloc.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include <grpc/support/useful.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
+
+#include "test/core/util/cmdline.h"
#include "test/core/util/memory_counters.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/memory_usage/memory_usage_test.cc b/test/core/memory_usage/memory_usage_test.cc
index f6316bda0b..cc3528b060 100644
--- a/test/core/memory_usage/memory_usage_test.cc
+++ b/test/core/memory_usage/memory_usage_test.cc
@@ -21,11 +21,11 @@
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
-#include <grpc/support/subprocess.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "test/core/util/port.h"
+#include "test/core/util/subprocess.h"
int main(int argc, char** argv) {
char* me = argv[0];
diff --git a/test/core/memory_usage/server.cc b/test/core/memory_usage/server.cc
index f5da3cb791..a276102e83 100644
--- a/test/core/memory_usage/server.cc
+++ b/test/core/memory_usage/server.cc
@@ -30,12 +30,12 @@
#endif
#include <grpc/support/alloc.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/host_port.h"
#include "test/core/end2end/data/ssl_test_data.h"
+#include "test/core/util/cmdline.h"
#include "test/core/util/memory_counters.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc
index fb982a10fd..dd577867ab 100644
--- a/test/core/network_benchmarks/low_level_ping_pong.cc
+++ b/test/core/network_benchmarks/low_level_ping_pong.cc
@@ -35,13 +35,13 @@
#include <sys/socket.h>
#include <grpc/support/alloc.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>
#include <grpc/support/useful.h>
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
+#include "test/core/util/cmdline.h"
#include "test/core/util/histogram.h"
typedef struct fd_pair {
diff --git a/test/core/security/BUILD b/test/core/security/BUILD
index 7cd3ae58da..425c617fd1 100644
--- a/test/core/security/BUILD
+++ b/test/core/security/BUILD
@@ -110,6 +110,7 @@ grpc_cc_binary(
deps = [
"//:gpr",
"//:grpc",
+ "//test/core/util:grpc_test_util",
],
)
@@ -121,6 +122,7 @@ grpc_cc_binary(
":oauth2_utils",
"//:gpr",
"//:grpc",
+ "//test/core/util:grpc_test_util",
],
)
@@ -131,5 +133,6 @@ grpc_cc_binary(
deps = [
"//:gpr",
"//:grpc",
+ "//test/core/util:grpc_test_util",
],
)
diff --git a/test/core/security/create_jwt.cc b/test/core/security/create_jwt.cc
index 56ae9c891c..bb8227f08f 100644
--- a/test/core/security/create_jwt.cc
+++ b/test/core/security/create_jwt.cc
@@ -24,9 +24,10 @@
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
+#include "test/core/util/cmdline.h"
+
void create_jwt(const char* json_key_file_path, const char* service_url,
const char* scope) {
grpc_auth_json_key key;
diff --git a/test/core/security/fetch_oauth2.cc b/test/core/security/fetch_oauth2.cc
index cb28a0487c..b0fa514400 100644
--- a/test/core/security/fetch_oauth2.cc
+++ b/test/core/security/fetch_oauth2.cc
@@ -23,13 +23,13 @@
#include <grpc/grpc_security.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "test/core/security/oauth2_utils.h"
+#include "test/core/util/cmdline.h"
static grpc_call_credentials* create_refresh_token_creds(
const char* json_refresh_token_file_path) {
diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc
index a90f997bda..828694afd1 100644
--- a/test/core/security/print_google_default_creds_token.cc
+++ b/test/core/security/print_google_default_creds_token.cc
@@ -23,7 +23,6 @@
#include <grpc/grpc_security.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
@@ -31,6 +30,7 @@
#include "src/core/lib/security/credentials/composite/composite_credentials.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/slice/slice_string_helpers.h"
+#include "test/core/util/cmdline.h"
typedef struct {
gpr_mu* mu;
diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc
index 5d32ce0cdb..747508f6f6 100644
--- a/test/core/security/verify_jwt.cc
+++ b/test/core/security/verify_jwt.cc
@@ -23,11 +23,11 @@
#include <grpc/grpc_security.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/security/credentials/jwt/jwt_verifier.h"
+#include "test/core/util/cmdline.h"
typedef struct {
grpc_pollset* pollset;
diff --git a/test/core/surface/channel_create_test.cc b/test/core/surface/channel_create_test.cc
index 37247f89d0..56f4f602e8 100644
--- a/test/core/surface/channel_create_test.cc
+++ b/test/core/surface/channel_create_test.cc
@@ -29,8 +29,8 @@
void test_unknown_scheme_target(void) {
grpc_channel* chan;
/* avoid default prefix */
- grpc_resolver_registry_shutdown();
- grpc_resolver_registry_init();
+ grpc_core::ResolverRegistry::Builder::ShutdownRegistry();
+ grpc_core::ResolverRegistry::Builder::InitRegistry();
chan = grpc_insecure_channel_create("blah://blah", nullptr, nullptr);
GPR_ASSERT(chan != nullptr);
diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c
index 93f07fc3ee..be2a5b7671 100644
--- a/test/core/surface/public_headers_must_be_c89.c
+++ b/test/core/surface/public_headers_must_be_c89.c
@@ -47,18 +47,15 @@
#include <grpc/support/alloc.h>
#include <grpc/support/atm.h>
#include <grpc/support/avl.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/cpu.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h>
-#include <grpc/support/subprocess.h>
#include <grpc/support/sync.h>
#include <grpc/support/sync_custom.h>
#include <grpc/support/sync_generic.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>
-#include <grpc/support/tls.h>
#include <grpc/support/useful.h>
#include <grpc/support/workaround_list.h>
@@ -247,15 +244,6 @@ int main(int argc, char **argv) {
printf("%lx", (unsigned long) gpr_avl_get);
printf("%lx", (unsigned long) gpr_avl_maybe_get);
printf("%lx", (unsigned long) gpr_avl_is_empty);
- printf("%lx", (unsigned long) gpr_cmdline_create);
- printf("%lx", (unsigned long) gpr_cmdline_add_int);
- printf("%lx", (unsigned long) gpr_cmdline_add_flag);
- printf("%lx", (unsigned long) gpr_cmdline_add_string);
- printf("%lx", (unsigned long) gpr_cmdline_on_extra_arg);
- printf("%lx", (unsigned long) gpr_cmdline_set_survive_failure);
- printf("%lx", (unsigned long) gpr_cmdline_parse);
- printf("%lx", (unsigned long) gpr_cmdline_destroy);
- printf("%lx", (unsigned long) gpr_cmdline_usage_string);
printf("%lx", (unsigned long) gpr_cpu_num_cores);
printf("%lx", (unsigned long) gpr_cpu_current_cpu);
printf("%lx", (unsigned long) gpr_log_severity_string);
@@ -266,11 +254,6 @@ int main(int argc, char **argv) {
printf("%lx", (unsigned long) gpr_set_log_function);
printf("%lx", (unsigned long) gpr_strdup);
printf("%lx", (unsigned long) gpr_asprintf);
- printf("%lx", (unsigned long) gpr_subprocess_binary_extension);
- printf("%lx", (unsigned long) gpr_subprocess_create);
- printf("%lx", (unsigned long) gpr_subprocess_destroy);
- printf("%lx", (unsigned long) gpr_subprocess_join);
- printf("%lx", (unsigned long) gpr_subprocess_interrupt);
printf("%lx", (unsigned long) gpr_mu_init);
printf("%lx", (unsigned long) gpr_mu_destroy);
printf("%lx", (unsigned long) gpr_mu_lock);
diff --git a/test/core/surface/secure_channel_create_test.cc b/test/core/surface/secure_channel_create_test.cc
index fa22cd6873..c10d6796a7 100644
--- a/test/core/surface/secure_channel_create_test.cc
+++ b/test/core/surface/secure_channel_create_test.cc
@@ -28,8 +28,8 @@
#include "test/core/util/test_config.h"
void test_unknown_scheme_target(void) {
- grpc_resolver_registry_shutdown();
- grpc_resolver_registry_init();
+ grpc_core::ResolverRegistry::Builder::ShutdownRegistry();
+ grpc_core::ResolverRegistry::Builder::InitRegistry();
grpc_channel_credentials* creds =
grpc_fake_transport_security_credentials_create();
grpc_channel* chan =
diff --git a/test/core/util/BUILD b/test/core/util/BUILD
index 2237cfc173..886cfddf86 100644
--- a/test/core/util/BUILD
+++ b/test/core/util/BUILD
@@ -51,6 +51,7 @@ grpc_cc_library(
grpc_cc_library(
name = "grpc_test_util_base",
srcs = [
+ "cmdline.cc",
"grpc_profiler.cc",
"histogram.cc",
"mock_endpoint.cc",
@@ -61,11 +62,14 @@ grpc_cc_library(
"port_server_client.cc",
"reconnect_server.cc",
"slice_splitter.cc",
+ "subprocess_posix.cc",
+ "subprocess_windows.cc",
"test_tcp_server.cc",
"tracer_util.cc",
"trickle_endpoint.cc",
],
hdrs = [
+ "cmdline.h",
"grpc_profiler.h",
"histogram.h",
"mock_endpoint.h",
@@ -74,6 +78,7 @@ grpc_cc_library(
"port.h",
"port_server_client.h",
"reconnect_server.h",
+ "subprocess.h",
"slice_splitter.h",
"test_tcp_server.h",
"tracer_util.h",
@@ -109,6 +114,16 @@ grpc_cc_library(
],
)
+grpc_cc_test(
+ name = "cmdline_test",
+ srcs = ["cmdline_test.cc"],
+ language = "C++",
+ deps = [
+ ":grpc_test_util",
+ "//:gpr",
+ ],
+)
+
grpc_cc_library(
name = "fuzzer_corpus_test",
testonly = 1,
diff --git a/test/core/util/cmdline.cc b/test/core/util/cmdline.cc
new file mode 100644
index 0000000000..20bce273cd
--- /dev/null
+++ b/test/core/util/cmdline.cc
@@ -0,0 +1,330 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "test/core/util/cmdline.h"
+
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+#include "src/core/lib/gpr/string.h"
+
+typedef enum { ARGTYPE_INT, ARGTYPE_BOOL, ARGTYPE_STRING } argtype;
+
+typedef struct arg {
+ const char* name;
+ const char* help;
+ argtype type;
+ void* value;
+ struct arg* next;
+} arg;
+
+struct gpr_cmdline {
+ const char* description;
+ arg* args;
+ const char* argv0;
+
+ const char* extra_arg_name;
+ const char* extra_arg_help;
+ void (*extra_arg)(void* user_data, const char* arg);
+ void* extra_arg_user_data;
+
+ int (*state)(gpr_cmdline* cl, char* arg);
+ arg* cur_arg;
+
+ int survive_failure;
+};
+
+static int normal_state(gpr_cmdline* cl, char* arg);
+
+gpr_cmdline* gpr_cmdline_create(const char* description) {
+ gpr_cmdline* cl = (gpr_cmdline*)gpr_zalloc(sizeof(gpr_cmdline));
+
+ cl->description = description;
+ cl->state = normal_state;
+
+ return cl;
+}
+
+void gpr_cmdline_set_survive_failure(gpr_cmdline* cl) {
+ cl->survive_failure = 1;
+}
+
+void gpr_cmdline_destroy(gpr_cmdline* cl) {
+ while (cl->args) {
+ arg* a = cl->args;
+ cl->args = a->next;
+ gpr_free(a);
+ }
+ gpr_free(cl);
+}
+
+static void add_arg(gpr_cmdline* cl, const char* name, const char* help,
+ argtype type, void* value) {
+ arg* a;
+
+ for (a = cl->args; a; a = a->next) {
+ GPR_ASSERT(0 != strcmp(a->name, name));
+ }
+
+ a = (arg*)gpr_zalloc(sizeof(arg));
+ a->name = name;
+ a->help = help;
+ a->type = type;
+ a->value = value;
+ a->next = cl->args;
+ cl->args = a;
+}
+
+void gpr_cmdline_add_int(gpr_cmdline* cl, const char* name, const char* help,
+ int* value) {
+ add_arg(cl, name, help, ARGTYPE_INT, value);
+}
+
+void gpr_cmdline_add_flag(gpr_cmdline* cl, const char* name, const char* help,
+ int* value) {
+ add_arg(cl, name, help, ARGTYPE_BOOL, value);
+}
+
+void gpr_cmdline_add_string(gpr_cmdline* cl, const char* name, const char* help,
+ const char** value) {
+ add_arg(cl, name, help, ARGTYPE_STRING, value);
+}
+
+void gpr_cmdline_on_extra_arg(
+ gpr_cmdline* cl, const char* name, const char* help,
+ void (*on_extra_arg)(void* user_data, const char* arg), void* user_data) {
+ GPR_ASSERT(!cl->extra_arg);
+ GPR_ASSERT(on_extra_arg);
+
+ cl->extra_arg = on_extra_arg;
+ cl->extra_arg_user_data = user_data;
+ cl->extra_arg_name = name;
+ cl->extra_arg_help = help;
+}
+
+/* recursively descend argument list, adding the last element
+ to s first - so that arguments are added in the order they were
+ added to the list by api calls */
+static void add_args_to_usage(gpr_strvec* s, arg* a) {
+ char* tmp;
+
+ if (!a) return;
+ add_args_to_usage(s, a->next);
+
+ switch (a->type) {
+ case ARGTYPE_BOOL:
+ gpr_asprintf(&tmp, " [--%s|--no-%s]", a->name, a->name);
+ gpr_strvec_add(s, tmp);
+ break;
+ case ARGTYPE_STRING:
+ gpr_asprintf(&tmp, " [--%s=string]", a->name);
+ gpr_strvec_add(s, tmp);
+ break;
+ case ARGTYPE_INT:
+ gpr_asprintf(&tmp, " [--%s=int]", a->name);
+ gpr_strvec_add(s, tmp);
+ break;
+ }
+}
+
+char* gpr_cmdline_usage_string(gpr_cmdline* cl, const char* argv0) {
+ /* TODO(ctiller): make this prettier */
+ gpr_strvec s;
+ char* tmp;
+ const char* name = strrchr(argv0, '/');
+
+ if (name) {
+ name++;
+ } else {
+ name = argv0;
+ }
+
+ gpr_strvec_init(&s);
+
+ gpr_asprintf(&tmp, "Usage: %s", name);
+ gpr_strvec_add(&s, tmp);
+ add_args_to_usage(&s, cl->args);
+ if (cl->extra_arg) {
+ gpr_asprintf(&tmp, " [%s...]", cl->extra_arg_name);
+ gpr_strvec_add(&s, tmp);
+ }
+ gpr_strvec_add(&s, gpr_strdup("\n"));
+
+ tmp = gpr_strvec_flatten(&s, nullptr);
+ gpr_strvec_destroy(&s);
+ return tmp;
+}
+
+static int print_usage_and_die(gpr_cmdline* cl) {
+ char* usage = gpr_cmdline_usage_string(cl, cl->argv0);
+ fprintf(stderr, "%s", usage);
+ gpr_free(usage);
+ if (!cl->survive_failure) {
+ exit(1);
+ }
+ return 0;
+}
+
+static int extra_state(gpr_cmdline* cl, char* str) {
+ if (!cl->extra_arg) {
+ return print_usage_and_die(cl);
+ }
+ cl->extra_arg(cl->extra_arg_user_data, str);
+ return 1;
+}
+
+static arg* find_arg(gpr_cmdline* cl, char* name) {
+ arg* a;
+
+ for (a = cl->args; a; a = a->next) {
+ if (0 == strcmp(a->name, name)) {
+ break;
+ }
+ }
+
+ if (!a) {
+ fprintf(stderr, "Unknown argument: %s\n", name);
+ return nullptr;
+ }
+
+ return a;
+}
+
+static int value_state(gpr_cmdline* cl, char* str) {
+ long intval;
+ char* end;
+
+ GPR_ASSERT(cl->cur_arg);
+
+ switch (cl->cur_arg->type) {
+ case ARGTYPE_INT:
+ intval = strtol(str, &end, 0);
+ if (*end || intval < INT_MIN || intval > INT_MAX) {
+ fprintf(stderr, "expected integer, got '%s' for %s\n", str,
+ cl->cur_arg->name);
+ return print_usage_and_die(cl);
+ }
+ *(int*)cl->cur_arg->value = (int)intval;
+ break;
+ case ARGTYPE_BOOL:
+ if (0 == strcmp(str, "1") || 0 == strcmp(str, "true")) {
+ *(int*)cl->cur_arg->value = 1;
+ } else if (0 == strcmp(str, "0") || 0 == strcmp(str, "false")) {
+ *(int*)cl->cur_arg->value = 0;
+ } else {
+ fprintf(stderr, "expected boolean, got '%s' for %s\n", str,
+ cl->cur_arg->name);
+ return print_usage_and_die(cl);
+ }
+ break;
+ case ARGTYPE_STRING:
+ *(char**)cl->cur_arg->value = str;
+ break;
+ }
+
+ cl->state = normal_state;
+ return 1;
+}
+
+static int normal_state(gpr_cmdline* cl, char* str) {
+ char* eq = nullptr;
+ char* tmp = nullptr;
+ char* arg_name = nullptr;
+ int r = 1;
+
+ if (0 == strcmp(str, "-help") || 0 == strcmp(str, "--help") ||
+ 0 == strcmp(str, "-h")) {
+ return print_usage_and_die(cl);
+ }
+
+ cl->cur_arg = nullptr;
+
+ if (str[0] == '-') {
+ if (str[1] == '-') {
+ if (str[2] == 0) {
+ /* handle '--' to move to just extra args */
+ cl->state = extra_state;
+ return 1;
+ }
+ str += 2;
+ } else {
+ str += 1;
+ }
+ /* first byte of str is now past the leading '-' or '--' */
+ if (str[0] == 'n' && str[1] == 'o' && str[2] == '-') {
+ /* str is of the form '--no-foo' - it's a flag disable */
+ str += 3;
+ cl->cur_arg = find_arg(cl, str);
+ if (cl->cur_arg == nullptr) {
+ return print_usage_and_die(cl);
+ }
+ if (cl->cur_arg->type != ARGTYPE_BOOL) {
+ fprintf(stderr, "%s is not a flag argument\n", str);
+ return print_usage_and_die(cl);
+ }
+ *(int*)cl->cur_arg->value = 0;
+ return 1; /* early out */
+ }
+ eq = strchr(str, '=');
+ if (eq != nullptr) {
+ /* copy the string into a temp buffer and extract the name */
+ tmp = arg_name = (char*)gpr_malloc((size_t)(eq - str + 1));
+ memcpy(arg_name, str, (size_t)(eq - str));
+ arg_name[eq - str] = 0;
+ } else {
+ arg_name = str;
+ }
+ cl->cur_arg = find_arg(cl, arg_name);
+ if (cl->cur_arg == nullptr) {
+ return print_usage_and_die(cl);
+ }
+ if (eq != nullptr) {
+ /* str was of the type --foo=value, parse the value */
+ r = value_state(cl, eq + 1);
+ } else if (cl->cur_arg->type != ARGTYPE_BOOL) {
+ /* flag types don't have a '--foo value' variant, other types do */
+ cl->state = value_state;
+ } else {
+ /* flag parameter: just set the value */
+ *(int*)cl->cur_arg->value = 1;
+ }
+ } else {
+ r = extra_state(cl, str);
+ }
+
+ gpr_free(tmp);
+ return r;
+}
+
+int gpr_cmdline_parse(gpr_cmdline* cl, int argc, char** argv) {
+ int i;
+
+ GPR_ASSERT(argc >= 1);
+ cl->argv0 = argv[0];
+
+ for (i = 1; i < argc; i++) {
+ if (!cl->state(cl, argv[i])) {
+ return 0;
+ }
+ }
+ return 1;
+}
diff --git a/test/core/util/cmdline.h b/test/core/util/cmdline.h
new file mode 100644
index 0000000000..3ae35d6e6a
--- /dev/null
+++ b/test/core/util/cmdline.h
@@ -0,0 +1,80 @@
+/*
+ *
+ * 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_UTIL_CMDLINE_H
+#define GRPC_TEST_CORE_UTIL_CMDLINE_H
+
+#include <grpc/support/port_platform.h>
+
+/** Simple command line parser.
+
+ Supports flags that can be specified as -foo, --foo, --no-foo, -no-foo, etc
+ And integers, strings that can be specified as -foo=4, -foo blah, etc
+
+ No support for short command line options (but we may get that in the
+ future.)
+
+ Usage (for a program with a single flag argument 'foo'):
+
+ int main(int argc, char **argv) {
+ gpr_cmdline *cl;
+ int verbose = 0;
+
+ cl = gpr_cmdline_create("My cool tool");
+ gpr_cmdline_add_int(cl, "verbose", "Produce verbose output?", &verbose);
+ gpr_cmdline_parse(cl, argc, argv);
+ gpr_cmdline_destroy(cl);
+
+ if (verbose) {
+ gpr_log(GPR_INFO, "Goodbye cruel world!");
+ }
+
+ return 0;
+ } */
+
+typedef struct gpr_cmdline gpr_cmdline;
+
+/** Construct a command line parser: takes a short description of the tool
+ doing the parsing */
+gpr_cmdline* gpr_cmdline_create(const char* description);
+/** Add an integer parameter, with a name (used on the command line) and some
+ helpful text (used in the command usage) */
+void gpr_cmdline_add_int(gpr_cmdline* cl, const char* name, const char* help,
+ int* value);
+/** The same, for a boolean flag */
+void gpr_cmdline_add_flag(gpr_cmdline* cl, const char* name, const char* help,
+ int* value);
+/** And for a string */
+void gpr_cmdline_add_string(gpr_cmdline* cl, const char* name, const char* help,
+ const char** value);
+/** Set a callback for non-named arguments */
+void gpr_cmdline_on_extra_arg(
+ gpr_cmdline* cl, const char* name, const char* help,
+ void (*on_extra_arg)(void* user_data, const char* arg), void* user_data);
+/** Enable surviving failure: default behavior is to exit the process */
+void gpr_cmdline_set_survive_failure(gpr_cmdline* cl);
+/** Parse the command line; returns 1 on success, on failure either dies
+ (by default) or returns 0 if gpr_cmdline_set_survive_failure() has been
+ called */
+int gpr_cmdline_parse(gpr_cmdline* cl, int argc, char** argv);
+/** Destroy the parser */
+void gpr_cmdline_destroy(gpr_cmdline* cl);
+/** Get a string describing usage */
+char* gpr_cmdline_usage_string(gpr_cmdline* cl, const char* argv0);
+
+#endif /* GRPC_TEST_CORE_UTIL_CMDLINE_H */
diff --git a/test/core/gpr/cmdline_test.cc b/test/core/util/cmdline_test.cc
index 172efda8a0..ed4412aa9f 100644
--- a/test/core/gpr/cmdline_test.cc
+++ b/test/core/util/cmdline_test.cc
@@ -16,13 +16,13 @@
*
*/
-#include <grpc/support/cmdline.h>
-
#include <string.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/useful.h>
+
+#include "test/core/util/cmdline.h"
#include "test/core/util/test_config.h"
#define LOG_TEST() gpr_log(GPR_INFO, "test at %s:%d", __FILE__, __LINE__)
diff --git a/test/core/util/subprocess.h b/test/core/util/subprocess.h
new file mode 100644
index 0000000000..c7fe9af435
--- /dev/null
+++ b/test/core/util/subprocess.h
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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_UTIL_SUBPROCESS_H
+#define GRPC_TEST_CORE_UTIL_SUBPROCESS_H
+
+#include <grpc/support/port_platform.h>
+
+typedef struct gpr_subprocess gpr_subprocess;
+
+/** .exe on windows, empty on unices */
+const char* gpr_subprocess_binary_extension();
+
+gpr_subprocess* gpr_subprocess_create(int argc, const char** argv);
+/** if subprocess has not been joined, kill it */
+void gpr_subprocess_destroy(gpr_subprocess* p);
+/** returns exit status; can be called at most once */
+int gpr_subprocess_join(gpr_subprocess* p);
+void gpr_subprocess_interrupt(gpr_subprocess* p);
+
+#endif /* GRPC_TEST_CORE_UTIL_SUBPROCESS_H */
diff --git a/test/core/util/subprocess_posix.cc b/test/core/util/subprocess_posix.cc
new file mode 100644
index 0000000000..0f6c99731f
--- /dev/null
+++ b/test/core/util/subprocess_posix.cc
@@ -0,0 +1,99 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include <grpc/support/port_platform.h>
+
+#ifdef GPR_POSIX_SUBPROCESS
+
+#include <assert.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+
+#include "test/core/util/subprocess.h"
+
+struct gpr_subprocess {
+ int pid;
+ bool joined;
+};
+
+const char* gpr_subprocess_binary_extension() { return ""; }
+
+gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) {
+ gpr_subprocess* r;
+ int pid;
+ char** exec_args;
+
+ pid = fork();
+ if (pid == -1) {
+ return nullptr;
+ } else if (pid == 0) {
+ exec_args = (char**)gpr_malloc(((size_t)argc + 1) * sizeof(char*));
+ memcpy(exec_args, argv, (size_t)argc * sizeof(char*));
+ exec_args[argc] = nullptr;
+ execv(exec_args[0], exec_args);
+ /* if we reach here, an error has occurred */
+ gpr_log(GPR_ERROR, "execv '%s' failed: %s", exec_args[0], strerror(errno));
+ _exit(1);
+ return nullptr;
+ } else {
+ r = (gpr_subprocess*)gpr_zalloc(sizeof(gpr_subprocess));
+ r->pid = pid;
+ return r;
+ }
+}
+
+void gpr_subprocess_destroy(gpr_subprocess* p) {
+ if (!p->joined) {
+ kill(p->pid, SIGKILL);
+ gpr_subprocess_join(p);
+ }
+ gpr_free(p);
+}
+
+int gpr_subprocess_join(gpr_subprocess* p) {
+ int status;
+retry:
+ if (waitpid(p->pid, &status, 0) == -1) {
+ if (errno == EINTR) {
+ goto retry;
+ }
+ gpr_log(GPR_ERROR, "waitpid failed for pid %d: %s", p->pid,
+ strerror(errno));
+ return -1;
+ }
+ p->joined = true;
+ return status;
+}
+
+void gpr_subprocess_interrupt(gpr_subprocess* p) {
+ if (!p->joined) {
+ kill(p->pid, SIGINT);
+ }
+}
+
+#endif /* GPR_POSIX_SUBPROCESS */
diff --git a/test/core/util/subprocess_windows.cc b/test/core/util/subprocess_windows.cc
new file mode 100644
index 0000000000..d3295244ea
--- /dev/null
+++ b/test/core/util/subprocess_windows.cc
@@ -0,0 +1,126 @@
+/*
+ *
+ * Copyright 2016 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 <grpc/support/port_platform.h>
+
+#ifdef GPR_WINDOWS_SUBPROCESS
+
+#include <string.h>
+#include <tchar.h>
+#include <windows.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include "src/core/lib/gpr/string.h"
+#include "src/core/lib/gpr/string_windows.h"
+#include "test/core/util/subprocess.h"
+
+struct gpr_subprocess {
+ PROCESS_INFORMATION pi;
+ int joined;
+ int interrupted;
+};
+
+const char* gpr_subprocess_binary_extension() { return ".exe"; }
+
+gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) {
+ gpr_subprocess* r;
+
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+
+ char* args = gpr_strjoin_sep(argv, (size_t)argc, " ", NULL);
+ TCHAR* args_tchar;
+
+ args_tchar = gpr_char_to_tchar(args);
+ gpr_free(args);
+
+ memset(&si, 0, sizeof(si));
+ si.cb = sizeof(si);
+ memset(&pi, 0, sizeof(pi));
+
+ if (!CreateProcess(NULL, args_tchar, NULL, NULL, FALSE,
+ CREATE_NEW_PROCESS_GROUP, NULL, NULL, &si, &pi)) {
+ gpr_free(args_tchar);
+ return NULL;
+ }
+ gpr_free(args_tchar);
+
+ r = (gpr_subprocess*)gpr_malloc(sizeof(gpr_subprocess));
+ memset(r, 0, sizeof(*r));
+ r->pi = pi;
+ return r;
+}
+
+void gpr_subprocess_destroy(gpr_subprocess* p) {
+ if (p) {
+ if (!p->joined) {
+ gpr_subprocess_interrupt(p);
+ gpr_subprocess_join(p);
+ }
+ if (p->pi.hProcess) {
+ CloseHandle(p->pi.hProcess);
+ }
+ if (p->pi.hThread) {
+ CloseHandle(p->pi.hThread);
+ }
+ gpr_free(p);
+ }
+}
+
+int gpr_subprocess_join(gpr_subprocess* p) {
+ DWORD dwExitCode;
+ if (GetExitCodeProcess(p->pi.hProcess, &dwExitCode)) {
+ if (dwExitCode == STILL_ACTIVE) {
+ if (WaitForSingleObject(p->pi.hProcess, INFINITE) == WAIT_OBJECT_0) {
+ p->joined = 1;
+ goto getExitCode;
+ }
+ return -1; // failed to join
+ } else {
+ goto getExitCode;
+ }
+ } else {
+ return -1; // failed to get exit code
+ }
+
+getExitCode:
+ if (p->interrupted) {
+ return 0;
+ }
+ if (GetExitCodeProcess(p->pi.hProcess, &dwExitCode)) {
+ return (int)dwExitCode;
+ } else {
+ return -1; // failed to get exit code
+ }
+}
+
+void gpr_subprocess_interrupt(gpr_subprocess* p) {
+ DWORD dwExitCode;
+ if (GetExitCodeProcess(p->pi.hProcess, &dwExitCode)) {
+ if (dwExitCode == STILL_ACTIVE) {
+ gpr_log(GPR_INFO, "sending ctrl-break");
+ GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, p->pi.dwProcessId);
+ p->joined = 1;
+ p->interrupted = 1;
+ }
+ }
+ return;
+}
+
+#endif /* GPR_WINDOWS_SUBPROCESS */
diff --git a/test/cpp/client/client_channel_stress_test.cc b/test/cpp/client/client_channel_stress_test.cc
index 80d1583333..bb8553f56a 100644
--- a/test/cpp/client/client_channel_stress_test.cc
+++ b/test/cpp/client/client_channel_stress_test.cc
@@ -36,6 +36,7 @@
#include <grpc/support/time.h>
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
+#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "test/core/util/port.h"
@@ -230,8 +231,7 @@ class ClientChannelStressTest {
}
grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses);
grpc_channel_args fake_result = {1, &fake_addresses};
- grpc_fake_resolver_response_generator_set_response(response_generator_,
- &fake_result);
+ response_generator_->SetResponse(&fake_result);
grpc_lb_addresses_destroy(addresses);
}
@@ -253,9 +253,10 @@ class ClientChannelStressTest {
void CreateStub() {
ChannelArguments args;
- response_generator_ = grpc_fake_resolver_response_generator_create();
+ response_generator_ =
+ grpc_core::MakeRefCounted<grpc_core::FakeResolverResponseGenerator>();
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
- response_generator_);
+ response_generator_.get());
std::ostringstream uri;
uri << "fake:///servername_not_used";
channel_ =
@@ -298,7 +299,6 @@ class ClientChannelStressTest {
for (size_t i = 0; i < backends_.size(); ++i) {
backend_servers_[i].Shutdown();
}
- grpc_fake_resolver_response_generator_unref(response_generator_);
}
std::atomic_bool shutdown_{false};
@@ -310,7 +310,8 @@ class ClientChannelStressTest {
std::vector<std::unique_ptr<BalancerServiceImpl>> balancers_;
std::vector<ServerThread<BackendServiceImpl>> backend_servers_;
std::vector<ServerThread<BalancerServiceImpl>> balancer_servers_;
- grpc_fake_resolver_response_generator* response_generator_;
+ grpc_core::RefCountedPtr<grpc_core::FakeResolverResponseGenerator>
+ response_generator_;
std::vector<std::thread> client_threads_;
};
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 44cd81a6a4..482f0cb24f 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -32,9 +32,9 @@
#include <grpc/support/log.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>
-#include <grpc/support/tls.h>
#include "src/core/lib/gpr/env.h"
+#include "src/core/lib/gpr/tls.h"
#include "src/core/lib/iomgr/port.h"
#include "src/proto/grpc/health/v1/health.grpc.pb.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc
index ee5adbc6fa..386d18e95d 100644
--- a/test/cpp/end2end/client_lb_end2end_test.cc
+++ b/test/cpp/end2end/client_lb_end2end_test.cc
@@ -40,6 +40,7 @@
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/debug_location.h"
+#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"
@@ -119,11 +120,11 @@ class ClientLbEnd2endTest : public ::testing::Test {
}
void SetUp() override {
- response_generator_ = grpc_fake_resolver_response_generator_create();
+ response_generator_ =
+ grpc_core::MakeRefCounted<grpc_core::FakeResolverResponseGenerator>();
}
void TearDown() override {
- grpc_fake_resolver_response_generator_unref(response_generator_);
for (size_t i = 0; i < servers_.size(); ++i) {
servers_[i]->Shutdown();
}
@@ -153,13 +154,9 @@ class ClientLbEnd2endTest : public ::testing::Test {
grpc_uri_destroy(lb_uri);
gpr_free(lb_uri_str);
}
- const grpc_arg fake_addresses =
- grpc_lb_addresses_create_channel_arg(addresses);
- grpc_channel_args* fake_result =
- grpc_channel_args_copy_and_add(nullptr, &fake_addresses, 1);
- grpc_fake_resolver_response_generator_set_response(response_generator_,
- fake_result);
- grpc_channel_args_destroy(fake_result);
+ grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses);
+ grpc_channel_args fake_result = {1, &fake_addresses};
+ response_generator_->SetResponse(&fake_result);
grpc_lb_addresses_destroy(addresses);
}
@@ -178,13 +175,9 @@ class ClientLbEnd2endTest : public ::testing::Test {
grpc_uri_destroy(lb_uri);
gpr_free(lb_uri_str);
}
- const grpc_arg fake_addresses =
- grpc_lb_addresses_create_channel_arg(addresses);
- grpc_channel_args* fake_result =
- grpc_channel_args_copy_and_add(nullptr, &fake_addresses, 1);
- grpc_fake_resolver_response_generator_set_response_upon_error(
- response_generator_, fake_result);
- grpc_channel_args_destroy(fake_result);
+ grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses);
+ grpc_channel_args fake_result = {1, &fake_addresses};
+ response_generator_->SetReresolutionResponse(&fake_result);
grpc_lb_addresses_destroy(addresses);
}
@@ -206,7 +199,7 @@ class ClientLbEnd2endTest : public ::testing::Test {
args.SetLoadBalancingPolicyName(lb_policy_name);
} // else, default to pick first
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
- response_generator_);
+ response_generator_.get());
return CreateCustomChannel("fake:///", InsecureChannelCredentials(), args);
}
@@ -323,7 +316,8 @@ class ClientLbEnd2endTest : public ::testing::Test {
const grpc::string server_host_;
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
std::vector<std::unique_ptr<ServerData>> servers_;
- grpc_fake_resolver_response_generator* response_generator_;
+ grpc_core::RefCountedPtr<grpc_core::FakeResolverResponseGenerator>
+ response_generator_;
const grpc::string kRequestMessage_;
};
diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc
index 5591acf880..89c9c2bf76 100644
--- a/test/cpp/end2end/grpclb_end2end_test.cc
+++ b/test/cpp/end2end/grpclb_end2end_test.cc
@@ -35,6 +35,7 @@
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/lib/gpr/env.h"
+#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "test/core/util/port.h"
@@ -339,7 +340,8 @@ class GrpclbEnd2endTest : public ::testing::Test {
}
void SetUp() override {
- response_generator_ = grpc_fake_resolver_response_generator_create();
+ response_generator_ =
+ grpc_core::MakeRefCounted<grpc_core::FakeResolverResponseGenerator>();
// Start the backends.
for (size_t i = 0; i < num_backends_; ++i) {
backends_.emplace_back(new BackendServiceImpl());
@@ -363,7 +365,6 @@ class GrpclbEnd2endTest : public ::testing::Test {
for (size_t i = 0; i < balancers_.size(); ++i) {
if (balancers_[i]->Shutdown()) balancer_servers_[i].Shutdown();
}
- grpc_fake_resolver_response_generator_unref(response_generator_);
}
void SetNextResolutionAllBalancers() {
@@ -378,7 +379,7 @@ class GrpclbEnd2endTest : public ::testing::Test {
ChannelArguments args;
args.SetGrpclbFallbackTimeout(fallback_timeout);
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
- response_generator_);
+ response_generator_.get());
std::ostringstream uri;
uri << "fake:///servername_not_used";
channel_ =
@@ -478,20 +479,18 @@ class GrpclbEnd2endTest : public ::testing::Test {
CreateLbAddressesFromAddressDataList(address_data);
grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses);
grpc_channel_args fake_result = {1, &fake_addresses};
- grpc_fake_resolver_response_generator_set_response(response_generator_,
- &fake_result);
+ response_generator_->SetResponse(&fake_result);
grpc_lb_addresses_destroy(addresses);
}
- void SetNextResolutionUponError(
+ void SetNextReresolutionResponse(
const std::vector<AddressData>& address_data) {
grpc_core::ExecCtx exec_ctx;
grpc_lb_addresses* addresses =
CreateLbAddressesFromAddressDataList(address_data);
grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses);
grpc_channel_args fake_result = {1, &fake_addresses};
- grpc_fake_resolver_response_generator_set_response_upon_error(
- response_generator_, &fake_result);
+ response_generator_->SetReresolutionResponse(&fake_result);
grpc_lb_addresses_destroy(addresses);
}
@@ -593,7 +592,8 @@ class GrpclbEnd2endTest : public ::testing::Test {
std::vector<std::unique_ptr<BalancerServiceImpl>> balancers_;
std::vector<ServerThread<BackendService>> backend_servers_;
std::vector<ServerThread<BalancerService>> balancer_servers_;
- grpc_fake_resolver_response_generator* response_generator_;
+ grpc_core::RefCountedPtr<grpc_core::FakeResolverResponseGenerator>
+ response_generator_;
const grpc::string kRequestMessage_ = "Live long and prosper.";
};
diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc
index 4a9fd7ce76..06ab8c3ff8 100644
--- a/test/cpp/grpclb/grpclb_test.cc
+++ b/test/cpp/grpclb/grpclb_test.cc
@@ -43,6 +43,7 @@
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
+#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "src/core/lib/surface/channel.h"
@@ -558,8 +559,8 @@ static void setup_client(const server_fixture* lb_server,
const char* backends_name = lb_server->servers_hostport;
gpr_asprintf(&expected_target_names, "%s;%s", backends_name, BALANCERS_NAME);
- grpc_fake_resolver_response_generator* response_generator =
- grpc_fake_resolver_response_generator_create();
+ auto response_generator =
+ grpc_core::MakeRefCounted<grpc_core::FakeResolverResponseGenerator>();
grpc_lb_addresses* addresses = grpc_lb_addresses_create(1, nullptr);
char* lb_uri_str;
@@ -578,25 +579,22 @@ static void setup_client(const server_fixture* lb_server,
grpc_channel_args_copy_and_add(nullptr, &fake_addresses, 1);
grpc_lb_addresses_destroy(addresses);
- const grpc_arg new_args[] = {
+ grpc_arg new_args[] = {
grpc_fake_transport_expected_targets_arg(expected_target_names),
- grpc_fake_resolver_response_generator_arg(response_generator)};
+ grpc_core::FakeResolverResponseGenerator::MakeChannelArg(
+ response_generator.get())};
- grpc_channel_args* args = grpc_channel_args_copy_and_add(
- nullptr, new_args, GPR_ARRAY_SIZE(new_args));
- gpr_free(expected_target_names);
+ grpc_channel_args args = {GPR_ARRAY_SIZE(new_args), new_args};
cf->cq = grpc_completion_queue_create_for_next(nullptr);
grpc_channel_credentials* fake_creds =
grpc_fake_transport_security_credentials_create();
cf->client =
- grpc_secure_channel_create(fake_creds, cf->server_uri, args, nullptr);
- grpc_fake_resolver_response_generator_set_response(response_generator,
- fake_result);
+ grpc_secure_channel_create(fake_creds, cf->server_uri, &args, nullptr);
+ response_generator->SetResponse(fake_result);
grpc_channel_args_destroy(fake_result);
grpc_channel_credentials_unref(fake_creds);
- grpc_channel_args_destroy(args);
- grpc_fake_resolver_response_generator_unref(response_generator);
+ gpr_free(expected_target_names);
}
static void teardown_client(client_fixture* cf) {
diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc
index aad2fa5f75..f4be064305 100644
--- a/test/cpp/naming/resolver_component_test.cc
+++ b/test/cpp/naming/resolver_component_test.cc
@@ -39,6 +39,7 @@
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
+#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
@@ -61,11 +62,9 @@ using namespace gflags;
DEFINE_string(target_name, "", "Target name to resolve.");
DEFINE_string(expected_addrs, "",
- "Comma-separated list of expected "
- "'<ip0:port0>,<is_balancer0>;<ip1:port1>,<is_balancer1>;...' "
- "addresses of "
- "backend and/or balancers. 'is_balancer' should be bool, i.e. "
- "true or false.");
+ "List of expected backend or balancer addresses in the form "
+ "'<ip0:port0>,<is_balancer0>;<ip1:port1>,<is_balancer1>;...'. "
+ "'is_balancer' should be bool, i.e. true or false.");
DEFINE_string(expected_chosen_service_config, "",
"Expected service config json string that gets chosen (no "
"whitespace). Empty for none.");
@@ -102,12 +101,10 @@ vector<GrpcLBAddress> ParseExpectedAddrs(std::string expected_addrs) {
// get the next <ip>,<port> (v4 or v6)
size_t next_comma = expected_addrs.find(",");
if (next_comma == std::string::npos) {
- gpr_log(
- GPR_ERROR,
- "Missing ','. Expected_addrs arg should be a semi-colon-separated "
- "list of "
- "<ip-port>,<bool> pairs. Left-to-be-parsed arg is |%s|",
- expected_addrs.c_str());
+ gpr_log(GPR_ERROR,
+ "Missing ','. Expected_addrs arg should be a semicolon-separated "
+ "list of <ip-port>,<bool> pairs. Left-to-be-parsed arg is |%s|",
+ expected_addrs.c_str());
abort();
}
std::string next_addr = expected_addrs.substr(0, next_comma);
@@ -125,7 +122,7 @@ vector<GrpcLBAddress> ParseExpectedAddrs(std::string expected_addrs) {
}
if (out.size() == 0) {
gpr_log(GPR_ERROR,
- "expected_addrs arg should be a comma-separated list of "
+ "expected_addrs arg should be a semicolon-separated list of "
"<ip-port>,<bool> pairs");
abort();
}
@@ -287,17 +284,16 @@ TEST(ResolverComponentTest, TestResolvesRelevantRecords) {
FLAGS_local_dns_server_address.c_str(),
FLAGS_target_name.c_str()));
// create resolver and resolve
- grpc_resolver* resolver =
- grpc_resolver_create(whole_uri, nullptr, args.pollset_set, args.lock);
+ grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
+ grpc_core::ResolverRegistry::CreateResolver(whole_uri, nullptr,
+ args.pollset_set, args.lock);
gpr_free(whole_uri);
grpc_closure on_resolver_result_changed;
GRPC_CLOSURE_INIT(&on_resolver_result_changed, CheckResolverResultLocked,
(void*)&args, grpc_combiner_scheduler(args.lock));
- grpc_resolver_next_locked(resolver, &args.channel_args,
- &on_resolver_result_changed);
+ resolver->NextLocked(&args.channel_args, &on_resolver_result_changed);
grpc_core::ExecCtx::Get()->Flush();
PollPollsetUntilRequestDone(&args);
- GRPC_RESOLVER_UNREF(resolver, nullptr);
ArgsFinish(&args);
}
diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD
index af25fca185..d092ba348e 100644
--- a/test/cpp/util/BUILD
+++ b/test/cpp/util/BUILD
@@ -74,6 +74,7 @@ grpc_cc_library(
deps = [
"//:grpc++",
"//test/core/end2end:ssl_test_data",
+ "//test/core/util:grpc_test_util",
],
external_deps = [
"protobuf",
@@ -86,6 +87,7 @@ grpc_cc_library(
hdrs = GRPCXX_TESTUTIL_HDRS,
deps = [
"//:grpc++_unsecure",
+ "//test/core/util:grpc_test_util",
],
external_deps = [
"protobuf",
diff --git a/test/cpp/util/subprocess.cc b/test/cpp/util/subprocess.cc
index a54d0c087a..ddaad89805 100644
--- a/test/cpp/util/subprocess.cc
+++ b/test/cpp/util/subprocess.cc
@@ -20,7 +20,7 @@
#include <vector>
-#include <grpc/support/subprocess.h>
+#include "test/core/util/subprocess.h"
namespace grpc {