Introduce a rake test:asan task for convenient running of Address Sanitizer (#141)

This commit is contained in:
Petko Bordjukov 2019-05-27 05:45:08 +00:00 committed by Sam
parent f407f68b53
commit aaff4fc494
2 changed files with 21 additions and 1 deletions

View File

@ -16,6 +16,21 @@ Rake::ExtensionTask.new( 'mini_racer_extension', gem )
# via http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html
namespace :test do
desc "run test suite with Address Sanitizer"
task :asan do
ENV["CONFIGURE_ARGS"] = [ENV["CONFIGURE_ARGS"], '--enable-asan'].compact.join(' ')
Rake::Task['compile'].invoke
asan_path = `ldconfig -N -p | grep libasan | sed 's/.* => \\(.*\\)$/\\1/'`.chomp
cmdline = "env LD_PRELOAD=\"#{asan_path}\" ruby test/test_leak.rb"
puts cmdline
system cmdline
cmdline = "env LD_PRELOAD=\"#{asan_path}\" rake test"
puts cmdline
system cmdline
end
# partial-loads-ok and undef-value-errors necessary to ignore
# spurious (and eminently ignorable) warnings from the ruby
# interpreter

View File

@ -49,10 +49,15 @@ if CONFIG['warnflags']
CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
end
if enable_config('debug')
if enable_config('debug') || enable_config('asan')
CONFIG['debugflags'] << ' -ggdb3 -O0'
end
Libv8.configure_makefile
if enable_config('asan')
$CPPFLAGS.insert(0, " -fsanitize=address ")
$LDFLAGS.insert(0, " -fsanitize=address ")
end
create_makefile 'mini_racer_extension'