# Invoke a process (valgrind) before a test is run

**URL:** <https://discuss.gradle.org/t/invoke-a-process-valgrind-before-a-test-is-run/45949>\
**Category:** Build Tool\
**Created:** [July 2, 2023, 10:59pm UTC](https://discuss.gradle.org/t/invoke-a-process-valgrind-before-a-test-is-run/45949 "2023-07-02T22:59:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmoliere](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jmoliere](https://discuss.gradle.org/u/jmoliere)\
**Post date:** [July 2, 2023, 10:59pm UTC](https://discuss.gradle.org/t/invoke-a-process-valgrind-before-a-test-is-run/45949/1 "2023-07-02T22:59:29Z")

</div>

Hello,  
I’d like to run Valgrind in some of my tests to ensure there are no memory leaks with native code within the Java code. I have 2 acceptable means of testing which are:

1. Run the tests in the same process as …  
./gradlew test  
…to ultimately have the command  
valgrind {valgrind flags to detect memory leaks (e.g. --leak-check=yes ) } ./gradlew test  
…the problem with the line above is that the actual test is run in a separate process.

2. Pass the executable command in the build.gradle file…  
build.gradle

* * *

## test { executable “valgrind {flags to detect memory leaks (e.g. --leak-check=yes ) } /opt/java/bin/java” }

The code above will substitute ‘java’ with the valgrind command above and eventually execute java.

I haven’t figured out how to do #1 above and #2 fails with ‘executable’ in the test.

Can someone please help me?
