From 1efe2de9256cb7fa19bf0adf073cbdccc4179106 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Sun, 22 Aug 2021 18:34:44 +0900 Subject: [PATCH] tests: lib: cmsis_dsp: interpolation: Add Q15 tests for 1.9.0 This commit adds the interpolation Q15 test patterns and implementations for the CMSIS-DSP 1.9.0. Signed-off-by: Stephanos Ioannidis --- .../cmsis_dsp/interpolation/CMakeLists.txt | 1 + tests/lib/cmsis_dsp/interpolation/src/main.c | 2 + tests/lib/cmsis_dsp/interpolation/src/q15.c | 103 +++++++++++++ tests/lib/cmsis_dsp/interpolation/src/q15.pat | 144 ++++++++++++++++++ 4 files changed, 250 insertions(+) create mode 100644 tests/lib/cmsis_dsp/interpolation/src/q15.c create mode 100644 tests/lib/cmsis_dsp/interpolation/src/q15.pat diff --git a/tests/lib/cmsis_dsp/interpolation/CMakeLists.txt b/tests/lib/cmsis_dsp/interpolation/CMakeLists.txt index 76c7d09032a..4fd0b106e56 100644 --- a/tests/lib/cmsis_dsp/interpolation/CMakeLists.txt +++ b/tests/lib/cmsis_dsp/interpolation/CMakeLists.txt @@ -6,5 +6,6 @@ project(cmsis_dsp_interpolation) target_sources(app PRIVATE src/q7.c + src/q15.c src/main.c ) diff --git a/tests/lib/cmsis_dsp/interpolation/src/main.c b/tests/lib/cmsis_dsp/interpolation/src/main.c index 7aca2a304f8..21f5d77ce78 100644 --- a/tests/lib/cmsis_dsp/interpolation/src/main.c +++ b/tests/lib/cmsis_dsp/interpolation/src/main.c @@ -8,8 +8,10 @@ #include extern void test_interpolation_q7(void); +extern void test_interpolation_q15(void); void test_main(void) { test_interpolation_q7(); + test_interpolation_q15(); } diff --git a/tests/lib/cmsis_dsp/interpolation/src/q15.c b/tests/lib/cmsis_dsp/interpolation/src/q15.c new file mode 100644 index 00000000000..71caa7d01ba --- /dev/null +++ b/tests/lib/cmsis_dsp/interpolation/src/q15.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 "q15.pat" + +#define SNR_ERROR_THRESH ((float32_t)70) +#define ABS_ERROR_THRESH ((q15_t)2) + +void test_arm_linear_interp_q15(void) +{ + size_t index; + size_t length = ARRAY_SIZE(ref_linear); + q15_t *output; + + /* Allocate output buffer */ + output = malloc(length * sizeof(q15_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_q15((q15_t *)in_linear_y, + in_linear_x[index], + ARRAY_SIZE(in_linear_y)); + } + + /* Validate output */ + zassert_true( + test_snr_error_q15(length, output, ref_linear, + SNR_ERROR_THRESH), + ASSERT_MSG_SNR_LIMIT_EXCEED); + + zassert_true( + test_near_equal_q15(length, output, ref_linear, + ABS_ERROR_THRESH), + ASSERT_MSG_ABS_ERROR_LIMIT_EXCEED); + + /* Free output buffer */ + free(output); +} + +void test_arm_bilinear_interp_q15(void) +{ + arm_bilinear_interp_instance_q15 inst; + size_t index; + size_t length = ARRAY_SIZE(ref_bilinear); + q15_t *output; + + /* Initialise instance */ + inst.numRows = in_bilinear_config[1]; + inst.numCols = in_bilinear_config[0]; + inst.pData = (q15_t *)in_bilinear_y; + + /* Allocate output buffer */ + output = malloc(length * sizeof(q15_t)); + zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); + + /* Run test function */ + for (index = 0; index < length; index++) { + output[index] = arm_bilinear_interp_q15( + &inst, + in_bilinear_x[2 * index], + in_bilinear_x[2 * index + 1] + ); + } + + /* Validate output */ + zassert_true( + test_snr_error_q15(length, output, ref_bilinear, + SNR_ERROR_THRESH), + ASSERT_MSG_SNR_LIMIT_EXCEED); + + zassert_true( + test_near_equal_q15(length, output, ref_bilinear, + ABS_ERROR_THRESH), + ASSERT_MSG_ABS_ERROR_LIMIT_EXCEED); + + /* Free output buffer */ + free(output); +} + +void test_interpolation_q15(void) +{ + ztest_test_suite(interpolation_q15, + ztest_unit_test(test_arm_linear_interp_q15), + ztest_unit_test(test_arm_bilinear_interp_q15) + ); + + ztest_run_test_suite(interpolation_q15); +} diff --git a/tests/lib/cmsis_dsp/interpolation/src/q15.pat b/tests/lib/cmsis_dsp/interpolation/src/q15.pat new file mode 100644 index 00000000000..99664c0afc8 --- /dev/null +++ b/tests/lib/cmsis_dsp/interpolation/src/q15.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 q15_t in_linear_y[41] = { + 0x7FFF, 0x7FF5, 0x7F54, 0x7C9B, 0x7561, 0x6697, 0x4D3B, 0x2795, + 0xF705, 0xC1F2, 0x94C2, 0x8019, 0x92ED, 0xD0A2, 0x2772, 0x6F77, + 0x7AFC, 0x36F4, 0xC7E6, 0x81CF, 0xA9C5, 0x274E, 0x7E72, 0x4567, + 0xB460, 0x8668, 0x06FB, 0x7E6C, 0x27FF, 0x8B7F, 0xC453, 0x70D6, + 0x3758, 0x87D1, 0xE60E, 0x7FFF, 0xE112, 0x928C, 0x640D, 0x2221, + 0x822F + }; + +static const q15_t ref_linear[40] = { + 0x7FFB, 0x7FA5, 0x7DF8, 0x78FE, 0x6DFC, 0x59E9, 0x3A68, 0x0F4D, + 0xDC7B, 0xAB5A, 0x8A6D, 0x8983, 0xB1C8, 0xFC0A, 0x4B74, 0x7539, + 0x58F8, 0xFF6D, 0xA4DB, 0x95CA, 0xE88A, 0x52E0, 0x61EC, 0xFCE4, + 0x9D64, 0xC6B1, 0x42B4, 0x5335, 0xD9BF, 0xA7E9, 0x1A94, 0x5417, + 0xDF94, 0xB6F0, 0x3307, 0x3089, 0xB9CF, 0xFB4D, 0x4317, 0xD228 + }; + +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 q15_t in_bilinear_y[56] = { + 0x61CE, 0x7A35, 0x81B6, 0xC7D1, 0x89ED, 0x5784, 0xA343, 0x2E9E, + 0xB48C, 0x3C78, 0xA542, 0xF74E, 0x3C31, 0x716B, 0xD5E6, 0x4F49, + 0xBF56, 0x5749, 0x03E4, 0xC818, 0x8C6E, 0x9586, 0x8ADB, 0x7B24, + 0x44C5, 0x7AE3, 0x9E88, 0x5239, 0xC9AA, 0x8111, 0x7B72, 0x02F8, + 0x569C, 0xD78A, 0x7920, 0x89ED, 0x96DA, 0x7237, 0x581C, 0x7F77, + 0x907D, 0x3DFE, 0x063F, 0x6F29, 0x9AA9, 0x2DDB, 0xD3AD, 0xF74E, + 0x803C, 0xE62A, 0x8867, 0x7029, 0xE512, 0x3E44, 0xF4F4, 0x7F6F + }; + +static const uint16_t in_bilinear_config[2] = { + 0x0007, 0x0008 + }; + +static const q15_t ref_bilinear[150] = { + 0x2FCB, 0x1A17, 0x017D, 0xE878, 0xD3D3, 0xC1CD, 0xB837, 0xBCB2, + 0xC83D, 0x053C, 0x035B, 0xD667, 0xF049, 0x1449, 0x0091, 0xCB6A, + 0xB471, 0xCFC5, 0xEC97, 0x13E3, 0xF8A8, 0xD997, 0xF33E, 0x14FF, + 0x09B2, 0xE35D, 0xD32C, 0xE7E2, 0xFC4C, 0x0EA8, 0x0472, 0x0C06, + 0x03A2, 0xF8F7, 0xFB15, 0x04DF, 0x08E8, 0x035B, 0xFE3D, 0xFC2C, + 0x103C, 0x3E75, 0x1407, 0xDCEF, 0xEC77, 0x2660, 0x3EA4, 0x1ED4, + 0x002E, 0xE9B1, 0xED56, 0x1284, 0x09E0, 0xFAB0, 0x0ED4, 0x382A, + 0x4AA5, 0x370B, 0x2005, 0xF10E, 0xBEC3, 0xCEFB, 0xF916, 0x26E4, + 0x3D6F, 0x4605, 0x4C38, 0x4E71, 0x4755, 0xFEE2, 0x9031, 0x8B73, + 0xE84D, 0x5318, 0x6C0A, 0x53E0, 0x4DCA, 0x65D8, 0x6EA5, 0x0CB5, + 0x97C1, 0x892E, 0xE635, 0x529A, 0x6597, 0x42EE, 0x380C, 0x54C9, + 0x638A, 0x1069, 0x9F51, 0x86EA, 0xE41C, 0x521C, 0x5F24, 0x31FD, + 0x224E, 0x43BB, 0x586F, 0x141D, 0xA3DE, 0x8651, 0xE321, 0x516D, + 0x5B31, 0x28A5, 0x1677, 0x3A3B, 0x5206, 0x15FF, 0x9C60, 0x8C66, + 0xE69A, 0x4FF9, 0x6142, 0x3DB0, 0x323C, 0x4EF9, 0x5E65, 0x109B, + 0x94E2, 0x927C, 0xEA13, 0x4E86, 0x6753, 0x52BC, 0x4E01, 0x63B7, + 0x6AC4, 0x0B36, 0xA8B8, 0xB44E, 0xF311, 0x3924, 0x530C, 0x5272, + 0x558C, 0x5ED0, 0x5BD3, 0x030D, 0xE58C, 0xFFBB, 0x0457, 0x05DD, + 0x1741, 0x322A, 0x3EBF, 0x3374, 0x23EC, 0xF6BC + }; +