test_connection: add regression test for 1-byte packet handling
All checks were successful
/ build-hamnet70 (push) Successful in 40s
/ build-doc (push) Successful in 23s
/ deploy-doc (push) Has been skipped

This commit is contained in:
Thomas Kolb 2025-11-01 17:51:37 +01:00
commit aedb139e38

View file

@ -388,6 +388,8 @@ int main(void)
ASSERT_STATE(expected_state, conn);
// reset the transmitter
LOG(LVL_INFO, ">>> Transmitter restart test");
connection_restart_tx(&conn);
expected_state.next_packet_index = 0;
@ -421,6 +423,8 @@ int main(void)
ASSERT_EQUAL_UINT(7, payload[1]);
// enqueue 10 more packets to test the sequence number overflow.
LOG(LVL_INFO, ">>> Testing sequence number overflow");
for(size_t i = 0; i < 10; i++) {
payload_len = 201;
static_payload[0] = i;
@ -463,7 +467,7 @@ int main(void)
ASSERT_STATE(expected_state, conn);
LOG(LVL_INFO, "Queue overflow test:");
LOG(LVL_INFO, ">>> Queue overflow test:");
// nothing has been acknowledged so far, so we have 11 packets in the queue.
// It must be possible to add 4 more packets, but the 5th must fail.
@ -506,6 +510,20 @@ int main(void)
ASSERT_STATE(expected_state, conn);
// Regression test: in the past, the program crashed if a packet with 1
// byte was decoded and passed to the connection instance. This can only
// happen due to decoder errors, because valid packets must contain at
// least the CRC which is 2 bytes large already.
LOG(LVL_INFO, ">>> Regression test: 1-byte packets must be handled correctly.");
// build corrupted packet
packet_buf[0] = 0x23;
packet_len = 1;
result_t result = connection_handle_packet(&conn, packet_buf, packet_len, &data_packet, &tx_req_rcvd);
ASSERT_RESULT(ERR_INTEGRITY, result);
// TODO: test connection close sequence
LOG(LVL_INFO, ">>> All assertions successful.");