From 827977a2aab103a5b18ae785c5dc1908ef218c55 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 21 Oct 2021 10:37:02 -0400 Subject: [PATCH] test: try using ruby_memcheck to look for leaks --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ Gemfile | 2 ++ rakelib/test.rake | 15 +++++++++++++++ test/helper.rb | 4 ++++ 4 files changed, 44 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de786fed17..4416d8b74a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -296,3 +296,26 @@ jobs: bundle install --local || bundle install bundle exec rake compile -- --${{matrix.sys}}-system-libraries bundle exec rake test + + memcheck: + continue-on-error: true # this is experimental! + strategy: + fail-fast: false + matrix: + sys: ["enable", "disable"] + ruby: ["3.0"] + runs-on: ubuntu-latest + container: + image: ghcr.io/sparklemotion/nokogiri-test:mri-${{matrix.ruby}} + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - uses: actions/cache@v2 + if: matrix.sys == 'disable' + with: + path: ports + key: ports-ubuntu-${{hashFiles('dependencies.yml', 'patches/**/*.patch')}} + - run: bundle install --local || bundle install + - run: bundle exec rake compile -- --${{matrix.sys}}-system-libraries + - run: bundle exec rake test:memcheck diff --git a/Gemfile b/Gemfile index b4e2a20bb6..e0988fa963 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ source "https://rubygems.org" gemspec + +gem "ruby_memcheck", git: "https://github.com/peterzhu2118/ruby_memcheck" diff --git a/rakelib/test.rake b/rakelib/test.rake index 4b87d2765e..1bd5f33be2 100644 --- a/rakelib/test.rake +++ b/rakelib/test.rake @@ -1,5 +1,14 @@ require "rake/testtask" +begin + require "ruby_memcheck" + valgrind_options = RubyMemcheck::Configuration::DEFAULT_VALGRIND_OPTIONS.dup + valgrind_options << "--gen-suppressions=all" + RubyMemcheck.config(binary_name: "nokogiri", valgrind_options: valgrind_options) +rescue LoadError + warn "could not load ruby_memcheck" +end + # # much of this was ripped out of hoe-debugging # @@ -95,4 +104,10 @@ namespace "test" do LldbTestTask.new("lldb") do |t| nokogiri_test_task_configuration(t) end + + if defined?(RubyMemcheck) + RubyMemcheck::TestTask.new("memcheck") do |t| + nokogiri_test_task_configuration(t) + end + end end diff --git a/test/helper.rb b/test/helper.rb index ed96d3baaf..f338ae0384 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -11,6 +11,10 @@ # - "stress" - run tests with GC.stress set to true # - NOKOGIRI_GC: read more in test/test_memory_leak.rb # + +# make sure we do one final major before the process exits (for valgrind) +at_exit { GC.start(full_mark: true) } unless ::RUBY_PLATFORM == "java" + require 'simplecov' SimpleCov.start do add_filter "/test/"