Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/ztest/unit/math/a_law/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright(c) 2026 Intel Corporation. All rights reserved.

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(test_math_a_law)

set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../..")

target_include_directories(app PRIVATE
${SOF_ROOT}/zephyr/include
${SOF_ROOT}/src/include
# Reference test vectors are #included in place from the CMocka tree
# rather than copied, so both frameworks share identical data.
${SOF_ROOT}/test/cmocka/src/math/arithmetic
)

# Define SOF-specific configurations for unit testing
target_compile_definitions(app PRIVATE
-DCONFIG_ZEPHYR_POSIX=1
-DCONFIG_LIBRARY=1
-DUNIT_TEST=1
)

target_sources(app PRIVATE
test_a_law_codec_ztest.c
${SOF_ROOT}/src/math/a_law.c
)
6 changes: 6 additions & 0 deletions test/ztest/unit/math/a_law/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright(c) 2026 Intel Corporation. All rights reserved.

CONFIG_ZTEST=y
CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n
74 changes: 74 additions & 0 deletions test/ztest/unit/math/a_law/test_a_law_codec_ztest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2026 Intel Corporation.
//
// These contents may have been developed with support from one or more
// Intel-operated generative artificial intelligence solutions.
//
// Converted from CMock to Ztest
// Original tests from test/cmocka/src/math/arithmetic/a_law_codec.c:
// Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>

#include <zephyr/ztest.h>
#include <stdint.h>
#include <stdio.h>
#include <sof/math/a_law.h>

/* Reference test vectors shared with the legacy CMocka test. They are
* #included in place from the CMocka tree (added to the include path in
* CMakeLists.txt) so the exact same fixed-point data is exercised.
*/
#include "ref_chirp_mono_8k_s16.h"
#include "a_law_codec.h"

/**
* @brief Verify A-law encoding against the reference vector
*
* Encodes every s16 chirp sample with sofm_a_law_encode() and checks the
* 8-bit code word matches the pre-computed reference, preserving the
* fixed-point semantics of the original CMocka test.
*/
ZTEST(math_a_law_suite, test_a_law_encode)
{
uint8_t a_law_sample, a_law_ref;
int i;

for (i = 0; i < REF_DATA_SAMPLE_COUNT; i++) {
a_law_sample = sofm_a_law_encode(chirp_mono_8k_s16[i]);
a_law_ref = ref_alaw_enc_data[i];

if (a_law_sample != a_law_ref) {
printf("%s: difference found at %d, encoded %d, ref %d, lin %d\n", __func__,
i, a_law_sample, a_law_ref, chirp_mono_8k_s16[i]);
zassert_true(false, "A-law encode mismatch");
}
}
}

/**
* @brief Verify A-law decoding against the reference vector
*
* Decodes every reference code word with sofm_a_law_decode() and checks the
* expanded s16 sample matches the pre-computed reference, preserving the
* fixed-point semantics of the original CMocka test.
*/
ZTEST(math_a_law_suite, test_a_law_decode)
{
int16_t s16_sample, s16_ref;
int i;

for (i = 0; i < REF_DATA_SAMPLE_COUNT; i++) {
s16_sample = sofm_a_law_decode(ref_alaw_enc_data[i]);
s16_ref = ref_alaw_dec_data[i];
if (s16_sample != s16_ref) {
printf("%s: difference found at %d, decoded %d, ref %d\n", __func__, i,
s16_sample, s16_ref);
zassert_true(false, "A-law decode mismatch");
}
}
}

/**
* @brief Define and initialize the A-law codec test suite
*/
ZTEST_SUITE(math_a_law_suite, NULL, NULL, NULL, NULL, NULL);
17 changes: 17 additions & 0 deletions test/ztest/unit/math/a_law/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright(c) 2026 Intel Corporation. All rights reserved.
#
# Math A-law codec unit tests converted from CMock to Ztest
#
# These contents may have been developed with support from one or more Intel-operated
# generative artificial intelligence solutions.
#

tests:
sof.unit.math.a_law:
tags: [math, a_law, codec, g711]
platform_allow: native_sim
integration_platforms:
- native_sim
build_only: false
28 changes: 28 additions & 0 deletions test/ztest/unit/math/mu_law/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright(c) 2026 Intel Corporation. All rights reserved.

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(test_math_mu_law)

set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../..")

target_include_directories(app PRIVATE
${SOF_ROOT}/zephyr/include
${SOF_ROOT}/src/include
# Share the reference vectors with the legacy CMocka test.
${SOF_ROOT}/test/cmocka/src/math/arithmetic
)

target_compile_definitions(app PRIVATE
-DCONFIG_ZEPHYR_POSIX=1
-DCONFIG_LIBRARY=1
-DUNIT_TEST=1
)

target_sources(app PRIVATE
test_mu_law_codec_ztest.c
${SOF_ROOT}/src/math/mu_law.c
)
6 changes: 6 additions & 0 deletions test/ztest/unit/math/mu_law/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright(c) 2026 Intel Corporation. All rights reserved.

CONFIG_ZTEST=y
CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n
61 changes: 61 additions & 0 deletions test/ztest/unit/math/mu_law/test_mu_law_codec_ztest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2026 Intel Corporation.
//
// Original tests from test/cmocka/src/math/arithmetic/mu_law_codec.c:
// Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>

#include <zephyr/ztest.h>
#include <stdint.h>
#include <stdio.h>
#include <sof/math/mu_law.h>

/* Include the same fixed-point reference vectors as the CMocka test. */
#include "ref_chirp_mono_8k_s16.h"
#include "mu_law_codec.h"

/**
* @brief Verify mu-law encoding of every chirp sample against its reference.
*
* Keep the legacy s16 input and 8-bit reference code words unchanged.
*/
ZTEST(math_mu_law_suite, test_mu_law_encode)
{
uint8_t mu_law_sample, mu_law_ref;
int i;

for (i = 0; i < REF_DATA_SAMPLE_COUNT; i++) {
mu_law_sample = sofm_mu_law_encode(chirp_mono_8k_s16[i]);
mu_law_ref = ref_mulaw_enc_data[i];

if (mu_law_sample != mu_law_ref) {
printf("%s: difference found at %d, encoded %d, ref %d, lin %d\n", __func__,
i, mu_law_sample, mu_law_ref, chirp_mono_8k_s16[i]);
zassert_true(false, "mu-law encode mismatch");
}
}
}

/**
* @brief Verify mu-law decoding of every reference code word.
*
* Compare the expanded s16 samples with the legacy fixed-point vector.
*/
ZTEST(math_mu_law_suite, test_mu_law_decode)
{
int16_t s16_sample, s16_ref;
int i;

for (i = 0; i < REF_DATA_SAMPLE_COUNT; i++) {
s16_sample = sofm_mu_law_decode(ref_mulaw_enc_data[i]);
s16_ref = ref_mulaw_dec_data[i];
if (s16_sample != s16_ref) {
printf("%s: difference found at %d, byte %d, decoded %d, ref %d\n",
__func__, i, ref_mulaw_enc_data[i], s16_sample, s16_ref);
zassert_true(false, "mu-law decode mismatch");
}
}
}

/** @brief Register the mu-law codec tests. */
ZTEST_SUITE(math_mu_law_suite, NULL, NULL, NULL, NULL, NULL);
11 changes: 11 additions & 0 deletions test/ztest/unit/math/mu_law/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright(c) 2026 Intel Corporation. All rights reserved.

tests:
sof.unit.math.mu_law:
tags: [math, mu_law, codec, g711]
platform_allow: native_sim
integration_platforms:
- native_sim
build_only: false
Loading