lib/os/cbprintf_nano.c: several improvements
This makes cbprintf_nano.c much closer to the standard printf and therefore more useful. The following are now implemented: - right justification for everything (only for numbers previously) - precision value for numbers, chars and strings - width/precision passed as arguments with * - "unlimited" padding length - lower/uppercase hex output - the #, + and ' ' flags are supported And the code was heavily reworked to reduce its size as much as possible to mitigate the size growth. Still, the binary resulting from cbprintf_nano.c is now between 10% and 20% bigger depending on the architecture. This is still far smaller than cbprintf_complete.c which remains about twice as big on average even without FP support. Many unit tests that were skipped with CONFIG_CBPRINTF_NANO are now enabled, and a few more were added for good measure. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
99425de387
commit
fb73ac392c
3 changed files with 292 additions and 317 deletions
|
@ -1,41 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2013-2014 Wind River Systems, Inc.
|
||||
* Copyright (c) 2020 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2021 BayLibre, SAS
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/cbprintf.h>
|
||||
#include <toolchain.h>
|
||||
#include <linker/sections.h>
|
||||
#include <syscall_handler.h>
|
||||
#include <logging/log.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
enum pad_type {
|
||||
PAD_NONE,
|
||||
PAD_ZERO_BEFORE,
|
||||
PAD_SPACE_BEFORE,
|
||||
PAD_SPACE_AFTER,
|
||||
};
|
||||
#include <sys/util.h>
|
||||
|
||||
#ifdef CONFIG_CBPRINTF_FULL_INTEGRAL
|
||||
typedef intmax_t int_value_type;
|
||||
typedef uintmax_t uint_value_type;
|
||||
#define DIGITS_BUFLEN 21
|
||||
BUILD_ASSERT(sizeof(uint_value_type) <= 8U,
|
||||
"DIGITS_BUFLEN may be incorrect");
|
||||
#else
|
||||
typedef int32_t int_value_type;
|
||||
typedef uint32_t uint_value_type;
|
||||
#define DIGITS_BUFLEN 10
|
||||
#endif
|
||||
|
||||
/* Maximum number of digits in a printed decimal value (hex is always
|
||||
* less, obviously). Funny formula produces 10 max digits for 32 bit,
|
||||
* 21 for 64. It may be incorrect for other value lengths.
|
||||
*/
|
||||
#define DIGITS_BUFLEN (11U * (sizeof(uint_value_type) / 4U) - 1U)
|
||||
#define ALPHA(fmt) (((fmt) & 0x60) - '0' - 10 + 1)
|
||||
|
||||
BUILD_ASSERT(sizeof(uint_value_type) <= 8U,
|
||||
"DIGITS_BUFLEN formula may be incorrect");
|
||||
/* Convert value to string, storing characters downwards */
|
||||
static inline int convert_value(uint_value_type num, unsigned int base,
|
||||
unsigned int alpha, char *buftop)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
unsigned int c = num % base;
|
||||
if (c >= 10) {
|
||||
c += alpha;
|
||||
}
|
||||
buftop[--i] = c + '0';
|
||||
num /= base;
|
||||
} while (num);
|
||||
|
||||
return -i;
|
||||
}
|
||||
|
||||
#define OUTC(_c) do { \
|
||||
out((int)(_c), ctx); \
|
||||
|
@ -44,76 +52,8 @@ BUILD_ASSERT(sizeof(uint_value_type) <= 8U,
|
|||
} \
|
||||
} while (false)
|
||||
|
||||
static void print_digits(cbprintf_cb out, void *ctx, uint_value_type num,
|
||||
unsigned int base, bool pad_before, char pad_char,
|
||||
int min_width, size_t *countp)
|
||||
{
|
||||
size_t count = 0;
|
||||
char buf[DIGITS_BUFLEN];
|
||||
int i = 0;
|
||||
|
||||
/* Print it backwards, low digits first */
|
||||
do {
|
||||
char c = num % base;
|
||||
if (c >= 10) {
|
||||
c += 'a' - '0' - 10;
|
||||
}
|
||||
buf[i++] = c + '0';
|
||||
num /= base;
|
||||
} while (num);
|
||||
|
||||
int pad = MAX(min_width - i, 0);
|
||||
|
||||
for (/**/; pad > 0 && pad_before; pad--) {
|
||||
OUTC(pad_char);
|
||||
}
|
||||
do {
|
||||
OUTC(buf[--i]);
|
||||
} while (i > 0);
|
||||
for (/**/; pad > 0; pad--) {
|
||||
OUTC(pad_char);
|
||||
}
|
||||
|
||||
*countp += count;
|
||||
}
|
||||
|
||||
static void print_hex(cbprintf_cb out, void *ctx, uint_value_type num,
|
||||
enum pad_type padding, int min_width, size_t *countp)
|
||||
{
|
||||
print_digits(out, ctx, num, 16U, padding != PAD_SPACE_AFTER,
|
||||
padding == PAD_ZERO_BEFORE ? '0' : ' ', min_width,
|
||||
countp);
|
||||
}
|
||||
|
||||
static void print_dec(cbprintf_cb out, void *ctx, uint_value_type num,
|
||||
enum pad_type padding, int min_width, size_t *countp)
|
||||
{
|
||||
print_digits(out, ctx, num, 10U, padding != PAD_SPACE_AFTER,
|
||||
padding == PAD_ZERO_BEFORE ? '0' : ' ', min_width,
|
||||
countp);
|
||||
}
|
||||
|
||||
static bool ok64(cbprintf_cb out, void *ctx, long long val, size_t *countp)
|
||||
{
|
||||
size_t count = 0;
|
||||
|
||||
if (sizeof(int_value_type) < 8U && val != (int_value_type) val) {
|
||||
const char *cp = "ERR";
|
||||
do {
|
||||
OUTC(*cp++);
|
||||
} while (*cp);
|
||||
*countp += count;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool negative(uint_value_type val)
|
||||
{
|
||||
const uint_value_type hibit = ~(((uint_value_type) ~1) >> 1U);
|
||||
|
||||
return (val & hibit) != 0U;
|
||||
}
|
||||
#define PAD_ZERO BIT(0)
|
||||
#define PAD_TAIL BIT(1)
|
||||
|
||||
/**
|
||||
* @brief Printk internals
|
||||
|
@ -122,38 +62,59 @@ static bool negative(uint_value_type val)
|
|||
* @param fmt Format string
|
||||
* @param ap Variable parameters
|
||||
*
|
||||
* @return N/A
|
||||
* @return printed byte count if CONFIG_CBPRINTF_LIBC_SUBSTS is set
|
||||
*/
|
||||
int cbvprintf(cbprintf_cb out, void *ctx, const char *fmt, va_list ap)
|
||||
{
|
||||
size_t count = 0;
|
||||
int might_format = 0; /* 1 if encountered a '%' */
|
||||
enum pad_type padding = PAD_NONE;
|
||||
int padlen, min_width = -1;
|
||||
char length_mod = 0;
|
||||
char buf[DIGITS_BUFLEN];
|
||||
char *prefix, *data;
|
||||
int min_width, precision, data_len;
|
||||
char padding_mode, length_mod, special;
|
||||
|
||||
/* fmt has already been adjusted if needed */
|
||||
while (*fmt) {
|
||||
if (!might_format) {
|
||||
if (*fmt != '%') {
|
||||
OUTC(*fmt);
|
||||
} else {
|
||||
might_format = 1;
|
||||
min_width = -1;
|
||||
padding = PAD_NONE;
|
||||
length_mod = 0;
|
||||
/* we pre-increment in the loop afterwards */
|
||||
fmt--;
|
||||
|
||||
start:
|
||||
while (*++fmt != '%') {
|
||||
if (*fmt == 0) {
|
||||
return count;
|
||||
}
|
||||
} else {
|
||||
OUTC(*fmt);
|
||||
}
|
||||
|
||||
min_width = -1;
|
||||
precision = -1;
|
||||
prefix = "";
|
||||
padding_mode = 0;
|
||||
length_mod = 0;
|
||||
special = 0;
|
||||
|
||||
for (fmt++ ; ; fmt++) {
|
||||
switch (*fmt) {
|
||||
case 0:
|
||||
return count;
|
||||
|
||||
case '%':
|
||||
OUTC('%');
|
||||
goto start;
|
||||
|
||||
case '-':
|
||||
padding = PAD_SPACE_AFTER;
|
||||
goto still_might_format;
|
||||
padding_mode = PAD_TAIL;
|
||||
continue;
|
||||
|
||||
case '.':
|
||||
precision = 0;
|
||||
padding_mode &= ~PAD_ZERO;
|
||||
continue;
|
||||
|
||||
case '0':
|
||||
if (min_width < 0 && padding == PAD_NONE) {
|
||||
padding = PAD_ZERO_BEFORE;
|
||||
goto still_might_format;
|
||||
if (min_width < 0 && precision < 0 && !padding_mode) {
|
||||
padding_mode = PAD_ZERO;
|
||||
continue;
|
||||
}
|
||||
__fallthrough;
|
||||
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
|
@ -163,15 +124,34 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fmt, va_list ap)
|
|||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (precision >= 0) {
|
||||
precision = 10 * precision + *fmt - '0';
|
||||
} else {
|
||||
if (min_width < 0) {
|
||||
min_width = 0;
|
||||
}
|
||||
min_width = 10 * min_width + *fmt - '0';
|
||||
|
||||
if (padding == PAD_NONE) {
|
||||
padding = PAD_SPACE_BEFORE;
|
||||
}
|
||||
goto still_might_format;
|
||||
continue;
|
||||
|
||||
case '*':
|
||||
if (precision >= 0) {
|
||||
precision = va_arg(ap, int);
|
||||
} else {
|
||||
min_width = va_arg(ap, int);
|
||||
if (min_width < 0) {
|
||||
min_width = -min_width;
|
||||
padding_mode = PAD_TAIL;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
||||
case '+':
|
||||
case ' ':
|
||||
case '#':
|
||||
special = *fmt;
|
||||
continue;
|
||||
|
||||
case 'h':
|
||||
case 'l':
|
||||
case 'z':
|
||||
|
@ -184,9 +164,10 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fmt, va_list ap)
|
|||
} else {
|
||||
OUTC('%');
|
||||
OUTC(*fmt);
|
||||
break;
|
||||
goto start;
|
||||
}
|
||||
goto still_might_format;
|
||||
continue;
|
||||
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u': {
|
||||
|
@ -197,10 +178,13 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fmt, va_list ap)
|
|||
} else if (length_mod == 'l') {
|
||||
d = va_arg(ap, long);
|
||||
} else if (length_mod == 'L') {
|
||||
long long lld = va_arg(ap, long long);
|
||||
|
||||
long long lld = va_arg(ap,
|
||||
long long);
|
||||
if (!ok64(out, ctx, lld, &count)) {
|
||||
if (sizeof(int_value_type) < 8U &&
|
||||
lld != (int_value_type) lld) {
|
||||
data = "ERR";
|
||||
data_len = 3;
|
||||
precision = 0;
|
||||
break;
|
||||
}
|
||||
d = (uint_value_type) lld;
|
||||
|
@ -210,38 +194,36 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fmt, va_list ap)
|
|||
d = va_arg(ap, int);
|
||||
}
|
||||
|
||||
if (*fmt != 'u' && negative(d)) {
|
||||
OUTC('-');
|
||||
if (*fmt != 'u' && (int_value_type)d < 0) {
|
||||
d = -d;
|
||||
prefix = "-";
|
||||
min_width--;
|
||||
} else if (special == ' ') {
|
||||
prefix = " ";
|
||||
min_width--;
|
||||
} else if (special == '+') {
|
||||
prefix = "+";
|
||||
min_width--;
|
||||
}
|
||||
print_dec(out, ctx, d, padding, min_width,
|
||||
&count);
|
||||
data_len = convert_value(d, 10, 0, buf + sizeof(buf));
|
||||
data = buf + sizeof(buf) - data_len;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'p':
|
||||
case 'x':
|
||||
case 'X': {
|
||||
uint_value_type x;
|
||||
|
||||
if (*fmt == 'p') {
|
||||
const char *cp;
|
||||
|
||||
x = (uintptr_t)va_arg(ap, void *);
|
||||
if (x == 0) {
|
||||
cp = "(nil)";
|
||||
} else {
|
||||
cp = "0x";
|
||||
data = "(nil)";
|
||||
data_len = 5;
|
||||
precision = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
do {
|
||||
OUTC(*cp++);
|
||||
} while (*cp);
|
||||
if (x == 0) {
|
||||
padlen = min_width - 5;
|
||||
goto pad_string;
|
||||
}
|
||||
min_width -= 2;
|
||||
special = '#';
|
||||
} else if (length_mod == 'l') {
|
||||
x = va_arg(ap, unsigned long);
|
||||
} else if (length_mod == 'L') {
|
||||
|
@ -249,48 +231,69 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fmt, va_list ap)
|
|||
} else {
|
||||
x = va_arg(ap, unsigned int);
|
||||
}
|
||||
|
||||
print_hex(out, ctx, x, padding, min_width,
|
||||
&count);
|
||||
if (special == '#') {
|
||||
prefix = (*fmt & 0x20) ? "0x" : "0X";
|
||||
min_width -= 2;
|
||||
}
|
||||
data_len = convert_value(x, 16, ALPHA(*fmt),
|
||||
buf + sizeof(buf));
|
||||
data = buf + sizeof(buf) - data_len;
|
||||
break;
|
||||
}
|
||||
|
||||
case 's': {
|
||||
char *s = va_arg(ap, char *);
|
||||
char *start = s;
|
||||
|
||||
while (*s) {
|
||||
OUTC(*s++);
|
||||
}
|
||||
padlen = min_width - (s - start);
|
||||
|
||||
pad_string:
|
||||
if (padding == PAD_SPACE_AFTER) {
|
||||
while (padlen-- > 0) {
|
||||
OUTC(' ');
|
||||
}
|
||||
data = va_arg(ap, char *);
|
||||
data_len = strlen(data);
|
||||
if (precision >= 0 && data_len > precision) {
|
||||
data_len = precision;
|
||||
}
|
||||
precision = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'c': {
|
||||
int c = va_arg(ap, int);
|
||||
|
||||
OUTC(c);
|
||||
break;
|
||||
}
|
||||
case '%': {
|
||||
OUTC('%');
|
||||
buf[0] = c;
|
||||
data = buf;
|
||||
data_len = 1;
|
||||
precision = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
OUTC('%');
|
||||
OUTC(*fmt);
|
||||
break;
|
||||
}
|
||||
might_format = 0;
|
||||
}
|
||||
still_might_format:
|
||||
++fmt;
|
||||
goto start;
|
||||
}
|
||||
|
||||
return count;
|
||||
if (precision < 0 && (padding_mode & PAD_ZERO)) {
|
||||
precision = min_width;
|
||||
}
|
||||
min_width -= data_len;
|
||||
precision -= data_len;
|
||||
if (precision > 0) {
|
||||
min_width -= precision;
|
||||
}
|
||||
|
||||
if (!(padding_mode & PAD_TAIL)) {
|
||||
while (--min_width >= 0) {
|
||||
OUTC(' ');
|
||||
}
|
||||
}
|
||||
while (*prefix) {
|
||||
OUTC(*prefix++);
|
||||
}
|
||||
while (--precision >= 0) {
|
||||
OUTC('0');
|
||||
}
|
||||
while (--data_len >= 0) {
|
||||
OUTC(*data++);
|
||||
}
|
||||
while (--min_width >= 0) {
|
||||
OUTC(' ');
|
||||
}
|
||||
|
||||
goto start;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,8 +117,7 @@ static void help_item_print(const struct shell *shell, const char *item_name,
|
|||
}
|
||||
|
||||
if (!IS_ENABLED(CONFIG_NEWLIB_LIBC) &&
|
||||
!IS_ENABLED(CONFIG_ARCH_POSIX) &&
|
||||
!IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
!IS_ENABLED(CONFIG_ARCH_POSIX)) {
|
||||
/* print option name */
|
||||
z_shell_fprintf(shell, SHELL_NORMAL, "%s%-*s%s:", tabulator,
|
||||
item_name_width, item_name, tabulator);
|
||||
|
|
|
@ -301,18 +301,6 @@ static void test_c(void)
|
|||
rc = TEST_PRF("%c", 'a');
|
||||
PRF_CHECK("a", rc);
|
||||
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
TC_PRINT("short test for nano\n");
|
||||
return;
|
||||
}
|
||||
|
||||
rc = TEST_PRF("%lc", (wint_t)'a');
|
||||
if (ENABLED_USE_LIBC) {
|
||||
PRF_CHECK("a", rc);
|
||||
} else {
|
||||
PRF_CHECK("%lc", rc);
|
||||
}
|
||||
|
||||
rc = prf("/%256c/", 'a');
|
||||
|
||||
const char *bp = buf;
|
||||
|
@ -328,6 +316,18 @@ static void test_c(void)
|
|||
zassert_equal(*bp, 'a', NULL);
|
||||
++bp;
|
||||
zassert_equal(*bp, '/', NULL);
|
||||
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
TC_PRINT("short test for nano\n");
|
||||
return;
|
||||
}
|
||||
|
||||
rc = TEST_PRF("%lc", (wint_t)'a');
|
||||
if (ENABLED_USE_LIBC) {
|
||||
PRF_CHECK("a", rc);
|
||||
} else {
|
||||
PRF_CHECK("%lc", rc);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_s(void)
|
||||
|
@ -340,20 +340,16 @@ static void test_s(void)
|
|||
PRF_CHECK("/123/", rc);
|
||||
|
||||
rc = TEST_PRF("/%6s/%-6s/%2s/", s, s, s);
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
PRF_CHECK("/ 123/123 /123/", rc);
|
||||
} else {
|
||||
PRF_CHECK("/ 123/123 /123/", rc);
|
||||
}
|
||||
|
||||
rc = TEST_PRF("/%.6s/%.2s/%.s/", s, s, s);
|
||||
PRF_CHECK("/123/12//", rc);
|
||||
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
TC_PRINT("short test for nano\n");
|
||||
return;
|
||||
}
|
||||
|
||||
rc = TEST_PRF("/%.6s/%.2s/%.s/", s, s, s);
|
||||
PRF_CHECK("/123/12//", rc);
|
||||
|
||||
rc = TEST_PRF("%ls", ws);
|
||||
if (ENABLED_USE_LIBC) {
|
||||
PRF_CHECK("abc", rc);
|
||||
|
@ -381,11 +377,15 @@ static void test_d_length(void)
|
|||
int min = -1234567890;
|
||||
int max = 1876543210;
|
||||
long long svll = 123LL << 48;
|
||||
long long svll2 = -2LL;
|
||||
int rc;
|
||||
|
||||
rc = TEST_PRF("%d/%d", min, max);
|
||||
PRF_CHECK("-1234567890/1876543210", rc);
|
||||
|
||||
rc = TEST_PRF("%u/%u", min, max);
|
||||
PRF_CHECK("3060399406/1876543210", rc);
|
||||
|
||||
if (!IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
rc = TEST_PRF("%hd/%hd", min, max);
|
||||
PRF_CHECK("-722/-14614", rc);
|
||||
|
@ -403,13 +403,13 @@ static void test_d_length(void)
|
|||
PRF_CHECK("%ld/%ld", rc);
|
||||
}
|
||||
|
||||
rc = TEST_PRF("/%lld/%lld/", svll, -svll);
|
||||
rc = TEST_PRF("/%lld/%lld/%lld/", svll, -svll, svll2);
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_FULL_INTEGRAL)) {
|
||||
PRF_CHECK("/34621422135410688/-34621422135410688/", rc);
|
||||
PRF_CHECK("/34621422135410688/-34621422135410688/-2/", rc);
|
||||
} else if (IS_ENABLED(CONFIG_CBPRINTF_COMPLETE)) {
|
||||
PRF_CHECK("/%lld/%lld/", rc);
|
||||
PRF_CHECK("/%lld/%lld/%lld/", rc);
|
||||
} else if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
PRF_CHECK("/ERR/ERR/", rc);
|
||||
PRF_CHECK("/ERR/ERR/-2/", rc);
|
||||
} else {
|
||||
zassert_true(false, "Missed case!");
|
||||
}
|
||||
|
@ -459,11 +459,6 @@ static void test_d_flags(void)
|
|||
int sv = 123;
|
||||
int rc;
|
||||
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
TC_PRINT("skipped test for nano\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Stuff related to sign */
|
||||
rc = TEST_PRF("/%d/%-d/%+d/% d/",
|
||||
sv, sv, sv, sv);
|
||||
|
@ -512,10 +507,15 @@ static void test_x_length(void)
|
|||
int rc;
|
||||
|
||||
rc = TEST_PRF("%x/%X", min, max);
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
PRF_CHECK("4c3c2c1c/4d3d2d1d", rc);
|
||||
} else {
|
||||
PRF_CHECK("4c3c2c1c/4D3D2D1D", rc);
|
||||
|
||||
rc = TEST_PRF("%lx/%lX", (unsigned long)min, (unsigned long)max);
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_FULL_INTEGRAL)
|
||||
|| (sizeof(long) <= 4)
|
||||
|| IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
PRF_CHECK("4c3c2c1c/4D3D2D1D", rc);
|
||||
} else {
|
||||
PRF_CHECK("%lx/%lX", rc);
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
|
@ -529,14 +529,6 @@ static void test_x_length(void)
|
|||
rc = TEST_PRF("%hhx/%hhX", min, max);
|
||||
PRF_CHECK("1c/1D", rc);
|
||||
|
||||
rc = TEST_PRF("%lx/%lX", (unsigned long)min, (unsigned long)max);
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_FULL_INTEGRAL)
|
||||
|| (sizeof(long) <= 4)) {
|
||||
PRF_CHECK("4c3c2c1c/4D3D2D1D", rc);
|
||||
} else {
|
||||
PRF_CHECK("%lx/%lX", rc);
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_FULL_INTEGRAL)) {
|
||||
rc = TEST_PRF("%llx/%llX", (unsigned long long)min,
|
||||
(unsigned long long)max);
|
||||
|
@ -578,11 +570,6 @@ static void test_x_flags(void)
|
|||
unsigned int sv = 0x123;
|
||||
int rc;
|
||||
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
TC_PRINT("skipped test for nano\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Stuff related to sign flags, which have no effect on
|
||||
* unsigned conversions, and alternate form
|
||||
*/
|
||||
|
@ -891,11 +878,6 @@ static void test_fp_flags(void)
|
|||
|
||||
static void test_star_width(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
TC_PRINT("skipped test for nano\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int rc;
|
||||
|
||||
rc = TEST_PRF("/%3c/%-3c/", 'a', 'a');
|
||||
|
@ -907,17 +889,17 @@ static void test_star_width(void)
|
|||
|
||||
static void test_star_precision(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
TC_PRINT("skipped test for nano\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int rc;
|
||||
|
||||
rc = TEST_PRF("/%.*x/%10.*x/",
|
||||
5, 0x12, 5, 0x12);
|
||||
PRF_CHECK("/00012/ 00012/", rc);
|
||||
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
TC_PRINT("short test for nano\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) {
|
||||
double dv = 1.2345678;
|
||||
|
||||
|
@ -1001,10 +983,6 @@ static void test_p(void)
|
|||
rc = TEST_PRF("%p", NULL);
|
||||
PRF_CHECK("(nil)", rc);
|
||||
|
||||
/* Nano doesn't support left-justification of pointer
|
||||
* values.
|
||||
*/
|
||||
if (!IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
reset_out();
|
||||
rc = rawprf("/%12p/", ptr);
|
||||
zassert_equal(rc, 14, NULL);
|
||||
|
@ -1014,7 +992,6 @@ static void test_p(void)
|
|||
rc = rawprf("/%12p/", NULL);
|
||||
zassert_equal(rc, 14, NULL);
|
||||
zassert_equal(strncmp("/ (nil)/", buf, rc), 0, NULL);
|
||||
}
|
||||
|
||||
reset_out();
|
||||
rc = rawprf("/%-12p/", ptr);
|
||||
|
@ -1026,15 +1003,11 @@ static void test_p(void)
|
|||
zassert_equal(rc, 14, NULL);
|
||||
zassert_equal(strncmp("/(nil) /", buf, rc), 0, NULL);
|
||||
|
||||
/* Nano doesn't support zero-padding of pointer values.
|
||||
*/
|
||||
if (!IS_ENABLED(CONFIG_CBPRINTF_NANO)) {
|
||||
reset_out();
|
||||
rc = rawprf("/%.8p/", ptr);
|
||||
zassert_equal(rc, 12, NULL);
|
||||
zassert_equal(strncmp("/0x00cafe21/", buf, rc), 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static int out_counter(int c,
|
||||
void *ctx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue