Skip to content

Latest commit

 

History

History

doc

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Building & Running Cmocka Unit Tests

Prerequisites

You need cmocka to run unit tests.

For building native libraries you can just use package manager to install it, for example with apt:

sudo apt install libcmocka-dev

If you want to use custom version of cmocka (for example for cross-compilation) then you have to provide path to cmocka built for chosen architecture using --with-cmocka-prefix option.

Enabling unit tests

In order to build and run unit tests you need to provide path to cmocka using --with-cmocka-prefix option of the configure script.

After configuration you can build and run all unit tests by typing:

make check

There is no need for reconfiguration when cmocka path is set in configuration script. You can use make for building normal APL Binary and make check to build and run unit tests.

Example: Running tests for APL

In order to build tests for APL platform you have to use custom version of cmocka. You can run ./configure script with almost the same parameters as for building usual APL binary - just add --with-cmocka-prefix=<path to cmocka>, like:

./autogen.sh
./configure --with-arch=xtensa --with-platform=apollolake --with-dsp-core=$XTENSA_CORE --with-root-dir=$CONFIG_PATH/xtensa-elf --host=xtensa-bxt-elf --with-meu=$MEU_PATH --with-key=$PRIVATE_KEY_PATH CC=xt-xcc OBJCOPY=xt-objcopy OBJDUMP=xt-objdump --with-cmocka-prefix=/home/admin/cminstall_apl_2017_8/
make check

Preparing cmocka package

  1. Build cmocka with static library on:

    cmake <cmocka src dir> -DWITH_STATIC_LIB=ON

    In order to build cmocka with xt-xcc to be linked with a DSP binary code, you need two things:

    1. add another option -DCMAKE_C_COMPILER=xt-xcc
    2. play with cmocka build scripts to disable building of shared library
  2. Mkdir for package to be referenced by main sof build script and copy required files there:

    mkdir /home/<you>/cminstall
    mkdir /home/<you>/cminstall/include
    mkdir /home/<you>/cminstall/lib
    
    cp cmocka.h /home/<you>/cminstall/include
    cp libcmocka.a /home/<you>/cminstall/lib
  3. Use the target location for cmocka files when invoking configure script:

    ./configure --with-cmocka-prefix=/home/<you>/cminstall ...

Notes

  1. It is recommended to use make check -j option while running tests that use xt-run to speed up tests significantly by running multiple instances of xt-run simulator (it also speeds up build if you have many unit tests).

  2. When you switch platforms for example from native to APL, please use make clean, otherwise make will not build binaries for new platform and your tests will fail.

  3. To speed up development of new unit tests you can run specific tests like:
    make check check_PROGRAMS="testname1 testname2"