Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binary_name back #27

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ If you want to override any of the default configurations you can call `RubyMemc

`RubyMemcheck::Configuration` accepts a variety of keyword arguments. Here are all the arguments:

- `binary_name`: Optional. The name of the only binary to report errors for. Use this if there is too much noise caused by other binaries.
- `ruby`: Optional. The command to run to invoke Ruby. Defaults to the Ruby that is currently being used.
- `valgrind`: Optional. The command to run to invoke Valgrind. Defaults to the string `"valgrind"`.
- `valgrind_options`: Optional. Array of options to pass into Valgrind. This is only present as an escape hatch, so avoid using it. This may be deprecated or removed in future versions.
Expand Down
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
28 changes: 28 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,34 @@ 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
RubyMemcheck::CTestTwo.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