summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2022-09-16 11:06:24 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-20 21:12:24 +0000
commit4504f7ab7f1a75289c3b0a2a44d5ce621b9e9c87 (patch)
treeafdf564f6f35b454db1631eb0cbd4e3ff6513a40
parent9d723813b2e6c5619016e83b194ffdab6bd23d41 (diff)
downloadchrome-ec-4504f7ab7f1a75289c3b0a2a44d5ce621b9e9c87.tar.gz
test: Rest of standard SBS virtual_battery cmds
Some of the SBS read commands had not been tested via the virtual battery interface. Verify read commands for: Battery Status Design Voltage Manufacturer Data BRANCH=none BUG=b:246652125 TEST=./twister --clobber -i -s zephyr/test/drivers/drivers.default Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: Iaeecf912dc965ee2479e42fd7a2650f011af2dc6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3902457 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Wai-Hong Tam <waihong@google.com>
-rw-r--r--zephyr/emul/emul_smart_battery.c2
-rw-r--r--zephyr/include/emul/emul_smart_battery.h2
-rw-r--r--zephyr/test/drivers/default/src/virtual_battery.c30
3 files changed, 26 insertions, 8 deletions
diff --git a/zephyr/emul/emul_smart_battery.c b/zephyr/emul/emul_smart_battery.c
index cd2e9a09ed..9b8774d099 100644
--- a/zephyr/emul/emul_smart_battery.c
+++ b/zephyr/emul/emul_smart_battery.c
@@ -815,6 +815,7 @@ static int sbat_emul_init(const struct emul *emul, const struct device *parent)
(DT_INST_PROP(n, primary_battery) * \
MODE_PRIMARY_BATTERY_SUPPORT), \
.design_mv = DT_INST_PROP(n, design_mv), \
+ .default_design_mv = DT_INST_PROP(n, design_mv),\
.design_cap = DT_INST_PROP(n, design_cap), \
.temp = DT_INST_PROP(n, temperature), \
.volt = DT_INST_PROP(n, volt), \
@@ -881,6 +882,7 @@ static void emul_smart_battery_reset_capacity(const struct emul *emul)
struct sbat_emul_data *bat_data = emul->data;
bat_data->bat.cap = bat_data->bat.default_cap;
bat_data->bat.full_cap = bat_data->bat.default_full_cap;
+ bat_data->bat.design_mv = bat_data->bat.default_design_mv;
}
#define SBAT_EMUL_RESET_RULE_AFTER(n) \
diff --git a/zephyr/include/emul/emul_smart_battery.h b/zephyr/include/emul/emul_smart_battery.h
index ed6c10000b..4ff9d4a613 100644
--- a/zephyr/include/emul/emul_smart_battery.h
+++ b/zephyr/include/emul/emul_smart_battery.h
@@ -67,6 +67,8 @@ struct sbat_emul_bat_data {
uint16_t error_code;
/** Design battery voltage in mV */
uint16_t design_mv;
+ /** Default Design battery voltage in mV */
+ const uint16_t default_design_mv;
/** Battery temperature at the moment in Kelvins */
uint16_t temp;
/** Battery voltage at the moment in mV */
diff --git a/zephyr/test/drivers/default/src/virtual_battery.c b/zephyr/test/drivers/default/src/virtual_battery.c
index c03928ffca..51419944f3 100644
--- a/zephyr/test/drivers/default/src/virtual_battery.c
+++ b/zephyr/test/drivers/default/src/virtual_battery.c
@@ -109,20 +109,26 @@ static int virtual_battery_read_str(uint8_t command, char **read_buf,
return len;
}
+static void virtual_battery_read_data(uint8_t command, char **read_buf,
+ int read_len)
+{
+ uint8_t write_buf[1] = { command };
+
+ virtual_battery_xfer(write_buf, 1, (uint8_t **)read_buf, read_len);
+}
+
#define BATTERY_NODE DT_NODELABEL(battery)
ZTEST_USER(virtual_battery, test_read_regs)
{
- struct sbat_emul_bat_data *bat;
const struct emul *emul = EMUL_DT_GET(BATTERY_NODE);
+ struct sbat_emul_bat_data *bat = sbat_emul_get_bat_data(emul);
int16_t int16;
uint16_t word;
int expected;
char *str;
int len;
- bat = sbat_emul_get_bat_data(emul);
-
/*
* Iterate all the registers, which issues the I2C passthru host
* command to query the emulated smart battery. Most of the values
@@ -218,12 +224,20 @@ ZTEST_USER(virtual_battery, test_read_regs)
word = virtual_battery_read16(SB_SPECIFICATION_INFO);
zassert_equal(expected, word, "%d != %d", expected, word);
+ zassume_ok(battery_status(&expected));
+ word = virtual_battery_read16(SB_BATTERY_STATUS);
+ zassert_equal(expected, word, "%d != %d", expected, word);
+
+ zassume_ok(battery_design_voltage(&expected));
+ word = virtual_battery_read16(SB_DESIGN_VOLTAGE);
+ zassert_equal(expected, word, "%d != %d", expected, word);
+
+ virtual_battery_read_data(SB_MANUFACTURER_DATA, &str, bat->mf_data_len);
+ zassert_mem_equal(str, bat->mf_data, bat->mf_data_len, "%s != %s", str,
+ bat->mf_data);
+
/*
- * TODO: Test the following registers:
- * SB_BATTERY_STATUS
- * SB_DESIGN_VOLTAGE
- * SB_MANUFACTURER_DATA
- * SB_MANUFACTURE_INFO
+ * TODO(b/247103618): Verify manufacturer info extended SB spec command
*/
}