diff options
author | Denis Brockus <dbrockus@google.com> | 2021-01-06 10:52:29 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-07 21:14:16 +0000 |
commit | fd9de64cdfd14943110cde1ac69c1f5542acccd1 (patch) | |
tree | f189873895b15e62ddff4f3dd801581f7f2372cc /common/mock | |
parent | 9759b382b2ce0900c5dd20ad351b213a2c786897 (diff) | |
download | chrome-ec-fd9de64cdfd14943110cde1ac69c1f5542acccd1.tar.gz |
TCPMv2: Compliance Unit Test - TD.PD.SRC3.E7
BUG=none
BRANCH=none
TEST=make buildall
Signed-off-by: Denis Brockus <dbrockus@google.com>
Change-Id: Iaa6888d2e0d861d64b2747856465789304dde414
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2613724
Tested-by: Denis Brockus <dbrockus@chromium.org>
Auto-Submit: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Edward Hill <ecgh@chromium.org>
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'common/mock')
-rw-r--r-- | common/mock/tcpci_i2c_mock.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/common/mock/tcpci_i2c_mock.c b/common/mock/tcpci_i2c_mock.c index 7cf213533c..e3c3b63675 100644 --- a/common/mock/tcpci_i2c_mock.c +++ b/common/mock/tcpci_i2c_mock.c @@ -282,6 +282,80 @@ int verify_tcpci_tx_with_data(enum tcpm_transmit_type tx_type, } return rv; } + +int verify_tcpci_possible_tx(struct possible_tx possible[], + int possible_cnt, + int *found_index, + uint8_t *data, + int data_bytes, + int *msg_len, + int timeout) +{ + uint64_t end_time; + + *found_index = -1; + + if (timeout <= 0) + timeout = VERIFY_TIMEOUT; + end_time = get_time().val + timeout; + + /* + * Check that nothing was already transmitted. This ensures that all + * transmits are checked, and the test stays in sync with the code + * being tested. + */ + TEST_EQ(tcpci_regs[TCPC_REG_TRANSMIT].value, 0, "%d"); + + /* Now wait for the expected message to be transmitted. */ + while (get_time().val < end_time) { + if (tcpci_regs[TCPC_REG_TRANSMIT].value != 0) { + int i; + int tx_type = TCPC_REG_TRANSMIT_TYPE( + tcpci_regs[TCPC_REG_TRANSMIT].value); + uint16_t header = UINT16_FROM_BYTE_ARRAY_LE( + tx_buffer, 1); + int pd_type = PD_HEADER_TYPE(header); + int pd_cnt = PD_HEADER_CNT(header); + + for (i = 0; i < possible_cnt; ++i) { + int want_tx_type = possible[i].tx_type; + int want_ctrl_msg = possible[i].ctrl_msg; + int want_data_msg = possible[i].data_msg; + + if (tx_type != want_tx_type) + continue; + + if (want_ctrl_msg != 0) { + if (pd_type != want_ctrl_msg || + pd_cnt != 0) + continue; + } + if (want_data_msg != 0) { + if (pd_type != want_data_msg || + pd_cnt == 0) + continue; + + if (data != NULL) { + TEST_GE(data_bytes, + tx_msg_cnt, "%d"); + memcpy(data, tx_buffer, + tx_msg_cnt); + } + if (msg_len != NULL) + *msg_len = tx_msg_cnt; + } + *found_index = i; + tcpci_regs[TCPC_REG_TRANSMIT].value = 0; + return EC_SUCCESS; + } + break; + } + task_wait_event(5 * MSEC); + } + TEST_ASSERT(0); + return EC_ERROR_UNKNOWN; +} + void mock_tcpci_receive(enum pd_msg_type sop, uint16_t header, uint32_t *payload) { |