Integrated minimal-printf in mbed-os

pull/11051/head
Evelyne Donnaes 2019-07-05 15:45:33 +01:00
parent 4018753837
commit 65ab34695e
10 changed files with 40 additions and 323 deletions

View File

@ -28,7 +28,7 @@ static char buffer[256] = {0};
#define CLEAN_BUFFER memset(::buffer, 0x00, sizeof(::buffer))
#define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,-1,-4231,-999,-4123,-32760,-99999
#define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999
#define FLOATS 0.002,0.92430,15.91320,791.77368,6208.2,25719.4952,426815.982588,6429271.046,42468024.93,212006462.910
#define FLOATS 0.002,0.92430,15.91320,791.77368,6208.2,25719.4952,426815.982588,6429271.046,42468024.93,212006462.910,6579.048
using namespace utest::v1;
@ -47,7 +47,7 @@ void test_case_c_string_u_d()
TEST_ASSERT_EQUAL_STRING("32768 3214 999 100 1 0 1 4231 999 4123 32760 99999", buffer);
}
void test_case_c_string_x_E()
void test_case_c_string_x_X()
{
CLEAN_BUFFER;
sprintf(buffer, "%x %X %x %X %x %X %x %X %x %X %x %X", POSITIVE_INTEGERS);
@ -57,22 +57,22 @@ void test_case_c_string_x_E()
void test_case_c_string_f_f()
{
CLEAN_BUFFER;
sprintf(buffer, "%f %f %f %f %f %f %f %f %f %f", FLOATS);
TEST_ASSERT_EQUAL_STRING("0.002000 0.924300 15.913200 791.773680 6208.200000 25719.495200 426815.982588 6429271.046000 42468024.930000 212006462.910000", buffer);
sprintf(buffer, "%f %f %f %f %f %f %f %f %f %f %f", FLOATS);
TEST_ASSERT_EQUAL_STRING("0.002000 0.924300 15.913200 791.773680 6208.200000 25719.495200 426815.982588 6429271.046000 42468024.930000 212006462.910000 6579.048000", buffer);
}
void test_case_c_string_g_g()
{
CLEAN_BUFFER;
sprintf(buffer, "%g %g %g %g %g %g %g %g %g %g", FLOATS);
TEST_ASSERT_EQUAL_STRING("0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+06 4.2468e+07 2.12006e+08", buffer);
sprintf(buffer, "%g %g %g %g %g %g %g %g %g %g %g", FLOATS);
TEST_ASSERT_EQUAL_STRING("0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+06 4.2468e+07 2.12006e+08 6579.05", buffer);
}
void test_case_c_string_e_E()
{
CLEAN_BUFFER;
sprintf(buffer, "%e %E %e %E %e %E %e %E %e %E", FLOATS);
TEST_ASSERT_EQUAL_STRING("2.000000e-03 9.243000E-01 1.591320e+01 7.917737E+02 6.208200e+03 2.571950E+04 4.268160e+05 6.429271E+06 4.246802e+07 2.120065E+08", buffer);
sprintf(buffer, "%e %E %e %E %e %E %e %E %e %E %e", FLOATS);
TEST_ASSERT_EQUAL_STRING("2.000000e-03 9.243000E-01 1.591320e+01 7.917737E+02 6.208200e+03 2.571950E+04 4.268160e+05 6.429271E+06 4.246802e+07 2.120065E+08 6.579048e+03", buffer);
}
void test_case_c_string_strtok()
@ -112,10 +112,12 @@ Case cases[] = {
Case("C strings: strpbrk", test_case_c_string_strpbrk, greentea_failure_handler),
Case("C strings: %i %d integer formatting", test_case_c_string_i_d, greentea_failure_handler),
Case("C strings: %u %d integer formatting", test_case_c_string_u_d, greentea_failure_handler),
Case("C strings: %x %E integer formatting", test_case_c_string_x_E, greentea_failure_handler),
Case("C strings: %x %E integer formatting", test_case_c_string_x_X, greentea_failure_handler),
Case("C strings: %f %f float formatting", test_case_c_string_f_f, greentea_failure_handler),
#ifndef MBED_MINIMAL_PRINTF
Case("C strings: %e %E float formatting", test_case_c_string_e_E, greentea_failure_handler),
Case("C strings: %g %g float formatting", test_case_c_string_g_g, greentea_failure_handler),
#endif
};
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)

