diff --git a/BUILD b/BUILD index a059ff3e611..5aee6cc12d1 100644 --- a/BUILD +++ b/BUILD @@ -2177,7 +2177,10 @@ grpc_cc_library( hdrs = [ "src/core/lib/iomgr/error.h", ], - external_deps = ["absl/status"], + external_deps = [ + "absl/status", + "absl/strings:str_format", + ], deps = [ "gpr", "gpr_spinlock", diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index cd0b6cacb56..9d6e59230cd 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -22,6 +22,8 @@ #include #include +#include "absl/strings/str_format.h" + #include #include #include @@ -65,13 +67,32 @@ std::string grpc_error_std_string(absl::Status error) { return grpc_core::StatusToString(error); } +namespace { +#ifdef GPR_WINDOWS +std::string StrError(int err) { return strerror(err); } +#else +std::string StrError(int err) { + struct Finish { + static std::string Run(char* buf, int err, int r) { + if (r == 0) return buf; + return absl::StrFormat("strerror_r(%d) failed: %d", err, r); + } + static std::string Run(char*, int, const char* r) { return r; } + }; + char buf[256]; + return Finish::Run(buf, err, strerror_r(err, buf, sizeof(buf))); +} +#endif // !GPR_WINDOWS +} // namespace + absl::Status grpc_os_error(const grpc_core::DebugLocation& location, int err, const char* call_name) { + auto err_string = StrError(err); absl::Status s = - StatusCreate(absl::StatusCode::kUnknown, strerror(err), location, {}); + StatusCreate(absl::StatusCode::kUnknown, err_string, location, {}); grpc_core::StatusSetInt(&s, grpc_core::StatusIntProperty::kErrorNo, err); grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::kOsError, - strerror(err)); + err_string); grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::kSyscall, call_name); return s; diff --git a/test/core/end2end/fixtures/h2_local_abstract_uds_percent_encoded.cc b/test/core/end2end/fixtures/h2_local_abstract_uds_percent_encoded.cc index 02ffbedb4d0..cfcbb63ba0d 100644 --- a/test/core/end2end/fixtures/h2_local_abstract_uds_percent_encoded.cc +++ b/test/core/end2end/fixtures/h2_local_abstract_uds_percent_encoded.cc @@ -15,6 +15,7 @@ #include #include +#include #include #include "absl/strings/str_format.h" @@ -27,7 +28,7 @@ #include "test/core/end2end/fixtures/local_util.h" #include "test/core/util/test_config.h" -static int unique{0}; +static std::atomic unique{0}; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_uds( const grpc_channel_args* /*client_args*/, diff --git a/test/core/end2end/fixtures/h2_local_uds.cc b/test/core/end2end/fixtures/h2_local_uds.cc index 91756e18795..792b3bc2c9a 100644 --- a/test/core/end2end/fixtures/h2_local_uds.cc +++ b/test/core/end2end/fixtures/h2_local_uds.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include "absl/strings/str_format.h" @@ -31,7 +32,7 @@ #include "test/core/end2end/fixtures/local_util.h" #include "test/core/util/test_config.h" -static int unique = 1; +static std::atomic unique{1}; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_uds( const grpc_channel_args* /*client_args*/, diff --git a/test/core/end2end/fixtures/h2_local_uds_percent_encoded.cc b/test/core/end2end/fixtures/h2_local_uds_percent_encoded.cc index 495f4bb95a4..7b4a4e4eef8 100644 --- a/test/core/end2end/fixtures/h2_local_uds_percent_encoded.cc +++ b/test/core/end2end/fixtures/h2_local_uds_percent_encoded.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include "absl/strings/str_format.h" @@ -31,7 +32,7 @@ #include "test/core/end2end/fixtures/local_util.h" #include "test/core/util/test_config.h" -static int unique = 1; +static std::atomic unique{1}; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_uds( const grpc_channel_args* /*client_args*/, diff --git a/test/core/end2end/fixtures/h2_uds.cc b/test/core/end2end/fixtures/h2_uds.cc index 4c990cc0d55..0f17b78371c 100644 --- a/test/core/end2end/fixtures/h2_uds.cc +++ b/test/core/end2end/fixtures/h2_uds.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -37,7 +38,7 @@ struct fullstack_fixture_data { std::string localaddr; }; -static int unique = 1; +static std::atomic unique{1}; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_base( std::string addr) { diff --git a/test/core/end2end/fixtures/h2_uds_abstract.cc b/test/core/end2end/fixtures/h2_uds_abstract.cc index a06efd5358c..9d22cd65a17 100644 --- a/test/core/end2end/fixtures/h2_uds_abstract.cc +++ b/test/core/end2end/fixtures/h2_uds_abstract.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -37,7 +38,7 @@ struct fullstack_fixture_data { std::string localaddr; }; -static int unique = 1; +static std::atomic unique{1}; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_base( std::string addr) { diff --git a/test/core/end2end/tests/hpack_size.cc b/test/core/end2end/tests/hpack_size.cc index 6bea0ecfb1a..0bc80af2268 100644 --- a/test/core/end2end/tests/hpack_size.cc +++ b/test/core/end2end/tests/hpack_size.cc @@ -20,16 +20,22 @@ #include #include +#include +#include #include +#include #include "absl/strings/str_format.h" +#include "absl/synchronization/notification.h" +#include #include #include #include #include #include +#include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/gpr/useful.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/end2end_tests.h" @@ -386,11 +392,21 @@ void hpack_size(grpc_end2end_test_config config) { 1000, 32768, 4 * 1024 * 1024}; size_t i, j; + auto event_engine = grpc_event_engine::experimental::GetDefaultEventEngine(); + std::vector> dones; for (i = 0; i < GPR_ARRAY_SIZE(interesting_sizes); i++) { for (j = 0; j < GPR_ARRAY_SIZE(interesting_sizes); j++) { - test_size(config, interesting_sizes[i], interesting_sizes[j]); + auto done = std::make_shared(); + dones.push_back(done); + event_engine->Run([done, config, i, j] { + test_size(config, interesting_sizes[i], interesting_sizes[j]); + done->Notify(); + }); } } + for (auto& done : dones) { + done->WaitForNotification(); + } } void hpack_size_pre_init(void) {}