[core/gpr] move subprocess to gpr (#33870)

Move subprocess util to gpr.
Add support for communication with the subprocess.
This is required to support authentication using an executable.
pull/33967/head
Mario Jones Vimal 2 years ago committed by GitHub
parent c79c1bf90f
commit f10a8e3418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      BUILD
  2. 162
      CMakeLists.txt
  3. 243
      build_autogenerated.yaml
  4. 6
      grpc.gyp
  5. 15
      src/core/lib/gpr/subprocess.h
  6. 266
      src/core/lib/gpr/subprocess_posix.cc
  7. 2
      src/core/lib/gpr/subprocess_windows.cc
  8. 2
      test/core/bad_ssl/bad_ssl_test.cc
  9. 1
      test/core/bad_ssl/generate_tests.bzl
  10. 1
      test/core/event_engine/test_suite/tests/BUILD
  11. 3
      test/core/http/BUILD
  12. 2
      test/core/http/httpcli_test.cc
  13. 2
      test/core/http/httpcli_test_util.cc
  14. 2
      test/core/http/httpcli_test_util.h
  15. 2
      test/core/http/httpscli_test.cc
  16. 2
      test/core/memory_usage/BUILD
  17. 2
      test/core/memory_usage/memory_usage_test.cc
  18. 3
      test/core/util/BUILD
  19. 101
      test/core/util/subprocess_posix.cc
  20. 2
      test/cpp/util/BUILD
  21. 2
      test/cpp/util/subprocess.cc

20
BUILD

@ -4000,6 +4000,26 @@ grpc_cc_library(
],
)
grpc_cc_library(
name = "subprocess",
srcs = [
"//src/core:lib/gpr/subprocess_posix.cc",
"//src/core:lib/gpr/subprocess_windows.cc",
],
hdrs = [
"//src/core:lib/gpr/subprocess.h",
],
external_deps = [
"absl/strings",
"absl/types:span",
],
deps = [
"gpr",
"//src/core:strerror",
"//src/core:tchar",
],
)
# TODO(yashykt): Remove the UPB definitions from here once they are no longer needed
### UPB Targets

162
CMakeLists.txt generated

