diff options
author | Abe Levkoy <alevkoy@chromium.org> | 2021-01-15 12:09:13 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-22 00:01:49 +0000 |
commit | ea4a53732db48588bb77f853e574d52b0b70a528 (patch) | |
tree | 7f4bd7d89bb77b117d96e7f908d9ff2cfb6cb331 | |
parent | cc65a4bc8a1a39cd884878e3d57e1325493895b7 (diff) | |
download | chrome-ec-ea4a53732db48588bb77f853e574d52b0b70a528.tar.gz |
charge_manager: Create mock
Allow tests to use a mock charge_manager. Do not build the real charge
manager when this is used.
BUG=b:173023378,b:169385081,b:172709198,b:173028832,b:173028791
BUG=b:173141941,b:173142113
TEST=make buildall
BRANCH=none
Signed-off-by: Abe Levkoy <alevkoy@chromium.org>
Change-Id: I49caccafd024515833880d7251092b77623d4a71
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2639584
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r-- | common/build.mk | 2 | ||||
-rw-r--r-- | common/charge_manager.c | 4 | ||||
-rw-r--r-- | common/mock/build.mk | 1 | ||||
-rw-r--r-- | common/mock/charge_manager_mock.c | 45 | ||||
-rw-r--r-- | common/mock/usb_tc_sm_mock.c | 5 | ||||
-rw-r--r-- | include/mock/charge_manager_mock.h | 27 |
6 files changed, 84 insertions, 0 deletions
diff --git a/common/build.mk b/common/build.mk index 1acc35347b..c4ee00836c 100644 --- a/common/build.mk +++ b/common/build.mk @@ -48,7 +48,9 @@ common-$(CONFIG_BODY_DETECTION)+=body_detection.o common-$(CONFIG_CAPSENSE)+=capsense.o common-$(CONFIG_CEC)+=cec.o common-$(CONFIG_CROS_BOARD_INFO)+=cbi.o +ifeq ($(HAS_MOCK_CHARGE_MANAGER),) common-$(CONFIG_CHARGE_MANAGER)+=charge_manager.o +endif common-$(CONFIG_CHARGE_RAMP_HW)+=charge_ramp.o common-$(CONFIG_CHARGE_RAMP_SW)+=charge_ramp.o charge_ramp_sw.o common-$(CONFIG_CMD_CHARGEN) += chargen.o diff --git a/common/charge_manager.c b/common/charge_manager.c index b831b8ba38..e5256b4b26 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -21,6 +21,10 @@ #include "usb_pd_tcpm.h" #include "util.h" +#ifdef HAS_MOCK_CHARGE_MANAGER +#error Mock defined HAS_MOCK_CHARGE_MANAGER +#endif + #define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) #define POWER(charge_port) ((charge_port.current) * (charge_port.voltage)) diff --git a/common/mock/build.mk b/common/mock/build.mk index bacf52069b..91607b2b1e 100644 --- a/common/mock/build.mk +++ b/common/mock/build.mk @@ -5,6 +5,7 @@ # See common/mock/README.md for more information. mock-$(HAS_MOCK_BATTERY) += battery_mock.o +mock-$(HAS_MOCK_CHARGE_MANAGER) += charge_manager_mock.o mock-$(HAS_MOCK_FP_SENSOR) += fp_sensor_mock.o mock-$(HAS_MOCK_FPSENSOR_DETECT) += fpsensor_detect_mock.o mock-$(HAS_MOCK_FPSENSOR_STATE) += fpsensor_state_mock.o diff --git a/common/mock/charge_manager_mock.c b/common/mock/charge_manager_mock.c new file mode 100644 index 0000000000..a61552240f --- /dev/null +++ b/common/mock/charge_manager_mock.c @@ -0,0 +1,45 @@ +/* Copyright 2021 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. + */ + +/** + * @file + * @brief Mock charge_manager + */ + +#include <stdlib.h> + +#include "charge_manager.h" +#include "common.h" +#include "mock/charge_manager_mock.h" + +#ifndef TEST_BUILD +#error "Mocks should only be in the test build." +#endif + +void charge_manager_update_dualrole(int port, enum dualrole_capabilities cap) +{ +} + +void charge_manager_set_ceil(int port, enum ceil_requestor requestor, int ceil) +{ +} + +int charge_manager_get_selected_charge_port(void) +{ + return 0; +} + +int charge_manager_get_vbus_voltage(int port) +{ + return mock_ctrl_charge_manager.vbus_voltage_mv; +} + +void mock_charge_manager_set_vbus_voltage(int voltage_mv) +{ + mock_ctrl_charge_manager.vbus_voltage_mv = voltage_mv; +} + +struct mock_ctrl_charge_manager mock_ctrl_charge_manager = +MOCK_CTRL_DEFAULT_CHARGE_MANAGER; diff --git a/common/mock/usb_tc_sm_mock.c b/common/mock/usb_tc_sm_mock.c index 71609cb2b2..cb866a9268 100644 --- a/common/mock/usb_tc_sm_mock.c +++ b/common/mock/usb_tc_sm_mock.c @@ -167,6 +167,11 @@ bool pd_get_partner_usb_comm_capable(int port) return true; } +bool pd_get_partner_dual_role_power(int port) +{ + return true; +} + void pd_set_suspend(int port, int suspend) { } diff --git a/include/mock/charge_manager_mock.h b/include/mock/charge_manager_mock.h new file mode 100644 index 0000000000..8a791f6121 --- /dev/null +++ b/include/mock/charge_manager_mock.h @@ -0,0 +1,27 @@ +/* Copyright 2021 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. + */ + +/** + * @file + * @brief Controls for the mock charge_manager + */ + +#ifndef __MOCK_CHARGE_MANAGER_MOCK_H +#define __MOCK_CHARGE_MANAGER_MOCK_H + +struct mock_ctrl_charge_manager { + int vbus_voltage_mv; +}; + +#define MOCK_CTRL_DEFAULT_CHARGE_MANAGER \ + ((struct mock_ctrl_charge_manager) { \ + .vbus_voltage_mv = 0, \ + }) + +extern struct mock_ctrl_charge_manager mock_ctrl_charge_manager; + +void mock_charge_manager_set_vbus_voltage(int voltage_mv); + +#endif /* __MOCK_CHARGE_MANAGER_MOCK_H */ |