test_connection: check empty queue handling and empty packets
This commit is contained in:
parent
56742ef811
commit
399df50413
2 changed files with 72 additions and 4 deletions
|
|
@ -72,7 +72,9 @@ int main(void)
|
|||
ASSERT_RESULT(OK, connection_init(&conn, &dut_address, &peer_address));
|
||||
ASSERT_STATE(expected_state, conn);
|
||||
|
||||
LOG(LVL_INFO, "connection_setup_outgoing() must change state to CONNECTING.");
|
||||
//-----------------//
|
||||
|
||||
LOG(LVL_INFO, ">>> connection_setup_outgoing() must change state to CONNECTING.");
|
||||
|
||||
connection_setup_outgoing(&conn);
|
||||
|
||||
|
|
@ -80,7 +82,9 @@ int main(void)
|
|||
|
||||
ASSERT_STATE(expected_state, conn);
|
||||
|
||||
LOG(LVL_INFO, "Empty packet in init state must not change the connection state.");
|
||||
//-----------------//
|
||||
|
||||
LOG(LVL_INFO, ">>> Empty packet in init state must not change the connection state.");
|
||||
|
||||
layer2_packet_header_t header;
|
||||
|
||||
|
|
@ -101,7 +105,9 @@ int main(void)
|
|||
ASSERT_RESULT(ERR_INVALID_STATE, connection_handle_packet(&conn, packet_buf, packet_len, &data_packet, &tx_req_rcvd));
|
||||
ASSERT_STATE(expected_state, conn);
|
||||
|
||||
LOG(LVL_INFO, "Beacon must trigger Connection Request.");
|
||||
//-----------------//
|
||||
|
||||
LOG(LVL_INFO, ">>> Beacon must trigger Connection Request.");
|
||||
|
||||
ham64_t broadcast = {{0xFFFF, 0, 0, 0}, 1};
|
||||
|
||||
|
|
@ -120,7 +126,9 @@ int main(void)
|
|||
ASSERT_STATE(expected_state, conn);
|
||||
|
||||
ASSERT_TRUE(connection_can_transmit(&conn));
|
||||
ASSERT_EQUAL_UINT(1, packet_queue_get_used_space(&conn.packet_queue));
|
||||
|
||||
// connection request is not written to the packet queue
|
||||
ASSERT_EQUAL_UINT(0, packet_queue_get_used_space(&conn.packet_queue));
|
||||
|
||||
bool end_burst;
|
||||
packet_len = connection_encode_next_packet(&conn,
|
||||
|
|
@ -156,4 +164,62 @@ int main(void)
|
|||
|
||||
// check the connection request type
|
||||
ASSERT_EQUAL_UINT(CONN_MGMT_TYPE_CONNECTION_REQUEST, packet_buf[header_size]);
|
||||
|
||||
LOG(LVL_INFO, "Connection request received.");
|
||||
|
||||
//-----------------//
|
||||
|
||||
LOG(LVL_INFO, ">>> Sending Connection Parameters, which must switch the state to CONNECTED.");
|
||||
|
||||
// build connection parameters packet
|
||||
header.dst_addr = dut_address;
|
||||
header.src_addr = peer_address;
|
||||
header.msg_type = L2_MSG_TYPE_CONN_MGMT;
|
||||
header.rx_seq_nr = 0;
|
||||
header.tx_seq_nr = 0;
|
||||
header.tx_request = 1;
|
||||
|
||||
static_payload[0] = CONN_MGMT_TYPE_CONNECTION_PARAMETERS;
|
||||
|
||||
packet_len = layer2_encode_packet(&header, static_payload, 1, packet_buf, sizeof(packet_buf));
|
||||
ASSERT_EQUAL_UINT(13, packet_len);
|
||||
|
||||
ASSERT_RESULT(OK, connection_handle_packet(&conn, packet_buf, packet_len, &data_packet, &tx_req_rcvd));
|
||||
|
||||
// after the connection was accepted, the connection must switch to established state.
|
||||
|
||||
expected_state.conn_state = CONN_STATE_ESTABLISHED;
|
||||
expected_state.next_expected_seq = 1;
|
||||
|
||||
ASSERT_STATE(expected_state, conn);
|
||||
|
||||
//-----------------//
|
||||
|
||||
LOG(LVL_INFO, ">>> Empty queue must not produce a packet when connection_encode_next_packet() is called.");
|
||||
|
||||
ASSERT_FALSE(connection_can_transmit(&conn));
|
||||
|
||||
packet_len = connection_encode_next_packet(&conn,
|
||||
packet_buf, sizeof(packet_buf), &end_burst);
|
||||
|
||||
ASSERT_EQUAL_UINT(0, packet_len);
|
||||
|
||||
LOG(LVL_INFO, ">>> It must be possible to generate an empty packet in CONNECTED state with empty queue.");
|
||||
|
||||
packet_len = connection_encode_empty_packet(&conn, true, packet_buf, sizeof(packet_buf));
|
||||
ASSERT_EQUAL_UINT(12, packet_len);
|
||||
|
||||
// check consistency of the empty packet
|
||||
crc_ok = crc_check_key(PAYLOAD_CRC_SCHEME, (unsigned char*)packet_buf, packet_len - crc_size);
|
||||
ASSERT_TRUE(crc_ok);
|
||||
|
||||
// check that the header can be decoded and check the message type
|
||||
memset(&header, 0, sizeof(header));
|
||||
header_decoded_ok = layer2_decode_packet_header(packet_buf, packet_len, &header);
|
||||
|
||||
LOG(LVL_DUMP, "Header of supposed empty packet:");
|
||||
layer2_dump_packet_header(LVL_DUMP, &header);
|
||||
|
||||
ASSERT_TRUE(header_decoded_ok);
|
||||
ASSERT_EQUAL_UINT(L2_MSG_TYPE_EMPTY, header.msg_type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
} \
|
||||
}
|
||||
|
||||
#define ASSERT_FALSE(call) ASSERT_TRUE(!call)
|
||||
|
||||
#define ASSERT_EQUAL_INT(expected, call) { \
|
||||
int64_t result = (int64_t)call; \
|
||||
if(result != expected) { \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue