• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 21724008972

05 Feb 2026 06:42PM UTC coverage: 49.029% (+0.07%) from 48.959%
21724008972

push

github

web-flow
core: fix MAVLink message sequence (#2762)

* core: fix MAVLink message sequence

The MAVLink headers use an inline function to get the mavlink channel,
so we end up having separate sequence numbers in different translation
units. By defining this function ourselves and linking it later, we make
sure to use the same sequence everywhere.

This should fix seq numbering that's invalid (per component).

We also add a system test to actually test this.

* system_tests: fixup thread sanitizer issues

* system_tests: use TCP for seq to avoid drops

51 of 56 new or added lines in 6 files covered. (91.07%)

5 existing lines in 4 files now uncovered.

18362 of 37451 relevant lines covered (49.03%)

671.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.97
/src/system_tests/mavlink_seq.cpp
1
#include "log.h"
2
#include "mavsdk.h"
3
#include <chrono>
4
#include <thread>
5
#include <mutex>
6
#include <vector>
7
#include <gtest/gtest.h>
8

9
using namespace mavsdk;
10

11
TEST(SystemTest, MavlinkSeqSequential)
4✔
12
{
13
    Mavsdk mavsdk_autopilot{Mavsdk::Configuration{ComponentType::Autopilot}};
1✔
14
    Mavsdk mavsdk_groundstation{Mavsdk::Configuration{ComponentType::GroundStation}};
1✔
15

16
    ASSERT_EQ(
1✔
17
        mavsdk_groundstation.add_any_connection("tcpin://0.0.0.0:17012"),
18
        ConnectionResult::Success);
1✔
19
    ASSERT_EQ(
1✔
20
        mavsdk_autopilot.add_any_connection("tcpout://127.0.0.1:17012"), ConnectionResult::Success);
1✔
21

22
    auto maybe_system = mavsdk_groundstation.first_autopilot(10.0);
1✔
23
    ASSERT_TRUE(maybe_system);
1✔
24

25
    std::mutex seq_mutex;
1✔
26
    std::vector<uint8_t> seq_numbers;
1✔
27

28
    constexpr unsigned num_messages = 10;
1✔
29

30
    // Intercept all incoming messages on the ground station and record
31
    // sequence numbers from the autopilot system (sysid 1, compid 1).
32
    mavsdk_groundstation.intercept_incoming_messages_async([&](mavlink_message_t& message) -> bool {
11✔
33
        if (message.sysid == 1 && message.compid == MAV_COMP_ID_AUTOPILOT1) {
10✔
34
            std::lock_guard<std::mutex> lock(seq_mutex);
10✔
35
            seq_numbers.push_back(message.seq);
10✔
36
        }
10✔
37
        return true;
10✔
38
    });
39

40
    // Collect messages (heartbeats at 1 Hz plus any other traffic).
41
    for (unsigned i = 0; i < 150; ++i) {
51✔
42
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
51✔
43
        std::lock_guard<std::mutex> lock(seq_mutex);
51✔
44
        if (seq_numbers.size() >= num_messages) {
51✔
45
            break;
1✔
46
        }
47
    }
51✔
48

49
    // Stop intercepting.
50
    mavsdk_groundstation.intercept_incoming_messages_async(nullptr);
1✔
51

52
    std::lock_guard<std::mutex> lock(seq_mutex);
1✔
53
    ASSERT_GE(seq_numbers.size(), num_messages);
1✔
54

55
    // Verify that all messages from the autopilot component have strictly
56
    // sequential seq numbers (incrementing by 1 with uint8_t wrapping).
57
    for (unsigned i = 1; i < num_messages; ++i) {
10✔
58
        uint8_t expected = static_cast<uint8_t>(seq_numbers[i - 1] + 1);
9✔
59
        EXPECT_EQ(seq_numbers[i], expected)
9✔
NEW
60
            << "seq[" << i - 1 << "]=" << static_cast<int>(seq_numbers[i - 1]) << " seq[" << i
×
61
            << "]=" << static_cast<int>(seq_numbers[i]);
9✔
62
    }
63
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc