Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Sep 18, 2023
1 parent 3b1d7a4 commit ef8952a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/ruby_memcheck/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Configuration
/\Arb_yield/,
].freeze

attr_reader :binary_name
attr_reader :ruby
attr_reader :valgrind
attr_reader :valgrind_options
Expand All @@ -57,8 +58,7 @@ def initialize(
output_io: $stderr,
filter_all_errors: false
)
warn("ruby_memcheck: binary_name is no longer required for configuration") if binary_name

@binary_name = binary_name
@ruby = ruby
@valgrind = valgrind
@valgrind_options = valgrind_options
Expand Down
14 changes: 12 additions & 2 deletions lib/ruby_memcheck/test_task_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ def loaded_binaries
@loaded_binaries = loaded_features.keep_if do |feat|
# Keep only binaries (ignore Ruby files).
File.extname(feat) == ".so"
end.freeze
end

if configuration.binary_name
@loaded_binaries.keep_if do |feat|
File.basename(feat, ".*") == configuration.binary_name
end

if @loaded_binaries.empty?
raise "The Ruby program executed never loaded a binary called `#{configuration.binary_name}`"
end
end

@loaded_binaries
@loaded_binaries.freeze
end

def valgrind_xml_files
Expand Down
27 changes: 27 additions & 0 deletions test/ruby_memcheck/shared_test_task_reporter_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,33 @@ def test_envionment_variable_RUBY_MEMCHECK_RUNNING
end
end

def test_configration_binary_name
build_configuration(binary_name: "ruby_memcheck_c_test_one")
error = assert_raises do
run_with_memcheck(<<~RUBY)
RubyMemcheck::CTestOne.new.memory_leak
RUBY
end
assert_equal(RubyMemcheck::TestTaskReporter::VALGRIND_REPORT_MSG, error.message)

assert_equal(1, @test_task.reporter.errors.length)

output = @output_io.string
refute_empty(output)
assert_match(/^100 bytes in 1 blocks are definitely lost in loss record/, output)
assert_match(/^ \*c_test_one_memory_leak \(ruby_memcheck_c_test_one\.c:\d+\)$/, output)
end

def test_configration_invalid_binary_name
build_configuration(binary_name: "invalid_binary_name")
error = assert_raises do
run_with_memcheck(<<~RUBY)
RubyMemcheck::CTestOne.new.memory_leak
RUBY
end
assert_includes(error.message, "`invalid_binary_name`")
end

private

def run_with_memcheck(code, raise_on_failure: true, spawn_opts: {})
Expand Down

0 comments on commit ef8952a

Please sign in to comment.