Skip to content

Commit ed0b560

Browse files
dcpleungcfriedt
authored andcommitted
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 <[email protected]>
1 parent cf7e2e6 commit ed0b560

File tree

5 files changed

+217
-38
lines changed

5 files changed

+217
-38
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: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
13+
14+
static volatile uint32_t old_host_dt;
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_ept host_ipc_ept;
25+
26+
struct intel_adsp_ipc_ept_priv_data test_priv_data;
27+
28+
void clock_ipc_receive_cb(const void *data, size_t len, void *priv)
29+
{
30+
if (len == INTEL_ADSP_IPC_CB_MSG) {
31+
const struct intel_adsp_ipc_msg *msg = (const struct intel_adsp_ipc_msg *)data;
32+
struct intel_adsp_ipc_ept_priv_data *tpd =
33+
(struct intel_adsp_ipc_ept_priv_data *)priv;
34+
35+
tpd->priv = (void *)msg->data;
36+
37+
tpd->cb_ret = INTEL_ADSP_IPC_CB_RET_OKAY;
38+
}
39+
}
40+
41+
struct ipc_ept_cfg clock_ipc_ept_cfg = {
42+
.name = "host_ipc_ept",
43+
.cb = {
44+
.received = clock_ipc_receive_cb,
45+
},
46+
.priv = (void *)&test_priv_data,
47+
};
48+
49+
extern int intel_adsp_ipc_send_message(const struct device *dev, uint32_t data, uint32_t ext_data);
50+
51+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
52+
53+
ZTEST(intel_adsp, test_clock_calibrate)
54+
{
55+
uint32_t cyc0, cyc1, hz, diff;
56+
volatile uint32_t *host_dt;
57+
58+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
59+
host_dt = &old_host_dt;
60+
#else
61+
int ret;
62+
63+
host_dt = (volatile uint32_t *)&test_priv_data.priv;
64+
65+
ret = ipc_service_register_endpoint(INTEL_ADSP_IPC_HOST_DEV, &host_ipc_ept,
66+
&clock_ipc_ept_cfg);
67+
zassert_equal(ret, 0, "cannot register IPC endpoint");
68+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
69+
70+
/* Prime the host script's timestamp */
71+
cyc0 = k_cycle_get_32();
72+
intel_adsp_ipc_send_message(INTEL_ADSP_IPC_HOST_DEV, IPCCMD_TIMESTAMP, 0);
73+
74+
k_msleep(1000);
75+
*host_dt = 0;
76+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
77+
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, clock_msg, (void *)host_dt);
78+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
79+
80+
/* Now do it again, but with a handler to catch the result */
81+
cyc1 = k_cycle_get_32();
82+
intel_adsp_ipc_send_message(INTEL_ADSP_IPC_HOST_DEV, IPCCMD_TIMESTAMP, 0);
83+
AWAIT(*host_dt != 0);
84+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
85+
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, NULL, NULL);
86+
#else
87+
ret = ipc_service_deregister_endpoint(&host_ipc_ept);
88+
zassert_equal(ret, 0, "cannot de-register IPC endpoint");
89+
#endif
90+
91+
hz = 1000000ULL * (cyc1 - cyc0) / *host_dt;
92+
printk("CLOCK: %lld Hz\n", (1000000ULL * (cyc1 - cyc0)) / *host_dt);
93+
94+
/* Make sure we're within 1% of spec */
95+
diff = abs((int32_t)(hz - CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC));
96+
zassert_true((hz / MIN(1, diff)) > 100, "clock rate wrong");
97+
}

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

