tests: drivers: uart: uart_pm: Call pm action from the thread context

PM action shall be called from the thread context thus switching to
k_work instead of the k_timer.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2024-04-08 17:34:03 +02:00 committed by Fabio Baltieri
commit a0bb05eb4c

View file

@ -203,36 +203,36 @@ ZTEST(uart_pm, test_uart_pm_poll_tx)
communication_verify(dev, true); communication_verify(dev, true);
} }
static void timeout(struct k_timer *timer) static void work_handler(struct k_work *work)
{ {
const struct device *uart = k_timer_user_data_get(timer); const struct device *dev = DEVICE_DT_GET(UART_NODE);
action_run(uart, PM_DEVICE_ACTION_SUSPEND, 0); action_run(dev, PM_DEVICE_ACTION_SUSPEND, 0);
} }
static K_TIMER_DEFINE(pm_timer, timeout, NULL);
/* Test going into low power state after interrupting poll out. Use various /* Test going into low power state after interrupting poll out. Use various
* delays to test interruption at multiple places. * delays to test interruption at multiple places.
*/ */
ZTEST(uart_pm, test_uart_pm_poll_tx_interrupted) ZTEST(uart_pm, test_uart_pm_poll_tx_interrupted)
{ {
static struct k_work_delayable dwork;
static struct k_work_sync sync;
const struct device *dev; const struct device *dev;
char str[] = "test"; char str[] = "test";
dev = DEVICE_DT_GET(UART_NODE); dev = DEVICE_DT_GET(UART_NODE);
zassert_true(device_is_ready(dev), "uart device is not ready"); zassert_true(device_is_ready(dev), "uart device is not ready");
k_timer_user_data_set(&pm_timer, (void *)dev); k_work_init_delayable(&dwork, work_handler);
for (int i = 1; i < 100; i++) { for (int i = 1; i < 100; i++) {
k_timer_start(&pm_timer, K_USEC(i * 10), K_NO_WAIT); k_work_schedule(&dwork, K_USEC(i * 10));
for (int j = 0; j < sizeof(str); j++) { for (int j = 0; j < sizeof(str); j++) {
uart_poll_out(dev, str[j]); uart_poll_out(dev, str[j]);
} }
k_timer_status_sync(&pm_timer); k_work_flush_delayable(&dwork, &sync);
action_run(dev, PM_DEVICE_ACTION_RESUME, 0); action_run(dev, PM_DEVICE_ACTION_RESUME, 0);