-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API examples overhaul & roundtrip tests (#3204)
**Commit by commit** This PR overhauls API examples to make them roundtrippable and checks those roundtrips on CI. These roundtrips serve two purposes: A) the obvious one: they make sure that using our different SDKs in similar ways actually yield similar data, but more importantly B) they act as regression tests since it is highly unlikely that two or more tests written in different languages fail in the exact same way at the exact same time. As I've painfully found out during the `MsgSender` migration, _a lot_ of our tests had bitrotten and simply did not work in one way or another anymore (in fact I ended up fixing yet another batch for this PR). This PR should provide the foundations so that this doesn't happen again. A nice side-effect of this is the introduction of the `_RERUN_TEST_FORCE_SAVE` environment variable, which forces all `RecordingStream`s instantiated across all 3 languages to write to an rrd file on disk rather than do whatever they were asked to do. This makes testing things _much_ easier.
- Loading branch information
Showing
73 changed files
with
818 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ screenshot*.png | |
web_demo | ||
|
||
.nox/ | ||
out.rrd | ||
*.rrd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
# Setup builds for examples | ||
file(GLOB sources_list true ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) | ||
|
||
add_custom_target(doc_examples) | ||
|
||
foreach(SOURCE_PATH ${sources_list}) | ||
get_filename_component(SOURCE_NAME ${SOURCE_PATH} NAME_WLE) | ||
|
||
if(${SOURCE_NAME} STREQUAL "CMakeFiles") | ||
CONTINUE() | ||
endif() | ||
|
||
set(EXAMPLE_TARGET ${SOURCE_NAME}) | ||
|
||
add_executable(${EXAMPLE_TARGET} ${SOURCE_PATH}) | ||
|
||
set_default_warning_settings(rerun_example) | ||
target_link_libraries(${EXAMPLE_TARGET} PRIVATE rerun_sdk) | ||
|
||
add_dependencies(doc_examples ${EXAMPLE_TARGET}) | ||
endforeach() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# API Examples | ||
|
||
These examples showcase common usage of each individual Rerun `Archetype`s. | ||
|
||
Most of these examples are automatically used as docstrings for the `Archetype` APIs in their respective SDKs, as well as the [Archetypes](https://www.rerun.io/docs/reference/data_types) section of the high-level documentation. | ||
|
||
## Usage | ||
|
||
You can run each example individually using the following: | ||
|
||
- **Python**: `python <example_name>.py`, e.g. `python point3d_random.py`. | ||
- **Rust**: `cargo r -p code_examples --bin <example_name`, e.g. `cargo r -p code_examples --bin point3d_random`. | ||
- **C++**: | ||
- `./docs/code-examples/build_all.sh` to compile all examples | ||
- start a Rerun Viewer listening on the default port: `rerun` | ||
- `./build/docs/code-examples/<example_name>` to run, e.g. `./build/docs/code-examples/point3d_random` | ||
|
||
## Roundtrips | ||
|
||
All API examples support cross-language roundtrip tests: i.e. we execute the same logging commands from all 3 SDKs, save the results to distinct rrd files, and finally compare these rrd files. | ||
These tests are then automatically run by the CI, which will loudly complain if the resulting rrd files don't match. | ||
|
||
These tests check that A) all of our SDKs yield the exact same data when used the same way and B) act as regression tests, relying on the fact that it is extremely unlikely that all supported languages break in the exact same way at the exact same time. | ||
|
||
### Usage | ||
|
||
To run the roundtrip tests, check out `./docs/code-examples/roundtrips.py --help`. | ||
`./docs/code-examples/roundtrips.py` is a valid invocation that will build all 3 SDKs and run all tests for all of them. | ||
|
||
### Implementing new tests | ||
|
||
Just pick a name for your test, and look at existing examples to get started. The `app_id` must be `rerun_example_<test_name>`. | ||
|
||
The roundtrip process is driven by file names, so make sure all 3 tests use the same name: `<test_name>.rs`, `<test_name>.cpp`, `<test_name>.py`. | ||
|
||
For Rust, also make sure to declare the new binary in `docs/code-examples/Cargo.toml`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
import rerun as rr | ||
import rerun.experimental as rr2 | ||
from rerun.experimental import dt as rrd | ||
|
||
rr.init("rerun_example_annotation_context_connections", spawn=True) | ||
|
||
rr.log_annotation_context( | ||
rr2.log( | ||
"/", | ||
rr.ClassDescription( | ||
info=0, | ||
keypoint_annotations=[ | ||
rr.AnnotationInfo(0, "zero", (255, 0, 0)), | ||
rr.AnnotationInfo(1, "one", (0, 255, 0)), | ||
rr.AnnotationInfo(2, "two", (0, 0, 255)), | ||
rr.AnnotationInfo(3, "three", (255, 255, 0)), | ||
], | ||
keypoint_connections=[(0, 2), (1, 2), (2, 3)], | ||
rr2.AnnotationContext( | ||
[ | ||
rrd.ClassDescription( | ||
info=0, | ||
keypoint_annotations=[ | ||
(0, "zero", (255, 0, 0)), | ||
(1, "one", (0, 255, 0)), | ||
(2, "two", (0, 0, 255)), | ||
(3, "three", (255, 255, 0)), | ||
], | ||
keypoint_connections=[(0, 2), (1, 2), (2, 3)], | ||
) | ||
] | ||
), | ||
) | ||
|
||
rr.log_points( | ||
rr2.log( | ||
"points", | ||
[ | ||
(0, 0, 0), | ||
(50, 0, 20), | ||
(100, 100, 30), | ||
(0, 50, 40), | ||
], | ||
keypoint_ids=[0, 1, 2, 3], | ||
rr2.Points3D( | ||
[ | ||
(0, 0, 0), | ||
(50, 0, 20), | ||
(100, 100, 30), | ||
(0, 50, 40), | ||
], | ||
class_ids=[0], | ||
keypoint_ids=[0, 1, 2, 3], | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.