|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | +/* |
| 3 | + * Copyright(c) 2026 Intel Corporation. |
| 4 | + */ |
| 5 | + |
| 6 | +/* |
| 7 | + * Test case for creation and destruction of IPC4 pipelines. |
| 8 | + */ |
| 9 | + |
| 10 | +#include <zephyr/kernel.h> |
| 11 | +#include <zephyr/ztest.h> |
| 12 | +#include <zephyr/logging/log.h> |
| 13 | +#include <sof/ipc/topology.h> |
| 14 | +#include <ipc4/pipeline.h> |
| 15 | +#include <sof/ipc/msg.h> |
| 16 | +#include <rtos/alloc.h> |
| 17 | +#include <rtos/sof.h> |
| 18 | + |
| 19 | +LOG_MODULE_DECLARE(sof_boot_test, LOG_LEVEL_DBG); |
| 20 | + |
| 21 | +ZTEST(userspace_ipc4_pipeline, test_pipeline_create_destroy_helpers) |
| 22 | +{ |
| 23 | + struct ipc *ipc = ipc_get(); |
| 24 | + struct ipc4_pipeline_create msg = { 0 }; |
| 25 | + struct ipc_comp_dev *ipc_pipe; |
| 26 | + int ret; |
| 27 | + |
| 28 | + LOG_INF("Starting IPC4 pipeline test (helpers)"); |
| 29 | + |
| 30 | + /* 1. Setup msg */ |
| 31 | + msg.primary.r.instance_id = 1; |
| 32 | + msg.primary.r.ppl_priority = SOF_IPC4_PIPELINE_PRIORITY_0; |
| 33 | + msg.primary.r.ppl_mem_size = 1; |
| 34 | + msg.primary.r.type = SOF_IPC4_GLB_CREATE_PIPELINE; |
| 35 | + msg.extension.r.core_id = 0; |
| 36 | + |
| 37 | + /* 2. Create pipeline */ |
| 38 | + ret = ipc_pipeline_new(ipc, (ipc_pipe_new *)&msg); |
| 39 | + zassert_equal(ret, 0, "ipc_pipeline_new failed with %d", ret); |
| 40 | + |
| 41 | + /* 3. Validate pipeline exists */ |
| 42 | + ipc_pipe = ipc_get_pipeline_by_id(ipc, 1); |
| 43 | + zassert_not_null(ipc_pipe, "pipeline 1 not found after creation"); |
| 44 | + |
| 45 | + /* 4. Destroy pipeline */ |
| 46 | + ret = ipc_pipeline_free(ipc, 1); |
| 47 | + zassert_equal(ret, 0, "ipc_pipeline_free failed with %d", ret); |
| 48 | + |
| 49 | + /* 5. Validate pipeline is destroyed */ |
| 50 | + ipc_pipe = ipc_get_pipeline_by_id(ipc, 1); |
| 51 | + zassert_is_null(ipc_pipe, "pipeline 1 still exists after destruction"); |
| 52 | + |
| 53 | + LOG_INF("IPC4 pipeline test (helpers) complete"); |
| 54 | +} |
| 55 | + |
| 56 | +ZTEST(userspace_ipc4_pipeline, test_pipeline_create_destroy_handlers) |
| 57 | +{ |
| 58 | + struct ipc *ipc = ipc_get(); |
| 59 | + struct ipc4_pipeline_create create_msg = { 0 }; |
| 60 | + struct ipc4_message_request req = { 0 }; |
| 61 | + struct ipc_comp_dev *ipc_pipe; |
| 62 | + int ret; |
| 63 | + |
| 64 | + LOG_INF("Starting IPC4 pipeline test (handlers)"); |
| 65 | + |
| 66 | + /* 1. Setup create message */ |
| 67 | + create_msg.primary.r.instance_id = 2; |
| 68 | + create_msg.primary.r.ppl_priority = SOF_IPC4_PIPELINE_PRIORITY_0; |
| 69 | + create_msg.primary.r.ppl_mem_size = 1; |
| 70 | + create_msg.primary.r.type = SOF_IPC4_GLB_CREATE_PIPELINE; |
| 71 | + create_msg.extension.r.core_id = 0; |
| 72 | + |
| 73 | + /* Pack the create message into a generic request */ |
| 74 | + req.primary.dat = create_msg.primary.dat; |
| 75 | + req.extension.dat = create_msg.extension.dat; |
| 76 | + |
| 77 | + /* 2. Create pipeline using handler */ |
| 78 | + ret = ipc4_new_pipeline(&req); |
| 79 | + zassert_equal(ret, 0, "ipc4_new_pipeline failed with %d", ret); |
| 80 | + |
| 81 | + /* 3. Validate pipeline exists */ |
| 82 | + ipc_pipe = ipc_get_pipeline_by_id(ipc, 2); |
| 83 | + zassert_not_null(ipc_pipe, "pipeline 2 not found after creation"); |
| 84 | + |
| 85 | + /* 4. Setup delete message */ |
| 86 | + struct ipc4_pipeline_delete delete_msg = { 0 }; |
| 87 | + |
| 88 | + delete_msg.primary.r.instance_id = 2; |
| 89 | + delete_msg.primary.r.type = SOF_IPC4_GLB_DELETE_PIPELINE; |
| 90 | + |
| 91 | + /* Pack the delete message into a generic request */ |
| 92 | + req.primary.dat = delete_msg.primary.dat; |
| 93 | + req.extension.dat = delete_msg.extension.dat; |
| 94 | + |
| 95 | + /* Destroy pipeline using handler */ |
| 96 | + ret = ipc4_delete_pipeline(&req); |
| 97 | + zassert_equal(ret, 0, "ipc4_delete_pipeline failed with %d", ret); |
| 98 | + |
| 99 | + /* 5. Validate pipeline is destroyed */ |
| 100 | + ipc_pipe = ipc_get_pipeline_by_id(ipc, 2); |
| 101 | + zassert_is_null(ipc_pipe, "pipeline 2 still exists after destruction"); |
| 102 | + |
| 103 | + LOG_INF("IPC4 pipeline test (handlers) complete"); |
| 104 | +} |
| 105 | + |
| 106 | +static void *ipc4_pipeline_setup(void) |
| 107 | +{ |
| 108 | + struct sof *sof = sof_get(); |
| 109 | + |
| 110 | + /* SOF_BOOT_TEST_STANDALONE skips IPC init. We must allocate it manually for testing. */ |
| 111 | + if (!sof->ipc) { |
| 112 | + sof->ipc = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*sof->ipc)); |
| 113 | + sof->ipc->comp_data = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, |
| 114 | + SOF_IPC_MSG_MAX_SIZE); |
| 115 | + k_spinlock_init(&sof->ipc->lock); |
| 116 | + list_init(&sof->ipc->msg_list); |
| 117 | + list_init(&sof->ipc->comp_list); |
| 118 | + } |
| 119 | + |
| 120 | + return NULL; |
| 121 | +} |
| 122 | + |
| 123 | +ZTEST_SUITE(userspace_ipc4_pipeline, NULL, ipc4_pipeline_setup, NULL, NULL, NULL); |
| 124 | + |
| 125 | + |
0 commit comments