diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-15 21:33:41 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-15 21:33:41 +0300 |
commit | 3dd665b514943f69657b593eb51af90b99b1206b (patch) | |
tree | 0eb633e628bb1fe6c639574b1184d43def7c0a73 /contrib/libs/grpc/test/core | |
parent | a68afc731202027f105bc5723ee11788017c29e2 (diff) | |
download | ydb-3dd665b514943f69657b593eb51af90b99b1206b.tar.gz |
intermediate changes
ref:953ca886ec160075b38c0f3614de029b423f0a9e
Diffstat (limited to 'contrib/libs/grpc/test/core')
23 files changed, 380 insertions, 410 deletions
diff --git a/contrib/libs/grpc/test/core/util/cmdline.cc b/contrib/libs/grpc/test/core/util/cmdline.cc index 62b47f927a..350d4bc046 100644 --- a/contrib/libs/grpc/test/core/util/cmdline.cc +++ b/contrib/libs/grpc/test/core/util/cmdline.cc @@ -59,7 +59,7 @@ struct gpr_cmdline { int survive_failure; }; -static int normal_state(gpr_cmdline* cl, char* arg); +static int normal_state(gpr_cmdline* cl, char* str); gpr_cmdline* gpr_cmdline_create(const char* description) { gpr_cmdline* cl = static_cast<gpr_cmdline*>(gpr_zalloc(sizeof(gpr_cmdline))); diff --git a/contrib/libs/grpc/test/core/util/cmdline_test.cc b/contrib/libs/grpc/test/core/util/cmdline_test.cc index b1b7da6b17..6831684bf6 100644 --- a/contrib/libs/grpc/test/core/util/cmdline_test.cc +++ b/contrib/libs/grpc/test/core/util/cmdline_test.cc @@ -30,7 +30,7 @@ static void test_simple_int(void) { int x = 1; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("-foo"), + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("-foo"), const_cast<char*>("3")}; LOG_TEST(); @@ -46,7 +46,7 @@ static void test_simple_int(void) { static void test_eq_int(void) { int x = 1; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("-foo=3")}; + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("-foo=3")}; LOG_TEST(); @@ -61,7 +61,7 @@ static void test_eq_int(void) { static void test_2dash_int(void) { int x = 1; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--foo"), + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo"), const_cast<char*>("3")}; LOG_TEST(); @@ -77,7 +77,7 @@ static void test_2dash_int(void) { static void test_2dash_eq_int(void) { int x = 1; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--foo=3")}; + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=3")}; LOG_TEST(); @@ -92,7 +92,7 @@ static void test_2dash_eq_int(void) { static void test_simple_string(void) { const char* x = nullptr; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("-foo"), + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("-foo"), const_cast<char*>("3")}; LOG_TEST(); @@ -108,7 +108,7 @@ static void test_simple_string(void) { static void test_eq_string(void) { const char* x = nullptr; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("-foo=3")}; + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("-foo=3")}; LOG_TEST(); @@ -123,7 +123,7 @@ static void test_eq_string(void) { static void test_2dash_string(void) { const char* x = nullptr; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--foo"), + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo"), const_cast<char*>("3")}; LOG_TEST(); @@ -139,7 +139,7 @@ static void test_2dash_string(void) { static void test_2dash_eq_string(void) { const char* x = nullptr; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--foo=3")}; + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=3")}; LOG_TEST(); @@ -154,7 +154,7 @@ static void test_2dash_eq_string(void) { static void test_flag_on(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--foo")}; + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo")}; LOG_TEST(); @@ -169,7 +169,7 @@ static void test_flag_on(void) { static void test_flag_no(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--no-foo")}; + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--no-foo")}; LOG_TEST(); @@ -184,7 +184,7 @@ static void test_flag_no(void) { static void test_flag_val_1(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--foo=1")}; + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=1")}; LOG_TEST(); @@ -199,7 +199,7 @@ static void test_flag_val_1(void) { static void test_flag_val_0(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--foo=0")}; + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=0")}; LOG_TEST(); @@ -214,7 +214,7 @@ static void test_flag_val_0(void) { static void test_flag_val_true(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--foo=true")}; + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=true")}; LOG_TEST(); @@ -229,7 +229,8 @@ static void test_flag_val_true(void) { static void test_flag_val_false(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--foo=false")}; + char* args[] = {const_cast<char*>(__FILE__), + const_cast<char*>("--foo=false")}; LOG_TEST(); @@ -247,7 +248,7 @@ static void test_many(void) { int flag = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast<char*>("--str"), + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--str"), const_cast<char*>("hello"), const_cast<char*>("-x=4"), const_cast<char*>("-no-flag")}; @@ -275,7 +276,7 @@ static void extra_arg_cb(void* user_data, const char* arg) { static void test_extra(void) { gpr_cmdline* cl; int count = 0; - char* args[] = {(char*)__FILE__, const_cast<char*>("a"), + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("a"), const_cast<char*>("b"), const_cast<char*>("c")}; LOG_TEST(); @@ -291,7 +292,7 @@ static void test_extra(void) { static void test_extra_dashdash(void) { gpr_cmdline* cl; int count = 0; - char* args[] = {(char*)__FILE__, const_cast<char*>("--"), + char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--"), const_cast<char*>("a"), const_cast<char*>("b"), const_cast<char*>("c")}; @@ -341,7 +342,7 @@ static void test_help(void) { int x = 0; int flag = 2; - char* help[] = {(char*)__FILE__, const_cast<char*>("-h")}; + char* help[] = {const_cast<char*>(__FILE__), const_cast<char*>("-h")}; LOG_TEST(); @@ -365,7 +366,8 @@ static void test_badargs1(void) { int x = 0; int flag = 2; - char* bad_arg_name[] = {(char*)__FILE__, const_cast<char*>("--y")}; + char* bad_arg_name[] = {const_cast<char*>(__FILE__), + const_cast<char*>("--y")}; LOG_TEST(); @@ -390,7 +392,8 @@ static void test_badargs2(void) { int x = 0; int flag = 2; - char* bad_int_value[] = {(char*)__FILE__, const_cast<char*>("--x"), + char* bad_int_value[] = {const_cast<char*>(__FILE__), + const_cast<char*>("--x"), const_cast<char*>("henry")}; LOG_TEST(); @@ -416,7 +419,8 @@ static void test_badargs3(void) { int x = 0; int flag = 2; - char* bad_bool_value[] = {(char*)__FILE__, const_cast<char*>("--flag=henry")}; + char* bad_bool_value[] = {const_cast<char*>(__FILE__), + const_cast<char*>("--flag=henry")}; LOG_TEST(); @@ -441,7 +445,8 @@ static void test_badargs4(void) { int x = 0; int flag = 2; - char* bad_bool_value[] = {(char*)__FILE__, const_cast<char*>("--no-str")}; + char* bad_bool_value[] = {const_cast<char*>(__FILE__), + const_cast<char*>("--no-str")}; LOG_TEST(); diff --git a/contrib/libs/grpc/test/core/util/debugger_macros.cc b/contrib/libs/grpc/test/core/util/debugger_macros.cc deleted file mode 100644 index fde68f3217..0000000000 --- a/contrib/libs/grpc/test/core/util/debugger_macros.cc +++ /dev/null @@ -1,57 +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. - * - */ - -/* - * A collection of 'macros' that help navigating the grpc object hierarchy - * Not intended to be robust for main-line code, often cuts across abstraction - * boundaries. - */ -#include <stdio.h> - -#include "src/core/ext/filters/client_channel/client_channel.h" -#include "src/core/ext/transport/chttp2/transport/internal.h" -#include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/surface/call.h" - -grpc_stream* grpc_transport_stream_from_call(grpc_call* call) { - grpc_call_stack* cs = grpc_call_get_call_stack(call); - for (;;) { - grpc_call_element* el = grpc_call_stack_element(cs, cs->count - 1); - if (el->filter == &grpc_client_channel_filter) { - grpc_core::RefCountedPtr<grpc_core::SubchannelCall> scc = - grpc_client_channel_get_subchannel_call(el); - if (scc == nullptr) { - fprintf(stderr, "No subchannel-call"); - fflush(stderr); - return nullptr; - } - cs = scc->GetCallStack(); - } else if (el->filter == &grpc_connected_filter) { - return grpc_connected_channel_get_stream(el); - } else { - fprintf(stderr, "Unrecognized filter: %s", el->filter->name); - fflush(stderr); - return nullptr; - } - } -} - -grpc_chttp2_stream* grpc_chttp2_stream_from_call(grpc_call* call) { - return reinterpret_cast<grpc_chttp2_stream*>( - grpc_transport_stream_from_call(call)); -} diff --git a/contrib/libs/grpc/test/core/util/debugger_macros.h b/contrib/libs/grpc/test/core/util/debugger_macros.h deleted file mode 100644 index 71228c6e87..0000000000 --- a/contrib/libs/grpc/test/core/util/debugger_macros.h +++ /dev/null @@ -1,27 +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. - * - */ - -#ifndef GRPC_TEST_CORE_UTIL_DEBUGGER_MACROS_H -#define GRPC_TEST_CORE_UTIL_DEBUGGER_MACROS_H - -#include "src/core/ext/transport/chttp2/transport/internal.h" -#include "src/core/lib/surface/call.h" - -grpc_chttp2_stream* grpc_chttp2_stream_from_call(grpc_call* call); - -#endif /* GRPC_TEST_CORE_UTIL_DEBUGGER_MACROS_H */ diff --git a/contrib/libs/grpc/test/core/util/eval_args_mock_endpoint.cc b/contrib/libs/grpc/test/core/util/eval_args_mock_endpoint.cc index 00d4056ba5..cc8758da7f 100644 --- a/contrib/libs/grpc/test/core/util/eval_args_mock_endpoint.cc +++ b/contrib/libs/grpc/test/core/util/eval_args_mock_endpoint.cc @@ -36,15 +36,16 @@ class EvalArgsMockEndpoint { base_.vtable = &vtable_; } grpc_endpoint* base() const { return const_cast<grpc_endpoint*>(&base_); } - static void Read(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb, bool unused) {} - static void Write(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb, void* unused) {} - static void AddToPollset(grpc_endpoint* ep, grpc_pollset* unused) {} - static void AddToPollsetSet(grpc_endpoint* ep, grpc_pollset_set* unused) {} - static void DeleteFromPollsetSet(grpc_endpoint* ep, - grpc_pollset_set* unused) {} - static void Shutdown(grpc_endpoint* ep, grpc_error* why) {} + static void Read(grpc_endpoint* /*ep*/, grpc_slice_buffer* /*slices*/, + grpc_closure* /*cb*/, bool /*unused*/) {} + static void Write(grpc_endpoint* /*ep*/, grpc_slice_buffer* /*slices*/, + grpc_closure* /*cb*/, void* /*unused*/) {} + static void AddToPollset(grpc_endpoint* /*ep*/, grpc_pollset* /*unused*/) {} + static void AddToPollsetSet(grpc_endpoint* /*ep*/, + grpc_pollset_set* /*unused*/) {} + static void DeleteFromPollsetSet(grpc_endpoint* /*ep*/, + grpc_pollset_set* /*unused*/) {} + static void Shutdown(grpc_endpoint* /*ep*/, grpc_error* /*why*/) {} static void Destroy(grpc_endpoint* ep) { EvalArgsMockEndpoint* m = reinterpret_cast<EvalArgsMockEndpoint*>(ep); delete m; @@ -60,12 +61,12 @@ class EvalArgsMockEndpoint { return m->local_address_; } - static grpc_resource_user* GetResourceUser(grpc_endpoint* ep) { + static grpc_resource_user* GetResourceUser(grpc_endpoint* /*ep*/) { return nullptr; } - static int GetFd(grpc_endpoint* unused) { return -1; } - static bool CanTrackErr(grpc_endpoint* unused) { return false; } + static int GetFd(grpc_endpoint* /*unused*/) { return -1; } + static bool CanTrackErr(grpc_endpoint* /*unused*/) { return false; } private: static constexpr grpc_endpoint_vtable vtable_ = { diff --git a/contrib/libs/grpc/test/core/util/fuzzer_corpus_test.cc b/contrib/libs/grpc/test/core/util/fuzzer_corpus_test.cc index 99ab45120d..5b3d728f8e 100644 --- a/contrib/libs/grpc/test/core/util/fuzzer_corpus_test.cc +++ b/contrib/libs/grpc/test/core/util/fuzzer_corpus_test.cc @@ -16,18 +16,16 @@ * */ -#include <stdbool.h> - #include <dirent.h> -#include <gflags/gflags.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <gtest/gtest.h> +#include <stdbool.h> #include <stdio.h> #include <sys/types.h> -#include <grpc/grpc.h> - +#include "y_absl/flags/flag.h" #include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/load_file.h" #include "test/core/util/test_config.h" @@ -37,15 +35,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); extern bool squelch; extern bool leak_check; -// In some distros, gflags is in the namespace google, and in some others, -// in gflags. This hack is enabling us to find both. -namespace google {} -namespace gflags {} -using namespace google; -using namespace gflags; - -DEFINE_string(file, "", "Use this file as test data"); -DEFINE_string(directory, "", "Use this directory as test data"); +Y_ABSL_FLAG(TString, file, "", "Use this file as test data"); +Y_ABSL_FLAG(TString, directory, "", "Use this directory as test data"); class FuzzerCorpusTest : public ::testing::TestWithParam<TString> {}; @@ -65,7 +56,7 @@ TEST_P(FuzzerCorpusTest, RunOneExample) { void* data = gpr_malloc(length); memcpy(data, GPR_SLICE_START_PTR(buffer), length); grpc_slice_unref(buffer); - grpc_shutdown_blocking(); + grpc_shutdown(); LLVMFuzzerTestOneInput(static_cast<uint8_t*>(data), length); gpr_free(data); } @@ -73,18 +64,21 @@ TEST_P(FuzzerCorpusTest, RunOneExample) { class ExampleGenerator : public ::testing::internal::ParamGeneratorInterface<TString> { public: - virtual ::testing::internal::ParamIteratorInterface<TString>* Begin() - const; - virtual ::testing::internal::ParamIteratorInterface<TString>* End() const; + ::testing::internal::ParamIteratorInterface<TString>* Begin() + const override; + ::testing::internal::ParamIteratorInterface<TString>* End() + const override; private: void Materialize() const { if (examples_.empty()) { - if (!FLAGS_file.empty()) examples_.push_back(FLAGS_file); - if (!FLAGS_directory.empty()) { + if (!y_absl::GetFlag(FLAGS_file).empty()) { + examples_.push_back(y_absl::GetFlag(FLAGS_file)); + } + if (!y_absl::GetFlag(FLAGS_directory).empty()) { char* test_srcdir = gpr_getenv("TEST_SRCDIR"); gpr_log(GPR_DEBUG, "test_srcdir=\"%s\"", test_srcdir); - TString directory = FLAGS_directory; + TString directory = y_absl::GetFlag(FLAGS_directory); if (test_srcdir != nullptr) { directory = test_srcdir + TString("/com_github_grpc_grpc/") + directory; @@ -124,13 +118,13 @@ class ExampleIterator std::vector<TString>::const_iterator begin) : base_(base_), begin_(begin), current_(begin) {} - virtual const ExampleGenerator* BaseGenerator() const { return &base_; } + const ExampleGenerator* BaseGenerator() const override { return &base_; } - virtual void Advance() { current_++; } - virtual ExampleIterator* Clone() const { return new ExampleIterator(*this); } - virtual const TString* Current() const { return &*current_; } + void Advance() override { current_++; } + ExampleIterator* Clone() const override { return new ExampleIterator(*this); } + const TString* Current() const override { return &*current_; } - virtual bool Equals(const ParamIteratorInterface<TString>& other) const { + bool Equals(const ParamIteratorInterface<TString>& other) const override { return &base_ == other.BaseGenerator() && current_ == dynamic_cast<const ExampleIterator*>(&other)->current_; } diff --git a/contrib/libs/grpc/test/core/util/histogram.cc b/contrib/libs/grpc/test/core/util/histogram.cc index f028ac404e..afb2c16c91 100644 --- a/contrib/libs/grpc/test/core/util/histogram.cc +++ b/contrib/libs/grpc/test/core/util/histogram.cc @@ -124,23 +124,23 @@ int grpc_histogram_merge(grpc_histogram* dst, const grpc_histogram* src) { return 1; } -void grpc_histogram_merge_contents(grpc_histogram* dst, const uint32_t* data, - size_t data_count, double min_seen, - double max_seen, double sum, +void grpc_histogram_merge_contents(grpc_histogram* histogram, + const uint32_t* data, size_t data_count, + double min_seen, double max_seen, double sum, double sum_of_squares, double count) { size_t i; - GPR_ASSERT(dst->num_buckets == data_count); - dst->sum += sum; - dst->sum_of_squares += sum_of_squares; - dst->count += count; - if (min_seen < dst->min_seen) { - dst->min_seen = min_seen; + GPR_ASSERT(histogram->num_buckets == data_count); + histogram->sum += sum; + histogram->sum_of_squares += sum_of_squares; + histogram->count += count; + if (min_seen < histogram->min_seen) { + histogram->min_seen = min_seen; } - if (max_seen > dst->max_seen) { - dst->max_seen = max_seen; + if (max_seen > histogram->max_seen) { + histogram->max_seen = max_seen; } - for (i = 0; i < dst->num_buckets; i++) { - dst->buckets[i] += data[i]; + for (i = 0; i < histogram->num_buckets; i++) { + histogram->buckets[i] += data[i]; } } @@ -224,7 +224,8 @@ double grpc_histogram_sum_of_squares(grpc_histogram* h) { return h->sum_of_squares; } -const uint32_t* grpc_histogram_get_contents(grpc_histogram* h, size_t* size) { - *size = h->num_buckets; - return h->buckets; +const uint32_t* grpc_histogram_get_contents(grpc_histogram* histogram, + size_t* count) { + *count = histogram->num_buckets; + return histogram->buckets; } diff --git a/contrib/libs/grpc/test/core/util/mock_endpoint.cc b/contrib/libs/grpc/test/core/util/mock_endpoint.cc index 3c2d6a3f8b..35a0f6d9f7 100644 --- a/contrib/libs/grpc/test/core/util/mock_endpoint.cc +++ b/contrib/libs/grpc/test/core/util/mock_endpoint.cc @@ -132,7 +132,8 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), grpc_resource_quota* resource_quota) { mock_endpoint* m = static_cast<mock_endpoint*>(gpr_malloc(sizeof(*m))); m->base.vtable = &vtable; - TString name = y_absl::StrFormat("mock_endpoint_%" PRIxPTR, (intptr_t)m); + TString name = + y_absl::StrFormat("mock_endpoint_%" PRIxPTR, reinterpret_cast<intptr_t>(m)); m->resource_user = grpc_resource_user_create(resource_quota, name.c_str()); grpc_slice_buffer_init(&m->read_buffer); gpr_mu_init(&m->mu); diff --git a/contrib/libs/grpc/test/core/util/mock_endpoint.h b/contrib/libs/grpc/test/core/util/mock_endpoint.h index 6521d3e8e8..8e58d65beb 100644 --- a/contrib/libs/grpc/test/core/util/mock_endpoint.h +++ b/contrib/libs/grpc/test/core/util/mock_endpoint.h @@ -23,7 +23,6 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), grpc_resource_quota* resource_quota); -void grpc_mock_endpoint_put_read(grpc_endpoint* mock_endpoint, - grpc_slice slice); +void grpc_mock_endpoint_put_read(grpc_endpoint* ep, grpc_slice slice); #endif diff --git a/contrib/libs/grpc/test/core/util/passthru_endpoint.cc b/contrib/libs/grpc/test/core/util/passthru_endpoint.cc index a5baafad02..6db2b349b2 100644 --- a/contrib/libs/grpc/test/core/util/passthru_endpoint.cc +++ b/contrib/libs/grpc/test/core/util/passthru_endpoint.cc @@ -197,8 +197,8 @@ static void half_init(half* m, passthru_endpoint* parent, m->parent = parent; grpc_slice_buffer_init(&m->read_buffer); m->on_read = nullptr; - TString name = y_absl::StrFormat("passthru_endpoint_%s_%" PRIxPTR, - half_name, (intptr_t)parent); + TString name = + y_absl::StrFormat("passthru_endpoint_%s_%p", half_name, parent); m->resource_user = grpc_resource_user_create(resource_quota, name.c_str()); } @@ -209,7 +209,7 @@ void grpc_passthru_endpoint_create(grpc_endpoint** client, passthru_endpoint* m = static_cast<passthru_endpoint*>(gpr_malloc(sizeof(*m))); m->halves = 2; - m->shutdown = 0; + m->shutdown = false; if (stats == nullptr) { m->stats = grpc_passthru_endpoint_stats_create(); } else { diff --git a/contrib/libs/grpc/test/core/util/port.cc b/contrib/libs/grpc/test/core/util/port.cc index 5a34b6026f..eae4fbfb35 100644 --- a/contrib/libs/grpc/test/core/util/port.cc +++ b/contrib/libs/grpc/test/core/util/port.cc @@ -73,7 +73,7 @@ static void free_chosen_ports(void) { for (i = 0; i < num_chosen_ports; i++) { grpc_free_port_using_server(chosen_ports[i]); } - grpc_shutdown_blocking(); + grpc_shutdown(); gpr_free(chosen_ports); } diff --git a/contrib/libs/grpc/test/core/util/reconnect_server.cc b/contrib/libs/grpc/test/core/util/reconnect_server.cc index 070ab3fa0a..06d4c1e39e 100644 --- a/contrib/libs/grpc/test/core/util/reconnect_server.cc +++ b/contrib/libs/grpc/test/core/util/reconnect_server.cc @@ -62,7 +62,7 @@ static void on_connect(void* arg, grpc_endpoint* tcp, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); y_absl::string_view peer; - int last_colon; + y_absl::string_view::size_type last_colon; reconnect_server* server = static_cast<reconnect_server*>(arg); gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); timestamp_list* new_tail; diff --git a/contrib/libs/grpc/test/core/util/resolve_localhost_ip46.cc b/contrib/libs/grpc/test/core/util/resolve_localhost_ip46.cc new file mode 100644 index 0000000000..b465b754ba --- /dev/null +++ b/contrib/libs/grpc/test/core/util/resolve_localhost_ip46.cc @@ -0,0 +1,58 @@ +// +// +// Copyright 2020 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/resolve_localhost_ip46.h" + +#include <grpc/support/log.h> + +#include "src/core/lib/iomgr/port.h" +#include "src/core/lib/iomgr/resolve_address.h" +#include "src/core/lib/iomgr/sockaddr.h" + +namespace grpc_core { +namespace { + +bool localhost_to_ipv4 = false; +bool localhost_to_ipv6 = false; +gpr_once g_resolve_localhost_ipv46 = GPR_ONCE_INIT; + +void InitResolveLocalhost() { + grpc_resolved_addresses* addresses; + grpc_error* err = + grpc_blocking_resolve_address("localhost", "https", &addresses); + GPR_ASSERT(err == GRPC_ERROR_NONE); + for (size_t i = 0; i < addresses->naddrs; i++) { + grpc_sockaddr* addr = + reinterpret_cast<grpc_sockaddr*>(addresses->addrs[i].addr); + if (addr->sa_family == GRPC_AF_INET) { + localhost_to_ipv4 = true; + } else if (addr->sa_family == GRPC_AF_INET6) { + localhost_to_ipv6 = true; + } + } + grpc_resolved_addresses_destroy(addresses); +} +} // namespace + +void LocalhostResolves(bool* ipv4, bool* ipv6) { + gpr_once_init(&g_resolve_localhost_ipv46, InitResolveLocalhost); + *ipv4 = localhost_to_ipv4; + *ipv6 = localhost_to_ipv6; +} + +} // namespace grpc_core diff --git a/contrib/libs/grpc/test/core/util/resolve_localhost_ip46.h b/contrib/libs/grpc/test/core/util/resolve_localhost_ip46.h new file mode 100644 index 0000000000..d8f7883adf --- /dev/null +++ b/contrib/libs/grpc/test/core/util/resolve_localhost_ip46.h @@ -0,0 +1,29 @@ +// +// +// Copyright 2020 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_RESOLVE_LOCALHOST_IP46_H_ +#define GRPC_TEST_CORE_UTIL_RESOLVE_LOCALHOST_IP46_H_ + +namespace grpc_core { + +// Test whether localhost resolves to ipv4 and/or ipv6 +void LocalhostResolves(bool* ipv4, bool* ipv6); + +} // namespace grpc_core + +#endif // GRPC_TEST_CORE_UTIL_RESOLVE_LOCALHOST_IP46_H_ diff --git a/contrib/libs/grpc/test/core/util/examine_stack.cc b/contrib/libs/grpc/test/core/util/stack_tracer.cc index 4400a343b4..c71dc14259 100644 --- a/contrib/libs/grpc/test/core/util/examine_stack.cc +++ b/contrib/libs/grpc/test/core/util/stack_tracer.cc @@ -18,7 +18,7 @@ #include <grpc/support/port_platform.h> -#include "test/core/util/examine_stack.h" +#include "test/core/util/stack_tracer.h" #include <cstdio> #include <util/generic/string.h> @@ -26,6 +26,8 @@ #include "y_absl/debugging/stacktrace.h" #include "y_absl/debugging/symbolize.h" +#include "src/core/lib/gprpp/examine_stack.h" + namespace { static constexpr int kPrintfPointerFieldWidth = 2 + 2 * sizeof(void*); @@ -87,16 +89,22 @@ static void DebugWriteToString(const char* data, void* str) { } // namespace namespace grpc_core { +namespace testing { -TString CurrentStackTrace() { +TString GetCurrentStackTrace() { TString result = "Stack trace:\n"; constexpr int kNumStackFrames = 32; void* stack[kNumStackFrames]; int frame_sizes[kNumStackFrames]; int depth = y_absl::GetStackFrames(stack, frame_sizes, kNumStackFrames, 1); - DumpStackTrace(stack, frame_sizes, depth, true, DebugWriteToString, - (void*)&result); + DumpStackTrace(stack, frame_sizes, depth, true, DebugWriteToString, &result); return result; } +void InitializeStackTracer(const char* argv0) { + y_absl::InitializeSymbolizer(argv0); + grpc_core::SetCurrentStackTraceProvider(&GetCurrentStackTrace); +} + +} // namespace testing } // namespace grpc_core diff --git a/contrib/libs/grpc/test/core/util/examine_stack.h b/contrib/libs/grpc/test/core/util/stack_tracer.h index 1eaf95792d..16c2a43346 100644 --- a/contrib/libs/grpc/test/core/util/examine_stack.h +++ b/contrib/libs/grpc/test/core/util/stack_tracer.h @@ -24,11 +24,25 @@ #include <util/generic/string.h> namespace grpc_core { +namespace testing { -// Return the current stack trace as a string (on multiple lines, beginning with -// "Stack trace:\n") -TString CurrentStackTrace(); +// Returns the current stack trace as a string. To have symbolized stack-traces, +// InitializeStackTracer needs to be called beforehand. +// +// Example of stack-trace is +// Stack trace: +// @ 0x405b0f 192 StackTracerTest_Basic_Test::TestBody() +// @ 0x7fbace6baf75 288 testing::internal::RunAllTests() +// @ 0x7fbace6baa93 144 testing::UnitTest::Run() +// @ 0x405d4d 64 main +// +TString GetCurrentStackTrace(); +// Initializes a stack tracer so that GetCurrentStackTrace can work. +// This inits debug symbols and sets this as a gRPC stack-trace provider. +void InitializeStackTracer(const char* argv0); + +} // namespace testing } // namespace grpc_core #endif /* GRPC_TEST_CORE_UTIL_EXAMINE_STACK_H */ diff --git a/contrib/libs/grpc/test/core/util/stack_tracer_test.cc b/contrib/libs/grpc/test/core/util/stack_tracer_test.cc new file mode 100644 index 0000000000..6b577984d6 --- /dev/null +++ b/contrib/libs/grpc/test/core/util/stack_tracer_test.cc @@ -0,0 +1,44 @@ +/* + * + * Copyright 2020 the 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/stack_tracer.h" + +#include <gtest/gtest.h> +#include <util/generic/string.h> + +#include "y_absl/debugging/symbolize.h" +#include "y_absl/strings/match.h" + +#include <grpc/support/log.h> + +#include "test/core/util/test_config.h" + +TEST(StackTracerTest, Basic) { + TString stack_trace = grpc_core::testing::GetCurrentStackTrace(); + gpr_log(GPR_INFO, "stack_trace=%s", stack_trace.c_str()); +#if !defined(NDEBUG) && !defined(GPR_MUSL_LIBC_COMPAT) + EXPECT_TRUE(y_absl::StrContains(stack_trace, "Basic")); +#endif +} + +int main(int argc, char** argv) { + grpc::testing::TestEnvironment env(argc, argv); + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} diff --git a/contrib/libs/grpc/test/core/util/test_config.cc b/contrib/libs/grpc/test/core/util/test_config.cc index 9e57a486b2..274c5c04b3 100644 --- a/contrib/libs/grpc/test/core/util/test_config.cc +++ b/contrib/libs/grpc/test/core/util/test_config.cc @@ -32,7 +32,9 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/examine_stack.h" #include "src/core/lib/surface/init.h" +#include "test/core/util/stack_tracer.h" #include "y_absl/debugging/failure_signal_handler.h" #include "y_absl/debugging/symbolize.h" @@ -50,226 +52,6 @@ static unsigned seed(void) { return static_cast<unsigned>(getpid()); } static unsigned seed(void) { return (unsigned)_getpid(); } #endif -#if GPR_WINDOWS_CRASH_HANDLER -#include <windows.h> - -#include <tchar.h> - -// disable warning 4091 - dbghelp.h is broken for msvc2015 -#pragma warning(disable : 4091) -#define DBGHELP_TRANSLATE_TCHAR -#include <dbghelp.h> - -#ifdef _MSC_VER -#pragma comment(lib, "dbghelp.lib") -#endif - -static void print_stack_from_context(HANDLE thread, CONTEXT c) { - STACKFRAME s; // in/out stackframe - memset(&s, 0, sizeof(s)); - DWORD imageType; -#ifdef _M_IX86 - // normally, call ImageNtHeader() and use machine info from PE header - imageType = IMAGE_FILE_MACHINE_I386; - s.AddrPC.Offset = c.Eip; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.Ebp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrStack.Offset = c.Esp; - s.AddrStack.Mode = AddrModeFlat; -#elif _M_X64 - imageType = IMAGE_FILE_MACHINE_AMD64; - s.AddrPC.Offset = c.Rip; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.Rbp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrStack.Offset = c.Rsp; - s.AddrStack.Mode = AddrModeFlat; -#elif _M_IA64 - imageType = IMAGE_FILE_MACHINE_IA64; - s.AddrPC.Offset = c.StIIP; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.IntSp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrBStore.Offset = c.RsBSP; - s.AddrBStore.Mode = AddrModeFlat; - s.AddrStack.Offset = c.IntSp; - s.AddrStack.Mode = AddrModeFlat; -#else -#error "Platform not supported!" -#endif - - HANDLE process = GetCurrentProcess(); - - SYMBOL_INFOW* symbol = - (SYMBOL_INFOW*)calloc(sizeof(SYMBOL_INFOW) + 256 * sizeof(wchar_t), 1); - symbol->MaxNameLen = 255; - symbol->SizeOfStruct = sizeof(SYMBOL_INFOW); - - const unsigned short MAX_CALLERS_SHOWN = - 8192; // avoid flooding the stderr if stacktrace is way too long - for (int frame = 0; frame < MAX_CALLERS_SHOWN && - StackWalk(imageType, process, thread, &s, &c, 0, - SymFunctionTableAccess, SymGetModuleBase, 0); - frame++) { - PWSTR symbol_name = L"<<no symbol>>"; - DWORD64 symbol_address = 0; - if (SymFromAddrW(process, (DWORD64)(s.AddrPC.Offset), 0, symbol)) { - symbol_name = symbol->Name; - symbol_address = (DWORD64)symbol->Address; - } - - PWSTR file_name = L"<<no line info>>"; - int line_number = 0; - IMAGEHLP_LINE64 line; - line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); - DWORD displacement = 0; - if (SymGetLineFromAddrW64(process, (DWORD64)(s.AddrPC.Offset), - &displacement, &line)) { - file_name = line.FileName; - line_number = (int)line.LineNumber; - } - - fwprintf(stderr, L"*** %d: %016I64X %ls - %016I64X (%ls:%d)\n", frame, - (DWORD64)(s.AddrPC.Offset), symbol_name, symbol_address, file_name, - line_number); - fflush(stderr); - } - - free(symbol); -} - -static void print_current_stack() { - CONTEXT context; - RtlCaptureContext(&context); - print_stack_from_context(GetCurrentThread(), context); -} - -static LONG crash_handler(struct _EXCEPTION_POINTERS* ex_info) { - fprintf(stderr, "Exception handler called, dumping information\n"); - bool try_to_print_stack = true; - PEXCEPTION_RECORD exrec = ex_info->ExceptionRecord; - while (exrec) { - DWORD code = exrec->ExceptionCode; - DWORD flgs = exrec->ExceptionFlags; - PVOID addr = exrec->ExceptionAddress; - if (code == EXCEPTION_STACK_OVERFLOW) try_to_print_stack = false; - fprintf(stderr, "code: %x - flags: %d - address: %p\n", code, flgs, addr); - exrec = exrec->ExceptionRecord; - } - if (try_to_print_stack) { - print_stack_from_context(GetCurrentThread(), *ex_info->ContextRecord); - } - if (IsDebuggerPresent()) { - __debugbreak(); - } else { - _exit(1); - } - return EXCEPTION_EXECUTE_HANDLER; -} - -static void abort_handler(int sig) { - fprintf(stderr, "Abort handler called.\n"); - print_current_stack(); - if (IsDebuggerPresent()) { - __debugbreak(); - } else { - _exit(1); - } -} - -static void install_crash_handler() { - if (!SymInitialize(GetCurrentProcess(), NULL, TRUE)) { - fprintf(stderr, "SymInitialize failed: %d\n", GetLastError()); - } - SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)crash_handler); - _set_abort_behavior(0, _WRITE_ABORT_MSG); - _set_abort_behavior(0, _CALL_REPORTFAULT); - signal(SIGABRT, abort_handler); -} -#elif GPR_POSIX_CRASH_HANDLER -#include <errno.h> -#include <execinfo.h> -#include <stdio.h> -#include <string.h> - -#define SIGNAL_NAMES_LENGTH 32 - -static const char* const signal_names[] = { - nullptr, "SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGTRAP", - "SIGABRT", "SIGBUS", "SIGFPE", "SIGKILL", "SIGUSR1", "SIGSEGV", - "SIGUSR2", "SIGPIPE", "SIGALRM", "SIGTERM", "SIGSTKFLT", "SIGCHLD", - "SIGCONT", "SIGSTOP", "SIGTSTP", "SIGTTIN", "SIGTTOU", "SIGURG", - "SIGXCPU", "SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH", "SIGIO", - "SIGPWR", "SIGSYS"}; - -static char g_alt_stack[GPR_MAX(MINSIGSTKSZ, 65536)]; - -#define MAX_FRAMES 32 - -/* signal safe output */ -static void output_string(const char* string) { - size_t len = strlen(string); - ssize_t r; - - do { - r = write(STDERR_FILENO, string, len); - } while (r == -1 && errno == EINTR); -} - -static void output_num(long num) { - char buf[GPR_LTOA_MIN_BUFSIZE]; - gpr_ltoa(num, buf); - output_string(buf); -} - -static void crash_handler(int signum, siginfo_t* /*info*/, void* /*data*/) { - void* addrlist[MAX_FRAMES + 1]; - int addrlen; - - output_string("\n\n\n*******************************\nCaught signal "); - if (signum > 0 && signum < SIGNAL_NAMES_LENGTH) { - output_string(signal_names[signum]); - } else { - output_num(signum); - } - output_string("\n"); - - addrlen = backtrace(addrlist, GPR_ARRAY_SIZE(addrlist)); - - if (addrlen == 0) { - output_string(" no backtrace\n"); - } else { - backtrace_symbols_fd(addrlist, addrlen, STDERR_FILENO); - } - - /* try to get a core dump for SIGTERM */ - if (signum == SIGTERM) signum = SIGQUIT; - raise(signum); -} - -static void install_crash_handler() { - stack_t ss; - struct sigaction sa; - - memset(&ss, 0, sizeof(ss)); - memset(&sa, 0, sizeof(sa)); - ss.ss_size = sizeof(g_alt_stack); - ss.ss_sp = g_alt_stack; - GPR_ASSERT(sigaltstack(&ss, nullptr) == 0); - sa.sa_flags = static_cast<int>(SA_SIGINFO | SA_ONSTACK | SA_RESETHAND); - sa.sa_sigaction = crash_handler; - GPR_ASSERT(sigaction(SIGILL, &sa, nullptr) == 0); - GPR_ASSERT(sigaction(SIGABRT, &sa, nullptr) == 0); - GPR_ASSERT(sigaction(SIGBUS, &sa, nullptr) == 0); - GPR_ASSERT(sigaction(SIGSEGV, &sa, nullptr) == 0); - GPR_ASSERT(sigaction(SIGTERM, &sa, nullptr) == 0); - GPR_ASSERT(sigaction(SIGQUIT, &sa, nullptr) == 0); -} -#else -static void install_crash_handler() {} -#endif - bool BuiltUnderValgrind() { #ifdef RUNNING_ON_VALGRIND return true; @@ -371,17 +153,11 @@ gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms) { GPR_TIMESPAN)); } -void grpc_test_init(int argc, char** argv) { -#if GPR_WINDOWS - // Windows cannot use y_absl::InitializeSymbolizer until it fixes mysterious - // SymInitialize failure using Bazel RBE on Windows - // https://github.com/grpc/grpc/issues/24178 - install_crash_handler(); -#else - y_absl::InitializeSymbolizer(argv[0]); +void grpc_test_init(int /*argc*/, char** argv) { + grpc_core::testing::InitializeStackTracer(argv[0]); y_absl::FailureSignalHandlerOptions options; y_absl::InstallFailureSignalHandler(options); -#endif + gpr_log_verbosity_init(); gpr_log(GPR_DEBUG, "test slowdown factor: sanitizer=%" PRId64 ", fixture=%" PRId64 ", poller=%" PRId64 ", total=%" PRId64, diff --git a/contrib/libs/grpc/test/core/util/test_lb_policies.cc b/contrib/libs/grpc/test/core/util/test_lb_policies.cc index c1c1e9c56a..f373441140 100644 --- a/contrib/libs/grpc/test/core/util/test_lb_policies.cc +++ b/contrib/libs/grpc/test/core/util/test_lb_policies.cc @@ -103,7 +103,7 @@ class TestPickArgsLb : public ForwardingLoadBalancingPolicy { : ForwardingLoadBalancingPolicy( y_absl::make_unique<Helper>(RefCountedPtr<TestPickArgsLb>(this), cb), std::move(args), - /*delegate_lb_policy_name=*/"pick_first", + /*delegate_policy_name=*/"pick_first", /*initial_refcount=*/2) {} ~TestPickArgsLb() override = default; @@ -208,7 +208,7 @@ class InterceptRecvTrailingMetadataLoadBalancingPolicy this), std::move(cb)), std::move(args), - /*delegate_lb_policy_name=*/"pick_first", + /*delegate_policy_name=*/"pick_first", /*initial_refcount=*/2) {} ~InterceptRecvTrailingMetadataLoadBalancingPolicy() override = default; @@ -347,7 +347,7 @@ class AddressTestLoadBalancingPolicy : public ForwardingLoadBalancingPolicy { RefCountedPtr<AddressTestLoadBalancingPolicy>(this), std::move(cb)), std::move(args), - /*delegate_lb_policy_name=*/"pick_first", + /*delegate_policy_name=*/"pick_first", /*initial_refcount=*/2) {} ~AddressTestLoadBalancingPolicy() override = default; diff --git a/contrib/libs/grpc/test/core/util/test_tcp_server.h b/contrib/libs/grpc/test/core/util/test_tcp_server.h index 8765ea9a22..549b47b259 100644 --- a/contrib/libs/grpc/test/core/util/test_tcp_server.h +++ b/contrib/libs/grpc/test/core/util/test_tcp_server.h @@ -31,7 +31,7 @@ struct test_tcp_server { grpc_closure shutdown_complete; bool shutdown = false; // mu is filled in by grpc_pollset_init and controls the pollset. - // TODO: Switch this to a Mutex once pollset_init can provide a Mutex + // TODO(unknown): Switch this to a Mutex once pollset_init can provide a Mutex gpr_mu* mu; std::vector<grpc_pollset*> pollset; grpc_tcp_server_cb on_connect; diff --git a/contrib/libs/grpc/test/core/util/tls_utils.cc b/contrib/libs/grpc/test/core/util/tls_utils.cc new file mode 100644 index 0000000000..cb812f1226 --- /dev/null +++ b/contrib/libs/grpc/test/core/util/tls_utils.cc @@ -0,0 +1,76 @@ +// +// Copyright 2020 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/tls_utils.h" + +#include "src/core/lib/gpr/tmpfile.h" +#include "src/core/lib/iomgr/load_file.h" +#include "src/core/lib/slice/slice_internal.h" + +namespace grpc_core { + +namespace testing { + +TmpFile::TmpFile(y_absl::string_view credential_data) { + name_ = CreateTmpFileAndWriteData(credential_data); + GPR_ASSERT(!name_.empty()); +} + +TmpFile::~TmpFile() { GPR_ASSERT(remove(name_.c_str()) == 0); } + +void TmpFile::RewriteFile(y_absl::string_view credential_data) { + // Create a new file containing new data. + TString new_name = CreateTmpFileAndWriteData(credential_data); + GPR_ASSERT(!new_name.empty()); + // Remove the old file. + GPR_ASSERT(remove(name_.c_str()) == 0); + // Rename the new file to the original name. + GPR_ASSERT(rename(new_name.c_str(), name_.c_str()) == 0); +} + +TString TmpFile::CreateTmpFileAndWriteData( + y_absl::string_view credential_data) { + char* name = nullptr; + FILE* file_descriptor = gpr_tmpfile("GrpcTlsCertificateProviderTest", &name); + GPR_ASSERT(fwrite(credential_data.data(), 1, credential_data.size(), + file_descriptor) == credential_data.size()); + GPR_ASSERT(fclose(file_descriptor) == 0); + GPR_ASSERT(file_descriptor != nullptr); + GPR_ASSERT(name != nullptr); + TString name_to_return = name; + gpr_free(name); + return name_to_return; +} + +PemKeyCertPairList MakeCertKeyPairs(y_absl::string_view private_key, + y_absl::string_view certs) { + if (private_key.empty() && certs.empty()) { + return {}; + } + return PemKeyCertPairList{PemKeyCertPair(private_key, certs)}; +} + +TString GetFileContents(const char* path) { + grpc_slice slice = grpc_empty_slice(); + GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(path, 0, &slice))); + TString credential = TString(StringViewFromSlice(slice)); + grpc_slice_unref(slice); + return credential; +} + +} // namespace testing + +} // namespace grpc_core diff --git a/contrib/libs/grpc/test/core/util/tls_utils.h b/contrib/libs/grpc/test/core/util/tls_utils.h new file mode 100644 index 0000000000..e7ace3bf77 --- /dev/null +++ b/contrib/libs/grpc/test/core/util/tls_utils.h @@ -0,0 +1,48 @@ +// +// Copyright 2020 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include "src/core/lib/security/security_connector/ssl_utils.h" + +namespace grpc_core { + +namespace testing { + +class TmpFile { + public: + // Create a temporary file with |credential_data| written in. + explicit TmpFile(y_absl::string_view credential_data); + + ~TmpFile(); + + const TString& name() { return name_; } + + // Rewrite |credential_data| to the temporary file, in an atomic way. + void RewriteFile(y_absl::string_view credential_data); + + private: + TString CreateTmpFileAndWriteData(y_absl::string_view credential_data); + + TString name_; +}; + +PemKeyCertPairList MakeCertKeyPairs(y_absl::string_view private_key, + y_absl::string_view certs); + +TString GetFileContents(const char* path); + +} // namespace testing + +} // namespace grpc_core diff --git a/contrib/libs/grpc/test/core/util/tracer_util.cc b/contrib/libs/grpc/test/core/util/tracer_util.cc index 34a132daa7..dc5a45568c 100644 --- a/contrib/libs/grpc/test/core/util/tracer_util.cc +++ b/contrib/libs/grpc/test/core/util/tracer_util.cc @@ -24,7 +24,7 @@ namespace grpc_core { namespace testing { void grpc_tracer_enable_flag(grpc_core::TraceFlag* flag) { - flag->set_enabled(1); + flag->set_enabled(true); } } // namespace testing |