From 08635312e5fbec000d46746c98fabcacbc8e18e5 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 30 Oct 2024 11:21:59 +0100 Subject: [PATCH] Setup ruby_memcheck Hoping it might find the leak reported in https://github.com/ruby/json/issues/460 --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ Gemfile | 1 + Rakefile | 10 ++++++++++ test/json/test_helper.rb | 3 +++ 4 files changed, 37 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0ff8301..c9422e0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,3 +56,26 @@ jobs: - run: gem install pkg/*.gem if: ${{ matrix.ruby != '3.2' }} + + valgrind: + name: Ruby memcheck + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby-pkgs@v1 + with: + ruby-version: "3.3" + apt-get: ragel valgrind + + - run: | + bundle config --without benchmark + bundle install + + - run: rake compile + + - run: rake valgrind diff --git a/Gemfile b/Gemfile index b5e84b43..ef2cf7fa 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ else end group :development do + gem "ruby_memcheck" if RUBY_PLATFORM =~ /linux/i gem "ostruct" gem "rake" gem "rake-compiler" diff --git a/Rakefile b/Rakefile index e22a3ddd..7a013eb0 100644 --- a/Rakefile +++ b/Rakefile @@ -250,6 +250,16 @@ else t.options = '-v' end + begin + require "ruby_memcheck" + RubyMemcheck::TestTask.new(valgrind: [ :set_env_ext, :check_env, :compile, :do_test_ext ]) do |t| + t.test_files = FileList['test/json/*_test.rb'] + t.verbose = true + t.options = '-v' + end + rescue LoadError + end + desc "Update the tags file" task :tags do system 'ctags', *Dir['**/*.{rb,c,h,java}'] diff --git a/test/json/test_helper.rb b/test/json/test_helper.rb index e8bba16f..7bff9b33 100644 --- a/test/json/test_helper.rb +++ b/test/json/test_helper.rb @@ -1,12 +1,15 @@ case ENV['JSON'] when 'pure' $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__)) + $stderr.puts("Testing JSON::Pure") require 'json/pure' when 'ext' + $stderr.puts("Testing JSON::Ext") $LOAD_PATH.unshift(File.expand_path('../../../ext', __FILE__), File.expand_path('../../../lib', __FILE__)) require 'json/ext' else $LOAD_PATH.unshift(File.expand_path('../../../ext', __FILE__), File.expand_path('../../../lib', __FILE__)) + $stderr.puts("Testing JSON") require 'json' end