Make module tests use common prj.conf configuration

Windows 11, VSCode, NCS v2.3.0

I am writing tests for a module.  The module has code which is very interdependent upon itself.  Any test will require nearly the same prj.conf files.

When I use twister to run a test, is there a way to have each test draw from a common prj.conf file that is module-wide?

Or some other alternative to copy/pasting the same values into each prj.conf, and having to keep them up to date over time?

Of course I'm flexible about how this works, I'm trying to get across the idea with the prj.conf concept, but other techniques are ok if they work without duplication.

Thanks.

  • Hi,

    It sounds like what you are trying to achieve can be done using the variables CONF_FILE and OVERLAY_CONFIG.
    Create a test_common.conf file which contains all the common configs, then create one additional testX.conf file for each test with its specific configs.
    test1.conf, test2.conf etc.

    For each test:
    Set the CONF_FILE variable to test_common.conf
    Set the OVERLAY_CONFIG variable to testX.conf

    This can be done in the test's CMakeLists.txt file, on the line after cmake_minimum_required() :

    cmake_minimum_required(VERSION 3.20.0)
    
    set(CONF_FILE ../test_common.conf)
    set(OVERLAY_CONFIG test1.conf)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

    Of course, set the names and paths of the files however you like.

  • Hi Oivind,

    I see.  Can that work with multiple modules, though?

    As in, today, I have a single module that I want to be able to add to a project, and have its prj.conf values automatically set.

    Tomorrow, I have a second module I want to be able to do the same with.

    Etc.

    I know, for example, that building against a specific board allows that board definition to have a prj.conf configuration independent of the build.

    That's basically what I'm looking for, per-module.

    Does that make sense?  Can you say how I can do that?

    I wonder if snippits could be used for this somehow?  Like, instead of including a specific module in my project, instead I include a snippit, and that snippit includes the module as well as the prj.conf values?

    I think snippits are only in the latest zephyr, which is beyond the version supported by NCS?  Do you know when snippits will be supported?

    Thanks.

    Doug

  • How are your modules and tests built up? Do they each contain a CMakeLists.txt and a prj.conf? If they do, then something like what I described should work.

    Could you show me how the file structure looks, and how you switch from one test to another? I could make this ticket private first if you'd like.

Related