diff --git a/tests/boards/intel_adsp/smoke/src/cpus.c b/tests/boards/intel_adsp/smoke/src/cpus.c index 2f5c7694727..61f4b23ae48 100644 --- a/tests/boards/intel_adsp/smoke/src/cpus.c +++ b/tests/boards/intel_adsp/smoke/src/cpus.c @@ -182,7 +182,7 @@ void halt_and_restart(int cpu) /* Startup can be slow */ k_msleep(50); - zassert_true(WAIT_FOR(alive_flag == true, 10000, k_msleep(1)), NULL); + AWAIT(alive_flag == true); k_thread_abort(&run_on_threads[cpu]); } diff --git a/tests/boards/intel_adsp/smoke/src/hostipc.c b/tests/boards/intel_adsp/smoke/src/hostipc.c index acc736834fd..ae2e9e98548 100644 --- a/tests/boards/intel_adsp/smoke/src/hostipc.c +++ b/tests/boards/intel_adsp/smoke/src/hostipc.c @@ -41,8 +41,8 @@ void test_host_ipc(void) done_flag = false; ret = cavs_ipc_send_message(CAVS_HOST_DEV, IPCCMD_SIGNAL_DONE, 0); zassert_true(ret, "send failed"); - zassert_true(WAIT_FOR(cavs_ipc_is_complete(CAVS_HOST_DEV), 10000, k_msleep(1)), NULL); - zassert_true(WAIT_FOR(done_flag, 10000, k_msleep(1)), NULL); + AWAIT(cavs_ipc_is_complete(CAVS_HOST_DEV)); + AWAIT(done_flag); /* Request the host to return a message which we will complete * immediately. @@ -53,9 +53,9 @@ void test_host_ipc(void) ret = cavs_ipc_send_message(CAVS_HOST_DEV, IPCCMD_RETURN_MSG, RETURN_MSG_SYNC_VAL); zassert_true(ret, "send failed"); - zassert_true(WAIT_FOR(done_flag, 10000, k_msleep(1)), NULL); - zassert_true(WAIT_FOR(cavs_ipc_is_complete(CAVS_HOST_DEV), 10000, k_msleep(1)), NULL); - zassert_true(WAIT_FOR(msg_flag, 10000, k_msleep(1)), NULL); + AWAIT(done_flag); + AWAIT(cavs_ipc_is_complete(CAVS_HOST_DEV)); + AWAIT(msg_flag); /* Do exactly the same thing again to check for state bugs * (e.g. failing to signal done on one side or the other) @@ -66,9 +66,9 @@ void test_host_ipc(void) ret = cavs_ipc_send_message(CAVS_HOST_DEV, IPCCMD_RETURN_MSG, RETURN_MSG_SYNC_VAL); zassert_true(ret, "send failed"); - zassert_true(WAIT_FOR(done_flag, 10000, k_msleep(1)), NULL); - zassert_true(WAIT_FOR(cavs_ipc_is_complete(CAVS_HOST_DEV), 10000, k_msleep(1)), NULL); - zassert_true(WAIT_FOR(msg_flag, 10000, k_msleep(1)), NULL); + AWAIT(done_flag); + AWAIT(cavs_ipc_is_complete(CAVS_HOST_DEV)); + AWAIT(msg_flag); /* Same, but we'll complete it asynchronously (1.8+ only) */ if (!IS_ENABLED(CONFIG_SOC_SERIES_INTEL_CAVS_V15)) { @@ -78,10 +78,9 @@ void test_host_ipc(void) ret = cavs_ipc_send_message(CAVS_HOST_DEV, IPCCMD_RETURN_MSG, RETURN_MSG_ASYNC_VAL); zassert_true(ret, "send failed"); - zassert_true(WAIT_FOR(done_flag, 10000, k_msleep(1)), NULL); - zassert_true(WAIT_FOR(cavs_ipc_is_complete(CAVS_HOST_DEV), 10000, k_msleep(1)), - NULL); - zassert_true(WAIT_FOR(msg_flag, 10000, k_msleep(1)), NULL); + AWAIT(done_flag); + AWAIT(cavs_ipc_is_complete(CAVS_HOST_DEV)); + AWAIT(msg_flag); cavs_ipc_complete(CAVS_HOST_DEV); } diff --git a/tests/boards/intel_adsp/smoke/src/main.c b/tests/boards/intel_adsp/smoke/src/main.c index 6ec18736bea..f1cb1be90d1 100644 --- a/tests/boards/intel_adsp/smoke/src/main.c +++ b/tests/boards/intel_adsp/smoke/src/main.c @@ -31,7 +31,7 @@ void test_clock_calibrate(void) /* Now do it again, but with a handler to catch the result */ cyc1 = k_cycle_get_32(); cavs_ipc_send_message(CAVS_HOST_DEV, IPCCMD_TIMESTAMP, 0); - zassert_true(WAIT_FOR(host_dt != 0, 10000, k_msleep(1)), NULL); + AWAIT(host_dt != 0); cavs_ipc_set_message_handler(CAVS_HOST_DEV, NULL, NULL); hz = 1000000ULL * (cyc1 - cyc0) / host_dt; diff --git a/tests/boards/intel_adsp/smoke/src/tests.h b/tests/boards/intel_adsp/smoke/src/tests.h index 48d8adcbe17..f5cd691625e 100644 --- a/tests/boards/intel_adsp/smoke/src/tests.h +++ b/tests/boards/intel_adsp/smoke/src/tests.h @@ -7,6 +7,19 @@ #include #include +/* Helper to escape from infinite polling loops with a test failure + * instead of a hang. Spins with a relaxation loop so that it works + * in interrupt context and doesn't stress shared resources like SRAM + */ +#define AWAIT(expr) do { \ + int i; \ + for (i = 0; !(expr) && i < 10000; i++) { \ + for (volatile int j = 0; j < 1000; j++) { \ + } \ + } \ + zassert_true(i < 10000, "timeout waiting for %s", #expr); \ + } while (0) + void test_post_boot_ipi(void); void test_smp_boot_delay(void); void test_host_ipc(void);