diff options
author | Edward Hill <ecgh@chromium.org> | 2020-11-29 16:12:59 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-12-01 18:19:40 +0000 |
commit | 725de7c47295adf7bc6a770c9867e4d413d1fafd (patch) | |
tree | 74ae39f6d337f994dabca14e4b6a2741dd2f5748 /common | |
parent | a2390f3c505a4684535c08da27736099a63850fe (diff) | |
download | chrome-ec-725de7c47295adf7bc6a770c9867e4d413d1fafd.tar.gz |
test: Improve test_send_caps_error in usb_pe_drp
Better mock tx and rx messages, add sop type.
BUG=b:161835483 b:173791979
BRANCH=none
TEST=make run-usb_pe_drp
Signed-off-by: Edward Hill <ecgh@chromium.org>
Change-Id: If1f91b6385d6841d662a8a6262af6382645da92e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2553343
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/mock/usb_prl_mock.c | 90 |
1 files changed, 63 insertions, 27 deletions
diff --git a/common/mock/usb_prl_mock.c b/common/mock/usb_prl_mock.c index 75c0976362..cb4b035ff4 100644 --- a/common/mock/usb_prl_mock.c +++ b/common/mock/usb_prl_mock.c @@ -2,7 +2,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * - * Fake Protocol Layer module. + * Mock Protocol Layer module. */ #include <string.h> #include "common.h" @@ -10,6 +10,9 @@ #include "usb_pe_sm.h" #include "usb_prl_sm.h" #include "mock/usb_prl_mock.h" +#include "task.h" +#include "test_util.h" +#include "timer.h" #ifndef TEST_BUILD #error "Mocks should only be in the test build." @@ -21,10 +24,12 @@ struct extended_msg tx_emsg[CONFIG_USB_PD_PORT_MAX_COUNT]; struct mock_prl_port_t { enum pd_ctrl_msg_type last_ctrl_msg; - enum pd_data_msg_type last_data_msg_type; + enum pd_data_msg_type last_data_msg; + enum tcpm_transmit_type last_tx_type; bool message_sent; bool message_received; - int pe_error; + enum pe_error error; + enum tcpm_transmit_type error_tx_type; }; struct mock_prl_port_t mock_prl_port[CONFIG_USB_PD_PORT_MAX_COUNT]; @@ -39,8 +44,10 @@ void mock_prl_reset(void) memset(mock_prl_port, 0, sizeof(mock_prl_port)); - for (port = 0 ; port < CONFIG_USB_PD_PORT_MAX_COUNT ; ++port) - mock_prl_port[port].pe_error = -1; + for (port = 0 ; port < CONFIG_USB_PD_PORT_MAX_COUNT ; ++port) { + mock_prl_port[port].last_tx_type = TCPC_TX_INVALID; + mock_prl_port[port].error_tx_type = TCPC_TX_INVALID; + } } void prl_end_ams(int port) @@ -77,12 +84,16 @@ void prl_send_ctrl_msg(int port, enum tcpm_transmit_type type, enum pd_ctrl_msg_type msg) { mock_prl_port[port].last_ctrl_msg = msg; + mock_prl_port[port].last_data_msg = 0; + mock_prl_port[port].last_tx_type = type; } void prl_send_data_msg(int port, enum tcpm_transmit_type type, enum pd_data_msg_type msg) { - mock_prl_port[port].last_data_msg_type = msg; + mock_prl_port[port].last_data_msg = msg; + mock_prl_port[port].last_ctrl_msg = 0; + mock_prl_port[port].last_tx_type = type; } void prl_send_ext_data_msg(int port, enum tcpm_transmit_type type, @@ -94,45 +105,69 @@ void prl_set_rev(int port, enum tcpm_transmit_type partner, {} -enum pd_ctrl_msg_type fake_prl_get_last_sent_ctrl_msg(int port) +int mock_prl_wait_for_tx_msg(int port, + enum tcpm_transmit_type tx_type, + enum pd_ctrl_msg_type ctrl_msg, + enum pd_data_msg_type data_msg, + int timeout) { - enum pd_ctrl_msg_type last = mock_prl_port[port].last_ctrl_msg; - - fake_prl_clear_last_sent_ctrl_msg(port); - return last; + uint64_t end_time = get_time().val + timeout; + + while (get_time().val < end_time) { + if (mock_prl_port[port].last_tx_type != TCPC_TX_INVALID) { + TEST_EQ(mock_prl_port[port].last_tx_type, + tx_type, "%d"); + TEST_EQ(mock_prl_port[port].last_ctrl_msg, + ctrl_msg, "%d"); + TEST_EQ(mock_prl_port[port].last_data_msg, + data_msg, "%d"); + mock_prl_clear_last_sent_msg(port); + return EC_SUCCESS; + } + task_wait_event(5 * MSEC); + } + TEST_ASSERT(0); + return EC_ERROR_UNKNOWN; } -void fake_prl_clear_last_sent_ctrl_msg(int port) +enum pd_ctrl_msg_type mock_prl_get_last_sent_ctrl_msg(int port) { - mock_prl_port[port].last_ctrl_msg = 0; + enum pd_ctrl_msg_type last = mock_prl_port[port].last_ctrl_msg; + + mock_prl_clear_last_sent_msg(port); + return last; } -enum pd_data_msg_type fake_prl_get_last_sent_data_msg_type(int port) +enum pd_data_msg_type mock_prl_get_last_sent_data_msg(int port) { - enum pd_data_msg_type last = mock_prl_port[port].last_data_msg_type; + enum pd_data_msg_type last = mock_prl_port[port].last_data_msg; - fake_prl_clear_last_sent_data_msg(port); + mock_prl_clear_last_sent_msg(port); return last; } -void fake_prl_clear_last_sent_data_msg(int port) +void mock_prl_clear_last_sent_msg(int port) { - mock_prl_port[port].last_data_msg_type = 0; + mock_prl_port[port].last_data_msg = 0; + mock_prl_port[port].last_ctrl_msg = 0; + mock_prl_port[port].last_tx_type = TCPC_TX_INVALID; } -void fake_prl_message_sent(int port) +void mock_prl_message_sent(int port) { mock_prl_port[port].message_sent = 1; } -void fake_prl_message_received(int port) +void mock_prl_message_received(int port) { mock_prl_port[port].message_received = 1; } -void fake_prl_report_error(int port, enum pe_error e) +void mock_prl_report_error(int port, enum pe_error e, + enum tcpm_transmit_type tx_type) { - mock_prl_port[port].pe_error = e; + mock_prl_port[port].error = e; + mock_prl_port[port].error_tx_type = tx_type; } void prl_run(int port, int evt, int en) @@ -147,11 +182,12 @@ void prl_run(int port, int evt, int en) pe_message_received(port); mock_prl_port[port].message_received = 0; } - if (mock_prl_port[port].pe_error >= 0) { - ccprints("pe_error %d", mock_prl_port[port].pe_error); + if (mock_prl_port[port].error_tx_type != TCPC_TX_INVALID) { + ccprints("pe_error %d", mock_prl_port[port].error); pe_report_error(port, - mock_prl_port[port].pe_error, - TCPC_TX_SOP); - mock_prl_port[port].pe_error = -1; + mock_prl_port[port].error, + mock_prl_port[port].error_tx_type); + mock_prl_port[port].error = 0; + mock_prl_port[port].error_tx_type = TCPC_TX_INVALID; } } |