Skip to content

Commit cb760a0

Browse files
committed
tests: boards: intel_adsp/smoke: update to use new IPC API
This updates the Intel Audio DSP smoke test to use the new IPC API based on IPC message service. The old API is still being tested for now until all users of the old API has moved to the new one. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
1 parent c8ecdd7 commit cb760a0

File tree

6 files changed

+205
-39
lines changed

6 files changed

+205
-39
lines changed

tests/boards/intel_adsp/smoke/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ cmake_minimum_required(VERSION 3.20.0)
44
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
55
project(intel_adsp)
66

7-
target_sources(app PRIVATE src/main.c src/smpboot.c src/hostipc.c src/cpus.c)
7+
target_sources(app PRIVATE src/main.c src/smpboot.c src/hostipc.c src/cpus.c src/clock.c)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2022, 2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/ztest.h>
9+
#include <stdlib.h>
10+
#include "tests.h"
11+
12+
static volatile uint32_t host_dt;
13+
14+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
15+
16+
static bool clock_msg(const struct device *dev, void *arg, uint32_t data, uint32_t ext_data)
17+
{
18+
*(uint32_t *)arg = data;
19+
return true;
20+
}
21+
22+
#else /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
23+
24+
extern struct ipc_msg_ept ipc_ept;
25+
26+
int clock_ipc_receive_cb(uint8_t msg_type, const void *msg_data, void *priv)
27+
{
28+
zassert_true(msg_type == INTEL_ADSP_IPC_MSG, "unexpected msg type");
29+
30+
const struct intel_adsp_ipc_msg *msg = (const struct intel_adsp_ipc_msg *)msg_data;
31+
32+
*(uint32_t *)priv = msg->data;
33+
34+
return 0;
35+
}
36+
37+
struct ipc_msg_ept_cfg clock_ipc_ept_cfg = {
38+
.name = "host_ipc_ept",
39+
.cb = {
40+
.received = clock_ipc_receive_cb,
41+
},
42+
.priv = (void *)&host_dt,
43+
};
44+
45+
extern int intel_adsp_ipc_send_message(const struct device *dev, uint32_t data, uint32_t ext_data);
46+
47+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
48+
49+
ZTEST(intel_adsp, test_clock_calibrate)
50+
{
51+
uint32_t cyc0, cyc1, hz, diff;
52+
53+
#ifndef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
54+
int ret;
55+
56+
ret = ipc_msg_service_register_endpoint(INTEL_ADSP_IPC_HOST_DEV, &ipc_ept,
57+
&clock_ipc_ept_cfg);
58+
zassert_equal(ret, 0, "cannot register IPC endpoint");
59+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
60+
61+
/* Prime the host script's timestamp */
62+
cyc0 = k_cycle_get_32();
63+
intel_adsp_ipc_send_message(INTEL_ADSP_IPC_HOST_DEV, IPCCMD_TIMESTAMP, 0);
64+
65+
k_msleep(1000);
66+
host_dt = 0;
67+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
68+
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, clock_msg, (void *)&host_dt);
69+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
70+
71+
/* Now do it again, but with a handler to catch the result */
72+
cyc1 = k_cycle_get_32();
73+
intel_adsp_ipc_send_message(INTEL_ADSP_IPC_HOST_DEV, IPCCMD_TIMESTAMP, 0);
74+
AWAIT(host_dt != 0);
75+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
76+
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, NULL, NULL);
77+
#else
78+
ret = ipc_msg_service_deregister_endpoint(&ipc_ept);
79+
zassert_equal(ret, 0, "cannot de-register IPC endpoint");
80+
#endif
81+
82+
hz = 1000000ULL * (cyc1 - cyc0) / host_dt;
83+
printk("CLOCK: %lld Hz\n", (1000000ULL * (cyc1 - cyc0)) / host_dt);
84+
85+
/* Make sure we're within 1% of spec */
86+
diff = (uint32_t)llabs((int64_t)hz - CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
87+
zassert_true((hz / MIN(1, diff)) > 100, "clock rate wrong");
88+
}

tests/boards/intel_adsp/smoke/src/cpus.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
/* Copyright (c) 2022 Intel Corporation
1+
/*
2+
* Copyright (c) 2022, 2025 Intel Corporation
3+
*
24
* SPDX-License-Identifier: Apache-2.0
35
*/
6+
47
#include <stdlib.h>
58
#include <zephyr/kernel.h>
69
#include <zephyr/kernel/smp.h>

