Skip to content

Commit 9f7b71c

Browse files
Merge pull request #393 from Infinoid/cli-tests
CLI tests
2 parents d464c7c + ba11012 commit 9f7b71c

File tree

5 files changed

+557
-0
lines changed

5 files changed

+557
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "python_bindings/pybind11"]
22
path = python_bindings/pybind11
33
url = https://github.com/pybind/pybind11
4+
[submodule "test/bats"]
5+
path = test/bats
6+
url = https://github.com/bats-core/bats-core

test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ else()
2020
include(GoogleTest)
2121
gtest_add_tests(TARGET taco-test)
2222
endif()
23+
24+
# This will run all *.bats test files in the source test/ folder.
25+
add_test(NAME taco-cli-test COMMAND ${CMAKE_SOURCE_DIR}/test/bats/bin/bats ${CMAKE_SOURCE_DIR}/test/)

test/README_testing.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# TACO testing
2+
3+
TACO has APIs and UIs in multiple languages and environments.
4+
As such, there are currently 3 test suites for TACO:
5+
6+
1. C++ tests (googletest)
7+
1. Python tests (python unittest)
8+
1. Command line tests (BATS)
9+
10+
## invoking tests
11+
12+
All 3 of these test suites are run when you run `make test`.
13+
14+
### code coverage analysis
15+
16+
These 3 test suites are also run during code coverage analysis. More details
17+
of that can be found in the top level README.
18+
19+
## test suite details
20+
21+
### C++ (googletest)
22+
23+
The TACO C++ API is tested using the `googletest` testing framework. The
24+
tests are implemented in `.cpp` files contained within the `test/` folder.
25+
26+
The tests are linked into an executable called `taco-test`. Individual tests
27+
can be listed using the `--gtest_list_tests` parameter, or run individually using
28+
the `--gtest_filter=<pattern>` parameter. For example:
29+
30+
```sh
31+
$ pwd
32+
.../build
33+
$ bin/taco-test --gtest_filter=scheduling.forallReplace
34+
Note: Google Test filter = scheduling.forallReplace
35+
[==========] Running 1 test from 1 test case.
36+
[----------] Global test environment set-up.
37+
[----------] 1 test from scheduling
38+
[ RUN ] scheduling.forallReplace
39+
[ OK ] scheduling.forallReplace (0 ms)
40+
[----------] 1 test from scheduling (0 ms total)
41+
42+
[----------] Global test environment tear-down
43+
[==========] 1 test from 1 test case ran. (0 ms total)
44+
[ PASSED ] 1 test.
45+
```
46+
47+
A copy of the `googletest` testing framework is bundled with TACO, in the
48+
`test/gtest/` folder.
49+
50+
[Here](https://google.github.io/googletest/primer.html#simple-tests) is a starting guide to
51+
writing test cases in googletest.
52+
53+
### Python (unittest)
54+
55+
The TACO Python API is tested using the python `unittest` module. The tests
56+
are implemented as subclasses of `unittest.TestCase` declared within the
57+
`python_bindings/unit_tests.py` script. A modified version of this script
58+
is written into the `build/python_bindings` folder during TACO compilation,
59+
and can be invoked directly from within that folder. This modified version
60+
hard-codes the build folder path, to ensure that the tests run against the
61+
TACO library in the build folder, and not a system-installed TACO.
62+
63+
The tests can be invoked by going into the `build/python_bindings` folder
64+
and running the `unit_tests.py` script. Individual test cases can be run
65+
using the `-k` parameter. For example:
66+
67+
```sh
68+
$ pwd
69+
.../build/python_bindings
70+
$ python3 unit_tests.py -k TestTensorCreation.test_tensor_from_numpy
71+
test_tensor_from_numpy (__main__.TestTensorCreation) ... ok
72+
73+
----------------------------------------------------------------------
74+
Ran 1 test in 1.023s
75+
76+
OK
77+
```
78+
79+
[Here](https://docs.python.org/3/library/unittest.html#basic-example) is a
80+
starting guide to writing Python test cases in unittest.
81+
82+
### Command line (BATS)
83+
84+
The TACO command line tool, `bin/taco`, is tested using the bash `bats-core`
85+
testing framework. The tests are implemented as `.bats` files contained
86+
within the `test/` folder.
87+
88+
The test suite needs the `CMAKE_BUILD_DIR` environment variable to be set, so
89+
it knows where to look for the `bin/taco` executable. It should be set to the
90+
folder you ran `cmake` in to configure and build TACO. This variable is set
91+
automatically when you run `make test`, but if you want to run tests by hand,
92+
you will need to set it yourself.
93+
94+
Individual test cases can be run by running `bats` directly with the `-f`
95+
parameter. For example:
96+
97+
```sh
98+
$ pwd
99+
.../src
100+
$ CMAKE_BUILD_DIR=../build test/bats/bin/bats -f layout test/
101+
test -f (tensor layout directives)
102+
103+
1 test, 0 failures
104+
105+
```
106+
107+
A copy of the `bats-core` testing framework is bundled with TACO as a
108+
submodule, in the `test/bats/` folder.
109+
110+
[Here](https://bats-core.readthedocs.io/en/latest/writing-tests.html) is a
111+
starting guide to writing test cases in bats.

test/bats

Submodule bats added at dcaec03

0 commit comments

Comments
 (0)