From fdae4bdea50d64a0ccde08ff39e1f3b20c5d89a9 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Mon, 7 Nov 2016 17:46:16 -0800 Subject: [PATCH 1/2] Add env variable GRPC_DNS_RESOLVER --- build.yaml | 1 + .../resolver/dns/c_ares/dns_resolver_ares.c | 7 ++++- .../ext/resolver/dns/native/dns_resolver.c | 8 +++++- .../plugin_registry/grpc_plugin_registry.c | 4 +++ .../grpc_unsecure_plugin_registry.c | 4 +++ tools/run_tests/run_tests.py | 3 +++ tools/run_tests/run_tests_matrix.py | 27 +++++++++++++++---- 7 files changed, 47 insertions(+), 7 deletions(-) diff --git a/build.yaml b/build.yaml index 99fb2d87bc9..32483d1314b 100644 --- a/build.yaml +++ b/build.yaml @@ -476,6 +476,7 @@ filegroups: - name: grpc_resolver_dns_native src: - src/core/ext/resolver/dns/native/dns_resolver.c + plugin: grpc_resolver_dns_native uses: - grpc_base - grpc_client_channel diff --git a/src/core/ext/resolver/dns/c_ares/dns_resolver_ares.c b/src/core/ext/resolver/dns/c_ares/dns_resolver_ares.c index b90f3bae5c2..90a302396c3 100644 --- a/src/core/ext/resolver/dns/c_ares/dns_resolver_ares.c +++ b/src/core/ext/resolver/dns/c_ares/dns_resolver_ares.c @@ -47,6 +47,7 @@ #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/support/backoff.h" +#include "src/core/lib/support/env.h" #include "src/core/lib/support/string.h" #define BACKOFF_MULTIPLIER 1.6 @@ -339,7 +340,11 @@ static grpc_resolver_factory *dns_ares_resolver_factory_create() { } void grpc_resolver_dns_ares_init(void) { - grpc_register_resolver_type(dns_ares_resolver_factory_create()); + char *resolver = gpr_getenv("GRPC_DNS_RESOLVER"); + if (resolver == NULL || gpr_stricmp(resolver, "ares") == 0) { + grpc_register_resolver_type(dns_ares_resolver_factory_create()); + } + gpr_free(resolver); } void grpc_resolver_dns_ares_shutdown(void) {} diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 958b8af8b28..de8552edd82 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -44,6 +44,7 @@ #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/support/backoff.h" +#include "src/core/lib/support/env.h" #include "src/core/lib/support/string.h" #define BACKOFF_MULTIPLIER 1.6 @@ -304,7 +305,12 @@ static grpc_resolver_factory *dns_resolver_factory_create() { } void grpc_resolver_dns_native_init(void) { - grpc_register_resolver_type(dns_resolver_factory_create()); + char *resolver = gpr_getenv("GRPC_DNS_RESOLVER"); + if (resolver != NULL && gpr_stricmp(resolver, "native") == 0) { + gpr_log(GPR_DEBUG, "Using native dns resolver"); + grpc_register_resolver_type(dns_resolver_factory_create()); + } + gpr_free(resolver); } void grpc_resolver_dns_native_shutdown(void) {} diff --git a/src/core/plugin_registry/grpc_plugin_registry.c b/src/core/plugin_registry/grpc_plugin_registry.c index ba03ed865b5..596e3b7114f 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.c +++ b/src/core/plugin_registry/grpc_plugin_registry.c @@ -45,6 +45,8 @@ extern void grpc_lb_policy_round_robin_init(void); extern void grpc_lb_policy_round_robin_shutdown(void); extern void grpc_resolver_dns_ares_init(void); extern void grpc_resolver_dns_ares_shutdown(void); +extern void grpc_resolver_dns_native_init(void); +extern void grpc_resolver_dns_native_shutdown(void); extern void grpc_resolver_sockaddr_init(void); extern void grpc_resolver_sockaddr_shutdown(void); extern void grpc_load_reporting_plugin_init(void); @@ -65,6 +67,8 @@ void grpc_register_built_in_plugins(void) { grpc_lb_policy_round_robin_shutdown); grpc_register_plugin(grpc_resolver_dns_ares_init, grpc_resolver_dns_ares_shutdown); + grpc_register_plugin(grpc_resolver_dns_native_init, + grpc_resolver_dns_native_shutdown); grpc_register_plugin(grpc_resolver_sockaddr_init, grpc_resolver_sockaddr_shutdown); grpc_register_plugin(grpc_load_reporting_plugin_init, diff --git a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c index 1052253250b..a05ebcb3af2 100644 --- a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c +++ b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c @@ -39,6 +39,8 @@ extern void grpc_client_channel_init(void); extern void grpc_client_channel_shutdown(void); extern void grpc_resolver_dns_ares_init(void); extern void grpc_resolver_dns_ares_shutdown(void); +extern void grpc_resolver_dns_native_init(void); +extern void grpc_resolver_dns_native_shutdown(void); extern void grpc_resolver_sockaddr_init(void); extern void grpc_resolver_sockaddr_shutdown(void); extern void grpc_load_reporting_plugin_init(void); @@ -59,6 +61,8 @@ void grpc_register_built_in_plugins(void) { grpc_client_channel_shutdown); grpc_register_plugin(grpc_resolver_dns_ares_init, grpc_resolver_dns_ares_shutdown); + grpc_register_plugin(grpc_resolver_dns_native_init, + grpc_resolver_dns_native_shutdown); grpc_register_plugin(grpc_resolver_sockaddr_init, grpc_resolver_sockaddr_shutdown); grpc_register_plugin(grpc_load_reporting_plugin_init, diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 05f819bd9bb..d1b8733ed55 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -230,6 +230,9 @@ class CLanguage(object): _ROOT + '/src/core/lib/tsi/test_creds/ca.pem', 'GRPC_POLL_STRATEGY': polling_strategy, 'GRPC_VERBOSITY': 'DEBUG'} + resolver = os.environ.get('GRPC_DNS_RESOLVER', None); + if resolver: + env['GRPC_DNS_RESOLVER'] = resolver shortname_ext = '' if polling_strategy=='all' else ' GRPC_POLL_STRATEGY=%s' % polling_strategy if self.config.build_config in target['exclude_configs']: continue diff --git a/tools/run_tests/run_tests_matrix.py b/tools/run_tests/run_tests_matrix.py index 41db67cdb58..260e0eee618 100755 --- a/tools/run_tests/run_tests_matrix.py +++ b/tools/run_tests/run_tests_matrix.py @@ -49,7 +49,8 @@ _RUNTESTS_TIMEOUT = 4*60*60 _DEFAULT_INNER_JOBS = 2 -def _docker_jobspec(name, runtests_args=[], inner_jobs=_DEFAULT_INNER_JOBS): +def _docker_jobspec(name, runtests_args=[], runtests_envs={}, + inner_jobs=_DEFAULT_INNER_JOBS): """Run a single instance of run_tests.py in a docker container""" test_job = jobset.JobSpec( cmdline=['python', 'tools/run_tests/run_tests.py', @@ -58,16 +59,19 @@ def _docker_jobspec(name, runtests_args=[], inner_jobs=_DEFAULT_INNER_JOBS): '-j', str(inner_jobs), '-x', 'report_%s.xml' % name, '--report_suite_name', '%s' % name] + runtests_args, + environ=runtests_envs, shortname='run_tests_%s' % name, timeout_seconds=_RUNTESTS_TIMEOUT) return test_job -def _workspace_jobspec(name, runtests_args=[], workspace_name=None, inner_jobs=_DEFAULT_INNER_JOBS): +def _workspace_jobspec(name, runtests_args=[], workspace_name=None, + runtests_envs={}, inner_jobs=_DEFAULT_INNER_JOBS): """Run a single instance of run_tests.py in a separate workspace""" if not workspace_name: workspace_name = 'workspace_%s' % name env = {'WORKSPACE_NAME': workspace_name} + env.update(runtests_envs) test_job = jobset.JobSpec( cmdline=['tools/run_tests/run_tests_in_workspace.sh', '-t', @@ -82,7 +86,7 @@ def _workspace_jobspec(name, runtests_args=[], workspace_name=None, inner_jobs=_ def _generate_jobs(languages, configs, platforms, arch=None, compiler=None, - labels=[], extra_args=[], + labels=[], extra_args=[], extra_envs={}, inner_jobs=_DEFAULT_INNER_JOBS): result = [] for language in languages: @@ -95,12 +99,16 @@ def _generate_jobs(languages, configs, platforms, name += '_%s_%s' % (arch, compiler) runtests_args += ['--arch', arch, '--compiler', compiler] + for extra_env in extra_envs: + name += '_%s=%s' % (extra_env, extra_envs[extra_env]) runtests_args += extra_args if platform == 'linux': - job = _docker_jobspec(name=name, runtests_args=runtests_args, inner_jobs=inner_jobs) + job = _docker_jobspec(name=name, runtests_args=runtests_args, + runtests_envs=extra_envs, inner_jobs=inner_jobs) else: - job = _workspace_jobspec(name=name, runtests_args=runtests_args, inner_jobs=inner_jobs) + job = _workspace_jobspec(name=name, runtests_args=runtests_args, + runtests_envs=extra_envs, inner_jobs=inner_jobs) job.labels = [platform, config, language] + labels result.append(job) @@ -212,6 +220,15 @@ def _create_portability_test_jobs(extra_args=[], inner_jobs=_DEFAULT_INNER_JOBS) extra_args=extra_args, inner_jobs=inner_jobs) + # Test c and C++ with the native DNS resolver + test_jobs += _generate_jobs(languages=['c', 'c++'], + configs=['dbg'], platforms=['linux', 'windows'], + arch='default', + compiler='default', + labels=['portability'], + extra_args=extra_args, + extra_envs={'GRPC_DNS_RESOLVER': 'native'}) + test_jobs += _generate_jobs(languages=['python'], configs=['dbg'], platforms=['linux'], From 87b5910345fba4b63be3314d59ed631832a8ed29 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Tue, 8 Nov 2016 10:50:12 -0800 Subject: [PATCH 2/2] Remove C++ native resolver test on windows --- tools/run_tests/run_tests_matrix.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/run_tests/run_tests_matrix.py b/tools/run_tests/run_tests_matrix.py index 260e0eee618..154b4f1ba52 100755 --- a/tools/run_tests/run_tests_matrix.py +++ b/tools/run_tests/run_tests_matrix.py @@ -100,7 +100,7 @@ def _generate_jobs(languages, configs, platforms, runtests_args += ['--arch', arch, '--compiler', compiler] for extra_env in extra_envs: - name += '_%s=%s' % (extra_env, extra_envs[extra_env]) + name += '_%s_%s' % (extra_env, extra_envs[extra_env]) runtests_args += extra_args if platform == 'linux': @@ -220,11 +220,16 @@ def _create_portability_test_jobs(extra_args=[], inner_jobs=_DEFAULT_INNER_JOBS) extra_args=extra_args, inner_jobs=inner_jobs) - # Test c and C++ with the native DNS resolver + # C and C++ with the native DNS resolver on Linux test_jobs += _generate_jobs(languages=['c', 'c++'], - configs=['dbg'], platforms=['linux', 'windows'], - arch='default', - compiler='default', + configs=['dbg'], platforms=['linux'], + labels=['portability'], + extra_args=extra_args, + extra_envs={'GRPC_DNS_RESOLVER': 'native'}) + + # C with the native DNS resolver on Windonws + test_jobs += _generate_jobs(languages=['c'], + configs=['dbg'], platforms=['windows'], labels=['portability'], extra_args=extra_args, extra_envs={'GRPC_DNS_RESOLVER': 'native'})