From ef8952a225a20bb655f1fc5fa69c5c181287ec54 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 18 Sep 2023 10:53:48 -0400 Subject: [PATCH] . --- .DS_Store | Bin 0 -> 6148 bytes lib/ruby_memcheck/configuration.rb | 4 +-- lib/ruby_memcheck/test_task_reporter.rb | 14 +++++++-- .../shared_test_task_reporter_tests.rb | 27 ++++++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..29f9d46361141e1029c0c58f70af1e33249e100a GIT binary patch literal 6148 zcmeHLy-EW?5S}%M#-Ac$V|g#2n94@w4ADYC1Uo^{XwX371(TqSa8IBQB325P+SrNs z7M5CQ?>Donx9cThB@%Xy-S2LGc4j~BcC#TORqE^&i3&uNM`H{|&~*{EbIZtp(M$pr zk5S(*ZtTX5X2#PiJOiGA|HuG;y8%tpKGmr0e7^%XiEV4d<#MGSSD?#Jtvn_xoA-;Z zeeXwm^T1jghSw2FL!Wu+fI3uhveVFW*2Au0?dh$0y&yGw8>bPcmGt&<>Y*8~Cr4E} zp{iR4U8NQ~|JmBs#r%@wH*t2}tkuoO>n-xt!TPs(&z`0hJKyb&l~3aAd|9iT?~e10 zQ42gbaUEf%EnGE<>5y9Pj0azS^0jLkKQBE@EDHxc$F{5djlWyB@Dxy6>UG~wTD?S_ zUpBk0UY7O&5|G0=zGtAXTUS?#Q?7lAsS<3FwrPW2Rbwp%2BK zRHV`Oo&nE*%Ro*)7I^<(>V5uqgZz_cz%$TS45*;IQ7&OhW^c_*j`!LSZ5xe+{Su85 lg3fHma>H9O|F0kdTgW%S$Y7!o8i@ZPAT;>SGw`Pjd;rT|!Vdrd literal 0 HcmV?d00001 diff --git a/lib/ruby_memcheck/configuration.rb b/lib/ruby_memcheck/configuration.rb index 0e31ac1..a373b3e 100644 --- a/lib/ruby_memcheck/configuration.rb +++ b/lib/ruby_memcheck/configuration.rb @@ -31,6 +31,7 @@ class Configuration /\Arb_yield/, ].freeze + attr_reader :binary_name attr_reader :ruby attr_reader :valgrind attr_reader :valgrind_options @@ -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 diff --git a/lib/ruby_memcheck/test_task_reporter.rb b/lib/ruby_memcheck/test_task_reporter.rb index a9c21b9..0803277 100644 --- a/lib/ruby_memcheck/test_task_reporter.rb +++ b/lib/ruby_memcheck/test_task_reporter.rb @@ -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 diff --git a/test/ruby_memcheck/shared_test_task_reporter_tests.rb b/test/ruby_memcheck/shared_test_task_reporter_tests.rb index 94eb914..eb3c891 100644 --- a/test/ruby_memcheck/shared_test_task_reporter_tests.rb +++ b/test/ruby_memcheck/shared_test_task_reporter_tests.rb @@ -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: {})