@ -3281,8 +3281,6 @@ add_library(benchmark_helpers
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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/cpp/microbenchmarks/helpers.cc
)
@ -4000,6 +3998,8 @@ endif()
if(gRPC_BUILD_TESTS)
add_library(grpc++_test_util
src/core/lib/gpr/subprocess_posix.cc
src/core/lib/gpr/subprocess_windows.cc
test/core/end2end/data/client_certs.cc
test/core/end2end/data/server1_cert.cc
test/core/end2end/data/server1_key.cc
@ -4013,8 +4013,6 @@ add_library(grpc++_test_util
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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/cpp/util/byte_buffer_proto_helper.cc
test/cpp/util/create_test_channel.cc
@ -5035,8 +5033,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
)
target_compile_features(fd_conservation_posix_test PUBLIC cxx_std_14)
@ -5172,8 +5168,6 @@ add_executable(test_core_iomgr_timer_list_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
)
target_compile_features(test_core_iomgr_timer_list_test PUBLIC cxx_std_14)
@ -5287,6 +5281,8 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(address_sorting_test_unsecure
src/core/lib/gpr/subprocess_posix.cc
src/core/lib/gpr/subprocess_windows.cc
test/core/util/cmdline.cc
test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc
@ -5296,8 +5292,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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/cpp/naming/address_sorting_test.cc
test/cpp/util/byte_buffer_proto_helper.cc
@ -5409,8 +5403,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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/cpp/common/alarm_test.cc
third_party/googletest/googletest/src/gtest-all.cc
@ -5853,8 +5845,6 @@ add_executable(alts_security_connector_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -6189,8 +6179,6 @@ add_executable(auth_context_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -6275,8 +6263,6 @@ add_executable(authorization_matchers_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -6401,8 +6387,6 @@ add_executable(aws_request_signer_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -6601,6 +6585,8 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(bad_ssl_alpn_test
src/core/lib/gpr/subprocess_posix.cc
src/core/lib/gpr/subprocess_windows.cc
test/core/bad_ssl/bad_ssl_test.cc
test/core/end2end/cq_verifier.cc
test/core/util/cmdline.cc
@ -6612,8 +6598,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -6653,6 +6637,8 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(bad_ssl_cert_test
src/core/lib/gpr/subprocess_posix.cc
src/core/lib/gpr/subprocess_windows.cc
test/core/bad_ssl/bad_ssl_test.cc
test/core/end2end/cq_verifier.cc
test/core/util/cmdline.cc
@ -6664,8 +6650,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -7221,8 +7205,6 @@ add_executable(buffer_list_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -7981,8 +7963,6 @@ add_executable(cel_authorization_engine_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -8317,8 +8297,6 @@ add_executable(channel_creds_registry_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -8614,8 +8592,6 @@ add_executable(check_gcp_environment_linux_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -8663,8 +8639,6 @@ add_executable(check_gcp_environment_windows_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -9306,8 +9280,6 @@ add_executable(cmdline_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -9432,8 +9404,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -9756,8 +9726,6 @@ add_executable(connectivity_state_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -10819,8 +10787,6 @@ add_executable(endpoint_pair_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -10956,8 +10922,6 @@ add_executable(error_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -11005,8 +10969,6 @@ add_executable(error_utils_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -11054,8 +11016,6 @@ add_executable(evaluate_args_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -11624,8 +11584,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -12281,8 +12239,6 @@ add_executable(format_request_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -12966,8 +12922,6 @@ add_executable(grpc_alts_credentials_options_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -13053,8 +13007,6 @@ add_executable(grpc_authorization_engine_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -13102,8 +13054,6 @@ add_executable(grpc_authorization_policy_provider_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -13463,8 +13413,6 @@ add_executable(grpc_ipv6_loopback_available_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -13722,8 +13670,6 @@ add_executable(grpc_tls_certificate_distributor_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -13771,8 +13717,6 @@ add_executable(grpc_tls_certificate_provider_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -13820,8 +13764,6 @@ add_executable(grpc_tls_certificate_verifier_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -13869,8 +13811,6 @@ add_executable(grpc_tls_credentials_options_comparator_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -13918,8 +13858,6 @@ add_executable(grpc_tls_credentials_options_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -14524,8 +14462,6 @@ add_executable(histogram_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -14610,8 +14546,6 @@ add_executable(hpack_encoder_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -14659,8 +14593,6 @@ add_executable(hpack_parser_table_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -14708,8 +14640,6 @@ add_executable(hpack_parser_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -15220,8 +15150,6 @@ add_executable(insecure_security_connector_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -15729,8 +15657,6 @@ add_executable(json_token_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -15778,8 +15704,6 @@ add_executable(jwt_verifier_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -16384,8 +16308,6 @@ add_executable(matchers_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -16755,8 +16677,6 @@ add_executable(message_compress_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -16841,8 +16761,6 @@ add_executable(metadata_map_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -17933,8 +17851,6 @@ add_executable(parser_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -18198,8 +18114,6 @@ add_executable(pid_controller_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -18247,8 +18161,6 @@ add_executable(ping_abuse_policy_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -18296,8 +18208,6 @@ add_executable(ping_configuration_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -18393,8 +18303,6 @@ add_executable(ping_rate_policy_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -19523,8 +19431,6 @@ add_executable(rbac_translator_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -19831,8 +19737,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -19883,8 +19787,6 @@ add_executable(resolve_address_using_ares_resolver_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -19934,8 +19836,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -19986,8 +19886,6 @@ add_executable(resolve_address_using_native_resolver_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -22094,8 +21992,6 @@ add_executable(secure_endpoint_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -22143,8 +22039,6 @@ add_executable(security_connector_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -22342,8 +22236,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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/cpp/server/server_builder_test.cc
third_party/googletest/googletest/src/gtest-all.cc
@ -22410,8 +22302,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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/cpp/server/server_builder_with_socket_mutator_test.cc
third_party/googletest/googletest/src/gtest-all.cc
@ -22822,8 +22712,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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/cpp/server/server_request_call_test.cc
third_party/googletest/googletest/src/gtest-all.cc
@ -23094,8 +22982,6 @@ add_executable(settings_timeout_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -23708,8 +23594,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -23831,8 +23715,6 @@ add_executable(ssl_credentials_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -24111,8 +23993,6 @@ add_executable(status_conversion_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -24236,8 +24116,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -24431,8 +24309,6 @@ add_executable(streams_not_seen_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -24592,8 +24468,6 @@ add_executable(system_roots_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -24683,8 +24557,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -24774,8 +24646,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -24825,8 +24695,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -25250,8 +25118,6 @@ add_executable(test_core_iomgr_load_file_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -25299,8 +25165,6 @@ add_executable(test_core_iomgr_timer_heap_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -25348,8 +25212,6 @@ add_executable(test_core_security_credentials_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -25957,8 +25819,6 @@ add_executable(timeout_encoding_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -26173,8 +26033,6 @@ add_executable(tls_security_connector_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
@ -27489,8 +27347,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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/cpp/performance/writes_per_rpc_test.cc
third_party/googletest/googletest/src/gtest-all.cc
@ -28511,8 +28367,6 @@ add_executable(xds_credentials_test
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.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
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc

File diff suppressed because it is too large Load Diff

6
grpc.gyp generated

@ -1504,8 +1504,6 @@
'test/core/util/passthru_endpoint.cc',
'test/core/util/resolve_localhost_ip46.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/cpp/microbenchmarks/helpers.cc',
],
@ -1646,6 +1644,8 @@
'grpc_test_util',
],
'sources': [
'src/core/lib/gpr/subprocess_posix.cc',
'src/core/lib/gpr/subprocess_windows.cc',
'test/core/end2end/data/client_certs.cc',
'test/core/end2end/data/server1_cert.cc',
'test/core/end2end/data/server1_key.cc',
@ -1659,8 +1659,6 @@
'test/core/util/passthru_endpoint.cc',
'test/core/util/resolve_localhost_ip46.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/cpp/util/byte_buffer_proto_helper.cc',
'test/cpp/util/create_test_channel.cc',

@ -16,17 +16,26 @@
//
//
#ifndef GRPC_TEST_CORE_UTIL_SUBPROCESS_H
#define GRPC_TEST_CORE_UTIL_SUBPROCESS_H
#ifndef GRPC_SRC_CORE_LIB_GPR_SUBPROCESS_H
#define GRPC_SRC_CORE_LIB_GPR_SUBPROCESS_H
#include <grpc/support/port_platform.h>
#include <string>
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);
gpr_subprocess* gpr_subprocess_create_with_envp(int argc, const char** argv,
int envc, const char** envp);
// communicate to the subprocess via stdin, stdout and stderr
bool gpr_subprocess_communicate(gpr_subprocess* p, std::string& input_data,
std::string* output_data, std::string* error);
/// if subprocess has not been joined, kill it
void gpr_subprocess_destroy(gpr_subprocess* p);
/// returns exit status; can be called at most once
@ -34,4 +43,4 @@ int gpr_subprocess_join(gpr_subprocess* p);
void gpr_subprocess_interrupt(gpr_subprocess* p);
int gpr_subprocess_get_process_id(gpr_subprocess* p);
#endif // GRPC_TEST_CORE_UTIL_SUBPROCESS_H
#endif // GRPC_SRC_CORE_LIB_GPR_SUBPROCESS_H

@ -0,0 +1,266 @@
//
//
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#include <grpc/support/port_platform.h>
#ifdef GPR_POSIX_SUBPROCESS
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <iostream>
#include "absl/strings/substitute.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gpr/subprocess.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/strerror.h"
struct gpr_subprocess {
int pid;
bool joined;
int child_stdin_;
int child_stdout_;
};
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;
int stdin_pipe[2];
int stdout_pipe[2];
int p0 = pipe(stdin_pipe);
int p1 = pipe(stdout_pipe);
GPR_ASSERT(p0 != -1);
GPR_ASSERT(p1 != -1);
pid = fork();
if (pid == -1) {
return nullptr;
} else if (pid == 0) {
dup2(stdin_pipe[0], STDIN_FILENO);
dup2(stdout_pipe[1], STDOUT_FILENO);
close(stdin_pipe[0]);
close(stdin_pipe[1]);
close(stdout_pipe[0]);
close(stdout_pipe[1]);
exec_args = static_cast<char**>(
gpr_malloc((static_cast<size_t>(argc) + 1) * sizeof(char*)));
memcpy(exec_args, argv, static_cast<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],
grpc_core::StrError(errno).c_str());
_exit(1);
} else {
r = grpc_core::Zalloc<gpr_subprocess>();
r->pid = pid;
close(stdin_pipe[0]);
close(stdout_pipe[1]);
r->child_stdin_ = stdin_pipe[1];
r->child_stdout_ = stdout_pipe[0];
return r;
}
}
gpr_subprocess* gpr_subprocess_create_with_envp(int argc, const char** argv,
int envc, const char** envp) {
gpr_subprocess* r;
int pid;
char **exec_args, **envp_args;
int stdin_pipe[2];
int stdout_pipe[2];
int p0 = pipe(stdin_pipe);
int p1 = pipe(stdout_pipe);
GPR_ASSERT(p0 != -1);
GPR_ASSERT(p1 != -1);
pid = fork();
if (pid == -1) {
return nullptr;
} else if (pid == 0) {
dup2(stdin_pipe[0], STDIN_FILENO);
dup2(stdout_pipe[1], STDOUT_FILENO);
close(stdin_pipe[0]);
close(stdin_pipe[1]);
close(stdout_pipe[0]);
close(stdout_pipe[1]);
exec_args = static_cast<char**>(
gpr_malloc((static_cast<size_t>(argc) + 1) * sizeof(char*)));
memcpy(exec_args, argv, static_cast<size_t>(argc) * sizeof(char*));
exec_args[argc] = nullptr;
envp_args = static_cast<char**>(
gpr_malloc((static_cast<size_t>(envc) + 1) * sizeof(char*)));
memcpy(envp_args, envp, static_cast<size_t>(envc) * sizeof(char*));
envp_args[envc] = nullptr;
execve(exec_args[0], exec_args, envp_args);
// if we reach here, an error has occurred
gpr_log(GPR_ERROR, "execvpe '%s' failed: %s", exec_args[0],
grpc_core::StrError(errno).c_str());
_exit(1);
} else {
r = grpc_core::Zalloc<gpr_subprocess>();
r->pid = pid;
close(stdin_pipe[0]);
close(stdout_pipe[1]);
r->child_stdin_ = stdin_pipe[1];
r->child_stdout_ = stdout_pipe[0];
return r;
}
}
bool gpr_subprocess_communicate(gpr_subprocess* p, std::string& input_data,
std::string* output_data, std::string* error) {
typedef void SignalHandler(int);
// Make sure SIGPIPE is disabled so that if the child dies it doesn't kill us.
SignalHandler* old_pipe_handler = signal(SIGPIPE, SIG_IGN);
int input_pos = 0;
int max_fd = std::max(p->child_stdin_, p->child_stdout_);
while (p->child_stdout_ != -1) {
fd_set read_fds;
fd_set write_fds;
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
if (p->child_stdout_ != -1) {
FD_SET(p->child_stdout_, &read_fds);
}
if (p->child_stdin_ != -1) {
FD_SET(p->child_stdin_, &write_fds);
}
if (select(max_fd + 1, &read_fds, &write_fds, nullptr, nullptr) < 0) {
if (errno == EINTR) {
// Interrupted by signal. Try again.
continue;
} else {
std::cerr << "select: " << strerror(errno) << std::endl;
GPR_ASSERT(0);
}
}
if (p->child_stdin_ != -1 && FD_ISSET(p->child_stdin_, &write_fds)) {
int n = write(p->child_stdin_, input_data.data() + input_pos,
input_data.size() - input_pos);
if (n < 0) {
// Child closed pipe. Presumably it will report an error later.
// Pretend we're done for now.
input_pos = input_data.size();
} else {
input_pos += n;
}
if (input_pos == static_cast<int>(input_data.size())) {
// We're done writing. Close.
close(p->child_stdin_);
p->child_stdin_ = -1;
}
}
if (p->child_stdout_ != -1 && FD_ISSET(p->child_stdout_, &read_fds)) {
char buffer[4096];
int n = read(p->child_stdout_, buffer, sizeof(buffer));
if (n > 0) {
output_data->append(buffer, static_cast<size_t>(n));
} else {
// We're done reading. Close.
close(p->child_stdout_);
p->child_stdout_ = -1;
}
}
}
if (p->child_stdin_ != -1) {
// Child did not finish reading input before it closed the output.
// Presumably it exited with an error.
close(p->child_stdin_);
p->child_stdin_ = -1;
}
int status;
while (waitpid(p->pid, &status, 0) == -1) {
if (errno != EINTR) {
std::cerr << "waitpid: " << strerror(errno) << std::endl;
GPR_ASSERT(0);
}
}
// Restore SIGPIPE handling.
signal(SIGPIPE, old_pipe_handler);
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) != 0) {
int error_code = WEXITSTATUS(status);
*error =
absl::Substitute("Plugin failed with status code $0.", error_code);
return false;
}
} else if (WIFSIGNALED(status)) {
int signal = WTERMSIG(status);
*error = absl::Substitute("Plugin killed by signal $0.", signal);
return false;
} else {
*error = "Neither WEXITSTATUS nor WTERMSIG is true?";
return false;
}
return true;
}
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,
grpc_core::StrError(errno).c_str());
return -1;
}
p->joined = true;
return status;
}
void gpr_subprocess_interrupt(gpr_subprocess* p) {
if (!p->joined) {
kill(p->pid, SIGINT);
}
}
int gpr_subprocess_get_process_id(gpr_subprocess* p) { return p->pid; }
#endif // GPR_POSIX_SUBPROCESS

@ -31,9 +31,9 @@
#include <grpc/support/log.h>
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/subprocess.h"
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/tchar.h"
#include "test/core/util/subprocess.h"
struct gpr_subprocess {
PROCESS_INFORMATION pi;

@ -32,11 +32,11 @@
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/subprocess.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gprpp/host_port.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 run_test(const char* target, size_t nops) {

@ -61,6 +61,7 @@ def grpc_bad_ssl_tests():
"//test/core/util:grpc_test_util_base",
"//:gpr",
"//:grpc",
"//:subprocess",
"//test/core/end2end:cq_verifier",
],
tags = ["no_windows"],

@ -68,6 +68,7 @@ grpc_cc_library(
"address_sorting",
],
deps = [
"//:subprocess",
"//src/core:env",
"//test/core/event_engine:event_engine_test_utils",
"//test/core/event_engine/test_suite:event_engine_test_framework",

@ -68,6 +68,7 @@ grpc_cc_library(
hdrs = ["httpcli_test_util.h"],
deps = [
"//:gpr",
"//:subprocess",
"//test/core/end2end:ssl_test_data",
"//test/core/util:grpc_test_util",
"//test/core/util:grpc_test_util_base",
@ -90,6 +91,7 @@ grpc_cc_test(
":httpcli_test_util",
"//:gpr",
"//:grpc",
"//:subprocess",
"//test/core/end2end:ssl_test_data",
"//test/core/util:fake_udp_and_tcp_server",
"//test/core/util:grpc_test_util",
@ -103,6 +105,7 @@ grpc_cc_test(
data = [
"python_wrapper.sh",
"test_server.py",
"//:subprocess",
"//src/core/tsi/test_creds:ca.pem",
"//src/core/tsi/test_creds:server1.key",
"//src/core/tsi/test_creds:server1.pem",

@ -44,6 +44,7 @@
#include <grpc/support/time.h>
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include "src/core/lib/gpr/subprocess.h"
#include "src/core/lib/gprpp/status_helper.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/gprpp/time_util.h"
@ -53,7 +54,6 @@
#include "test/core/http/httpcli_test_util.h"
#include "test/core/util/fake_udp_and_tcp_server.h"
#include "test/core/util/port.h"
#include "test/core/util/subprocess.h"
#include "test/core/util/test_config.h"
namespace {

@ -32,8 +32,8 @@
#include <grpc/support/time.h>
#include "src/core/lib/config/config_vars.h"
#include "src/core/lib/gpr/subprocess.h"
#include "test/core/util/port.h"
#include "test/core/util/subprocess.h"
namespace grpc_core {
namespace testing {

@ -19,7 +19,7 @@
#include <grpc/support/port_platform.h>
#include "test/core/util/subprocess.h"
#include "src/core/lib/gpr/subprocess.h"
namespace grpc_core {
namespace testing {

@ -42,6 +42,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/subprocess.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/status_helper.h"
#include "src/core/lib/gprpp/sync.h"
@ -60,7 +61,6 @@
#include "src/core/lib/uri/uri_parser.h"
#include "test/core/http/httpcli_test_util.h"
#include "test/core/util/fake_udp_and_tcp_server.h"
#include "test/core/util/subprocess.h"
#include "test/core/util/test_config.h"
namespace {

@ -159,6 +159,7 @@ grpc_cc_test(
deps = [
"//:gpr",
"//:grpc",
"//:subprocess",
"//test/core/util:grpc_test_util",
"//test/core/util:grpc_test_util_base",
],
@ -178,6 +179,7 @@ grpc_cc_binary(
deps = [
"//:gpr",
"//:grpc",
"//:subprocess",
"//test/core/util:grpc_test_util",
"//test/core/util:grpc_test_util_base",
],

@ -37,9 +37,9 @@
#include <grpc/support/time.h>
#include "src/core/lib/config/config_vars.h"
#include "src/core/lib/gpr/subprocess.h"
#include "src/core/lib/gprpp/host_port.h"
#include "test/core/util/port.h"
#include "test/core/util/subprocess.h"
#include "test/core/util/test_config.h"
ABSL_FLAG(std::string, benchmark_names, "call,channel",

@ -59,8 +59,6 @@ grpc_cc_library(
"passthru_endpoint.cc",
"resolve_localhost_ip46.cc",
"slice_splitter.cc",
"subprocess_posix.cc",
"subprocess_windows.cc",
"tracer_util.cc",
],
hdrs = [
@ -75,7 +73,6 @@ grpc_cc_library(
"passthru_endpoint.h",
"resolve_localhost_ip46.h",
"slice_splitter.h",
"subprocess.h",
"tracer_util.h",
],
external_deps = [

@ -1,101 +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 <grpc/support/port_platform.h>
#include <string>
#ifdef GPR_POSIX_SUBPROCESS
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/strerror.h"
#include "test/core/util/subprocess.h"
struct gpr_subprocess {
int pid;
bool joined;
};
const char* gpr_subprocess_binary_extension() { return ""; }
gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) {
gpr_subprocess* r;
int pid;
char** exec_args;
pid = fork();
if (pid == -1) {
return nullptr;
} else if (pid == 0) {
exec_args = static_cast<char**>(
gpr_malloc((static_cast<size_t>(argc) + 1) * sizeof(char*)));
memcpy(exec_args, argv, static_cast<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],
grpc_core::StrError(errno).c_str());
_exit(1);
} else {
r = grpc_core::Zalloc<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,
grpc_core::StrError(errno).c_str());
return -1;
}
p->joined = true;
return status;
}
void gpr_subprocess_interrupt(gpr_subprocess* p) {
if (!p->joined) {
kill(p->pid, SIGINT);
}
}
int gpr_subprocess_get_process_id(gpr_subprocess* p) { return p->pid; }
#endif // GPR_POSIX_SUBPROCESS

@ -80,6 +80,7 @@ grpc_cc_library(
],
deps = [
"//:grpc++",
"//:subprocess",
"//test/core/end2end:ssl_test_data",
"//test/core/util:grpc_test_util",
"//test/core/util:grpc_test_util_base",
@ -114,6 +115,7 @@ grpc_cc_library(
],
deps = [
"//:grpc++_unsecure",
"//:subprocess",
"//test/core/util:grpc_test_util_base",
"//test/core/util:grpc_test_util_unsecure",
],

@ -20,7 +20,7 @@
#include <vector>
#include "test/core/util/subprocess.h"
#include "src/core/lib/gpr/subprocess.h"
namespace grpc {

Loading…
Cancel
Save