tests: INA3221 power monitor PM

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
liquidraverandClaude Opus 5.5 committed 2026-11-29 16:46:09 +01:00
1 parent 442385bd32
commit 3a8b0dcdbb
1 file changed
+27 -2
+27 -2
View File
@@ -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<std::string> 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<std::string>{ "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<std::string>{ "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<std::string>{ "ina3221:resume", "ina3221:select2", "ina3221:fetch",
"ina3221:suspend" }));
CHECK(r.fields & ENV_F_CURRENT);
}