From 6922d4db5b56d4d8b6039d8a670aa734091a7904 Mon Sep 17 00:00:00 2001 From: PrasRsRos Date: Thu, 31 Aug 2023 17:47:07 +0530 Subject: [PATCH] Updated readme and imu tests --- realsense2_camera/test/README.md | 20 +++++++-- .../test/live_camera/test_camera_imu_tests.py | 41 ++++++++----------- .../test/utils/pytest_rs_utils.py | 8 +++- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/realsense2_camera/test/README.md b/realsense2_camera/test/README.md index 0be7600c24..a026a36b2e 100644 --- a/realsense2_camera/test/README.md +++ b/realsense2_camera/test/README.md @@ -146,7 +146,21 @@ The below command finds the test with the name test_static_tf_1 in realsense2_ca 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. - +## Points to be noted while writing pytests +The tests that are in one file are normally 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. +### Passing/changing parameters +The parameters passed while creating the node can be initialized individually for each test, please see the test_parameterized_template example for reference. The default values are taken from rs_launch.py and the passed parameters are used for overriding the default values. The parameters that can be dynamically modified can be changed using the param interface provided. However, the function create_param_ifs has to be called to create this interface. Please see the test_d455_basic_tests.py for reference. There are specific functions to change the string, integer and bool parameters, the utils can be extended if any more types are needed. +### Difference in setting the bool parameters +There is a difference between setting the default values of bool parameters and setting them dynamically. +The bool test params are assinged withn quotes as below. + test_params_all_profiles_d455 = { + 'camera_name': 'D455', + 'device_type': 'D455', + 'enable_accel':"True", + 'enable_gyro':"True", + 'unite_imu_method':1, + } + +However the function that implements the setting of bool parameter dynamically takes the python bool datatype. For example: + self.set_bool_param('enable_accel', False) diff --git a/realsense2_camera/test/live_camera/test_camera_imu_tests.py b/realsense2_camera/test/live_camera/test_camera_imu_tests.py index fa173e0a8e..c712cd1ba7 100644 --- a/realsense2_camera/test/live_camera/test_camera_imu_tests.py +++ b/realsense2_camera/test/live_camera/test_camera_imu_tests.py @@ -43,8 +43,8 @@ test_params_all_profiles_d455 = { 'camera_name': 'D455', 'device_type': 'D455', - 'enable_accel':True, - 'enable_gyro':True, + 'enable_accel':"True", + 'enable_gyro':"True", 'unite_imu_method':1, } @@ -64,62 +64,53 @@ def test_LiveCamera_check_motion_sensor(self,launch_descr_with_parameters): if params['unite_imu_method'] == '0': themes[IMU_TOPIC]['expected_data_chunks'] = 0 try: - ''' - initialize, run and check the data - ''' - msg = "Test with the default params " + #initialize self.init_test("RsTest"+params['camera_name']) self.create_param_ifs(get_node_heirarchy(params)) + + + #run with default params and check the data + msg = "Test with the default params " print(msg) - ret = self.run_test(themes) + ret = self.run_test(themes, timeout=50) assert ret[0], msg + str(ret[1]) assert self.process_data(themes), msg + " failed" - msg = "Test with the accel false " self.set_bool_param('enable_accel', False) self.set_bool_param('enable_gyro', True) - ''' - This step fails if the next line is commented - ''' - self.set_integer_param('unite_imu_method', 0) #this shouldn't matter because the unite_imu_method cannot be changed themes[ACCEL_TOPIC]['expected_data_chunks'] = 0 + #uncomment once RSDEV-550 is closed + #themes[IMU_TOPIC]['expected_data_chunks'] = 0 print(msg) ret = self.run_test(themes) assert ret[0], msg + str(ret[1]) assert self.process_data(themes), msg + " failed" - ''' - Test fails - ''' msg = "Test with the gyro false " self.set_bool_param('enable_accel', True) self.set_bool_param('enable_gyro', False) - self.set_integer_param('unite_imu_method', 0) #this shouldn't matter because the unite_imu_method cannot be changed - themes[IMU_TOPIC]['expected_data_chunks'] = 1 + themes[IMU_TOPIC]['expected_data_chunks'] = 0 themes[ACCEL_TOPIC]['expected_data_chunks'] = 1 themes[GYRO_TOPIC]['expected_data_chunks'] = 0 print(msg) + self.spin_for_time(wait_time=1.0) ret = self.run_test(themes) assert ret[0], msg + str(ret[1]) assert self.process_data(themes), msg + " failed" - ''' - Test fails, both gyro and accel data is available, not imu - ''' msg = "Test with both gyro and accel false " self.set_bool_param('enable_accel', False) self.set_bool_param('enable_gyro', False) - self.set_integer_param('unite_imu_method', 1) #this shouldn't matter because the unite_imu_method cannot be changed - + self.set_integer_param('unite_imu_method', 1) + self.spin_for_time(wait_time=1.0) themes[ACCEL_TOPIC]['expected_data_chunks'] = 0 themes[GYRO_TOPIC]['expected_data_chunks'] = 0 - themes[IMU_TOPIC]['expected_data_chunks'] = 1 #Seems that imu data is available even if gyro and accel is disabled + themes[IMU_TOPIC]['expected_data_chunks'] = 0 print(msg) - ret = self.run_test(themes, initial_wait_time=1.0) #wait_time added as test doesn't have to wait for any data + ret = self.run_test(themes, initial_wait_time=1.0) assert ret[0], msg + " failed" assert self.process_data(themes), msg +" failed" - finally: #this step is important because the test will fail next time pytest_rs_utils.kill_realsense2_camera_node() diff --git a/realsense2_camera/test/utils/pytest_rs_utils.py b/realsense2_camera/test/utils/pytest_rs_utils.py index d78eeb9ef8..e693eefc64 100644 --- a/realsense2_camera/test/utils/pytest_rs_utils.py +++ b/realsense2_camera/test/utils/pytest_rs_utils.py @@ -819,9 +819,12 @@ def spin_for_data(self,themes, timeout=5.0): ''' print('Waiting for topic... ' ) flag = False + data_not_expected = [i for i in themes if (i["expected_data_chunks"]) == 0] while (time.time() - start) < timeout: rclpy.spin_once(self.node, timeout_sec=1) debug_print('Spun once... ' ) + if data_not_expected == True: + continue all_found = True for theme in themes: if theme['expected_data_chunks'] > int(self.node.get_num_chunks(theme['topic'])): @@ -831,8 +834,9 @@ def spin_for_data(self,themes, timeout=5.0): flag =True break else: - print("Timed out waiting for", timeout, "seconds" ) - return False, "run_test timedout" + if data_not_expected == False: + print("Timed out waiting for", timeout, "seconds" ) + return False, "run_test timedout" return flag,"" def spin_for_time(self,wait_time):