diff options
author | Bill Richardson <wfrichar@chromium.org> | 2014-04-08 17:42:37 -0700 |
---|---|---|
committer | Bill Richardson <wfrichar@chromium.org> | 2014-04-11 15:37:53 +0000 |
commit | 9814e54204185398ff62bdf7a1a18ceb972021bc (patch) | |
tree | f27fc811ad15cde47ae521acd3275004bc133808 /board/host | |
parent | 5019551e1d63bdd95e8b358a409e923c16e604fd (diff) | |
download | chrome-ec-9814e54204185398ff62bdf7a1a18ceb972021bc.tar.gz |
Increase test coverage of charge_state_v2.c
This improves some of the smart battery mocks, and adds some more tests for
the new change state machine.
BUG=chrome-os-partner:20881
BRANCH=ToT
TEST=make coverage
Line coverage of this file jumps from 53% to 93%.
Change-Id: I4a9b8818cefaffd3022cebe08a36d592b0611295
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/193690
Diffstat (limited to 'board/host')
-rw-r--r-- | board/host/battery.c | 1 | ||||
-rw-r--r-- | board/host/charger.c | 26 |
2 files changed, 22 insertions, 5 deletions
diff --git a/board/host/battery.c b/board/host/battery.c index 85173f8378..a5c447f5d7 100644 --- a/board/host/battery.c +++ b/board/host/battery.c @@ -45,6 +45,7 @@ int sb_i2c_read_string(int port, int slave_addr, int offset, uint8_t *data, { return EC_SUCCESS; } +DECLARE_TEST_I2C_READ_STRING(sb_i2c_read_string); int battery_time_at_rate(int rate, int *minutes) { diff --git a/board/host/charger.c b/board/host/charger.c index 0e72fe8fb4..0ec8ab605c 100644 --- a/board/host/charger.c +++ b/board/host/charger.c @@ -27,8 +27,10 @@ static const struct charger_info mock_charger_info = { #define OPTION_CHARGE_INHIBIT (1 << 0) static uint32_t mock_option; +static uint32_t mock_mode; static uint32_t mock_current; static uint32_t mock_voltage; +static uint32_t mock_input_current; const struct charger_info *charger_get_info(void) { @@ -39,7 +41,7 @@ const struct charger_info *charger_get_info(void) int charger_get_status(int *status) { *status = CHARGER_LEVEL_2; - if (mock_option & CHARGE_FLAG_INHIBIT_CHARGE) + if (mock_mode & CHARGE_FLAG_INHIBIT_CHARGE) *status |= CHARGER_CHARGE_INHIBITED; return EC_SUCCESS; @@ -49,9 +51,9 @@ int charger_get_status(int *status) int charger_set_mode(int mode) { if (mode & CHARGE_FLAG_INHIBIT_CHARGE) - mock_option |= OPTION_CHARGE_INHIBIT; + mock_mode |= OPTION_CHARGE_INHIBIT; else - mock_option &= ~OPTION_CHARGE_INHIBIT; + mock_mode &= ~OPTION_CHARGE_INHIBIT; return EC_SUCCESS; } @@ -95,12 +97,14 @@ int charger_set_voltage(int voltage) int charger_get_option(int *option) { + *option = mock_option; return EC_SUCCESS; } int charger_set_option(int option) { + mock_option = option; return EC_SUCCESS; } @@ -119,18 +123,30 @@ int charger_device_id(int *id) int charger_get_input_current(int *input_current) { + *input_current = mock_input_current; return EC_SUCCESS; } -int charger_set_input_current(int input_current) +int charger_set_input_current(int current) { + const struct charger_info *info = charger_get_info(); + + if (current < info->input_current_min) + current = info->input_current_min; + if (current > info->input_current_max) + current = info->input_current_max; + + if (mock_input_current != current) + ccprintf("Charger set input current: %d\n", current); + + mock_input_current = current; return EC_SUCCESS; } int charger_post_init(void) { - mock_current = CONFIG_CHARGER_INPUT_CURRENT; + mock_current = mock_input_current = CONFIG_CHARGER_INPUT_CURRENT; return EC_SUCCESS; } |