Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable memcheck for jni unit tests #1321

Merged
merged 9 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ target/

## VSCode IDE
.vscode

#Generated files
cufile.log
rmm_log.txt
sanitizer_for_pid_*.log
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,40 @@ in errors finding libraries. The script `build/run-in-docker` was created to hel
situation. A test can be run directly using this script or the script can be run without any
arguments to get into an interactive shell inside the container.
```build/run-in-docker target/cmake-build/gtests/ROW_CONVERSION```

#### Testing with Compute Sanitizer
[Compute Sanitizer](https://docs.nvidia.com/compute-sanitizer/ComputeSanitizer/index.html) is a
functional correctness checking suite included in the CUDA toolkit. The RAPIDS Accelerator JNI
supports leveraging the Compute Sanitizer in memcheck mode in the unit tests to help catch any kernels
that may be doing something incorrectly. To run the unit tests with the Compute Sanitizer, append the
`-DUSE_SANITIZER=ON` to the build command. e.g.
```
> ./build/build-in-docker clean package -DUSE_SANITIZER=ON
```

The Compute Sanitizer will output its report into one or multiple log files named as
`sanitizer_for_pid_<pid number>.log` under the current workspace root path.

Please note not all the unit tests can run with Compute Sanitizer. For example, `RmmTest#testEventHandler`,
a problematic test, intentionally tries an illegal allocation because of a too big size as part of the
test, but Compute Sanitizer will still report the errors and fail the whole build process.
`UnsafeMemoryAccessorTest` is for host memory only, so there is no need to run it with
Compute Sanitizer either.

If you think your tests are not suitable for Compute Sanitizer, please add the JUnit5 tag (`@Tag("noSanitizer")`)
to the tests or the test class.
```
@Tag("noSanitizer")
class ExceptionCaseTest { ... }

# or for a single test
class NormalCaseTest {

@Tag("noSanitizer")
public void testOneErrorCase(){ ... }
}
```

### Benchmarks
Benchmarks exist for c++ benchmarks using NVBench and are in the `src/main/cpp/benchmarks` directory.
To build these benchmarks requires the `-DBUILD_BENCHMARKS` build option. Once built, the benchmarks
Expand Down
25 changes: 25 additions & 0 deletions build/sanitizer-java/bin/java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
#
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This special Java executable is specified to the "jvm" configuration of the
# the surefire plugin to intercept forking the processes for tests. Then
# the tests will run with the compute-sanitizer tool.
exec compute-sanitizer --tool memcheck \
--launch-timeout 600 \
--error-exitcode -2 \
--log-file "./sanitizer_for_pid_%p.log" \
java "$@"
3 changes: 2 additions & 1 deletion ci/nightly-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ ${MVN} clean package ${MVN_MIRROR} \
-DCPP_PARALLEL_LEVEL=${PARALLEL_LEVEL} \
-Dlibcudf.build.configure=true \
-DUSE_GDS=${USE_GDS} -Dtest=*,!CuFileTest,!CudaFatalTest,!ColumnViewNonEmptyNullsTest \
-DBUILD_TESTS=ON -Dcuda.version=$CUDA_VER
-DBUILD_TESTS=ON -Dcuda.version=$CUDA_VER \
-DUSE_SANITIZER=ON
5 changes: 3 additions & 2 deletions ci/premerge-build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
# Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -27,4 +27,5 @@ ${MVN} verify ${MVN_MIRROR} \
-DCPP_PARALLEL_LEVEL=${PARALLEL_LEVEL} \
-Dlibcudf.build.configure=true \
-DUSE_GDS=ON -Dtest=*,!CuFileTest,!CudaFatalTest,!ColumnViewNonEmptyNullsTest \
-DBUILD_TESTS=ON
-DBUILD_TESTS=ON \
-DUSE_SANITIZER=ON
49 changes: 46 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
Expand Down Expand Up @@ -199,14 +205,51 @@
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>test-with-sanitizer</id>
<activation>
<property>
<name>USE_SANITIZER</name>
<value>ON</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<groups>!noSanitizer</groups>
<jvm>${project.basedir}/build/sanitizer-java/bin/java</jvm>
</configuration>
</execution>
<execution>
<!-- Some tests (e.g. error cases) are not suitable to run with sanitizer, so run them separately here -->
<id>sanitizer-excluded-cases-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<groups>noSanitizer</groups>
</configuration>
</execution>
<execution>
<id>non-empty-null-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<argLine>-da:ai.rapids.cudf.AssertEmptyNulls</argLine>
<test>ColumnViewNonEmptyNullsTest</test>
<jvm>${project.basedir}/build/sanitizer-java/bin/java</jvm>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -250,7 +293,7 @@
</plugins>
</build>
</profile>
<profile>
<profile>
<id>test-cpp</id>
<activation>
<property>
Expand Down