From ef1bf876657a59a0911ee87e0a6ccb35b5538d5f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Sun, 28 Feb 2016 17:37:33 -0800 Subject: [PATCH 1/6] ESAN prototype --- Makefile | 8 ++++ build.yaml | 3 ++ src/core/iomgr/exec_ctx.c | 76 ++++++++++++++++++++++++++++++++ src/core/iomgr/exec_ctx.h | 20 ++++++--- src/core/iomgr/iomgr.c | 3 ++ src/core/iomgr/workqueue_posix.c | 4 +- tools/run_tests/configs.json | 3 ++ 7 files changed, 110 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 5be0d146afc..5d2f07145f2 100644 --- a/Makefile +++ b/Makefile @@ -209,6 +209,14 @@ CPPFLAGS_mutrace = -O0 LDFLAGS_mutrace = -rdynamic DEFINES_mutrace = _DEBUG DEBUG +VALID_CONFIG_esan = 1 +CC_esan = $(DEFAULT_CC) +CXX_esan = $(DEFAULT_CXX) +LD_esan = $(DEFAULT_CC) +LDXX_esan = $(DEFAULT_CXX) +CPPFLAGS_esan = -O0 +DEFINES_esan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER + # General settings. diff --git a/build.yaml b/build.yaml index a277539a054..c025b250e93 100644 --- a/build.yaml +++ b/build.yaml @@ -2724,6 +2724,9 @@ configs: dbg: CPPFLAGS: -O0 DEFINES: _DEBUG DEBUG + esan: + CPPFLAGS: -O0 + DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER gcov: CC: gcc CPPFLAGS: -O0 -fprofile-arcs -ftest-coverage -Wno-return-type diff --git a/src/core/iomgr/exec_ctx.c b/src/core/iomgr/exec_ctx.c index 1fd79f6ebac..abcdd2fa0a4 100644 --- a/src/core/iomgr/exec_ctx.c +++ b/src/core/iomgr/exec_ctx.c @@ -34,9 +34,12 @@ #include "src/core/iomgr/exec_ctx.h" #include +#include +#include #include "src/core/profiling/timers.h" +#ifndef GRPC_EXECUTION_CONTEXT_SANITIZER bool grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx) { bool did_something = 0; GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0); @@ -74,3 +77,76 @@ void grpc_exec_ctx_enqueue_list(grpc_exec_ctx *exec_ctx, GPR_ASSERT(offload_target_or_null == NULL); grpc_closure_list_move(list, &exec_ctx->closure_list); } + +void grpc_exec_ctx_global_init(void) {} +void grpc_exec_ctx_global_shutdown(void) {} +#else +static gpr_mu g_mu; +static gpr_cv g_cv; +static int g_threads = 0; + +static void run_closure(void *arg) { + grpc_closure *closure = arg; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + closure->cb(&exec_ctx, closure->cb_arg, (closure->final_data & 1) != 0); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(&g_mu); + if (--g_threads == 0) { + gpr_cv_signal(&g_cv); + } + gpr_mu_unlock(&g_mu); +} + +static void start_closure(grpc_closure *closure) { + gpr_thd_id id; + gpr_mu_lock(&g_mu); + g_threads++; + gpr_mu_unlock(&g_mu); + gpr_thd_new(&id, run_closure, closure, NULL); +} + +bool grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx) { + return false; +} + +void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx) { +} + +void grpc_exec_ctx_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure, + bool success, + grpc_workqueue *offload_target_or_null) { + GPR_ASSERT(offload_target_or_null == NULL); + closure->final_data = success; + start_closure(closure); +} + +void grpc_exec_ctx_enqueue_list(grpc_exec_ctx *exec_ctx, + grpc_closure_list *list, + grpc_workqueue *offload_target_or_null) { + GPR_ASSERT(offload_target_or_null == NULL); + grpc_closure *p = list->head; + while (p) { + grpc_closure *start = p; + p = grpc_closure_next(start); + start_closure(start); + } + grpc_closure_list r = GRPC_CLOSURE_LIST_INIT; + *list = r; +} + +void grpc_exec_ctx_global_init(void) { + gpr_mu_init(&g_mu); + gpr_cv_init(&g_cv); +} + +void grpc_exec_ctx_global_shutdown(void) { + gpr_mu_lock(&g_mu); + while (g_threads != 0) { + gpr_cv_wait(&g_cv, &g_mu, gpr_inf_future(GPR_CLOCK_REALTIME)); + } + gpr_mu_unlock(&g_mu); + + gpr_mu_destroy(&g_mu); + gpr_cv_destroy(&g_cv); +} +#endif diff --git a/src/core/iomgr/exec_ctx.h b/src/core/iomgr/exec_ctx.h index 9a9b2e55fa7..3403a978ecf 100644 --- a/src/core/iomgr/exec_ctx.h +++ b/src/core/iomgr/exec_ctx.h @@ -36,6 +36,14 @@ #include "src/core/iomgr/closure.h" +/* #define GRPC_EXECUTION_CONTEXT_SANITIZER 1 */ + +/** A workqueue represents a list of work to be executed asynchronously. + Forward declared here to avoid a circular dependency with workqueue.h. */ +struct grpc_workqueue; +typedef struct grpc_workqueue grpc_workqueue; + +#ifndef GRPC_EXECUTION_CONTEXT_SANITIZER /** Execution context. * A bag of data that collects information along a callstack. * Generally created at public API entry points, and passed down as @@ -57,13 +65,12 @@ struct grpc_exec_ctx { grpc_closure_list closure_list; }; -/** A workqueue represents a list of work to be executed asynchronously. - Forward declared here to avoid a circular dependency with workqueue.h. */ -struct grpc_workqueue; -typedef struct grpc_workqueue grpc_workqueue; - #define GRPC_EXEC_CTX_INIT \ { GRPC_CLOSURE_LIST_INIT } +#else +struct grpc_exec_ctx {}; +#define GRPC_EXEC_CTX_INIT {} +#endif /** Flush any work that has been enqueued onto this grpc_exec_ctx. * Caller must guarantee that no interfering locks are held. @@ -82,4 +89,7 @@ void grpc_exec_ctx_enqueue_list(grpc_exec_ctx *exec_ctx, grpc_closure_list *list, grpc_workqueue *offload_target_or_null); +void grpc_exec_ctx_global_init(void); +void grpc_exec_ctx_global_shutdown(void); + #endif diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c index 04580150f3a..bd279f6d799 100644 --- a/src/core/iomgr/iomgr.c +++ b/src/core/iomgr/iomgr.c @@ -42,6 +42,7 @@ #include #include +#include "src/core/iomgr/exec_ctx.h" #include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/timer.h" #include "src/core/support/string.h" @@ -55,6 +56,7 @@ void grpc_iomgr_init(void) { g_shutdown = 0; gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); + grpc_exec_ctx_global_init(); grpc_timer_list_init(gpr_now(GPR_CLOCK_MONOTONIC)); g_root_object.next = g_root_object.prev = &g_root_object; g_root_object.name = "root"; @@ -133,6 +135,7 @@ void grpc_iomgr_shutdown(void) { grpc_pollset_global_shutdown(); grpc_iomgr_platform_shutdown(); + grpc_exec_ctx_global_shutdown(); gpr_mu_destroy(&g_mu); gpr_cv_destroy(&g_rcv); } diff --git a/src/core/iomgr/workqueue_posix.c b/src/core/iomgr/workqueue_posix.c index c096dbfb30c..2b42e6d4fbf 100644 --- a/src/core/iomgr/workqueue_posix.c +++ b/src/core/iomgr/workqueue_posix.c @@ -107,7 +107,7 @@ void grpc_workqueue_flush(grpc_exec_ctx *exec_ctx, grpc_workqueue *workqueue) { if (grpc_closure_list_empty(workqueue->closure_list)) { grpc_wakeup_fd_wakeup(&workqueue->wakeup_fd); } - grpc_closure_list_move(&exec_ctx->closure_list, &workqueue->closure_list); + grpc_exec_ctx_enqueue_list(exec_ctx, &workqueue->closure_list, NULL); gpr_mu_unlock(&workqueue->mu); } @@ -123,7 +123,7 @@ static void on_readable(grpc_exec_ctx *exec_ctx, void *arg, bool success) { gpr_free(workqueue); } else { gpr_mu_lock(&workqueue->mu); - grpc_closure_list_move(&workqueue->closure_list, &exec_ctx->closure_list); + grpc_exec_ctx_enqueue_list(exec_ctx, &workqueue->closure_list, NULL); grpc_wakeup_fd_consume_wakeup(&workqueue->wakeup_fd); gpr_mu_unlock(&workqueue->mu); grpc_fd_notify_on_read(exec_ctx, workqueue->wakeup_read_fd, diff --git a/tools/run_tests/configs.json b/tools/run_tests/configs.json index cbb8ec57b61..47ce7862fd4 100644 --- a/tools/run_tests/configs.json +++ b/tools/run_tests/configs.json @@ -63,5 +63,8 @@ }, { "config": "mutrace" + }, + { + "config": "esan" } ] From d93aa14fd0c648905d1896306dfe204c48ada0d4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Sun, 28 Feb 2016 20:56:13 -0800 Subject: [PATCH 2/6] It seems saner to base this on TSAN --- Makefile | 13 ++++++++----- build.yaml | 12 +++++++++++- tools/run_tests/configs.json | 6 +++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 5d2f07145f2..8b42ac70655 100644 --- a/Makefile +++ b/Makefile @@ -210,12 +210,15 @@ LDFLAGS_mutrace = -rdynamic DEFINES_mutrace = _DEBUG DEBUG VALID_CONFIG_esan = 1 -CC_esan = $(DEFAULT_CC) -CXX_esan = $(DEFAULT_CXX) -LD_esan = $(DEFAULT_CC) -LDXX_esan = $(DEFAULT_CXX) -CPPFLAGS_esan = -O0 +REQUIRE_CUSTOM_LIBRARIES_esan = 1 +CC_esan = clang +CXX_esan = clang++ +LD_esan = clang +LDXX_esan = clang++ +CPPFLAGS_esan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_esan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) DEFINES_esan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER +DEFINES_esan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 diff --git a/build.yaml b/build.yaml index c025b250e93..81fcf4f6a8c 100644 --- a/build.yaml +++ b/build.yaml @@ -2725,8 +2725,18 @@ configs: CPPFLAGS: -O0 DEFINES: _DEBUG DEBUG esan: - CPPFLAGS: -O0 + CC: clang + CPPFLAGS: -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument + -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS + CXX: clang++ DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER + LD: clang + LDFLAGS: -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) + LDXX: clang++ + compile_the_world: true + test_environ: + TSAN_OPTIONS: suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1 + timeout_multiplier: 5 gcov: CC: gcc CPPFLAGS: -O0 -fprofile-arcs -ftest-coverage -Wno-return-type diff --git a/tools/run_tests/configs.json b/tools/run_tests/configs.json index 47ce7862fd4..cd5f99908e7 100644 --- a/tools/run_tests/configs.json +++ b/tools/run_tests/configs.json @@ -65,6 +65,10 @@ "config": "mutrace" }, { - "config": "esan" + "config": "esan", + "environ": { + "TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1" + }, + "timeout_multiplier": 5 } ] From 3af3f743c32af30adac4fbae780ee63a2af9a489 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Sun, 28 Feb 2016 21:53:13 -0800 Subject: [PATCH 3/6] Fixes to things --- Makefile | 147 ++++++++++++++++++++--------------- build.yaml | 19 ++++- src/core/iomgr/exec_ctx.c | 11 ++- src/core/iomgr/exec_ctx.h | 3 +- test/core/util/port_posix.c | 19 +++-- tools/run_tests/configs.json | 57 ++++++++------ 6 files changed, 151 insertions(+), 105 deletions(-) diff --git a/Makefile b/Makefile index 8b42ac70655..78257f023fb 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,46 @@ LDXX_opt = $(DEFAULT_CXX) CPPFLAGS_opt = -O2 DEFINES_opt = NDEBUG +VALID_CONFIG_dbg = 1 +CC_dbg = $(DEFAULT_CC) +CXX_dbg = $(DEFAULT_CXX) +LD_dbg = $(DEFAULT_CC) +LDXX_dbg = $(DEFAULT_CXX) +CPPFLAGS_dbg = -O0 +DEFINES_dbg = _DEBUG DEBUG + +VALID_CONFIG_easan = 1 +REQUIRE_CUSTOM_LIBRARIES_easan = 1 +CC_easan = clang +CXX_easan = clang++ +LD_easan = clang +LDXX_easan = clang++ +CPPFLAGS_easan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_easan = -fsanitize=address +DEFINES_easan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER +DEFINES_easan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 + +VALID_CONFIG_asan = 1 +REQUIRE_CUSTOM_LIBRARIES_asan = 1 +CC_asan = clang +CXX_asan = clang++ +LD_asan = clang +LDXX_asan = clang++ +CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_asan = -fsanitize=address +DEFINES_asan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 + +VALID_CONFIG_msan = 1 +REQUIRE_CUSTOM_LIBRARIES_msan = 1 +CC_msan = clang +CXX_msan = clang++ +LD_msan = clang +LDXX_msan = clang++ +CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) +DEFINES_msan = NDEBUG +DEFINES_msan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4 + VALID_CONFIG_basicprof = 1 CC_basicprof = $(DEFAULT_CC) CXX_basicprof = $(DEFAULT_CXX) @@ -123,6 +163,14 @@ CPPFLAGS_asan-noleaks = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unus LDFLAGS_asan-noleaks = -fsanitize=address DEFINES_asan-noleaks += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 +VALID_CONFIG_edbg = 1 +CC_edbg = $(DEFAULT_CC) +CXX_edbg = $(DEFAULT_CXX) +LD_edbg = $(DEFAULT_CC) +LDXX_edbg = $(DEFAULT_CXX) +CPPFLAGS_edbg = -O0 +DEFINES_edbg = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER + VALID_CONFIG_ubsan = 1 REQUIRE_CUSTOM_LIBRARIES_ubsan = 1 CC_ubsan = clang @@ -134,13 +182,15 @@ LDFLAGS_ubsan = -fsanitize=undefined DEFINES_ubsan = NDEBUG DEFINES_ubsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=1.5 -VALID_CONFIG_dbg = 1 -CC_dbg = $(DEFAULT_CC) -CXX_dbg = $(DEFAULT_CXX) -LD_dbg = $(DEFAULT_CC) -LDXX_dbg = $(DEFAULT_CXX) -CPPFLAGS_dbg = -O0 -DEFINES_dbg = _DEBUG DEBUG +VALID_CONFIG_tsan = 1 +REQUIRE_CUSTOM_LIBRARIES_tsan = 1 +CC_tsan = clang +CXX_tsan = clang++ +LD_tsan = clang +LDXX_tsan = clang++ +CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_tsan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) +DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 VALID_CONFIG_stapprof = 1 CC_stapprof = $(DEFAULT_CC) @@ -150,14 +200,14 @@ LDXX_stapprof = $(DEFAULT_CXX) CPPFLAGS_stapprof = -O2 -DGRPC_STAP_PROFILER DEFINES_stapprof = NDEBUG -VALID_CONFIG_gcov = 1 -CC_gcov = gcc -CXX_gcov = g++ -LD_gcov = gcc -LDXX_gcov = g++ -CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage -Wno-return-type -LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic -DEFINES_gcov = _DEBUG DEBUG GPR_GCOV +VALID_CONFIG_mutrace = 1 +CC_mutrace = $(DEFAULT_CC) +CXX_mutrace = $(DEFAULT_CXX) +LD_mutrace = $(DEFAULT_CC) +LDXX_mutrace = $(DEFAULT_CXX) +CPPFLAGS_mutrace = -O0 +LDFLAGS_mutrace = -rdynamic +DEFINES_mutrace = _DEBUG DEBUG VALID_CONFIG_memcheck = 1 CC_memcheck = $(DEFAULT_CC) @@ -169,56 +219,25 @@ LDFLAGS_memcheck = -rdynamic DEFINES_memcheck = _DEBUG DEBUG DEFINES_memcheck += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10 -VALID_CONFIG_asan = 1 -REQUIRE_CUSTOM_LIBRARIES_asan = 1 -CC_asan = clang -CXX_asan = clang++ -LD_asan = clang -LDXX_asan = clang++ -CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_asan = -fsanitize=address -DEFINES_asan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 - -VALID_CONFIG_tsan = 1 -REQUIRE_CUSTOM_LIBRARIES_tsan = 1 -CC_tsan = clang -CXX_tsan = clang++ -LD_tsan = clang -LDXX_tsan = clang++ -CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_tsan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) -DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 +VALID_CONFIG_etsan = 1 +REQUIRE_CUSTOM_LIBRARIES_etsan = 1 +CC_etsan = clang +CXX_etsan = clang++ +LD_etsan = clang +LDXX_etsan = clang++ +CPPFLAGS_etsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_etsan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) +DEFINES_etsan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER +DEFINES_etsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 -VALID_CONFIG_msan = 1 -REQUIRE_CUSTOM_LIBRARIES_msan = 1 -CC_msan = clang -CXX_msan = clang++ -LD_msan = clang -LDXX_msan = clang++ -CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) -DEFINES_msan = NDEBUG -DEFINES_msan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4 - -VALID_CONFIG_mutrace = 1 -CC_mutrace = $(DEFAULT_CC) -CXX_mutrace = $(DEFAULT_CXX) -LD_mutrace = $(DEFAULT_CC) -LDXX_mutrace = $(DEFAULT_CXX) -CPPFLAGS_mutrace = -O0 -LDFLAGS_mutrace = -rdynamic -DEFINES_mutrace = _DEBUG DEBUG - -VALID_CONFIG_esan = 1 -REQUIRE_CUSTOM_LIBRARIES_esan = 1 -CC_esan = clang -CXX_esan = clang++ -LD_esan = clang -LDXX_esan = clang++ -CPPFLAGS_esan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_esan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) -DEFINES_esan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER -DEFINES_esan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 +VALID_CONFIG_gcov = 1 +CC_gcov = gcc +CXX_gcov = g++ +LD_gcov = gcc +LDXX_gcov = g++ +CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage -Wno-return-type +LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic +DEFINES_gcov = _DEBUG DEBUG GPR_GCOV diff --git a/build.yaml b/build.yaml index 81fcf4f6a8c..d1423324720 100644 --- a/build.yaml +++ b/build.yaml @@ -2724,7 +2724,24 @@ configs: dbg: CPPFLAGS: -O0 DEFINES: _DEBUG DEBUG - esan: + easan: + CC: clang + CPPFLAGS: -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument + -DGPR_NO_DIRECT_SYSCALLS + CXX: clang++ + DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER + LD: clang + LDFLAGS: -fsanitize=address + LDXX: clang++ + compile_the_world: true + test_environ: + ASAN_OPTIONS: detect_leaks=1:color=always + LSAN_OPTIONS: suppressions=tools/lsan_suppressions.txt:report_objects=1 + timeout_multiplier: 3 + edbg: + CPPFLAGS: -O0 + DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER + etsan: CC: clang CPPFLAGS: -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS diff --git a/src/core/iomgr/exec_ctx.c b/src/core/iomgr/exec_ctx.c index abcdd2fa0a4..893fe4515c7 100644 --- a/src/core/iomgr/exec_ctx.c +++ b/src/core/iomgr/exec_ctx.c @@ -105,17 +105,15 @@ static void start_closure(grpc_closure *closure) { gpr_thd_new(&id, run_closure, closure, NULL); } -bool grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx) { - return false; -} +bool grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx) { return false; } -void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx) { -} +void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx) {} void grpc_exec_ctx_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure, bool success, grpc_workqueue *offload_target_or_null) { GPR_ASSERT(offload_target_or_null == NULL); + if (closure == NULL) return; closure->final_data = success; start_closure(closure); } @@ -123,7 +121,8 @@ void grpc_exec_ctx_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure, void grpc_exec_ctx_enqueue_list(grpc_exec_ctx *exec_ctx, grpc_closure_list *list, grpc_workqueue *offload_target_or_null) { - GPR_ASSERT(offload_target_or_null == NULL); + GPR_ASSERT(offload_target_or_null == NULL); + if (list == NULL) return; grpc_closure *p = list->head; while (p) { grpc_closure *start = p; diff --git a/src/core/iomgr/exec_ctx.h b/src/core/iomgr/exec_ctx.h index 3403a978ecf..b7388657ed1 100644 --- a/src/core/iomgr/exec_ctx.h +++ b/src/core/iomgr/exec_ctx.h @@ -69,7 +69,8 @@ struct grpc_exec_ctx { { GRPC_CLOSURE_LIST_INIT } #else struct grpc_exec_ctx {}; -#define GRPC_EXEC_CTX_INIT {} +#define GRPC_EXEC_CTX_INIT \ + {} #endif /** Flush any work that has been enqueued onto this grpc_exec_ctx. diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index ba382d242a3..c4bd00c1baa 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -77,6 +77,7 @@ typedef struct freereq { static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); + gpr_free(p); grpc_shutdown(); } @@ -95,7 +96,7 @@ static void free_port_using_server(char *server, int port) { freereq pr; char *path; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_closure shutdown_closure; + grpc_closure *shutdown_closure; grpc_init(); @@ -104,8 +105,8 @@ static void free_port_using_server(char *server, int port) { pr.pollset = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(pr.pollset, &pr.mu); - grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown, - pr.pollset); + shutdown_closure = + grpc_closure_create(destroy_pollset_and_shutdown, pr.pollset); req.host = server; gpr_asprintf(&path, "/drop/%d", port); @@ -126,9 +127,8 @@ static void free_port_using_server(char *server, int port) { grpc_httpcli_context_destroy(&context); grpc_exec_ctx_finish(&exec_ctx); - grpc_pollset_shutdown(&exec_ctx, pr.pollset, &shutdown_closure); + grpc_pollset_shutdown(&exec_ctx, pr.pollset, shutdown_closure); grpc_exec_ctx_finish(&exec_ctx); - gpr_free(pr.pollset); gpr_free(path); } @@ -262,7 +262,7 @@ static int pick_port_using_server(char *server) { grpc_httpcli_request req; portreq pr; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_closure shutdown_closure; + grpc_closure *shutdown_closure; grpc_init(); @@ -270,8 +270,8 @@ static int pick_port_using_server(char *server) { memset(&req, 0, sizeof(req)); pr.pollset = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(pr.pollset, &pr.mu); - grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown, - pr.pollset); + shutdown_closure = + grpc_closure_create(destroy_pollset_and_shutdown, pr.pollset); pr.port = -1; pr.server = server; pr.ctx = &context; @@ -294,9 +294,8 @@ static int pick_port_using_server(char *server) { gpr_mu_unlock(pr.mu); grpc_httpcli_context_destroy(&context); - grpc_pollset_shutdown(&exec_ctx, pr.pollset, &shutdown_closure); + grpc_pollset_shutdown(&exec_ctx, pr.pollset, shutdown_closure); grpc_exec_ctx_finish(&exec_ctx); - gpr_free(pr.pollset); return pr.port; } diff --git a/tools/run_tests/configs.json b/tools/run_tests/configs.json index cd5f99908e7..a858170d87a 100644 --- a/tools/run_tests/configs.json +++ b/tools/run_tests/configs.json @@ -2,6 +2,29 @@ { "config": "opt" }, + { + "config": "dbg" + }, + { + "config": "easan", + "environ": { + "ASAN_OPTIONS": "detect_leaks=1:color=always", + "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" + }, + "timeout_multiplier": 3 + }, + { + "config": "asan", + "environ": { + "ASAN_OPTIONS": "detect_leaks=1:color=always", + "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" + }, + "timeout_multiplier": 3 + }, + { + "config": "msan", + "timeout_multiplier": 4 + }, { "config": "basicprof" }, @@ -20,18 +43,25 @@ }, "timeout_multiplier": 3 }, + { + "config": "edbg" + }, { "config": "ubsan", "timeout_multiplier": 1.5 }, { - "config": "dbg" + "config": "tsan", + "environ": { + "TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1" + }, + "timeout_multiplier": 5 }, { "config": "stapprof" }, { - "config": "gcov" + "config": "mutrace" }, { "config": "memcheck", @@ -43,32 +73,13 @@ ] }, { - "config": "asan", - "environ": { - "ASAN_OPTIONS": "detect_leaks=1:color=always", - "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" - }, - "timeout_multiplier": 3 - }, - { - "config": "tsan", + "config": "etsan", "environ": { "TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1" }, "timeout_multiplier": 5 }, { - "config": "msan", - "timeout_multiplier": 4 - }, - { - "config": "mutrace" - }, - { - "config": "esan", - "environ": { - "TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1" - }, - "timeout_multiplier": 5 + "config": "gcov" } ] From b929d7667eb3a18526fe2d00de7d3103f384f1fa Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Sun, 28 Feb 2016 23:12:36 -0800 Subject: [PATCH 4/6] C++ fix --- src/core/iomgr/exec_ctx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/iomgr/exec_ctx.h b/src/core/iomgr/exec_ctx.h index b7388657ed1..ea09188c8f3 100644 --- a/src/core/iomgr/exec_ctx.h +++ b/src/core/iomgr/exec_ctx.h @@ -68,7 +68,7 @@ struct grpc_exec_ctx { #define GRPC_EXEC_CTX_INIT \ { GRPC_CLOSURE_LIST_INIT } #else -struct grpc_exec_ctx {}; +struct grpc_exec_ctx { int unused; }; #define GRPC_EXEC_CTX_INIT \ {} #endif From aa1c3392091c6cb9930067e005e5d19814a0cb76 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 1 Mar 2016 21:25:05 -0800 Subject: [PATCH 5/6] fix compile --- src/core/iomgr/exec_ctx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/iomgr/exec_ctx.h b/src/core/iomgr/exec_ctx.h index ea09188c8f3..8a2e5d5f6a2 100644 --- a/src/core/iomgr/exec_ctx.h +++ b/src/core/iomgr/exec_ctx.h @@ -70,7 +70,7 @@ struct grpc_exec_ctx { #else struct grpc_exec_ctx { int unused; }; #define GRPC_EXEC_CTX_INIT \ - {} + {0} #endif /** Flush any work that has been enqueued onto this grpc_exec_ctx. From 92bab124695f64588c84884511e32ef7d55c5c42 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 1 Mar 2016 23:35:35 -0800 Subject: [PATCH 6/6] clang-format --- src/core/iomgr/exec_ctx.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/iomgr/exec_ctx.h b/src/core/iomgr/exec_ctx.h index 8a2e5d5f6a2..1b627a5dcf8 100644 --- a/src/core/iomgr/exec_ctx.h +++ b/src/core/iomgr/exec_ctx.h @@ -68,9 +68,11 @@ struct grpc_exec_ctx { #define GRPC_EXEC_CTX_INIT \ { GRPC_CLOSURE_LIST_INIT } #else -struct grpc_exec_ctx { int unused; }; +struct grpc_exec_ctx { + int unused; +}; #define GRPC_EXEC_CTX_INIT \ - {0} + { 0 } #endif /** Flush any work that has been enqueued onto this grpc_exec_ctx.