This module is used to run tests for different backends. It is used to test the following backends:
- CUDA
- CPU
Run the project tests using Maven:
mvn test
Override default properties when running tests. For example:
mvn test -Dtest.heap.size=8g -Dsurefire.forks=2
Below are the properties you can override:
-
test.heap.size
: Heap size per test. This is used for dynamic memory allocation. Default: 6g. -
test.offheap.size
: Off-heap memory size per test. This is useful for manual memory management. Default: 6g. -
surefire.forks
: Number of JVM instances (forks) created for tests. Default: 1. -
surefire.threads
: Number of threads to use per fork. Default: 1. -
test.nogc
: Toggles garbage collector during tests. Disabling can speed up tests but might cause memory management issues. Default: true. -
test.asan.options
: Options for AddressSanitizer, a memory error detector. Default: various options. -
tests
: Defines the test tags to run. This allows for selective testing. Default: various tags. -
excludedTests
: Defines the test tags to exclude. This is useful for excluding long or unstable tests. Default: various tags. -
preload
: Sets LD_PRELOAD for loading a shared library before others. Default: path to jemalloc. -
jemalloc.path
: Path to the jemalloc library, a malloc implementation. Default: path to jemalloc.
This testing module comprehensively covers all tests in the code base. Tests are neatly organized and categorized using JUnit 5 tags, allowing for selective running and exclusion based on your specific needs.
Test tags enable selective testing. The default tags for tests to run include:
-
samediff
-
rng
-
java-only
-
dl4j-old-api
-
ndarray-indexing
-
compression
-
loss-functions
-
keras
-
python
-
tensorflow
-
onnx
Tests to exclude by default are:
-
large-resources
-
downloads
-
long-running-test
Please be aware that some tests may take a considerable amount of time to complete or may require downloads. This is particularly true for
large-resources
tests, which may require significant computational resources or time.To run many of the tests, the
dl4j-test-resources
Maven artifact must be installed. You can obtain this artifact from here. After downloading, runmvn install
in the root directory of the extracted project. Note that this JAR file is large but contains all necessary models and resources needed for tests.The test architecture utilizes two JUnit 5 extensions:
-
BackendCheckerExtension: This extension disables larger tests with specific tags when tests are run on a GPU. This helps manage resource use during GPU testing.
-
DeallocationExtension: This extension manages deallocating off-heap memory after each test. It hooks into the deallocator service and intercepts potential deallocation calls, thereby preventing race conditions between tests ending and deallocation.