Skip to content

Commit eca55b8

Browse files
author
Nathan Shreve
committed
Added a tutorial for running and creating unit tests.
1 parent e5d90af commit eca55b8

File tree

2 files changed

+120
-3
lines changed

2 files changed

+120
-3
lines changed

README.developers.md

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,70 @@ and should be used when making changes to Odin.
344344
## Unit Tests
345345

346346
VTR also has a limited set of unit tests, which can be run with:
347+
347348
```shell
348349
#From the VTR root directory
349350
$ make && make test
350351
```
351352

353+
This will run `test_vtrutil`, `test_vpr`, `test_fasm`, and `test_archfpga`. Each test suite is added in their CMake
354+
files.
355+
356+
### Running Individual Testers
357+
358+
To run one of the four testers listed above on its own, navigate to the appropriate folder:
359+
360+
| Test | Directory |
361+
|-----------------|------------------------------------|
362+
| `test_archfpga` | `$VTR_ROOT/build/libs/libarchfpga` |
363+
| `test_vtrutil` | `$VTR_ROOT/build/libs/libvtrutil` |
364+
| `test_fasm` | `$VTR_ROOT/build/utils/fasm` |
365+
| `test_vpr` | `$VTR_ROOT/build/vpr` |
366+
367+
To see tester options, run it with `-h`:
368+
369+
```shell
370+
# Using test_vpr as an example
371+
# From $VTR_ROOT/build/vpr
372+
$ ./test_vpr -h
373+
```
374+
375+
To see the names of each unit test, use `--list-tests`:
376+
377+
```shell
378+
# From $VTR_ROOT/build/vpr
379+
$ ./test_vpr --list-tests
380+
```
381+
382+
The output should look similar to this:
383+
384+
```shell
385+
All available test cases:
386+
test_route_flow
387+
[vpr_noc_bfs_routing]
388+
test_find_block_with_matching_name
389+
[vpr_clustered_netlist]
390+
connection_router
391+
[vpr]
392+
binary_heap
393+
[vpr]
394+
edge_groups_create_sets
395+
[vpr]
396+
read_interchange_models
397+
[vpr]
398+
399+
... # many more test cases
400+
401+
52 test cases
402+
```
403+
404+
To run specific unit tests, pass them as arguments. For example:
405+
406+
```shell
407+
# From $VTR_ROOT/build/vpr
408+
$ ./test_vpr test_route_flow connection_router
409+
```
410+
352411
# Evaluating Quality of Result (QoR) Changes
353412
VTR uses highly tuned and optimized algorithms and data structures.
354413
Changes which effect these can have significant impacts on the quality of VTR's design implementations (timing, area etc.) and VTR's run-time/memory usage.
@@ -972,6 +1031,63 @@ This describes adding a test to `vtr_reg_strong`, but the process is similar for
9721031
$ git commit
9731032
```
9741033

1034+
## Creating Unit Tests
1035+
1036+
You can find the source code for the unit tests in their respective directories. New unit tests must also be created in
1037+
these directories.
1038+
1039+
| Test | Directory |
1040+
|-----------------|-----------------------------------|
1041+
| `test_archfpga` | `$VTR_ROOT/libs/libarchfpga/test` |
1042+
| `test_vtrutil` | `$VTR_ROOT/libs/libvtrutil/test` |
1043+
| `test_fasm` | `$VTR_ROOT/utils/fasm/test` |
1044+
| `test_vpr` | `$VTR_ROOT/vpr/test` |
1045+
1046+
VTR uses [Catch2](https://github.com/catchorg/Catch2) for its unit testing framework. For a full tutorial of how to use
1047+
the framework, see `$VTR_ROOT/libs/EXTERNAL/libcatch2/docs/Readme.md`.
1048+
1049+
### Example: Creating and Running a VPR Test Case
1050+
1051+
Navigate to `$VTR_ROOT/vpr/test`.
1052+
1053+
```shell
1054+
$ cd $VTR_ROOT/vpr/test
1055+
```
1056+
1057+
From here, let's create and open a new file `test_new_vpr.cpp` (begin the file name with `test_`). Be sure to `#include "catch2/catch_test_macros.hpp"`.
1058+
Introduce a test case using the `TEST_CASE` macro, and include a name and a tag. For boolean assertions, use `REQUIRE`.
1059+
1060+
```shell
1061+
#include "catch2/catch_test_macros.hpp"
1062+
1063+
// To choose a tag, see examples from when you run ./test_vpr --list-tests in the test exectuable directory,
1064+
// as shown earlier. A good default tag name is the name of the test: in this case, [vpr].
1065+
TEST_CASE("a_vpr_test_name", "[test_tag]") {
1066+
int x = 0;
1067+
REQUIRE(x == 0);
1068+
}
1069+
```
1070+
1071+
To run our test case, we must navigate back to `$VTR_ROOT/build/vpr` (from the table
1072+
under [Running Individual Testers](#running-individual-testers)). Since we created a test, we need to rebuild the
1073+
tester. Then, we can run our test.
1074+
1075+
```shell
1076+
$ cd $VTR_ROOT/build/vpr
1077+
$ make // rebuild tester
1078+
$ ./test_vpr a_vpr_test_name // run new unit test
1079+
```
1080+
1081+
Output:
1082+
1083+
```shell
1084+
Filters: "a_vpr_test_name"
1085+
Randomness seeded to: 2089861684
1086+
===============================================================================
1087+
All tests passed (1 assertion in 1 test case)
1088+
```
1089+
1090+
9751091
# Debugging Aids
9761092
VTR has support for several additional tools/features to aid debugging.
9771093
@@ -1352,5 +1468,4 @@ The following outlines the procedure to following when making an official VTR re
13521468
* GitHub will automatically create a release based on the tag
13531469
* Add the new change log entry to the [GitHub release description](https://github.com/verilog-to-routing/vtr-verilog-to-routing/releases)
13541470
* Update the [ReadTheDocs configuration](https://readthedocs.org/projects/vtr/versions/) to build and serve documentation for the relevant tag (e.g. `v8.0.0`)
1355-
* Send a release announcement email to the [vtr-announce](mailto:[email protected]) mailing list (make sure to thank all contributors!)
1356-
1471+
* Send a release announcement email to the [vtr-announce](mailto:[email protected]) mailing list (make sure to thank all contributors!)

libs/libarchfpga/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ target_link_libraries(read_arch libarchfpga)
5757

5858
#Supress IPO link warnings if IPO is enabled
5959
get_target_property(READ_ARCH_USES_IPO read_arch INTERPROCEDURAL_OPTIMIZATION)
60-
if (READ_ARCH_USES_IPO)
60+
if(READ_ARCH_USES_IPO)
6161
set_property(TARGET read_arch APPEND PROPERTY LINK_FLAGS ${IPO_LINK_WARN_SUPRESS_FLAGS})
6262
endif()
6363

@@ -70,3 +70,5 @@ install(FILES ${LIB_HEADERS} DESTINATION include/libarchfpga)
7070
file(GLOB_RECURSE TEST_SOURCES test/*.cpp)
7171
add_executable(test_archfpga ${TEST_SOURCES})
7272
target_link_libraries(test_archfpga Catch2::Catch2WithMain libarchfpga)
73+
74+
add_test(NAME test_archfpga COMMAND test_archfpga --colour-mode ansi)

0 commit comments

Comments
 (0)