Home | History | Annotate | Line # | Download | only in dist
      1  1.1  christos Notes on Valgrind
      2  1.1  christos =================
      3  1.1  christos 
      4  1.1  christos [Valgrind](https://valgrind.org/) is a test harness that includes many tools such as memcheck,
      5  1.1  christos which is commonly used to check for memory leaks, etc. The default tool
      6  1.1  christos run by Valgrind is memcheck. There are [other tools available](https://valgrind.org/info/tools.html), but this
      7  1.1  christos will focus on memcheck.
      8  1.1  christos 
      9  1.1  christos Valgrind runs programs in a virtual machine, this means OpenSSL unit
     10  1.1  christos tests run under Valgrind will take longer than normal.
     11  1.1  christos 
     12  1.1  christos Requirements
     13  1.1  christos ------------
     14  1.1  christos 
     15  1.1  christos 1. Platform supported by Valgrind
     16  1.1  christos    - See [Valgrind Supported Platforms](http://valgrind.org/info/platforms.html)
     17  1.1  christos 2. Valgrind installed on the platform
     18  1.1  christos    - See [Valgrind Current Releases](http://valgrind.org/downloads/current.html)
     19  1.1  christos 3. OpenSSL compiled
     20  1.1  christos    - See [INSTALL.md](INSTALL.md)
     21  1.1  christos 
     22  1.1  christos Running Tests
     23  1.1  christos -------------
     24  1.1  christos 
     25  1.1  christos Test behavior can be modified by adjusting environment variables.
     26  1.1  christos 
     27  1.1  christos `EXE_SHELL`
     28  1.1  christos 
     29  1.1  christos This variable is used to specify the shell used to execute OpenSSL test
     30  1.1  christos programs. The default wrapper (`util/wrap.pl`) initializes the environment
     31  1.1  christos to allow programs to find shared libraries. The variable can be modified
     32  1.1  christos to specify a different executable environment.
     33  1.1  christos 
     34  1.1  christos     EXE_SHELL=\
     35  1.1  christos     "$(/bin/pwd)/util/wrap.pl valgrind --error-exitcode=1 --leak-check=full -q"
     36  1.1  christos 
     37  1.1  christos This will start up Valgrind with the default checker (`memcheck`).
     38  1.1  christos The `--error-exitcode=1` option specifies that Valgrind should exit with an
     39  1.1  christos error code of 1 when memory leaks occur.
     40  1.1  christos The `--leak-check=full` option specifies extensive memory checking.
     41  1.1  christos The `-q` option prints only error messages.
     42  1.1  christos Additional Valgrind options may be added to the `EXE_SHELL` variable.
     43  1.1  christos 
     44  1.1  christos `OPENSSL_ia32cap`
     45  1.1  christos 
     46  1.1  christos This variable controls the processor-specific code on Intel processors.
     47  1.1  christos By default, OpenSSL will attempt to figure out the capabilities of a
     48  1.1  christos processor, and use it to its fullest capability. This variable can be
     49  1.1  christos used to control what capabilities OpenSSL uses.
     50  1.1  christos 
     51  1.1  christos As of valgrind-3.15.0 on Linux/x86_64, instructions up to AVX2 are
     52  1.1  christos supported. Setting the following disables instructions beyond AVX2:
     53  1.1  christos 
     54  1.1  christos `OPENSSL_ia32cap=":0"`
     55  1.1  christos 
     56  1.1  christos This variable may need to be set to something different based on the
     57  1.1  christos processor and Valgrind version you are running tests on. More information
     58  1.1  christos may be found in [doc/man3/OPENSSL_ia32cap.pod](doc/man3/OPENSSL_ia32cap.pod).
     59  1.1  christos 
     60  1.1  christos Additional variables (such as `VERBOSE` and `TESTS`) are described in the
     61  1.1  christos file [test/README.md](test/README.md).
     62  1.1  christos 
     63  1.1  christos Example command line:
     64  1.1  christos 
     65  1.1  christos     $ make test EXE_SHELL="$(/bin/pwd)/util/wrap.pl valgrind --error-exitcode=1 \
     66  1.1  christos         --leak-check=full -q" OPENSSL_ia32cap=":0"
     67  1.1  christos 
     68  1.1  christos If an error occurs, you can then run the specific test via the `TESTS` variable
     69  1.1  christos with the `VERBOSE` or `VF` or `VFP` options to gather additional information.
     70  1.1  christos 
     71  1.1  christos     $ make test VERBOSE=1 TESTS=test_test EXE_SHELL="$(/bin/pwd)/util/wrap.pl \
     72  1.1  christos        valgrind --error-exitcode=1 --leak-check=full -q" OPENSSL_ia32cap=":0"
     73