Skip to content

Commit

Permalink
Skip assert_no_memory_leak when ASAN is enabled
Browse files Browse the repository at this point in the history
ASAN greatly increases the memory footprint of Ruby, so these static
thresholds are not appropriate. There's no real need to run these tests
under ASAN.

[Bug #20274]
  • Loading branch information
KJTsanaktsidis committed Feb 28, 2024
1 parent 47b46fd commit fe0b704
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ext/-test-/asan/asan.c
@@ -0,0 +1,24 @@
#include "ruby/ruby.h"

static VALUE
asan_enabled_p(VALUE self)
{
#if defined(__has_feature)
/* clang uses __has_feature for determining asan */
return __has_feature(address_sanitizer) ? Qtrue : Qfalse;
#elif defined(__SANITIZE_ADDRESS__)
/* GCC sets __SANITIZE_ADDRESS__ for determining asan */
return Qtrue;
#else
return Qfalse;
#endif
}

void
Init_asan(void)
{
VALUE m = rb_define_module("Test");
VALUE c = rb_define_class_under(m, "ASAN", rb_cObject);
rb_define_singleton_method(c, "enabled?", asan_enabled_p, 0);
}

2 changes: 2 additions & 0 deletions ext/-test-/asan/extconf.rb
@@ -0,0 +1,2 @@
require 'mkmf'
create_makefile('-test-/asan')
8 changes: 8 additions & 0 deletions tool/lib/core_assertions.rb
Expand Up @@ -74,6 +74,11 @@ def message msg = nil, ending = nil, &default
module CoreAssertions
require_relative 'envutil'
require 'pp'
begin
require '-test-/asan'
rescue LoadError
end

nil.pretty_inspect

def mu_pp(obj) #:nodoc:
Expand Down Expand Up @@ -152,6 +157,9 @@ def assert_no_memory_leak(args, prepare, code, message=nil, limit: 2.0, rss: fal
pend 'assert_no_memory_leak may consider RJIT memory usage as leak' if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
# For previous versions which implemented MJIT
pend 'assert_no_memory_leak may consider MJIT memory usage as leak' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
# ASAN has the same problem - its shadow memory greatly increases memory usage
# (plus asan has better ways to detect memory leaks than this assertion)
pend 'assert_no_memory_leak may consider ASAN memory usage as leak' if defined?(Test::ASAN) && Test::ASAN.enabled?

require_relative 'memory_status'
raise Test::Unit::PendedError, "unsupported platform" unless defined?(Memory::Status)
Expand Down

0 comments on commit fe0b704

Please sign in to comment.