From c93a0892885183ed2dd04dc7e3470d569b471c17 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Sun, 22 Aug 2021 18:30:47 +0900 Subject: [PATCH] tests: lib: cmsis_dsp: interpolation: Add Q7 tests for 1.9.0 This commit adds the interpolation Q7 test patterns and implementations for the CMSIS-DSP 1.9.0. Signed-off-by: Stephanos Ioannidis --- .../cmsis_dsp/interpolation/CMakeLists.txt | 10 ++ tests/lib/cmsis_dsp/interpolation/prj.conf | 4 + tests/lib/cmsis_dsp/interpolation/src/main.c | 15 ++ tests/lib/cmsis_dsp/interpolation/src/q7.c | 103 +++++++++++++ tests/lib/cmsis_dsp/interpolation/src/q7.pat | 144 ++++++++++++++++++ .../lib/cmsis_dsp/interpolation/testcase.yaml | 20 +++ 6 files changed, 296 insertions(+) create mode 100644 tests/lib/cmsis_dsp/interpolation/CMakeLists.txt create mode 100644 tests/lib/cmsis_dsp/interpolation/prj.conf create mode 100644 tests/lib/cmsis_dsp/interpolation/src/main.c create mode 100644 tests/lib/cmsis_dsp/interpolation/src/q7.c create mode 100644 tests/lib/cmsis_dsp/interpolation/src/q7.pat create mode 100644 tests/lib/cmsis_dsp/interpolation/testcase.yaml diff --git a/tests/lib/cmsis_dsp/interpolation/CMakeLists.txt b/tests/lib/cmsis_dsp/interpolation/CMakeLists.txt new file mode 100644 index 00000000000..76c7d09032a --- /dev/null +++ b/tests/lib/cmsis_dsp/interpolation/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(cmsis_dsp_interpolation) + +target_sources(app PRIVATE + src/q7.c + src/main.c + ) diff --git a/tests/lib/cmsis_dsp/interpolation/prj.conf b/tests/lib/cmsis_dsp/interpolation/prj.conf new file mode 100644 index 00000000000..7598efa1381 --- /dev/null +++ b/tests/lib/cmsis_dsp/interpolation/prj.conf @@ -0,0 +1,4 @@ +CONFIG_ZTEST=y +CONFIG_NEWLIB_LIBC=y +CONFIG_CMSIS_DSP=y +CONFIG_CMSIS_DSP_INTERPOLATION=y diff --git a/tests/lib/cmsis_dsp/interpolation/src/main.c b/tests/lib/cmsis_dsp/interpolation/src/main.c new file mode 100644 index 00000000000..7aca2a304f8 --- /dev/null +++ b/tests/lib/cmsis_dsp/interpolation/src/main.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021 Stephanos Ioannidis + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +extern void test_interpolation_q7(void); + +void test_main(void) +{ + test_interpolation_q7(); +} diff --git a/tests/lib/cmsis_dsp/interpolation/src/q7.c b/tests/lib/cmsis_dsp/interpolation/src/q7.c new file mode 100644 index 00000000000..967ed4df03f --- /dev/null +++ b/tests/lib/cmsis_dsp/interpolation/src/q7.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 Stephanos Ioannidis + * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include "../../common/test_common.h" + +#include "q7.pat" + +#define SNR_ERROR_THRESH ((float32_t)20) +#define ABS_ERROR_THRESH ((q7_t)2) + +void test_arm_linear_interp_q7(void) +{ + size_t index; + size_t length = ARRAY_SIZE(ref_linear); + q7_t *output; + + /* Allocate output buffer */ + output = malloc(length * sizeof(q7_t)); + zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); + + /* Run test function */ + for (index = 0; index < length; index++) { + /* + * FIXME: Remove the cast below once the upstream CMSIS is + * fixed to specify the const qualifier. + */ + output[index] = arm_linear_interp_q7((q7_t *)in_linear_y, + in_linear_x[index], + ARRAY_SIZE(in_linear_y)); + } + + /* Validate output */ + zassert_true( + test_snr_error_q7(length, output, ref_linear, + SNR_ERROR_THRESH), + ASSERT_MSG_SNR_LIMIT_EXCEED); + + zassert_true( + test_near_equal_q7(length, output, ref_linear, + ABS_ERROR_THRESH), + ASSERT_MSG_ABS_ERROR_LIMIT_EXCEED); + + /* Free output buffer */ + free(output); +} + +void test_arm_bilinear_interp_q7(void) +{ + arm_bilinear_interp_instance_q7 inst; + size_t index; + size_t length = ARRAY_SIZE(ref_bilinear); + q7_t *output; + + /* Initialise instance */ + inst.numRows = in_bilinear_config[1]; + inst.numCols = in_bilinear_config[0]; + inst.pData = (q7_t *)in_bilinear_y; + + /* Allocate output buffer */ + output = malloc(length * sizeof(q7_t)); + zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); + + /* Run test function */ + for (index = 0; index < length; index++) { + output[index] = arm_bilinear_interp_q7( + &inst, + in_bilinear_x[2 * index], + in_bilinear_x[2 * index + 1] + ); + } + + /* Validate output */ + zassert_true( + test_snr_error_q7(length, output, ref_bilinear, + SNR_ERROR_THRESH), + ASSERT_MSG_SNR_LIMIT_EXCEED); + + zassert_true( + test_near_equal_q7(length, output, ref_bilinear, + ABS_ERROR_THRESH), + ASSERT_MSG_ABS_ERROR_LIMIT_EXCEED); + + /* Free output buffer */ + free(output); +} + +void test_interpolation_q7(void) +{ + ztest_test_suite(interpolation_q7, + ztest_unit_test(test_arm_linear_interp_q7), + ztest_unit_test(test_arm_bilinear_interp_q7) + ); + + ztest_run_test_suite(interpolation_q7); +} diff --git a/tests/lib/cmsis_dsp/interpolation/src/q7.pat b/tests/lib/cmsis_dsp/interpolation/src/q7.pat new file mode 100644 index 00000000000..25023da1172 --- /dev/null +++ b/tests/lib/cmsis_dsp/interpolation/src/q7.pat @@ -0,0 +1,144 @@ +static const q31_t in_linear_x[40] = { + 0x00080000, 0x00180000, 0x00280000, 0x00380000, + 0x00480000, 0x00580000, 0x00680000, 0x00780000, + 0x00880000, 0x00980000, 0x00A80000, 0x00B80000, + 0x00C80000, 0x00D80000, 0x00E80000, 0x00F80000, + 0x01080000, 0x01180000, 0x01280000, 0x01380000, + 0x01480000, 0x01580000, 0x01680000, 0x01780000, + 0x01880000, 0x01980000, 0x01A80000, 0x01B80000, + 0x01C80000, 0x01D80000, 0x01E80000, 0x01F80000, + 0x02080000, 0x02180000, 0x02280000, 0x02380000, + 0x02480000, 0x02580000, 0x02680000, 0x02780000 + }; + +static const q7_t in_linear_y[41] = { + 0x7F, 0x7F, 0x7F, 0x7D, 0x75, 0x67, 0x4D, 0x28, + 0xF7, 0xC2, 0x95, 0x80, 0x93, 0xD1, 0x27, 0x6F, + 0x7B, 0x37, 0xC8, 0x82, 0xAA, 0x27, 0x7E, 0x45, + 0xB4, 0x86, 0x07, 0x7E, 0x28, 0x8B, 0xC4, 0x71, + 0x37, 0x88, 0xE6, 0x7F, 0xE1, 0x93, 0x64, 0x22, + 0x82 + }; + +static const q7_t ref_linear[40] = { + 0x7F, 0x7F, 0x7E, 0x79, 0x6E, 0x5A, 0x3A, 0x0F, + 0xDC, 0xAB, 0x8A, 0x8A, 0xB2, 0xFC, 0x4B, 0x75, + 0x59, 0xFF, 0xA5, 0x96, 0xE9, 0x53, 0x62, 0xFD, + 0x9D, 0xC7, 0x43, 0x53, 0xDA, 0xA8, 0x1B, 0x54, + 0xE0, 0xB7, 0x33, 0x31, 0xBA, 0xFB, 0x43, 0xD2 + }; + +static const q31_t in_bilinear_x[300] = { + 0x00080000, 0x00080000, 0x000F1C72, 0x00080000, + 0x001638E4, 0x00080000, 0x001D5555, 0x00080000, + 0x002471C7, 0x00080000, 0x002B8E39, 0x00080000, + 0x0032AAAB, 0x00080000, 0x0039C71C, 0x00080000, + 0x0040E38E, 0x00080000, 0x00480000, 0x00080000, + 0x00080000, 0x000DB6DB, 0x000F1C72, 0x000DB6DB, + 0x001638E4, 0x000DB6DB, 0x001D5555, 0x000DB6DB, + 0x002471C7, 0x000DB6DB, 0x002B8E39, 0x000DB6DB, + 0x0032AAAB, 0x000DB6DB, 0x0039C71C, 0x000DB6DB, + 0x0040E38E, 0x000DB6DB, 0x00480000, 0x000DB6DB, + 0x00080000, 0x00136DB7, 0x000F1C72, 0x00136DB7, + 0x001638E4, 0x00136DB7, 0x001D5555, 0x00136DB7, + 0x002471C7, 0x00136DB7, 0x002B8E39, 0x00136DB7, + 0x0032AAAB, 0x00136DB7, 0x0039C71C, 0x00136DB7, + 0x0040E38E, 0x00136DB7, 0x00480000, 0x00136DB7, + 0x00080000, 0x00192492, 0x000F1C72, 0x00192492, + 0x001638E4, 0x00192492, 0x001D5555, 0x00192492, + 0x002471C7, 0x00192492, 0x002B8E39, 0x00192492, + 0x0032AAAB, 0x00192492, 0x0039C71C, 0x00192492, + 0x0040E38E, 0x00192492, 0x00480000, 0x00192492, + 0x00080000, 0x001EDB6E, 0x000F1C72, 0x001EDB6E, + 0x001638E4, 0x001EDB6E, 0x001D5555, 0x001EDB6E, + 0x002471C7, 0x001EDB6E, 0x002B8E39, 0x001EDB6E, + 0x0032AAAB, 0x001EDB6E, 0x0039C71C, 0x001EDB6E, + 0x0040E38E, 0x001EDB6E, 0x00480000, 0x001EDB6E, + 0x00080000, 0x00249249, 0x000F1C72, 0x00249249, + 0x001638E4, 0x00249249, 0x001D5555, 0x00249249, + 0x002471C7, 0x00249249, 0x002B8E39, 0x00249249, + 0x0032AAAB, 0x00249249, 0x0039C71C, 0x00249249, + 0x0040E38E, 0x00249249, 0x00480000, 0x00249249, + 0x00080000, 0x002A4925, 0x000F1C72, 0x002A4925, + 0x001638E4, 0x002A4925, 0x001D5555, 0x002A4925, + 0x002471C7, 0x002A4925, 0x002B8E39, 0x002A4925, + 0x0032AAAB, 0x002A4925, 0x0039C71C, 0x002A4925, + 0x0040E38E, 0x002A4925, 0x00480000, 0x002A4925, + 0x00080000, 0x00300000, 0x000F1C72, 0x00300000, + 0x001638E4, 0x00300000, 0x001D5555, 0x00300000, + 0x002471C7, 0x00300000, 0x002B8E39, 0x00300000, + 0x0032AAAB, 0x00300000, 0x0039C71C, 0x00300000, + 0x0040E38E, 0x00300000, 0x00480000, 0x00300000, + 0x00080000, 0x0035B6DB, 0x000F1C72, 0x0035B6DB, + 0x001638E4, 0x0035B6DB, 0x001D5555, 0x0035B6DB, + 0x002471C7, 0x0035B6DB, 0x002B8E39, 0x0035B6DB, + 0x0032AAAB, 0x0035B6DB, 0x0039C71C, 0x0035B6DB, + 0x0040E38E, 0x0035B6DB, 0x00480000, 0x0035B6DB, + 0x00080000, 0x003B6DB7, 0x000F1C72, 0x003B6DB7, + 0x001638E4, 0x003B6DB7, 0x001D5555, 0x003B6DB7, + 0x002471C7, 0x003B6DB7, 0x002B8E39, 0x003B6DB7, + 0x0032AAAB, 0x003B6DB7, 0x0039C71C, 0x003B6DB7, + 0x0040E38E, 0x003B6DB7, 0x00480000, 0x003B6DB7, + 0x00080000, 0x00412492, 0x000F1C72, 0x00412492, + 0x001638E4, 0x00412492, 0x001D5555, 0x00412492, + 0x002471C7, 0x00412492, 0x002B8E39, 0x00412492, + 0x0032AAAB, 0x00412492, 0x0039C71C, 0x00412492, + 0x0040E38E, 0x00412492, 0x00480000, 0x00412492, + 0x00080000, 0x0046DB6E, 0x000F1C72, 0x0046DB6E, + 0x001638E4, 0x0046DB6E, 0x001D5555, 0x0046DB6E, + 0x002471C7, 0x0046DB6E, 0x002B8E39, 0x0046DB6E, + 0x0032AAAB, 0x0046DB6E, 0x0039C71C, 0x0046DB6E, + 0x0040E38E, 0x0046DB6E, 0x00480000, 0x0046DB6E, + 0x00080000, 0x004C9249, 0x000F1C72, 0x004C9249, + 0x001638E4, 0x004C9249, 0x001D5555, 0x004C9249, + 0x002471C7, 0x004C9249, 0x002B8E39, 0x004C9249, + 0x0032AAAB, 0x004C9249, 0x0039C71C, 0x004C9249, + 0x0040E38E, 0x004C9249, 0x00480000, 0x004C9249, + 0x00080000, 0x00524925, 0x000F1C72, 0x00524925, + 0x001638E4, 0x00524925, 0x001D5555, 0x00524925, + 0x002471C7, 0x00524925, 0x002B8E39, 0x00524925, + 0x0032AAAB, 0x00524925, 0x0039C71C, 0x00524925, + 0x0040E38E, 0x00524925, 0x00480000, 0x00524925, + 0x00080000, 0x00580000, 0x000F1C72, 0x00580000, + 0x001638E4, 0x00580000, 0x001D5555, 0x00580000, + 0x002471C7, 0x00580000, 0x002B8E39, 0x00580000, + 0x0032AAAB, 0x00580000, 0x0039C71C, 0x00580000, + 0x0040E38E, 0x00580000, 0x00480000, 0x00580000 + }; + +static const q7_t in_bilinear_y[56] = { + 0x62, 0x7A, 0x82, 0xC8, 0x8A, 0x58, 0xA3, 0x2F, + 0xB5, 0x3C, 0xA5, 0xF7, 0x3C, 0x71, 0xD6, 0x4F, + 0xBF, 0x57, 0x04, 0xC8, 0x8C, 0x96, 0x8B, 0x7B, + 0x45, 0x7B, 0x9F, 0x52, 0xCA, 0x81, 0x7B, 0x03, + 0x57, 0xD8, 0x79, 0x8A, 0x97, 0x72, 0x58, 0x7F, + 0x90, 0x3E, 0x06, 0x6F, 0x9B, 0x2E, 0xD4, 0xF7, + 0x80, 0xE6, 0x88, 0x70, 0xE5, 0x3E, 0xF5, 0x7F + }; + +static const uint16_t in_bilinear_config[2] = { + 0x0007, 0x0008 + }; + +static const q7_t ref_bilinear[150] = { + 0x30, 0x1A, 0x01, 0xE8, 0xD4, 0xC2, 0xB8, 0xBD, + 0xC8, 0x05, 0x03, 0xD6, 0xF0, 0x14, 0x01, 0xCB, + 0xB4, 0xD0, 0xED, 0x14, 0xF9, 0xDA, 0xF3, 0x15, + 0x0A, 0xE3, 0xD3, 0xE8, 0xFC, 0x0F, 0x04, 0x0C, + 0x04, 0xF9, 0xFB, 0x05, 0x09, 0x03, 0xFE, 0xFC, + 0x10, 0x3E, 0x14, 0xDD, 0xEC, 0x26, 0x3F, 0x1F, + 0x00, 0xEA, 0xED, 0x13, 0x0A, 0xFB, 0x0F, 0x38, + 0x4B, 0x37, 0x20, 0xF1, 0xBF, 0xCF, 0xF9, 0x27, + 0x3D, 0x46, 0x4C, 0x4E, 0x47, 0xFF, 0x90, 0x8B, + 0xE8, 0x53, 0x6C, 0x54, 0x4E, 0x66, 0x6F, 0x0D, + 0x98, 0x89, 0xE6, 0x53, 0x66, 0x43, 0x38, 0x55, + 0x64, 0x10, 0x9F, 0x87, 0xE4, 0x52, 0x5F, 0x32, + 0x22, 0x44, 0x58, 0x14, 0xA4, 0x86, 0xE3, 0x51, + 0x5B, 0x29, 0x16, 0x3A, 0x52, 0x16, 0x9C, 0x8C, + 0xE7, 0x50, 0x61, 0x3E, 0x32, 0x4F, 0x5E, 0x11, + 0x95, 0x92, 0xEA, 0x4F, 0x67, 0x53, 0x4E, 0x64, + 0x6B, 0x0B, 0xA9, 0xB4, 0xF3, 0x39, 0x53, 0x52, + 0x56, 0x5F, 0x5C, 0x03, 0xE6, 0x00, 0x04, 0x06, + 0x17, 0x32, 0x3F, 0x33, 0x24, 0xF7 + }; + diff --git a/tests/lib/cmsis_dsp/interpolation/testcase.yaml b/tests/lib/cmsis_dsp/interpolation/testcase.yaml new file mode 100644 index 00000000000..6a6a29a96ff --- /dev/null +++ b/tests/lib/cmsis_dsp/interpolation/testcase.yaml @@ -0,0 +1,20 @@ +tests: + libraries.cmsis_dsp.interpolation: + filter: ((CONFIG_CPU_CORTEX_R or CONFIG_CPU_CORTEX_M) and TOOLCHAIN_HAS_NEWLIB == 1) or CONFIG_ARCH_POSIX + integration_platforms: + - frdm_k64f + - sam_e70_xplained + - mps2_an521 + - native_posix + tags: cmsis_dsp + min_flash: 128 + min_ram: 64 + libraries.cmsis_dsp.interpolation.fpu: + filter: ((CONFIG_CPU_CORTEX_R or CONFIG_CPU_CORTEX_M) and CONFIG_CPU_HAS_FPU and TOOLCHAIN_HAS_NEWLIB == 1) or CONFIG_ARCH_POSIX + integration_platforms: + - mps2_an521_remote + tags: cmsis_dsp fpu + extra_configs: + - CONFIG_FPU=y + min_flash: 128 + min_ram: 64