From 6f67dd02f57be8f4563ce45b2dcd98645fc531c7 Mon Sep 17 00:00:00 2001 From: Tomasz Lauda Date: Wed, 27 Mar 2019 16:15:50 +0100 Subject: [PATCH 1/2] debug: add assert macro Adds assert macro to easily locate wrong parameters. If condition is not met we will panic. Signed-off-by: Tomasz Lauda --- src/host/CMakeLists.txt | 1 + src/host/panic.c | 33 +++++++++++++++++++++++++++++++++ src/include/sof/sof.h | 4 ++++ src/include/uapi/abi.h | 2 +- src/include/uapi/ipc/trace.h | 1 + 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/host/panic.c diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt index ed540a8246ba..563357828167 100644 --- a/src/host/CMakeLists.txt +++ b/src/host/CMakeLists.txt @@ -18,6 +18,7 @@ add_local_sources(tb_common schedule.c edf_schedule.c ll_schedule.c + panic.c topology.c trace.c ) diff --git a/src/host/panic.c b/src/host/panic.c new file mode 100644 index 000000000000..2a56cc0bf20f --- /dev/null +++ b/src/host/panic.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +#include + +void __panic(uint32_t p, char *filename, uint32_t linenum) { } diff --git a/src/include/sof/sof.h b/src/include/sof/sof.h index 2fea7d65b49a..7cff13251419 100644 --- a/src/include/sof/sof.h +++ b/src/include/sof/sof.h @@ -34,6 +34,7 @@ #include #include #include +#include #include struct ipc; @@ -56,6 +57,9 @@ struct sa; __attribute__((unused)) \ typedef char META_CONCAT(assertion_failed_, MESSAGE)[(COND) ? 1 : -1] +/* runtime assertion */ +#define assert(cond) (void)((cond) || (panic(SOF_IPC_PANIC_ASSERT), 0)) + /* general firmware context */ struct sof { /* init data */ diff --git a/src/include/uapi/abi.h b/src/include/uapi/abi.h index bd14f6a2254f..f83e5e2cf72e 100644 --- a/src/include/uapi/abi.h +++ b/src/include/uapi/abi.h @@ -52,7 +52,7 @@ /** \brief SOF ABI version major, minor and patch numbers */ #define SOF_ABI_MAJOR 3 -#define SOF_ABI_MINOR 3 +#define SOF_ABI_MINOR 4 #define SOF_ABI_PATCH 0 /** \brief SOF ABI version number. Format within 32bit word is MMmmmppp */ diff --git a/src/include/uapi/ipc/trace.h b/src/include/uapi/ipc/trace.h index 8fb914e640bd..d52d29156978 100644 --- a/src/include/uapi/ipc/trace.h +++ b/src/include/uapi/ipc/trace.h @@ -84,6 +84,7 @@ struct sof_ipc_dma_trace_posn { #define SOF_IPC_PANIC_STACK (SOF_IPC_PANIC_MAGIC | 0x8) #define SOF_IPC_PANIC_IDLE (SOF_IPC_PANIC_MAGIC | 0x9) #define SOF_IPC_PANIC_WFI (SOF_IPC_PANIC_MAGIC | 0xa) +#define SOF_IPC_PANIC_ASSERT (SOF_IPC_PANIC_MAGIC | 0xb) /* panic info include filename and line number */ struct sof_ipc_panic_info { From 29af0ccaef75d6ee6885f68d19dd9d19c4ef28bc Mon Sep 17 00:00:00 2001 From: Tomasz Lauda Date: Wed, 27 Mar 2019 16:20:14 +0100 Subject: [PATCH 2/2] component: add check if optional comp_ops are available Adds check if optional comp_ops are available. This patch also adds assert for mandatory ops. Signed-off-by: Tomasz Lauda --- src/include/sof/audio/component.h | 30 ++++++++++++++----- .../src/audio/pipeline/pipeline_mocks.c | 7 +++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index 67c41e0e1b96..f87841ed672b 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -341,6 +341,8 @@ struct comp_dev *comp_new(struct sof_ipc_comp *comp); */ static inline void comp_free(struct comp_dev *dev) { + assert(dev->drv->ops.free); + dev->drv->ops.free(dev); } @@ -369,13 +371,15 @@ void comp_set_period_bytes(struct comp_dev *dev, uint32_t frames, enum sof_ipc_frame *format, uint32_t *period_bytes); /** - * Component parameter init - mandatory. + * Component parameter init. * @param dev Component device. * @return 0 if succeeded, error code otherwise. */ static inline int comp_params(struct comp_dev *dev) { - return dev->drv->ops.params(dev); + if (dev->drv->ops.params) + return dev->drv->ops.params(dev); + return 0; } /** @@ -395,7 +399,7 @@ static inline int comp_host_buffer(struct comp_dev *dev, } /** - * Send component command (mandatory). + * Send component command. * @param dev Component device. * @param cmd Command. * @param data Command data. @@ -416,7 +420,9 @@ static inline int comp_cmd(struct comp_dev *dev, int cmd, void *data, return -EINVAL; } - return dev->drv->ops.cmd(dev, cmd, data, max_data_size); + if (dev->drv->ops.cmd) + return dev->drv->ops.cmd(dev, cmd, data, max_data_size); + return -EINVAL; } /** @@ -427,17 +433,21 @@ static inline int comp_cmd(struct comp_dev *dev, int cmd, void *data, */ static inline int comp_trigger(struct comp_dev *dev, int cmd) { + assert(dev->drv->ops.trigger); + return dev->drv->ops.trigger(dev, cmd); } /** - * Prepare component - mandatory. + * Prepare component. * @param dev Component device. * @return 0 if succeeded, error code otherwise. */ static inline int comp_prepare(struct comp_dev *dev) { - return dev->drv->ops.prepare(dev); + if (dev->drv->ops.prepare) + return dev->drv->ops.prepare(dev); + return 0; } /** @@ -447,17 +457,21 @@ static inline int comp_prepare(struct comp_dev *dev) */ static inline int comp_copy(struct comp_dev *dev) { + assert(dev->drv->ops.copy); + return dev->drv->ops.copy(dev); } /** - * Component reset and free runtime resources -mandatory. + * Component reset and free runtime resources. * @param dev Component device. * @return 0 if succeeded, error code otherwise. */ static inline int comp_reset(struct comp_dev *dev) { - return dev->drv->ops.reset(dev); + if (dev->drv->ops.reset) + return dev->drv->ops.reset(dev); + return 0; } /** diff --git a/test/cmocka/src/audio/pipeline/pipeline_mocks.c b/test/cmocka/src/audio/pipeline/pipeline_mocks.c index 2e246fa4a8c7..da59c315850c 100644 --- a/test/cmocka/src/audio/pipeline/pipeline_mocks.c +++ b/test/cmocka/src/audio/pipeline/pipeline_mocks.c @@ -126,3 +126,10 @@ void heap_trace_all(int force) { (void)force; } + +void __panic(uint32_t p, char *filename, uint32_t linenum) +{ + (void)p; + (void)filename; + (void)linenum; +}