Remove TLS_NO_SUPPORT and always use GPR_TLS. Reorder statements in grpc_init and grpc_shutdown. Add grpc_init and grpc_shutdown in failing test/cpp tests

pull/13058/head
Yash Tibrewal 7 years ago
parent 81fc8c9c33
commit 03412ee9de
  1. 1
      include/grpc/impl/codegen/port_platform.h
  2. 6
      src/core/lib/iomgr/exec_ctx.cc
  3. 18
      src/core/lib/iomgr/exec_ctx.h
  4. 13
      src/core/lib/iomgr/iomgr.cc
  5. 10
      src/core/lib/surface/init.cc
  6. 2
      src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm
  7. 2
      test/core/end2end/fuzzers/api_fuzzer.cc
  8. 6
      test/core/http/httpscli_test.cc
  9. 3
      test/core/slice/percent_decode_fuzzer.cc
  10. 3
      test/core/slice/percent_encode_fuzzer.cc
  11. 2
      test/core/util/one_corpus_entry_fuzzer.cc
  12. 5
      test/cpp/common/channel_arguments_test.cc
  13. 6
      test/cpp/grpclb/grpclb_api_test.cc
  14. 7
      test/cpp/server/server_builder_test.cc
  15. 6
      test/cpp/util/byte_buffer_test.cc
  16. 6
      test/cpp/util/slice_test.cc

@ -182,7 +182,6 @@
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
#define TLS_NO_SUPPORT 1 /* thread-local storage not supported. Use GPR_TLS */
#if TARGET_OS_IPHONE
#define GPR_PLATFORM_STRING "ios"
#define GPR_CPU_IPHONE 1

@ -104,17 +104,11 @@ static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable};
grpc_closure_scheduler* grpc_schedule_on_exec_ctx = &exec_ctx_scheduler;
namespace grpc_core {
#ifdef TLS_NO_SUPPORT
GPR_TLS_CLASS_DEF(ExecCtx::exec_ctx_);
#else
thread_local ExecCtx* ExecCtx::exec_ctx_ = nullptr;
#endif
void ExecCtx::GlobalInit(void) {
g_start_time = gpr_now(GPR_CLOCK_MONOTONIC);
#ifdef TLS_NO_SUPPORT
gpr_tls_init(&exec_ctx_);
#endif
}
bool ExecCtx::Flush() {

@ -170,19 +170,11 @@ on outside context */
static void GlobalInit(void);
/** Global shutdown for ExecCtx. Called by iomgr */
static void GlobalShutdown(void) {
#ifdef TLS_NO_SUPPORT
gpr_tls_destroy(&exec_ctx_);
#endif
}
static void GlobalShutdown(void) { gpr_tls_destroy(&exec_ctx_); }
/** Gets pointer to current exec_ctx */
static ExecCtx* Get() {
#ifdef TLS_NO_SUPPORT
return reinterpret_cast<ExecCtx*>(gpr_tls_get(&exec_ctx_));
#else
return exec_ctx_;
#endif
}
protected:
@ -192,11 +184,7 @@ on outside context */
private:
/** Set exec_ctx_ to exec_ctx */
void Set(ExecCtx* exec_ctx) {
#ifdef TLS_NO_SUPPORT
gpr_tls_set(&exec_ctx_, reinterpret_cast<intptr_t>(exec_ctx));
#else
exec_ctx_ = exec_ctx;
#endif
}
grpc_closure_list closure_list_ = GRPC_CLOSURE_LIST_INIT;
@ -207,11 +195,7 @@ on outside context */
bool now_is_valid_ = false;
grpc_millis now_ = 0;
#ifdef TLS_NO_SUPPORT
GPR_TLS_CLASS_DECL(exec_ctx_);
#else
static thread_local ExecCtx* exec_ctx_;
#endif
ExecCtx* last_exec_ctx_ = Get();
};
} // namespace grpc_core

