Skip to content

Commit

Permalink
Emulator actual embodiment: fixes in test generation system; misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
divanchykhin committed Apr 3, 2015
1 parent 630880d commit 419fa12
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
17 changes: 11 additions & 6 deletions tests/emulator/sa_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion tests/emulator/sa_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
12 changes: 11 additions & 1 deletion tests/emulator/sasp_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
16 changes: 11 additions & 5 deletions tests/emulator/test-generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );
Expand All @@ -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
Expand All @@ -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;
}


Expand Down

0 comments on commit 419fa12

Please sign in to comment.