test: SBS gauge gets initially supported props
Add a test that validates fetching every property from the sbs gauge driver
results in no driver error codes being returned.
Signed-off-by: Aaron Massey <aaronmassey@google.com>
diff --git a/subsys/emul/i2c/emul_sbs_gauge.c b/subsys/emul/i2c/emul_sbs_gauge.c
index 7d1a316..97fb7e3 100644
--- a/subsys/emul/i2c/emul_sbs_gauge.c
+++ b/subsys/emul/i2c/emul_sbs_gauge.c
@@ -62,8 +62,10 @@
case SBS_GAUGE_CMD_NOM_CAPACITY:
case SBS_GAUGE_CMD_AVG_TIME2EMPTY:
case SBS_GAUGE_CMD_AVG_TIME2FULL:
+ case SBS_GAUGE_CMD_RUNTIME2EMPTY:
case SBS_GAUGE_CMD_CYCLE_COUNT:
case SBS_GAUGE_CMD_DESIGN_VOLTAGE:
+ case SBS_GAUGE_CMD_CURRENT:
/* Arbitrary stub value. */
*val = 1;
break;
diff --git a/tests/drivers/fuel_gauge/sbs_gauge/src/test_sbs_gauge.c b/tests/drivers/fuel_gauge/sbs_gauge/src/test_sbs_gauge.c
index 60f5026..055f063 100644
--- a/tests/drivers/fuel_gauge/sbs_gauge/src/test_sbs_gauge.c
+++ b/tests/drivers/fuel_gauge/sbs_gauge/src/test_sbs_gauge.c
@@ -9,6 +9,7 @@
#include <zephyr/drivers/i2c.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/byteorder.h>
+#include <zephyr/sys/util.h>
#include <zephyr/ztest.h>
#include <zephyr/ztest_assert.h>
@@ -38,12 +39,51 @@
zassert_not_equal(NULL, fixture->api->get_property);
}
-ZTEST_F(sbs_gauge_new_api, test_voltage_read)
+ZTEST_F(sbs_gauge_new_api, test_get_props__returns_ok)
{
- struct fuel_gauge_get_property prop = {
- .property_type = FUEL_GAUGE_VOLTAGE,
+ /* Validate what props are supported by the driver */
+
+ struct fuel_gauge_get_property props[] = {
+ {
+ .property_type = FUEL_GAUGE_VOLTAGE,
+ },
+ {
+ .property_type = FUEL_GAUGE_CURRENT,
+ },
+ {
+ .property_type = FUEL_GAUGE_AVG_CURRENT,
+ },
+ {
+ .property_type = FUEL_GAUGE_TEMPERATURE,
+ },
+ {
+ .property_type = FUEL_GAUGE_STATE_OF_CHARGE,
+ },
+ {
+ .property_type = FUEL_GAUGE_RUNTIME_TO_FULL,
+ },
+ {
+ .property_type = FUEL_GAUGE_RUNTIME_TO_EMPTY,
+ },
+ {
+ .property_type = FUEL_GAUGE_REMAINING_CAPACITY,
+ },
+ {
+ .property_type = FUEL_GAUGE_FULL_CHARGE_CAPACITY,
+ },
+ {
+ .property_type = FUEL_GAUGE_CYCLE_COUNT,
+ },
};
- zassert_ok(fixture->api->get_property(fixture->dev, &prop, 1));
+
+ int ret = fixture->api->get_property(fixture->dev, props, ARRAY_SIZE(props));
+
+ for (int i = 0; i < ARRAY_SIZE(props); i++) {
+ zassert_ok(props[i].status, "Property %d getting %d has a bad status.", i,
+ props[i].property_type);
+ }
+
+ zassert_ok(ret);
}
ZTEST_SUITE(sbs_gauge_new_api, NULL, sbs_gauge_new_api_setup, NULL, NULL, NULL);