diff options
author | Vic Yang <victoryang@chromium.org> | 2013-09-16 14:50:11 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-09-17 03:22:15 +0000 |
commit | 1b66740546799fd9d6df4a34fc4182f5749cc505 (patch) | |
tree | bf2306c165a5f6f1b8b7ce80c3407cf1fac82ff0 /common | |
parent | d5e183f9e56d9e623885b163d9b71203d04880cf (diff) | |
download | chrome-ec-1b66740546799fd9d6df4a34fc4182f5749cc505.tar.gz |
Mock smart battery at lower level
Instead of mocking it at sb_read()/sb_write() level, let's mock them at
I2C transaction level so as to increase test coverage of smart battery
driver.
BUG=chrome-os-partner:19236
TEST=Pass sbs_charging test.
BRANCH=None
Change-Id: I9bcd69517b084ea598c7b074a40143338e6150fe
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/169512
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/mock_smart_battery.c | 41 | ||||
-rw-r--r-- | common/smart_battery.c | 4 |
2 files changed, 19 insertions, 26 deletions
diff --git a/common/mock_smart_battery.c b/common/mock_smart_battery.c index 98112c3ec0..0620de6e39 100644 --- a/common/mock_smart_battery.c +++ b/common/mock_smart_battery.c @@ -10,42 +10,40 @@ #include "console.h" #include "smart_battery.h" #include "smart_battery_stub.h" +#include "test_util.h" #include "uart.h" #include "util.h" static uint16_t mock_smart_battery[SB_MANUFACTURER_DATA + 1]; -int sb_read(int cmd, int *param) +int sb_i2c_read16(int port, int slave_addr, int offset, int *data) { - if (cmd >= ARRAY_SIZE(mock_smart_battery)) + if (port != I2C_PORT_BATTERY || slave_addr != BATTERY_ADDR) + return EC_ERROR_INVAL; + if (offset >= ARRAY_SIZE(mock_smart_battery)) return EC_ERROR_UNIMPLEMENTED; - if (cmd < 0 || param == NULL) + if (offset < 0 || data == NULL) return EC_ERROR_INVAL; - *param = mock_smart_battery[cmd]; + *data = mock_smart_battery[offset]; return EC_SUCCESS; } +DECLARE_TEST_I2C_READ16(sb_i2c_read16); -int sb_write(int cmd, int param) +int sb_i2c_write16(int port, int slave_addr, int offset, int data) { - if (cmd >= ARRAY_SIZE(mock_smart_battery)) + if (port != I2C_PORT_BATTERY || slave_addr != BATTERY_ADDR) + return EC_ERROR_INVAL; + if (offset >= ARRAY_SIZE(mock_smart_battery)) return EC_ERROR_UNIMPLEMENTED; - if (cmd < 0) + if (offset < 0) return EC_ERROR_INVAL; - mock_smart_battery[cmd] = param; - return EC_SUCCESS; -} - -int battery_manufacturer_name(char *manufacturer_name, int buf_size) -{ - return EC_SUCCESS; -} - -int battery_device_name(char *device_name, int buf_size) -{ + mock_smart_battery[offset] = data; return EC_SUCCESS; } +DECLARE_TEST_I2C_WRITE16(sb_i2c_write16); -int battery_device_chemistry(char *device_chemistry, int buf_size) +int sb_i2c_read_string(int port, int slave_addr, int offset, uint8_t *data, + int len) { return EC_SUCCESS; } @@ -55,11 +53,6 @@ int battery_time_at_rate(int rate, int *minutes) return EC_SUCCESS; } -int battery_manufacturer_date(int *year, int *month, int *day) -{ - return EC_SUCCESS; -} - /* Fake battery */ const struct battery_temperature_ranges bat_temp_ranges = { /* diff --git a/common/smart_battery.c b/common/smart_battery.c index ef9136ee00..84ae7d15b0 100644 --- a/common/smart_battery.c +++ b/common/smart_battery.c @@ -21,12 +21,12 @@ test_mockable int sbc_write(int cmd, int param) return i2c_write16(I2C_PORT_CHARGER, CHARGER_ADDR, cmd, param); } -test_mockable int sb_read(int cmd, int *param) +int sb_read(int cmd, int *param) { return i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); } -test_mockable int sb_write(int cmd, int param) +int sb_write(int cmd, int param) { return i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); } |