FTorch's test suite includes unit tests of components, and integration tests based on a subset of the worked examples.
To enable FTorch's test suite, set CMAKE_BUILD_TESTS=TRUE during the build.
To run the unit tests, you will need to install
pFUnit and provide its
install location to the CMAKE_PREFIX_PATH or as the environment variable PFUNIT_DIR:
# Update `CMAKE_PREFIX_PATH` explicitly with pFUnit install directory
cmake -DCMAKE_PREFIX_PATH="</path/to/pFUnit/build/installed/PFUNIT-VERSION>" \
-DCMAKE_BUILD_TESTS=True -S </path/to/FTorch> -B </path/to/FTorch/build>
or
# Using an environment variable with pFUnit install directory
export PFUNIT_DIR=</path/to/pFUnit/build/installed/PFUNIT-VERSION>
cmake -DCMAKE_BUILD_TESTS=TRUE -S </path/to/FTorch> -B </path/to/FTorch/build>
Note that pFUnit includes the version number in the install directory name,
so for version 4.12 that path will need to be specified as
/path/to/pFUnit/build/installed/PFUNIT-4.12, for example.
Note
If a GPU_DEVICE is specified but only one is available, set MULTI_GPU=OFF to skip
the 'multiple GPU devices' integration test.
Building with tests enabled will automatically install any Python dependencies for the examples, so should be executed from within a virtual environment.1 If this is not the case it will fail with appropriate warnings.
Note that, whilst example 5_Looping is built if CMAKE_BUILD_TESTS=TRUE is
specified, it is not run as part of the integration test suite because it
demonstrates 'good' versus 'bad' practice, as opposed to functionality.
Ensure that the Python virtual environment used when
building is active and then run ctest from the build directory to execute all tests.
Use ctest arguments
for greater control over the testing configuration.
This will produce a report on which of the requested tests passed, and which, if any, failed for your build.
Unit tests may be executed in the following ways:
ctest -R unittest.ctest -R unittest_tensor_constructors_destructors, for example.Integration tests may be executed in the following ways:
ctest -R examplectest -R example2, for example.${BUILD_DIR}/examples
and call ctest.New components should come with unit tests written using the pFUnit framework.
test/unit/ directory and start with
unittest_.CMakeLists.txt in that directory in order
to be built as part of the test suite.New functionalities should come with integration tests in the form of worked examples.
examples/ directory.CMakeLists.txt to build the example code there
should also be a section at the end setting up running of the example
using CTest.example_examples/CMakeLists.txtIf you built FTorch against LibTorch (rather than creating a virtual environment) then you will need to create a virtual environment for the purposes of integration testing as this script will install packages into your Python environment and will check that a virtual environment is in use. ↩