mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-02 14:30:59 +08:00
fix(uorb): keep shared topics advertised on publisher teardown (#29176)
* fix(dataman_client): keep request topic advertised on client teardown * fix(uorb): keep shared topics advertised on publisher teardown Single-instance publications share one advertised flag, so destroying one publisher must not hide updates from the others. Keep automatic unadvertising in PublicationMultiBase and remove the DatamanClient workaround. Cover surviving publishers and instance reuse, and reset retained input samples between test cases. Tested: make tests (215/215), make format. Signed-off-by: jonas <jonas.perolini@rigi.tech> Assisted-by: Codex * docs(uorb): correct unadvertise comments and document teardown The unadvertise comment claimed it has no effect on single-instance topics, which is how one publisher's teardown came to hide the others. State what clearing the shared flag does, and document that only PublicationMulti releases its instance on destruction. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: jonas <jonas.perolini@rigi.tech> * test(uorb): keep test cases independent of retained samples A destroyed single-instance publication now leaves its last sample visible, so ManualControlTest, test_prec_takeoff and mixer_module_tests passed only in declaration order and failed under --gtest_shuffle. Reset with an inert sample where one exists, otherwise unadvertise the test's own publications, and drop module outputs left over from a previous case. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: jonas <jonas.perolini@rigi.tech> * fix(boards): drop the PublicationBase destructor from the ITCM lists The destructor is now trivial and no longer emitted, so itcm_check.py fails on the missing section. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> --------- Signed-off-by: jonas <jonas.perolini@rigi.tech> Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> Co-authored-by: jonas <jonas.perolini@rigi.tech> Co-authored-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
18 files changed
+118
-20
No files matched your search
@@ -696,7 +696,6 @@
|
||||
*(.text._ZN30MavlinkStreamGlobalPositionInt8get_sizeEv)
|
||||
*(.text._ZN22MavlinkStreamESCStatus8get_sizeEv)
|
||||
*(.text.read)
|
||||
*(.text._ZN4uORB15PublicationBaseD1Ev)
|
||||
*(.text._ZN22MavlinkStreamDebugVect8get_sizeEv)
|
||||
*(.text._ZN7Mission11on_inactiveEv)
|
||||
*(.text._ZN7sensors19VehicleMagnetometer20UpdateMagCalibrationEv)
|
||||
|
||||
@@ -679,7 +679,6 @@
|
||||
*(.text._ZN30MavlinkStreamGlobalPositionInt8get_sizeEv)
|
||||
*(.text._ZN22MavlinkStreamESCStatus8get_sizeEv)
|
||||
*(.text.read)
|
||||
*(.text._ZN4uORB15PublicationBaseD1Ev)
|
||||
*(.text._ZN22MavlinkStreamDebugVect8get_sizeEv)
|
||||
*(.text._ZN7Mission11on_inactiveEv)
|
||||
*(.text._ZN7sensors19VehicleMagnetometer20UpdateMagCalibrationEv)
|
||||
|
||||
@@ -686,7 +686,6 @@
|
||||
*(.text._ZN30MavlinkStreamGlobalPositionInt8get_sizeEv)
|
||||
*(.text._ZN22MavlinkStreamESCStatus8get_sizeEv)
|
||||
*(.text.read)
|
||||
*(.text._ZN4uORB15PublicationBaseD1Ev)
|
||||
*(.text._ZN22MavlinkStreamDebugVect8get_sizeEv)
|
||||
*(.text._ZN7Mission11on_inactiveEv)
|
||||
*(.text._ZN7sensors19VehicleMagnetometer20UpdateMagCalibrationEv)
|
||||
|
||||
@@ -685,7 +685,6 @@
|
||||
*(.text._ZN30MavlinkStreamGlobalPositionInt8get_sizeEv)
|
||||
*(.text._ZN22MavlinkStreamESCStatus8get_sizeEv)
|
||||
*(.text.read)
|
||||
*(.text._ZN4uORB15PublicationBaseD1Ev)
|
||||
*(.text._ZN22MavlinkStreamDebugVect8get_sizeEv)
|
||||
*(.text._ZN7Mission11on_inactiveEv)
|
||||
*(.text._ZN7sensors19VehicleMagnetometer20UpdateMagCalibrationEv)
|
||||
|
||||
@@ -696,7 +696,6 @@
|
||||
*(.text._ZN30MavlinkStreamGlobalPositionInt8get_sizeEv)
|
||||
*(.text._ZN22MavlinkStreamESCStatus8get_sizeEv)
|
||||
*(.text.read)
|
||||
*(.text._ZN4uORB15PublicationBaseD1Ev)
|
||||
*(.text._ZN22MavlinkStreamDebugVect8get_sizeEv)
|
||||
*(.text._ZN7Mission11on_inactiveEv)
|
||||
*(.text._ZN7sensors19VehicleMagnetometer20UpdateMagCalibrationEv)
|
||||
|
||||
@@ -187,6 +187,9 @@ A subscriber will then have to choose to which instance to subscribe to using `o
|
||||
|
||||
Make sure not to mix `orb_advertise_multi` and `orb_advertise` for the same topic!
|
||||
|
||||
Destroying a `uORB::PublicationMulti` frees its instance for the next publisher.
|
||||
Destroying a `uORB::Publication` leaves the topic advertised with its last sample, because other publishers may share it.
|
||||
|
||||
The full API is documented in [platforms/common/uORB/uORBManager.hpp](https://github.com/PX4/PX4-Autopilot/blob/main/platforms/common/uORB/uORBManager.hpp).
|
||||
|
||||
## Listing Topics and Listening in
|
||||
|
||||
@@ -45,10 +45,10 @@
|
||||
namespace uORB
|
||||
{
|
||||
|
||||
PublicationBase::~PublicationBase()
|
||||
PublicationMultiBase::~PublicationMultiBase()
|
||||
{
|
||||
if (_handle != nullptr) {
|
||||
// don't automatically unadvertise queued publications (eg vehicle_command)
|
||||
// free the instance for the next advertiser, but keep queued publications advertised
|
||||
if (Manager::orb_get_queue_size(_handle) == 1) {
|
||||
unadvertise();
|
||||
}
|
||||
|
||||
@@ -64,7 +64,8 @@ protected:
|
||||
|
||||
PublicationBase(ORB_ID id) : _orb_id(id) {}
|
||||
|
||||
~PublicationBase();
|
||||
// Single-instance publishers share the node, so destruction must not unadvertise it.
|
||||
~PublicationBase() = default;
|
||||
|
||||
// type-independent publish; data points to a message of the topic's type
|
||||
bool publish(const void *data);
|
||||
|
||||
@@ -63,6 +63,8 @@ protected:
|
||||
PublicationBase(id)
|
||||
{}
|
||||
|
||||
~PublicationMultiBase();
|
||||
|
||||
// type-independent publish; data points to a message of the topic's type
|
||||
bool publish(const void *data);
|
||||
};
|
||||
|
||||
@@ -304,15 +304,9 @@ int uORB::DeviceNode::unadvertise(orb_advert_t handle)
|
||||
uORB::DeviceNode *devnode = (uORB::DeviceNode *)handle;
|
||||
|
||||
/*
|
||||
* We are cheating a bit here. First, with the current implementation, we can only
|
||||
* have multiple publishers for instance 0. In this case the caller will have
|
||||
* instance=nullptr and _published has no effect at all. Thus no unadvertise is
|
||||
* necessary.
|
||||
* In case of multiple instances, we have at most 1 publisher per instance and
|
||||
* we can signal an instance as 'free' by setting _published to false.
|
||||
* We never really free the DeviceNode, for this we would need reference counting
|
||||
* of subscribers and publishers. But we also do not have a leak since future
|
||||
* publishers reuse the same DeviceNode object.
|
||||
* Frees a multi-instance node for the next advertiser and hides it from all subscribers.
|
||||
* Publishers of a single-instance topic share this flag, so unadvertising hides all of them.
|
||||
* The DeviceNode is never freed; later publishers reuse it.
|
||||
*/
|
||||
devnode->_advertised.store(false);
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ private:
|
||||
List<uORB::SubscriptionCallback *> _callbacks;
|
||||
|
||||
const uint8_t _instance; /**< orb multi instance identifier */
|
||||
px4::atomic_bool _advertised{false}; /**< has ever been advertised (not necessarily published data yet) */
|
||||
px4::atomic_bool _advertised{false}; /**< set on advertise, cleared on unadvertise; subscribers only read while set */
|
||||
|
||||
int8_t _subscriber_count{0};
|
||||
|
||||
|
||||
@@ -258,6 +258,7 @@ public:
|
||||
|
||||
/**
|
||||
* Unadvertise a topic.
|
||||
* This hides the topic instance from all subscribers, including data from other publishers of a single-instance topic.
|
||||
*
|
||||
* @param handle handle returned by orb_advertise or orb_advertise_multi.
|
||||
* @return 0 on success
|
||||
|
||||
@@ -39,7 +39,9 @@
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <lib/cdev/CDev.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/SubscriptionMultiArray.hpp>
|
||||
|
||||
uORBTest::UnitTest &uORBTest::UnitTest::instance()
|
||||
@@ -324,6 +326,32 @@ int uORBTest::UnitTest::test_single()
|
||||
return test_fail("orb_unadvertise failed: %i", ret);
|
||||
}
|
||||
|
||||
uORB::Publication<orb_test_s> surviving_pub{ORB_ID::orb_test};
|
||||
uORB::Subscription sub{ORB_ID::orb_test};
|
||||
t.val = 3;
|
||||
|
||||
if (!surviving_pub.publish(t) || !sub.update(&u) || u.val != t.val) {
|
||||
return test_fail("initial publication failed");
|
||||
}
|
||||
|
||||
{
|
||||
uORB::Publication<orb_test_s> temporary_pub{ORB_ID::orb_test};
|
||||
t.val = 4;
|
||||
|
||||
if (!temporary_pub.publish(t) || !sub.update(&u) || u.val != t.val) {
|
||||
return test_fail("second publication failed");
|
||||
}
|
||||
}
|
||||
|
||||
t.val = 5;
|
||||
|
||||
if (!surviving_pub.publish(t) || !sub.update(&u) || u.val != t.val) {
|
||||
return test_fail("publication lost after another publisher was destroyed");
|
||||
}
|
||||
|
||||
// Leave the topic unadvertised for the multi-instance tests.
|
||||
surviving_pub.unadvertise();
|
||||
|
||||
return test_note("PASS single-topic test");
|
||||
}
|
||||
|
||||
@@ -332,6 +360,14 @@ int uORBTest::UnitTest::test_multi()
|
||||
/* this routine tests the multi-topic support */
|
||||
test_note("try multi-topic support");
|
||||
|
||||
{
|
||||
uORB::PublicationMulti<orb_test_s> temporary_pub{ORB_ID::orb_multitest};
|
||||
|
||||
if (!temporary_pub.advertise() || temporary_pub.get_instance() != 0) {
|
||||
return test_fail("multi-instance advertisement failed");
|
||||
}
|
||||
} // Destruction must release instance 0 for reuse below.
|
||||
|
||||
orb_test_s t{};
|
||||
orb_test_s u{};
|
||||
|
||||
|
||||
@@ -82,6 +82,14 @@ class OutputModuleTest : public OutputModuleInterface
|
||||
public:
|
||||
OutputModuleTest() : OutputModuleInterface(MODULE_NAME, px4::wq_configurations::hp_default) {};
|
||||
|
||||
~OutputModuleTest() override
|
||||
{
|
||||
// Hide this test's commands from the next test: a zero actuator command is not inert
|
||||
_actuator_motors_pub.unadvertise();
|
||||
_actuator_servos_pub.unadvertise();
|
||||
_actuator_armed_pub.unadvertise();
|
||||
}
|
||||
|
||||
void Run() override
|
||||
{
|
||||
was_scheduled = true;
|
||||
|
||||
@@ -83,10 +83,24 @@ public:
|
||||
param_set(param_find("COM_FLTMODE5"), &mode);
|
||||
mode = NAVIGATION_STATE_AUTO_MISSION;
|
||||
param_set(param_find("COM_FLTMODE6"), &mode);
|
||||
|
||||
// Drop outputs left over from a previous test
|
||||
while (_manual_control_setpoint_sub.update()) {}
|
||||
|
||||
while (_action_request_sub.update()) {}
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
// Hide this test's inputs from the next test: empty switch or status samples are not inert
|
||||
_manual_control_switches_pub.unadvertise();
|
||||
_manual_control_input_pub.unadvertise();
|
||||
_vehicle_status_pub.unadvertise();
|
||||
}
|
||||
|
||||
uORB::Publication<manual_control_switches_s> _manual_control_switches_pub{ORB_ID(manual_control_switches)};
|
||||
uORB::Publication<manual_control_setpoint_s> _manual_control_input_pub{ORB_ID(manual_control_input)};
|
||||
uORB::Publication<vehicle_status_s> _vehicle_status_pub{ORB_ID(vehicle_status)};
|
||||
uORB::SubscriptionData<manual_control_setpoint_s> _manual_control_setpoint_sub{ORB_ID(manual_control_setpoint)};
|
||||
uORB::SubscriptionData<action_request_s> _action_request_sub{ORB_ID(action_request)};
|
||||
|
||||
@@ -309,8 +323,7 @@ TEST_F(SwitchTest, ModeSwitchInitialization)
|
||||
TEST_F(SwitchTest, ModeSwitchInitializationArmed)
|
||||
{
|
||||
// GIVEN: vehicle is armed
|
||||
uORB::Publication<vehicle_status_s> vehicle_status_pub{ORB_ID(vehicle_status)};
|
||||
vehicle_status_pub.publish({.arming_state = vehicle_status_s::ARMING_STATE_ARMED});
|
||||
_vehicle_status_pub.publish({.arming_state = vehicle_status_s::ARMING_STATE_ARMED});
|
||||
|
||||
// GIVEN: valid stick input from RC
|
||||
_manual_control_input_pub.publish({.timestamp_sample = _timestamp, .valid = true, .data_source = manual_control_setpoint_s::SOURCE_RC});
|
||||
|
||||
@@ -162,6 +162,43 @@ protected:
|
||||
MissionRouteCache _cache{};
|
||||
};
|
||||
|
||||
TEST_F(MissionRouteCacheTest, DatamanRequestsSurviveAnotherClientBeingDestroyed)
|
||||
{
|
||||
const mission_item_s expected = makePositionItemFromOffset(kBaseLat, kBaseLon, 10.f, 20.f, kAlt);
|
||||
writeMissionItem(expected, 0);
|
||||
|
||||
{
|
||||
// A client destroyed at runtime, e.g. with a stopped MAVLink instance,
|
||||
// must not cut off the clients that remain on the shared request topic.
|
||||
DatamanClient temporary_client;
|
||||
mission_item_s item{};
|
||||
ASSERT_TRUE(temporary_client.readSync(DM_KEY_WAYPOINTS_OFFBOARD_0, 0,
|
||||
reinterpret_cast<uint8_t *>(&item), sizeof(item)));
|
||||
expectMissionItemMatches(item, expected);
|
||||
}
|
||||
|
||||
mission_item_s item{};
|
||||
ASSERT_TRUE(_dataman_client.readAsync(DM_KEY_WAYPOINTS_OFFBOARD_0, 0,
|
||||
reinterpret_cast<uint8_t *>(&item), sizeof(item)));
|
||||
ASSERT_TRUE(DatamanClientTestPeer::waitForOperation(_dataman_client, 1_s));
|
||||
bool success = false;
|
||||
ASSERT_TRUE(_dataman_client.lastOperationCompleted(success));
|
||||
ASSERT_TRUE(success);
|
||||
expectMissionItemMatches(item, expected);
|
||||
|
||||
item = {};
|
||||
ASSERT_TRUE(_dataman_client.readSync(DM_KEY_WAYPOINTS_OFFBOARD_0, 0,
|
||||
reinterpret_cast<uint8_t *>(&item), sizeof(item), 1_s));
|
||||
expectMissionItemMatches(item, expected);
|
||||
|
||||
const mission_s mission = makeMission(47, 1);
|
||||
ASSERT_TRUE(MissionRouteCacheTestPeer::runCacheUntil(_cache, mission, [&] {
|
||||
return _cache.missionItemsReady(mission);
|
||||
}));
|
||||
ASSERT_TRUE(_cache.loadMissionItem(0, item));
|
||||
expectMissionItemMatches(item, expected);
|
||||
}
|
||||
|
||||
// Fully loaded mission cache with readable items.
|
||||
TEST_F(MissionRouteCacheTest, MissionCacheLoadsAllMissionItems)
|
||||
{
|
||||
|
||||
@@ -95,6 +95,9 @@ protected:
|
||||
prec_takeoff_status_s status;
|
||||
|
||||
while (_status_sub.update(&status)) {}
|
||||
|
||||
// Replace a target retained from a previous test with an invalid one
|
||||
_target_pub.publish({});
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
|
||||
@@ -143,6 +143,11 @@ protected:
|
||||
_uav_gnss_pub = std::make_unique<uORB::Publication<vehicle_gnss_s>>(ORB_ID(vehicle_gnss));
|
||||
_target_gps_pub = std::make_unique<uORB::Publication<target_gnss_s>>(ORB_ID(target_gnss));
|
||||
|
||||
// Discard input samples retained from the previous test.
|
||||
_vision_pub->publish({});
|
||||
_uav_gnss_pub->publish({});
|
||||
_target_gps_pub->publish({});
|
||||
|
||||
_aid_fiducial_sub = std::make_unique<uORB::SubscriptionData<vte_aid_source3d_s>>(ORB_ID(vte_aid_fiducial_marker));
|
||||
_aid_gps_mission_sub = std::make_unique<uORB::SubscriptionData<vte_aid_source3d_s>>(ORB_ID(vte_aid_gps_pos_mission));
|
||||
_aid_gps_target_sub = std::make_unique<uORB::SubscriptionData<vte_aid_source3d_s>>(ORB_ID(vte_aid_gps_pos_target));
|
||||
|
||||
Reference in new issue
Block a user