Skip to content
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

Add live tests #2834

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0f763ed
Update README.md
PrasRsRos Aug 2, 2023
0426cbe
add template for d455 live camera with dynamic parameter change
PrasRsRos Aug 2, 2023
734ba1f
added conditional test addition based on device connected to the system
PrasRsRos Aug 2, 2023
fd11219
Merge branch 'IntelRealSense:ros2-development' into add_live_tests
PrasRsRos Aug 4, 2023
a9fcee4
Added live camera test for changing profile based on enumerated data
PrasRsRos Aug 4, 2023
8fa253f
added tests for all profiles of d455 415 based on the inputs from rs-…
PrasRsRos Aug 4, 2023
eee09de
Added a new test for failing tests, without assert
PrasRsRos Aug 7, 2023
bd92294
Merge branch 'add_live_tests' of https://github.com/PrasRsRos/realsen…
PrasRsRos Aug 7, 2023
0fccb9d
added failing 415 tests for further testing
PrasRsRos Aug 9, 2023
1f9df74
Merge branch 'IntelRealSense:ros2-development' into add_live_tests
PrasRsRos Aug 9, 2023
9b64dca
Moved configs to utils
PrasRsRos Aug 9, 2023
d89bd17
removed all skips in live camera test
PrasRsRos Aug 10, 2023
6538c6d
added dynamic change of gyro enablement
PrasRsRos Aug 10, 2023
fea39c2
added dynamic change of gyro enablement, code cleaned
PrasRsRos Aug 10, 2023
9b4ea54
added dynamic change of gyro enablement, fixed gyro accel false issue…
PrasRsRos Aug 10, 2023
9c287b2
Added fps tests
PrasRsRos Aug 14, 2023
ea54ea9
added ros2topic to package
PrasRsRos Aug 14, 2023
e547ddb
Increase the timeout, due to failure in prerelease
PrasRsRos Aug 16, 2023
436edc3
reverting back to 250 as the timeout for running test
PrasRsRos Aug 16, 2023
bf515dc
increased delay to compensate for prerelease delay
PrasRsRos Aug 16, 2023
b861562
Added variable delay to take care of machine capability
PrasRsRos Aug 17, 2023
f098ad8
testing ...1
PrasRsRos Aug 17, 2023
cb44783
Merge branch 'IntelRealSense:ros2-development' into add_live_tests
PrasRsRos Aug 17, 2023
8ba72db
testing... 2
PrasRsRos Aug 17, 2023
8260825
testing... 3
PrasRsRos Aug 17, 2023
94db55d
testing... 4
PrasRsRos Aug 17, 2023
b272f2a
testing...5
PrasRsRos Aug 18, 2023
aa391f8
removed the tests added for the failing formats
PrasRsRos Aug 18, 2023
6ece2e5
Upload before rebase
PrasRsRos Aug 30, 2023
c673c4b
- Reduce changes between hkr and development
SamerKhshiboun Jul 31, 2023
99dbc5d
added failing 415 tests for further testing
PrasRsRos Aug 9, 2023
d03a8f2
Update rs_launch.py, rs_multi_camera_launch.py
hyunseok-yang Jun 2, 2023
3f609f7
Moved configs to utils
PrasRsRos Aug 9, 2023
5a62e54
removed all skips in live camera test
PrasRsRos Aug 10, 2023
4d59658
added dynamic change of gyro enablement
PrasRsRos Aug 10, 2023
b36f068
added dynamic change of gyro enablement, code cleaned
PrasRsRos Aug 10, 2023
a17fe02
added dynamic change of gyro enablement, fixed gyro accel false issue…
PrasRsRos Aug 10, 2023
61be45c
Added fps tests
PrasRsRos Aug 14, 2023
ee75cce
added ros2topic to package
PrasRsRos Aug 14, 2023
8ac03a3
Increase the timeout, due to failure in prerelease
PrasRsRos Aug 16, 2023
a614bb6
reverting back to 250 as the timeout for running test
PrasRsRos Aug 16, 2023
9e6deb8
increased delay to compensate for prerelease delay
PrasRsRos Aug 16, 2023
2d18285
Added variable delay to take care of machine capability
PrasRsRos Aug 17, 2023
30b7f40
testing ...1
PrasRsRos Aug 17, 2023
f57c050
support color and depth/ir formats
SamerKhshiboun Aug 8, 2023
4ce8a61
return status when filling cv matrix and ros images
SamerKhshiboun Aug 15, 2023
6fa71f3
testing... 2
PrasRsRos Aug 17, 2023
5a6ace7
testing... 3
PrasRsRos Aug 17, 2023
5e81d75
testing... 4
PrasRsRos Aug 17, 2023
d96e9a1
testing...5
PrasRsRos Aug 18, 2023
8a6b6d0
removed the tests added for the failing formats
PrasRsRos Aug 18, 2023
885bb8e
Upload before rebase
PrasRsRos Aug 30, 2023
a0a8ff1
Merge branch 'add_live_tests' of https://github.com/PrasRsRos/realsen…
PrasRsRos Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions realsense2_camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,16 @@ if(BUILD_TESTING)


