Skip to content

Commit

Permalink
Handle multiple components: Add integration test
Browse files Browse the repository at this point in the history
This adds integration test to verify whether DroneCore can
recognize different type of components. Below is the procedure
to test it.
1. Connect a camera to Linux system
2. Launch Camera streaming Daemon
3. Launch PX4 SITL
4. Run SitlTest.DiscoverOneAutopilotAndCamera test
The test discovers two componets (autopilot and camera).
  • Loading branch information
Shakthi Prashanth M committed Mar 7, 2018
1 parent 53203f8 commit e3a96bd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ void Device::process_heartbeat(const mavlink_message_t &message)

/* If we don't know the UUID yet, we try to find out. */
// Lets request autopilot version only from an Autopilot.
if (heartbeat.autopilot != MAV_AUTOPILOT_INVALID
&& _target_uuid == 0
&& !_target_uuid_initialized) {
if (heartbeat.autopilot == MAV_AUTOPILOT_INVALID &&
_target_uuid == 0 && !_target_uuid_initialized) {
// For Non-Autopilot components, lets fill UUID by ourself.
_target_uuid_initialized = true;
_target_uuid = message.sysid;
} else if (_target_uuid == 0 && !_target_uuid_initialized) {
request_autopilot_version();
}

Expand Down
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
# This includes all GTests that run integration tests
add_executable(integration_tests_runner
../core/unittests_main.cpp
multi_component_discovery.cpp
simple_connect.cpp
async_connect.cpp
telemetry_simple.cpp
Expand Down
32 changes: 32 additions & 0 deletions integration_tests/multi_component_discovery.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include "integration_test_helper.h"
#include "global_include.h"
#include "dronecore.h"

using namespace dronecore;
using namespace std::chrono;
using namespace std::this_thread;
using namespace std::placeholders;
static size_t _component_count = 0;

static void on_component_discover(uint64_t uuid, uint8_t component_id)
{
if (uuid && int(component_id)) {
_component_count++;
}
std::cout << "Discovered component " << int(component_id)
<< " on vehicle " << uuid << std::endl;
}

TEST_F(SitlTest, DiscoverOneAutopilotAndCamera)
{
DroneCore connection;
std::cout << "started" << std::endl;

connection.add_udp_connection();
connection.register_on_discover(std::bind(on_component_discover, _1, _2));

sleep_for(seconds(5));
EXPECT_EQ(_component_count, 2);
std::cout << "exiting" << std::endl;
}

0 comments on commit e3a96bd

Please sign in to comment.