Skip to content

Commit

Permalink
[nrf fromtree] tests: drivers: regulator: added regulator-boot-off tests
Browse files Browse the repository at this point in the history
Added tests for new regulator-boot-off property.

Signed-off-by: Andy Sinclair <[email protected]>
(cherry picked from commit b46e2f3)
  • Loading branch information
aasinclair authored and maxd-nordic committed Apr 18, 2024
1 parent 3d0a995 commit ec42c63
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/drivers/regulator/api/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,14 @@
regulator-initial-mode = <1>;
regulator-active-discharge = <1>;
};

reg4: REG4 {
regulator-boot-off;
};

reg5: REG5 {
regulator-boot-off;
fake-is-enabled-in-hardware;
};
};
};
29 changes: 29 additions & 0 deletions tests/drivers/regulator/api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ static const struct device *const reg1 = DEVICE_DT_GET(DT_NODELABEL(reg1));
static const struct device *const reg2 = DEVICE_DT_GET(DT_NODELABEL(reg2));
/* REG3: regulator-max/min-microvolt/microamp, regulator-allowed-modes */
static const struct device *const reg3 = DEVICE_DT_GET(DT_NODELABEL(reg3));
/* REG4: regulator-boot-off */
static const struct device *const reg4 = DEVICE_DT_GET(DT_NODELABEL(reg4));
/* REG5: regulator-boot-off and is_enabled */
static const struct device *const reg5 = DEVICE_DT_GET(DT_NODELABEL(reg5));

ZTEST(regulator_api, test_parent_dvs_state_set_not_implemented)
{
Expand Down Expand Up @@ -129,6 +133,10 @@ ZTEST(regulator_api, test_common_config)
zassert_equal(config->allowed_modes[1], 10U);
zassert_equal(config->allowed_modes_cnt, 2U);
zassert_equal(REGULATOR_ACTIVE_DISCHARGE_GET_BITS(config->flags), 1U);

/* reg4: regulator-boot-off */
config = reg4->config;
zassert_equal(config->flags & REGULATOR_BOOT_OFF, REGULATOR_BOOT_OFF);
}

ZTEST(regulator_api, test_common_is_init_enabled)
Expand All @@ -137,6 +145,8 @@ ZTEST(regulator_api, test_common_is_init_enabled)
zassert_true(regulator_common_is_init_enabled(reg1));
zassert_true(regulator_common_is_init_enabled(reg2));
zassert_false(regulator_common_is_init_enabled(reg3));
zassert_false(regulator_common_is_init_enabled(reg4));
zassert_false(regulator_common_is_init_enabled(reg5));
}

ZTEST(regulator_api, test_enable_disable)
Expand Down Expand Up @@ -171,6 +181,16 @@ ZTEST(regulator_api, test_enable_disable)
zassert_equal(regulator_disable(reg0), 0);
zassert_equal(regulator_fake_disable_fake.arg0_val, reg0);
zassert_equal(regulator_fake_disable_fake.call_count, 2U);

/* REG5: disabled at boot, can be enabled again */
zassert_equal(regulator_enable(reg5), 0);
zassert_equal(regulator_fake_enable_fake.call_count, 3U);

/* REG5: disable */
zassert_equal(regulator_disable(reg5), 0);
zassert_equal(regulator_fake_disable_fake.call_count, 3U);


}

ZTEST(regulator_api, test_count_voltages_not_implemented)
Expand Down Expand Up @@ -776,6 +796,8 @@ void *setup(void)
zassert_true(device_is_ready(reg1));
zassert_true(device_is_ready(reg2));
zassert_true(device_is_ready(reg3));
zassert_true(device_is_ready(reg4));
zassert_true(device_is_ready(reg5));

/* REG1, REG2 initialized at init time (always-on/boot-on) */
zassert_equal(regulator_fake_enable_fake.call_count, 2U);
Expand All @@ -785,6 +807,13 @@ void *setup(void)
/* REG3 mode set at init time (initial-mode) */
zassert_equal(regulator_fake_set_mode_fake.call_count, 1U);

/* REG4 already disabled at init time (boot-off) */
zassert_false(regulator_is_enabled(reg4));

/* REG5 explicitly disabled at init time (boot-off) */
zassert_equal(regulator_fake_disable_fake.call_count, 1U);
zassert_false(regulator_is_enabled(reg5));

return NULL;
}

Expand Down

0 comments on commit ec42c63

Please sign in to comment.