Lines changed: 100 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,103 @@ 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_service.h>
39+
#include <zephyr/ipc/backends/intel_adsp_host_ipc.h>
40+
41+
struct ipc_ept host_ipc_ept;
42+
43+
void ipc_receive_cb(const void *data, size_t len, void *priv)
44+
{
45+
struct intel_adsp_ipc_ept_priv_data *priv_data =
46+
(struct intel_adsp_ipc_ept_priv_data *)priv;
47+
48+
if (len == INTEL_ADSP_IPC_CB_MSG) {
49+
const struct intel_adsp_ipc_msg *msg = (const struct intel_adsp_ipc_msg *)data;
50+
51+
zassert_equal(msg->data, msg->ext_data, "unequal message data/ext_data");
52+
zassert_true(msg->data == RETURN_MSG_SYNC_VAL ||
53+
msg->data == RETURN_MSG_ASYNC_VAL, "unexpected msg data");
54+
55+
msg_flag = true;
56+
57+
if (msg->data == RETURN_MSG_SYNC_VAL) {
58+
priv_data->cb_ret = INTEL_ADSP_IPC_CB_RET_OKAY;
59+
} else {
60+
priv_data->cb_ret = -EINVAL;
61+
}
62+
} else if (len == INTEL_ADSP_IPC_CB_DONE) {
63+
zassert_false(done_flag, "done called unexpectedly");
64+
65+
done_flag = true;
66+
67+
priv_data->cb_ret = INTEL_ADSP_IPC_CB_RET_OKAY;
68+
}
69+
}
70+
71+
static struct intel_adsp_ipc_ept_priv_data host_ipc_priv_data;
72+
73+
struct ipc_ept_cfg host_ipc_ept_cfg = {
74+
.name = "host_ipc_ept",
75+
.cb = {
76+
.received = ipc_receive_cb,
77+
},
78+
.priv = &host_ipc_priv_data,
79+
};
80+
81+
static void intel_adsp_ipc_complete(const struct device *dev)
82+
{
83+
int ret;
84+
85+
ret = ipc_service_send(&host_ipc_ept, NULL, INTEL_ADSP_IPC_SEND_DONE);
86+
87+
ARG_UNUSED(ret);
88+
}
89+
90+
static bool intel_adsp_ipc_is_complete(const struct device *dev)
91+
{
92+
int ret;
93+
94+
ret = ipc_service_send(&host_ipc_ept, NULL, INTEL_ADSP_IPC_SEND_IS_COMPLETE);
95+
96+
return ret == 0;
97+
}
98+
99+
int intel_adsp_ipc_send_message(const struct device *dev, uint32_t data, uint32_t ext_data)
100+
{
101+
struct intel_adsp_ipc_msg msg = {.data = data, .ext_data = ext_data};
102+
int ret;
103+
104+
ret = ipc_service_send(&host_ipc_ept, &msg, INTEL_ADSP_IPC_SEND_MSG);
105+
106+
return ret;
107+
}
108+
109+
static int intel_adsp_ipc_send_message_sync(const struct device *dev, uint32_t data,
110+
uint32_t ext_data, k_timeout_t timeout)
111+
{
112+
struct intel_adsp_ipc_msg msg = {.data = data, .ext_data = ext_data, .timeout = timeout};
113+
int ret;
114+
115+
ret = ipc_service_send(&host_ipc_ept, &msg, INTEL_ADSP_IPC_SEND_MSG_SYNC);
116+
117+
return ret;
118+
}
119+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
32120

33121
ZTEST(intel_adsp, test_host_ipc)
34122
{
35123
int ret;
36124

125+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
37126
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, ipc_message, NULL);
38127
intel_adsp_ipc_set_done_handler(INTEL_ADSP_IPC_HOST_DEV, ipc_done, NULL);
128+
#else /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
129+
ret = ipc_service_register_endpoint(INTEL_ADSP_IPC_HOST_DEV, &host_ipc_ept,
130+
&host_ipc_ept_cfg);
131+
zassert_equal(ret, 0, "cannot register IPC endpoint");
132+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
39133

40134
/* Just send a message and wait for it to complete */
41135
printk("Simple message send...\n");
@@ -97,7 +191,12 @@ ZTEST(intel_adsp, test_host_ipc)
97191
zassert_true(intel_adsp_ipc_is_complete(INTEL_ADSP_IPC_HOST_DEV),
98192
"sync message incomplete");
99193

194+
#ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
100195
/* Clean up. Further tests might want to use IPC */
101196
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, NULL, NULL);
102197
intel_adsp_ipc_set_done_handler(INTEL_ADSP_IPC_HOST_DEV, NULL, NULL);
198+
#else /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
199+
ret = ipc_service_deregister_endpoint(&host_ipc_ept);
200+
zassert_equal(ret, 0, "cannot de-register IPC endpoint");
201+
#endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
103202
}

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 = abs(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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
tests:
22
boards.intel_adsp.smoke:
3+
extra_configs:
4+
- CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE=n
35
platform_allow:
46
- intel_adsp/cavs25
57
- intel_adsp/ace15_mtpm
8+
- intel_adsp/ace20_lnl
9+
- intel_adsp/ace30/ptl
10+
integration_platforms:
11+
- intel_adsp/cavs25
12+
- intel_adsp/ace15_mtpm
13+
- intel_adsp/ace30/ptl
14+
boards.intel_adsp.smoke.ipc_old:
15+
extra_configs:
16+
- CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE=y
17+
platform_allow:
18+
- intel_adsp/cavs25
19+
- intel_adsp/ace15_mtpm
20+
- intel_adsp/ace20_lnl
621
- intel_adsp/ace30/ptl
722
integration_platforms:
823
- intel_adsp/cavs25

0 commit comments

Comments
 (0)