Skip to content

Commit 8d3fda6

Browse files
aasinclaircvinayak
authored andcommitted
[nrf fromtree] tests: drivers: regulator: added regulator-boot-off tests
Added tests for new regulator-boot-off property. Signed-off-by: Andy Sinclair <[email protected]> (cherry picked from commit b46e2f3)
1 parent 4698e88 commit 8d3fda6

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/drivers/regulator/api/app.overlay

+9
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,14 @@
2626
regulator-initial-mode = <1>;
2727
regulator-active-discharge = <1>;
2828
};
29+
30+
reg4: REG4 {
31+
regulator-boot-off;
32+
};
33+
34+
reg5: REG5 {
35+
regulator-boot-off;
36+
fake-is-enabled-in-hardware;
37+
};
2938
};
3039
};

tests/drivers/regulator/api/src/main.c

+29
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ static const struct device *const reg1 = DEVICE_DT_GET(DT_NODELABEL(reg1));
1919
static const struct device *const reg2 = DEVICE_DT_GET(DT_NODELABEL(reg2));
2020
/* REG3: regulator-max/min-microvolt/microamp, regulator-allowed-modes */
2121
static const struct device *const reg3 = DEVICE_DT_GET(DT_NODELABEL(reg3));
22+
/* REG4: regulator-boot-off */
23+
static const struct device *const reg4 = DEVICE_DT_GET(DT_NODELABEL(reg4));
24+
/* REG5: regulator-boot-off and is_enabled */
25+
static const struct device *const reg5 = DEVICE_DT_GET(DT_NODELABEL(reg5));
2226

2327
ZTEST(regulator_api, test_parent_dvs_state_set_not_implemented)
2428
{
@@ -129,6 +133,10 @@ ZTEST(regulator_api, test_common_config)
129133
zassert_equal(config->allowed_modes[1], 10U);
130134
zassert_equal(config->allowed_modes_cnt, 2U);
131135
zassert_equal(REGULATOR_ACTIVE_DISCHARGE_GET_BITS(config->flags), 1U);
136+
137+
/* reg4: regulator-boot-off */
138+
config = reg4->config;
139+
zassert_equal(config->flags & REGULATOR_BOOT_OFF, REGULATOR_BOOT_OFF);
132140
}
133141

134142
ZTEST(regulator_api, test_common_is_init_enabled)
@@ -137,6 +145,8 @@ ZTEST(regulator_api, test_common_is_init_enabled)
137145
zassert_true(regulator_common_is_init_enabled(reg1));
138146
zassert_true(regulator_common_is_init_enabled(reg2));
139147
zassert_false(regulator_common_is_init_enabled(reg3));
148+
zassert_false(regulator_common_is_init_enabled(reg4));
149+
zassert_false(regulator_common_is_init_enabled(reg5));
140150
}
141151

142152
ZTEST(regulator_api, test_enable_disable)
@@ -171,6 +181,16 @@ ZTEST(regulator_api, test_enable_disable)
171181
zassert_equal(regulator_disable(reg0), 0);
172182
zassert_equal(regulator_fake_disable_fake.arg0_val, reg0);
173183
zassert_equal(regulator_fake_disable_fake.call_count, 2U);
184+
185+
/* REG5: disabled at boot, can be enabled again */
186+
zassert_equal(regulator_enable(reg5), 0);
187+
zassert_equal(regulator_fake_enable_fake.call_count, 3U);
188+
189+
/* REG5: disable */
190+
zassert_equal(regulator_disable(reg5), 0);
191+
zassert_equal(regulator_fake_disable_fake.call_count, 3U);
192+
193+
174194
}
175195

176196
ZTEST(regulator_api, test_count_voltages_not_implemented)
@@ -776,6 +796,8 @@ void *setup(void)
776796
zassert_true(device_is_ready(reg1));
777797
zassert_true(device_is_ready(reg2));
778798
zassert_true(device_is_ready(reg3));
799+
zassert_true(device_is_ready(reg4));
800+
zassert_true(device_is_ready(reg5));
779801

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

810+
/* REG4 already disabled at init time (boot-off) */
811+
zassert_false(regulator_is_enabled(reg4));
812+
813+
/* REG5 explicitly disabled at init time (boot-off) */
814+
zassert_equal(regulator_fake_disable_fake.call_count, 1U);
815+
zassert_false(regulator_is_enabled(reg5));
816+
788817
return NULL;
789818
}
790819

0 commit comments

Comments
 (0)