pull/36509/head
Craig Tiller 10 months ago
parent 9ea318e41f
commit fbe696f865
  1. 13
      test/core/event_engine/event_engine_test_utils.cc
  2. 37
      test/core/test_util/build.cc
  3. 3
      test/core/test_util/build.h

@ -41,16 +41,7 @@
#include "src/core/lib/gprpp/notification.h" #include "src/core/lib/gprpp/notification.h"
#include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time.h"
#include "src/core/lib/resource_quota/memory_quota.h" #include "src/core/lib/resource_quota/memory_quota.h"
#include "test/core/test_util/build.h"
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#include <sanitizer/lsan_interface.h>
#define GRPC_FORCE_LEAK_CHECK() __lsan_do_leak_check()
#endif
#endif
#ifndef GRPC_FORCE_LEAK_CHECK
#define GRPC_FORCE_LEAK_CHECK()
#endif
// IWYU pragma: no_include <sys/socket.h> // IWYU pragma: no_include <sys/socket.h>
@ -90,7 +81,7 @@ void WaitForSingleOwner(std::shared_ptr<EventEngine> engine) {
int n = 0; int n = 0;
while (engine.use_count() > 1) { while (engine.use_count() > 1) {
++n; ++n;
if (n == 500) GRPC_FORCE_LEAK_CHECK(); if (n == 100) AsanAssertNoLeaks();
GRPC_LOG_EVERY_N_SEC(2, GPR_INFO, "engine.use_count() = %ld", GRPC_LOG_EVERY_N_SEC(2, GPR_INFO, "engine.use_count() = %ld",
engine.use_count()); engine.use_count());
absl::SleepFor(absl::Milliseconds(100)); absl::SleepFor(absl::Milliseconds(100));

@ -12,6 +12,25 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "build.h"
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define GRPC_BUILD_HAS_ASAN 1
#else
#define GRPC_BUILD_HAS_ASAN 0
#endif
#else
#ifdef ADDRESS_SANITIZER
#define GRPC_BUILD_HAS_ASAN 1
#else
#define GRPC_BUILD_HAS_ASAN 0
#endif
#endif
#if GRPC_BUILD_HAS_ASAN
#include <sanitizer/lsan_interface.h>
#endif
bool BuiltUnderValgrind() { bool BuiltUnderValgrind() {
#ifdef RUNNING_ON_VALGRIND #ifdef RUNNING_ON_VALGRIND
return true; return true;
@ -36,19 +55,11 @@ bool BuiltUnderTsan() {
#endif #endif
} }
bool BuiltUnderAsan() { bool BuiltUnderAsan() { return GRPC_BUILD_HAS_ASAN != 0; }
#if defined(__has_feature)
#if __has_feature(address_sanitizer) void AsanAssertNoLeaks() {
return true; #if GRPC_BUILD_HAS_ASAN
#else __lsan_do_leak_check();
return false;
#endif
#else
#ifdef ADDRESS_SANITIZER
return true;
#else
return false;
#endif
#endif #endif
} }

@ -30,4 +30,7 @@ bool BuiltUnderMsan();
// Returns whether this is built under UndefinedBehaviorSanitizer // Returns whether this is built under UndefinedBehaviorSanitizer
bool BuiltUnderUbsan(); bool BuiltUnderUbsan();
// Force a leak check if built under ASAN. If there are leaks, crash.
void AsanAssertNoLeaks();
#endif // GRPC_TEST_CORE_TEST_UTIL_BUILD_H #endif // GRPC_TEST_CORE_TEST_UTIL_BUILD_H

Loading…
Cancel
Save