tests: lib: add test for formatted output variants
Confirm that several ways of producing formatted output on the console all work, and support evaluating the relative space requirements for each. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
8528e45897
commit
9d6dcde81c
5 changed files with 150 additions and 0 deletions
8
tests/lib/cbprintf_fp/CMakeLists.txt
Normal file
8
tests/lib/cbprintf_fp/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(cbprintf_fp)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
25
tests/lib/cbprintf_fp/Kconfig
Normal file
25
tests/lib/cbprintf_fp/Kconfig
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Copyright (c) 2020 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
choice APP_FORMATTER
|
||||
prompt "Select print formatter"
|
||||
default APP_FORMATTER_PRINTK
|
||||
|
||||
config APP_FORMATTER_PRINTK
|
||||
bool "Emit with printk"
|
||||
|
||||
config APP_FORMATTER_PRINTF
|
||||
bool "Emit with printf"
|
||||
|
||||
config APP_FORMATTER_PRINTFCB
|
||||
bool "Emit with printfcb"
|
||||
|
||||
config APP_FORMATTER_FPRINTF
|
||||
bool "Emit with fprintf"
|
||||
|
||||
config APP_FORMATTER_FPRINTFCB
|
||||
bool "Emit with fprintfcb"
|
||||
|
||||
endchoice # APP_FORMATTER
|
||||
|
||||
source "Kconfig.zephyr"
|
3
tests/lib/cbprintf_fp/prj.conf
Normal file
3
tests/lib/cbprintf_fp/prj.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
# nothing here
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_CBPRINTF_LIBC_SUBSTS=y
|
42
tests/lib/cbprintf_fp/src/main.c
Normal file
42
tests/lib/cbprintf_fp/src/main.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_APP_FORMATTER_PRINTK)
|
||||
#include <sys/printk.h>
|
||||
#define PRINT_S "printk"
|
||||
#define PRINT(...) printk(__VA_ARGS__)
|
||||
#elif defined(CONFIG_APP_FORMATTER_PRINTF)
|
||||
#include <stdio.h>
|
||||
#ifdef CONFIG_NEWLIB_LIBC
|
||||
#define PRINT_S "printf/newlib"
|
||||
#else /* NEWLIB_LIBC */
|
||||
#define PRINT_S "printf"
|
||||
#endif /* NEWLIB_LIBC */
|
||||
#define PRINT(...) printf(__VA_ARGS__)
|
||||
#elif defined(CONFIG_APP_FORMATTER_PRINTFCB)
|
||||
#include <sys/cbprintf.h>
|
||||
#ifdef CONFIG_NEWLIB_LIBC
|
||||
#define PRINT_S "printfcb/newlib"
|
||||
#else /* NEWLIB_LIBC */
|
||||
#define PRINT_S "printfcb"
|
||||
#endif /* NEWLIB_LIBC */
|
||||
#define PRINT(...) printfcb(__VA_ARGS__)
|
||||
#elif defined(CONFIG_APP_FORMATTER_FPRINTF)
|
||||
#include <stdio.h>
|
||||
#define PRINT_S "fprintf"
|
||||
#define PRINT(...) fprintf(stdout, __VA_ARGS__)
|
||||
#elif defined(CONFIG_APP_FORMATTER_FPRINTFCB)
|
||||
#include <sys/cbprintf.h>
|
||||
#define PRINT_S "fprintfcb"
|
||||
#define PRINT(...) fprintfcb(stdout, __VA_ARGS__)
|
||||
#else
|
||||
#error Unsupported configuration
|
||||
#endif
|
||||
|
||||
void main(void)
|
||||
{
|
||||
PRINT("Hello with %s on %s\nComplete\n", PRINT_S, CONFIG_BOARD);
|
||||
}
|
72
tests/lib/cbprintf_fp/testcase.yaml
Normal file
72
tests/lib/cbprintf_fp/testcase.yaml
Normal file
|
@ -0,0 +1,72 @@
|
|||
common:
|
||||
harness: console
|
||||
platform_exclude: native_posix native_posix_64 nrf52_bsim
|
||||
integration_platforms:
|
||||
- qemu_x86
|
||||
- qemu_x86_64
|
||||
tests:
|
||||
lib.cbprintf_fp.printk:
|
||||
extra_configs:
|
||||
- CONFIG_APP_FORMATTER_PRINTK=y
|
||||
harness_config:
|
||||
type: multi_line
|
||||
ordered: true
|
||||
regex:
|
||||
- "Hello with printk"
|
||||
- "Complete"
|
||||
lib.cbprintf_fp.printf:
|
||||
extra_configs:
|
||||
- CONFIG_APP_FORMATTER_PRINTF=y
|
||||
harness_config:
|
||||
type: multi_line
|
||||
ordered: true
|
||||
regex:
|
||||
- "Hello with printf"
|
||||
- "Complete"
|
||||
lib.cbprintf_fp.printf_nl:
|
||||
extra_configs:
|
||||
- CONFIG_APP_FORMATTER_PRINTF=y
|
||||
- CONFIG_NEWLIB_LIBC=y
|
||||
harness_config:
|
||||
type: multi_line
|
||||
ordered: true
|
||||
regex:
|
||||
- "Hello with printf/newlib"
|
||||
- "Complete"
|
||||
lib.cbprintf_fp.printfcb:
|
||||
extra_configs:
|
||||
- CONFIG_APP_FORMATTER_PRINTFCB=y
|
||||
harness_config:
|
||||
type: multi_line
|
||||
ordered: true
|
||||
regex:
|
||||
- "Hello with printfcb"
|
||||
- "Complete"
|
||||
lib.cbprintf_fp.printfcb_nl:
|
||||
extra_configs:
|
||||
- CONFIG_APP_FORMATTER_PRINTFCB=y
|
||||
- CONFIG_NEWLIB_LIBC=y
|
||||
harness_config:
|
||||
type: multi_line
|
||||
ordered: true
|
||||
regex:
|
||||
- "Hello with printfcb/newlib"
|
||||
- "Complete"
|
||||
lib.cbprintf_fp.fprintf:
|
||||
extra_configs:
|
||||
- CONFIG_APP_FORMATTER_FPRINTF=y
|
||||
harness_config:
|
||||
type: multi_line
|
||||
ordered: true
|
||||
regex:
|
||||
- "Hello with fprintf"
|
||||
- "Complete"
|
||||
lib.cbprintf_fp.fprintfcb:
|
||||
extra_configs:
|
||||
- CONFIG_APP_FORMATTER_FPRINTFCB=y
|
||||
harness_config:
|
||||
type: multi_line
|
||||
ordered: true
|
||||
regex:
|
||||
- "Hello with fprintfcb"
|
||||
- "Complete"
|
Loading…
Add table
Add a link
Reference in a new issue