View File

@ -1,118 +0,0 @@
// Jenkins configuration.
properties ([
buildDiscarder(
logRotator(artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '30',
numToKeepStr: '100'
)
)
])
// RaaS credentials and settings.
raas_username = "ci"
raas_password = "ci"
raas_timeout = 1200
// Test combinations, for each listed target, each toolchain is build and tested on RaaS instance.
targets = [
"K64F": ["toolchains": [ "ARM", "IAR", "GCC_ARM"], "raas": "https://eeva.mbedcloudtesting.com"],
"NUCLEO_F429ZI": ["toolchains": [ "ARM", "IAR", "GCC_ARM"], "raas": "https://ruka.mbedcloudtesting.com"],
]
// Map toolchains to compiler labels to find suitable node on Jenkins.
def nodes = [
ARM: "armcc",
IAR: "iar_arm",
GCC_ARM: "arm-none-eabi-gcc",
SXOS: "linux"
]
// Initial maps for parallel build steps
def buildStepsForParallel = [:]
def testStepsForParallel = [:]
for (target in targets.keySet()) {
for (toolchain_key in targets[target]["toolchains"]) {
echo "Include for build: ${target} ${toolchain_key}"
def stepName = "${target} ${toolchain_key}"
buildStepsForParallel[stepName] = buildStep(target, nodes[toolchain_key], toolchain_key)
}
}
for (target in targets.keySet()) {
for (toolchain_key in targets[target]["toolchains"]) {
echo "Include for test: ${target} ${toolchain_key}"
def stepName = "${target} ${toolchain_key}"
testStepsForParallel[stepName] = testStep(target, nodes[toolchain_key], toolchain_key)
}
}
// Actually run the steps in parallel - parallel takes a map as an argument, hence the above.
timestamps {
parallel buildStepsForParallel
parallel testStepsForParallel
}
// Create build steps for parallel execution.
def buildStep(target, compilerLabel, toolchain) {
return {
stage("Build_${target}_${toolchain}") {
node("${compilerLabel}") {
deleteDir()
echo "buildStep: ${target} ${compilerLabel} ${toolchain}"
dir("test") {
// checkout PR.
checkout scm
// remove wrapper file so we don't compare minimal-printf with itself.
sh "rm ./mbed_printf_wrapper.c"
// checkout newest Mbed OS release.
sh "mbed new ."
// use default release profile for ARM and IAR.
sh "mbed test -vv --compile -m ${target} -t ${toolchain} -n '*minimal-printf*' --build ci --stats-depth 10 --app-config ./TESTS/minimal-printf/compliance/test_app.json"
// stash build directory for testins step.
stash name: "minimal-printf-greentea-${target}-${toolchain}", includes: "ci/**"
}
step([$class: 'WsCleanup'])
}
}
}
}
def testStep(target, compilerLabel, toolchain) {
return {
stage("Light suite ${target}_${toolchain}") {
node("${compilerLabel}") {
deleteDir()
echo "testStep: ${target} ${toolchain}"
// unstash build directory containing greentea tests.
unstash "minimal-printf-greentea-${target}-${toolchain}"
// setup RaaS environment.
env.RAAS_USERNAME = raas_username
env.RAAS_PASSWORD = raas_password
env.RAAS_PYCLIENT_FORCE_REMOTE_ALLOCATION = 1
env.RAAS_PYCLIENT_ALLOCATION_QUEUE_TIMEOUT = raas_timeout
raas = targets[target]["raas"]
// execute greentea on RaaS.
execute("mbedgt -g ${target}:raas_client:${raas}:443 -vV --test-spec ./ci/test_spec.json --polling-timeout 240")
// Clean up workarea.
step([$class: 'WsCleanup'])
}
}
}
}

View File

