Skip to content

Commit 47c6bf8

Browse files
update the tests
1 parent 6721481 commit 47c6bf8

9 files changed

Lines changed: 405 additions & 249 deletions

libudpard/udpard.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ typedef struct udpard_tx_mem_resources_t
341341
/// These may be distinct per interface to allow each interface to draw buffers from a specific memory region
342342
/// or a specific DMA-compatible memory pool.
343343
///
344-
/// IMPORTANT: DISTINCT MEMORY RESOURCES INCREASE TX MEMORY USAGE AND DATA COPYING.
344+
/// IMPORTANT: distinct memory resources increase tx memory usage and data copying.
345345
/// If possible, it is recommended to use the same memory resource for all interfaces, because the library will be
346346
/// able to avoid frame duplication and instead reuse each frame across all interfaces when the MTUs are identical.
347347
udpard_mem_t payload[UDPARD_IFACE_COUNT_MAX];
@@ -392,6 +392,7 @@ typedef struct udpard_tx_vtable_t
392392
{
393393
/// Invoked from udpard_tx_poll() et al to push outgoing UDP datagrams into the socket/NIC driver.
394394
/// The callback must not mutate the TX pipeline (no udpard_tx_push/cancel/free).
395+
///
395396
/// The destination endpoint is provided only for P2P transfers; for multicast transfers, the application
396397
/// must compute the endpoint using udpard_make_subject_endpoint() based on the subject-ID. This is because
397398
/// the subject-ID may be changed by the consensus algorithm at any time if a collision/divergence is detected.
@@ -416,7 +417,7 @@ struct udpard_tx_t
416417
/// The Cyphal/UDP header is added to this value to obtain the total UDP datagram payload size.
417418
/// The value can be changed arbitrarily between enqueue operations as long as it is at least UDPARD_MTU_MIN.
418419
///
419-
/// IMPORTANT: DISTINCT MTU VALUES INCREASE TX MEMORY USAGE AND DATA COPYING.
420+
/// IMPORTANT: distinct MTU values increase tx memory usage and data copying.
420421
/// If possible, it is recommended to use the same MTU for all interfaces, because the library will be
421422
/// able to avoid frame duplication and instead reuse each frame across all interfaces.
422423
size_t mtu[UDPARD_IFACE_COUNT_MAX];

tests/src/test_e2e_api.cpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void tx_refcount_free(void* const user, const size_t size, void* const payload)
4545
// Shared deleter for captured TX frames.
4646
constexpr udpard_deleter_vtable_t tx_refcount_deleter_vt{ .free = &tx_refcount_free };
4747

48-
bool capture_tx_frame(udpard_tx_t* const tx, udpard_tx_ejection_t* const ejection)
48+
bool capture_tx_frame_impl(udpard_tx_t* const tx, udpard_tx_ejection_t* const ejection)
4949
{
5050
auto* frames = static_cast<std::vector<CapturedFrame>*>(tx->user);
5151
if (frames == nullptr) {
@@ -58,6 +58,16 @@ bool capture_tx_frame(udpard_tx_t* const tx, udpard_tx_ejection_t* const ejectio
5858
return true;
5959
}
6060

61+
bool capture_tx_frame_subject(udpard_tx_t* const tx, udpard_tx_ejection_t* const ejection)
62+
{
63+
return capture_tx_frame_impl(tx, ejection);
64+
}
65+
66+
bool capture_tx_frame_p2p(udpard_tx_t* const tx, udpard_tx_ejection_t* const ejection, udpard_udpip_ep_t /*dest*/)
67+
{
68+
return capture_tx_frame_impl(tx, ejection);
69+
}
70+
6171
void drop_frame(const CapturedFrame& frame)
6272
{
6373
udpard_tx_refcount_dec(udpard_bytes_t{ .size = frame.datagram.size, .data = frame.datagram.data });
@@ -70,7 +80,8 @@ void fill_random(std::vector<uint8_t>& data)
7080
}
7181
}
7282

73-
constexpr udpard_tx_vtable_t tx_vtable{ .eject = &capture_tx_frame };
83+
constexpr udpard_tx_vtable_t tx_vtable{ .eject_subject = &capture_tx_frame_subject,
84+
.eject_p2p = &capture_tx_frame_p2p };
7485

7586
// Feedback callback records completion.
7687
void record_feedback(udpard_tx_t*, const udpard_tx_feedback_t fb)
@@ -203,12 +214,6 @@ void test_reliable_delivery_under_losses()
203214
udpard_udpip_ep_t{ .ip = 0x0A000011U, .port = 7601U },
204215
udpard_udpip_ep_t{ .ip = 0x0A000012U, .port = 7602U },
205216
};
206-
const std::array<udpard_udpip_ep_t, UDPARD_IFACE_COUNT_MAX> topic_multicast{
207-
udpard_make_subject_endpoint(111U),
208-
udpard_udpip_ep_t{ .ip = 0x0A00000BU, .port = 7501U },
209-
udpard_udpip_ep_t{ .ip = 0x0A00000CU, .port = 7502U },
210-
};
211-
212217
// Payload and context.
213218
std::vector<uint8_t> payload(4096);
214219
fill_random(payload);
@@ -219,21 +224,21 @@ void test_reliable_delivery_under_losses()
219224
sub_rx.user = &ctx;
220225

221226
// Reliable transfer with staged losses.
222-
FeedbackState fb{};
223-
const udpard_bytes_scattered_t payload_view = make_scattered(payload.data(), payload.size());
224-
std::array<udpard_udpip_ep_t, UDPARD_IFACE_COUNT_MAX> dest_per_iface = topic_multicast;
225-
pub_tx.mtu[0] = 600;
226-
pub_tx.mtu[1] = 900;
227-
pub_tx.mtu[2] = 500;
228-
const udpard_us_t start = 0;
229-
const udpard_us_t deadline = start + 200000;
227+
FeedbackState fb{};
228+
const udpard_bytes_scattered_t payload_view = make_scattered(payload.data(), payload.size());
229+
pub_tx.mtu[0] = 600;
230+
pub_tx.mtu[1] = 900;
231+
pub_tx.mtu[2] = 500;
232+
const udpard_us_t start = 0;
233+
const udpard_us_t deadline = start + 200000;
234+
const uint16_t iface_bitmap_all = UDPARD_IFACE_BITMAP_ALL;
230235
const udpard_deleter_t tx_payload_deleter{ .vtable = &tx_refcount_deleter_vt, .context = nullptr };
231236
TEST_ASSERT_TRUE(udpard_tx_push(&pub_tx,
232237
start,
233238
deadline,
239+
iface_bitmap_all,
234240
udpard_prio_fast,
235241
topic_hash,
236-
dest_per_iface.data(),
237242
1U,
238243
payload_view,
239244
&record_feedback,
@@ -341,14 +346,14 @@ void test_reliable_stats_and_failures()
341346
TEST_ASSERT_TRUE(udpard_tx_new(&exp_tx, 0x9999000011112222ULL, 2U, 4, exp_mem, &tx_vtable));
342347
exp_tx.user = &exp_frames;
343348
FeedbackState fb_fail{};
344-
const udpard_udpip_ep_t exp_dest[UDPARD_IFACE_COUNT_MAX] = { udpard_make_subject_endpoint(99U), {}, {} };
345-
const udpard_bytes_scattered_t exp_payload = make_scattered("ping", 4);
349+
const uint16_t iface_bitmap_1 = (1U << 0U);
350+
const udpard_bytes_scattered_t exp_payload = make_scattered("ping", 4);
346351
TEST_ASSERT_TRUE(udpard_tx_push(&exp_tx,
347352
0,
348353
10,
354+
iface_bitmap_1,
349355
udpard_prio_fast,
350356
0xABCULL,
351-
exp_dest,
352357
5U,
353358
exp_payload,
354359
&record_feedback,
@@ -400,15 +405,14 @@ void test_reliable_stats_and_failures()
400405
TEST_ASSERT_TRUE(
401406
udpard_rx_port_new(&port, 0x12340000ULL, 64, UDPARD_RX_REORDERING_WINDOW_UNORDERED, rx_mem, &callbacks));
402407

403-
const udpard_udpip_ep_t src_dest[UDPARD_IFACE_COUNT_MAX] = { udpard_make_subject_endpoint(12U), {}, {} };
404408
const udpard_bytes_scattered_t src_payload = make_scattered(ctx.expected.data(), ctx.expected.size());
405409
FeedbackState fb_ignore{};
406410
TEST_ASSERT_TRUE(udpard_tx_push(&src_tx,
407411
0,
408412
1000,
413+
iface_bitmap_1,
409414
udpard_prio_fast,
410415
port.topic_hash,
411-
src_dest,
412416
7U,
413417
src_payload,
414418
&record_feedback,

0 commit comments

Comments
 (0)