Skip to content

Conversation

@linguini1
Copy link
Contributor

@linguini1 linguini1 commented Dec 23, 2025

Summary

This commit introduces a Kconfig switch to include the cmocka binary built from cmocka_main.c. The default behaviour is now changed so that cmocka is built as a library only, which would be the desired behaviour for users creating their own cmocka projects.

Impact

Cmocka is now only built as a library, so the cmocka binary is no longer
included by default.

PR (apache/nuttx#17653) to the NuttX kernel preserves the compilation of the cmocka binary for the two existing defconfigs which use the cmocka application.

Testing

Compilation of the cmocka libary without the binary using sim:nsh as a basis:

$ make -j
Create version.h
LN: platform/board to /home/linguini/coding/nuttx-space/apps/platform/dummy
Register: dd
Register: nsh
Register: sh
Register: gcov
Register: hello
Register: dumpstack
Register: gpio
Register: ostest
CP:  /home/linguini/coding/nuttx-space/nuttx/include/nuttx/config.h
CP:  /home/linguini/coding/nuttx-space/nuttx/include/nuttx/fs/hostfs.h
LD:  nuttx
Pac SIM with dynamic libs..
'/usr/lib/libm.so.6' -> 'sim-pac/libs/libm.so.6'
'/usr/lib/libz.so.1' -> 'sim-pac/libs/libz.so.1'
'/usr/lib/libc.so.6' -> 'sim-pac/libs/libc.so.6'
'/usr/lib64/ld-linux-x86-64.so.2' -> 'sim-pac/libs/ld-linux-x86-64.so.2'
'/lib64/ld-linux-x86-64.so.2' -> 'sim-pac/ld-linux-x86-64.so.2'
SIM elf with dynamic libs archive in nuttx.tgz

Then, when disabling CONFIG_TESTING_CMOCKA_ASLIB, the compilation is:

$ make -j
Create version.h
LN: platform/board to /home/linguini/coding/nuttx-space/apps/platform/dummy
Register: cmocka
Register: hello
Register: nsh
Register: sh
Register: dd
Register: gcov
Register: gpio
Register: dumpstack
Register: ostest
CP:  /home/linguini/coding/nuttx-space/nuttx/include/nuttx/config.h
LD:  nuttx
Pac SIM with dynamic libs..
'/usr/lib/libm.so.6' -> 'sim-pac/libs/libm.so.6'
'/usr/lib/libz.so.1' -> 'sim-pac/libs/libz.so.1'
'/usr/lib/libc.so.6' -> 'sim-pac/libs/libc.so.6'
'/usr/lib64/ld-linux-x86-64.so.2' -> 'sim-pac/libs/ld-linux-x86-64.so.2'
'/lib64/ld-linux-x86-64.so.2' -> 'sim-pac/ld-linux-x86-64.so.2'
SIM elf with dynamic libs archive in nuttx.tgz

and I can run the cmocka application on sim:

nsh> cmocka --help
an elegant unit testing framework for C with support for mock objects
Usage: cmocka [OPTION [ARG]] ...
 -?, --help       show this help statement
 -l, --list       display only the names of testcases and testsuite,
                  don't execute them
 -t, --test A     only run cases where case function name matches A pattern
 -p, --skip B     don't run cases where case function name matches B pattern
 -s, --suite C    only run suites where PROGNAME matches C pattern
 -f, --output-path use xml report instead of standard output
 -d, --shuffle-seed shuffling test sequence,between 0 and 99999,
                   when seed is 0,use time(NULL) as the seed for
                   the random number generator
Example: cmocka --suite mm|sched --test Test* --skip TestNuttxMm0[123]

nsh>

@linguini1
Copy link
Contributor Author

Build is failing because sim:citest needs the change in apache/nuttx#17653

This commit introduces a Kconfig switch to include the cmocka binary
built from cmocka_main.c. The default behaviour is now changed so that
cmocka is built as a library only, which would be the desired behaviour
for users creating their own cmocka projects.

Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
#

config TESTING_CMOCKA
tristate "Enable libcmocka"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool "Enable libcmocka"

if TESTING_CMOCKA

config TESTING_CMOCKA_PROG
bool "Compile cmocka binary"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool "Compile cmocka binary"
tristate "Compile cmocka binary"

Copy link
Contributor Author

@linguini1 linguini1 Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come tristate should be used here? Is it because of the MODULE variable in Makefile?

CFLAGS += -DHAVE_STRUCT_TIMESPEC=1
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/testing/cmocka

MODULE = $(CONFIG_TESTING_CMOCKA)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MODULE = $(CONFIG_TESTING_CMOCKA)
MODULE = $(CONFIG_TESTING_CMOCKA_PROG)


MODULE = $(CONFIG_TESTING_CMOCKA)

ifeq ($(CONFIG_TESTING_CMOCKA_PROG),y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ifeq ($(CONFIG_TESTING_CMOCKA_PROG),y)
ifneq ($(CONFIG_TESTING_CMOCKA_PROG),)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants