From 419fa128a650ea29306ccbbea08be01037ef454a Mon Sep 17 00:00:00 2001 From: divanchykhin Date: Fri, 3 Apr 2015 10:40:34 +0300 Subject: [PATCH] Emulator actual embodiment: fixes in test generation system; misc fixes --- tests/emulator/sa_client.cpp | 17 +++++++++++------ tests/emulator/sa_server.cpp | 2 +- tests/emulator/sasp_protocol.cpp | 12 +++++++++++- tests/emulator/test-generator.cpp | 16 +++++++++++----- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/tests/emulator/sa_client.cpp b/tests/emulator/sa_client.cpp index 41c2f93..6d0c853 100644 --- a/tests/emulator/sa_client.cpp +++ b/tests/emulator/sa_client.cpp @@ -464,10 +464,12 @@ int main_loop( REQUEST_REPLY_HANDLE mem_h, REQUEST_REPLY_HANDLE mem_h_tmp ) tester_registerOutgoingPacket( mem_h ); /*+*/ bool syncSendReceive; + bool is_packet_to_send = true; if ( tester_holdPacketOnRequest( mem_h ) ) { INCREMENT_COUNTER( 95, "MAIN LOOP, holdPacketOnRequest() called" ); syncSendReceive = false; + is_packet_to_send = false; } else syncSendReceive = tester_get_rand_val() % 4 == 0 && !tester_isOutgoingPacketOnHold(); @@ -489,14 +491,17 @@ int main_loop( REQUEST_REPLY_HANDLE mem_h, REQUEST_REPLY_HANDLE mem_h_tmp ) if ( !tester_shouldDropOutgoingPacket() ) { - ret_code = sendMessage( mem_h ); - zepto_response_to_request( mem_h ); - if (ret_code != COMMLAYER_RET_OK ) + if ( is_packet_to_send ) { - return -1; + ret_code = sendMessage( mem_h ); + zepto_response_to_request( mem_h ); + if (ret_code != COMMLAYER_RET_OK ) + { + return -1; + } + INCREMENT_COUNTER( 82, "MAIN LOOP, packet sent" ); + printf("\nMessage sent to comm peer\n"); } - INCREMENT_COUNTER( 82, "MAIN LOOP, packet sent" ); - printf("\nMessage sent to comm peer\n"); } else { diff --git a/tests/emulator/sa_server.cpp b/tests/emulator/sa_server.cpp index 1c77e8d..e3b5be5 100644 --- a/tests/emulator/sa_server.cpp +++ b/tests/emulator/sa_server.cpp @@ -132,7 +132,7 @@ int main_loop2( REQUEST_REPLY_HANDLE mem_h ) printf("Message from client received\n"); printf( "ret: %d; rq_size: %d, rsp_size: %d\n", ret_code, ugly_hook_get_request_size( mem_h ), ugly_hook_get_response_size( mem_h ) ); -rectosasp: +//rectosasp: // 2. Pass to SASP ret_code = handlerSASP_receive( pid, mem_h, stack, stackSize, data_buff + DADA_OFFSET_SASP ); zepto_response_to_request( mem_h ); diff --git a/tests/emulator/sasp_protocol.cpp b/tests/emulator/sasp_protocol.cpp index cbc1ddf..d4a3ff4 100644 --- a/tests/emulator/sasp_protocol.cpp +++ b/tests/emulator/sasp_protocol.cpp @@ -334,16 +334,26 @@ uint8_t handlerSASP_receive( uint8_t* pid, MEMORY_HANDLE mem_h, uint8_t* stack, // init parser object parser_obj po; zepto_parser_init( &po, mem_h ); + uint16_t packet_size = zepto_parsing_remaining_bytes( &po ); + if ( packet_size == 0 ) + { + return SASP_RET_IGNORE; + } + // zepto_parse_read_block( &po, stack, SASP_NONCE_SIZE ); zepto_parser_decode_uint( &po, stack, SASP_NONCE_SIZE ); bool for_sasp = SASP_NonceIsIntendedForSasp( stack ); + uint16_t debug_rem_b = zepto_parsing_remaining_bytes( &po ); if ( for_sasp ) { PRINTF( "handlerSASP_receive(): for sasp; nonce: %02x %02x %02x %02x %02x %02x\n", stack[0], stack[1], stack[2], stack[3], stack[4], stack[5] ); PRINTF( "handlerSASP_receive(): packet size: %d\n", zepto_parsing_remaining_bytes( &po ) ); - assert( zepto_parsing_remaining_bytes( &po ) == 2 * SASP_ENC_BLOCK_SIZE ); } bool ipaad = SASP_IntraPacketAuthenticateAndDecrypt( pid, mem_h, stack + SASP_NONCE_SIZE, stackSize ); + if ( ipaad && for_sasp ) + { + assert( debug_rem_b == 2 * SASP_ENC_BLOCK_SIZE ); + } PRINTF( "handlerSASP_receive(): PID: %02x %02x %02x %02x %02x %02x\n", pid[0], pid[1], pid[2], pid[3], pid[4], pid[5] ); if ( !ipaad ) diff --git a/tests/emulator/test-generator.cpp b/tests/emulator/test-generator.cpp index 5d26f99..75d832a 100644 --- a/tests/emulator/test-generator.cpp +++ b/tests/emulator/test-generator.cpp @@ -95,7 +95,7 @@ bool tester_shouldInsertOutgoingPacket( REQUEST_REPLY_HANDLE mem_h ) bool tester_holdOutgoingPacket( REQUEST_REPLY_HANDLE mem_h ) { - return false; +// return false; uint8_t buff[ PACKET_MAX_SIZE ]; uint16_t packet_size; // init parser object @@ -104,12 +104,15 @@ bool tester_holdOutgoingPacket( REQUEST_REPLY_HANDLE mem_h ) packet_size = zepto_parsing_remaining_bytes( &po ); assert( packet_size <= PACKET_MAX_SIZE ); zepto_parse_read_block( &po, buff, packet_size ); - return tester_holdOutgoingPacket( buff, &packet_size ); + bool ret = tester_holdOutgoingPacket( buff, &packet_size ); + if ( ret ) + zepto_response_to_request( mem_h ); + return ret; } bool tester_releaseOutgoingPacket( REQUEST_REPLY_HANDLE mem_h ) { - return false; +// return false; uint8_t buff[ PACKET_MAX_SIZE ]; uint16_t packet_size; bool ret = tester_releaseOutgoingPacket( buff, &packet_size ); @@ -121,7 +124,7 @@ bool tester_releaseOutgoingPacket( REQUEST_REPLY_HANDLE mem_h ) bool tester_holdPacketOnRequest( REQUEST_REPLY_HANDLE mem_h ) { - return false; +// return false; uint8_t buff[ PACKET_MAX_SIZE ]; uint16_t packet_size; // init parser object @@ -131,7 +134,10 @@ bool tester_holdPacketOnRequest( REQUEST_REPLY_HANDLE mem_h ) assert( packet_size <= PACKET_MAX_SIZE ); zepto_parse_read_block( &po, buff, packet_size ); // return tester_holdOutgoingPacket( buff, &packet_size ); - return tester_holdPacketOnRequest( buff, &packet_size ); + bool ret = tester_holdPacketOnRequest( buff, &packet_size ); + if ( ret ) + zepto_response_to_request( mem_h ); + return ret; }