diff --git a/tests/unit/env_sensor_tests.cpp b/tests/unit/env_sensor_tests.cpp index 3232008..7398218 100644 --- a/tests/unit/env_sensor_tests.cpp +++ b/tests/unit/env_sensor_tests.cpp @@ -12,7 +12,9 @@ namespace { const struct device ina219 = { "ina219" }; const struct device bme280 = { "bme280" }; +const struct device ina3221 = { "ina3221" }; bool bme280_present; +bool ina3221_present; int resume_result; std::vector calls; @@ -39,12 +41,19 @@ extern "C" const struct device *test_device_by_label(const char *label) if (bme280_present && std::strcmp(label, "bme280") == 0) { return &bme280; } + if (ina3221_present && std::strcmp(label, "ina3221") == 0) { + return &ina3221; + } return nullptr; } extern "C" bool device_is_ready(const struct device *dev) { return dev != nullptr; } extern "C" int device_init(const struct device *) { return 0; } -extern "C" int sensor_attr_set(const struct device *, enum sensor_channel, enum sensor_attribute, - const struct sensor_value *) { return 0; } +extern "C" int sensor_attr_set(const struct device *dev, enum sensor_channel, enum sensor_attribute, + const struct sensor_value *val) +{ + calls.push_back(std::string(dev->name) + ":select" + std::to_string(val->val1)); + return 0; +} extern "C" int sensor_sample_fetch(const struct device *dev) { calls.push_back(std::string(dev->name) + ":fetch"); @@ -116,3 +125,19 @@ TEST(env_sensor_left_alone, "UNIT-SENSOR-005", CHECK((calls == std::vector{ "bme280:fetch" })); CHECK(r.fields & ENV_F_TEMPERATURE); } + +TEST(env_ina3221_pm, "UNIT-SENSOR-006", + "Each INA3221 channel is a power monitor: suspended after probe, woken around its read") { + ina3221_present = true; + start(false, 0); + CHECK(env_sensor_count() == 4); + CHECK((calls == std::vector{ "ina3221:suspend", "ina3221:suspend", "ina3221:suspend", + "ina219:suspend" })); + calls.clear(); + + struct env_sensor_reading r; + CHECK(env_sensor_read(1, &r) == 0); + CHECK((calls == std::vector{ "ina3221:resume", "ina3221:select2", "ina3221:fetch", + "ina3221:suspend" })); + CHECK(r.fields & ENV_F_CURRENT); +}