diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-08-06 15:03:39 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-08-14 16:17:17 +0900 |
commit | 3a2840e80d275895523a526ce56e4f6e7b8f9cc4 (patch) | |
tree | 72064ea57e1f470ea0400effa8950a9dcc805997 /test | |
parent | f0754f0b2f335c84a276508cabe9eee8c46e04f8 (diff) | |
download | ruby-openssl-3a2840e80d275895523a526ce56e4f6e7b8f9cc4.tar.gz |
test: add MDEBUG environment variable
When the OpenSSL is compiled with crypto-mdebug, and the environment
variable MDEBUG is set, print found memory leaks on exit.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_engine.rb | 2 | ||||
-rw-r--r-- | test/utils.rb | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/test/test_engine.rb b/test/test_engine.rb index c236bd69..529a8010 100644 --- a/test/test_engine.rb +++ b/test/test_engine.rb @@ -83,7 +83,7 @@ class OpenSSL::TestEngine < OpenSSL::TestCase # this is required because OpenSSL::Engine methods change global state def with_openssl(code) - assert_separately(["-ropenssl"], <<~"end;") + assert_separately([{ "MDEBUG" => nil }, "-ropenssl"], <<~"end;") require #{__FILE__.dump} include OpenSSL::TestEngine::Utils #{code} diff --git a/test/utils.rb b/test/utils.rb index 5cd772e7..fc303d1d 100644 --- a/test/utils.rb +++ b/test/utils.rb @@ -8,6 +8,29 @@ begin OpenSSL.fips_mode=false rescue LoadError end + +# Compile OpenSSL with crypto-mdebug and run this test suite with MDEBUG +# environment variable to enable memory leak check. +if ENV["MDEBUG"] + begin + require "mdebug" + rescue LoadError + end + + if OpenSSL.respond_to?(:print_mem_leaks) + END { + # FIXME: maybe extract fixtures to file and load dynamically? + OpenSSL::TestUtils.constants.each do |v| + OpenSSL::TestUtils.send(:remove_const, v) + end + GC.start + OpenSSL.print_mem_leaks + } + else + warn "OpenSSL is not built with crypto-mdebug" + end +end + require "test/unit" require "digest/md5" require 'tempfile' |