]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add a method to run our test suite under valgrind
authorNeil Horman <nhorman@openssl.org>
Wed, 7 Jan 2026 20:48:29 +0000 (15:48 -0500)
committerNeil Horman <nhorman@openssl.org>
Thu, 29 Jan 2026 16:37:17 +0000 (11:37 -0500)
As part of our effort to provide a supression file for valgrind that we
can maintain, we should have the ability to run our tests under
valgrind.

Add an environment variable OSSL_USE_VALGRIND to prefix all our app and
test executions with the valgrind tool so that we can run it
automatically

Fixes openssl/project#1801

Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Norbert Pocs <norbertp@openssl.org>
MergeDate: Thu Jan 29 16:37:26 2026
(Merged from https://github.com/openssl/openssl/pull/29573)

test/README.md
util/perl/OpenSSL/Test.pm

index 746a0156ceeaef65637a5b9a794798581a4bb90f..71faaac9d7f5ccab0cc36d720203989bab52db2d 100644 (file)
@@ -184,3 +184,19 @@ To randomise the test ordering:
 To run the tests using the order defined by the random seed `42`:
 
     $ make OPENSSL_TEST_RAND_ORDER=42 test
+
+Running Tests under Valgrind
+----------------------------
+
+Normally, testing for memory leaks is accomplished by building Openssl with the
+enable-asan option, which links the library with the compiler asan library.  However
+Some people prefer to use valgrind to do dynamic instrumentation for memory leak checking.
+OpenSSL also offers a suppression file to suppress reachable memory leaks, that are often
+inappropriately considered to be true leaks.  In order to maintain and test this
+suppression file, OpenSSL tests can be run under valgrind automatically.
+
+To run the test suite under valgrind:
+
+    $ make OSSL_USE_VALGRIND=yes test
+
+Doing so will create valgrind.log file for each test under the test-runs subdirectory.
index a0396499a73b978ad3d84ec59fa3a31b8d9b04af..bc470ace0f3aee79306fa0519add032a0bdf5f5e 100644 (file)
@@ -328,8 +328,13 @@ sub app {
     return sub {
         my @cmdargs = ( @{$cmd} );
         my @prog = __fixup_prg(__apps_file(shift @cmdargs, __exeext()));
-        return cmd([ @prog, @cmdargs ],
-                   exe_shell => $ENV{EXE_SHELL}, %opts) -> (shift);
+        if ($ENV{OSSL_USE_VALGRIND} eq "yes") {
+            return cmd([ "valgrind", "--leak-check=full", "--show-leak-kinds=all", "--gen-suppressions=all", "--log-file=./valgrind.log", @prog, @cmdargs ],
+                       exe_shell => $ENV{EXE_SHELL}, %opts) -> (shift);
+        } else {
+            return cmd([ @prog, @cmdargs ],
+                       exe_shell => $ENV{EXE_SHELL}, %opts) -> (shift);
+        }
     }
 }
 
@@ -350,8 +355,13 @@ sub test {
     return sub {
         my @cmdargs = ( @{$cmd} );
         my @prog = __fixup_prg(__test_file(shift @cmdargs, __exeext()));
-        return cmd([ @prog, @cmdargs ],
+        if ($ENV{OSSL_USE_VALGRIND} eq "yes") {
+           return cmd([ "valgrind", "--leak-check=full", "--show-leak-kinds=all", "--gen-suppressions=all", "--log-file=./valgrind.log", @prog, @cmdargs ],
+                   exe_shell => $ENV{EXE_SHELL}, %opts) -> (shift);
+        } else {
+            return cmd([ @prog, @cmdargs ],
                    exe_shell => $ENV{EXE_SHELL}, %opts) -> (shift);
+        }
     }
 }