-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When valgrind is run with `--gen-suppressions`, it will write the error's suppression to XML as something like: <suppression> <sname>insert_a_suppression_name_here</sname> <skind>Memcheck:Leak</skind> <skaux>match-leak-kinds: definite</skaux> <sframe> <fun>malloc</fun> </sframe> <sframe> <fun>objspace_xmalloc0</fun> </sframe> <sframe> <fun>ruby_xmalloc0</fun> </sframe> <sframe> <fun>ruby_xmalloc_body</fun> </sframe> <sframe> <fun>ruby_xmalloc</fun> </sframe> </suppression> If this data is present, then ValgrindError will stream it in the right format for copy-pasting into a suppressions file. See https://wiki.wxwidgets.org/Valgrind_Suppression_File_Howto for more.
- Loading branch information
1 parent
73ef3ba
commit e04b259
Showing
5 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyMemcheck | ||
class Suppression | ||
attr_reader :root | ||
|
||
def initialize(configuration, suppression_node) | ||
@root = suppression_node | ||
end | ||
|
||
def to_s | ||
return "" if root.nil? | ||
|
||
str = StringIO.new | ||
str << "{\n" | ||
str << " #{root.at_xpath("sname").content}\n" | ||
str << " #{root.at_xpath("skind").content}\n" | ||
root.xpath("./sframe/fun | ./sframe/obj").each do |frame| | ||
str << " #{frame.name}:#{frame.content}\n" | ||
end | ||
str << "}\n" | ||
str.string | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "nokogiri" | ||
|
||
module RubyMemcheck | ||
class RubyMemcheckSuppressionTest < Minitest::Test | ||
def setup | ||
@configuration = Configuration.new( | ||
binary_name: "ruby_memcheck_c_test", | ||
output_io: @output_io, | ||
) | ||
end | ||
|
||
def test_given_nil | ||
assert_equal("", RubyMemcheck::Suppression.new(@configuration, nil).to_s) | ||
end | ||
|
||
def test_given_a_suppression_node | ||
suppression = ::Nokogiri::XML(<<~EOF).at_xpath("//suppression") | ||
<foo> | ||
<suppression> | ||
<sname>insert_a_suppression_name_here</sname> | ||
<skind>Memcheck:Leak</skind> | ||
<skaux>match-leak-kinds: definite</skaux> | ||
<sframe> <fun>malloc</fun> </sframe> | ||
<sframe> <fun>objspace_xmalloc0</fun> </sframe> | ||
<sframe> <fun>ruby_xmalloc0</fun> </sframe> | ||
<sframe> <obj>/usr/lib/libX11.so.6.3.0</fun> </sframe> | ||
<sframe> <fun>ruby_xmalloc_body</fun> </sframe> | ||
<sframe> <fun>ruby_xmalloc</fun> </sframe> | ||
</suppression> | ||
</foo> | ||
EOF | ||
expected = <<~EOF | ||
{ | ||
insert_a_suppression_name_here | ||
Memcheck:Leak | ||
fun:malloc | ||
fun:objspace_xmalloc0 | ||
fun:ruby_xmalloc0 | ||
obj:/usr/lib/libX11.so.6.3.0 | ||
fun:ruby_xmalloc_body | ||
fun:ruby_xmalloc | ||
} | ||
EOF | ||
assert_equal( | ||
expected, | ||
RubyMemcheck::Suppression.new(@configuration, suppression).to_s, | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters