Skip to content

Commit eb0b714

Browse files
committed
[nrf fromlist] tests: drivers: clock_control: Add initial DVFS polling
Add a setup routine that waits until DVFS finishes its initialization and during that time tries to constantly make requests that involve DVFS. This polling ensures that the clock control driver can properly recover after an unsuccessful request. Upstream PR #: 89952 Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent d1a60d3 commit eb0b714

File tree

1 file changed

+53
-3
lines changed
  • tests/drivers/clock_control/nrf_clock_control/src

1 file changed

+53
-3
lines changed

tests/drivers/clock_control/nrf_clock_control/src/main.c

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ static void test_clock_control_request(const struct test_clk_context *clk_contex
210210
ZTEST(nrf2_clock_control, test_cpuapp_hsfll_control)
211211
{
212212
TC_PRINT("APPLICATION DOMAIN HSFLL test\n");
213-
/* Wait for the DVFS init to complete */
214-
k_msleep(3000);
215213
test_clock_control_request(cpuapp_hsfll_test_clk_contexts,
216214
ARRAY_SIZE(cpuapp_hsfll_test_clk_contexts));
217215
}
@@ -306,4 +304,56 @@ ZTEST(nrf2_clock_control, test_safe_request_cancellation)
306304
zassert_between_inclusive(ret, ONOFF_STATE_ON, ONOFF_STATE_TO_ON);
307305
}
308306

309-
ZTEST_SUITE(nrf2_clock_control, NULL, NULL, NULL, NULL, NULL);
307+
static void *setup(void)
308+
{
309+
#if defined(CONFIG_BOARD_NRF54H20DK_NRF54H20_CPUAPP)
310+
const struct device *clk_dev = DEVICE_DT_GET(DT_NODELABEL(cpuapp_hsfll));
311+
const struct nrf_clock_spec clk_spec = {
312+
.frequency = MHZ(64),
313+
};
314+
struct onoff_client cli;
315+
uint32_t start_uptime;
316+
const uint32_t timeout_ms = 3000;
317+
318+
zassert_true(device_is_ready(clk_dev),
319+
"%s is not ready", clk_dev->name);
320+
321+
/* Constantly make requests to DVFS until one is successful (what also
322+
* means that the service has finished its initialization). This loop
323+
* also verifies that the clock control driver is able to recover after
324+
* an unsuccesful attempt to start a clock (at least one initial request
325+
* is expected to fail here due to DFVS not being initialized yet).
326+
*/
327+
TC_PRINT("Polling DVFS until it is ready\n");
328+
start_uptime = k_uptime_get_32();
329+
while (1) {
330+
int status;
331+
int ret;
332+
333+
sys_notify_init_spinwait(&cli.notify);
334+
ret = nrf_clock_control_request(clk_dev, &clk_spec, &cli);
335+
/* The on-off manager for this clock controller is expected to
336+
* always be in the off state when a request is done (its error
337+
* state is expected to be cleared by the clock control driver).
338+
*/
339+
zassert_equal(ret, ONOFF_STATE_OFF, "request result: %d", ret);
340+
do {
341+
ret = sys_notify_fetch_result(&cli.notify, &status);
342+
k_yield();
343+
} while (ret == -EAGAIN);
344+
345+
if (status == 0) {
346+
TC_PRINT("DVFS is ready\n");
347+
break;
348+
} else if ((k_uptime_get_32() - start_uptime) >= timeout_ms) {
349+
TC_PRINT("DVFS is not ready after %u ms\n", timeout_ms);
350+
ztest_test_fail();
351+
break;
352+
}
353+
}
354+
#endif
355+
356+
return NULL;
357+
}
358+
359+
ZTEST_SUITE(nrf2_clock_control, NULL, setup, NULL, NULL, NULL);

0 commit comments

Comments
 (0)