Skip to content

Commit 00bae72

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

File tree

1 file changed

+119
-3
lines changed

1 file changed

+119
-3
lines changed

README.developers.md

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,131 @@ $ ./run_reg_test.py odin_reg_strong
341341
```
342342
and should be used when making changes to Odin.
343343

344-
## Unit Tests
344+
# 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`, and `test_fasm`. `test_archfpga` is not run.
354+
355+
## Running Individual Testers
356+
357+
To run one of the four testers listed above on its own, navigate to the appropriate folder:
358+
359+
| Test | Directory |
360+
|-----------------|------------------------------------|
361+
| `test_archfpga` | `$VTR_ROOT/build/libs/libarchfpga` |
362+
| `test_vtrutil` | `$VTR_ROOT/build/libs/libvtrutil` |
363+
| `test_fasm` | `$VTR_ROOT/build/utils/fasm` |
364+
| `test_vpr` | `$VTR_ROOT/build/vpr` |
365+
366+
To see tester options, run it with `-h`:
367+
368+
```shell
369+
# Using test_vpr as an example
370+
# From $VTR_ROOT/build/vpr
371+
$ ./test_vpr -h
372+
```
373+
374+
To see the names of each unit test, use `--list-tests`:
375+
376+
```shell
377+
# From $VTR_ROOT/build/vpr
378+
$ ./test_vpr --list-tests
379+
```
380+
381+
The output should look similar to this:
382+
383+
```shell
384+
All available test cases:
385+
test_route_flow
386+
[vpr_noc_bfs_routing]
387+
test_find_block_with_matching_name
388+
[vpr_clustered_netlist]
389+
connection_router
390+
[vpr]
391+
binary_heap
392+
[vpr]
393+
edge_groups_create_sets
394+
[vpr]
395+
read_interchange_models
396+
[vpr]
397+
398+
... # many more test cases
399+
400+
52 test cases
401+
```
402+
403+
To run specific unit tests, pass them as arguments. For example:
404+
405+
```shell
406+
# From $VTR_ROOT/build/vpr
407+
$ ./test_vpr test_route_flow connection_router
408+
```
409+
410+
## Creating Test Cases
411+
412+
You can find the source code for the unit tests in the respective directories. New unit tests must also be created in
413+
these directories.
414+
415+
| Test | Directory |
416+
|-----------------|-----------------------------------|
417+
| `test_archfpga` | `$VTR_ROOT/libs/libarchfpga/test` |
418+
| `test_vtrutil` | `$VTR_ROOT/libs/libvtrutil/test` |
419+
| `test_fasm` | `$VTR_ROOT/utils/fasm/test` |
420+
| `test_vpr` | `$VTR_ROOT/vpr/test` |
421+
422+
VTR uses [Catch2](https://github.com/catchorg/Catch2) for its unit testing framework. For a full tutorial of how to use
423+
the framework, see `$VTR_ROOT/libs/EXTERNAL/libcatch2/docs/Readme.md`.
424+
425+
### Example: Creating and Running a VPR Test Case
426+
427+
Navigate to `$VTR_ROOT/vpr/test`.
428+
429+
```shell
430+
$ cd $VTR_ROOT/vpr/test
431+
```
432+
433+
From here, let's create and open a new file `my_vpr_test.cpp`. Be sure to `#include "catch2/catch_test_macros.hpp"`.
434+
Introduce a test case using the `TEST_CASE` macro, and include a name and a tag. For boolean assertions, use `REQUIRE`.
435+
436+
```shell
437+
#include "catch2/catch_test_macros.hpp"
438+
439+
// To choose a tag, see examples from when you run ./test_vpr --list-tests in the test exectuable directory,
440+
// as shown earlier. A good default tag name is the name of the test: in this case, [vpr].
441+
TEST_CASE("a_vpr_test_name", "[test_tag]") {
442+
int x = 0;
443+
REQUIRE(x == 0);
444+
}
445+
```
446+
447+
To run our test case, we must navigate back to `$VTR_ROOT/build/vpr` (from the table
448+
under [Running Individual Testers](#running-individual-testers)). Since we created a test, we need to rebuild the
449+
tester. Then, we can run our test.
450+
451+
```shell
452+
$ cd $VTR_ROOT/build/vpr
453+
$ make // rebuild tester
454+
$ ./test_vpr a_vpr_test_name // run new unit test
455+
```
456+
457+
Output:
458+
459+
```shell
460+
Filters: "a_vpr_test_name"
461+
Randomness seeded to: 2089861684
462+
===============================================================================
463+
All tests passed (1 assertion in 1 test case)
464+
```
465+
466+
Note: If you modify VTR, you must build it *before* the unit tester (which you must rebuild even if no unit tests have
467+
been changed).
468+
352469
# Evaluating Quality of Result (QoR) Changes
353470
VTR uses highly tuned and optimized algorithms and data structures.
354471
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.
@@ -1352,5 +1469,4 @@ The following outlines the procedure to following when making an official VTR re
13521469
* GitHub will automatically create a release based on the tag
13531470
* Add the new change log entry to the [GitHub release description](https://github.com/verilog-to-routing/vtr-verilog-to-routing/releases)
13541471
* 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-
1472+
* Send a release announcement email to the [vtr-announce](mailto:[email protected]) mailing list (make sure to thank all contributors!)

0 commit comments

Comments
 (0)