Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions docs/en/cpp/contributing/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
MAVSDK-C++ is split into a [core](https://github.com/mavlink/MAVSDK/tree/main/src/core) and multiple independent [plugins](https://github.com/mavlink/MAVSDK/tree/main/src/mavsdk/plugins).

Plugins that are located in the *correct location* (a subfolder of **/plugins**) and have the *correct structure* are built at compile time.
The [CMakeLists.txt](https://github.com/mavlink/MAVSDK/blob/main/CMakeLists.txt) takes care of including the plugin folders and integration tests.
The [CMakeLists.txt](https://github.com/mavlink/MAVSDK/blob/main/CMakeLists.txt) takes care of including the plugin folders.

## Plugin Architecture

Plugins should be written so that they are independent of each other (they will still need to be dependent on the core source).
This allows plugins to be removed/replaced as needed at the cost of some duplicated functionality across the plugin modules.

The code for each plugin (and its unit test if one has been defined) is stored in a sub-folder of the **plugins** directory.
Integration tests for all plugins in the library are stored in **integration_tests**.
System tests are stored in **system_tests**.

A simplified view of the folder structure is shown below:

Expand Down Expand Up @@ -306,11 +306,10 @@ Unit tests typically include the header file of the class to be tested and `<gte

### Integration tests {#integration_tests}

We have opted to slowly fade out integration tests and use a few examples instead.
Integration tests have been removed from MAVSDK. They required an external SITL simulator and were slow to run, making them impractical for CI. The functionality they covered is now addressed through:

The rationale is as follows: the integration tests were used to test functionality against SITL (sofware in the loop) simulation. However, we learnt that it was slow to start up the simulatoin and then run a test all the way through. It was also cumbersome to keep track of the potential test matrix including both MAVSDK and PX4 as well as ArduPilot versions. In reality it's only really possible to test a few full integrations like this, so only a small part of the functionality/code coverage.

At this point, the integration tests ended up quite similar to the examples. For contributors it was then often confusing whether they should provide an integration test or an example, or both. Given the integration tests weren't useful as we had to remove them from CI, we decided to move away from them and instead focus on readable examples instead.
- **System tests**: Test MAVLink protocol logic using two MAVSDK instances (client and server) without external dependencies
- **Examples**: Demonstrate realistic usage patterns that users can run against SITL when needed

### Examples {#examples}

Expand Down
2 changes: 1 addition & 1 deletion docs/en/cpp/examples/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# C++ Examples

::: tip
Information about *writing* example code is covered in the [Contributing > Writing Plugins](../contributing/plugins.md) (*plugin developers* should initially create [integration tests](../contributing/plugins.md#integration_tests) rather than examples for new code).
Information about *writing* example code is covered in the [Contributing > Writing Plugins](../contributing/plugins.md).
:::

This section contains examples showing how to use MAVSDK.
Expand Down
4 changes: 2 additions & 2 deletions docs/en/cpp/guide/dev_logging.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Plugin/Test Logging

The MAVSDK provides an API that developers can use for console logging in plugins and integration tests.
The MAVSDK provides an API that developers can use for console logging in plugins and tests.
Basic [message logging](#message_logging) can be enabled by building with a specific `#define`.


Expand All @@ -15,7 +15,7 @@ It is not exported, or intended, for use in SDK apps (and we do not commit to ma

### Usage

The API is defined in [src/core/log.h](https://github.com/mavlink/MAVSDK/blob/main/src/core/log.h) (and made available to integration tests via [/src/integration_tests/integration_test_helper.h](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/integration_test_helper.h)).
The API is defined in [src/core/log.h](https://github.com/mavlink/MAVSDK/blob/main/src/core/log.h).

The API methods are called as shown below for `LogDebug()`, with the insertion operator (`<<`) used to append the message-specific text.

Expand Down
2 changes: 0 additions & 2 deletions docs/en/cpp/guide/follow_me.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,3 @@ Before a target position is first set this API will return `Nan`.
Additional information/examples for the Follow Me API are linked below:

* [Example:Follow Me Mode](../examples/follow_me.md)
* Integration tests:
* [follow_me.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/follow_me.cpp)
12 changes: 5 additions & 7 deletions docs/en/cpp/guide/missions.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,8 @@ The code fragment below shows how to download a mission:

* [Mission Flight Mode](https://docs.px4.io/master/en/flight_modes/mission.html) (PX4 User Guide)
* [Example:Fly Mission](../examples/fly_mission.md)
* Integration tests:
* [mission.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/mission.cpp)
* [mission_cancellation.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/mission_cancellation.cpp)
* [mission_change_speed.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/mission_change_speed.cpp)
* [mission_raw_mission_changed.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/mission_raw_mission_changed.cpp)
* [mission_rtl.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/mission_rtl.cpp)
* [mission_transfer_lossy.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/mission_transfer_lossy.cpp)
* System tests:
* [mission_raw_upload.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/system_tests/mission_raw_upload.cpp)
* [mission_cancellation.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/system_tests/mission_cancellation.cpp)
* [mission_changed.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/system_tests/mission_changed.cpp)
* [mission_transfer_lossy.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/system_tests/mission_transfer_lossy.cpp)
2 changes: 0 additions & 2 deletions docs/en/cpp/guide/offboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,5 @@ Depending on the particular use case, offboard code may need to explicitly monit
Additional information/examples for the Offboard API are linked below:

* [Example: Offboard Velocity](../examples/offboard_velocity.md)
* Integration tests:
* [offboard_velocity.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/offboard_velocity.cpp)


6 changes: 2 additions & 4 deletions docs/en/cpp/guide/taking_off_landing.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ Additional information/examples for the Action API are linked below:

* [Example: Takeoff and Land](../examples/takeoff_and_land.md)
* [Example: VTOL Transitions](../examples/transition_vtol_fixed_wing.md)
* Integration tests:
* [action_hover_async.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/action_hover_async.cpp)
* [action_takeoff_and_kill.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/action_takeoff_and_kill.cpp)
* [action_transition_multicopter_fixedwing.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/action_transition_multicopter_fixedwing.cpp)
* [Example: Goto Location](https://github.com/mavlink/MAVSDK/blob/main/examples/goto_location/goto_location.cpp)
* [Example: Hold](https://github.com/mavlink/MAVSDK/blob/main/examples/hold/hold.cpp)

7 changes: 2 additions & 5 deletions docs/en/cpp/guide/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,5 @@ Usually though it is easier to understand program flow using the approach above.
Additional information/examples for the Telemetry API are linked below:

* [SDK Examples](../examples/index.md)
* Integration tests:
* [telemetry_async.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/telemetry_async.cpp)
* [telemetry_health.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/telemetry_health.cpp)
* [telemetry_modes.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/telemetry_modes.cpp)
* [telemetry_sync.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/telemetry_sync.cpp)
* System tests:
* [telemetry_subscription.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/system_tests/telemetry_subscription.cpp)
68 changes: 12 additions & 56 deletions docs/en/cpp/guide/test.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,48 @@
# Testing

The MAVSDK C++ library has both unit and integration tests, written using the [Google C++ Test Framework](https://google.github.io/googletest/primer.html) (`gtest`).
The MAVSDK C++ library has both unit and system tests, written using the [Google C++ Test Framework](https://google.github.io/googletest/primer.html) (`gtest`).
The unit tests are run every time new code is committed to the library, and must pass before the code can be merged.

This topic shows how to run the existing tests.

::: tip
For information on _writing_ tests see: [Writing Plugins &gt; Test Code](../contributing/plugins.md#testing).
For information on _writing_ tests see: [Writing Plugins > Test Code](../contributing/plugins.md#testing).
:::

## Running Unit Tests

To run all unit tests:

```
./build/default/src/unit_tests_runner
./build/debug/src/unit_tests/unit_tests_runner
```

## Running Integration Tests
## Running System Tests

Tests can be run against the simulator (either manually starting PX4 SITL or letting the tests start it automatically) or against a real vehicle.

::: tip
To run SITL you will need to install the _Gazebo_ simulator.
This is included as part of the standard PX4 installation for [macOS](https://docs.px4.io/master/en/dev_setup/dev_env_mac.html) and [Linux](https://docs.px4.io/master/en/dev_setup/dev_env_linux_ubuntu.html).
It does not run on Windows.
:::

### Autostart PX4 SITL

Make sure that the [PX4 Gazebo simulation](https://docs.px4.io/master/en/simulation/gazebo.html) is built and works:

```
cd path/to/Firmware/
make px4_sitl gazebo
```

Then press **Ctrl+C** to stop the simulation and run the integration tests:

```
cd path/to/MAVSDK/
AUTOSTART_SITL=1 ./build/debug/src/integration_tests/integration_tests_runner
```

To run the tests without the 3D viewer (_gzclient_), use:
System tests use two MAVSDK instances (a ground station and an autopilot) to test functionality without requiring an external simulator. To run all system tests:

```
AUTOSTART_SITL=1 HEADLESS=1 ./build/debug/src/integration_tests/integration_tests_runner
./build/debug/src/system_tests/system_tests_runner
```

### Run PX4 SITL Manually

Build and run the PX4 simulation manually:

```
cd path/to/Firmware/
make px4_sitl gazebo
```

Then run the tests as shown:

```
cd path/to/MAVSDK/
./build/debug/src/integration_tests/integration_tests_runner
```

::: tip
The tests are designed to run in simulation, and may not be safe if run on a real vehicle.
:::

### Gtest Tricks

To list all integration tests:
To list all system tests:

```
./build/default/src/integration_tests/integration_tests_runner --gtest_list_tests
./build/debug/src/system_tests/system_tests_runner --gtest_list_tests
```

To run a single integration test:
To run a single system test:

```
./build/default/src/integration_tests/integration_tests_runner --gtest_filter="SitlTest.TelemetryAsync"
./build/debug/src/system_tests/system_tests_runner --gtest_filter="SystemTest.MissionRawUpload"
```

To run all telemetry tests:
To run all mission tests:

```
./build/default/src/integration_tests/integration_tests_runner --gtest_filter="SitlTest.Telemetry*"
./build/debug/src/system_tests/system_tests_runner --gtest_filter="*Mission*"
```

## Fuzz Testing
Expand Down
2 changes: 0 additions & 2 deletions docs/en/cpp/guide/vtol.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,4 @@ Additional information/examples are linked below:

* [Guide: Taking Off and Landing > Transition to fixed wing mode](../guide/taking_off_landing.md#transition_vtol)
* [Example: VTOL Transitions](../examples/transition_vtol_fixed_wing.md)
* Integration tests:
* [action_transition_multicopter_fixedwing.cpp](https://github.com/mavlink/MAVSDK/blob/main/src/integration_tests/action_transition_multicopter_fixedwing.cpp)

6 changes: 2 additions & 4 deletions docs/en/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,11 @@ mavsdk::Mavsdk mavsdk;

The API to construct `Mavsdk` has changed with v2. Check [API changes](cpp/api_changes.md):

## What is the difference between unit, system, and integration tests?
## What is the difference between unit and system tests?

The unit tests are only concerned with one class or less. It's often used for MAVSDK internal logic or helpers.

System tests are used to test the MAVLink implementation, by running a plugin against it's server plugin counterpart. This way we can test both at the same time while keeping the tests fast because they don't rely on an simulation that would need to be started up.

We have opted to slowly fade out integration tests and use a few examples instead (also see (explanation)[documentation.md#integration_tests]).
System tests are used to test the MAVLink implementation, by running a plugin against its server plugin counterpart. This way we can test both at the same time while keeping the tests fast because they don't rely on a simulation that would need to be started up.

## Why are the plugins called plugins?

Expand Down
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ add_subdirectory(ftp_server)
add_subdirectory(geofence)
add_subdirectory(gimbal)
add_subdirectory(gimbal_device_tester)
add_subdirectory(goto_location)
add_subdirectory(hold)
add_subdirectory(log_callback)
add_subdirectory(logfile_download)
add_subdirectory(log_streaming)
Expand Down
22 changes: 22 additions & 0 deletions examples/goto_location/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.10.2)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(goto_location)

add_executable(goto_location
goto_location.cpp
)

find_package(MAVSDK REQUIRED)

target_link_libraries(goto_location
MAVSDK::mavsdk
)

if(NOT MSVC)
add_compile_options(goto_location PRIVATE -Wall -Wextra)
else()
add_compile_options(goto_location PRIVATE -W2)
endif()
Loading
Loading