libc: fix CONFIG_STDOUT_CONSOLE semantics

The intent of this Kconfig is to allow libc stdout
functions like printf() to send their output to the
active console driver instead of discarding it.

This somehow evolved into preferring to use
printf() instead of printk() for all test case output
if enabled. Libc printf() implementation for both
minimal libc and newlib use considerably more stack
space than printk(), with nothing gained by using
them.

Remove all instances where we are conditionally
sending test case output based on this config, enable
it by default, and adjust a few tests that disabled
this because they were blowing stack.

printk() and vprintk() now work as expected for
unit_testing targets, they are just wrappers for
host printf().

Fixes: #13701

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2019-02-24 13:17:31 -08:00 committed by Kumar Gala
commit feab37096b
18 changed files with 42 additions and 118 deletions

View file

@ -13,14 +13,9 @@
#include <string.h>
#include <shell/shell.h>
#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define PRINT_DATA(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#include <misc/printk.h>
#define PRINT_DATA(fmt, ...) printk(fmt, ##__VA_ARGS__)
#endif /* CONFIG_STDOUT_CONSOLE */
#if defined CONFIG_ARCH_POSIX
#include "posix_board_if.h"

View file

@ -43,18 +43,14 @@ extern "C" {
#define CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC 10000000
/* FIXME: Properly integrate with Zephyr's arch specific code */
#define CONFIG_X86 1
#define PRINT printf
#endif /* !KERNEL */
#define CONFIG_PRINTK 1
#endif
#include <misc/printk.h>
#define PRINT printk
#include <zephyr.h>
#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define PRINT printf
#else /* !CONFIG_STDOUT_CONSOLE */
#include <misc/printk.h>
#define PRINT printk
#endif /* CONFIG_STDOUT_CONSOLE */
#include <ztest_assert.h>
#include <ztest_mock.h>

View file

@ -48,13 +48,8 @@ static inline void _zassert(int cond,
va_start(vargs, msg);
PRINT("\n Assertion failed at %s:%d: %s: %s\n",
file, line, func, default_msg);
#if defined(CONFIG_STDOUT_CONSOLE)
vprintf(msg, vargs);
printf("\n");
#else
vprintk(msg, vargs);
printk("\n");
#endif
va_end(vargs);
ztest_test_fail();
}

View file

@ -19,6 +19,7 @@ struct parameter {
#ifndef KERNEL
#include <stdlib.h>
#include <stdarg.h>
static void free_parameter(struct parameter *param)
{
@ -43,6 +44,19 @@ void _init_mock(void)
}
void printk(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
void vprintk(const char *fmt, va_list ap)
{
vprintf(fmt, ap);
}
#else
/*