From b97bc8bc71a6dac6dafc2afe7c4cbe2085fa2d55 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 7 May 2014 18:27:19 +0200 Subject: tests: Add locked_printf_plugin() Add locked_vprintf(). Return an int just like printf(), etc. --- testsuites/support/include/test_support.h | 15 +++++++-- testsuites/support/src/locked_print.c | 52 ++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 18 deletions(-) (limited to 'testsuites/support') diff --git a/testsuites/support/include/test_support.h b/testsuites/support/include/test_support.h index 1950388bc1..7c459ff1d9 100644 --- a/testsuites/support/include/test_support.h +++ b/testsuites/support/include/test_support.h @@ -10,6 +10,8 @@ #ifndef __TEST_SUPPORT_h #define __TEST_SUPPORT_h +#include + #ifdef __cplusplus extern "C" { #endif @@ -65,9 +67,16 @@ void rtems_time_test_measure_operation( /************** TEST SUPPORT **************/ /*********************************************************************/ /*********************************************************************/ -extern void locked_print_initialize(void); -extern void locked_printf(const char *fmt, ...); -extern void locked_printk(const char *fmt, ...); + +void locked_print_initialize(void); + +int locked_printf(const char *fmt, ...); + +int locked_vprintf(const char *fmt, va_list ap); + +int locked_printf_plugin(void *context, const char *fmt, ...); + +void locked_printk(const char *fmt, ...); #ifdef __cplusplus }; diff --git a/testsuites/support/src/locked_print.c b/testsuites/support/src/locked_print.c index 86cddde2f6..8414479061 100644 --- a/testsuites/support/src/locked_print.c +++ b/testsuites/support/src/locked_print.c @@ -11,12 +11,7 @@ #include "config.h" #endif -#include -#include -#include -#include -#include - +#include "test_support.h" #include "tmacros.h" static rtems_id locked_print_semaphore; /* synchronisation semaphore */ @@ -45,8 +40,9 @@ void locked_print_initialize(void) directive_failed( sc, "rtems_semaphore_create" ); } -void locked_printf(const char *fmt, ...) { - va_list ap; /* points to each unnamed argument in turn */ +int locked_vprintf(const char *fmt, va_list ap) +{ + int rv; rtems_status_code sc; locked_print_initialize(); @@ -56,16 +52,42 @@ void locked_printf(const char *fmt, ...) { sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 ); } while (sc != RTEMS_SUCCESSFUL ); + rv = vprintf(fmt, ap); + + /* Release the semaphore */ + rtems_semaphore_release( locked_print_semaphore ); + + return rv; +} + +int locked_printf_plugin(void *context, const char *fmt, ...) +{ + int rv; + va_list ap; + + (void) context; + + va_start(ap, fmt); + rv = locked_vprintf(fmt, ap); + va_end(ap); + + return rv; +} + +int locked_printf(const char *fmt, ...) +{ + int rv; + va_list ap; /* points to each unnamed argument in turn */ va_start(ap, fmt); /* make ap point to 1st unnamed arg */ - vprintf(fmt, ap); + rv = locked_vprintf(fmt, ap); va_end(ap); /* clean up when done */ - /* Release the semaphore */ - sc = rtems_semaphore_release( locked_print_semaphore ); -} + return rv; +} -void locked_printk(const char *fmt, ...) { +void locked_printk(const char *fmt, ...) +{ va_list ap; /* points to each unnamed argument in turn */ rtems_status_code sc; @@ -82,5 +104,5 @@ void locked_printk(const char *fmt, ...) { va_end(ap); /* clean up when done */ /* Release the semaphore */ - sc = rtems_semaphore_release( locked_print_semaphore ); -} + rtems_semaphore_release( locked_print_semaphore ); +} -- cgit v1.2.3