From 33db71602297092026bb714f8b038ac0e7ac593d Mon Sep 17 00:00:00 2001 From: Paul Fagerburg Date: Fri, 14 Aug 2020 17:20:04 -0600 Subject: usb_pe_drp: new unit test with mocks Add a new unit test for usb_pe_drp with mocks for the various subsystems that it will use. The fake_prl module is already essentially a mock for the PRL layer, so just move it into the mocks directory and make it available as mock to other tests. BUG=b:163421994 BRANCH=None TEST=`make runhosttests` succeeds Signed-off-by: Paul Fagerburg Change-Id: I2aea3fa0694e8d9e6bae1f47516cb4d5d2a1e714 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2364050 Tested-by: Paul Fagerburg Reviewed-by: Jett Rink Commit-Queue: Paul Fagerburg --- test/usb_pe_drp.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/usb_pe_drp.c (limited to 'test/usb_pe_drp.c') diff --git a/test/usb_pe_drp.c b/test/usb_pe_drp.c new file mode 100644 index 0000000000..b210db4ae9 --- /dev/null +++ b/test/usb_pe_drp.c @@ -0,0 +1,56 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Test USB PE module. + */ +#include "common.h" +#include "task.h" +#include "test_util.h" +#include "timer.h" +#include "usb_emsg.h" +#include "usb_mux.h" +#include "usb_pe.h" +#include "usb_pe_sm.h" +#include "usb_sm_checks.h" +#include "mock/usb_tc_sm_mock.h" +#include "mock/tcpc_mock.h" +#include "mock/usb_mux_mock.h" +#include "mock/usb_pd_mock.h" +#include "mock/usb_pd_dpm_mock.h" +#include "mock/dp_alt_mode_mock.h" +#include "mock/usb_prl_mock.h" + +/* Install Mock TCPC and MUX drivers */ +const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { + { + .drv = &mock_tcpc_driver, + }, +}; + +const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = { + { + .driver = &mock_usb_mux_driver, + } +}; + +void before_test(void) +{ + mock_tc_port_reset(); + mock_tcpc_reset(); + mock_usb_mux_reset(); + mock_pd_reset(); + mock_dpm_reset(); + mock_dp_alt_mode_reset(); + mock_prl_reset(); +} + +void run_test(int argc, char **argv) +{ + test_reset(); + + /* Do basic state machine validity checks last. */ + RUN_TEST(test_pe_no_parent_cycles); + + test_print_result(); +} -- cgit v1.2.1