summaryrefslogtreecommitdiff
path: root/board/host/battery.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-09-15 12:15:49 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-16 14:49:46 -0700
commitc2c02249a01ec56857a51e1645060325f7558b59 (patch)
tree0c62ecf9d06d85faf881396d28c196ba187e23a8 /board/host/battery.c
parentfe77303bec6c78786a9df1dbdb33af64787e20c8 (diff)
downloadchrome-ec-c2c02249a01ec56857a51e1645060325f7558b59.tar.gz
host: mock i2c_xfer
Instead of mocking i2c_read8/16/32, mock i2c_xfer. We can now test code that call i2c_xfer directly and test common/i2c.c BRANCH=samus, ryu BUG=chrome-os-partner:45223 TEST=Unit tests pass. Change-Id: Iaa772515c40cf55d2050d0019e2062d63278adc0 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/299768 Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'board/host/battery.c')
-rw-r--r--board/host/battery.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/board/host/battery.c b/board/host/battery.c
index a5c447f5d7..e2c4b26b85 100644
--- a/board/host/battery.c
+++ b/board/host/battery.c
@@ -14,38 +14,34 @@
static uint16_t mock_smart_battery[SB_MANUFACTURER_DATA + 1];
-int sb_i2c_read16(int port, int slave_addr, int offset, int *data)
+int sb_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
+ uint8_t *in, int in_size, int flags)
{
- 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 (offset < 0 || data == NULL)
- return EC_ERROR_INVAL;
- *data = mock_smart_battery[offset];
- return EC_SUCCESS;
-}
-DECLARE_TEST_I2C_READ16(sb_i2c_read16);
+ if (out_size == 0 && in_size == 0)
+ return EC_SUCCESS;
-int sb_i2c_write16(int port, int slave_addr, int offset, int data)
-{
if (port != I2C_PORT_BATTERY || slave_addr != BATTERY_ADDR)
return EC_ERROR_INVAL;
- if (offset >= ARRAY_SIZE(mock_smart_battery))
+ if (out[0] >= ARRAY_SIZE(mock_smart_battery))
return EC_ERROR_UNIMPLEMENTED;
- if (offset < 0)
- return EC_ERROR_INVAL;
- mock_smart_battery[offset] = data;
- return EC_SUCCESS;
-}
-DECLARE_TEST_I2C_WRITE16(sb_i2c_write16);
-
-int sb_i2c_read_string(int port, int slave_addr, int offset, uint8_t *data,
- int len)
-{
+ if (out_size == 1) {
+ /* Read */
+ if (in_size != 2)
+ /* We are not doing a read16, assume read string */
+ return EC_SUCCESS;
+ else
+ *(uint16_t *)in = mock_smart_battery[out[0]];
+ } else {
+ /* write */
+ if (out_size != 3)
+ /* We are only expecting write 16 */
+ return EC_ERROR_UNIMPLEMENTED;
+ else
+ mock_smart_battery[out[0]] = (out[2] << 8) | out[1];
+ }
return EC_SUCCESS;
}
-DECLARE_TEST_I2C_READ_STRING(sb_i2c_read_string);
+DECLARE_TEST_I2C_XFER(sb_i2c_xfer);
int battery_time_at_rate(int rate, int *minutes)
{