tests: sprintf: cleanup to work with newlib

newlib doesn't implement the internal buffer the same way that minimal
libc does, so only run that check with min libc (ie !CONFIG_NEWLIB_LIBC).
Also, reported the length we did get if the buffer is to big.  Finally
include <stdarg.h> since we are dealing with va_lists and such.

Change-Id: I6b23e448e5785df978ac8c2757099e2b8aaace54
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2017-04-14 14:31:18 -05:00 committed by Anas Nashif
commit 7fb0e36060

View file

@ -13,6 +13,7 @@ This module contains the code for testing sprintf() functionality.
#include <tc_util.h> #include <tc_util.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
#define DEADBEEF 0xdeadbeef #define DEADBEEF 0xdeadbeef
@ -619,11 +620,13 @@ int sprintfStringTest(void)
} }
len = sprintf(buffer, "%s", REALLY_LONG_STRING); len = sprintf(buffer, "%s", REALLY_LONG_STRING);
#ifndef CONFIG_NEWLIB_LIBC
if (len != PRINTF_MAX_STRING_LENGTH) { if (len != PRINTF_MAX_STRING_LENGTH) {
TC_ERROR("Internals changed. Max string length no longer %d\n", TC_ERROR("Internals changed. Max string length no longer %d got %d\n",
PRINTF_MAX_STRING_LENGTH); PRINTF_MAX_STRING_LENGTH, len);
status = TC_FAIL; status = TC_FAIL;
} }
#endif
if (strncmp(buffer, REALLY_LONG_STRING, PRINTF_MAX_STRING_LENGTH) != 0) { if (strncmp(buffer, REALLY_LONG_STRING, PRINTF_MAX_STRING_LENGTH) != 0) {
TC_ERROR("First %d characters of REALLY_LONG_STRING not printed!\n", TC_ERROR("First %d characters of REALLY_LONG_STRING not printed!\n",
PRINTF_MAX_STRING_LENGTH); PRINTF_MAX_STRING_LENGTH);