Skip to content

Commit

Permalink
add tests for USER_CMD error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
lmbsog0 committed Jul 22, 2022
1 parent eb3ce13 commit 1fff745
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/asam_error_matrix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,68 @@ def test_transport_layer_cmd_err_out_of_range(self, payload):
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info(payload))
handle.lib.Xcp_MainFunction()
assert tuple(handle.can_if_transmit.call_args[0][1].SduDataPtr[0:2]) == (0xFE, 0x22)


class TestUserCmdErrorHandling:
"""
Command Error Pre-Action Action
USER_CMD timeout t1 SYNCH repeat 2 times
USER_CMD ERR_CMD_BUSY wait t7 repeat ∞ times
USER_CMD ERR_PGM_ACTIVE wait t7 repeat ∞ times
USER_CMD ERR_CMD_SYNTAX - retry other syntax
USER_CMD ERR_OUT_OF_RANGE - retry other parameter
"""

def test_user_cmd_err_cmd_busy(self):
handle = XcpTest(DefaultConfig(channel_rx_pdu_ref=0x0001))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xFF, 0x00)))
handle.lib.Xcp_MainFunction()
handle.lib.Xcp_CanIfTxConfirmation(0x0001, handle.define('E_OK'))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xFD,)))
handle.lib.Xcp_MainFunction()
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xF1, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00)))
handle.lib.Xcp_MainFunction()
assert tuple(handle.can_if_transmit.call_args[0][1].SduDataPtr[0:2]) == (0xFE, 0x10)

@pytest.mark.parametrize('mode_bit', (0b00000001, 0b00000100, 0b00001000))
def test_user_cmd_err_pgm_active(self, mode_bit):
handle = XcpTest(DefaultConfig(channel_rx_pdu_ref=0x0001))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xFF, 0x00)))
handle.lib.Xcp_MainFunction()
handle.lib.Xcp_CanIfTxConfirmation(0x0001, handle.define('E_OK'))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xF9, mode_bit, 0x00, 0x00)))
handle.lib.Xcp_MainFunction()
handle.lib.Xcp_CanIfTxConfirmation(0x0001, handle.define('E_OK'))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xF1, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00)))
handle.lib.Xcp_MainFunction()
assert tuple(handle.can_if_transmit.call_args[0][1].SduDataPtr[0:2]) == (0xFE, 0x12)

@pytest.mark.parametrize('payload', ((0xF1,), (0xF1, 0xFF)))
def test_user_cmd_err_cmd_syntax(self, payload):
handle = XcpTest(DefaultConfig(channel_rx_pdu_ref=0x0001))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xFF, 0x00)))
handle.lib.Xcp_MainFunction()
handle.lib.Xcp_CanIfTxConfirmation(0x0001, handle.define('E_OK'))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info(payload))
handle.lib.Xcp_MainFunction()
assert tuple(handle.can_if_transmit.call_args[0][1].SduDataPtr[0:2]) == (0xFE, 0x21)

@pytest.mark.parametrize('response_payload', ((0xFE, 0x22),))
def test_user_cmd_err_out_of_range(self, response_payload):
handle = XcpTest(DefaultConfig(channel_rx_pdu_ref=0x0001, user_cmd_function='Xcp_UserCmdFunction'))

def xcp_user_cmd_function(_p_cmd_pdu_info, p_res_err_pdu_info):
p_res_err_pdu_info[0].SduLength = 2
for i in range(len(response_payload)):
p_res_err_pdu_info[0].SduDataPtr[i] = response_payload[i]
return handle.define('E_OK')

handle.xcp_user_cmd_function.side_effect = xcp_user_cmd_function

handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xFF, 0x00)))
handle.lib.Xcp_MainFunction()
handle.lib.Xcp_CanIfTxConfirmation(0x0001, handle.define('E_OK'))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xF1, 0x00, 0x00)))
handle.lib.Xcp_MainFunction()
handle.lib.Xcp_CanIfTxConfirmation(0x0001, handle.define('E_OK'))
assert tuple(handle.can_if_transmit.call_args[0][1].SduDataPtr[0:2]) == (0xFE, 0x22)

0 comments on commit 1fff745

Please sign in to comment.