Skip to content

Commit 88e00cd

Browse files
fix tests
1 parent 451d584 commit 88e00cd

File tree

3 files changed

+59
-232
lines changed

3 files changed

+59
-232
lines changed

libudpard/udpard.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static tx_chain_t tx_spool(const udpard_tx_mem_resources_t memory,
473473
uint32_t prefix_crc = CRC_INITIAL;
474474
tx_chain_t out = { NULL, NULL, 0 };
475475
size_t offset = 0U;
476-
while (offset < payload.size) {
476+
do {
477477
const size_t progress = smaller(payload.size - offset, mtu);
478478
udpard_tx_item_t* const item = tx_item_new(memory, //
479479
deadline,
@@ -504,7 +504,7 @@ static tx_chain_t tx_spool(const udpard_tx_mem_resources_t memory,
504504
UDPARD_ASSERT(offset <= payload.size);
505505
UDPARD_ASSERT((!last) || (offset == payload.size));
506506
out.count++;
507-
}
507+
} while (offset < payload.size);
508508
UDPARD_ASSERT((offset == payload.size) || (out.tail == NULL));
509509
return out;
510510
}
@@ -519,7 +519,7 @@ static uint32_t tx_push(udpard_tx_t* const tx,
519519
UDPARD_ASSERT(tx != NULL);
520520
uint32_t out = 0; // The number of frames enqueued; zero on error (error counters incremented).
521521
const size_t mtu = larger(tx->mtu, UDPARD_MTU_MIN);
522-
const size_t frame_count = (payload.size + mtu - 1U) / mtu;
522+
const size_t frame_count = larger(1, (payload.size + mtu - 1U) / mtu);
523523
if ((tx->queue_size + frame_count) > tx->queue_capacity) {
524524
tx->errors_capacity++;
525525
} else {

tests/src/test_intrusive_header.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static void test_header_v2(void)
1717
.sender_uid = 0x1122334455667788ULL,
1818
.topic_hash = 0x99AABBCCDDEEFF00ULL,
1919
};
20-
header_serialize(buffer, meta_in, true, 0x00123456, 0x00654321);
20+
header_serialize(buffer, meta_in, true, 0x00123456, 0x00654321, 0x11223344);
2121

2222
// >>> from pycyphal.transport.commons.crc import CRC32C
2323
// >>> list(CRC32C.new(data).value_as_bytes)
@@ -32,8 +32,8 @@ static void test_header_v2(void)
3232
0x11, 0x00, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, // transfer_id
3333
0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, // sender_uid
3434
0x00, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, // topic_hash
35-
0, 0, 0, 0, // reserved
36-
8, 200, 228, 86 // header CRC
35+
0x44, 0x33, 0x22, 0x11, // prefix_crc
36+
113, 119, 83, 71 // header CRC
3737
};
3838
// clang-format on
3939
TEST_ASSERT_EQUAL_MEMORY(reference, buffer, HEADER_SIZE_BYTES);
@@ -43,11 +43,13 @@ static void test_header_v2(void)
4343
bool flag_eot = false;
4444
uint32_t frame_index = 0;
4545
uint32_t frame_payload_offset = 0;
46+
uint32_t prefix_crc = 0;
4647
TEST_ASSERT(header_deserialize((udpard_bytes_mut_t){ .size = sizeof(buffer), .data = buffer },
4748
&meta_out,
4849
&flag_eot,
4950
&frame_index,
5051
&frame_payload_offset,
52+
&prefix_crc,
5153
&payload_out));
5254
TEST_ASSERT_EQUAL(sizeof(buffer) - HEADER_SIZE_BYTES, payload_out.size);
5355
TEST_ASSERT_EQUAL(&buffer[HEADER_SIZE_BYTES], payload_out.data);
@@ -57,6 +59,7 @@ static void test_header_v2(void)
5759
TEST_ASSERT_FALSE(meta_out.flag_ack);
5860
TEST_ASSERT_EQUAL_UINT32(0x00123456, frame_index);
5961
TEST_ASSERT_EQUAL_UINT32(0x00654321, frame_payload_offset);
62+
TEST_ASSERT_EQUAL_UINT32(0x11223344, prefix_crc);
6063
TEST_ASSERT_EQUAL_UINT32(meta_in.transfer_payload_size, meta_out.transfer_payload_size);
6164
TEST_ASSERT_EQUAL_UINT64(meta_in.transfer_id, meta_out.transfer_id);
6265
TEST_ASSERT_EQUAL_UINT64(meta_in.sender_uid, meta_out.sender_uid);
@@ -67,20 +70,23 @@ static void test_header_v2(void)
6770
&flag_eot,
6871
&frame_index,
6972
&frame_payload_offset,
73+
&prefix_crc,
7074
&payload_out));
7175

7276
TEST_ASSERT(header_deserialize((udpard_bytes_mut_t){ .size = sizeof(buffer), .data = buffer },
7377
&meta_out,
7478
&flag_eot,
7579
&frame_index,
7680
&frame_payload_offset,
81+
&prefix_crc,
7782
&payload_out));
7883
buffer[HEADER_SIZE_BYTES - 1] ^= 0xFFU; // Corrupt the CRC.
7984
TEST_ASSERT_FALSE(header_deserialize((udpard_bytes_mut_t){ .size = sizeof(buffer), .data = buffer },
8085
&meta_out,
8186
&flag_eot,
8287
&frame_index,
8388
&frame_payload_offset,
89+
&prefix_crc,
8490
&payload_out));
8591
}
8692

0 commit comments

Comments
 (0)