@ -46,15 +46,12 @@ static int g_shutdown;
static grpc_iomgr_object g_root_object;
void grpc_iomgr_init() {
grpc_core::ExecCtx _local_exec_ctx;
g_shutdown = 0;
gpr_mu_init(&g_mu);
gpr_cv_init(&g_rcv);
grpc_core::ExecCtx::GlobalInit();
{
grpc_core::ExecCtx _local_exec_ctx;
grpc_executor_init();
grpc_timer_list_init();
}
grpc_executor_init();
grpc_timer_list_init();
g_root_object.next = g_root_object.prev = &g_root_object;
g_root_object.name = (char*)"root";
grpc_network_status_init();
@ -85,7 +82,6 @@ void grpc_iomgr_shutdown() {
gpr_timespec last_warning_time = gpr_now(GPR_CLOCK_REALTIME);
{
grpc_core::ExecCtx _local_exec_ctx(0);
grpc_timer_manager_shutdown();
grpc_iomgr_platform_flush();
grpc_executor_shutdown();
@ -141,8 +137,8 @@ void grpc_iomgr_shutdown() {
}
}
gpr_mu_unlock(&g_mu);
grpc_timer_list_shutdown();
grpc_core::ExecCtx::Get()->Flush();
}
/* ensure all threads have left g_mu */
@ -150,7 +146,6 @@ void grpc_iomgr_shutdown() {
gpr_mu_unlock(&g_mu);
grpc_iomgr_platform_shutdown();
grpc_core::ExecCtx::GlobalShutdown();
grpc_network_status_shutdown();
gpr_mu_destroy(&g_mu);
gpr_cv_destroy(&g_rcv);

@ -124,6 +124,7 @@ void grpc_init(void) {
grpc_mdctx_global_init();
grpc_channel_init_init();
grpc_security_pre_init();
grpc_core::ExecCtx::GlobalInit();
grpc_iomgr_init();
gpr_timers_global_init();
grpc_handshaker_factory_registry_init();
@ -156,8 +157,8 @@ void grpc_shutdown(void) {
gpr_mu_lock(&g_init_mu);
if (--g_initializations == 0) {
{
grpc_core::ExecCtx _local_exec_ctx(0);
{
grpc_core::ExecCtx _local_exec_ctx(0);
grpc_executor_shutdown();
grpc_timer_manager_set_threading(
false); // shutdown timer_manager thread
@ -166,15 +167,16 @@ void grpc_shutdown(void) {
g_all_of_the_plugins[i].destroy();
}
}
grpc_mdctx_global_shutdown();
grpc_handshaker_factory_registry_shutdown();
}
grpc_iomgr_shutdown();
gpr_timers_global_destroy();
grpc_tracer_shutdown();
grpc_handshaker_factory_registry_shutdown();
grpc_iomgr_shutdown();
grpc_mdctx_global_shutdown();
grpc_slice_intern_shutdown();
grpc_stats_shutdown();
}
grpc_core::ExecCtx::GlobalShutdown();
}
gpr_mu_unlock(&g_init_mu);
}

@ -110,7 +110,7 @@ static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
static void cronet_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
grpc_exec_ctx _local_exec_ctx;
grpc_core::ExecCtx _local_exec_ctx;
stream_engine *cronetEngine = [Cronet getGlobalEngine];
grpc_channel_args *new_client_args = grpc_channel_args_copy(client_args);

@ -745,8 +745,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
input_stream inp = {data, data + size};
grpc_tcp_client_connect_impl = my_tcp_client_connect;
gpr_now_impl = now_impl;
grpc_timer_manager_set_threading(false);
grpc_init();
grpc_timer_manager_set_threading(false);
{
grpc_core::ExecCtx _local_exec_ctx;
grpc_executor_set_threading(false);

@ -89,7 +89,7 @@ static void test_get(int port) {
"pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops),
&worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_core::ExecCtx::Get()->Flush();
gpr_mu_lock(g_mu);
}
gpr_mu_unlock(g_mu);
@ -129,7 +129,7 @@ static void test_post(int port) {
"pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops),
&worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_core::ExecCtx::Get()->Flush();
gpr_mu_lock(g_mu);
}
gpr_mu_unlock(g_mu);
@ -144,7 +144,6 @@ static void destroy_pops(void* p, grpc_error* error) {
int main(int argc, char** argv) {
grpc_closure destroyed;
grpc_core::ExecCtx _local_exec_ctx;
gpr_subprocess* server;
char* me = argv[0];
char* lslash = strrchr(me, '/');
@ -196,6 +195,7 @@ int main(int argc, char** argv) {
test_post(port);
{
grpc_core::ExecCtx _local_exec_ctx;
grpc_httpcli_context_destroy(&g_context);
GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops,
grpc_schedule_on_exec_ctx);

@ -20,6 +20,7 @@
#include <stdint.h>
#include <string.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -31,6 +32,7 @@ bool leak_check = true;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
struct grpc_memory_counters counters;
grpc_init();
grpc_memory_counters_init();
grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size);
grpc_slice output;
@ -46,6 +48,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
grpc_slice_unref(input);
counters = grpc_memory_counters_snapshot();
grpc_memory_counters_destroy();
grpc_shutdown();
GPR_ASSERT(counters.total_size_relative == 0);
return 0;
}

@ -20,6 +20,7 @@
#include <stdint.h>
#include <string.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -31,6 +32,7 @@ bool leak_check = true;
static void test(const uint8_t* data, size_t size, const uint8_t* dict) {
struct grpc_memory_counters counters;
grpc_init();
grpc_memory_counters_init();
grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size);
grpc_slice output = grpc_percent_encode_slice(input, dict);
@ -48,6 +50,7 @@ static void test(const uint8_t* data, size_t size, const uint8_t* dict) {
grpc_slice_unref(permissive_decoded_output);
counters = grpc_memory_counters_snapshot();
grpc_memory_counters_destroy();
grpc_shutdown();
GPR_ASSERT(counters.total_size_relative == 0);
}

@ -36,12 +36,10 @@ int main(int argc, char** argv) {
/* TODO(yashkt) Calling grpc_init breaks tests. Fix the tests and replace
* grpc_core::ExecCtx::GlobalInit with grpc_init and GlobalShutdown with
* grpc_shutdown */
grpc_core::ExecCtx::GlobalInit();
GPR_ASSERT(
GRPC_LOG_IF_ERROR("load_file", grpc_load_file(argv[1], 0, &buffer)));
LLVMFuzzerTestOneInput(GRPC_SLICE_START_PTR(buffer),
GRPC_SLICE_LENGTH(buffer));
grpc_core::ExecCtx::GlobalShutdown();
grpc_core::ExecCtx::GlobalInit();
grpc_slice_unref(buffer);
grpc_core::ExecCtx::GlobalShutdown();

@ -249,5 +249,8 @@ TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) {
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
grpc_init();
int ret = RUN_ALL_TESTS();
grpc_shutdown();
return ret;
}

@ -17,6 +17,7 @@
*/
#include <grpc++/impl/codegen/config.h>
#include <grpc/grpc.h>
#include <gtest/gtest.h>
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h"
@ -135,5 +136,8 @@ TEST_F(GrpclbTest, ParseResponseServerList) {
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
grpc_init();
int ret = RUN_ALL_TESTS();
grpc_shutdown();
return ret;
}

@ -22,6 +22,8 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc/grpc.h>
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"
@ -77,5 +79,8 @@ TEST(ServerBuilderTest, CreateServerRepeatedPortWithDisallowedReusePort) {
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
grpc_init();
int ret = RUN_ALL_TESTS();
grpc_shutdown();
return ret;
}

@ -22,6 +22,7 @@
#include <vector>
#include <grpc++/support/slice.h>
#include <grpc/grpc.h>
#include <grpc/slice.h>
#include <gtest/gtest.h>
@ -109,5 +110,8 @@ TEST_F(ByteBufferTest, SerializationMakesCopy) {
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
grpc_init();
int ret = RUN_ALL_TESTS();
grpc_shutdown();
return ret;
}

@ -18,6 +18,7 @@
#include <grpc++/support/slice.h>
#include <grpc/grpc.h>
#include <grpc/slice.h>
#include <gtest/gtest.h>
@ -127,5 +128,8 @@ TEST_F(SliceTest, Cslice) {
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
grpc_init();
int ret = RUN_ALL_TESTS();
grpc_shutdown();
return ret;
}

Loading…
Cancel
Save