Skip to content

Commit cae58b6

Browse files
wip
1 parent e42f628 commit cae58b6

File tree

3 files changed

+56
-17
lines changed

3 files changed

+56
-17
lines changed

libudpard/udpard.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ static byte_t* header_serialize(byte_t* const buffer,
332332
return ptr;
333333
}
334334

335-
static bool header_deserialize(const udpard_bytes_mut_t dgram_payload,
336-
meta_t* const out_meta,
337-
uint32_t* const frame_index,
338-
uint32_t* const frame_payload_offset,
339-
uint32_t* const prefix_crc,
340-
udpard_bytes_mut_t* const out_payload)
335+
static bool header_deserialize(const udpard_bytes_mut_t dgram_payload,
336+
meta_t* const out_meta,
337+
uint32_t* const frame_index,
338+
uint32_t* const frame_payload_offset,
339+
uint32_t* const prefix_crc,
340+
udpard_bytes_t* const out_payload)
341341
{
342342
UDPARD_ASSERT(out_payload != NULL);
343343
bool ok = (dgram_payload.size >= HEADER_SIZE_BYTES) && (dgram_payload.data != NULL) && //
@@ -1744,16 +1744,14 @@ bool udpard_rx_port_push(udpard_rx_t* const rx,
17441744
if (ok) {
17451745
port->invoked = true;
17461746
// Parse and validate the frame.
1747-
udpard_bytes_mut_t payload = { 0 };
1748-
rx_frame_t frame = { 0 };
1749-
uint32_t frame_index = 0;
1750-
uint32_t offset_32 = 0;
1751-
const bool frame_valid =
1752-
header_deserialize(datagram_payload, &frame.meta, &frame_index, &offset_32, &frame.base.crc, &payload);
1747+
rx_frame_t frame = { 0 };
1748+
uint32_t frame_index = 0;
1749+
uint32_t offset_32 = 0;
1750+
const bool frame_valid = header_deserialize(
1751+
datagram_payload, &frame.meta, &frame_index, &offset_32, &frame.base.crc, &frame.base.payload);
17531752
frame.base.offset = (size_t)offset_32;
1754-
(void)frame_index; // currently not used by this reassembler implementation.
1755-
UDPARD_ASSERT((frame.base.origin.data == datagram_payload.data) &&
1756-
(frame.base.origin.size == datagram_payload.size));
1753+
(void)frame_index; // currently not used by this reassembler implementation.
1754+
frame.base.origin = datagram_payload; // Take ownership of the payload.
17571755
// Process the frame.
17581756
if (frame_valid) {
17591757
if (frame.meta.topic_hash == port->topic_hash) {

tests/src/test_intrusive_header.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static void test_header_v2(void)
2828
// Just verify deserialization works correctly
2929

3030
meta_t meta_out;
31-
udpard_bytes_mut_t payload_out;
31+
udpard_bytes_t payload_out;
3232
uint32_t frame_index = 0;
3333
uint32_t frame_payload_offset = 0;
3434
uint32_t prefix_crc = 0;
@@ -86,7 +86,7 @@ static void test_header_deserialize_edge_cases(void)
8686
};
8787

8888
meta_t meta_out;
89-
udpard_bytes_mut_t payload_out;
89+
udpard_bytes_t payload_out;
9090
uint32_t frame_index = 0;
9191
uint32_t frame_payload_offset = 0;
9292
uint32_t prefix_crc = 0;

tests/src/test_intrusive_rx.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,6 +2876,45 @@ static void test_session_unordered(void)
28762876
instrumented_allocator_reset(&alloc_payload);
28772877
}
28782878

2879+
// --------------------------------------------- PORT ---------------------------------------------
2880+
2881+
/// Tests ports in ORDERED, UNORDERED, and STATELESS modes.
2882+
/// The UNORDERED port is the p2p_port in the rx instance; the other modes are tested on separate port instances.
2883+
/// All transfers are single-frame transfers for simplicity, since we already have dedicated lower-level tests.
2884+
static void test_port(void)
2885+
{
2886+
// Initialize the memory resources.
2887+
instrumented_allocator_t alloc_frag = { 0 };
2888+
instrumented_allocator_new(&alloc_frag);
2889+
const udpard_mem_resource_t mem_frag = instrumented_allocator_make_resource(&alloc_frag);
2890+
2891+
instrumented_allocator_t alloc_session = { 0 };
2892+
instrumented_allocator_new(&alloc_session);
2893+
const udpard_mem_resource_t mem_session = instrumented_allocator_make_resource(&alloc_session);
2894+
2895+
instrumented_allocator_t alloc_payload = { 0 };
2896+
instrumented_allocator_new(&alloc_payload);
2897+
const udpard_mem_resource_t mem_payload = instrumented_allocator_make_resource(&alloc_payload);
2898+
const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter(&alloc_payload);
2899+
2900+
const udpard_rx_memory_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
2901+
2902+
// Initialize the shared RX instance.
2903+
const uint64_t local_uid = 0x6EC164169C3088B4ULL;
2904+
udpard_rx_t rx;
2905+
TEST_ASSERT(udpard_rx_new(&rx, local_uid, rx_mem, &on_message, &on_collision, &on_ack_mandate));
2906+
callback_result_t cb_result = { 0 };
2907+
rx.user = &cb_result;
2908+
TEST_ASSERT_EQUAL(local_uid, rx.p2p_port.topic_hash);
2909+
TEST_ASSERT_EQUAL(UDPARD_REORDERING_WINDOW_UNORDERED, rx.p2p_port.reordering_window);
2910+
2911+
// TODO continue: init two ports, one ORDERED, one STATELESS. Feed frames from different remote nodes into each.
2912+
// Verify the callbacks: on message, on ack, on collision.
2913+
// Feed bad frames and verify they are rejected with no memory leaks.
2914+
(void)mem_payload; // TODO: Will be used when test is completed
2915+
(void)del_payload; // TODO: Will be used when test is completed
2916+
}
2917+
28792918
void setUp(void) {}
28802919

28812920
void tearDown(void) {}
@@ -2897,5 +2936,7 @@ int main(void)
28972936
RUN_TEST(test_session_ordered);
28982937
RUN_TEST(test_session_unordered);
28992938

2939+
RUN_TEST(test_port);
2940+
29002941
return UNITY_END();
29012942
}

0 commit comments

Comments
 (0)