summaryrefslogtreecommitdiffstats
path: root/testsuites
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-23 13:30:44 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-11-06 07:25:51 +0100
commit10827984c2cf54188a9af71b94a7e83197812bb5 (patch)
treed0faa328fff4ed71c72993675a231a1b6a0d710c /testsuites
parentsmpscheduler02: Avoid sporadic test failures (diff)
downloadrtems-10827984c2cf54188a9af71b94a7e83197812bb5.tar.bz2
score: Add _IO_Printf() and _IO_Vprintf()
The previous vprintk() implementation had a questionable licence header, lacks support for the 'z' and 'j' format specifiers, is not robust against invalid format specifiers, uses a global variable for output. Replace it with a stripped down version of the FreeBSD kernel kvprintf() function. The new implementation allows a low overhead rtems_snprintf() if necessary. Update #3199. Close #3216.
Diffstat (limited to 'testsuites')
-rw-r--r--testsuites/sptests/spprintk/init.c161
-rw-r--r--testsuites/sptests/spprintk/spprintk.scn81
2 files changed, 150 insertions, 92 deletions
diff --git a/testsuites/sptests/spprintk/init.c b/testsuites/sptests/spprintk/init.c
index e956c76ff3..4ef28daf5d 100644
--- a/testsuites/sptests/spprintk/init.c
+++ b/testsuites/sptests/spprintk/init.c
@@ -13,7 +13,7 @@
#include "config.h"
#endif
-#include <rtems/score/basedefs.h>
+#include <rtems/score/io.h>
/*
* Undefined the RTEMS_PRINTFLIKE and make it nothing. The test code
@@ -27,19 +27,12 @@
const char rtems_test_name[] = "SPPRINTK";
-/* forward declarations to avoid warnings */
-rtems_task Init(rtems_task_argument argument);
-int test_getchar(void);
-void do_getchark(void);
-void do_putk(void);
-void do_printk(void);
-
-int test_getchar(void)
+static int test_getchar(void)
{
return 0x35;
}
-void do_getchark(void)
+static void do_getchark(void)
{
int sc;
BSP_polling_getchar_function_type poll_char;
@@ -60,52 +53,49 @@ void do_getchark(void)
BSP_poll_char = poll_char;
}
-void do_putk(void)
+static void do_putk(void)
{
putk( "This is a test of putk" );
}
-void do_printk(void)
+static void do_printk(void)
{
long lm = 2147483647L;
unsigned long ulm = 4294967295UL;
long long llm = 9223372036854775807LL;
long long ullm = 18446744073709551615ULL;
- printk( "bad format -- %%q in parentheses (%q)\n" );
+ printk( "bad format -- %%q in parentheses (%q)\n" );
- printk( "bad format -- %%lq in parentheses (%lq)\n", 0x1234 );
+ printk( "bad format -- %%lq in parentheses (%lq)\n" );
- printk( "%%O octal upper case 16 -- %O\n", 16 );
- printk( "%%o octal lower case of 16 -- %O\n", 16 );
- printk( "%%I of 16 -- %I\n", 16 );
- printk( "%%i of 16 -- %i\n", 16 );
- printk( "%%D of 16 -- %D\n", 16 );
- printk( "%%d of 16 -- %d\n", 16 );
- printk( "%%-3d of 16 -- %-3d\n", 16 );
- printk( "%%U of 16 -- %U\n", 16 );
- printk( "%%u of 16 -- %u\n", 16 );
- printk( "%%X of 16 -- %X\n", 16 );
- printk( "%%x of 16 -- %x\n", 16 );
- printk( "%%p of 0x1234 -- %p\n", (void *)0x1234 );
+ printk( "%%o of 16 -- %o\n", 16 );
+ printk( "%%i of 16 -- %i\n", 16 );
+ printk( "%%d of 16 -- %d\n", 16 );
+ printk( "'%%-3d' of 16 -- '%-3d'\n", 16 );
+ printk( "'%%3d' of 16 -- '%3d'\n", 16 );
+ printk( "%%u of 16 -- %u\n", 16 );
+ printk( "%%X of 16 -- %X\n", 16 );
+ printk( "%%x of 16 -- %x\n", 16 );
+ printk( "%%p of 0x1234 -- %p\n", (void *)0x1234 );
/* long */
- printk( "%%lo of 2147483647 -- %lo\n", lm );
- printk( "%%li of 2147483647 -- %li\n", lm );
- printk( "%%lu of 2147483647 -- %lu\n", lm );
- printk( "%%lx of 2147483647 -- %lx\n", lm );
- printk( "%%lo of -2147483648 -- %lo\n", -lm - 1L );
- printk( "%%li of -2147483648 -- %li\n", -lm - 1L );
- printk( "%%lx of -2147483648 -- %lx\n", -lm - 1L );
- printk( "%%lo of 4294967295 -- %lo\n", ulm );
- printk( "%%lu of 4294967295 -- %lu\n", ulm );
- printk( "%%lx of 4294967295 -- %lx\n", ulm );
+ printk( "%%lo of 2147483647 -- %lo\n", lm );
+ printk( "%%li of 2147483647 -- %li\n", lm );
+ printk( "%%lu of 2147483647 -- %lu\n", lm );
+ printk( "%%lx of 2147483647 -- %lx\n", lm );
+ printk( "%%lo of -2147483648 -- %lo\n", -lm - 1L );
+ printk( "%%li of -2147483648 -- %li\n", -lm - 1L );
+ printk( "%%lx of -2147483648 -- %lx\n", -lm - 1L );
+ printk( "%%lo of 4294967295 -- %lo\n", ulm );
+ printk( "%%lu of 4294967295 -- %lu\n", ulm );
+ printk( "%%lx of 4294967295 -- %lx\n", ulm );
/* long long */
- printk( "%%llo of 9223372036854775807 -- %llo\n", llm );
- printk( "%%lli of 9223372036854775807 -- %lli\n", llm );
- printk( "%%llu of 9223372036854775807 -- %llu\n", llm );
- printk( "%%llx of 9223372036854775807 -- %llx\n", llm );
+ printk( "%%llo of 9223372036854775807 -- %llo\n", llm );
+ printk( "%%lli of 9223372036854775807 -- %lli\n", llm );
+ printk( "%%llu of 9223372036854775807 -- %llu\n", llm );
+ printk( "%%llx of 9223372036854775807 -- %llx\n", llm );
printk( "%%llo of -9223372036854775808 -- %llo\n", -llm - 1LL );
printk( "%%lli of -9223372036854775808 -- %lli\n", -llm - 1LL );
printk( "%%llx of -9223372036854775808 -- %llx\n", -llm - 1LL );
@@ -114,22 +104,90 @@ void do_printk(void)
printk( "%%llx of 18446744073709551615 -- %llx\n", ullm );
/* negative numbers */
- printk( "%%d of -16 -- %d\n", -16 );
- printk( "%%d of -16 -- %-3d\n", -16 );
- printk( "%%u of -16 -- %u\n", -16 );
+ printk( "%%d of -16 -- %d\n", -16 );
+ printk( "%%d of -16 -- %-3d\n", -16 );
+ printk( "%%u of -16 -- %u\n", -16 );
/* string formats */
- printk( "%%s of Mary Had a Little Lamb -- (%s)\n",
+ printk( "%%s of Mary Had a Little Lamb -- '%s'\n",
"Mary Had a Little Lamb" );
- printk( "%%s of NULL -- (%s)\n", NULL );
- printk( "%%12s of joel -- (%20s)\n", "joel" );
- printk( "%%4s of joel -- (%4s)\n", "joel" );
- printk( "%%-12s of joel -- (%-20s)\n", "joel" );
- printk( "%%-4s of joel -- (%-4s)\n", "joel" );
- printk( "%%c of X -- (%c)\n", 'X' );
+ printk( "%%s of NULL -- '%s'\n", NULL );
+ printk( "%%12s of joel -- '%20s'\n", "joel" );
+ printk( "%%4s of joel -- '%4s'\n", "joel" );
+ printk( "%%-12s of joel -- '%-20s'\n", "joel" );
+ printk( "%%-4s of joel -- '%-4s'\n", "joel" );
+ printk( "%%c of X -- '%c'\n", 'X' );
+ printk( "%%hhu of X -- %hhu\n", 'X' );
+}
+
+typedef struct {
+ char buf[128];
+ size_t i;
+} test_context;
+
+static test_context test_instance;
+
+static void clear( test_context *ctx )
+{
+ ctx->i = 0;
+ memset( ctx->buf, 0, sizeof( ctx->buf ) );
+}
+
+static void put_char( int c, void *arg )
+{
+ test_context *ctx;
+
+ ctx = arg;
+
+ if ( ctx->i < sizeof( ctx->buf ) ) {
+ ctx->buf[ ctx->i ] = (char) c;
+ ++ctx->i;
+ }
+}
+
+static test_context test_instance;
+
+static void test_io_printf( test_context *ctx )
+{
+ int i;
+ intmax_t j;
+ long long ll;
+ long l;
+ size_t z;
+ ptrdiff_t t;
+
+ clear( ctx );
+ i = 123;
+ _IO_Printf( put_char, ctx, "%i", i );
+ rtems_test_assert( strcmp( ctx->buf, "123" ) == 0 );
+
+ clear( ctx );
+ j = 456;
+ _IO_Printf( put_char, ctx, "%ji", j );
+ rtems_test_assert( strcmp( ctx->buf, "456" ) == 0 );
+
+ clear( ctx );
+ ll = 789;
+ _IO_Printf( put_char, ctx, "%lli", ll );
+ rtems_test_assert( strcmp( ctx->buf, "789" ) == 0 );
+
+ clear( ctx );
+ l = 101112;
+ _IO_Printf( put_char, ctx, "%li", l );
+ rtems_test_assert( strcmp( ctx->buf, "101112" ) == 0 );
+
+ clear( ctx );
+ z = 131415;
+ _IO_Printf( put_char, ctx, "%zi", z );
+ rtems_test_assert( strcmp( ctx->buf, "131415" ) == 0 );
+
+ clear( ctx );
+ t = 161718;
+ _IO_Printf( put_char, ctx, "%ti", t );
+ rtems_test_assert( strcmp( ctx->buf, "161718" ) == 0 );
}
-rtems_task Init(
+static rtems_task Init(
rtems_task_argument argument
)
{
@@ -142,6 +200,7 @@ rtems_task Init(
putk("");
do_getchark();
+ test_io_printf(&test_instance);
TEST_END();
rtems_test_exit( 0 );
diff --git a/testsuites/sptests/spprintk/spprintk.scn b/testsuites/sptests/spprintk/spprintk.scn
index 4b8130b75c..d537750472 100644
--- a/testsuites/sptests/spprintk/spprintk.scn
+++ b/testsuites/sptests/spprintk/spprintk.scn
@@ -1,51 +1,50 @@
-*** TEST PRINTK ***
+*** BEGIN OF TEST SPPRINTK ***
This is a test of putk
-bad format -- %q in parentheses (q)
-bad format -- %lq in parentheses (q)
-%O octal upper case 16 -- 20
-%o octal lower case of 16 -- 20
-%I of 16 -- 16
-%i of 16 -- 16
-%D of 16 -- 16
-%d of 16 -- 16
-%-3d of 16 -- 16
-%U of 16 -- 16
-%u of 16 -- 16
-%X of 16 -- 10
-%x of 16 -- 10
-%p of 0x1234 -- 1234
-%lo of 2147483647 -- 17777777777
-%li of 2147483647 -- 2147483647
-%lu of 2147483647 -- 2147483647
-%lx of 2147483647 -- 7FFFFFFF
-%lo of -2147483648 -- 20000000000
-%li of -2147483648 -- -2147483648
-%lx of -2147483648 -- 80000000
-%lo of 4294967295 -- 37777777777
-%lu of 4294967295 -- 4294967295
-%lx of 4294967295 -- FFFFFFFF
-%llo of 9223372036854775807 -- 777777777777777777777
-%lli of 9223372036854775807 -- 9223372036854775807
-%llu of 9223372036854775807 -- 9223372036854775807
-%llx of 9223372036854775807 -- 7FFFFFFFFFFFFFFF
+bad format -- %q in parentheses (%q)
+bad format -- %lq in parentheses (%lq)
+%o of 16 -- 20
+%i of 16 -- 16
+%d of 16 -- 16
+'%-3d' of 16 -- '16 '
+'%3d' of 16 -- ' 16'
+%u of 16 -- 16
+%X of 16 -- 10
+%x of 16 -- 10
+%p of 0x1234 -- 0x1234
+%lo of 2147483647 -- 17777777777
+%li of 2147483647 -- 2147483647
+%lu of 2147483647 -- 2147483647
+%lx of 2147483647 -- 7fffffff
+%lo of -2147483648 -- 20000000000
+%li of -2147483648 -- -2147483648
+%lx of -2147483648 -- 80000000
+%lo of 4294967295 -- 37777777777
+%lu of 4294967295 -- 4294967295
+%lx of 4294967295 -- ffffffff
+%llo of 9223372036854775807 -- 777777777777777777777
+%lli of 9223372036854775807 -- 9223372036854775807
+%llu of 9223372036854775807 -- 9223372036854775807
+%llx of 9223372036854775807 -- 7fffffffffffffff
%llo of -9223372036854775808 -- 1000000000000000000000
%lli of -9223372036854775808 -- -9223372036854775808
%llx of -9223372036854775808 -- 8000000000000000
%llo of 18446744073709551615 -- 1777777777777777777777
%llu of 18446744073709551615 -- 18446744073709551615
-%llx of 18446744073709551615 -- FFFFFFFFFFFFFFFF
-%d of -16 -- -16
-%d of -16 -- -16
-%u of -16 -- 4294967280
-%s of Mary Had a Little Lamb -- (Mary Had a Little Lamb)
-%s of NULL -- ()
-%12s of joel -- ( joel)
-%4s of joel -- (joel)
-%-12s of joel -- (joel )
-%-4s of joel -- (joel)
-%c of X -- (X)
+%llx of 18446744073709551615 -- ffffffffffffffff
+%d of -16 -- -16
+%d of -16 -- -16
+%u of -16 -- 4294967280
+%s of Mary Had a Little Lamb -- 'Mary Had a Little Lamb'
+%s of NULL -- '(null)'
+%12s of joel -- ' joel'
+%4s of joel -- 'joel'
+%-12s of joel -- 'joel '
+%-4s of joel -- 'joel'
+%c of X -- 'X'
+%hhu of X -- 88
getchark - NULL getchar method - return -1
getchark - test getchar method - returns 0x35
-*** END OF TEST PRINTK ***
+
+*** END OF TEST SPPRINTK ***