tests/boards/intel_adsp/smoke/src/hostipc.c

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
/* Copyright (c) 2022 Intel Corporation
1+
/*
2+
* Copyright (c) 2022, 2025 Intel Corporation
3+
*
24
* SPDX-License-Identifier: Apache-2.0
35
*/
6+
47
#include <zephyr/kernel.h>
58
#include <zephyr/ztest.h>
69
#include <intel_adsp_ipc.h>
@@ -11,6 +14,7 @@ static volatile bool done_flag, msg_flag;
1114
#define RETURN_MSG_SYNC_VAL 0x12345
1215
#define RETURN_MSG_ASYNC_VAL 0x54321
1316

17+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
1418
static bool ipc_message(const struct device *dev, void *arg,
1519
uint32_t data, uint32_t ext_data)
1620
{
@@ -29,13 +33,100 @@ static bool ipc_done(const struct device *dev, void *arg)
2933
done_flag = true;
3034
return false;
3135
}
36+
#else /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
37+
38+
#include <zephyr/ipc/ipc_msg_service.h>
39+
#include "../../../../../subsys/ipc/ipc_msg_service/backends/ipc_msg_intel_adsp_ipc.h"
40+
41+
struct ipc_msg_ept ipc_ept;
42+
43+
int ipc_receive_cb(uint8_t msg_type, const void *msg_data, void *priv)
44+
{
45+
zassert_true(msg_type == INTEL_ADSP_IPC_MSG ||
46+
msg_type == INTEL_ADSP_IPC_MSG_SYNC, "unexpected msg type");
47+
48+
const struct intel_adsp_ipc_msg *msg = (const struct intel_adsp_ipc_msg *)msg_data;
49+
50+
zassert_equal(msg->data, msg->extdata, "unequal message data/ext_data");
51+
zassert_true(msg->data == RETURN_MSG_SYNC_VAL ||
52+
msg->data == RETURN_MSG_ASYNC_VAL, "unexpected msg data");
53+
54+
msg_flag = true;
55+
56+
return 0;
57+
}
58+
59+
int ipc_event_cb(uint8_t evt_type, const void *evt_data, void *priv)
60+
{
61+
zassert_false(done_flag, "done called unexpectedly");
62+
63+
done_flag = true;
64+
65+
return 0;
66+
}
67+
68+
struct ipc_msg_ept_cfg host_ipc_ept_cfg = {
69+
.name = "host_ipc_ept",
70+
.cb = {
71+
.received = ipc_receive_cb,
72+
.event = ipc_event_cb,
73+
},
74+
};
75+
76+
static void intel_adsp_ipc_complete(const struct device *dev)
77+
{
78+
int ret;
79+
80+
ret = ipc_msg_service_send(&ipc_ept, INTEL_ADSP_IPC_MSG_DONE, NULL);
81+
82+
ARG_UNUSED(ret);
83+
}
84+
85+
static bool intel_adsp_ipc_is_complete(const struct device *dev)
86+
{
87+
int ret;
88+
89+
ret = ipc_msg_service_query(&ipc_ept, INTEL_ADSP_IPC_QUERY_IS_COMPLETE, NULL);
90+
91+
return ret == 0;
92+
}
93+
94+
int intel_adsp_ipc_send_message(const struct device *dev, uint32_t data, uint32_t ext_data)
95+
{
96+
struct intel_adsp_ipc_msg msg = {.data = data, .extdata = ext_data};
97+
int ret;
98+
99+
ret = ipc_msg_service_send(&ipc_ept, INTEL_ADSP_IPC_MSG, &msg);
100+
101+
return ret;
102+
}
103+
104+
static int intel_adsp_ipc_send_message_sync(const struct device *dev, uint32_t data,
105+
uint32_t ext_data, k_timeout_t timeout)
106+
{
107+
struct intel_adsp_ipc_msg_sync msg = {
108+
.data = data, .extdata = ext_data, .timeout = timeout};
109+
int ret;
110+
111+
ret = ipc_msg_service_send(&ipc_ept, INTEL_ADSP_IPC_MSG_SYNC, &msg);
112+
113+
return ret;
114+
}
115+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
32116

