Skip to content

Commit 01b93e2

Browse files
author
jonas
committed
fix(test): testAsyncAbortAndReissue ensure stale reply is cleared
1 parent 5333e50 commit 01b93e2

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

src/systemcmds/tests/test_dataman.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -778,22 +778,30 @@ DatamanTest::testAsyncAbortAndReissue()
778778
// and still return current data.
779779
const dm_item_t item = DM_KEY_WAYPOINTS_OFFBOARD_0;
780780
const uint32_t length = g_per_item_size[item];
781-
const uint32_t index = 7;
782-
const uint8_t value = 0xC3;
781+
const uint32_t stale_index = 7;
782+
const uint8_t stale_value = 0xC3;
783+
const uint32_t new_index = 8;
784+
const uint8_t new_value = 0xAA;
783785

784-
// Store a known value.
785-
memset(_buffer_write, value, sizeof(_buffer_write));
786+
memset(_buffer_write, stale_value, sizeof(_buffer_write));
786787

787-
if (!_dataman_client1.writeSync(item, index, _buffer_write, length)) {
788-
PX4_ERR("seed writeSync failed");
788+
if (!_dataman_client1.writeSync(item, stale_index, _buffer_write, length)) {
789+
PX4_ERR("stale seed writeSync failed");
790+
return false;
791+
}
792+
793+
memset(_buffer_write, new_value, sizeof(_buffer_write));
794+
795+
if (!_dataman_client1.writeSync(item, new_index, _buffer_write, length)) {
796+
PX4_ERR("new seed writeSync failed");
789797
return false;
790798
}
791799

792800
// Start an async read but never call update():
793801
// this leaves a reply queued on the response topic.
794802
uint8_t scratch[DM_MAX_DATA_SIZE] = {};
795803

796-
if (!_dataman_client1.readAsync(item, index, scratch, length)) {
804+
if (!_dataman_client1.readAsync(item, stale_index, scratch, length)) {
797805
PX4_ERR("first readAsync failed");
798806
return false;
799807
}
@@ -804,10 +812,10 @@ DatamanTest::testAsyncAbortAndReissue()
804812
// Abandon the operation. The queued reply is now stale.
805813
_dataman_client1.abortCurrentOperation();
806814

807-
// A fresh async read must drain the stale reply and return the current value.
815+
// A fresh async read must drain the stale reply and return the new request's value.
808816
memset(_buffer_read, 0, sizeof(_buffer_read));
809817

810-
if (!_dataman_client1.readAsync(item, index, _buffer_read, length)) {
818+
if (!_dataman_client1.readAsync(item, new_index, _buffer_read, length)) {
811819
PX4_ERR("second readAsync failed");
812820
return false;
813821
}
@@ -837,7 +845,7 @@ DatamanTest::testAsyncAbortAndReissue()
837845
}
838846

839847
for (uint32_t i = 0; i < length; ++i) {
840-
if (_buffer_read[i] != value) {
848+
if (_buffer_read[i] != new_value) {
841849
PX4_ERR("reissued read returned wrong data at %" PRIu32, i);
842850
return false;
843851
}

0 commit comments

Comments
 (0)