Skip to content

Commit

Permalink
lib: os: assert: Avoid including printk.h in __assert.h
Browse files Browse the repository at this point in the history
Create wrapper for printk to avoid including printk.h in __assert.h.
__assert.h is used everywhere thus should not have dependency to
printk.h.

Cleanup assert Kconfig options.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
  • Loading branch information
nordic-krch authored and carlescufi committed Mar 16, 2022
1 parent aa00781 commit 786647b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
17 changes: 13 additions & 4 deletions include/sys/__assert.h
Expand Up @@ -8,7 +8,7 @@
#define ZEPHYR_INCLUDE_SYS___ASSERT_H_

#include <stdbool.h>
#include <sys/printk.h>
#include <toolchain.h>

#ifdef CONFIG_ASSERT
#ifndef __ASSERT_ON
Expand All @@ -21,8 +21,19 @@
#define __ASSERT_ON 0
#endif

#ifdef __cplusplus
extern "C" {
#endif

/* Wrapper around printk to avoid including printk.h in assert.h */
void assert_print(const char *fmt, ...);

#ifdef __cplusplus
}
#endif

#if defined(CONFIG_ASSERT_VERBOSE)
#define __ASSERT_PRINT(fmt, ...) printk(fmt, ##__VA_ARGS__)
#define __ASSERT_PRINT(fmt, ...) assert_print(fmt, ##__VA_ARGS__)
#else /* CONFIG_ASSERT_VERBOSE */
#define __ASSERT_PRINT(fmt, ...)
#endif /* CONFIG_ASSERT_VERBOSE */
Expand Down Expand Up @@ -64,8 +75,6 @@

#if __ASSERT_ON

#include <sys/printk.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
12 changes: 12 additions & 0 deletions lib/os/assert.c
Expand Up @@ -5,6 +5,7 @@
*/

#include <sys/__assert.h>
#include <sys/printk.h>
#include <zephyr.h>


Expand Down Expand Up @@ -41,3 +42,14 @@ __weak void assert_post_action(const char *file, unsigned int line)

k_panic();
}

void assert_print(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);

vprintk(fmt, ap);

va_end(ap);
}
22 changes: 12 additions & 10 deletions subsys/debug/Kconfig
Expand Up @@ -206,11 +206,20 @@ config ASSERT
Disabling this option will cause assertions to compile to nothing,
improving performance and system footprint.

config FORCE_NO_ASSERT
bool "Force-disable no assertions"
help
This boolean option disables Zephyr assertion testing even
in circumstances (twister) where it is enabled via
CFLAGS and not Kconfig. Added solely to be able to work
around compiler bugs for specific tests.

if ASSERT

config ASSERT_LEVEL
int "__ASSERT() level"
default 2
range 0 2
depends on ASSERT
help
This option specifies the assertion level used by the __ASSERT()
macro. It can be set to one of three possible values:
Expand All @@ -221,7 +230,6 @@ config ASSERT_LEVEL

config SPIN_VALIDATE
bool "Spinlock validation"
depends on ASSERT
depends on MULTITHREADING
depends on MP_NUM_CPUS <= 4
default y if !FLASH || FLASH_SIZE > 32
Expand All @@ -230,14 +238,6 @@ config SPIN_VALIDATE
enabled. It adds a relatively hefty overhead (about 3k or so) to
kernel code size, don't use on platforms known to be small.

config FORCE_NO_ASSERT
bool "Force-disable no assertions"
help
This boolean option disables Zephyr assertion testing even
in circumstances (twister) where it is enabled via
CFLAGS and not Kconfig. Added solely to be able to work
around compiler bugs for specific tests.

config ASSERT_VERBOSE
bool "Verbose assertions"
default y
Expand Down Expand Up @@ -272,6 +272,8 @@ config ASSERT_NO_MSG_INFO
before disabling file info since the message can be found in the
source using file info.

endif # ASSERT

config OVERRIDE_FRAME_POINTER_DEFAULT
bool "Override compiler defaults for -fomit-frame-pointer"
help
Expand Down

0 comments on commit 786647b

Please sign in to comment.