1# JIT C++ Tests 2 3## Adding a new test 4First, create a new test file. Test files should have be placed in this 5directory, with a name that starts with `test_`, like `test_foo.cpp`. 6 7In general a single test suite 8 9Add your test file to the `JIT_TEST_SRCS` list in `test/cpp/jit/CMakeLists.txt`. 10 11A test file may look like: 12```cpp 13#include <gtest/gtest.h> 14 15using namespace ::torch::jit 16 17TEST(FooTest, BarBaz) { 18 // ... 19} 20 21// Append '_CUDA' to the test case name will automatically filter it out if CUDA 22// is not compiled. 23TEST(FooTest, NeedsAGpu_CUDA) { 24 // ... 25} 26 27// Similarly, if only one GPU is detected, tests with `_MultiCUDA` at the end 28// will not be run. 29TEST(FooTest, NeedsMultipleGpus_MultiCUDA) { 30 // ... 31} 32``` 33 34## Building and running the tests 35The following commands assume you are in PyTorch root. 36 37```bash 38# ... Build PyTorch from source, e.g. 39python setup.py develop 40# (re)build just the binary 41ninja -C build bin/test_jit 42# run tests 43build/bin/test_jit --gtest_filter='glob_style_filter*' 44``` 45