test: mux calc_sample_s16le

Unit tests for calc_sample_s16le with up to 8 channels.

Signed-off-by: Janusz Jankowski <janusz.jankowski@linux.intel.com>
This commit is contained in:
Janusz Jankowski 2019-07-22 16:51:05 +02:00
parent 1bf779eef7
commit f837e57b6e
4 changed files with 140 additions and 3 deletions

View File

@ -26,9 +26,9 @@
* \param[in] offset Offset in source buffer.
* \param[in] mask Routing bitmask for calculating output sample.
*/
static inline int32_t calc_sample_s16le(struct comp_buffer *source,
uint8_t num_ch, uint32_t offset,
uint8_t mask)
UT_STATIC inline int32_t calc_sample_s16le(struct comp_buffer *source,
uint8_t num_ch, uint32_t offset,
uint8_t mask)
{
int32_t sample = 0;
int16_t *src;

View File

@ -90,6 +90,9 @@ demux_func demux_get_processing_function(struct comp_dev *dev);
#ifdef UNIT_TEST
void sys_comp_mux_init(void);
int32_t calc_sample_s16le(struct comp_buffer *source,
uint8_t num_ch, uint32_t offset,
uint8_t mask);
int32_t calc_sample_s24le(struct comp_buffer *source,
uint8_t num_ch, uint32_t offset,
uint8_t mask);

View File

@ -36,6 +36,12 @@ cmocka_test(
mock.c
)
cmocka_test(
mux_generic_calc_sample_s16le
mux_generic_calc_sample_s16le.c
mock.c
)
cmocka_test(
mux_generic_calc_sample_s24le
mux_generic_calc_sample_s24le.c

View File

@ -0,0 +1,128 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2019 Intel Corporation. All rights reserved.
//
// Author: Daniel Bogdzia <danielx.bogdzia@linux.intel.com>
// Janusz Jankowski <janusz.jankowski@linux.intel.com>
#include <sof/audio/component.h>
#include <sof/audio/mux.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <stdlib.h>
#include <cmocka.h>
struct test_data {
const char *name;
uint32_t channels;
uint8_t mask;
int16_t *input;
struct comp_buffer *buffer;
int32_t expected_result;
};
static int16_t input_samples[][PLATFORM_MAX_CHANNELS] = {
{ 0x1, 0x2, 0x4, 0x8,
0x10, 0x20, 0x40, 0x80, },
{ 0x100, 0x200, 0x400, 0x800,
0x1000, 0x2000, 0x4000, 0x8000, },
{ 0x8000, 0xf000, 0x8000, 0xf000,
0xf000, 0x8000, 0xf000, 0x8000, },
};
#define TEST_CASE(channels, mask, input_index) \
{ ("test_calc_sample_s16le_ch_" #channels "_mask_" #mask \
"_input_" #input_index), channels, mask, \
input_samples[input_index], NULL, 0 }
static struct test_data test_cases[] = {
TEST_CASE(1, 0x0, 0),
TEST_CASE(1, 0x0, 1),
TEST_CASE(1, 0x0, 2),
TEST_CASE(1, 0x1, 0),
TEST_CASE(1, 0x1, 1),
TEST_CASE(1, 0x1, 2),
TEST_CASE(2, 0x0, 0),
TEST_CASE(2, 0x0, 1),
TEST_CASE(2, 0x0, 2),
TEST_CASE(2, 0x1, 0),
TEST_CASE(2, 0x1, 2),
TEST_CASE(2, 0x2, 0),
TEST_CASE(2, 0x2, 2),
TEST_CASE(2, 0x3, 0),
TEST_CASE(2, 0x3, 2),
TEST_CASE(3, 0x1, 1),
TEST_CASE(3, 0x7, 1),
TEST_CASE(5, 0x4, 1),
TEST_CASE(5, 0x12, 1),
TEST_CASE(7, 0x10, 1),
TEST_CASE(7, 0x11, 1),
TEST_CASE(8, 0x0f, 1),
TEST_CASE(8, 0x0f, 2),
TEST_CASE(8, 0x10, 0),
TEST_CASE(8, 0x11, 0),
TEST_CASE(8, 0xf0, 1),
TEST_CASE(8, 0xf0, 2),
TEST_CASE(8, 0xff, 1),
TEST_CASE(8, 0xff, 2),
};
static void test_calc_sample(void **state)
{
struct test_data *td = *((struct test_data **)state);
int32_t ret = calc_sample_s16le(td->buffer,
td->channels,
0,
td->mask);
assert_int_equal(ret, td->expected_result);
}
static int setup(void **state)
{
struct test_data *td = *((struct test_data **)state);
int ch;
td->buffer = calloc(1, sizeof(struct comp_buffer));
td->buffer->r_ptr = td->input;
td->expected_result = 0;
for (ch = 0; ch < td->channels; ++ch) {
if (td->mask & BIT(ch))
td->expected_result += td->input[ch];
}
return 0;
}
static int teardown(void **state)
{
struct test_data *td = *((struct test_data **)state);
free(td->buffer);
return 0;
}
int main(void)
{
int i;
struct CMUnitTest tests[ARRAY_SIZE(test_cases)];
for (i = 0; i < ARRAY_SIZE(test_cases); ++i) {
tests[i].name = test_cases[i].name;
tests[i].test_func = test_calc_sample;
tests[i].initial_state = &test_cases[i];
tests[i].setup_func = setup;
tests[i].teardown_func = teardown;
}
cmocka_set_message_output(CM_OUTPUT_TAP);
return cmocka_run_group_tests(tests, NULL, NULL);
}