综合测试

官网英文原文地址:http://dev.px4.io/tutorial-integration-testing.html

这是综合测试,测试会自动执行(Jenkins CI)。

ROS / MAVROS测试

前提:

执行测试

运行完整的MAVROS测试套件:

  1. cd <Firmware_clone>
  2. source integrationtests/setup_gazebo_ros.bash $(pwd)
  3. rostest px4 mavros_posix_tests_iris.launch

或者使用GUI查看:

  1. rostest px4 mavros_posix_tests_iris.launch gui:=true headless:=false

编写新的MAVROS测试 (Python)

1.) 创建新的测试脚本

测试脚本位于integrationtests/python_src/px4_it/mavros/,可以参考这些脚本文件。或者查阅ROS官方文档学习如何使用unittest

空的测试框架:

  1. #!/usr/bin/env python
  2. # [... LICENSE ...]
  3. #
  4. # @author Example Author <author@example.com>
  5. #
  6. PKG = 'px4'
  7. import unittest
  8. import rospy
  9. import rosbag
  10. from sensor_msgs.msg import NavSatFix
  11. class MavrosNewTest(unittest.TestCase):
  12. """
  13. Test description
  14. """
  15. def setUp(self):
  16. rospy.init_node('test_node', anonymous=True)
  17. rospy.wait_for_service('mavros/cmd/arming', 30)
  18. rospy.Subscriber("mavros/global_position/global", NavSatFix, self.global_position_callback)
  19. self.rate = rospy.Rate(10) # 10hz
  20. self.has_global_pos = False
  21. def tearDown(self):
  22. pass
  23. #
  24. # General callback functions used in tests
  25. #
  26. def global_position_callback(self, data):
  27. self.has_global_pos = True
  28. def test_method(self):
  29. """Test method description"""
  30. # FIXME: hack to wait for simulation to be ready
  31. while not self.has_global_pos:
  32. self.rate.sleep()
  33. # TODO: execute test
  34. if __name__ == '__main__':
  35. import rostest
  36. rostest.rosrun(PKG, 'mavros_new_test', MavrosNewTest)

2.) 只运行新的测试

  1. # Start simulation
  2. cd <Firmware_clone>
  3. source integrationtests/setup_gazebo_ros.bash $(pwd)
  4. roslaunch px4 mavros_posix_sitl.launch
  5. # Run test (in a new shell):
  6. cd <Firmware_clone>
  7. source integrationtests/setup_gazebo_ros.bash $(pwd)
  8. rosrun px4 mavros_new_test.py

3.) 添加新的测试结点到launch文件

launch/mavros_posix_tests_irisl.launch中的测试组中添加新的条目:

  1. <group ns="$(arg ns)">
  2. [...]
  3. <test test-name="mavros_new_test" pkg="px4" type="mavros_new_test.py" />
  4. </group>

按照前文所述方法运行完整测试套件。