From 8a99fdb57e564f2166f5f83e50baa4c47e9a3f8d Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 25 Jan 2018 15:38:20 -0800 Subject: Move cmdline and subprocess from public gpr to test/core/util --- BUILD | 5 - CMakeLists.txt | 78 ++-- Makefile | 113 +++-- build.yaml | 37 +- config.m4 | 3 - config.w32 | 3 - gRPC-C++.podspec | 2 + gRPC-Core.podspec | 10 +- grpc.def | 14 - grpc.gemspec | 5 - grpc.gyp | 9 +- include/grpc/module.modulemap | 2 - include/grpc/support/cmdline.h | 88 ---- include/grpc/support/subprocess.h | 44 -- package.xml | 5 - src/core/lib/gpr/cmdline.cc | 330 -------------- src/core/lib/gpr/subprocess_posix.cc | 99 ----- src/core/lib/gpr/subprocess_windows.cc | 126 ------ src/python/grpcio/grpc_core_dependencies.py | 3 - src/ruby/ext/grpc/rb_grpc_imports.generated.c | 28 -- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 44 -- test/core/bad_ssl/bad_ssl_test.cc | 2 +- test/core/bad_ssl/server_common.cc | 2 +- test/core/fling/client.cc | 2 +- test/core/fling/fling_stream_test.cc | 3 +- test/core/fling/fling_test.cc | 3 +- test/core/fling/server.cc | 2 +- test/core/gpr/BUILD | 10 - test/core/gpr/cmdline_test.cc | 491 --------------------- test/core/http/httpcli_test.cc | 3 +- test/core/http/httpscli_test.cc | 3 +- test/core/json/json_rewrite.cc | 2 +- test/core/memory_usage/client.cc | 3 +- test/core/memory_usage/memory_usage_test.cc | 3 +- test/core/memory_usage/server.cc | 2 +- .../core/network_benchmarks/low_level_ping_pong.cc | 2 +- test/core/security/BUILD | 3 + test/core/security/create_jwt.cc | 3 +- test/core/security/fetch_oauth2.cc | 2 +- .../security/print_google_default_creds_token.cc | 2 +- test/core/security/verify_jwt.cc | 2 +- test/core/surface/public_headers_must_be_c89.c | 16 - test/core/util/BUILD | 15 + test/core/util/cmdline.cc | 330 ++++++++++++++ test/core/util/cmdline.h | 88 ++++ test/core/util/cmdline_test.cc | 491 +++++++++++++++++++++ test/core/util/subprocess.h | 44 ++ test/core/util/subprocess_posix.cc | 99 +++++ test/core/util/subprocess_windows.cc | 126 ++++++ test/cpp/util/BUILD | 2 + test/cpp/util/subprocess.cc | 2 +- tools/doxygen/Doxyfile.c++ | 2 - tools/doxygen/Doxyfile.c++.internal | 2 - tools/doxygen/Doxyfile.core | 2 - tools/doxygen/Doxyfile.core.internal | 5 - tools/run_tests/generated/sources_and_headers.json | 61 +-- tools/run_tests/generated/tests.json | 48 +- 57 files changed, 1413 insertions(+), 1513 deletions(-) delete mode 100644 include/grpc/support/cmdline.h delete mode 100644 include/grpc/support/subprocess.h delete mode 100644 src/core/lib/gpr/cmdline.cc delete mode 100644 src/core/lib/gpr/subprocess_posix.cc delete mode 100644 src/core/lib/gpr/subprocess_windows.cc delete mode 100644 test/core/gpr/cmdline_test.cc create mode 100644 test/core/util/cmdline.cc create mode 100644 test/core/util/cmdline.h create mode 100644 test/core/util/cmdline_test.cc create mode 100644 test/core/util/subprocess.h create mode 100644 test/core/util/subprocess_posix.cc create mode 100644 test/core/util/subprocess_windows.cc diff --git a/BUILD b/BUILD index 0a8be79e8a..1086d3fd47 100644 --- a/BUILD +++ b/BUILD @@ -67,14 +67,12 @@ GPR_PUBLIC_HDRS = [ "include/grpc/support/atm_gcc_sync.h", "include/grpc/support/atm_windows.h", "include/grpc/support/avl.h", - "include/grpc/support/cmdline.h", "include/grpc/support/cpu.h", "include/grpc/support/host_port.h", "include/grpc/support/log.h", "include/grpc/support/log_windows.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", @@ -458,7 +456,6 @@ grpc_cc_library( "src/core/lib/gpr/arena.cc", "src/core/lib/gpr/atm.cc", "src/core/lib/gpr/avl.cc", - "src/core/lib/gpr/cmdline.cc", "src/core/lib/gpr/cpu_iphone.cc", "src/core/lib/gpr/cpu_linux.cc", "src/core/lib/gpr/cpu_posix.cc", @@ -479,8 +476,6 @@ grpc_cc_library( "src/core/lib/gpr/string_posix.cc", "src/core/lib/gpr/string_util_windows.cc", "src/core/lib/gpr/string_windows.cc", - "src/core/lib/gpr/subprocess_posix.cc", - "src/core/lib/gpr/subprocess_windows.cc", "src/core/lib/gpr/sync.cc", "src/core/lib/gpr/sync_posix.cc", "src/core/lib/gpr/sync_windows.cc", diff --git a/CMakeLists.txt b/CMakeLists.txt index c557e9469a..7678eee093 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,6 +222,7 @@ add_dependencies(buildtests_c channel_create_test) add_dependencies(buildtests_c chttp2_hpack_encoder_test) add_dependencies(buildtests_c chttp2_stream_map_test) add_dependencies(buildtests_c chttp2_varint_test) +add_dependencies(buildtests_c cmdline_test) add_dependencies(buildtests_c combiner_test) add_dependencies(buildtests_c compression_test) add_dependencies(buildtests_c concurrent_connectivity_test) @@ -258,7 +259,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_c goaway_server_test) endif() add_dependencies(buildtests_c gpr_avl_test) -add_dependencies(buildtests_c gpr_cmdline_test) add_dependencies(buildtests_c gpr_cpu_test) add_dependencies(buildtests_c gpr_env_test) add_dependencies(buildtests_c gpr_host_port_test) @@ -628,7 +628,6 @@ add_library(gpr src/core/lib/gpr/arena.cc src/core/lib/gpr/atm.cc src/core/lib/gpr/avl.cc - src/core/lib/gpr/cmdline.cc src/core/lib/gpr/cpu_iphone.cc src/core/lib/gpr/cpu_linux.cc src/core/lib/gpr/cpu_posix.cc @@ -649,8 +648,6 @@ add_library(gpr src/core/lib/gpr/string_posix.cc src/core/lib/gpr/string_util_windows.cc src/core/lib/gpr/string_windows.cc - src/core/lib/gpr/subprocess_posix.cc - src/core/lib/gpr/subprocess_windows.cc src/core/lib/gpr/sync.cc src/core/lib/gpr/sync_posix.cc src/core/lib/gpr/sync_windows.cc @@ -704,14 +701,12 @@ foreach(_hdr include/grpc/support/atm_gcc_sync.h include/grpc/support/atm_windows.h include/grpc/support/avl.h - include/grpc/support/cmdline.h include/grpc/support/cpu.h include/grpc/support/host_port.h include/grpc/support/log.h include/grpc/support/log_windows.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 @@ -1448,6 +1443,7 @@ add_library(grpc_test_util test/core/end2end/fixtures/http_proxy_fixture.cc test/core/end2end/fixtures/proxy.cc test/core/iomgr/endpoint_tests.cc + test/core/util/cmdline.cc test/core/util/debugger_macros.cc test/core/util/grpc_profiler.cc test/core/util/histogram.cc @@ -1459,6 +1455,8 @@ add_library(grpc_test_util test/core/util/port_isolated_runtime_environment.cc test/core/util/port_server_client.cc test/core/util/slice_splitter.cc + test/core/util/subprocess_posix.cc + test/core/util/subprocess_windows.cc test/core/util/tracer_util.cc test/core/util/trickle_endpoint.cc src/core/lib/backoff/backoff.cc @@ -1717,6 +1715,7 @@ add_library(grpc_test_util_unsecure test/core/end2end/fixtures/http_proxy_fixture.cc test/core/end2end/fixtures/proxy.cc test/core/iomgr/endpoint_tests.cc + test/core/util/cmdline.cc test/core/util/debugger_macros.cc test/core/util/grpc_profiler.cc test/core/util/histogram.cc @@ -1728,6 +1727,8 @@ add_library(grpc_test_util_unsecure test/core/util/port_isolated_runtime_environment.cc test/core/util/port_server_client.cc test/core/util/slice_splitter.cc + test/core/util/subprocess_posix.cc + test/core/util/subprocess_windows.cc test/core/util/tracer_util.cc test/core/util/trickle_endpoint.cc src/core/lib/backoff/backoff.cc @@ -2498,14 +2499,12 @@ foreach(_hdr include/grpc/support/atm_gcc_sync.h include/grpc/support/atm_windows.h include/grpc/support/avl.h - include/grpc/support/cmdline.h include/grpc/support/cpu.h include/grpc/support/host_port.h include/grpc/support/log.h include/grpc/support/log_windows.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 @@ -2982,14 +2981,12 @@ foreach(_hdr include/grpc/support/atm_gcc_sync.h include/grpc/support/atm_windows.h include/grpc/support/avl.h - include/grpc/support/cmdline.h include/grpc/support/cpu.h include/grpc/support/host_port.h include/grpc/support/log.h include/grpc/support/log_windows.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 @@ -3712,14 +3709,12 @@ foreach(_hdr include/grpc/support/atm_gcc_sync.h include/grpc/support/atm_windows.h include/grpc/support/avl.h - include/grpc/support/cmdline.h include/grpc/support/cpu.h include/grpc/support/host_port.h include/grpc/support/log.h include/grpc/support/log_windows.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 @@ -5123,6 +5118,32 @@ target_link_libraries(chttp2_varint_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(cmdline_test + test/core/util/cmdline_test.cc +) + + +target_include_directories(cmdline_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} +) + +target_link_libraries(cmdline_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gpr + gpr_test_util + grpc_test_util +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(combiner_test test/core/iomgr/combiner_test.cc ) @@ -5677,31 +5698,6 @@ target_link_libraries(gpr_avl_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(gpr_cmdline_test - test/core/gpr/cmdline_test.cc -) - - -target_include_directories(gpr_cmdline_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} -) - -target_link_libraries(gpr_cmdline_test - ${_gRPC_ALLTARGETS_LIBRARIES} - gpr_test_util - gpr -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - add_executable(gpr_cpu_test test/core/gpr/cpu_test.cc ) @@ -6261,7 +6257,9 @@ target_include_directories(grpc_create_jwt target_link_libraries(grpc_create_jwt ${_gRPC_SSL_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util grpc + gpr_test_util gpr ) @@ -6430,7 +6428,9 @@ target_include_directories(grpc_print_google_default_creds_token target_link_libraries(grpc_print_google_default_creds_token ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util grpc + gpr_test_util gpr ) @@ -6516,7 +6516,9 @@ target_include_directories(grpc_verify_jwt target_link_libraries(grpc_verify_jwt ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util grpc + gpr_test_util gpr ) @@ -6886,7 +6888,9 @@ target_include_directories(json_rewrite target_link_libraries(json_rewrite ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util grpc + gpr_test_util gpr ) diff --git a/Makefile b/Makefile index 39a94d8c55..a8f10fd2fa 100644 --- a/Makefile +++ b/Makefile @@ -966,6 +966,7 @@ chttp2_hpack_encoder_test: $(BINDIR)/$(CONFIG)/chttp2_hpack_encoder_test chttp2_stream_map_test: $(BINDIR)/$(CONFIG)/chttp2_stream_map_test chttp2_varint_test: $(BINDIR)/$(CONFIG)/chttp2_varint_test client_fuzzer: $(BINDIR)/$(CONFIG)/client_fuzzer +cmdline_test: $(BINDIR)/$(CONFIG)/cmdline_test combiner_test: $(BINDIR)/$(CONFIG)/combiner_test compression_test: $(BINDIR)/$(CONFIG)/compression_test concurrent_connectivity_test: $(BINDIR)/$(CONFIG)/concurrent_connectivity_test @@ -986,7 +987,6 @@ fling_stream_test: $(BINDIR)/$(CONFIG)/fling_stream_test fling_test: $(BINDIR)/$(CONFIG)/fling_test goaway_server_test: $(BINDIR)/$(CONFIG)/goaway_server_test gpr_avl_test: $(BINDIR)/$(CONFIG)/gpr_avl_test -gpr_cmdline_test: $(BINDIR)/$(CONFIG)/gpr_cmdline_test gpr_cpu_test: $(BINDIR)/$(CONFIG)/gpr_cpu_test gpr_env_test: $(BINDIR)/$(CONFIG)/gpr_env_test gpr_host_port_test: $(BINDIR)/$(CONFIG)/gpr_host_port_test @@ -1369,6 +1369,7 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/chttp2_hpack_encoder_test \ $(BINDIR)/$(CONFIG)/chttp2_stream_map_test \ $(BINDIR)/$(CONFIG)/chttp2_varint_test \ + $(BINDIR)/$(CONFIG)/cmdline_test \ $(BINDIR)/$(CONFIG)/combiner_test \ $(BINDIR)/$(CONFIG)/compression_test \ $(BINDIR)/$(CONFIG)/concurrent_connectivity_test \ @@ -1389,7 +1390,6 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/fling_test \ $(BINDIR)/$(CONFIG)/goaway_server_test \ $(BINDIR)/$(CONFIG)/gpr_avl_test \ - $(BINDIR)/$(CONFIG)/gpr_cmdline_test \ $(BINDIR)/$(CONFIG)/gpr_cpu_test \ $(BINDIR)/$(CONFIG)/gpr_env_test \ $(BINDIR)/$(CONFIG)/gpr_host_port_test \ @@ -1806,6 +1806,8 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/chttp2_stream_map_test || ( echo test chttp2_stream_map_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_varint_test" $(Q) $(BINDIR)/$(CONFIG)/chttp2_varint_test || ( echo test chttp2_varint_test failed ; exit 1 ) + $(E) "[RUN] Testing cmdline_test" + $(Q) $(BINDIR)/$(CONFIG)/cmdline_test || ( echo test cmdline_test failed ; exit 1 ) $(E) "[RUN] Testing combiner_test" $(Q) $(BINDIR)/$(CONFIG)/combiner_test || ( echo test combiner_test failed ; exit 1 ) $(E) "[RUN] Testing compression_test" @@ -1842,8 +1844,6 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/goaway_server_test || ( echo test goaway_server_test failed ; exit 1 ) $(E) "[RUN] Testing gpr_avl_test" $(Q) $(BINDIR)/$(CONFIG)/gpr_avl_test || ( echo test gpr_avl_test failed ; exit 1 ) - $(E) "[RUN] Testing gpr_cmdline_test" - $(Q) $(BINDIR)/$(CONFIG)/gpr_cmdline_test || ( echo test gpr_cmdline_test failed ; exit 1 ) $(E) "[RUN] Testing gpr_cpu_test" $(Q) $(BINDIR)/$(CONFIG)/gpr_cpu_test || ( echo test gpr_cpu_test failed ; exit 1 ) $(E) "[RUN] Testing gpr_env_test" @@ -2849,7 +2849,6 @@ LIBGPR_SRC = \ src/core/lib/gpr/arena.cc \ src/core/lib/gpr/atm.cc \ src/core/lib/gpr/avl.cc \ - src/core/lib/gpr/cmdline.cc \ src/core/lib/gpr/cpu_iphone.cc \ src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_posix.cc \ @@ -2870,8 +2869,6 @@ LIBGPR_SRC = \ src/core/lib/gpr/string_posix.cc \ src/core/lib/gpr/string_util_windows.cc \ src/core/lib/gpr/string_windows.cc \ - src/core/lib/gpr/subprocess_posix.cc \ - src/core/lib/gpr/subprocess_windows.cc \ src/core/lib/gpr/sync.cc \ src/core/lib/gpr/sync_posix.cc \ src/core/lib/gpr/sync_windows.cc \ @@ -2897,14 +2894,12 @@ PUBLIC_HEADERS_C += \ include/grpc/support/atm_gcc_sync.h \ include/grpc/support/atm_windows.h \ include/grpc/support/avl.h \ - include/grpc/support/cmdline.h \ include/grpc/support/cpu.h \ include/grpc/support/host_port.h \ include/grpc/support/log.h \ include/grpc/support/log_windows.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 \ @@ -3653,6 +3648,7 @@ LIBGRPC_TEST_UTIL_SRC = \ test/core/end2end/fixtures/http_proxy_fixture.cc \ test/core/end2end/fixtures/proxy.cc \ test/core/iomgr/endpoint_tests.cc \ + test/core/util/cmdline.cc \ test/core/util/debugger_macros.cc \ test/core/util/grpc_profiler.cc \ test/core/util/histogram.cc \ @@ -3664,6 +3660,8 @@ LIBGRPC_TEST_UTIL_SRC = \ test/core/util/port_isolated_runtime_environment.cc \ test/core/util/port_server_client.cc \ test/core/util/slice_splitter.cc \ + test/core/util/subprocess_posix.cc \ + test/core/util/subprocess_windows.cc \ test/core/util/tracer_util.cc \ test/core/util/trickle_endpoint.cc \ src/core/lib/backoff/backoff.cc \ @@ -3915,6 +3913,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ test/core/end2end/fixtures/http_proxy_fixture.cc \ test/core/end2end/fixtures/proxy.cc \ test/core/iomgr/endpoint_tests.cc \ + test/core/util/cmdline.cc \ test/core/util/debugger_macros.cc \ test/core/util/grpc_profiler.cc \ test/core/util/histogram.cc \ @@ -3926,6 +3925,8 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ test/core/util/port_isolated_runtime_environment.cc \ test/core/util/port_server_client.cc \ test/core/util/slice_splitter.cc \ + test/core/util/subprocess_posix.cc \ + test/core/util/subprocess_windows.cc \ test/core/util/tracer_util.cc \ test/core/util/trickle_endpoint.cc \ src/core/lib/backoff/backoff.cc \ @@ -4629,14 +4630,12 @@ PUBLIC_HEADERS_CXX += \ include/grpc/support/atm_gcc_sync.h \ include/grpc/support/atm_windows.h \ include/grpc/support/avl.h \ - include/grpc/support/cmdline.h \ include/grpc/support/cpu.h \ include/grpc/support/host_port.h \ include/grpc/support/log.h \ include/grpc/support/log_windows.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 \ @@ -5118,14 +5117,12 @@ PUBLIC_HEADERS_CXX += \ include/grpc/support/atm_gcc_sync.h \ include/grpc/support/atm_windows.h \ include/grpc/support/avl.h \ - include/grpc/support/cmdline.h \ include/grpc/support/cpu.h \ include/grpc/support/host_port.h \ include/grpc/support/log.h \ include/grpc/support/log_windows.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 \ @@ -5837,14 +5834,12 @@ PUBLIC_HEADERS_CXX += \ include/grpc/support/atm_gcc_sync.h \ include/grpc/support/atm_windows.h \ include/grpc/support/avl.h \ - include/grpc/support/cmdline.h \ include/grpc/support/cpu.h \ include/grpc/support/host_port.h \ include/grpc/support/log.h \ include/grpc/support/log_windows.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 \ @@ -9267,6 +9262,38 @@ endif endif +CMDLINE_TEST_SRC = \ + test/core/util/cmdline_test.cc \ + +CMDLINE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CMDLINE_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/cmdline_test: openssl_dep_error + +else + + + +$(BINDIR)/$(CONFIG)/cmdline_test: $(CMDLINE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LD) $(LDFLAGS) $(CMDLINE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/cmdline_test + +endif + +$(OBJDIR)/$(CONFIG)/test/core/util/cmdline_test.o: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a + +deps_cmdline_test: $(CMDLINE_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(CMDLINE_TEST_OBJS:.o=.dep) +endif +endif + + COMBINER_TEST_SRC = \ test/core/iomgr/combiner_test.cc \ @@ -9910,38 +9937,6 @@ endif endif -GPR_CMDLINE_TEST_SRC = \ - test/core/gpr/cmdline_test.cc \ - -GPR_CMDLINE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GPR_CMDLINE_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/gpr_cmdline_test: openssl_dep_error - -else - - - -$(BINDIR)/$(CONFIG)/gpr_cmdline_test: $(GPR_CMDLINE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(GPR_CMDLINE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/gpr_cmdline_test - -endif - -$(OBJDIR)/$(CONFIG)/test/core/gpr/cmdline_test.o: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_gpr_cmdline_test: $(GPR_CMDLINE_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(GPR_CMDLINE_TEST_OBJS:.o=.dep) -endif -endif - - GPR_CPU_TEST_SRC = \ test/core/gpr/cpu_test.cc \ @@ -10628,14 +10623,14 @@ else -$(BINDIR)/$(CONFIG)/grpc_create_jwt: $(GRPC_CREATE_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/grpc_create_jwt: $(GRPC_CREATE_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(GRPC_CREATE_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_create_jwt + $(Q) $(LD) $(LDFLAGS) $(GRPC_CREATE_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_create_jwt endif -$(OBJDIR)/$(CONFIG)/test/core/security/create_jwt.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/security/create_jwt.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_grpc_create_jwt: $(GRPC_CREATE_JWT_OBJS:.o=.dep) @@ -10820,14 +10815,14 @@ else -$(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token: $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token: $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token + $(Q) $(LD) $(LDFLAGS) $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token endif -$(OBJDIR)/$(CONFIG)/test/core/security/print_google_default_creds_token.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/security/print_google_default_creds_token.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_grpc_print_google_default_creds_token: $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS:.o=.dep) @@ -10916,14 +10911,14 @@ else -$(BINDIR)/$(CONFIG)/grpc_verify_jwt: $(GRPC_VERIFY_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/grpc_verify_jwt: $(GRPC_VERIFY_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(GRPC_VERIFY_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_verify_jwt + $(Q) $(LD) $(LDFLAGS) $(GRPC_VERIFY_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_verify_jwt endif -$(OBJDIR)/$(CONFIG)/test/core/security/verify_jwt.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/security/verify_jwt.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_grpc_verify_jwt: $(GRPC_VERIFY_JWT_OBJS:.o=.dep) @@ -11466,14 +11461,14 @@ else -$(BINDIR)/$(CONFIG)/json_rewrite: $(JSON_REWRITE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/json_rewrite: $(JSON_REWRITE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(JSON_REWRITE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/json_rewrite + $(Q) $(LD) $(LDFLAGS) $(JSON_REWRITE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/json_rewrite endif -$(OBJDIR)/$(CONFIG)/test/core/json/json_rewrite.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/json/json_rewrite.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_json_rewrite: $(JSON_REWRITE_OBJS:.o=.dep) diff --git a/build.yaml b/build.yaml index d4d5af1371..3564d465fb 100644 --- a/build.yaml +++ b/build.yaml @@ -30,7 +30,6 @@ filegroups: - src/core/lib/gpr/arena.cc - src/core/lib/gpr/atm.cc - src/core/lib/gpr/avl.cc - - src/core/lib/gpr/cmdline.cc - src/core/lib/gpr/cpu_iphone.cc - src/core/lib/gpr/cpu_linux.cc - src/core/lib/gpr/cpu_posix.cc @@ -51,8 +50,6 @@ filegroups: - src/core/lib/gpr/string_posix.cc - src/core/lib/gpr/string_util_windows.cc - src/core/lib/gpr/string_windows.cc - - src/core/lib/gpr/subprocess_posix.cc - - src/core/lib/gpr/subprocess_windows.cc - src/core/lib/gpr/sync.cc - src/core/lib/gpr/sync_posix.cc - src/core/lib/gpr/sync_windows.cc @@ -80,14 +77,12 @@ filegroups: - include/grpc/support/atm_gcc_sync.h - include/grpc/support/atm_windows.h - include/grpc/support/avl.h - - include/grpc/support/cmdline.h - include/grpc/support/cpu.h - include/grpc/support/host_port.h - include/grpc/support/log.h - include/grpc/support/log_windows.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 @@ -715,6 +710,7 @@ filegroups: - test/core/end2end/fixtures/http_proxy_fixture.h - test/core/end2end/fixtures/proxy.h - test/core/iomgr/endpoint_tests.h + - test/core/util/cmdline.h - test/core/util/debugger_macros.h - test/core/util/grpc_profiler.h - test/core/util/histogram.h @@ -725,6 +721,7 @@ filegroups: - test/core/util/port.h - test/core/util/port_server_client.h - test/core/util/slice_splitter.h + - test/core/util/subprocess.h - test/core/util/tracer_util.h - test/core/util/trickle_endpoint.h src: @@ -733,6 +730,7 @@ filegroups: - test/core/end2end/fixtures/http_proxy_fixture.cc - test/core/end2end/fixtures/proxy.cc - test/core/iomgr/endpoint_tests.cc + - test/core/util/cmdline.cc - test/core/util/debugger_macros.cc - test/core/util/grpc_profiler.cc - test/core/util/histogram.cc @@ -744,6 +742,8 @@ filegroups: - test/core/util/port_isolated_runtime_environment.cc - test/core/util/port_server_client.cc - test/core/util/slice_splitter.cc + - test/core/util/subprocess_posix.cc + - test/core/util/subprocess_windows.cc - test/core/util/tracer_util.cc - test/core/util/trickle_endpoint.cc deps: @@ -1881,6 +1881,16 @@ targets: - test/core/end2end/fuzzers/client_fuzzer_corpus dict: test/core/end2end/fuzzers/hpack.dictionary maxlen: 2048 +- name: cmdline_test + build: test + language: c + src: + - test/core/util/cmdline_test.cc + deps: + - gpr + - gpr_test_util + - grpc_test_util + uses_polling: false - name: combiner_test cpu_cost: 10 build: test @@ -2141,15 +2151,6 @@ targets: - gpr_test_util - gpr uses_polling: false -- name: gpr_cmdline_test - build: test - language: c - src: - - test/core/gpr/cmdline_test.cc - deps: - - gpr_test_util - - gpr - uses_polling: false - name: gpr_cpu_test cpu_cost: 30 build: test @@ -2366,7 +2367,9 @@ targets: src: - test/core/security/create_jwt.cc deps: + - grpc_test_util - grpc + - gpr_test_util - gpr secure: true uses_polling: false @@ -2434,7 +2437,9 @@ targets: src: - test/core/security/print_google_default_creds_token.cc deps: + - grpc_test_util - grpc + - gpr_test_util - gpr uses_polling: false - name: grpc_security_connector_test @@ -2463,7 +2468,9 @@ targets: src: - test/core/security/verify_jwt.cc deps: + - grpc_test_util - grpc + - gpr_test_util - gpr uses_polling: false - name: handshake_client @@ -2679,7 +2686,9 @@ targets: src: - test/core/json/json_rewrite.cc deps: + - grpc_test_util - grpc + - gpr_test_util - gpr uses_polling: false - name: json_rewrite_test diff --git a/config.m4 b/config.m4 index 9fc624d880..774cf1bcc3 100644 --- a/config.m4 +++ b/config.m4 @@ -43,7 +43,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/gpr/arena.cc \ src/core/lib/gpr/atm.cc \ src/core/lib/gpr/avl.cc \ - src/core/lib/gpr/cmdline.cc \ src/core/lib/gpr/cpu_iphone.cc \ src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_posix.cc \ @@ -64,8 +63,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/gpr/string_posix.cc \ src/core/lib/gpr/string_util_windows.cc \ src/core/lib/gpr/string_windows.cc \ - src/core/lib/gpr/subprocess_posix.cc \ - src/core/lib/gpr/subprocess_windows.cc \ src/core/lib/gpr/sync.cc \ src/core/lib/gpr/sync_posix.cc \ src/core/lib/gpr/sync_windows.cc \ diff --git a/config.w32 b/config.w32 index bb9a17da33..e3fc4a66a1 100644 --- a/config.w32 +++ b/config.w32 @@ -20,7 +20,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\gpr\\arena.cc " + "src\\core\\lib\\gpr\\atm.cc " + "src\\core\\lib\\gpr\\avl.cc " + - "src\\core\\lib\\gpr\\cmdline.cc " + "src\\core\\lib\\gpr\\cpu_iphone.cc " + "src\\core\\lib\\gpr\\cpu_linux.cc " + "src\\core\\lib\\gpr\\cpu_posix.cc " + @@ -41,8 +40,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\gpr\\string_posix.cc " + "src\\core\\lib\\gpr\\string_util_windows.cc " + "src\\core\\lib\\gpr\\string_windows.cc " + - "src\\core\\lib\\gpr\\subprocess_posix.cc " + - "src\\core\\lib\\gpr\\subprocess_windows.cc " + "src\\core\\lib\\gpr\\sync.cc " + "src\\core\\lib\\gpr\\sync_posix.cc " + "src\\core\\lib\\gpr\\sync_windows.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 55f33d9aef..5236cda02e 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -618,6 +618,7 @@ Pod::Spec.new do |s| 'test/core/end2end/fixtures/http_proxy_fixture.h', 'test/core/end2end/fixtures/proxy.h', 'test/core/iomgr/endpoint_tests.h', + 'test/core/util/cmdline.h', 'test/core/util/debugger_macros.h', 'test/core/util/grpc_profiler.h', 'test/core/util/histogram.h', @@ -628,6 +629,7 @@ Pod::Spec.new do |s| 'test/core/util/port.h', 'test/core/util/port_server_client.h', 'test/core/util/slice_splitter.h', + 'test/core/util/subprocess.h', 'test/core/util/tracer_util.h', 'test/core/util/trickle_endpoint.h', 'src/core/ext/filters/client_channel/backup_poller.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 7ee7bb52d2..23a01010d0 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -115,14 +115,12 @@ Pod::Spec.new do |s| 'include/grpc/support/atm_gcc_sync.h', 'include/grpc/support/atm_windows.h', 'include/grpc/support/avl.h', - 'include/grpc/support/cmdline.h', 'include/grpc/support/cpu.h', 'include/grpc/support/host_port.h', 'include/grpc/support/log.h', 'include/grpc/support/log_windows.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', @@ -215,7 +213,6 @@ Pod::Spec.new do |s| 'src/core/lib/gpr/arena.cc', 'src/core/lib/gpr/atm.cc', 'src/core/lib/gpr/avl.cc', - 'src/core/lib/gpr/cmdline.cc', 'src/core/lib/gpr/cpu_iphone.cc', 'src/core/lib/gpr/cpu_linux.cc', 'src/core/lib/gpr/cpu_posix.cc', @@ -236,8 +233,6 @@ Pod::Spec.new do |s| 'src/core/lib/gpr/string_posix.cc', 'src/core/lib/gpr/string_util_windows.cc', 'src/core/lib/gpr/string_windows.cc', - 'src/core/lib/gpr/subprocess_posix.cc', - 'src/core/lib/gpr/subprocess_windows.cc', 'src/core/lib/gpr/sync.cc', 'src/core/lib/gpr/sync_posix.cc', 'src/core/lib/gpr/sync_windows.cc', @@ -993,6 +988,7 @@ Pod::Spec.new do |s| 'test/core/end2end/fixtures/http_proxy_fixture.cc', 'test/core/end2end/fixtures/proxy.cc', 'test/core/iomgr/endpoint_tests.cc', + 'test/core/util/cmdline.cc', 'test/core/util/debugger_macros.cc', 'test/core/util/grpc_profiler.cc', 'test/core/util/histogram.cc', @@ -1004,6 +1000,8 @@ Pod::Spec.new do |s| 'test/core/util/port_isolated_runtime_environment.cc', 'test/core/util/port_server_client.cc', 'test/core/util/slice_splitter.cc', + 'test/core/util/subprocess_posix.cc', + 'test/core/util/subprocess_windows.cc', 'test/core/util/tracer_util.cc', 'test/core/util/trickle_endpoint.cc', 'test/core/end2end/data/ssl_test_data.h', @@ -1012,6 +1010,7 @@ Pod::Spec.new do |s| 'test/core/end2end/fixtures/http_proxy_fixture.h', 'test/core/end2end/fixtures/proxy.h', 'test/core/iomgr/endpoint_tests.h', + 'test/core/util/cmdline.h', 'test/core/util/debugger_macros.h', 'test/core/util/grpc_profiler.h', 'test/core/util/histogram.h', @@ -1022,6 +1021,7 @@ Pod::Spec.new do |s| 'test/core/util/port.h', 'test/core/util/port_server_client.h', 'test/core/util/slice_splitter.h', + 'test/core/util/subprocess.h', 'test/core/util/tracer_util.h', 'test/core/util/trickle_endpoint.h', 'test/core/end2end/end2end_tests.cc', diff --git a/grpc.def b/grpc.def index 2bec47480a..28589b10f0 100644 --- a/grpc.def +++ b/grpc.def @@ -190,15 +190,6 @@ EXPORTS gpr_avl_get gpr_avl_maybe_get gpr_avl_is_empty - gpr_cmdline_create - gpr_cmdline_add_int - gpr_cmdline_add_flag - gpr_cmdline_add_string - gpr_cmdline_on_extra_arg - gpr_cmdline_set_survive_failure - gpr_cmdline_parse - gpr_cmdline_destroy - gpr_cmdline_usage_string gpr_cpu_num_cores gpr_cpu_current_cpu gpr_join_host_port @@ -212,11 +203,6 @@ EXPORTS gpr_format_message gpr_strdup gpr_asprintf - gpr_subprocess_binary_extension - gpr_subprocess_create - gpr_subprocess_destroy - gpr_subprocess_join - gpr_subprocess_interrupt gpr_mu_init gpr_mu_destroy gpr_mu_lock diff --git a/grpc.gemspec b/grpc.gemspec index 41e56d0bf1..86d6408c8c 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -50,14 +50,12 @@ Gem::Specification.new do |s| s.files += %w( include/grpc/support/atm_gcc_sync.h ) s.files += %w( include/grpc/support/atm_windows.h ) s.files += %w( include/grpc/support/avl.h ) - s.files += %w( include/grpc/support/cmdline.h ) s.files += %w( include/grpc/support/cpu.h ) s.files += %w( include/grpc/support/host_port.h ) s.files += %w( include/grpc/support/log.h ) s.files += %w( include/grpc/support/log_windows.h ) s.files += %w( include/grpc/support/port_platform.h ) s.files += %w( include/grpc/support/string_util.h ) - s.files += %w( include/grpc/support/subprocess.h ) s.files += %w( include/grpc/support/sync.h ) s.files += %w( include/grpc/support/sync_custom.h ) s.files += %w( include/grpc/support/sync_generic.h ) @@ -105,7 +103,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/gpr/arena.cc ) s.files += %w( src/core/lib/gpr/atm.cc ) s.files += %w( src/core/lib/gpr/avl.cc ) - s.files += %w( src/core/lib/gpr/cmdline.cc ) s.files += %w( src/core/lib/gpr/cpu_iphone.cc ) s.files += %w( src/core/lib/gpr/cpu_linux.cc ) s.files += %w( src/core/lib/gpr/cpu_posix.cc ) @@ -126,8 +123,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/gpr/string_posix.cc ) s.files += %w( src/core/lib/gpr/string_util_windows.cc ) s.files += %w( src/core/lib/gpr/string_windows.cc ) - s.files += %w( src/core/lib/gpr/subprocess_posix.cc ) - s.files += %w( src/core/lib/gpr/subprocess_windows.cc ) s.files += %w( src/core/lib/gpr/sync.cc ) s.files += %w( src/core/lib/gpr/sync_posix.cc ) s.files += %w( src/core/lib/gpr/sync_windows.cc ) diff --git a/grpc.gyp b/grpc.gyp index 7b1178f898..b394b5e32b 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -165,7 +165,6 @@ 'src/core/lib/gpr/arena.cc', 'src/core/lib/gpr/atm.cc', 'src/core/lib/gpr/avl.cc', - 'src/core/lib/gpr/cmdline.cc', 'src/core/lib/gpr/cpu_iphone.cc', 'src/core/lib/gpr/cpu_linux.cc', 'src/core/lib/gpr/cpu_posix.cc', @@ -186,8 +185,6 @@ 'src/core/lib/gpr/string_posix.cc', 'src/core/lib/gpr/string_util_windows.cc', 'src/core/lib/gpr/string_windows.cc', - 'src/core/lib/gpr/subprocess_posix.cc', - 'src/core/lib/gpr/subprocess_windows.cc', 'src/core/lib/gpr/sync.cc', 'src/core/lib/gpr/sync_posix.cc', 'src/core/lib/gpr/sync_windows.cc', @@ -508,6 +505,7 @@ 'test/core/end2end/fixtures/http_proxy_fixture.cc', 'test/core/end2end/fixtures/proxy.cc', 'test/core/iomgr/endpoint_tests.cc', + 'test/core/util/cmdline.cc', 'test/core/util/debugger_macros.cc', 'test/core/util/grpc_profiler.cc', 'test/core/util/histogram.cc', @@ -519,6 +517,8 @@ 'test/core/util/port_isolated_runtime_environment.cc', 'test/core/util/port_server_client.cc', 'test/core/util/slice_splitter.cc', + 'test/core/util/subprocess_posix.cc', + 'test/core/util/subprocess_windows.cc', 'test/core/util/tracer_util.cc', 'test/core/util/trickle_endpoint.cc', 'src/core/lib/backoff/backoff.cc', @@ -722,6 +722,7 @@ 'test/core/end2end/fixtures/http_proxy_fixture.cc', 'test/core/end2end/fixtures/proxy.cc', 'test/core/iomgr/endpoint_tests.cc', + 'test/core/util/cmdline.cc', 'test/core/util/debugger_macros.cc', 'test/core/util/grpc_profiler.cc', 'test/core/util/histogram.cc', @@ -733,6 +734,8 @@ 'test/core/util/port_isolated_runtime_environment.cc', 'test/core/util/port_server_client.cc', 'test/core/util/slice_splitter.cc', + 'test/core/util/subprocess_posix.cc', + 'test/core/util/subprocess_windows.cc', 'test/core/util/tracer_util.cc', 'test/core/util/trickle_endpoint.cc', 'src/core/lib/backoff/backoff.cc', diff --git a/include/grpc/module.modulemap b/include/grpc/module.modulemap index d23072f556..8f0cd46ae0 100644 --- a/include/grpc/module.modulemap +++ b/include/grpc/module.modulemap @@ -5,14 +5,12 @@ framework module grpc { header "support/alloc.h" header "support/atm.h" header "support/avl.h" - header "support/cmdline.h" header "support/cpu.h" header "support/host_port.h" header "support/log.h" header "support/log_windows.h" header "support/port_platform.h" header "support/string_util.h" - header "support/subprocess.h" header "support/sync.h" header "support/sync_generic.h" header "support/thd.h" diff --git a/include/grpc/support/cmdline.h b/include/grpc/support/cmdline.h deleted file mode 100644 index c34a109fbd..0000000000 --- a/include/grpc/support/cmdline.h +++ /dev/null @@ -1,88 +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. - * - */ - -#ifndef GRPC_SUPPORT_CMDLINE_H -#define GRPC_SUPPORT_CMDLINE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** 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 */ -GPRAPI 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) */ -GPRAPI void gpr_cmdline_add_int(gpr_cmdline* cl, const char* name, - const char* help, int* value); -/** The same, for a boolean flag */ -GPRAPI void gpr_cmdline_add_flag(gpr_cmdline* cl, const char* name, - const char* help, int* value); -/** And for a string */ -GPRAPI void gpr_cmdline_add_string(gpr_cmdline* cl, const char* name, - const char* help, const char** value); -/** Set a callback for non-named arguments */ -GPRAPI 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 */ -GPRAPI 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 */ -GPRAPI int gpr_cmdline_parse(gpr_cmdline* cl, int argc, char** argv); -/** Destroy the parser */ -GPRAPI void gpr_cmdline_destroy(gpr_cmdline* cl); -/** Get a string describing usage */ -GPRAPI char* gpr_cmdline_usage_string(gpr_cmdline* cl, const char* argv0); - -#ifdef __cplusplus -} -#endif - -#endif /* GRPC_SUPPORT_CMDLINE_H */ diff --git a/include/grpc/support/subprocess.h b/include/grpc/support/subprocess.h deleted file mode 100644 index 175f7b50eb..0000000000 --- a/include/grpc/support/subprocess.h +++ /dev/null @@ -1,44 +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. - * - */ - -#ifndef GRPC_SUPPORT_SUBPROCESS_H -#define GRPC_SUPPORT_SUBPROCESS_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct gpr_subprocess gpr_subprocess; - -/** .exe on windows, empty on unices */ -GPRAPI const char* gpr_subprocess_binary_extension(); - -GPRAPI gpr_subprocess* gpr_subprocess_create(int argc, const char** argv); -/** if subprocess has not been joined, kill it */ -GPRAPI void gpr_subprocess_destroy(gpr_subprocess* p); -/** returns exit status; can be called at most once */ -GPRAPI int gpr_subprocess_join(gpr_subprocess* p); -GPRAPI void gpr_subprocess_interrupt(gpr_subprocess* p); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif /* GRPC_SUPPORT_SUBPROCESS_H */ diff --git a/package.xml b/package.xml index 3f529a2096..7a7858af65 100644 --- a/package.xml +++ b/package.xml @@ -57,14 +57,12 @@ - - @@ -112,7 +110,6 @@ - @@ -133,8 +130,6 @@ - - diff --git a/src/core/lib/gpr/cmdline.cc b/src/core/lib/gpr/cmdline.cc deleted file mode 100644 index 4118f9a72a..0000000000 --- a/src/core/lib/gpr/cmdline.cc +++ /dev/null @@ -1,330 +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 - -#include -#include -#include - -#include -#include -#include -#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/src/core/lib/gpr/subprocess_posix.cc b/src/core/lib/gpr/subprocess_posix.cc deleted file mode 100644 index dc046b6499..0000000000 --- a/src/core/lib/gpr/subprocess_posix.cc +++ /dev/null @@ -1,99 +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 - -#ifdef GPR_POSIX_SUBPROCESS - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -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/src/core/lib/gpr/subprocess_windows.cc b/src/core/lib/gpr/subprocess_windows.cc deleted file mode 100644 index 1947d475e3..0000000000 --- a/src/core/lib/gpr/subprocess_windows.cc +++ /dev/null @@ -1,126 +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 - -#ifdef GPR_WINDOWS_SUBPROCESS - -#include -#include -#include - -#include -#include -#include -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/string_windows.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/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 86122f909c..d9ff181c6c 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -19,7 +19,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/gpr/arena.cc', 'src/core/lib/gpr/atm.cc', 'src/core/lib/gpr/avl.cc', - 'src/core/lib/gpr/cmdline.cc', 'src/core/lib/gpr/cpu_iphone.cc', 'src/core/lib/gpr/cpu_linux.cc', 'src/core/lib/gpr/cpu_posix.cc', @@ -40,8 +39,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/gpr/string_posix.cc', 'src/core/lib/gpr/string_util_windows.cc', 'src/core/lib/gpr/string_windows.cc', - 'src/core/lib/gpr/subprocess_posix.cc', - 'src/core/lib/gpr/subprocess_windows.cc', 'src/core/lib/gpr/sync.cc', 'src/core/lib/gpr/sync_posix.cc', 'src/core/lib/gpr/sync_windows.cc', diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 5473c52bb5..d52468ae55 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -213,15 +213,6 @@ gpr_avl_remove_type gpr_avl_remove_import; gpr_avl_get_type gpr_avl_get_import; gpr_avl_maybe_get_type gpr_avl_maybe_get_import; gpr_avl_is_empty_type gpr_avl_is_empty_import; -gpr_cmdline_create_type gpr_cmdline_create_import; -gpr_cmdline_add_int_type gpr_cmdline_add_int_import; -gpr_cmdline_add_flag_type gpr_cmdline_add_flag_import; -gpr_cmdline_add_string_type gpr_cmdline_add_string_import; -gpr_cmdline_on_extra_arg_type gpr_cmdline_on_extra_arg_import; -gpr_cmdline_set_survive_failure_type gpr_cmdline_set_survive_failure_import; -gpr_cmdline_parse_type gpr_cmdline_parse_import; -gpr_cmdline_destroy_type gpr_cmdline_destroy_import; -gpr_cmdline_usage_string_type gpr_cmdline_usage_string_import; gpr_cpu_num_cores_type gpr_cpu_num_cores_import; gpr_cpu_current_cpu_type gpr_cpu_current_cpu_import; gpr_join_host_port_type gpr_join_host_port_import; @@ -235,11 +226,6 @@ gpr_set_log_function_type gpr_set_log_function_import; gpr_format_message_type gpr_format_message_import; gpr_strdup_type gpr_strdup_import; gpr_asprintf_type gpr_asprintf_import; -gpr_subprocess_binary_extension_type gpr_subprocess_binary_extension_import; -gpr_subprocess_create_type gpr_subprocess_create_import; -gpr_subprocess_destroy_type gpr_subprocess_destroy_import; -gpr_subprocess_join_type gpr_subprocess_join_import; -gpr_subprocess_interrupt_type gpr_subprocess_interrupt_import; gpr_mu_init_type gpr_mu_init_import; gpr_mu_destroy_type gpr_mu_destroy_import; gpr_mu_lock_type gpr_mu_lock_import; @@ -486,15 +472,6 @@ void grpc_rb_load_imports(HMODULE library) { gpr_avl_get_import = (gpr_avl_get_type) GetProcAddress(library, "gpr_avl_get"); gpr_avl_maybe_get_import = (gpr_avl_maybe_get_type) GetProcAddress(library, "gpr_avl_maybe_get"); gpr_avl_is_empty_import = (gpr_avl_is_empty_type) GetProcAddress(library, "gpr_avl_is_empty"); - gpr_cmdline_create_import = (gpr_cmdline_create_type) GetProcAddress(library, "gpr_cmdline_create"); - gpr_cmdline_add_int_import = (gpr_cmdline_add_int_type) GetProcAddress(library, "gpr_cmdline_add_int"); - gpr_cmdline_add_flag_import = (gpr_cmdline_add_flag_type) GetProcAddress(library, "gpr_cmdline_add_flag"); - gpr_cmdline_add_string_import = (gpr_cmdline_add_string_type) GetProcAddress(library, "gpr_cmdline_add_string"); - gpr_cmdline_on_extra_arg_import = (gpr_cmdline_on_extra_arg_type) GetProcAddress(library, "gpr_cmdline_on_extra_arg"); - gpr_cmdline_set_survive_failure_import = (gpr_cmdline_set_survive_failure_type) GetProcAddress(library, "gpr_cmdline_set_survive_failure"); - gpr_cmdline_parse_import = (gpr_cmdline_parse_type) GetProcAddress(library, "gpr_cmdline_parse"); - gpr_cmdline_destroy_import = (gpr_cmdline_destroy_type) GetProcAddress(library, "gpr_cmdline_destroy"); - gpr_cmdline_usage_string_import = (gpr_cmdline_usage_string_type) GetProcAddress(library, "gpr_cmdline_usage_string"); gpr_cpu_num_cores_import = (gpr_cpu_num_cores_type) GetProcAddress(library, "gpr_cpu_num_cores"); gpr_cpu_current_cpu_import = (gpr_cpu_current_cpu_type) GetProcAddress(library, "gpr_cpu_current_cpu"); gpr_join_host_port_import = (gpr_join_host_port_type) GetProcAddress(library, "gpr_join_host_port"); @@ -508,11 +485,6 @@ void grpc_rb_load_imports(HMODULE library) { gpr_format_message_import = (gpr_format_message_type) GetProcAddress(library, "gpr_format_message"); gpr_strdup_import = (gpr_strdup_type) GetProcAddress(library, "gpr_strdup"); gpr_asprintf_import = (gpr_asprintf_type) GetProcAddress(library, "gpr_asprintf"); - gpr_subprocess_binary_extension_import = (gpr_subprocess_binary_extension_type) GetProcAddress(library, "gpr_subprocess_binary_extension"); - gpr_subprocess_create_import = (gpr_subprocess_create_type) GetProcAddress(library, "gpr_subprocess_create"); - gpr_subprocess_destroy_import = (gpr_subprocess_destroy_type) GetProcAddress(library, "gpr_subprocess_destroy"); - gpr_subprocess_join_import = (gpr_subprocess_join_type) GetProcAddress(library, "gpr_subprocess_join"); - gpr_subprocess_interrupt_import = (gpr_subprocess_interrupt_type) GetProcAddress(library, "gpr_subprocess_interrupt"); gpr_mu_init_import = (gpr_mu_init_type) GetProcAddress(library, "gpr_mu_init"); gpr_mu_destroy_import = (gpr_mu_destroy_type) GetProcAddress(library, "gpr_mu_destroy"); gpr_mu_lock_import = (gpr_mu_lock_type) GetProcAddress(library, "gpr_mu_lock"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index d701d2f571..afcf573863 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -35,13 +35,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -619,33 +617,6 @@ extern gpr_avl_maybe_get_type gpr_avl_maybe_get_import; typedef int(*gpr_avl_is_empty_type)(gpr_avl avl); extern gpr_avl_is_empty_type gpr_avl_is_empty_import; #define gpr_avl_is_empty gpr_avl_is_empty_import -typedef gpr_cmdline*(*gpr_cmdline_create_type)(const char* description); -extern gpr_cmdline_create_type gpr_cmdline_create_import; -#define gpr_cmdline_create gpr_cmdline_create_import -typedef void(*gpr_cmdline_add_int_type)(gpr_cmdline* cl, const char* name, const char* help, int* value); -extern gpr_cmdline_add_int_type gpr_cmdline_add_int_import; -#define gpr_cmdline_add_int gpr_cmdline_add_int_import -typedef void(*gpr_cmdline_add_flag_type)(gpr_cmdline* cl, const char* name, const char* help, int* value); -extern gpr_cmdline_add_flag_type gpr_cmdline_add_flag_import; -#define gpr_cmdline_add_flag gpr_cmdline_add_flag_import -typedef void(*gpr_cmdline_add_string_type)(gpr_cmdline* cl, const char* name, const char* help, const char** value); -extern gpr_cmdline_add_string_type gpr_cmdline_add_string_import; -#define gpr_cmdline_add_string gpr_cmdline_add_string_import -typedef void(*gpr_cmdline_on_extra_arg_type)(gpr_cmdline* cl, const char* name, const char* help, void (*on_extra_arg)(void* user_data, const char* arg), void* user_data); -extern gpr_cmdline_on_extra_arg_type gpr_cmdline_on_extra_arg_import; -#define gpr_cmdline_on_extra_arg gpr_cmdline_on_extra_arg_import -typedef void(*gpr_cmdline_set_survive_failure_type)(gpr_cmdline* cl); -extern gpr_cmdline_set_survive_failure_type gpr_cmdline_set_survive_failure_import; -#define gpr_cmdline_set_survive_failure gpr_cmdline_set_survive_failure_import -typedef int(*gpr_cmdline_parse_type)(gpr_cmdline* cl, int argc, char** argv); -extern gpr_cmdline_parse_type gpr_cmdline_parse_import; -#define gpr_cmdline_parse gpr_cmdline_parse_import -typedef void(*gpr_cmdline_destroy_type)(gpr_cmdline* cl); -extern gpr_cmdline_destroy_type gpr_cmdline_destroy_import; -#define gpr_cmdline_destroy gpr_cmdline_destroy_import -typedef char*(*gpr_cmdline_usage_string_type)(gpr_cmdline* cl, const char* argv0); -extern gpr_cmdline_usage_string_type gpr_cmdline_usage_string_import; -#define gpr_cmdline_usage_string gpr_cmdline_usage_string_import typedef unsigned(*gpr_cpu_num_cores_type)(void); extern gpr_cpu_num_cores_type gpr_cpu_num_cores_import; #define gpr_cpu_num_cores gpr_cpu_num_cores_import @@ -685,21 +656,6 @@ extern gpr_strdup_type gpr_strdup_import; typedef int(*gpr_asprintf_type)(char** strp, const char* format, ...) GPR_PRINT_FORMAT_CHECK(2, 3); extern gpr_asprintf_type gpr_asprintf_import; #define gpr_asprintf gpr_asprintf_import -typedef const char*(*gpr_subprocess_binary_extension_type)(); -extern gpr_subprocess_binary_extension_type gpr_subprocess_binary_extension_import; -#define gpr_subprocess_binary_extension gpr_subprocess_binary_extension_import -typedef gpr_subprocess*(*gpr_subprocess_create_type)(int argc, const char** argv); -extern gpr_subprocess_create_type gpr_subprocess_create_import; -#define gpr_subprocess_create gpr_subprocess_create_import -typedef void(*gpr_subprocess_destroy_type)(gpr_subprocess* p); -extern gpr_subprocess_destroy_type gpr_subprocess_destroy_import; -#define gpr_subprocess_destroy gpr_subprocess_destroy_import -typedef int(*gpr_subprocess_join_type)(gpr_subprocess* p); -extern gpr_subprocess_join_type gpr_subprocess_join_import; -#define gpr_subprocess_join gpr_subprocess_join_import -typedef void(*gpr_subprocess_interrupt_type)(gpr_subprocess* p); -extern gpr_subprocess_interrupt_type gpr_subprocess_interrupt_import; -#define gpr_subprocess_interrupt gpr_subprocess_interrupt_import typedef void(*gpr_mu_init_type)(gpr_mu* mu); extern gpr_mu_init_type gpr_mu_init_import; #define gpr_mu_init gpr_mu_init_import diff --git a/test/core/bad_ssl/bad_ssl_test.cc b/test/core/bad_ssl/bad_ssl_test.cc index 8a7960b5ed..1979ecbb17 100644 --- a/test/core/bad_ssl/bad_ssl_test.cc +++ b/test/core/bad_ssl/bad_ssl_test.cc @@ -25,11 +25,11 @@ #include #include #include -#include #include "src/core/lib/gpr/env.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 #include #include #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/fling/client.cc b/test/core/fling/client.cc index 28e62e0e83..b6d6cb9518 100644 --- a/test/core/fling/client.cc +++ b/test/core/fling/client.cc @@ -21,11 +21,11 @@ #include #include -#include #include #include #include #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 b5a5ce816e..48df6d5fb3 100644 --- a/test/core/fling/fling_stream_test.cc +++ b/test/core/fling/fling_stream_test.cc @@ -22,9 +22,10 @@ #include #include #include -#include + #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 3792e45c42..7586be234f 100644 --- a/test/core/fling/fling_test.cc +++ b/test/core/fling/fling_test.cc @@ -22,9 +22,10 @@ #include #include #include -#include + #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 f3a8a1ccf8..097730b5d7 100644 --- a/test/core/fling/server.cc +++ b/test/core/fling/server.cc @@ -30,12 +30,12 @@ #endif #include -#include #include #include #include #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 @@ -38,16 +38,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"], diff --git a/test/core/gpr/cmdline_test.cc b/test/core/gpr/cmdline_test.cc deleted file mode 100644 index 172efda8a0..0000000000 --- a/test/core/gpr/cmdline_test.cc +++ /dev/null @@ -1,491 +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 - -#include - -#include -#include -#include -#include "test/core/util/test_config.h" - -#define LOG_TEST() gpr_log(GPR_INFO, "test at %s:%d", __FILE__, __LINE__) - -static void test_simple_int(void) { - int x = 1; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("-foo"), - const_cast("3")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_int(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 1); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 3); - gpr_cmdline_destroy(cl); -} - -static void test_eq_int(void) { - int x = 1; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("-foo=3")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_int(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 1); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 3); - gpr_cmdline_destroy(cl); -} - -static void test_2dash_int(void) { - int x = 1; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo"), - const_cast("3")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_int(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 1); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 3); - gpr_cmdline_destroy(cl); -} - -static void test_2dash_eq_int(void) { - int x = 1; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=3")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_int(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 1); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 3); - gpr_cmdline_destroy(cl); -} - -static void test_simple_string(void) { - const char* x = nullptr; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("-foo"), - const_cast("3")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_string(cl, "foo", nullptr, &x); - GPR_ASSERT(x == nullptr); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(0 == strcmp(x, "3")); - gpr_cmdline_destroy(cl); -} - -static void test_eq_string(void) { - const char* x = nullptr; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("-foo=3")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_string(cl, "foo", nullptr, &x); - GPR_ASSERT(x == nullptr); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(0 == strcmp(x, "3")); - gpr_cmdline_destroy(cl); -} - -static void test_2dash_string(void) { - const char* x = nullptr; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo"), - const_cast("3")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_string(cl, "foo", nullptr, &x); - GPR_ASSERT(x == nullptr); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(0 == strcmp(x, "3")); - gpr_cmdline_destroy(cl); -} - -static void test_2dash_eq_string(void) { - const char* x = nullptr; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=3")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_string(cl, "foo", nullptr, &x); - GPR_ASSERT(x == nullptr); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(0 == strcmp(x, "3")); - gpr_cmdline_destroy(cl); -} - -static void test_flag_on(void) { - int x = 2; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_flag(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 2); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 1); - gpr_cmdline_destroy(cl); -} - -static void test_flag_no(void) { - int x = 2; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--no-foo")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_flag(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 2); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 0); - gpr_cmdline_destroy(cl); -} - -static void test_flag_val_1(void) { - int x = 2; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=1")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_flag(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 2); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 1); - gpr_cmdline_destroy(cl); -} - -static void test_flag_val_0(void) { - int x = 2; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=0")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_flag(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 2); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 0); - gpr_cmdline_destroy(cl); -} - -static void test_flag_val_true(void) { - int x = 2; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=true")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_flag(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 2); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 1); - gpr_cmdline_destroy(cl); -} - -static void test_flag_val_false(void) { - int x = 2; - gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=false")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_flag(cl, "foo", nullptr, &x); - GPR_ASSERT(x == 2); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 0); - gpr_cmdline_destroy(cl); -} - -static void test_many(void) { - const char* str = nullptr; - int x = 0; - int flag = 2; - gpr_cmdline* cl; - - char* args[] = {(char*)__FILE__, const_cast("--str"), - const_cast("hello"), const_cast("-x=4"), - const_cast("-no-flag")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_string(cl, "str", nullptr, &str); - gpr_cmdline_add_int(cl, "x", nullptr, &x); - gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(x == 4); - GPR_ASSERT(0 == strcmp(str, "hello")); - GPR_ASSERT(flag == 0); - gpr_cmdline_destroy(cl); -} - -static void extra_arg_cb(void* user_data, const char* arg) { - int* count = static_cast(user_data); - GPR_ASSERT(arg != nullptr); - GPR_ASSERT(strlen(arg) == 1); - GPR_ASSERT(arg[0] == 'a' + *count); - ++*count; -} - -static void test_extra(void) { - gpr_cmdline* cl; - int count = 0; - char* args[] = {(char*)__FILE__, const_cast("a"), - const_cast("b"), const_cast("c")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, - &count); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(count == 3); - gpr_cmdline_destroy(cl); -} - -static void test_extra_dashdash(void) { - gpr_cmdline* cl; - int count = 0; - char* args[] = {(char*)__FILE__, const_cast("--"), - const_cast("a"), const_cast("b"), - const_cast("c")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, - &count); - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); - GPR_ASSERT(count == 3); - gpr_cmdline_destroy(cl); -} - -static void test_usage(void) { - gpr_cmdline* cl; - char* usage; - - const char* str = nullptr; - int x = 0; - int flag = 2; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_string(cl, "str", nullptr, &str); - gpr_cmdline_add_int(cl, "x", nullptr, &x); - gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); - gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, - nullptr); - - usage = gpr_cmdline_usage_string(cl, "test"); - GPR_ASSERT(0 == strcmp(usage, - "Usage: test [--str=string] [--x=int] " - "[--flag|--no-flag] [file...]\n")); - gpr_free(usage); - - usage = gpr_cmdline_usage_string(cl, "/foo/test"); - GPR_ASSERT(0 == strcmp(usage, - "Usage: test [--str=string] [--x=int] " - "[--flag|--no-flag] [file...]\n")); - gpr_free(usage); - - gpr_cmdline_destroy(cl); -} - -static void test_help(void) { - gpr_cmdline* cl; - - const char* str = nullptr; - int x = 0; - int flag = 2; - - char* help[] = {(char*)__FILE__, const_cast("-h")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_set_survive_failure(cl); - gpr_cmdline_add_string(cl, "str", nullptr, &str); - gpr_cmdline_add_int(cl, "x", nullptr, &x); - gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); - gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, - nullptr); - - GPR_ASSERT(0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(help), help)); - - gpr_cmdline_destroy(cl); -} - -static void test_badargs1(void) { - gpr_cmdline* cl; - - const char* str = nullptr; - int x = 0; - int flag = 2; - - char* bad_arg_name[] = {(char*)__FILE__, const_cast("--y")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_set_survive_failure(cl); - gpr_cmdline_add_string(cl, "str", nullptr, &str); - gpr_cmdline_add_int(cl, "x", nullptr, &x); - gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); - gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, - nullptr); - - GPR_ASSERT(0 == - gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_arg_name), bad_arg_name)); - - gpr_cmdline_destroy(cl); -} - -static void test_badargs2(void) { - gpr_cmdline* cl; - - const char* str = nullptr; - int x = 0; - int flag = 2; - - char* bad_int_value[] = {(char*)__FILE__, const_cast("--x"), - const_cast("henry")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_set_survive_failure(cl); - gpr_cmdline_add_string(cl, "str", nullptr, &str); - gpr_cmdline_add_int(cl, "x", nullptr, &x); - gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); - gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, - nullptr); - - GPR_ASSERT( - 0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_int_value), bad_int_value)); - - gpr_cmdline_destroy(cl); -} - -static void test_badargs3(void) { - gpr_cmdline* cl; - - const char* str = nullptr; - int x = 0; - int flag = 2; - - char* bad_bool_value[] = {(char*)__FILE__, const_cast("--flag=henry")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_set_survive_failure(cl); - gpr_cmdline_add_string(cl, "str", nullptr, &str); - gpr_cmdline_add_int(cl, "x", nullptr, &x); - gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); - gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, - nullptr); - - GPR_ASSERT(0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_bool_value), - bad_bool_value)); - - gpr_cmdline_destroy(cl); -} - -static void test_badargs4(void) { - gpr_cmdline* cl; - - const char* str = nullptr; - int x = 0; - int flag = 2; - - char* bad_bool_value[] = {(char*)__FILE__, const_cast("--no-str")}; - - LOG_TEST(); - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_set_survive_failure(cl); - gpr_cmdline_add_string(cl, "str", nullptr, &str); - gpr_cmdline_add_int(cl, "x", nullptr, &x); - gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); - gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, - nullptr); - - GPR_ASSERT(0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_bool_value), - bad_bool_value)); - - gpr_cmdline_destroy(cl); -} - -int main(int argc, char** argv) { - grpc_test_init(argc, argv); - test_simple_int(); - test_eq_int(); - test_2dash_int(); - test_2dash_eq_int(); - test_simple_string(); - test_eq_string(); - test_2dash_string(); - test_2dash_eq_string(); - test_flag_on(); - test_flag_no(); - test_flag_val_1(); - test_flag_val_0(); - test_flag_val_true(); - test_flag_val_false(); - test_many(); - test_extra(); - test_extra_dashdash(); - test_usage(); - test_help(); - test_badargs1(); - test_badargs2(); - test_badargs3(); - test_badargs4(); - return 0; -} diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index 259e3aa463..aa9416c3dd 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -24,10 +24,11 @@ #include #include #include -#include #include + #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 adf69f1b16..ed2016e643 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -24,10 +24,11 @@ #include #include #include -#include #include + #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 #include -#include #include #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 #include #include -#include #include #include #include #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 fb6d290130..bf248c92ba 100644 --- a/test/core/memory_usage/memory_usage_test.cc +++ b/test/core/memory_usage/memory_usage_test.cc @@ -22,9 +22,10 @@ #include #include #include -#include + #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 60ebcece3e..4303ec70ec 100644 --- a/test/core/memory_usage/server.cc +++ b/test/core/memory_usage/server.cc @@ -30,11 +30,11 @@ #endif #include -#include #include #include #include #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 #include -#include #include #include #include #include #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 #include -#include #include +#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 #include #include -#include #include #include #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 #include #include -#include #include #include @@ -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 #include #include -#include #include #include #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/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index f4de5d7d8a..a191987577 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -48,13 +48,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -255,15 +253,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_join_host_port); @@ -276,11 +265,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/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 +#include +#include + +#include +#include +#include +#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..54f45167fa --- /dev/null +++ b/test/core/util/cmdline.h @@ -0,0 +1,88 @@ +/* + * + * 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 + +#ifdef __cplusplus +extern "C" { +#endif + +/** 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); + +#ifdef __cplusplus +} +#endif + +#endif /* GRPC_TEST_CORE_UTIL_CMDLINE_H */ diff --git a/test/core/util/cmdline_test.cc b/test/core/util/cmdline_test.cc new file mode 100644 index 0000000000..ed4412aa9f --- /dev/null +++ b/test/core/util/cmdline_test.cc @@ -0,0 +1,491 @@ +/* + * + * 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 + +#include +#include +#include + +#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__) + +static void test_simple_int(void) { + int x = 1; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("-foo"), + const_cast("3")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_int(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 1); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 3); + gpr_cmdline_destroy(cl); +} + +static void test_eq_int(void) { + int x = 1; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("-foo=3")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_int(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 1); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 3); + gpr_cmdline_destroy(cl); +} + +static void test_2dash_int(void) { + int x = 1; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--foo"), + const_cast("3")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_int(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 1); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 3); + gpr_cmdline_destroy(cl); +} + +static void test_2dash_eq_int(void) { + int x = 1; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--foo=3")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_int(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 1); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 3); + gpr_cmdline_destroy(cl); +} + +static void test_simple_string(void) { + const char* x = nullptr; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("-foo"), + const_cast("3")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_string(cl, "foo", nullptr, &x); + GPR_ASSERT(x == nullptr); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(0 == strcmp(x, "3")); + gpr_cmdline_destroy(cl); +} + +static void test_eq_string(void) { + const char* x = nullptr; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("-foo=3")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_string(cl, "foo", nullptr, &x); + GPR_ASSERT(x == nullptr); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(0 == strcmp(x, "3")); + gpr_cmdline_destroy(cl); +} + +static void test_2dash_string(void) { + const char* x = nullptr; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--foo"), + const_cast("3")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_string(cl, "foo", nullptr, &x); + GPR_ASSERT(x == nullptr); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(0 == strcmp(x, "3")); + gpr_cmdline_destroy(cl); +} + +static void test_2dash_eq_string(void) { + const char* x = nullptr; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--foo=3")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_string(cl, "foo", nullptr, &x); + GPR_ASSERT(x == nullptr); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(0 == strcmp(x, "3")); + gpr_cmdline_destroy(cl); +} + +static void test_flag_on(void) { + int x = 2; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--foo")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_flag(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 2); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 1); + gpr_cmdline_destroy(cl); +} + +static void test_flag_no(void) { + int x = 2; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--no-foo")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_flag(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 2); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 0); + gpr_cmdline_destroy(cl); +} + +static void test_flag_val_1(void) { + int x = 2; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--foo=1")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_flag(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 2); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 1); + gpr_cmdline_destroy(cl); +} + +static void test_flag_val_0(void) { + int x = 2; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--foo=0")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_flag(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 2); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 0); + gpr_cmdline_destroy(cl); +} + +static void test_flag_val_true(void) { + int x = 2; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--foo=true")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_flag(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 2); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 1); + gpr_cmdline_destroy(cl); +} + +static void test_flag_val_false(void) { + int x = 2; + gpr_cmdline* cl; + char* args[] = {(char*)__FILE__, const_cast("--foo=false")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_flag(cl, "foo", nullptr, &x); + GPR_ASSERT(x == 2); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 0); + gpr_cmdline_destroy(cl); +} + +static void test_many(void) { + const char* str = nullptr; + int x = 0; + int flag = 2; + gpr_cmdline* cl; + + char* args[] = {(char*)__FILE__, const_cast("--str"), + const_cast("hello"), const_cast("-x=4"), + const_cast("-no-flag")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_string(cl, "str", nullptr, &str); + gpr_cmdline_add_int(cl, "x", nullptr, &x); + gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(x == 4); + GPR_ASSERT(0 == strcmp(str, "hello")); + GPR_ASSERT(flag == 0); + gpr_cmdline_destroy(cl); +} + +static void extra_arg_cb(void* user_data, const char* arg) { + int* count = static_cast(user_data); + GPR_ASSERT(arg != nullptr); + GPR_ASSERT(strlen(arg) == 1); + GPR_ASSERT(arg[0] == 'a' + *count); + ++*count; +} + +static void test_extra(void) { + gpr_cmdline* cl; + int count = 0; + char* args[] = {(char*)__FILE__, const_cast("a"), + const_cast("b"), const_cast("c")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, + &count); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(count == 3); + gpr_cmdline_destroy(cl); +} + +static void test_extra_dashdash(void) { + gpr_cmdline* cl; + int count = 0; + char* args[] = {(char*)__FILE__, const_cast("--"), + const_cast("a"), const_cast("b"), + const_cast("c")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, + &count); + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args); + GPR_ASSERT(count == 3); + gpr_cmdline_destroy(cl); +} + +static void test_usage(void) { + gpr_cmdline* cl; + char* usage; + + const char* str = nullptr; + int x = 0; + int flag = 2; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_add_string(cl, "str", nullptr, &str); + gpr_cmdline_add_int(cl, "x", nullptr, &x); + gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); + gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, + nullptr); + + usage = gpr_cmdline_usage_string(cl, "test"); + GPR_ASSERT(0 == strcmp(usage, + "Usage: test [--str=string] [--x=int] " + "[--flag|--no-flag] [file...]\n")); + gpr_free(usage); + + usage = gpr_cmdline_usage_string(cl, "/foo/test"); + GPR_ASSERT(0 == strcmp(usage, + "Usage: test [--str=string] [--x=int] " + "[--flag|--no-flag] [file...]\n")); + gpr_free(usage); + + gpr_cmdline_destroy(cl); +} + +static void test_help(void) { + gpr_cmdline* cl; + + const char* str = nullptr; + int x = 0; + int flag = 2; + + char* help[] = {(char*)__FILE__, const_cast("-h")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_set_survive_failure(cl); + gpr_cmdline_add_string(cl, "str", nullptr, &str); + gpr_cmdline_add_int(cl, "x", nullptr, &x); + gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); + gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, + nullptr); + + GPR_ASSERT(0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(help), help)); + + gpr_cmdline_destroy(cl); +} + +static void test_badargs1(void) { + gpr_cmdline* cl; + + const char* str = nullptr; + int x = 0; + int flag = 2; + + char* bad_arg_name[] = {(char*)__FILE__, const_cast("--y")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_set_survive_failure(cl); + gpr_cmdline_add_string(cl, "str", nullptr, &str); + gpr_cmdline_add_int(cl, "x", nullptr, &x); + gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); + gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, + nullptr); + + GPR_ASSERT(0 == + gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_arg_name), bad_arg_name)); + + gpr_cmdline_destroy(cl); +} + +static void test_badargs2(void) { + gpr_cmdline* cl; + + const char* str = nullptr; + int x = 0; + int flag = 2; + + char* bad_int_value[] = {(char*)__FILE__, const_cast("--x"), + const_cast("henry")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_set_survive_failure(cl); + gpr_cmdline_add_string(cl, "str", nullptr, &str); + gpr_cmdline_add_int(cl, "x", nullptr, &x); + gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); + gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, + nullptr); + + GPR_ASSERT( + 0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_int_value), bad_int_value)); + + gpr_cmdline_destroy(cl); +} + +static void test_badargs3(void) { + gpr_cmdline* cl; + + const char* str = nullptr; + int x = 0; + int flag = 2; + + char* bad_bool_value[] = {(char*)__FILE__, const_cast("--flag=henry")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_set_survive_failure(cl); + gpr_cmdline_add_string(cl, "str", nullptr, &str); + gpr_cmdline_add_int(cl, "x", nullptr, &x); + gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); + gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, + nullptr); + + GPR_ASSERT(0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_bool_value), + bad_bool_value)); + + gpr_cmdline_destroy(cl); +} + +static void test_badargs4(void) { + gpr_cmdline* cl; + + const char* str = nullptr; + int x = 0; + int flag = 2; + + char* bad_bool_value[] = {(char*)__FILE__, const_cast("--no-str")}; + + LOG_TEST(); + + cl = gpr_cmdline_create(nullptr); + gpr_cmdline_set_survive_failure(cl); + gpr_cmdline_add_string(cl, "str", nullptr, &str); + gpr_cmdline_add_int(cl, "x", nullptr, &x); + gpr_cmdline_add_flag(cl, "flag", nullptr, &flag); + gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb, + nullptr); + + GPR_ASSERT(0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_bool_value), + bad_bool_value)); + + gpr_cmdline_destroy(cl); +} + +int main(int argc, char** argv) { + grpc_test_init(argc, argv); + test_simple_int(); + test_eq_int(); + test_2dash_int(); + test_2dash_eq_int(); + test_simple_string(); + test_eq_string(); + test_2dash_string(); + test_2dash_eq_string(); + test_flag_on(); + test_flag_no(); + test_flag_val_1(); + test_flag_val_0(); + test_flag_val_true(); + test_flag_val_false(); + test_many(); + test_extra(); + test_extra_dashdash(); + test_usage(); + test_help(); + test_badargs1(); + test_badargs2(); + test_badargs3(); + test_badargs4(); + return 0; +} diff --git a/test/core/util/subprocess.h b/test/core/util/subprocess.h new file mode 100644 index 0000000000..7419de27bb --- /dev/null +++ b/test/core/util/subprocess.h @@ -0,0 +1,44 @@ +/* + * + * 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 + +#ifdef __cplusplus +extern "C" { +#endif + +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); + +#ifdef __cplusplus +} // extern "C" +#endif + +#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 + +#ifdef GPR_POSIX_SUBPROCESS + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#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 + +#ifdef GPR_WINDOWS_SUBPROCESS + +#include +#include +#include + +#include +#include +#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/util/BUILD b/test/cpp/util/BUILD index 19e15b1adf..8818999a50 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 -#include +#include "test/core/util/subprocess.h" namespace grpc { diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 6873256dcd..317dd0e1eb 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -911,14 +911,12 @@ include/grpc/support/atm_gcc_atomic.h \ include/grpc/support/atm_gcc_sync.h \ include/grpc/support/atm_windows.h \ include/grpc/support/avl.h \ -include/grpc/support/cmdline.h \ include/grpc/support/cpu.h \ include/grpc/support/host_port.h \ include/grpc/support/log.h \ include/grpc/support/log_windows.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 \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 2c6505ddad..3645d5d752 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -912,14 +912,12 @@ include/grpc/support/atm_gcc_atomic.h \ include/grpc/support/atm_gcc_sync.h \ include/grpc/support/atm_windows.h \ include/grpc/support/avl.h \ -include/grpc/support/cmdline.h \ include/grpc/support/cpu.h \ include/grpc/support/host_port.h \ include/grpc/support/log.h \ include/grpc/support/log_windows.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 \ diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index e2ccc78f56..da862ecb68 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -851,14 +851,12 @@ include/grpc/support/atm_gcc_atomic.h \ include/grpc/support/atm_gcc_sync.h \ include/grpc/support/atm_windows.h \ include/grpc/support/avl.h \ -include/grpc/support/cmdline.h \ include/grpc/support/cpu.h \ include/grpc/support/host_port.h \ include/grpc/support/log.h \ include/grpc/support/log_windows.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 \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 00057c2897..4c9841feab 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -851,14 +851,12 @@ include/grpc/support/atm_gcc_atomic.h \ include/grpc/support/atm_gcc_sync.h \ include/grpc/support/atm_windows.h \ include/grpc/support/avl.h \ -include/grpc/support/cmdline.h \ include/grpc/support/cpu.h \ include/grpc/support/host_port.h \ include/grpc/support/log.h \ include/grpc/support/log_windows.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 \ @@ -1074,7 +1072,6 @@ src/core/lib/gpr/arena.cc \ src/core/lib/gpr/arena.h \ src/core/lib/gpr/atm.cc \ src/core/lib/gpr/avl.cc \ -src/core/lib/gpr/cmdline.cc \ src/core/lib/gpr/cpu_iphone.cc \ src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_posix.cc \ @@ -1102,8 +1099,6 @@ src/core/lib/gpr/string_posix.cc \ src/core/lib/gpr/string_util_windows.cc \ src/core/lib/gpr/string_windows.cc \ src/core/lib/gpr/string_windows.h \ -src/core/lib/gpr/subprocess_posix.cc \ -src/core/lib/gpr/subprocess_windows.cc \ src/core/lib/gpr/sync.cc \ src/core/lib/gpr/sync_posix.cc \ src/core/lib/gpr/sync_windows.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index f61288b70d..bdbcb89b3c 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -264,6 +264,22 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c", + "name": "cmdline_test", + "src": [ + "test/core/util/cmdline_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", @@ -602,21 +618,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "gpr", - "gpr_test_util" - ], - "headers": [], - "is_filegroup": false, - "language": "c", - "name": "gpr_cmdline_test", - "src": [ - "test/core/gpr/cmdline_test.cc" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -951,7 +952,9 @@ { "deps": [ "gpr", - "grpc" + "gpr_test_util", + "grpc", + "grpc_test_util" ], "headers": [], "is_filegroup": false, @@ -1051,7 +1054,9 @@ { "deps": [ "gpr", - "grpc" + "gpr_test_util", + "grpc", + "grpc_test_util" ], "headers": [], "is_filegroup": false, @@ -1100,7 +1105,9 @@ { "deps": [ "gpr", - "grpc" + "gpr_test_util", + "grpc", + "grpc_test_util" ], "headers": [], "is_filegroup": false, @@ -1393,7 +1400,9 @@ { "deps": [ "gpr", - "grpc" + "gpr_test_util", + "grpc", + "grpc_test_util" ], "headers": [], "is_filegroup": false, @@ -7850,7 +7859,6 @@ "src/core/lib/gpr/arena.cc", "src/core/lib/gpr/atm.cc", "src/core/lib/gpr/avl.cc", - "src/core/lib/gpr/cmdline.cc", "src/core/lib/gpr/cpu_iphone.cc", "src/core/lib/gpr/cpu_linux.cc", "src/core/lib/gpr/cpu_posix.cc", @@ -7871,8 +7879,6 @@ "src/core/lib/gpr/string_posix.cc", "src/core/lib/gpr/string_util_windows.cc", "src/core/lib/gpr/string_windows.cc", - "src/core/lib/gpr/subprocess_posix.cc", - "src/core/lib/gpr/subprocess_windows.cc", "src/core/lib/gpr/sync.cc", "src/core/lib/gpr/sync_posix.cc", "src/core/lib/gpr/sync_windows.cc", @@ -7905,14 +7911,12 @@ "include/grpc/support/atm_gcc_sync.h", "include/grpc/support/atm_windows.h", "include/grpc/support/avl.h", - "include/grpc/support/cmdline.h", "include/grpc/support/cpu.h", "include/grpc/support/host_port.h", "include/grpc/support/log.h", "include/grpc/support/log_windows.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", @@ -7954,14 +7958,12 @@ "include/grpc/support/atm_gcc_sync.h", "include/grpc/support/atm_windows.h", "include/grpc/support/avl.h", - "include/grpc/support/cmdline.h", "include/grpc/support/cpu.h", "include/grpc/support/host_port.h", "include/grpc/support/log.h", "include/grpc/support/log_windows.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", @@ -9026,6 +9028,7 @@ "test/core/end2end/fixtures/http_proxy_fixture.h", "test/core/end2end/fixtures/proxy.h", "test/core/iomgr/endpoint_tests.h", + "test/core/util/cmdline.h", "test/core/util/debugger_macros.h", "test/core/util/grpc_profiler.h", "test/core/util/histogram.h", @@ -9036,6 +9039,7 @@ "test/core/util/port.h", "test/core/util/port_server_client.h", "test/core/util/slice_splitter.h", + "test/core/util/subprocess.h", "test/core/util/tracer_util.h", "test/core/util/trickle_endpoint.h" ], @@ -9053,6 +9057,8 @@ "test/core/end2end/fixtures/proxy.h", "test/core/iomgr/endpoint_tests.cc", "test/core/iomgr/endpoint_tests.h", + "test/core/util/cmdline.cc", + "test/core/util/cmdline.h", "test/core/util/debugger_macros.cc", "test/core/util/debugger_macros.h", "test/core/util/grpc_profiler.cc", @@ -9074,6 +9080,9 @@ "test/core/util/port_server_client.h", "test/core/util/slice_splitter.cc", "test/core/util/slice_splitter.h", + "test/core/util/subprocess.h", + "test/core/util/subprocess_posix.cc", + "test/core/util/subprocess_windows.cc", "test/core/util/tracer_util.cc", "test/core/util/tracer_util.h", "test/core/util/trickle_endpoint.cc", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 866e2c3280..8fd124014c 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -315,6 +315,30 @@ ], "uses_polling": false }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c", + "name": "cmdline_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false, @@ -743,30 +767,6 @@ ], "uses_polling": false }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c", - "name": "gpr_cmdline_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, { "args": [], "benchmark": false, -- cgit v1.2.3 From 80e23d19df972a697c3ed4fef841ebc83838e38b Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 25 Jan 2018 21:50:18 -0800 Subject: Separate out cmdline so that it can be used in tool and test builds --- CMakeLists.txt | 93 ++++++++++++----- Makefile | 111 ++++++++++++++++----- build.yaml | 22 ++-- gRPC-C++.podspec | 20 +++- gRPC-Core.podspec | 4 +- grpc.gyp | 4 +- tools/run_tests/generated/sources_and_headers.json | 36 ++++--- 7 files changed, 214 insertions(+), 76 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7678eee093..1fc416b5a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1443,7 +1443,6 @@ add_library(grpc_test_util test/core/end2end/fixtures/http_proxy_fixture.cc test/core/end2end/fixtures/proxy.cc test/core/iomgr/endpoint_tests.cc - test/core/util/cmdline.cc test/core/util/debugger_macros.cc test/core/util/grpc_profiler.cc test/core/util/histogram.cc @@ -1459,6 +1458,7 @@ add_library(grpc_test_util test/core/util/subprocess_windows.cc test/core/util/tracer_util.cc test/core/util/trickle_endpoint.cc + test/core/util/cmdline.cc src/core/lib/backoff/backoff.cc src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc @@ -1677,14 +1677,30 @@ target_link_libraries(grpc_test_util ) foreach(_hdr - include/grpc/impl/codegen/byte_buffer.h - include/grpc/impl/codegen/byte_buffer_reader.h - include/grpc/impl/codegen/compression_types.h - include/grpc/impl/codegen/connectivity_state.h - include/grpc/impl/codegen/grpc_types.h - include/grpc/impl/codegen/propagation_bits.h - include/grpc/impl/codegen/slice.h - include/grpc/impl/codegen/status.h + include/grpc/support/alloc.h + include/grpc/support/atm.h + include/grpc/support/atm_gcc_atomic.h + include/grpc/support/atm_gcc_sync.h + include/grpc/support/atm_windows.h + include/grpc/support/avl.h + include/grpc/support/cpu.h + include/grpc/support/host_port.h + include/grpc/support/log.h + include/grpc/support/log_windows.h + include/grpc/support/port_platform.h + include/grpc/support/string_util.h + include/grpc/support/sync.h + include/grpc/support/sync_custom.h + include/grpc/support/sync_generic.h + include/grpc/support/sync_posix.h + include/grpc/support/sync_windows.h + include/grpc/support/thd.h + include/grpc/support/time.h + include/grpc/support/tls.h + include/grpc/support/tls_gcc.h + include/grpc/support/tls_msvc.h + include/grpc/support/tls_pthread.h + include/grpc/support/useful.h include/grpc/impl/codegen/atm.h include/grpc/impl/codegen/atm_gcc_atomic.h include/grpc/impl/codegen/atm_gcc_sync.h @@ -1698,6 +1714,14 @@ foreach(_hdr include/grpc/impl/codegen/sync_generic.h include/grpc/impl/codegen/sync_posix.h include/grpc/impl/codegen/sync_windows.h + include/grpc/impl/codegen/byte_buffer.h + include/grpc/impl/codegen/byte_buffer_reader.h + include/grpc/impl/codegen/compression_types.h + include/grpc/impl/codegen/connectivity_state.h + include/grpc/impl/codegen/grpc_types.h + include/grpc/impl/codegen/propagation_bits.h + include/grpc/impl/codegen/slice.h + include/grpc/impl/codegen/status.h ) string(REPLACE "include/" "" _path ${_hdr}) get_filename_component(_path ${_path} PATH) @@ -1715,7 +1739,6 @@ add_library(grpc_test_util_unsecure test/core/end2end/fixtures/http_proxy_fixture.cc test/core/end2end/fixtures/proxy.cc test/core/iomgr/endpoint_tests.cc - test/core/util/cmdline.cc test/core/util/debugger_macros.cc test/core/util/grpc_profiler.cc test/core/util/histogram.cc @@ -1731,6 +1754,7 @@ add_library(grpc_test_util_unsecure test/core/util/subprocess_windows.cc test/core/util/tracer_util.cc test/core/util/trickle_endpoint.cc + test/core/util/cmdline.cc src/core/lib/backoff/backoff.cc src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc @@ -1949,14 +1973,30 @@ target_link_libraries(grpc_test_util_unsecure ) foreach(_hdr - include/grpc/impl/codegen/byte_buffer.h - include/grpc/impl/codegen/byte_buffer_reader.h - include/grpc/impl/codegen/compression_types.h - include/grpc/impl/codegen/connectivity_state.h - include/grpc/impl/codegen/grpc_types.h - include/grpc/impl/codegen/propagation_bits.h - include/grpc/impl/codegen/slice.h - include/grpc/impl/codegen/status.h + include/grpc/support/alloc.h + include/grpc/support/atm.h + include/grpc/support/atm_gcc_atomic.h + include/grpc/support/atm_gcc_sync.h + include/grpc/support/atm_windows.h + include/grpc/support/avl.h + include/grpc/support/cpu.h + include/grpc/support/host_port.h + include/grpc/support/log.h + include/grpc/support/log_windows.h + include/grpc/support/port_platform.h + include/grpc/support/string_util.h + include/grpc/support/sync.h + include/grpc/support/sync_custom.h + include/grpc/support/sync_generic.h + include/grpc/support/sync_posix.h + include/grpc/support/sync_windows.h + include/grpc/support/thd.h + include/grpc/support/time.h + include/grpc/support/tls.h + include/grpc/support/tls_gcc.h + include/grpc/support/tls_msvc.h + include/grpc/support/tls_pthread.h + include/grpc/support/useful.h include/grpc/impl/codegen/atm.h include/grpc/impl/codegen/atm_gcc_atomic.h include/grpc/impl/codegen/atm_gcc_sync.h @@ -1970,6 +2010,14 @@ foreach(_hdr include/grpc/impl/codegen/sync_generic.h include/grpc/impl/codegen/sync_posix.h include/grpc/impl/codegen/sync_windows.h + include/grpc/impl/codegen/byte_buffer.h + include/grpc/impl/codegen/byte_buffer_reader.h + include/grpc/impl/codegen/compression_types.h + include/grpc/impl/codegen/connectivity_state.h + include/grpc/impl/codegen/grpc_types.h + include/grpc/impl/codegen/propagation_bits.h + include/grpc/impl/codegen/slice.h + include/grpc/impl/codegen/status.h ) string(REPLACE "include/" "" _path ${_hdr}) get_filename_component(_path ${_path} PATH) @@ -6240,6 +6288,7 @@ endif (gRPC_BUILD_TESTS) add_executable(grpc_create_jwt test/core/security/create_jwt.cc + test/core/util/cmdline.cc ) @@ -6257,9 +6306,7 @@ target_include_directories(grpc_create_jwt target_link_libraries(grpc_create_jwt ${_gRPC_SSL_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util grpc - gpr_test_util gpr ) @@ -6412,6 +6459,7 @@ endif (gRPC_BUILD_TESTS) add_executable(grpc_print_google_default_creds_token test/core/security/print_google_default_creds_token.cc + test/core/util/cmdline.cc ) @@ -6428,9 +6476,7 @@ target_include_directories(grpc_print_google_default_creds_token target_link_libraries(grpc_print_google_default_creds_token ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util grpc - gpr_test_util gpr ) @@ -6500,6 +6546,7 @@ endif (gRPC_BUILD_TESTS) add_executable(grpc_verify_jwt test/core/security/verify_jwt.cc + test/core/util/cmdline.cc ) @@ -6516,9 +6563,7 @@ target_include_directories(grpc_verify_jwt target_link_libraries(grpc_verify_jwt ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util grpc - gpr_test_util gpr ) diff --git a/Makefile b/Makefile index a8f10fd2fa..c13de78534 100644 --- a/Makefile +++ b/Makefile @@ -3648,7 +3648,6 @@ LIBGRPC_TEST_UTIL_SRC = \ test/core/end2end/fixtures/http_proxy_fixture.cc \ test/core/end2end/fixtures/proxy.cc \ test/core/iomgr/endpoint_tests.cc \ - test/core/util/cmdline.cc \ test/core/util/debugger_macros.cc \ test/core/util/grpc_profiler.cc \ test/core/util/histogram.cc \ @@ -3664,6 +3663,7 @@ LIBGRPC_TEST_UTIL_SRC = \ test/core/util/subprocess_windows.cc \ test/core/util/tracer_util.cc \ test/core/util/trickle_endpoint.cc \ + test/core/util/cmdline.cc \ src/core/lib/backoff/backoff.cc \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ @@ -3851,14 +3851,30 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/ext/filters/http/server/http_server_filter.cc \ PUBLIC_HEADERS_C += \ - include/grpc/impl/codegen/byte_buffer.h \ - include/grpc/impl/codegen/byte_buffer_reader.h \ - include/grpc/impl/codegen/compression_types.h \ - include/grpc/impl/codegen/connectivity_state.h \ - include/grpc/impl/codegen/grpc_types.h \ - include/grpc/impl/codegen/propagation_bits.h \ - include/grpc/impl/codegen/slice.h \ - include/grpc/impl/codegen/status.h \ + include/grpc/support/alloc.h \ + include/grpc/support/atm.h \ + include/grpc/support/atm_gcc_atomic.h \ + include/grpc/support/atm_gcc_sync.h \ + include/grpc/support/atm_windows.h \ + include/grpc/support/avl.h \ + include/grpc/support/cpu.h \ + include/grpc/support/host_port.h \ + include/grpc/support/log.h \ + include/grpc/support/log_windows.h \ + include/grpc/support/port_platform.h \ + include/grpc/support/string_util.h \ + include/grpc/support/sync.h \ + include/grpc/support/sync_custom.h \ + include/grpc/support/sync_generic.h \ + include/grpc/support/sync_posix.h \ + include/grpc/support/sync_windows.h \ + include/grpc/support/thd.h \ + include/grpc/support/time.h \ + include/grpc/support/tls.h \ + include/grpc/support/tls_gcc.h \ + include/grpc/support/tls_msvc.h \ + include/grpc/support/tls_pthread.h \ + include/grpc/support/useful.h \ include/grpc/impl/codegen/atm.h \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ @@ -3872,6 +3888,14 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/sync_generic.h \ include/grpc/impl/codegen/sync_posix.h \ include/grpc/impl/codegen/sync_windows.h \ + include/grpc/impl/codegen/byte_buffer.h \ + include/grpc/impl/codegen/byte_buffer_reader.h \ + include/grpc/impl/codegen/compression_types.h \ + include/grpc/impl/codegen/connectivity_state.h \ + include/grpc/impl/codegen/grpc_types.h \ + include/grpc/impl/codegen/propagation_bits.h \ + include/grpc/impl/codegen/slice.h \ + include/grpc/impl/codegen/status.h \ LIBGRPC_TEST_UTIL_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC_TEST_UTIL_SRC)))) @@ -3913,7 +3937,6 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ test/core/end2end/fixtures/http_proxy_fixture.cc \ test/core/end2end/fixtures/proxy.cc \ test/core/iomgr/endpoint_tests.cc \ - test/core/util/cmdline.cc \ test/core/util/debugger_macros.cc \ test/core/util/grpc_profiler.cc \ test/core/util/histogram.cc \ @@ -3929,6 +3952,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ test/core/util/subprocess_windows.cc \ test/core/util/tracer_util.cc \ test/core/util/trickle_endpoint.cc \ + test/core/util/cmdline.cc \ src/core/lib/backoff/backoff.cc \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ @@ -4116,14 +4140,30 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/ext/filters/http/server/http_server_filter.cc \ PUBLIC_HEADERS_C += \ - include/grpc/impl/codegen/byte_buffer.h \ - include/grpc/impl/codegen/byte_buffer_reader.h \ - include/grpc/impl/codegen/compression_types.h \ - include/grpc/impl/codegen/connectivity_state.h \ - include/grpc/impl/codegen/grpc_types.h \ - include/grpc/impl/codegen/propagation_bits.h \ - include/grpc/impl/codegen/slice.h \ - include/grpc/impl/codegen/status.h \ + include/grpc/support/alloc.h \ + include/grpc/support/atm.h \ + include/grpc/support/atm_gcc_atomic.h \ + include/grpc/support/atm_gcc_sync.h \ + include/grpc/support/atm_windows.h \ + include/grpc/support/avl.h \ + include/grpc/support/cpu.h \ + include/grpc/support/host_port.h \ + include/grpc/support/log.h \ + include/grpc/support/log_windows.h \ + include/grpc/support/port_platform.h \ + include/grpc/support/string_util.h \ + include/grpc/support/sync.h \ + include/grpc/support/sync_custom.h \ + include/grpc/support/sync_generic.h \ + include/grpc/support/sync_posix.h \ + include/grpc/support/sync_windows.h \ + include/grpc/support/thd.h \ + include/grpc/support/time.h \ + include/grpc/support/tls.h \ + include/grpc/support/tls_gcc.h \ + include/grpc/support/tls_msvc.h \ + include/grpc/support/tls_pthread.h \ + include/grpc/support/useful.h \ include/grpc/impl/codegen/atm.h \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ @@ -4137,6 +4177,14 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/sync_generic.h \ include/grpc/impl/codegen/sync_posix.h \ include/grpc/impl/codegen/sync_windows.h \ + include/grpc/impl/codegen/byte_buffer.h \ + include/grpc/impl/codegen/byte_buffer_reader.h \ + include/grpc/impl/codegen/compression_types.h \ + include/grpc/impl/codegen/connectivity_state.h \ + include/grpc/impl/codegen/grpc_types.h \ + include/grpc/impl/codegen/propagation_bits.h \ + include/grpc/impl/codegen/slice.h \ + include/grpc/impl/codegen/status.h \ LIBGRPC_TEST_UTIL_UNSECURE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC_TEST_UTIL_UNSECURE_SRC)))) @@ -10611,6 +10659,7 @@ endif GRPC_CREATE_JWT_SRC = \ test/core/security/create_jwt.cc \ + test/core/util/cmdline.cc \ GRPC_CREATE_JWT_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_CREATE_JWT_SRC)))) ifeq ($(NO_SECURE),true) @@ -10623,14 +10672,16 @@ else -$(BINDIR)/$(CONFIG)/grpc_create_jwt: $(GRPC_CREATE_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/grpc_create_jwt: $(GRPC_CREATE_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(GRPC_CREATE_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_create_jwt + $(Q) $(LD) $(LDFLAGS) $(GRPC_CREATE_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_create_jwt endif -$(OBJDIR)/$(CONFIG)/test/core/security/create_jwt.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/security/create_jwt.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + +$(OBJDIR)/$(CONFIG)/test/core/util/cmdline.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_grpc_create_jwt: $(GRPC_CREATE_JWT_OBJS:.o=.dep) @@ -10803,6 +10854,7 @@ endif GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_SRC = \ test/core/security/print_google_default_creds_token.cc \ + test/core/util/cmdline.cc \ GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_SRC)))) ifeq ($(NO_SECURE),true) @@ -10815,14 +10867,16 @@ else -$(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token: $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token: $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token + $(Q) $(LD) $(LDFLAGS) $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token endif -$(OBJDIR)/$(CONFIG)/test/core/security/print_google_default_creds_token.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/security/print_google_default_creds_token.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + +$(OBJDIR)/$(CONFIG)/test/core/util/cmdline.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_grpc_print_google_default_creds_token: $(GRPC_PRINT_GOOGLE_DEFAULT_CREDS_TOKEN_OBJS:.o=.dep) @@ -10899,6 +10953,7 @@ endif GRPC_VERIFY_JWT_SRC = \ test/core/security/verify_jwt.cc \ + test/core/util/cmdline.cc \ GRPC_VERIFY_JWT_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_VERIFY_JWT_SRC)))) ifeq ($(NO_SECURE),true) @@ -10911,14 +10966,16 @@ else -$(BINDIR)/$(CONFIG)/grpc_verify_jwt: $(GRPC_VERIFY_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/grpc_verify_jwt: $(GRPC_VERIFY_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(GRPC_VERIFY_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_verify_jwt + $(Q) $(LD) $(LDFLAGS) $(GRPC_VERIFY_JWT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_verify_jwt endif -$(OBJDIR)/$(CONFIG)/test/core/security/verify_jwt.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/security/verify_jwt.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + +$(OBJDIR)/$(CONFIG)/test/core/util/cmdline.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_grpc_verify_jwt: $(GRPC_VERIFY_JWT_OBJS:.o=.dep) diff --git a/build.yaml b/build.yaml index 3564d465fb..4370e0a31e 100644 --- a/build.yaml +++ b/build.yaml @@ -24,6 +24,13 @@ filegroups: uses: - grpc_base - nanopb +- name: cmdline + headers: + - test/core/util/cmdline.h + src: + - test/core/util/cmdline.cc + uses: + - gpr_base_headers - name: gpr_base src: - src/core/lib/gpr/alloc.cc @@ -710,7 +717,6 @@ filegroups: - test/core/end2end/fixtures/http_proxy_fixture.h - test/core/end2end/fixtures/proxy.h - test/core/iomgr/endpoint_tests.h - - test/core/util/cmdline.h - test/core/util/debugger_macros.h - test/core/util/grpc_profiler.h - test/core/util/histogram.h @@ -730,7 +736,6 @@ filegroups: - test/core/end2end/fixtures/http_proxy_fixture.cc - test/core/end2end/fixtures/proxy.cc - test/core/iomgr/endpoint_tests.cc - - test/core/util/cmdline.cc - test/core/util/debugger_macros.cc - test/core/util/grpc_profiler.cc - test/core/util/histogram.cc @@ -750,6 +755,7 @@ filegroups: - gpr_test_util - gpr uses: + - cmdline - grpc_base - grpc_client_channel - grpc_transport_chttp2 @@ -2367,10 +2373,10 @@ targets: src: - test/core/security/create_jwt.cc deps: - - grpc_test_util - grpc - - gpr_test_util - gpr + filegroups: + - cmdline secure: true uses_polling: false - name: grpc_credentials_test @@ -2437,10 +2443,10 @@ targets: src: - test/core/security/print_google_default_creds_token.cc deps: - - grpc_test_util - grpc - - gpr_test_util - gpr + filegroups: + - cmdline uses_polling: false - name: grpc_security_connector_test build: test @@ -2468,10 +2474,10 @@ targets: src: - test/core/security/verify_jwt.cc deps: - - grpc_test_util - grpc - - gpr_test_util - gpr + filegroups: + - cmdline uses_polling: false - name: handshake_client build: test diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 5236cda02e..ace558aa20 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -618,7 +618,6 @@ Pod::Spec.new do |s| 'test/core/end2end/fixtures/http_proxy_fixture.h', 'test/core/end2end/fixtures/proxy.h', 'test/core/iomgr/endpoint_tests.h', - 'test/core/util/cmdline.h', 'test/core/util/debugger_macros.h', 'test/core/util/grpc_profiler.h', 'test/core/util/histogram.h', @@ -632,6 +631,25 @@ Pod::Spec.new do |s| 'test/core/util/subprocess.h', 'test/core/util/tracer_util.h', 'test/core/util/trickle_endpoint.h', + 'test/core/util/cmdline.h', + 'src/core/lib/gpr/arena.h', + 'src/core/lib/gpr/env.h', + 'src/core/lib/gpr/fork.h', + 'src/core/lib/gpr/mpscq.h', + 'src/core/lib/gpr/murmur_hash.h', + 'src/core/lib/gpr/spinlock.h', + 'src/core/lib/gpr/string.h', + 'src/core/lib/gpr/string_windows.h', + 'src/core/lib/gpr/thd_internal.h', + 'src/core/lib/gpr/time_precise.h', + 'src/core/lib/gpr/tmpfile.h', + 'src/core/lib/gprpp/abstract.h', + 'src/core/lib/gprpp/atomic.h', + 'src/core/lib/gprpp/atomic_with_atm.h', + 'src/core/lib/gprpp/atomic_with_std.h', + 'src/core/lib/gprpp/manual_constructor.h', + 'src/core/lib/gprpp/memory.h', + 'src/core/lib/profiling/timers.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 23a01010d0..9a173cd7b6 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -988,7 +988,6 @@ Pod::Spec.new do |s| 'test/core/end2end/fixtures/http_proxy_fixture.cc', 'test/core/end2end/fixtures/proxy.cc', 'test/core/iomgr/endpoint_tests.cc', - 'test/core/util/cmdline.cc', 'test/core/util/debugger_macros.cc', 'test/core/util/grpc_profiler.cc', 'test/core/util/histogram.cc', @@ -1004,13 +1003,13 @@ Pod::Spec.new do |s| 'test/core/util/subprocess_windows.cc', 'test/core/util/tracer_util.cc', 'test/core/util/trickle_endpoint.cc', + 'test/core/util/cmdline.cc', 'test/core/end2end/data/ssl_test_data.h', 'test/core/security/oauth2_utils.h', 'test/core/end2end/cq_verifier.h', 'test/core/end2end/fixtures/http_proxy_fixture.h', 'test/core/end2end/fixtures/proxy.h', 'test/core/iomgr/endpoint_tests.h', - 'test/core/util/cmdline.h', 'test/core/util/debugger_macros.h', 'test/core/util/grpc_profiler.h', 'test/core/util/histogram.h', @@ -1024,6 +1023,7 @@ Pod::Spec.new do |s| 'test/core/util/subprocess.h', 'test/core/util/tracer_util.h', 'test/core/util/trickle_endpoint.h', + 'test/core/util/cmdline.h', 'test/core/end2end/end2end_tests.cc', 'test/core/end2end/end2end_test_utils.cc', 'test/core/end2end/tests/authority_not_supported.cc', diff --git a/grpc.gyp b/grpc.gyp index b394b5e32b..40f6f54086 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -505,7 +505,6 @@ 'test/core/end2end/fixtures/http_proxy_fixture.cc', 'test/core/end2end/fixtures/proxy.cc', 'test/core/iomgr/endpoint_tests.cc', - 'test/core/util/cmdline.cc', 'test/core/util/debugger_macros.cc', 'test/core/util/grpc_profiler.cc', 'test/core/util/histogram.cc', @@ -521,6 +520,7 @@ 'test/core/util/subprocess_windows.cc', 'test/core/util/tracer_util.cc', 'test/core/util/trickle_endpoint.cc', + 'test/core/util/cmdline.cc', 'src/core/lib/backoff/backoff.cc', 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', @@ -722,7 +722,6 @@ 'test/core/end2end/fixtures/http_proxy_fixture.cc', 'test/core/end2end/fixtures/proxy.cc', 'test/core/iomgr/endpoint_tests.cc', - 'test/core/util/cmdline.cc', 'test/core/util/debugger_macros.cc', 'test/core/util/grpc_profiler.cc', 'test/core/util/histogram.cc', @@ -738,6 +737,7 @@ 'test/core/util/subprocess_windows.cc', 'test/core/util/tracer_util.cc', 'test/core/util/trickle_endpoint.cc', + 'test/core/util/cmdline.cc', 'src/core/lib/backoff/backoff.cc', 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index bdbcb89b3c..d557cda25d 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -951,10 +951,9 @@ }, { "deps": [ + "cmdline", "gpr", - "gpr_test_util", - "grpc", - "grpc_test_util" + "grpc" ], "headers": [], "is_filegroup": false, @@ -1053,10 +1052,9 @@ }, { "deps": [ + "cmdline", "gpr", - "gpr_test_util", - "grpc", - "grpc_test_util" + "grpc" ], "headers": [], "is_filegroup": false, @@ -1104,10 +1102,9 @@ }, { "deps": [ + "cmdline", "gpr", - "gpr_test_util", - "grpc", - "grpc_test_util" + "grpc" ], "headers": [], "is_filegroup": false, @@ -7846,6 +7843,23 @@ "third_party": false, "type": "filegroup" }, + { + "deps": [ + "gpr_base_headers" + ], + "headers": [ + "test/core/util/cmdline.h" + ], + "is_filegroup": true, + "language": "c", + "name": "cmdline", + "src": [ + "test/core/util/cmdline.cc", + "test/core/util/cmdline.h" + ], + "third_party": false, + "type": "filegroup" + }, { "deps": [ "gpr_base_headers" @@ -9016,6 +9030,7 @@ }, { "deps": [ + "cmdline", "gpr", "gpr_test_util", "grpc_base", @@ -9028,7 +9043,6 @@ "test/core/end2end/fixtures/http_proxy_fixture.h", "test/core/end2end/fixtures/proxy.h", "test/core/iomgr/endpoint_tests.h", - "test/core/util/cmdline.h", "test/core/util/debugger_macros.h", "test/core/util/grpc_profiler.h", "test/core/util/histogram.h", @@ -9057,8 +9071,6 @@ "test/core/end2end/fixtures/proxy.h", "test/core/iomgr/endpoint_tests.cc", "test/core/iomgr/endpoint_tests.h", - "test/core/util/cmdline.cc", - "test/core/util/cmdline.h", "test/core/util/debugger_macros.cc", "test/core/util/debugger_macros.h", "test/core/util/grpc_profiler.cc", -- cgit v1.2.3 From 0dbb00eef0e53c87dcd6958839ec0d532cdf858c Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Fri, 2 Feb 2018 08:39:47 -0800 Subject: Remove extern "C" --- test/core/util/cmdline.h | 8 -------- test/core/util/subprocess.h | 8 -------- 2 files changed, 16 deletions(-) diff --git a/test/core/util/cmdline.h b/test/core/util/cmdline.h index 54f45167fa..3ae35d6e6a 100644 --- a/test/core/util/cmdline.h +++ b/test/core/util/cmdline.h @@ -21,10 +21,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - /** Simple command line parser. Supports flags that can be specified as -foo, --foo, --no-foo, -no-foo, etc @@ -81,8 +77,4 @@ void gpr_cmdline_destroy(gpr_cmdline* cl); /** Get a string describing usage */ char* gpr_cmdline_usage_string(gpr_cmdline* cl, const char* argv0); -#ifdef __cplusplus -} -#endif - #endif /* GRPC_TEST_CORE_UTIL_CMDLINE_H */ diff --git a/test/core/util/subprocess.h b/test/core/util/subprocess.h index 7419de27bb..c7fe9af435 100644 --- a/test/core/util/subprocess.h +++ b/test/core/util/subprocess.h @@ -21,10 +21,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - typedef struct gpr_subprocess gpr_subprocess; /** .exe on windows, empty on unices */ @@ -37,8 +33,4 @@ void gpr_subprocess_destroy(gpr_subprocess* p); int gpr_subprocess_join(gpr_subprocess* p); void gpr_subprocess_interrupt(gpr_subprocess* p); -#ifdef __cplusplus -} // extern "C" -#endif - #endif /* GRPC_TEST_CORE_UTIL_SUBPROCESS_H */ -- cgit v1.2.3