Skip to content

Commit

Permalink
test: add integration test for mav_type configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cramke committed Jan 1, 2025
1 parent 4f8523a commit 2d629a1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_executable(integration_tests_runner
action_transition_multicopter_fixedwing.cpp
action_goto.cpp
action_hold.cpp
autopilot_server_configuration.cpp
calibration.cpp
connection.cpp
follow_me.cpp
Expand Down
51 changes: 51 additions & 0 deletions src/integration_tests/autopilot_server_configuration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "log.h"
#include "future"
#include "chrono"
#include "mavsdk.h"
#include "plugins/mavlink_passthrough/mavlink_passthrough.h"
#include <gtest/gtest.h>
#include <thread>

using namespace mavsdk;

TEST(SystemTest, Configuration)
{
Mavsdk mavsdk_groundstation{Mavsdk::Configuration{ComponentType::GroundStation}};

Mavsdk::Configuration config{ComponentType::Autopilot};
MAV_TYPE TEST_VARIABLE = MAV_TYPE_GROUND_ROVER;
config.set_mav_type(TEST_VARIABLE);
Mavsdk mavsdk_autopilot{config};

ASSERT_EQ(
mavsdk_groundstation.add_any_connection("udpin://0.0.0.0:17000"),
ConnectionResult::Success);
ASSERT_EQ(
mavsdk_autopilot.add_any_connection("udpout://127.0.0.1:17000"), ConnectionResult::Success);

auto maybe_system = mavsdk_groundstation.first_autopilot(10.0);
ASSERT_TRUE(maybe_system);
auto system = maybe_system.value();

ASSERT_TRUE(system->has_autopilot());

auto mavlink_passthrough = MavlinkPassthrough{system};

std::promise<void> promise;
auto future = promise.get_future();
mavlink_passthrough.subscribe_message(
MAVLINK_MSG_ID_HEARTBEAT, [&promise, TEST_VARIABLE](const mavlink_message_t& message) {
mavlink_heartbeat_t heartbeat;
mavlink_msg_heartbeat_decode(&message, &heartbeat);
LogInfo() << "Received heartbeat from system " << static_cast<int>(message.sysid)
<< " with type " << static_cast<int>(heartbeat.type);
ASSERT_EQ(heartbeat.type, TEST_VARIABLE);
promise.set_value();
});

// Wait for the message or timeout
if (future.wait_for(std::chrono::seconds(5)) == std::future_status::timeout) {
LogErr() << "Timeout: No heartbeat message received within 10 seconds";
FAIL();
}
}

0 comments on commit 2d629a1

Please sign in to comment.