Skip to content

[FEATURE] Migrate SOF Unit Tests from CMock to Zephyr ztest Framework #10110

Description

@tmleman

Feature Request

Problem Description

The current SOF unit test infrastructure uses CMock/CMocka framework, which creates problems:

  1. Framework Mismatch: SOF is transitioning to Zephyr RTOS, but unit tests still use CMock instead of Zephyr's native testing framework
  2. Integration Challenges: CMock tests don't integrate well with Zephyr's development workflow and Twister test runner
  3. Platform Fragmentation: 15 different platform configurations with varying test counts (48-56 tests)
  4. Developer Experience: Context-switching between different testing frameworks

Proposed Solution

Migrate all 56 existing CMock-based unit tests to Zephyr's native ztest framework:

Goals:

  • Complete framework migration from CMock to ztest
  • Unified testing experience aligned with Zephyr ecosystem
  • Enhanced CI/CD integration with Twister test runner
  • Maintain functional equivalence of all existing tests

Key Features:

  • All 56 tests migrated (18 audio components, 10 library functions, 28 mathematical functions)
  • Platform consistency across all 15 configurations
  • Split architecture: basic unit tests (native_sim only) vs integration tests (multi-platform)

Current State

  • 56 tests across 15 platform configurations using CMock
  • Proof of Concept: Working ztest implementation in development branch (not yet integrated)

Platform Configurations

Platform ConfigurationTest CountPrimary Target
unit_test_defconfig56 testsGeneric UT framework
acp_6_3_defconfig50 testsAMD ACP 6.3
acp_7_0_defconfig50 testsAMD ACP 7.0
imx8_defconfig48 testsNXP i.MX8
imx8m_defconfig48 testsNXP i.MX8M
imx8ulp_defconfig48 testsNXP i.MX8ULP
imx8x_defconfig48 testsNXP i.MX8X
mt8186_defconfig48 testsMediaTek MT8186
mt8188_defconfig48 testsMediaTek MT8188
mt8195_defconfig48 testsMediaTek MT8195
mt8196_defconfig48 testsMediaTek MT8196
mt8365_defconfig48 testsMediaTek MT8365
rembrandt_defconfig48 testsAMD Rembrandt
renoir_defconfig48 testsAMD Renoir
vangogh_defconfig48 testsAMD Van Gogh

Note: All platform configurations are built in CI using native host compilers (not cross-compilation). The tests executed across different platform configurations are largely identical, with minimal platform-specific differences. This results in significant redundancy in CI builds, where the same test logic is compiled and executed multiple times with only minor configuration variations. The proposed ztest architecture aims to eliminate this redundancy by distinguishing between basic unit tests (native_sim only) and platform-specific integration tests.

Complete Test Migration Status

Audio Components (18 tests)

Test NameStatusPR LinkNotes
buffer_copy⏳ Pending-Buffer management
buffer_new⏳ Pending-Buffer creation
buffer_wrap⏳ Pending-Buffer wrapping
buffer_write⏳ Pending-Buffer write operations
comp_set_state⏳ Pending-Component state management
pcm_float_generic⏳ Pending-PCM format conversion
mixer⏳ Pending-Audio mixing
pipeline_new⏳ Pending-Pipeline creation
pipeline_connect_upstream⏳ Pending-Pipeline connection
pipeline_free⏳ Pending-Pipeline cleanup
volume_process⏳ Pending-Volume processing
mux_get_processing_function⏳ Pending-MUX function selection
mux_copy⏳ Pending-MUX copy operations
demux_copy⏳ Pending-DEMUX copy operations
selector_test⏳ Pending-Channel selector
eq_iir_process⏳ Pending-IIR equalizer
eq_fir_process⏳ Pending-FIR equalizer
drc_math_test⏳ Pending-Dynamic range compression

Library Functions (10 tests)

Test NameStatusPR LinkNotes
rstrcmp❌ BlockedCommentString comparison
rstrlen❌ BlockedCommentString length
fast-get-tests✅ Complete#10136Fast getter functions
list_init✅ Complete#10066List initialization (PoC exists)
list_is_empty✅ Complete#10066List empty check (PoC exists)
list_item_append✅ Complete#10066List append (PoC exists)
list_item_del✅ Complete#10066List deletion (PoC exists)
list_item_is_last✅ Complete#10066List last item check (PoC exists)
list_item_prepend✅ Complete#10066List prepend (PoC exists)
list_item✅ Complete#10066List item operations (PoC exists)