@ -3,7 +3,7 @@
Library supports both printf and snprintf in 1252 bytes of flash.
Prints directly to stdio/UART without using malloc. All flags and precision modifiers are ignored.
Floating point is disabled by default.
Floating point is enabled by default.
Printing to a FILE stream is enabled by default.
Supports:
@ -23,29 +23,27 @@ Supports:
Unrecognized format specifiers are treated as ordinary characters.
Floating point support:
* Floating point is disabled by default.
* Floating point is enabled by default.
* All floating points are treated as %f.
* No support for inf, infinity or nan
To replace the standard implementations of the printf functions with the ones in this library:
## Usage
* Add the library to your project.
* Compile with mbed-cli using one of the custom profiles in the `profiles/` subdirectory. For
example, to compile in release mode:
To replace the standard implementation of the printf functions with the ones in this library:
Compile with mbed-cli using the custom `mprintf` profile. For example, to compile in release mode:
```
$ mbed compile -t <toolchain> -m <target> --profile mbed-printf/profiles/release.json
$ mbed compile -t <toolchain> -m <target> --profile release --profile mprintf
```
## Enabling floating point, FILE stream, 64 bit integers, new line conversion, and setting baud rate
## Enabling FILE stream, floating point and 64 bit integers
In mbed_app.json:
```
"target_overrides": {
"*": {
"platform.stdio-baud-rate": 115200,
"platform.stdio-convert-newlines": false,
"minimal-printf.enable-file-stream": true,
"minimal-printf.enable-floating-point": true,
"minimal-printf.set-floating-point-max-decimals": 6,

View File

@ -0,0 +1,11 @@
# Description
This document describes how to run minimal-printf tests.
## Running tests
You can use the following command to run tests:
`mbed test -m K64F -t GCC_ARM -n *printf* -v -c`
Do not use --profile mprintf so minimal-printf is not compared with itself.

View File

@ -15,7 +15,7 @@
},
"enable-floating-point": {
"help": "Enable floating point printing",
"value": false
"value": true
},
"set-floating-point-max-decimals": {
"help": "Maximum number of decimals to be printed",

View File

@ -1,64 +0,0 @@
{
"GCC_ARM": {
"common": ["-c", "-Wall", "-Wextra",
"-Wno-unused-parameter", "-Wno-missing-field-initializers",
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
"-ffunction-sections", "-fdata-sections", "-funsigned-char",
"-MMD", "-fno-delete-null-pointer-checks",
"-fomit-frame-pointer", "-O0", "-g3", "-DMBED_DEBUG",
"-DMBED_TRAP_ERRORS_ENABLED=1"],
"asm": ["-x", "assembler-with-cpp"],
"c": ["-std=gnu99"],
"cxx": ["-std=gnu++98", "-fno-rtti", "-Wvla"],
"ld": ["-Wl,--gc-sections", "-Wl,--wrap,main", "-Wl,--wrap,_malloc_r",
"-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_memalign_r",
"-Wl,--wrap,_calloc_r", "-Wl,--wrap,exit", "-Wl,--wrap,atexit",
"-Wl,-n",
"-Wl,--wrap,printf", "-Wl,--wrap,sprintf", "-Wl,--wrap,snprintf",
"-Wl,--wrap,vprintf", "-Wl,--wrap,vsprintf", "-Wl,--wrap,vsnprintf",
"-Wl,--wrap,fprintf", "-Wl,--wrap,vfprintf"]
},
"ARMC6": {
"common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-g", "-O1",
"-Wno-armcc-pragma-push-pop", "-Wno-armcc-pragma-anon-unions",
"-DMULADDC_CANNOT_USE_R7", "-fdata-sections",
"-fno-exceptions", "-MMD", "-D_LIBCPP_EXTERN_TEMPLATE(...)=",
"-fshort-enums", "-fshort-wchar", "-DMBED_DEBUG",
"-DMBED_TRAP_ERRORS_ENABLED=1", "--ide=mbed"],
"asm": ["--ide=mbed"],
"c": ["-D__ASSERT_MSG", "-std=gnu99"],
"cxx": ["-fno-rtti", "-std=gnu++98"],
"ld": ["--verbose", "--remove", "--show_full_path", "--legacyalign", "--keep=os_cb_sections"]
},
"ARM": {
"common": ["-c", "--gnu", "-Otime", "--split_sections",
"--apcs=interwork", "--brief_diagnostics", "--restrict",
"--multibyte_chars", "-O0", "-g", "-DMBED_DEBUG",
"-DMBED_TRAP_ERRORS_ENABLED=1"],
"asm": [],
"c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
"cxx": ["--cpp", "--no_rtti", "--no_vla"],
"ld": ["--show_full_path", "--keep=os_cb_sections"]
},
"uARM": {
"common": ["-c", "--gnu", "-Otime", "--split_sections",
"--apcs=interwork", "--brief_diagnostics", "--restrict",
"--multibyte_chars", "-O0", "-D__MICROLIB", "-g",
"--library_type=microlib", "-DMBED_RTOS_SINGLE_THREAD", "-DMBED_DEBUG",
"-DMBED_TRAP_ERRORS_ENABLED=1"],
"asm": [],
"c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
"cxx": ["--cpp", "--no_rtti", "--no_vla"],
"ld": ["--library_type=microlib"]
},
"IAR": {
"common": [
"--no_wrap_diagnostics", "-e",
"--diag_suppress=Pa050,Pa084,Pa093,Pa082", "-On", "-r", "-DMBED_DEBUG",
"-DMBED_TRAP_ERRORS_ENABLED=1", "--enable_restrict"],
"asm": [],
"c": ["--vla", "--diag_suppress=Pe546"],
"cxx": ["--guard_calls", "--no_static_destruction"],
"ld": ["--skip_dynamic_initialization", "--threaded_lib"]
}
}

View File

@ -1,61 +0,0 @@
{
"GCC_ARM": {
"common": ["-c", "-Wall", "-Wextra",
"-Wno-unused-parameter", "-Wno-missing-field-initializers",
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
"-ffunction-sections", "-fdata-sections", "-funsigned-char",
"-MMD", "-fno-delete-null-pointer-checks",
"-fomit-frame-pointer", "-Os", "-g1", "-DMBED_TRAP_ERRORS_ENABLED=1"],
"asm": ["-x", "assembler-with-cpp"],
"c": ["-std=gnu99"],
"cxx": ["-std=gnu++98", "-fno-rtti", "-Wvla"],
"ld": ["-Wl,--gc-sections", "-Wl,--wrap,main", "-Wl,--wrap,_malloc_r",
"-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_memalign_r",
"-Wl,--wrap,_calloc_r", "-Wl,--wrap,exit", "-Wl,--wrap,atexit",
"-Wl,-n",
"-Wl,--wrap,printf", "-Wl,--wrap,sprintf", "-Wl,--wrap,snprintf",
"-Wl,--wrap,vprintf", "-Wl,--wrap,vsprintf", "-Wl,--wrap,vsnprintf",
"-Wl,--wrap,fprintf", "-Wl,--wrap,vfprintf"]
},
"ARMC6": {
"common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Os",
"-Wno-armcc-pragma-push-pop", "-Wno-armcc-pragma-anon-unions",
"-DMULADDC_CANNOT_USE_R7", "-fdata-sections",
"-fno-exceptions", "-MMD", "-D_LIBCPP_EXTERN_TEMPLATE(...)=",
"-fshort-enums", "-fshort-wchar", "-DMBED_TRAP_ERRORS_ENABLED=1", "--ide=mbed"],
"asm": ["--ide=mbed"],
"c": ["-D__ASSERT_MSG", "-std=gnu99"],
"cxx": ["-fno-rtti", "-std=gnu++98"],
"ld": ["--show_full_path", "--legacyalign", "--keep=os_cb_sections"]
},
"ARM": {
"common": ["-c", "--gnu", "-Otime", "--split_sections",
"--apcs=interwork", "--brief_diagnostics", "--restrict",
"--multibyte_chars", "-O3", "-DMBED_TRAP_ERRORS_ENABLED=1"],
"asm": [],
"c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
"cxx": ["--cpp", "--no_rtti", "--no_vla"],
"ld": ["--show_full_path", "--keep=os_cb_sections"]
},
"uARM": {
"common": ["-c", "--gnu", "-Otime", "--split_sections",
"--apcs=interwork", "--brief_diagnostics", "--restrict",
"--multibyte_chars", "-O3", "-D__MICROLIB",
"--library_type=microlib", "-DMBED_RTOS_SINGLE_THREAD",
"-DMBED_TRAP_ERRORS_ENABLED=1"],
"asm": [],
"c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
"cxx": ["--cpp", "--no_rtti", "--no_vla"],
"ld": ["--library_type=microlib"]
},
"IAR": {
"common": [
"--no_wrap_diagnostics", "-e",
"--diag_suppress=Pa050,Pa084,Pa093,Pa082", "-Oh", "--enable_restrict",
"-DMBED_TRAP_ERRORS_ENABLED=1"],
"asm": [],
"c": ["--vla", "--diag_suppress=Pe546"],
"cxx": ["--guard_calls", "--no_static_destruction"],
"ld": ["--skip_dynamic_initialization", "--threaded_lib"]
}
}

View File

@ -1,59 +0,0 @@
{
"GCC_ARM": {
"common": ["-c", "-Wall", "-Wextra",
"-Wno-unused-parameter", "-Wno-missing-field-initializers",
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
"-ffunction-sections", "-fdata-sections", "-funsigned-char",
"-MMD", "-fno-delete-null-pointer-checks",
"-fomit-frame-pointer", "-Os", "-DNDEBUG", "-g1"],
"asm": ["-x", "assembler-with-cpp"],
"c": ["-std=gnu99"],
"cxx": ["-std=gnu++98", "-fno-rtti", "-Wvla"],
"ld": ["-Wl,--gc-sections", "-Wl,--wrap,main", "-Wl,--wrap,_malloc_r",
"-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_memalign_r",
"-Wl,--wrap,_calloc_r", "-Wl,--wrap,exit", "-Wl,--wrap,atexit",
"-Wl,-n",
"-Wl,--wrap,printf", "-Wl,--wrap,sprintf", "-Wl,--wrap,snprintf",
"-Wl,--wrap,vprintf", "-Wl,--wrap,vsprintf", "-Wl,--wrap,vsnprintf",
"-Wl,--wrap,fprintf", "-Wl,--wrap,vfprintf"]
},
"ARMC6": {
"common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Oz",
"-Wno-armcc-pragma-push-pop", "-Wno-armcc-pragma-anon-unions",
"-DMULADDC_CANNOT_USE_R7", "-fdata-sections",
"-fno-exceptions", "-MMD", "-D_LIBCPP_EXTERN_TEMPLATE(...)=",
"-fshort-enums", "-fshort-wchar", "-DNDEBUG", "--ide=mbed"],
"asm": ["--ide=mbed"],
"c": ["-D__ASSERT_MSG", "-std=gnu99"],
"cxx": ["-fno-rtti", "-std=gnu++98"],
"ld": ["--show_full_path", "--legacyalign"]
},
"ARM": {
"common": ["-c", "--gnu", "-Ospace", "--split_sections",
"--apcs=interwork", "--brief_diagnostics", "--restrict",
"--multibyte_chars", "-O3", "-DNDEBUG"],
"asm": [],
"c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
"cxx": ["--cpp", "--no_rtti", "--no_vla"],
"ld": ["--show_full_path", "--keep=os_cb_sections"]
},
"uARM": {
"common": ["-c", "--gnu", "-Ospace", "--split_sections",
"--apcs=interwork", "--brief_diagnostics", "--restrict",
"--multibyte_chars", "-O3", "-D__MICROLIB",
"--library_type=microlib", "-DMBED_RTOS_SINGLE_THREAD", "-DNDEBUG"],
"asm": [],
"c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
"cxx": ["--cpp", "--no_rtti", "--no_vla"],
"ld": ["--library_type=microlib"]
},
"IAR": {
"common": [
"--no_wrap_diagnostics", "-e",
"--diag_suppress=Pa050,Pa084,Pa093,Pa082", "-Ohz", "-DNDEBUG", "--enable_restrict"],
"asm": [],
"c": ["--vla", "--diag_suppress=Pe546"],
"cxx": ["--guard_calls", "--no_static_destruction"],
"ld": ["--skip_dynamic_initialization", "--threaded_lib"]
}
}

View File

@ -1,4 +1,4 @@
{
"name": "bare-metal",
"requires": ["platform", "drivers"]
"requires": ["platform", "drivers", "minimal-printf"]
}

View File

@ -0,0 +1,8 @@
{
"GCC_ARM": {
"common": ["-DMBED_MINIMAL_PRINTF"],
"ld": ["-Wl,--wrap,printf", "-Wl,--wrap,sprintf", "-Wl,--wrap,snprintf",
"-Wl,--wrap,vprintf", "-Wl,--wrap,vsprintf", "-Wl,--wrap,vsnprintf",
"-Wl,--wrap,fprintf", "-Wl,--wrap,vfprintf"]
}
}