33117
ZTEST(intel_adsp, test_host_ipc)
34118
{
35119
int ret;
36120

121+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
37122
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, ipc_message, NULL);
38123
intel_adsp_ipc_set_done_handler(INTEL_ADSP_IPC_HOST_DEV, ipc_done, NULL);
124+
#else /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
125+
ret = ipc_msg_service_register_endpoint(INTEL_ADSP_IPC_HOST_DEV, &ipc_ept,
126+
&host_ipc_ept_cfg);
127+
zassert_equal(ret, 0, "cannot register IPC endpoint");
128+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
129+
39130

40131
/* Just send a message and wait for it to complete */
41132
printk("Simple message send...\n");
@@ -97,7 +188,12 @@ ZTEST(intel_adsp, test_host_ipc)
97188
zassert_true(intel_adsp_ipc_is_complete(INTEL_ADSP_IPC_HOST_DEV),
98189
"sync message incomplete");
99190

191+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
100192
/* Clean up. Further tests might want to use IPC */
101193
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, NULL, NULL);
102194
intel_adsp_ipc_set_done_handler(INTEL_ADSP_IPC_HOST_DEV, NULL, NULL);
195+
#else /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
196+
ret = ipc_msg_service_deregister_endpoint(&ipc_ept);
197+
zassert_equal(ret, 0, "cannot de-register IPC endpoint");
198+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
103199
}

tests/boards/intel_adsp/smoke/src/main.c

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,12 @@
1-
/* Copyright (c) 2022 Intel Corporation
1+
/*
2+
* Copyright (c) 2022, 2025 Intel Corporation
3+
*
24
* SPDX-License-Identifier: Apache-2.0
35
*/
6+
47
#include <zephyr/kernel.h>
58
#include <zephyr/ztest.h>
69
#include <stdlib.h>
7-
#include "tests.h"
8-
9-
static bool clock_msg(const struct device *dev, void *arg,
10-
uint32_t data, uint32_t ext_data)
11-
{
12-
*(uint32_t *)arg = data;
13-
return true;
14-
}
15-
16-
ZTEST(intel_adsp, test_clock_calibrate)
17-
{
18-
static volatile uint32_t host_dt;
19-
uint32_t cyc0, cyc1, hz, diff;
20-
21-
/* Prime the host script's timestamp */
22-
cyc0 = k_cycle_get_32();
23-
intel_adsp_ipc_send_message(INTEL_ADSP_IPC_HOST_DEV, IPCCMD_TIMESTAMP, 0);
24-
25-
k_msleep(1000);
26-
host_dt = 0;
27-
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, clock_msg, (void *)&host_dt);
28-
29-
/* Now do it again, but with a handler to catch the result */
30-
cyc1 = k_cycle_get_32();
31-
intel_adsp_ipc_send_message(INTEL_ADSP_IPC_HOST_DEV, IPCCMD_TIMESTAMP, 0);
32-
AWAIT(host_dt != 0);
33-
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, NULL, NULL);
34-
35-
hz = 1000000ULL * (cyc1 - cyc0) / host_dt;
36-
printk("CLOCK: %lld Hz\n", (1000000ULL * (cyc1 - cyc0)) / host_dt);
37-
38-
/* Make sure we're within 1% of spec */
39-
diff = (uint32_t)llabs((int64_t)hz - CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
40-
zassert_true((hz / MIN(1, diff)) > 100, "clock rate wrong");
41-
}
4210

4311
#if XCHAL_HAVE_VECBASE
4412
ZTEST(intel_adsp, test_vecbase_lock)

tests/boards/intel_adsp/smoke/testcase.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ tests:
88
- intel_adsp/cavs25
99
- intel_adsp/ace15_mtpm
1010
- intel_adsp/ace30/ptl
11+
boards.intel_adsp.smoke.ipc_msg:
12+
extra_configs:
13+
- CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE=n
14+
platform_allow:
15+
- intel_adsp/cavs25
16+
- intel_adsp/ace15_mtpm
17+
- intel_adsp/ace30/ptl
18+
integration_platforms:
19+
- intel_adsp/cavs25
20+
- intel_adsp/ace15_mtpm
21+
- intel_adsp/ace30/ptl

0 commit comments

Comments
 (0)