find_package(ament_cmake_pytest REQUIRED)

set(_pytest_folders
test
test/templates
test/rosbag
test/post_processing_filters
)



foreach(test_folder ${_pytest_folders})
file(GLOB files "${test_folder}/test_*.py")
foreach(file ${files})
Expand All @@ -314,6 +318,41 @@ if(BUILD_TESTING)
)
endforeach()
endforeach()

unset(_pytest_folders)

set(rs_query_cmd "rs-enumerate-devices -s")
execute_process(COMMAND bash -c ${rs_query_cmd}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE rs_result
OUTPUT_VARIABLE RS_DEVICE_INFO)
message(STATUS "rs_device_info:")
message(STATUS "${RS_DEVICE_INFO}")
if(RS_DEVICE_INFO MATCHES "D455")
message(STATUS "D455 device found")
set(_pytest_live_folders
test/live_camera
)
elseif(RS_DEVICE_INFO MATCHES "D415")
message(STATUS "D415 device found")
set(_pytest_live_folders
test/live_camera
)
endif()

foreach(test_folder ${_pytest_live_folders})
file(GLOB files "${test_folder}/test_*.py")
foreach(file ${files})

get_filename_component(_test_name ${file} NAME_WE)
ament_add_pytest_test(${_test_name} ${file}
APPEND_ENV PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_SOURCE_DIR}/test/utils:${CMAKE_SOURCE_DIR}/launch:${CMAKE_SOURCE_DIR}/scripts
TIMEOUT 500
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endforeach()
endforeach()

endif()

# Ament exports
Expand Down
3 changes: 2 additions & 1 deletion realsense2_camera/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
<test_depend>sensor_msgs_py</test_depend>
<test_depend>python3-requests</test_depend>
<test_depend>tf2_ros_py</test_depend>

<test_depend>ros2topic</test_depend>

<exec_depend>launch_ros</exec_depend>
<build_depend>ros_environment</build_depend>

Expand Down
58 changes: 33 additions & 25 deletions realsense2_camera/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,31 @@ The pytests can be grouped using markers. These markers can be used to run a gro
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.


### Running multipe test instances using parameters and a single test case

If a test is generic enough that it can be used for say, two devices (D415 and D455). then the same testcase be triggered as many times by giving different settings as parameters to the testcase. "@pytest.mark.parametrize" can be used to specify the parameters. See the example below, the test TestLiveCamera_Change_Resolution will be run two times one with test_params_all_profiles_d455 and the other with test_params_all_profiles_d415.

```
@pytest.mark.parametrize("launch_descr_with_parameters", [test_params_all_profiles_d455, test_params_all_profiles_d415]
,indirect=True)
@pytest.mark.launch(fixture=launch_descr_with_parameters)
class TestLiveCamera_Change_Resolution(pytest_rs_utils.RsTestBaseClass):
```
### Grouping the set of parameters using mark option

Just like the marking of testcases using mark option as mentioned before, the parameters can also be marked using pytest.mark option. One example is given below as reference.

```
@pytest.mark.parametrize("launch_descr_with_parameters", [
pytest.param(test_params_all_profiles_d455, marks=pytest.mark.d455),
pytest.param(test_params_all_profiles_d415, marks=pytest.mark.d415),
pytest.param(test_params_all_profiles_d435, marks=pytest.mark.d435),]
,indirect=True)
@pytest.mark.launch(fixture=launch_descr_with_parameters)
class TestLiveCamera_Change_Resolution(pytest_rs_utils.RsTestBaseClass):
```

## Building and running tests

### Build steps
Expand All @@ -68,27 +92,15 @@ 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:
1. 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.
2. 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.
3. 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
```
Expand All @@ -97,11 +109,6 @@ 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
```
Expand Down Expand Up @@ -129,22 +136,23 @@ The xml files mentioned by the command can be directly opened also.

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
PYTHONPATH=$PYTHONPATH:$PWD/realsense2_camera/test/utils:$PWD/realsense2_camera//launch:$PWD/realsense2_camera//scripts pytest-3 -s realsense2_camera/test/test_integration_template.py
Note: The PYTHONPATH additions are required because we are bypassing the python path settings in CMakeLists.txt for ament_cmake_pytest. If the above mentioned command is failing, but colcon test is passing, then it could be due to some difference in the python paths. Please check the paths in the CMakeLists.txt and modify the command accordingly.

All the pytests in a test folder can be directly run using the below command:

pytest-3 -s realsense2_camera/test/
PYTHONPATH=$PYTHONPATH:$PWD/realsense2_camera/test/utils:$PWD/realsense2_camera//launch:$PWD/realsense2_camera//scripts 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/
PYTHONPATH=$PYTHONPATH:$PWD/realsense2_camera/test/utils:$PWD/realsense2_camera//launch:$PWD/realsense2_camera//scripts 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/
PYTHONPATH=$PYTHONPATH:$PWD/realsense2_camera/test/utils:$PWD/realsense2_camera//launch:$PWD/realsense2_camera//scripts 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.
Expand Down
Loading