xref: /aosp_15_r20/external/pytorch/test/cpp/tensorexpr/README.md (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# TensorExpr C++ Tests
2
3## How to add 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
7Here is an example test file you can copy-paste.
8```cpp
9#include <test/cpp/tensorexpr/test_base.h>
10
11// Tests go in torch::jit
12namespace torch {
13namespace jit {
14
15// 1. Test cases are void() functions.
16// 2. They start with the prefix `test`
17void testCaseOne() {
18    // ...
19}
20
21void testCaseTwo() {
22    // ...
23}
24}
25}
26```
27
28Then, register your test in `tests.h`:
29```cpp
30// Add to TH_FORALL_TESTS_CUDA instead for CUDA-requiring tests
31#define TH_FORALL_TESTS(_)             \
32  _(ADFormulas)                        \
33  _(Attributes)                        \
34  ...
35  _(CaseOne)  // note that the `test` prefix is omitted.
36  _(CaseTwo)
37```
38
39We glob all the test files together in `CMakeLists.txt` so that you don't
40have to edit it every time you add a test. Unfortunately, this means that in
41order to get the build to pick up your new test file, you need to re-run
42cmake:
43```
44python setup.py build --cmake
45```
46
47## How do I run the tests?
48The following commands assume you are in PyTorch root.
49
50 ```bash
51 # (re)build the test binary
52 ninja build/bin/test_tensorexpr
53 # run
54 build/bin/test_tensorexpr --gtest_filter='glob_style_filter*'
55 ```
56