diff options
Diffstat (limited to 'test/core')
-rwxr-xr-x | test/core/end2end/generate_tests.bzl | 564 | ||||
-rw-r--r-- | test/core/iomgr/BUILD | 32 | ||||
-rw-r--r-- | test/core/iomgr/ev_epollsig_linux_test.cc | 321 | ||||
-rw-r--r-- | test/core/iomgr/pollset_set_test.cc | 447 | ||||
-rw-r--r-- | test/core/tsi/alts/fake_handshaker/BUILD | 5 | ||||
-rw-r--r-- | test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc | 31 | ||||
-rw-r--r-- | test/core/tsi/alts/fake_handshaker/fake_handshaker_server.h | 29 | ||||
-rw-r--r-- | test/core/tsi/alts/fake_handshaker/fake_handshaker_server_main.cc | 53 |
8 files changed, 410 insertions, 1072 deletions
diff --git a/test/core/end2end/generate_tests.bzl b/test/core/end2end/generate_tests.bzl index db2886d8e3..6d9ffcfb91 100755 --- a/test/core/end2end/generate_tests.bzl +++ b/test/core/end2end/generate_tests.bzl @@ -13,277 +13,347 @@ # See the License for the specific language governing permissions and # limitations under the License. -POLLERS = ['epollex', 'epollsig', 'epoll1', 'poll', 'poll-cv'] - -load("//bazel:grpc_build_system.bzl", "grpc_sh_test", "grpc_cc_binary", "grpc_cc_library") - """Generates the appropriate build.json data for all the end2end tests.""" +load("//bazel:grpc_build_system.bzl", "grpc_cc_binary", "grpc_cc_library") -def fixture_options(fullstack=True, includes_proxy=False, dns_resolver=True, - name_resolution=True, secure=True, tracing=False, - platforms=['windows', 'linux', 'mac', 'posix'], - is_inproc=False, is_http2=True, supports_proxy_auth=False, - supports_write_buffering=True, client_channel=True): - return struct( - fullstack=fullstack, - includes_proxy=includes_proxy, - dns_resolver=dns_resolver, - name_resolution=name_resolution, - secure=secure, - tracing=tracing, - is_inproc=is_inproc, - is_http2=is_http2, - supports_proxy_auth=supports_proxy_auth, - supports_write_buffering=supports_write_buffering, - client_channel=client_channel, - #platforms=platforms, - ) +POLLERS = ["epollex", "epoll1", "poll", "poll-cv"] +def _fixture_options( + fullstack = True, + includes_proxy = False, + dns_resolver = True, + name_resolution = True, + secure = True, + tracing = False, + _platforms = ["windows", "linux", "mac", "posix"], + is_inproc = False, + is_http2 = True, + supports_proxy_auth = False, + supports_write_buffering = True, + client_channel = True): + return struct( + fullstack = fullstack, + includes_proxy = includes_proxy, + dns_resolver = dns_resolver, + name_resolution = name_resolution, + secure = secure, + tracing = tracing, + is_inproc = is_inproc, + is_http2 = is_http2, + supports_proxy_auth = supports_proxy_auth, + supports_write_buffering = supports_write_buffering, + client_channel = client_channel, + #_platforms=_platforms, + ) # maps fixture name to whether it requires the security library END2END_FIXTURES = { - 'h2_compress': fixture_options(), - 'h2_census': fixture_options(), + "h2_compress": _fixture_options(), + "h2_census": _fixture_options(), # TODO(juanlishen): This is disabled for now, but should be considered to re-enable once we have # decided how the load reporting service should be enabled. - #'h2_load_reporting': fixture_options(), - 'h2_fakesec': fixture_options(), - 'h2_fd': fixture_options(dns_resolver=False, fullstack=False, - client_channel=False, - platforms=['linux', 'mac', 'posix']), - 'h2_full': fixture_options(), - 'h2_full+pipe': fixture_options(platforms=['linux']), - 'h2_full+trace': fixture_options(tracing=True), - 'h2_full+workarounds': fixture_options(), - 'h2_http_proxy': fixture_options(supports_proxy_auth=True), - 'h2_oauth2': fixture_options(), - 'h2_proxy': fixture_options(includes_proxy=True), - 'h2_sockpair_1byte': fixture_options(fullstack=False, dns_resolver=False, - client_channel=False), - 'h2_sockpair': fixture_options(fullstack=False, dns_resolver=False, - client_channel=False), - 'h2_sockpair+trace': fixture_options(fullstack=False, dns_resolver=False, - tracing=True, client_channel=False), - 'h2_ssl': fixture_options(secure=True), - 'h2_local': fixture_options(secure=True, dns_resolver=False, platforms=['linux', 'mac', 'posix']), - 'h2_ssl_proxy': fixture_options(includes_proxy=True, secure=True), - 'h2_uds': fixture_options(dns_resolver=False, - platforms=['linux', 'mac', 'posix']), - 'inproc': fixture_options(fullstack=False, dns_resolver=False, - name_resolution=False, is_inproc=True, - is_http2=False, supports_write_buffering=False, - client_channel=False), + #'h2_load_reporting': _fixture_options(), + "h2_fakesec": _fixture_options(), + "h2_fd": _fixture_options( + dns_resolver = False, + fullstack = False, + client_channel = False, + _platforms = ["linux", "mac", "posix"], + ), + "h2_full": _fixture_options(), + "h2_full+pipe": _fixture_options(_platforms = ["linux"]), + "h2_full+trace": _fixture_options(tracing = True), + "h2_full+workarounds": _fixture_options(), + "h2_http_proxy": _fixture_options(supports_proxy_auth = True), + "h2_oauth2": _fixture_options(), + "h2_proxy": _fixture_options(includes_proxy = True), + "h2_sockpair_1byte": _fixture_options( + fullstack = False, + dns_resolver = False, + client_channel = False, + ), + "h2_sockpair": _fixture_options( + fullstack = False, + dns_resolver = False, + client_channel = False, + ), + "h2_sockpair+trace": _fixture_options( + fullstack = False, + dns_resolver = False, + tracing = True, + client_channel = False, + ), + "h2_ssl": _fixture_options(secure = True), + "h2_local": _fixture_options(secure = True, dns_resolver = False, _platforms = ["linux", "mac", "posix"]), + "h2_ssl_proxy": _fixture_options(includes_proxy = True, secure = True), + "h2_uds": _fixture_options( + dns_resolver = False, + _platforms = ["linux", "mac", "posix"], + ), + "inproc": _fixture_options( + fullstack = False, + dns_resolver = False, + name_resolution = False, + is_inproc = True, + is_http2 = False, + supports_write_buffering = False, + client_channel = False, + ), } - -def test_options(needs_fullstack=False, needs_dns=False, needs_names=False, - proxyable=True, secure=False, traceable=False, - exclude_inproc=False, needs_http2=False, - needs_proxy_auth=False, needs_write_buffering=False, - needs_client_channel=False): - return struct( - needs_fullstack=needs_fullstack, - needs_dns=needs_dns, - needs_names=needs_names, - proxyable=proxyable, - secure=secure, - traceable=traceable, - exclude_inproc=exclude_inproc, - needs_http2=needs_http2, - needs_proxy_auth=needs_proxy_auth, - needs_write_buffering=needs_write_buffering, - needs_client_channel=needs_client_channel, - ) - +def _test_options( + needs_fullstack = False, + needs_dns = False, + needs_names = False, + proxyable = True, + secure = False, + traceable = False, + exclude_inproc = False, + needs_http2 = False, + needs_proxy_auth = False, + needs_write_buffering = False, + needs_client_channel = False): + return struct( + needs_fullstack = needs_fullstack, + needs_dns = needs_dns, + needs_names = needs_names, + proxyable = proxyable, + secure = secure, + traceable = traceable, + exclude_inproc = exclude_inproc, + needs_http2 = needs_http2, + needs_proxy_auth = needs_proxy_auth, + needs_write_buffering = needs_write_buffering, + needs_client_channel = needs_client_channel, + ) # maps test names to options END2END_TESTS = { - 'bad_hostname': test_options(needs_names=True), - 'bad_ping': test_options(needs_fullstack=True,proxyable=False), - 'binary_metadata': test_options(), - 'resource_quota_server': test_options(proxyable=False), - 'call_creds': test_options(secure=True), - 'call_host_override': test_options(needs_fullstack=True, needs_dns=True, - needs_names=True), - 'cancel_after_accept': test_options(), - 'cancel_after_client_done': test_options(), - 'cancel_after_invoke': test_options(), - 'cancel_after_round_trip': test_options(), - 'cancel_before_invoke': test_options(), - 'cancel_in_a_vacuum': test_options(), - 'cancel_with_status': test_options(), - 'compressed_payload': test_options(proxyable=False, exclude_inproc=True), - 'connectivity': test_options(needs_fullstack=True, needs_names=True, - proxyable=False), - 'channelz': test_options(), - 'default_host': test_options(needs_fullstack=True, needs_dns=True, - needs_names=True), - 'disappearing_server': test_options(needs_fullstack=True,needs_names=True), - 'empty_batch': test_options(), - 'filter_causes_close': test_options(), - 'filter_call_init_fails': test_options(), - 'graceful_server_shutdown': test_options(exclude_inproc=True), - 'hpack_size': test_options(proxyable=False, traceable=False, - exclude_inproc=True), - 'high_initial_seqno': test_options(), - 'idempotent_request': test_options(), - 'invoke_large_request': test_options(), - 'keepalive_timeout': test_options(proxyable=False, needs_http2=True), - 'large_metadata': test_options(), - 'max_concurrent_streams': test_options(proxyable=False, - exclude_inproc=True), - 'max_connection_age': test_options(exclude_inproc=True), - 'max_connection_idle': test_options(needs_fullstack=True, proxyable=False), - 'max_message_length': test_options(), - 'negative_deadline': test_options(), - 'network_status_change': test_options(), - 'no_error_on_hotpath': test_options(proxyable=False), - 'no_logging': test_options(traceable=False), - 'no_op': test_options(), - 'payload': test_options(), + "bad_hostname": _test_options(needs_names = True), + "bad_ping": _test_options(needs_fullstack = True, proxyable = False), + "binary_metadata": _test_options(), + "resource_quota_server": _test_options(proxyable = False), + "call_creds": _test_options(secure = True), + "call_host_override": _test_options( + needs_fullstack = True, + needs_dns = True, + needs_names = True, + ), + "cancel_after_accept": _test_options(), + "cancel_after_client_done": _test_options(), + "cancel_after_invoke": _test_options(), + "cancel_after_round_trip": _test_options(), + "cancel_before_invoke": _test_options(), + "cancel_in_a_vacuum": _test_options(), + "cancel_with_status": _test_options(), + "compressed_payload": _test_options(proxyable = False, exclude_inproc = True), + "connectivity": _test_options( + needs_fullstack = True, + needs_names = True, + proxyable = False, + ), + "channelz": _test_options(), + "default_host": _test_options( + needs_fullstack = True, + needs_dns = True, + needs_names = True, + ), + "disappearing_server": _test_options(needs_fullstack = True, needs_names = True), + "empty_batch": _test_options(), + "filter_causes_close": _test_options(), + "filter_call_init_fails": _test_options(), + "graceful_server_shutdown": _test_options(exclude_inproc = True), + "hpack_size": _test_options( + proxyable = False, + traceable = False, + exclude_inproc = True, + ), + "high_initial_seqno": _test_options(), + "idempotent_request": _test_options(), + "invoke_large_request": _test_options(), + "keepalive_timeout": _test_options(proxyable = False, needs_http2 = True), + "large_metadata": _test_options(), + "max_concurrent_streams": _test_options( + proxyable = False, + exclude_inproc = True, + ), + "max_connection_age": _test_options(exclude_inproc = True), + "max_connection_idle": _test_options(needs_fullstack = True, proxyable = False), + "max_message_length": _test_options(), + "negative_deadline": _test_options(), + "network_status_change": _test_options(), + "no_error_on_hotpath": _test_options(proxyable = False), + "no_logging": _test_options(traceable = False), + "no_op": _test_options(), + "payload": _test_options(), # TODO(juanlishen): This is disabled for now because it depends on some generated functions in # end2end_tests.cc, which are not generated because they would depend on OpenCensus while # OpenCensus can only be built via Bazel so far. - # 'load_reporting_hook': test_options(), - 'ping_pong_streaming': test_options(), - 'ping': test_options(needs_fullstack=True, proxyable=False), - 'proxy_auth': test_options(needs_proxy_auth=True), - 'registered_call': test_options(), - 'request_with_flags': test_options(proxyable=False), - 'request_with_payload': test_options(), + # 'load_reporting_hook': _test_options(), + "ping_pong_streaming": _test_options(), + "ping": _test_options(needs_fullstack = True, proxyable = False), + "proxy_auth": _test_options(needs_proxy_auth = True), + "registered_call": _test_options(), + "request_with_flags": _test_options(proxyable = False), + "request_with_payload": _test_options(), # TODO(roth): Remove proxyable=False for all retry tests once we # have a way for the proxy to propagate the fact that trailing # metadata is available when initial metadata is returned. # See https://github.com/grpc/grpc/issues/14467 for context. - 'retry': test_options(needs_client_channel=True, proxyable=False), - 'retry_cancellation': test_options(needs_client_channel=True, - proxyable=False), - 'retry_disabled': test_options(needs_client_channel=True, proxyable=False), - 'retry_exceeds_buffer_size_in_initial_batch': test_options( - needs_client_channel=True, proxyable=False), - 'retry_exceeds_buffer_size_in_subsequent_batch': test_options( - needs_client_channel=True, proxyable=False), - 'retry_non_retriable_status': test_options(needs_client_channel=True, - proxyable=False), - 'retry_non_retriable_status_before_recv_trailing_metadata_started': - test_options(needs_client_channel=True, proxyable=False), - 'retry_recv_initial_metadata': test_options(needs_client_channel=True, - proxyable=False), - 'retry_recv_message': test_options(needs_client_channel=True, - proxyable=False), - 'retry_server_pushback_delay': test_options(needs_client_channel=True, - proxyable=False), - 'retry_server_pushback_disabled': test_options(needs_client_channel=True, - proxyable=False), - 'retry_streaming': test_options(needs_client_channel=True, proxyable=False), - 'retry_streaming_after_commit': test_options(needs_client_channel=True, - proxyable=False), - 'retry_streaming_succeeds_before_replay_finished': test_options( - needs_client_channel=True, proxyable=False), - 'retry_throttled': test_options(needs_client_channel=True, - proxyable=False), - 'retry_too_many_attempts': test_options(needs_client_channel=True, - proxyable=False), - 'server_finishes_request': test_options(), - 'shutdown_finishes_calls': test_options(), - 'shutdown_finishes_tags': test_options(), - 'simple_cacheable_request': test_options(), - 'simple_delayed_request': test_options(needs_fullstack=True), - 'simple_metadata': test_options(), - 'simple_request': test_options(), - 'streaming_error_response': test_options(), - 'stream_compression_compressed_payload': test_options(proxyable=False, - exclude_inproc=True), - 'stream_compression_payload': test_options(exclude_inproc=True), - 'stream_compression_ping_pong_streaming': test_options(exclude_inproc=True), - 'trailing_metadata': test_options(), - 'authority_not_supported': test_options(), - 'filter_latency': test_options(), - 'filter_status_code': test_options(), - 'workaround_cronet_compression': test_options(), - 'write_buffering': test_options(needs_write_buffering=True), - 'write_buffering_at_end': test_options(needs_write_buffering=True), + "retry": _test_options(needs_client_channel = True, proxyable = False), + "retry_cancellation": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_disabled": _test_options(needs_client_channel = True, proxyable = False), + "retry_exceeds_buffer_size_in_initial_batch": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_exceeds_buffer_size_in_subsequent_batch": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_non_retriable_status": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_non_retriable_status_before_recv_trailing_metadata_started": _test_options(needs_client_channel = True, proxyable = False), + "retry_recv_initial_metadata": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_recv_message": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_server_pushback_delay": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_server_pushback_disabled": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_streaming": _test_options(needs_client_channel = True, proxyable = False), + "retry_streaming_after_commit": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_streaming_succeeds_before_replay_finished": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_throttled": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "retry_too_many_attempts": _test_options( + needs_client_channel = True, + proxyable = False, + ), + "server_finishes_request": _test_options(), + "shutdown_finishes_calls": _test_options(), + "shutdown_finishes_tags": _test_options(), + "simple_cacheable_request": _test_options(), + "simple_delayed_request": _test_options(needs_fullstack = True), + "simple_metadata": _test_options(), + "simple_request": _test_options(), + "streaming_error_response": _test_options(), + "stream_compression_compressed_payload": _test_options( + proxyable = False, + exclude_inproc = True, + ), + "stream_compression_payload": _test_options(exclude_inproc = True), + "stream_compression_ping_pong_streaming": _test_options(exclude_inproc = True), + "trailing_metadata": _test_options(), + "authority_not_supported": _test_options(), + "filter_latency": _test_options(), + "filter_status_code": _test_options(), + "workaround_cronet_compression": _test_options(), + "write_buffering": _test_options(needs_write_buffering = True), + "write_buffering_at_end": _test_options(needs_write_buffering = True), } - -def compatible(fopt, topt): - if topt.needs_fullstack: - if not fopt.fullstack: - return False - if topt.needs_dns: - if not fopt.dns_resolver: - return False - if topt.needs_names: - if not fopt.name_resolution: - return False - if not topt.proxyable: - if fopt.includes_proxy: - return False - if not topt.traceable: - if fopt.tracing: - return False - if topt.exclude_inproc: - if fopt.is_inproc: - return False - if topt.needs_http2: - if not fopt.is_http2: - return False - if topt.needs_proxy_auth: - if not fopt.supports_proxy_auth: - return False - if topt.needs_write_buffering: - if not fopt.supports_write_buffering: - return False - if topt.needs_client_channel: - if not fopt.client_channel: - return False - return True - +def _compatible(fopt, topt): + if topt.needs_fullstack: + if not fopt.fullstack: + return False + if topt.needs_dns: + if not fopt.dns_resolver: + return False + if topt.needs_names: + if not fopt.name_resolution: + return False + if not topt.proxyable: + if fopt.includes_proxy: + return False + if not topt.traceable: + if fopt.tracing: + return False + if topt.exclude_inproc: + if fopt.is_inproc: + return False + if topt.needs_http2: + if not fopt.is_http2: + return False + if topt.needs_proxy_auth: + if not fopt.supports_proxy_auth: + return False + if topt.needs_write_buffering: + if not fopt.supports_write_buffering: + return False + if topt.needs_client_channel: + if not fopt.client_channel: + return False + return True def grpc_end2end_tests(): - grpc_cc_library( - name = 'end2end_tests', - srcs = ['end2end_tests.cc', 'end2end_test_utils.cc'] + [ - 'tests/%s.cc' % t - for t in sorted(END2END_TESTS.keys())], - hdrs = [ - 'tests/cancel_test_helpers.h', - 'end2end_tests.h' - ], - language = "C++", - deps = [ - ':cq_verifier', - ':ssl_test_data', - ':http_proxy', - ':proxy', - ] - ) - - for f, fopt in END2END_FIXTURES.items(): - grpc_cc_binary( - name = '%s_test' % f, - srcs = ['fixtures/%s.cc' % f], - language = "C++", - deps = [ - ':end2end_tests', - '//test/core/util:grpc_test_util', - '//:grpc', - '//test/core/util:gpr_test_util', - '//:gpr', - ], + grpc_cc_library( + name = "end2end_tests", + srcs = ["end2end_tests.cc", "end2end_test_utils.cc"] + [ + "tests/%s.cc" % t + for t in sorted(END2END_TESTS.keys()) + ], + hdrs = [ + "tests/cancel_test_helpers.h", + "end2end_tests.h", + ], + language = "C++", + deps = [ + ":cq_verifier", + ":ssl_test_data", + ":http_proxy", + ":proxy", + ], ) - for t, topt in END2END_TESTS.items(): - #print(compatible(fopt, topt), f, t, fopt, topt) - if not compatible(fopt, topt): continue - for poller in POLLERS: - native.sh_test( - name = '%s_test@%s@poller=%s' % (f, t, poller), - data = [':%s_test' % f], - srcs = ['end2end_test.sh'], - args = [ - '$(location %s_test)' % f, - t, - poller, - ], + + for f, fopt in END2END_FIXTURES.items(): + grpc_cc_binary( + name = "%s_test" % f, + srcs = ["fixtures/%s.cc" % f], + language = "C++", + deps = [ + ":end2end_tests", + "//test/core/util:grpc_test_util", + "//:grpc", + "//test/core/util:gpr_test_util", + "//:gpr", + ], ) + for t, topt in END2END_TESTS.items(): + #print(_compatible(fopt, topt), f, t, fopt, topt) + if not _compatible(fopt, topt): + continue + for poller in POLLERS: + native.sh_test( + name = "%s_test@%s@poller=%s" % (f, t, poller), + data = [":%s_test" % f], + srcs = ["end2end_test.sh"], + args = [ + "$(location %s_test)" % f, + t, + poller, + ], + ) diff --git a/test/core/iomgr/BUILD b/test/core/iomgr/BUILD index 7754bc4970..70ee83acd2 100644 --- a/test/core/iomgr/BUILD +++ b/test/core/iomgr/BUILD @@ -40,6 +40,7 @@ grpc_cc_library( grpc_cc_test( name = "combiner_test", srcs = ["combiner_test.cc"], + data = ["//third_party/toolchains:RBE_USE_MACHINE_TYPE_LARGE"], language = "C++", deps = [ "//:gpr", @@ -47,7 +48,6 @@ grpc_cc_test( "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", ], - data = ["//third_party/toolchains:RBE_USE_MACHINE_TYPE_LARGE"], ) grpc_cc_test( @@ -89,18 +89,6 @@ grpc_cc_test( ) grpc_cc_test( - name = "ev_epollsig_linux_test", - srcs = ["ev_epollsig_linux_test.cc"], - language = "C++", - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:gpr_test_util", - "//test/core/util:grpc_test_util", - ], -) - -grpc_cc_test( name = "fd_conservation_posix_test", srcs = ["fd_conservation_posix_test.cc"], language = "C++", @@ -136,7 +124,6 @@ grpc_cc_test( ], ) - grpc_cc_test( name = "load_file_test", srcs = ["load_file_test.cc"], @@ -150,18 +137,6 @@ grpc_cc_test( ) grpc_cc_test( - name = "pollset_set_test", - srcs = ["pollset_set_test.cc"], - language = "C++", - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:gpr_test_util", - "//test/core/util:grpc_test_util", - ], -) - -grpc_cc_test( name = "resolve_address_posix_test", srcs = ["resolve_address_posix_test.cc"], language = "C++", @@ -176,10 +151,10 @@ grpc_cc_test( grpc_cc_test( name = "resolve_address_using_ares_resolver_test", srcs = ["resolve_address_test.cc"], - language = "C++", args = [ "--resolver=ares", ], + language = "C++", deps = [ "//:gpr", "//:grpc", @@ -191,10 +166,10 @@ grpc_cc_test( grpc_cc_test( name = "resolve_address_using_native_resolver_test", srcs = ["resolve_address_test.cc"], - language = "C++", args = [ "--resolver=native", ], + language = "C++", deps = [ "//:gpr", "//:grpc", @@ -276,7 +251,6 @@ grpc_cc_test( ], ) - grpc_cc_test( name = "tcp_server_posix_test", srcs = ["tcp_server_posix_test.cc"], diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc deleted file mode 100644 index 28c9dd408c..0000000000 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ /dev/null @@ -1,321 +0,0 @@ -/* - * - * 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 "src/core/lib/iomgr/port.h" - -/* This test only relevant on linux systems where epoll() is available */ -#ifdef GRPC_LINUX_EPOLL_CREATE1 -#include "src/core/lib/iomgr/ev_epollsig_linux.h" -#include "src/core/lib/iomgr/ev_posix.h" - -#include <errno.h> -#include <string.h> -#include <unistd.h> - -#include <grpc/grpc.h> -#include <grpc/support/alloc.h> -#include <grpc/support/log.h> - -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/gprpp/thd.h" -#include "src/core/lib/iomgr/iomgr.h" -#include "test/core/util/test_config.h" - -typedef struct test_pollset { - grpc_pollset* pollset; - gpr_mu* mu; -} test_pollset; - -typedef struct test_fd { - int inner_fd; - grpc_fd* fd; -} test_fd; - -/* num_fds should be an even number */ -static void test_fd_init(test_fd* tfds, int* fds, int num_fds) { - int i; - int r; - - /* Create some dummy file descriptors. Currently using pipe file descriptors - * for this test but we could use any other type of file descriptors. Also, - * since pipe() used in this test creates two fds in each call, num_fds should - * be an even number */ - GPR_ASSERT((num_fds % 2) == 0); - for (i = 0; i < num_fds; i = i + 2) { - r = pipe(fds + i); - if (r != 0) { - gpr_log(GPR_ERROR, "Error in creating pipe. %d (%s)", errno, - strerror(errno)); - return; - } - } - - for (i = 0; i < num_fds; i++) { - tfds[i].inner_fd = fds[i]; - tfds[i].fd = grpc_fd_create(fds[i], "test_fd", false); - } -} - -static void test_fd_cleanup(test_fd* tfds, int num_fds) { - int release_fd; - int i; - - for (i = 0; i < num_fds; i++) { - grpc_fd_shutdown(tfds[i].fd, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_fd_cleanup")); - grpc_core::ExecCtx::Get()->Flush(); - - grpc_fd_orphan(tfds[i].fd, nullptr, &release_fd, "test_fd_cleanup"); - grpc_core::ExecCtx::Get()->Flush(); - - GPR_ASSERT(release_fd == tfds[i].inner_fd); - close(tfds[i].inner_fd); - } -} - -static void test_pollset_init(test_pollset* pollsets, int num_pollsets) { - int i; - for (i = 0; i < num_pollsets; i++) { - pollsets[i].pollset = - static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(pollsets[i].pollset, &pollsets[i].mu); - } -} - -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); -} - -static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { - grpc_closure destroyed; - int i; - - for (i = 0; i < num_pollsets; i++) { - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, pollsets[i].pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(pollsets[i].pollset, &destroyed); - - grpc_core::ExecCtx::Get()->Flush(); - gpr_free(pollsets[i].pollset); - } -} - - /* - * Cases to test: - * case 1) Polling islands of both fd and pollset are NULL - * case 2) Polling island of fd is NULL but that of pollset is not-NULL - * case 3) Polling island of fd is not-NULL but that of pollset is NULL - * case 4) Polling islands of both fd and pollset are not-NULL and: - * case 4.1) Polling islands of fd and pollset are equal - * case 4.2) Polling islands of fd and pollset are NOT-equal (This results - * in a merge) - * */ - -#define NUM_FDS 8 -#define NUM_POLLSETS 4 - -static void test_add_fd_to_pollset() { - grpc_core::ExecCtx exec_ctx; - test_fd tfds[NUM_FDS]; - int fds[NUM_FDS]; - test_pollset pollsets[NUM_POLLSETS]; - void* expected_pi = nullptr; - int i; - - test_fd_init(tfds, fds, NUM_FDS); - test_pollset_init(pollsets, NUM_POLLSETS); - - /*Step 1. - * Create three polling islands (This will exercise test case 1 and 2) with - * the following configuration: - * polling island 0 = { fds:0,1,2, pollsets:0} - * polling island 1 = { fds:3,4, pollsets:1} - * polling island 2 = { fds:5,6,7 pollsets:2} - * - *Step 2. - * Add pollset 3 to polling island 0 (by adding fds 0 and 1 to pollset 3) - * (This will exercise test cases 3 and 4.1). The configuration becomes: - * polling island 0 = { fds:0,1,2, pollsets:0,3} <<< pollset 3 added here - * polling island 1 = { fds:3,4, pollsets:1} - * polling island 2 = { fds:5,6,7 pollsets:2} - * - *Step 3. - * Merge polling islands 0 and 1 by adding fd 0 to pollset 1 (This will - * exercise test case 4.2). The configuration becomes: - * polling island (merged) = {fds: 0,1,2,3,4, pollsets: 0,1,3} - * polling island 2 = {fds: 5,6,7 pollsets: 2} - * - *Step 4. - * Finally do one more merge by adding fd 3 to pollset 2. - * polling island (merged) = {fds: 0,1,2,3,4,5,6,7, pollsets: 0,1,2,3} - */ - - /* == Step 1 == */ - for (i = 0; i <= 2; i++) { - grpc_pollset_add_fd(pollsets[0].pollset, tfds[i].fd); - grpc_core::ExecCtx::Get()->Flush(); - } - - for (i = 3; i <= 4; i++) { - grpc_pollset_add_fd(pollsets[1].pollset, tfds[i].fd); - grpc_core::ExecCtx::Get()->Flush(); - } - - for (i = 5; i <= 7; i++) { - grpc_pollset_add_fd(pollsets[2].pollset, tfds[i].fd); - grpc_core::ExecCtx::Get()->Flush(); - } - - /* == Step 2 == */ - for (i = 0; i <= 1; i++) { - grpc_pollset_add_fd(pollsets[3].pollset, tfds[i].fd); - grpc_core::ExecCtx::Get()->Flush(); - } - - /* == Step 3 == */ - grpc_pollset_add_fd(pollsets[1].pollset, tfds[0].fd); - grpc_core::ExecCtx::Get()->Flush(); - - /* == Step 4 == */ - grpc_pollset_add_fd(pollsets[2].pollset, tfds[3].fd); - grpc_core::ExecCtx::Get()->Flush(); - - /* All polling islands are merged at this point */ - - /* Compare Fd:0's polling island with that of all other Fds */ - expected_pi = grpc_fd_get_polling_island(tfds[0].fd); - for (i = 1; i < NUM_FDS; i++) { - GPR_ASSERT(grpc_are_polling_islands_equal( - expected_pi, grpc_fd_get_polling_island(tfds[i].fd))); - } - - /* Compare Fd:0's polling island with that of all other pollsets */ - for (i = 0; i < NUM_POLLSETS; i++) { - GPR_ASSERT(grpc_are_polling_islands_equal( - expected_pi, grpc_pollset_get_polling_island(pollsets[i].pollset))); - } - - test_fd_cleanup(tfds, NUM_FDS); - test_pollset_cleanup(pollsets, NUM_POLLSETS); -} - -#undef NUM_FDS -#undef NUM_POLLSETS - -typedef struct threading_shared { - gpr_mu* mu; - grpc_pollset* pollset; - grpc_wakeup_fd* wakeup_fd; - grpc_fd* wakeup_desc; - grpc_closure on_wakeup; - int wakeups; -} threading_shared; - -static __thread int thread_wakeups = 0; - -static void test_threading_loop(void* arg) { - threading_shared* shared = static_cast<threading_shared*>(arg); - while (thread_wakeups < 1000000) { - grpc_core::ExecCtx exec_ctx; - grpc_pollset_worker* worker; - gpr_mu_lock(shared->mu); - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(shared->pollset, &worker, GRPC_MILLIS_INF_FUTURE))); - gpr_mu_unlock(shared->mu); - } -} - -static void test_threading_wakeup(void* arg, grpc_error* error) { - threading_shared* shared = static_cast<threading_shared*>(arg); - ++shared->wakeups; - ++thread_wakeups; - if (error == GRPC_ERROR_NONE) { - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "consume_wakeup", grpc_wakeup_fd_consume_wakeup(shared->wakeup_fd))); - grpc_fd_notify_on_read(shared->wakeup_desc, &shared->on_wakeup); - GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_next", - grpc_wakeup_fd_wakeup(shared->wakeup_fd))); - } -} - -static void test_threading(void) { - threading_shared shared; - shared.pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(shared.pollset, &shared.mu); - - grpc_core::Thread thds[10]; - for (auto& th : thds) { - th = grpc_core::Thread("test_thread", test_threading_loop, &shared); - th.Start(); - } - grpc_wakeup_fd fd; - GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&fd))); - shared.wakeup_fd = &fd; - shared.wakeup_desc = grpc_fd_create(fd.read_fd, "wakeup", false); - shared.wakeups = 0; - { - grpc_core::ExecCtx exec_ctx; - grpc_pollset_add_fd(shared.pollset, shared.wakeup_desc); - grpc_fd_notify_on_read( - shared.wakeup_desc, - GRPC_CLOSURE_INIT(&shared.on_wakeup, test_threading_wakeup, &shared, - grpc_schedule_on_exec_ctx)); - } - GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_first", - grpc_wakeup_fd_wakeup(shared.wakeup_fd))); - for (auto& th : thds) { - th.Join(); - } - fd.read_fd = 0; - grpc_wakeup_fd_destroy(&fd); - { - grpc_core::ExecCtx exec_ctx; - grpc_fd_shutdown(shared.wakeup_desc, GRPC_ERROR_CANCELLED); - grpc_fd_orphan(shared.wakeup_desc, nullptr, nullptr, "done"); - grpc_pollset_shutdown(shared.pollset, - GRPC_CLOSURE_CREATE(destroy_pollset, shared.pollset, - grpc_schedule_on_exec_ctx)); - } - gpr_free(shared.pollset); -} - -int main(int argc, char** argv) { - const char* poll_strategy = nullptr; - grpc_test_init(argc, argv); - grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - - poll_strategy = grpc_get_poll_strategy_name(); - if (poll_strategy != nullptr && strcmp(poll_strategy, "epollsig") == 0) { - test_add_fd_to_pollset(); - test_threading(); - } else { - gpr_log(GPR_INFO, - "Skipping the test. The test is only relevant for 'epollsig' " - "strategy. and the current strategy is: '%s'", - poll_strategy); - } - } - - grpc_shutdown(); - return 0; -} -#else /* defined(GRPC_LINUX_EPOLL_CREATE1) */ -int main(int argc, char** argv) { return 0; } -#endif /* !defined(GRPC_LINUX_EPOLL_CREATE1) */ diff --git a/test/core/iomgr/pollset_set_test.cc b/test/core/iomgr/pollset_set_test.cc deleted file mode 100644 index 1aae1daa02..0000000000 --- a/test/core/iomgr/pollset_set_test.cc +++ /dev/null @@ -1,447 +0,0 @@ -/* - * - * 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 "src/core/lib/iomgr/port.h" - -/* This test only relevant on linux systems where epoll is available */ -#ifdef GRPC_LINUX_EPOLL_CREATE1 - -#include <errno.h> -#include <string.h> -#include <unistd.h> - -#include <grpc/grpc.h> -#include <grpc/support/alloc.h> -#include <grpc/support/log.h> - -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/iomgr/ev_posix.h" -#include "src/core/lib/iomgr/iomgr.h" -#include "test/core/util/test_config.h" - -/******************************************************************************* - * test_pollset_set - */ - -typedef struct test_pollset_set { - grpc_pollset_set* pss; -} test_pollset_set; - -void init_test_pollset_sets(test_pollset_set* pollset_sets, const int num_pss) { - for (int i = 0; i < num_pss; i++) { - pollset_sets[i].pss = grpc_pollset_set_create(); - } -} - -void cleanup_test_pollset_sets(test_pollset_set* pollset_sets, - const int num_pss) { - for (int i = 0; i < num_pss; i++) { - grpc_pollset_set_destroy(pollset_sets[i].pss); - pollset_sets[i].pss = nullptr; - } -} - -/******************************************************************************* - * test_pollset - */ - -typedef struct test_pollset { - grpc_pollset* ps; - gpr_mu* mu; -} test_pollset; - -static void init_test_pollsets(test_pollset* pollsets, const int num_pollsets) { - for (int i = 0; i < num_pollsets; i++) { - pollsets[i].ps = - static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(pollsets[i].ps, &pollsets[i].mu); - } -} - -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); -} - -static void cleanup_test_pollsets(test_pollset* pollsets, - const int num_pollsets) { - grpc_closure destroyed; - for (int i = 0; i < num_pollsets; i++) { - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, pollsets[i].ps, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(pollsets[i].ps, &destroyed); - - grpc_core::ExecCtx::Get()->Flush(); - gpr_free(pollsets[i].ps); - pollsets[i].ps = nullptr; - } -} - -/******************************************************************************* - * test_fd - */ - -typedef struct test_fd { - grpc_fd* fd; - grpc_wakeup_fd wakeup_fd; - - bool is_on_readable_called; /* Is on_readable closure is called ? */ - grpc_closure on_readable; /* Closure to call when this fd is readable */ -} test_fd; - -void on_readable(void* tfd, grpc_error* error) { - (static_cast<test_fd*>(tfd))->is_on_readable_called = true; -} - -static void reset_test_fd(test_fd* tfd) { - tfd->is_on_readable_called = false; - - GRPC_CLOSURE_INIT(&tfd->on_readable, on_readable, tfd, - grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(tfd->fd, &tfd->on_readable); -} - -static void init_test_fds(test_fd* tfds, const int num_fds) { - for (int i = 0; i < num_fds; i++) { - GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_init(&tfds[i].wakeup_fd)); - tfds[i].fd = grpc_fd_create(GRPC_WAKEUP_FD_GET_READ_FD(&tfds[i].wakeup_fd), - "test_fd", false); - reset_test_fd(&tfds[i]); - } -} - -static void cleanup_test_fds(test_fd* tfds, const int num_fds) { - int release_fd; - - for (int i = 0; i < num_fds; i++) { - grpc_fd_shutdown(tfds[i].fd, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("fd cleanup")); - grpc_core::ExecCtx::Get()->Flush(); - - /* grpc_fd_orphan frees the memory allocated for grpc_fd. Normally it also - * calls close() on the underlying fd. In our case, we are using - * grpc_wakeup_fd and we would like to destroy it ourselves (by calling - * grpc_wakeup_fd_destroy). To prevent grpc_fd from calling close() on the - * underlying fd, call it with a non-NULL 'release_fd' parameter */ - grpc_fd_orphan(tfds[i].fd, nullptr, &release_fd, "test_fd_cleanup"); - grpc_core::ExecCtx::Get()->Flush(); - - grpc_wakeup_fd_destroy(&tfds[i].wakeup_fd); - } -} - -static void make_test_fds_readable(test_fd* tfds, const int num_fds) { - for (int i = 0; i < num_fds; i++) { - GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_wakeup(&tfds[i].wakeup_fd)); - } -} - -static void verify_readable_and_reset(test_fd* tfds, const int num_fds) { - for (int i = 0; i < num_fds; i++) { - /* Verify that the on_readable callback was called */ - GPR_ASSERT(tfds[i].is_on_readable_called); - - /* Reset the tfd[i] structure */ - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_wakeup_fd_consume_wakeup(&tfds[i].wakeup_fd)); - reset_test_fd(&tfds[i]); - } -} - -/******************************************************************************* - * Main tests - */ - -/* Test some typical scenarios in pollset_set */ -static void pollset_set_test_basic() { - /* We construct the following structure for this test: - * - * +---> FD0 (Added before PSS1, PS1 and PS2 are added to PSS0) - * | - * +---> FD5 (Added after PSS1, PS1 and PS2 are added to PSS0) - * | - * | - * | +---> FD1 (Added before PSS1 is added to PSS0) - * | | - * | +---> FD6 (Added after PSS1 is added to PSS0) - * | | - * +---> PSS1--+ +--> FD2 (Added before PS0 is added to PSS1) - * | | | - * | +---> PS0---+ - * | | - * PSS0---+ +--> FD7 (Added after PS0 is added to PSS1) - * | - * | - * | +---> FD3 (Added before PS1 is added to PSS0) - * | | - * +---> PS1---+ - * | | - * | +---> FD8 (Added after PS1 added to PSS0) - * | - * | - * | +---> FD4 (Added before PS2 is added to PSS0) - * | | - * +---> PS2---+ - * | - * +---> FD9 (Added after PS2 is added to PSS0) - */ - grpc_core::ExecCtx exec_ctx; - grpc_pollset_worker* worker; - grpc_millis deadline; - - test_fd tfds[10]; - test_pollset pollsets[3]; - test_pollset_set pollset_sets[2]; - const int num_fds = GPR_ARRAY_SIZE(tfds); - const int num_ps = GPR_ARRAY_SIZE(pollsets); - const int num_pss = GPR_ARRAY_SIZE(pollset_sets); - - init_test_fds(tfds, num_fds); - init_test_pollsets(pollsets, num_ps); - init_test_pollset_sets(pollset_sets, num_pss); - - /* Construct the pollset_set/pollset/fd tree (see diagram above) */ - - grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[1].fd); - - grpc_pollset_add_fd(pollsets[0].ps, tfds[2].fd); - grpc_pollset_add_fd(pollsets[1].ps, tfds[3].fd); - grpc_pollset_add_fd(pollsets[2].ps, tfds[4].fd); - - grpc_pollset_set_add_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - - grpc_pollset_set_add_pollset(pollset_sets[1].pss, pollsets[0].ps); - grpc_pollset_set_add_pollset(pollset_sets[0].pss, pollsets[1].ps); - grpc_pollset_set_add_pollset(pollset_sets[0].pss, pollsets[2].ps); - - grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[5].fd); - grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[6].fd); - - grpc_pollset_add_fd(pollsets[0].ps, tfds[7].fd); - grpc_pollset_add_fd(pollsets[1].ps, tfds[8].fd); - grpc_pollset_add_fd(pollsets[2].ps, tfds[9].fd); - - grpc_core::ExecCtx::Get()->Flush(); - - /* Test that if any FD in the above structure is readable, it is observable by - * doing grpc_pollset_work on any pollset - * - * For every pollset, do the following: - * - (Ensure that all FDs are in reset state) - * - Make all FDs readable - * - Call grpc_pollset_work() on the pollset - * - Flush the exec_ctx - * - Verify that on_readable call back was called for all FDs (and - * reset the FDs) - * */ - for (int i = 0; i < num_ps; i++) { - make_test_fds_readable(tfds, num_fds); - - gpr_mu_lock(pollsets[i].mu); - deadline = grpc_timespec_to_millis_round_up( - grpc_timeout_milliseconds_to_deadline(2)); - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(pollsets[i].ps, &worker, deadline)); - gpr_mu_unlock(pollsets[i].mu); - - grpc_core::ExecCtx::Get()->Flush(); - - verify_readable_and_reset(tfds, num_fds); - grpc_core::ExecCtx::Get()->Flush(); - } - - /* Test tear down */ - grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[5].fd); - grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[6].fd); - grpc_core::ExecCtx::Get()->Flush(); - - grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollsets[0].ps); - grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[1].ps); - grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[2].ps); - - grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - grpc_core::ExecCtx::Get()->Flush(); - - cleanup_test_fds(tfds, num_fds); - cleanup_test_pollsets(pollsets, num_ps); - cleanup_test_pollset_sets(pollset_sets, num_pss); -} - -/* Same FD added multiple times to the pollset_set tree */ -void pollset_set_test_dup_fds() { - /* We construct the following structure for this test: - * - * +---> FD0 - * | - * | - * PSS0---+ - * | +---> FD0 (also under PSS0) - * | | - * +---> PSS1--+ +--> FD1 (also under PSS1) - * | | - * +---> PS ---+ - * | | - * | +--> FD2 - * +---> FD1 - */ - grpc_core::ExecCtx exec_ctx; - grpc_pollset_worker* worker; - grpc_millis deadline; - - test_fd tfds[3]; - test_pollset pollset; - test_pollset_set pollset_sets[2]; - const int num_fds = GPR_ARRAY_SIZE(tfds); - const int num_ps = 1; - const int num_pss = GPR_ARRAY_SIZE(pollset_sets); - - init_test_fds(tfds, num_fds); - init_test_pollsets(&pollset, num_ps); - init_test_pollset_sets(pollset_sets, num_pss); - - /* Construct the structure */ - grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[0].fd); - grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[1].fd); - - grpc_pollset_add_fd(pollset.ps, tfds[1].fd); - grpc_pollset_add_fd(pollset.ps, tfds[2].fd); - - grpc_pollset_set_add_pollset(pollset_sets[1].pss, pollset.ps); - grpc_pollset_set_add_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - - /* Test. Make all FDs readable and make sure that can be observed by doing a - * grpc_pollset_work on the pollset 'PS' */ - make_test_fds_readable(tfds, num_fds); - - gpr_mu_lock(pollset.mu); - deadline = grpc_timespec_to_millis_round_up( - grpc_timeout_milliseconds_to_deadline(2)); - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(pollset.ps, &worker, deadline)); - gpr_mu_unlock(pollset.mu); - grpc_core::ExecCtx::Get()->Flush(); - - verify_readable_and_reset(tfds, num_fds); - grpc_core::ExecCtx::Get()->Flush(); - - /* Tear down */ - grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[0].fd); - grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); - - grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollset.ps); - grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - grpc_core::ExecCtx::Get()->Flush(); - - cleanup_test_fds(tfds, num_fds); - cleanup_test_pollsets(&pollset, num_ps); - cleanup_test_pollset_sets(pollset_sets, num_pss); -} - -/* Pollset_set with an empty pollset */ -void pollset_set_test_empty_pollset() { - /* We construct the following structure for this test: - * - * +---> PS0 (EMPTY) - * | - * +---> FD0 - * | - * PSS0---+ - * | +---> FD1 - * | | - * +---> PS1--+ - * | - * +---> FD2 - */ - grpc_core::ExecCtx exec_ctx; - grpc_pollset_worker* worker; - grpc_millis deadline; - - test_fd tfds[3]; - test_pollset pollsets[2]; - test_pollset_set pollset_set; - const int num_fds = GPR_ARRAY_SIZE(tfds); - const int num_ps = GPR_ARRAY_SIZE(pollsets); - const int num_pss = 1; - - init_test_fds(tfds, num_fds); - init_test_pollsets(pollsets, num_ps); - init_test_pollset_sets(&pollset_set, num_pss); - - /* Construct the structure */ - grpc_pollset_set_add_fd(pollset_set.pss, tfds[0].fd); - grpc_pollset_add_fd(pollsets[1].ps, tfds[1].fd); - grpc_pollset_add_fd(pollsets[1].ps, tfds[2].fd); - - grpc_pollset_set_add_pollset(pollset_set.pss, pollsets[0].ps); - grpc_pollset_set_add_pollset(pollset_set.pss, pollsets[1].ps); - - /* Test. Make all FDs readable and make sure that can be observed by doing - * grpc_pollset_work on the empty pollset 'PS0' */ - make_test_fds_readable(tfds, num_fds); - - gpr_mu_lock(pollsets[0].mu); - deadline = grpc_timespec_to_millis_round_up( - grpc_timeout_milliseconds_to_deadline(2)); - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(pollsets[0].ps, &worker, deadline)); - gpr_mu_unlock(pollsets[0].mu); - grpc_core::ExecCtx::Get()->Flush(); - - verify_readable_and_reset(tfds, num_fds); - grpc_core::ExecCtx::Get()->Flush(); - - /* Tear down */ - grpc_pollset_set_del_fd(pollset_set.pss, tfds[0].fd); - grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[0].ps); - grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[1].ps); - grpc_core::ExecCtx::Get()->Flush(); - - cleanup_test_fds(tfds, num_fds); - cleanup_test_pollsets(pollsets, num_ps); - cleanup_test_pollset_sets(&pollset_set, num_pss); -} - -int main(int argc, char** argv) { - grpc_test_init(argc, argv); - grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - const char* poll_strategy = grpc_get_poll_strategy_name(); - - if (poll_strategy != nullptr && - (strcmp(poll_strategy, "epollsig") == 0 || - strcmp(poll_strategy, "epoll-threadpool") == 0)) { - pollset_set_test_basic(); - pollset_set_test_dup_fds(); - pollset_set_test_empty_pollset(); - } else { - gpr_log(GPR_INFO, - "Skipping the test. The test is only relevant for 'epoll' " - "strategy. and the current strategy is: '%s'", - poll_strategy); - } - } - grpc_shutdown(); - return 0; -} -#else /* defined(GRPC_LINUX_EPOLL_CREATE1) */ -int main(int argc, char** argv) { return 0; } -#endif /* !defined(GRPC_LINUX_EPOLL_CREATE1) */ diff --git a/test/core/tsi/alts/fake_handshaker/BUILD b/test/core/tsi/alts/fake_handshaker/BUILD index a09a046d27..98cd628a7d 100644 --- a/test/core/tsi/alts/fake_handshaker/BUILD +++ b/test/core/tsi/alts/fake_handshaker/BUILD @@ -37,21 +37,22 @@ grpc_cc_library( name = "fake_handshaker_lib", testonly = True, srcs = ["fake_handshaker_server.cc"], + hdrs = ["fake_handshaker_server.h"], language = "C++", deps = [ "handshaker_proto", "transport_security_common_proto", "//:grpc++", - "//test/cpp/util:test_config", ], ) grpc_cc_binary( name = "fake_handshaker_server", testonly = True, - srcs = ["fake_handshaker_server.cc"], + srcs = ["fake_handshaker_server_main.cc"], language = "C++", deps = [ + "//test/cpp/util:test_config", "fake_handshaker_lib", ], ) diff --git a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc index f6a4791b49..ba246b07eb 100644 --- a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc +++ b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc @@ -15,12 +15,12 @@ * limitations under the License. * */ +#include "test/core/tsi/alts/fake_handshaker/fake_handshaker_server.h" #include <memory> #include <sstream> #include <string> -#include <gflags/gflags.h> #include <grpc/grpc.h> #include <grpc/support/log.h> #include <grpcpp/impl/codegen/async_stream.h> @@ -32,10 +32,6 @@ #include "test/core/tsi/alts/fake_handshaker/handshaker.grpc.pb.h" #include "test/core/tsi/alts/fake_handshaker/handshaker.pb.h" #include "test/core/tsi/alts/fake_handshaker/transport_security_common.pb.h" -#include "test/cpp/util/test_config.h" - -DEFINE_int32(handshaker_port, 55056, - "TCP port on which the fake handshaker server listens to."); // Fake handshake messages. constexpr char kClientInitFrame[] = "ClientInit"; @@ -243,26 +239,9 @@ class FakeHandshakerService : public HandshakerService::Service { } }; -} // namespace gcp -} // namespace grpc - -void RunServer() { - GPR_ASSERT(FLAGS_handshaker_port != 0); - std::ostringstream server_address; - server_address << "[::1]:" << FLAGS_handshaker_port; - grpc::gcp::FakeHandshakerService service; - grpc::ServerBuilder builder; - builder.AddListeningPort(server_address.str(), - grpc::InsecureServerCredentials()); - builder.RegisterService(&service); - std::unique_ptr<grpc::Server> server(builder.BuildAndStart()); - gpr_log(GPR_INFO, "Fake handshaker server listening on %s", - server_address.str().c_str()); - server->Wait(); +std::unique_ptr<grpc::Service> CreateFakeHandshakerService() { + return std::unique_ptr<grpc::Service>{new grpc::gcp::FakeHandshakerService}; } -int main(int argc, char** argv) { - grpc::testing::InitTest(&argc, &argv, true); - RunServer(); - return 0; -} +} // namespace gcp +} // namespace grpc diff --git a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.h b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.h new file mode 100644 index 0000000000..eb4bfdffa1 --- /dev/null +++ b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.h @@ -0,0 +1,29 @@ +/* + * + * Copyright 2018 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 <memory> +#include <string> + +#include <grpcpp/grpcpp.h> + +namespace grpc { +namespace gcp { + +std::unique_ptr<grpc::Service> CreateFakeHandshakerService(); + +} // namespace gcp +} // namespace grpc diff --git a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server_main.cc b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server_main.cc new file mode 100644 index 0000000000..60351533d9 --- /dev/null +++ b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server_main.cc @@ -0,0 +1,53 @@ +/* + * + * Copyright 2018 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/tsi/alts/fake_handshaker/fake_handshaker_server.h" + +#include <sstream> + +#include <gflags/gflags.h> +#include <grpc/support/log.h> +#include <grpcpp/impl/codegen/service_type.h> +#include <grpcpp/server_builder.h> + +#include "test/cpp/util/test_config.h" + +DEFINE_int32(handshaker_port, 55056, + "TCP port on which the fake handshaker server listens to."); + +static void RunFakeHandshakerServer(const std::string& server_address) { + std::unique_ptr<grpc::Service> service = + grpc::gcp::CreateFakeHandshakerService(); + grpc::ServerBuilder builder; + builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); + builder.RegisterService(service.get()); + gpr_log(GPR_INFO, "Fake handshaker server listening on %s", + server_address.c_str()); + std::unique_ptr<grpc::Server> server = builder.BuildAndStart(); + server->Wait(); +} + +int main(int argc, char** argv) { + grpc::testing::InitTest(&argc, &argv, true); + + GPR_ASSERT(FLAGS_handshaker_port != 0); + std::ostringstream server_address; + server_address << "[::1]:" << FLAGS_handshaker_port; + + RunFakeHandshakerServer(server_address.str()); + return 0; +} |