-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration test template #2726
Merged
Nir-Az
merged 129 commits into
IntelRealSense:ros2-development
from
PrasRsRos:integration_test_template
Jul 25, 2023
Merged
Changes from all commits
Commits
Show all changes
129 commits
Select commit
Hold shift + click to select a range
6b64c6d
Added testcases:
PrasRsRos bbab11b
Update main.yml
PrasRsRos 3d0b668
Added copyright message
PrasRsRos b8817d7
Merge branch 'integration_test_template' of https://github.com/PrasRs…
PrasRsRos 4e5c222
One more fix...
PrasRsRos 5e8968e
Update main.yml
PrasRsRos d016a75
py file copyrights
PrasRsRos 9662e89
Merge branch 'integration_test_template' of https://github.com/PrasRs…
PrasRsRos 52562ab
Update main.yml
PrasRsRos bc6b036
Update main.yml
PrasRsRos fd95068
Update main.yml
PrasRsRos 0fe1456
Added fix for the pipe
PrasRsRos 3cf4598
pytest_integration_fn changed
PrasRsRos 8824b2c
Added comments to the tests
PrasRsRos e293e7d
fix comments in py test
PrasRsRos d40d758
Added a pytest util file for sharing common functions
62ed2f7
Moved launch description also to utils
PrasRsRos ddc330b
Merge branch 'IntelRealSense:ros2-development' into integration_test_…
PrasRsRos 577b77f
moved to single instance of camera
PrasRsRos 1f57524
moved common class files to utils
PrasRsRos d19d1cd
Added one more test and moved basic test class to utils
PrasRsRos fc7cd19
added check for the data content
PrasRsRos e0439ed
Added two streams, depth and color
PrasRsRos ed7dd72
Modified CMake to automate detaction of test files and added readme
PrasRsRos 4ac938a
updated Readme
PrasRsRos ebdf0ec
updated Readme for formatting
PrasRsRos 0f77e33
updated Readme for formatting 2
PrasRsRos d92d1d2
updated Readme for formatting 3
PrasRsRos 669ed01
updated Readme for formatting 4
PrasRsRos 354b631
fixed issue in template that checks the data from all topics
PrasRsRos 68185f7
fixed the order of frame pop
PrasRsRos ff631b3
Merge branch 'IntelRealSense:ros2-development' into integration_test_…
PrasRsRos d53e951
added prerequisites for running the tests
PrasRsRos 48f1fab
Merge branch 'integration_test_template' of https://github.com/PrasRs…
PrasRsRos aa06059
added prerequisites for running the tests + format
PrasRsRos 87c1eb2
added prerequisites for running the tests + format
PrasRsRos 7067e63
Aligned the message type with the old tests
PrasRsRos c6944de
Updated readme
PrasRsRos 1820041
added parameterized tests
PrasRsRos dcacfe0
parameterized template for test added
PrasRsRos 58714eb
added two paramters as two tests
PrasRsRos aa24cf3
split the steps in utils
PrasRsRos a051422
Merge branch 'IntelRealSense:ros2-development' into integration_test_…
PrasRsRos 63cd6a7
moved test files to directories
PrasRsRos fea7d8a
working for both pytest and colcon test
PrasRsRos 12fa03e
Clear comments
PrasRsRos a8b9baa
added paramter usage in functions
PrasRsRos 4b45356
ported rosbag tests accel_up_1 and vis_avg_2 from rs2_test.py
PrasRsRos 6d01b7b
cleared instability issues due to same node names and context initial…
PrasRsRos 4ec9828
Integration test failed: fixed
PrasRsRos 1c90912
updated rs2_test to align to the param name change
PrasRsRos 6cb80f5
Added point cloud test
PrasRsRos 7fe35d9
rs2_test updated with points_cloud test
PrasRsRos 5fdd7f8
added delayed RS node creation and test for depth and points cloud to…
PrasRsRos 470b4d8
Fixed and added static_tf1 test
PrasRsRos 5f9b5e1
Ported non-existent rosbag file test
PrasRsRos 169c74d
removed debug prints
PrasRsRos eff2fbf
Added and skipped depth aligned to Infra1. Was tested with modified r…
PrasRsRos aecd6d3
Merge branch 'IntelRealSense:ros2-development' into integration_test_…
PrasRsRos 594b4c4
removed pointscloud tests for compatibility with other ROS2 versions
PrasRsRos 101e1e2
Adding camera_info tests
PrasRsRos 3bd0f7a
Adding camera_info tests
PrasRsRos 56cf1a0
Extrinsics test
PrasRsRos 2a139c6
Added metadata test
PrasRsRos b1b0cc6
imu test, but without data check
PrasRsRos 1cffbdf
Merge branch 'IntelRealSense:ros2-development' into integration_test_…
PrasRsRos 15b90f9
added tests, fixed issues in data checks
PrasRsRos 2505972
Fixed CameraInfo comparison
PrasRsRos 4fe106e
Merge branch 'IntelRealSense:ros2-development' into integration_test_…
PrasRsRos ab7aa01
removed camera info check for aligned
PrasRsRos 7826e1f
Merge branch 'IntelRealSense:ros2-development' into integration_test_…
PrasRsRos 5821056
For stability?
PrasRsRos 39be88e
reduce the no of tests in one py file
PrasRsRos 3c17972
inconsistency in the metadata check
PrasRsRos 38df406
Update main.yml
PrasRsRos 4f4d7ea
dividing parallel execution further
PrasRsRos a238460
all topics test is too fast
PrasRsRos 1251511
all topics testing 1
PrasRsRos 9f79f4d
all topics testing 2
PrasRsRos c7ee653
all topics testing 3
PrasRsRos 1449ffc
all topics testing 4
PrasRsRos 5442450
testing for more timeout
PrasRsRos 9cdbc84
Update pytest_rs_utils.py
PrasRsRos bf173fa
all_topics test 5
PrasRsRos 9285dfa
all_topics test 6
PrasRsRos e371850
Add launch_pytest dependency in package.xml
PrasRsRos 4163535
sensor_msgs_py package added for testing
PrasRsRos feabe3c
Update package with quaternion
PrasRsRos 8e661ed
Update numpy-quaternion
PrasRsRos c8b67a8
revert quarternion
PrasRsRos 331c145
pre-release testing 1
PrasRsRos 3ed567c
package testing 2
PrasRsRos 3820d50
package testing 3
PrasRsRos 62952e7
package testing 4
PrasRsRos ad52a21
package testing 6
PrasRsRos e9f90e0
package testing 9
PrasRsRos 12bb55b
package testing 10
PrasRsRos 6197029
package testing 11
PrasRsRos e61569b
Update .travis.yml for jammy
PrasRsRos b15acff
testing pre-release 12
PrasRsRos 6da939a
pre-release testing 13
PrasRsRos 8a6491c
pre-release testing 15
PrasRsRos 1d9b674
pre-release testing 16
PrasRsRos f4486be
pre-release testing 17
PrasRsRos 47cca7b
pre-release testing 18
PrasRsRos 67c97cf
pre-release 19
PrasRsRos 261ac0f
pre-release testing 20
PrasRsRos ae81fe6
pre-release testing 21
PrasRsRos 61abdd3
pre-release testing 22
PrasRsRos 44d3dfe
pre-release testing 23
PrasRsRos 70a9774
prerelease testing 23
PrasRsRos 1db6a31
pre-release testing 24
PrasRsRos 7a3814f
pre-release testing 24
PrasRsRos 22639a3
pre-release testing 26
PrasRsRos 66aac2f
pre-release testing 28
PrasRsRos 65e8dee
pre-release testing 29
PrasRsRos 12762d6
prerelease testing 30
PrasRsRos a85f335
prerelease testing 31
PrasRsRos 2243242
package testing 32
PrasRsRos ec1c664
prerelease testing 33
PrasRsRos b9fa729
package testing 34
PrasRsRos 019c3ea
tqdm dependency added to package
PrasRsRos f3a2f21
Added paths for the dependent scripts
PrasRsRos 6d87de3
moved path dependency to CMakeLists.txt
PrasRsRos 1fb46d6
Merge branch 'IntelRealSense:ros2-development' into integration_test_…
PrasRsRos 22d450f
rosbag moved to a temp location
PrasRsRos 6bc6744
cleanup of prerelease
PrasRsRos 1ec085e
removing the download step
PrasRsRos 2971766
Merge branch 'IntelRealSense:ros2-development' into integration_test_…
PrasRsRos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Testing realsense2_camera | ||
The test infra for realsense2_camera uses both gtest and pytest. gtest is typically used here for testing at the unit level and pytest for integration level testing. Please be aware that the README assumes that the ROS2 version used is Humble or later, as the launch_pytest package used here is not available in prior versions | ||
|
||
## Test using gtest | ||
The default folder for the test cpp files is realsense2_camera/test. A test template gtest_template.cpp is available in the same folder. | ||
### Adding a new test | ||
If the user wants to add a new test, a copy of gtest_template.cpp as the starting point. Please name the file as gtest_`testname`.cpp format so that the CMake detects the file and add as a new test. Please be aware that, multiple tests can be added into one file, the gtest_template.cpp has 2 tests, test1 and test2. | ||
|
||
### Adding a new test folder | ||
It is recommended to use the test folder itself for storing all the cpp tests. However, if the user wants to add a different folder for a set of tests, please ensure that the file name format mentioned above is followed. The folder path is added to realsense_camera/CMakeLists.txt as below for the build to detect the tests within. | ||
|
||
``` | ||
find_package(ament_cmake_gtest REQUIRED) | ||
set(_gtest_folders | ||
test #<-- default folder for the gtest sources | ||
new_folder_for_test_but_why #<-- new folder name is added | ||
) | ||
``` | ||
|
||
## Test using pytest | ||
The default folder for the test py files is realsense2_camera/test. Two test template files test_launch_template.py and test_integration_template.py are available in the same folder for reference. | ||
### Add a new test | ||
To add a new test, the user can create a copy of the test_launch_template.py or test_integration_template.py and start from there. Please name the file in the format test_`testname`.py so that the CMake detects the file and add as a new test. Please be aware that, multiple tests can be added into one file, the test_integration_template.py itself has more than one test.i The marker `@pytest.mark.launch` is used to specify the test entry point. | ||
|
||
The test_launch_template.py uses the rs_launch.py to start the camera node, so this template can be used for testing the rs_launch.py together with the rs node. | ||
|
||
The test_integration_template.py gives a better control for testing, it uses few util functions and base test class from pytest_rs_utils.py located at the same location. However, it doesn't use the rs_launch.py, it creates the node directly instead. | ||
|
||
The test_integration_template.py has two types of tests, one has a function "test_using_function". If the user wants to have a better control over the launch context for any specific test scenarios, this can be used. Both the function based test and class based tests use a default launch configuration from the utils. It's recommended to modify the camera name to a unique one in the parameters itself so that there are not clashes between tests. | ||
|
||
It is expected that the class based test is used as the test format for most of the usecases. The class based test inherits from pytest_rs_utils.RsTestBaseClass and it has three steps, namely: init, run_test and process_data. Unless for the basic tests, the user will have to override the process_data function and check if the data received from the topics are as expected. Also, if the user doesn't want the base class to modify the data, use 'store_raw_data':True in the theme definition. Please see the test_integration_template.py for reference. | ||
|
||
An assert command can be used to indicate if the test failed or passed. Please see the template for more info. | ||
|
||
### Adding a new test folder | ||
It is recommended to use the test folder itself for storing all the pytests. However, if the user wants to add a different folder for a set of tests, please ensure that the file name format mentioned above is followed. The folder path should be added to realsense_camera/CMakeLists.txt as below for the infra to detect the new test folder and the tests within. | ||
|
||
``` | ||
find_package(ament_cmake_pytest REQUIRED) | ||
set(_pytest_folders | ||
test #default test folder | ||
test/templates | ||
test/rosbag | ||
new_folder_for_pytest #<-- new folder #but please be aware that the utils functions are in test/utils folder, | ||
#so if the template is used, change the include path also accordingly | ||
) | ||
``` | ||
|
||
### Grouping of tests | ||
The pytests can be grouped using markers. These markers can be used to run a group of tests. However, "colcon test" command doesn't pass a custom marker using (--pytest-args -m `marker_name`) to the pytest internally. This is because, the ament_cmake that works as a bridge between colcon and pytest doesn't pass the pytest arguments to pytest. So till this is fixed, pytest command has to be used directly for running a group of tests. Please see the next session for the commands to run a group py tests. | ||
|
||
The grouping is specified by adding a marker just before the test declaration. In the test_integration_template.py `rosbag` is specified as a marker specify tests that use rosbag file. This is achieved by adding "@pytest.mark.rosbag" to the begining of the test. So when the pytest parses for test, it detects the marker for the test. If this marker is selected or none of the markers are specified, the test will be added to the list, else will be listed as a deselected test. | ||
|
||
It is recommended to use markers such as ds457, rosbag, ds415 etc to differentiate the tests so that it's easier to run a group of tests in a machine that has the required hardware. | ||
|
||
## Building and running tests | ||
|
||
### Build steps | ||
|
||
The command used for building the tests along with the node: | ||
|
||
colcon build | ||
|
||
The test statements in CMakeLists.txt are protected by BUILD_TESTING macro. So in case, the tests are not being built, then it could be that the macro are disabled by default. | ||
|
||
Note: The below command helps view the steps taken by the build command. | ||
|
||
colcon build --event-handlers console_direct+ | ||
|
||
### Prerequisites for running the tests | ||
|
||
1. The template tests require the rosbag files from librealsense.intel.comi, the following commands download them: | ||
``` | ||
bag_filename="https://librealsense.intel.com/rs-tests/TestData/outdoors_1color.bag"; | ||
wget $bag_filename -P "records/" | ||
bag_filename="https://librealsense.intel.com/rs-tests/D435i_Depth_and_IMU_Stands_still.bag"; | ||
wget $bag_filename -P "records/" | ||
``` | ||
2. The tests use the environment variable ROSBAG_FILE_PATH as the directory that contains the rosbag files | ||
``` | ||
export ROSBAG_FILE_PATH=/path/to/directory/of/rosbag | ||
``` | ||
3. Install launch_pytest package. For humble: | ||
``` | ||
sudo apt install ros-$ROS_DISTRO-launch-pytest | ||
``` | ||
4. As in the case of all the packages, the install script of realsesnse2_camera has to be run. | ||
``` | ||
. install/local_setup.bash | ||
``` | ||
5. If the tests are run on a machine that has the RS board connected or the tests are using rosbag files, then its better to let the ROS search for the nodes in the local machine, this will be faster and less prone to interference and hence unexpected errors. It can be achieved using the following environment variable. | ||
``` | ||
export ROS_DOMAIN_ID=1 | ||
``` | ||
|
||
So, all put together: | ||
|
||
``` | ||
sudo apt install ros-$ROS_DISTRO-launch-pytest | ||
bag_filename="https://librealsense.intel.com/rs-tests/TestData/outdoors_1color.bag"; | ||
wget $bag_filename -P "records/" | ||
bag_filename="https://librealsense.intel.com/rs-tests/D435i_Depth_and_IMU_Stands_still.bag"; | ||
wget $bag_filename -P "records/" | ||
export ROSBAG_FILE_PATH=$PWD/records | ||
. install/local_setup.bash | ||
export ROS_DOMAIN_ID=1 | ||
``` | ||
|
||
### Running the tests using colcon | ||
|
||
All the tests can be run using the below command: | ||
|
||
colcon test --packages-select realsense2_camera | ||
|
||
This command will invoke both gtest and pytest infra and run all the tests specified in the files mentioned above. Since the test results are stored in build/realsense2_camera/test_results folder, it's good to clean this up after running the tests with a new test added/removed. | ||
|
||
The same command with console_direct can be used for more info on failing tests, as below: | ||
|
||
colcon test --packages-select realsense2_camera --event-handlers console_direct+ | ||
|
||
The test results can be viewed using the command: | ||
|
||
colcon test-result --all --test-result-base build/realsense2_camera/test_results/ | ||
|
||
The xml files mentioned by the command can be directly opened also. | ||
|
||
### Running pytests directly | ||
|
||
|
||
User can run all the tests in a pytest file directly using the below command: | ||
|
||
pytest-3 -s realsense2_camera/test/test_integration_template.py | ||
|
||
All the pytests in a test folder can be directly run using the below command: | ||
|
||
pytest-3 -s realsense2_camera/test/ | ||
|
||
### Running a group of pytests | ||
As mentioned above, a set of pytests that are grouped using markers can be run using the pytest command. The below command runs all the pytests in realsense2_camera/test folder that has the marker rosbag: | ||
|
||
pytest-3 -s -m rosbag realsense2_camera/test/ | ||
|
||
|
||
### Running a single pytest | ||
The below command finds the test with the name test_static_tf_1 in realsense2_camera/test folder run: | ||
|
||
pytest-3 -s -k test_static_tf_1 realsense2_camera/test/ | ||
|
||
### Points to be noted while writing pytests | ||
The tests that are in one file are nromally run in parallel. So if there are multiple tests in one file, the system capacity can influence the test execution. It's recomended to have 3-4 tests in file, more than that can affect the test results due to delays. | ||
|
||
|
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,33 @@ | ||
// Copyright 2023 Intel Corporation. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <gtest/gtest.h> | ||
|
||
TEST(realsense2_camera, test1) | ||
{ | ||
std::cout << "Running test1..."; | ||
ASSERT_EQ(4, 2 + 2); | ||
} | ||
TEST(realsense2_camera, test2) | ||
{ | ||
std::cout << "Running test2..."; | ||
ASSERT_EQ(4, 2 + 2); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this file in use anywhere ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SamerKhshiboun, I am not aware of any usage of it in the repo. May be, we can check if it's used in the dailies/weeklies? If not, we can remove this.