Mathematical Functions (28 tests)

Arithmetic Functions (6 tests)

Test NameStatusPR LinkNotes
gcd✅ Complete#10138Greatest common divisor
ceil_divide✅ Complete#10138Ceiling division
find_equal_int16✅ Complete#10138Find equal int16 values
find_min_int16✅ Complete#10138Find minimum int16
find_max_abs_int32✅ Complete#10138Find max absolute int32
norm_int32✅ Complete#10138Normalize int32

Trigonometry Functions (9 tests)

Test NameStatusPR LinkNotes
sin_32b_fixed✅ Complete#1023332-bit fixed sine
cos_32b_fixed✅ Complete#1023332-bit fixed cosine
sin_16b_fixed✅ Complete#1023316-bit fixed sine
cos_16b_fixed✅ Complete#1023316-bit fixed cosine
asin_32b_fixed✅ Complete#1023332-bit fixed arcsine
acos_32b_fixed✅ Complete#1023332-bit fixed arccosine
asin_16b_fixed✅ Complete#1023316-bit fixed arcsine
acos_16b_fixed✅ Complete#1023316-bit fixed arccosine
lut_sin_16b_fixed✅ Complete#1023316-bit sine lookup table

Advanced Math Functions (6 tests)

Test NameStatusPR LinkNotes
scalar_power✅ Complete#10364Scalar power operations
base2_logarithm✅ Complete#10590Base-2 logarithm
exponential✅ Complete#10590Exponential function
square_root🔄 In Progress#10764Square root
base_10_logarithm🔄 In Progress#10764Base-10 logarithm
base_e_logarithm🔄 In Progress#10764Natural logarithm

Audio Processing Math (7 tests)

Test NameStatusPR LinkNotes
a_law_codec⏳ Pending-A-law codec
mu_law_codec⏳ Pending-Mu-law codec
fft⏳ Pending-Fast Fourier Transform
window⏳ Pending-Window functions
matrix⏳ Pending-Matrix operations
auditory⏳ Pending-Auditory processing
dct⏳ Pending-Discrete Cosine Transform

Status Legend:

  • Pending: Not yet started
  • 🟡 PoC Ready: Proof of concept exists, ready for integration
  • 🔄 In Progress: Currently being migrated
  • Complete: Migration completed and merged
  • Blocked: Migration blocked by dependencies

Implementation Plan

Phase-Based Approach

PhaseScopeKey Deliverables
Phase 1PoC IntegrationMerge PoC to main, establish dual architecture
Phase 2Basic Unit TestsMath, string, library functions (native_sim only)
Phase 3Advanced Unit TestsComplex math, audio processing math (native_sim only)
Phase 4Integration TestsPipeline, modules, audio components (multi-platform)

Test Architecture

  1. Basic Unit Tests (sof/test/ztest/unit/)

    • Platform: native_sim only
    • Scope: Mathematical functions, basic library functions
    • Execution: Fast, isolated testing
  2. Integration Tests (sof/test/ztest/integration/)

    • Platform: native_sim in CI, with additional platforms enabled as needed (subset of current 15 configurations)
    • Scope: Pipeline management, audio modules, component interaction
    • Execution: Complex scenarios, real-world use cases

Migration Approach:

  • All tests will initially be ported to run on native_sim platform and executed in CI
  • Complex tests identified during migration will additionally be enabled on other platforms, requiring collaboration with specific platform developers
  • CI Impact: No change to current CI behavior - tests will continue to run natively on the host, maintaining the same execution model as today's CMock tests
  • Platform-specific work: Only complex integration tests will require platform maintainer involvement for multi-platform validation

Success Criteria

  • 100% test migration completion (56/56 tests)
  • Zero regression in test coverage or functionality

Benefits

  • Unified testing framework aligned with SOF's Zephyr transition
  • Improved developer productivity and reduced context switching
  • Enhanced CI/CD integration through Twister test runner
  • Future-proof testing infrastructure

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions