mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 02:36:37 +08:00
New Crowdin translations - zh-CN (#25483)
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
This commit is contained in:
@@ -15,14 +15,14 @@ To write a fuzz test:
|
||||
|
||||
1. Start by writing a "normal" [functional test](../test_and_ci/unit_tests.md#functional-test).
|
||||
2. Make sure the file name contains `fuzz` (lower case).
|
||||
For example `my_driver_fuzz_tests.cpp`.
|
||||
For example `my_driver_fuzz_tests.cpp`.
|
||||
3. Add one or more fuzz tests to the file.
|
||||
例如:
|
||||
例如:
|
||||
|
||||
```cpp
|
||||
#include <gtest/gtest.h>
|
||||
#include <fuzztest/fuzztest.h>
|
||||
|
||||
|
||||
void myDriverNeverCrashes(const std::string& s) {
|
||||
MyDriver driver;
|
||||
driver.handleInput(s);
|
||||
|
||||
@@ -9,8 +9,8 @@ Test topics include:
|
||||
- [Unit Tests](../test_and_ci/unit_tests.md)
|
||||
- [Continuous Integration (CI)](../test_and_ci/continous_integration.md)
|
||||
- [Integration Testing](../test_and_ci/integration_testing.md)
|
||||
- [MAVSDK Integration Testing](../test_and_ci/integration_testing_mavsdk.md)
|
||||
- [PX4 ROS2 Interface Library Integration Testing](../test_and_ci/integration_testing_px4_ros2_interface.md)
|
||||
- [ROS 1 Integration Testing](../test_and_ci/integration_testing_ros1_mavros.md) (Deprecated)
|
||||
- [MAVSDK Integration Testing](../test_and_ci/integration_testing_mavsdk.md)
|
||||
- [PX4 ROS2 Interface Library Integration Testing](../test_and_ci/integration_testing_px4_ros2_interface.md)
|
||||
- [ROS 1 Integration Testing](../test_and_ci/integration_testing_ros1_mavros.md) (Deprecated)
|
||||
- [Docker](../test_and_ci/docker.md)
|
||||
- [Maintenance](../test_and_ci/maintenance.md)
|
||||
|
||||
@@ -65,73 +65,73 @@ To write a new test:
|
||||
|
||||
1. Create a new test script by copying the empty test skeleton below:
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python
|
||||
# [... LICENSE ...]
|
||||
|
||||
#
|
||||
# @author Example Author <author@example.com>
|
||||
#
|
||||
PKG = 'px4'
|
||||
|
||||
import unittest
|
||||
import rospy
|
||||
import rosbag
|
||||
|
||||
from sensor_msgs.msg import NavSatFix
|
||||
|
||||
class MavrosNewTest(unittest.TestCase):
|
||||
"""
|
||||
Test description
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
rospy.init_node('test_node', anonymous=True)
|
||||
rospy.wait_for_service('mavros/cmd/arming', 30)
|
||||
|
||||
rospy.Subscriber("mavros/global_position/global", NavSatFix, self.global_position_callback)
|
||||
self.rate = rospy.Rate(10) # 10hz
|
||||
self.has_global_pos = False
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
#
|
||||
# General callback functions used in tests
|
||||
#
|
||||
def global_position_callback(self, data):
|
||||
self.has_global_pos = True
|
||||
|
||||
def test_method(self):
|
||||
"""Test method description"""
|
||||
|
||||
# FIXME: hack to wait for simulation to be ready
|
||||
while not self.has_global_pos:
|
||||
self.rate.sleep()
|
||||
|
||||
# TODO: execute test
|
||||
|
||||
if __name__ == '__main__':
|
||||
import rostest
|
||||
rostest.rosrun(PKG, 'mavros_new_test', MavrosNewTest)
|
||||
```
|
||||
```python
|
||||
#!/usr/bin/env python
|
||||
# [... LICENSE ...]
|
||||
|
||||
#
|
||||
# @author Example Author <author@example.com>
|
||||
#
|
||||
PKG = 'px4'
|
||||
|
||||
import unittest
|
||||
import rospy
|
||||
import rosbag
|
||||
|
||||
from sensor_msgs.msg import NavSatFix
|
||||
|
||||
class MavrosNewTest(unittest.TestCase):
|
||||
"""
|
||||
Test description
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
rospy.init_node('test_node', anonymous=True)
|
||||
rospy.wait_for_service('mavros/cmd/arming', 30)
|
||||
|
||||
rospy.Subscriber("mavros/global_position/global", NavSatFix, self.global_position_callback)
|
||||
self.rate = rospy.Rate(10) # 10hz
|
||||
self.has_global_pos = False
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
#
|
||||
# General callback functions used in tests
|
||||
#
|
||||
def global_position_callback(self, data):
|
||||
self.has_global_pos = True
|
||||
|
||||
def test_method(self):
|
||||
"""Test method description"""
|
||||
|
||||
# FIXME: hack to wait for simulation to be ready
|
||||
while not self.has_global_pos:
|
||||
self.rate.sleep()
|
||||
|
||||
# TODO: execute test
|
||||
|
||||
if __name__ == '__main__':
|
||||
import rostest
|
||||
rostest.rosrun(PKG, 'mavros_new_test', MavrosNewTest)
|
||||
```
|
||||
|
||||
2. Run the new test only
|
||||
- Start the simulator:
|
||||
|
||||
```sh
|
||||
cd <PX4-Autopilot_clone>
|
||||
source Tools/simulation/gazebo/setup_gazebo.bash
|
||||
roslaunch launch/mavros_posix_sitl.launch
|
||||
```
|
||||
```sh
|
||||
cd <PX4-Autopilot_clone>
|
||||
source Tools/simulation/gazebo/setup_gazebo.bash
|
||||
roslaunch launch/mavros_posix_sitl.launch
|
||||
```
|
||||
|
||||
- Run test (in a new shell):
|
||||
|
||||
```sh
|
||||
cd <PX4-Autopilot_clone>
|
||||
source Tools/simulation/gazebo/setup_gazebo.bash
|
||||
rosrun px4 mavros_new_test.py
|
||||
```
|
||||
```sh
|
||||
cd <PX4-Autopilot_clone>
|
||||
source Tools/simulation/gazebo/setup_gazebo.bash
|
||||
rosrun px4 mavros_new_test.py
|
||||
```
|
||||
|
||||
3. Add new test node to a launch file
|
||||
- In `test/` create a new `<test_name>.test` ROS launch file.
|
||||
@@ -145,9 +145,9 @@ To write a new test:
|
||||
|
||||
例如:
|
||||
|
||||
```sh
|
||||
tests_<new_test_target_name>: rostest
|
||||
@"$(SRC_DIR)"/test/rostest_px4_run.sh mavros_posix_tests_<new_test>.test
|
||||
```
|
||||
```sh
|
||||
tests_<new_test_target_name>: rostest
|
||||
@"$(SRC_DIR)"/test/rostest_px4_run.sh mavros_posix_tests_<new_test>.test
|
||||
```
|
||||
|
||||
Run the tests as described above.
|
||||
|
||||
@@ -28,3 +28,5 @@ These are run by the test team as part of release testing, and for more signific
|
||||
- [MC_04 - Failsafe Testing](../test_cards/mc_04_failsafe_testing.md)
|
||||
- [MC_05 - Indoor Flight (Manual Modes)](../test_cards/mc_05_indoor_flight_manual_modes.md)
|
||||
- [MC_06 - Indoor Flight (Optical Flow)](../test_cards/mc_06_optical_flow.md)
|
||||
- [MC_07 - VIO (Visual-Inertial Odometry)](../test_cards/mc_07_vio.md)
|
||||
- [MC_08 - DSHOT ESC](../test_cards/mc_08_dshot.md)
|
||||
|
||||
@@ -126,34 +126,34 @@ It can be run directly in a debugger, however be careful to only run one test pe
|
||||
|
||||
10. Within [tests_main.h](https://github.com/PX4/PX4-Autopilot/blob/main/src/systemcmds/tests/tests_main.h) define the new test:
|
||||
|
||||
```cpp
|
||||
extern int test_[description](int argc, char *argv[]);
|
||||
```
|
||||
```cpp
|
||||
extern int test_[description](int argc, char *argv[]);
|
||||
```
|
||||
|
||||
11. Within [tests_main.c](https://github.com/PX4/PX4-Autopilot/blob/main/src/systemcmds/tests/tests_main.c) add description name, test function and option:
|
||||
|
||||
```cpp
|
||||
...
|
||||
} tests[] = {
|
||||
{...
|
||||
{"[description]", test_[description], OPTION},
|
||||
...
|
||||
}
|
||||
```
|
||||
```cpp
|
||||
...
|
||||
} tests[] = {
|
||||
{...
|
||||
{"[description]", test_[description], OPTION},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
`OPTION` can be `OPT_NOALLTEST`,`OPT_NOJIGTEST` or `0` and is considered if within px4 shell one of the two commands are called:
|
||||
`OPTION` can be `OPT_NOALLTEST`,`OPT_NOJIGTEST` or `0` and is considered if within px4 shell one of the two commands are called:
|
||||
|
||||
```sh
|
||||
pxh> tests all
|
||||
```
|
||||
```sh
|
||||
pxh> tests all
|
||||
```
|
||||
|
||||
或
|
||||
或
|
||||
|
||||
```sh
|
||||
pxh> tests jig
|
||||
```
|
||||
```sh
|
||||
pxh> tests jig
|
||||
```
|
||||
|
||||
If a test has option `OPT_NOALLTEST`, then that test will be excluded when calling `tests all`. The same is true for `OPT_NOJITEST` when command `test jig` is called. Option `0` means that the test is never excluded, which is what most developer want to use.
|
||||
If a test has option `OPT_NOALLTEST`, then that test will be excluded when calling `tests all`. The same is true for `OPT_NOJITEST` when command `test jig` is called. Option `0` means that the test is never excluded, which is what most developer want to use.
|
||||
|
||||
12. Add the test `test_[description].cpp` to the [CMakeLists.txt](https://github.com/PX4/PX4-Autopilot/blob/main/src/systemcmds/tests/CMakeLists.txt).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user