From 152a28418871061a20dabfc4c73990b96cf18e93 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 28 Jun 2011 21:09:13 +0000 Subject: 2011-06-28 Joel Sherrill * configure.ac, support/include/test_support.h: * support/src/locked_print.c: New file. --- testsuites/support/include/test_support.h | 11 +++- testsuites/support/src/locked_print.c | 87 +++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 testsuites/support/src/locked_print.c (limited to 'testsuites/support') diff --git a/testsuites/support/include/test_support.h b/testsuites/support/include/test_support.h index 412226c9fe..8329f7f803 100644 --- a/testsuites/support/include/test_support.h +++ b/testsuites/support/include/test_support.h @@ -1,5 +1,5 @@ /* - * COPYRIGHT (c) 1989-2010. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -80,6 +80,15 @@ void rtems_time_test_measure_operation( int overhead ); +/*********************************************************************/ +/*********************************************************************/ +/************** TEST SUPPORT **************/ +/*********************************************************************/ +/*********************************************************************/ +extern void locked_print_init(void); +extern void locked_printf(const char *fmt, ...); +extern void locked_printk(const char *fmt, ...); + #ifdef __cplusplus }; #endif diff --git a/testsuites/support/src/locked_print.c b/testsuites/support/src/locked_print.c new file mode 100644 index 0000000000..52e6729509 --- /dev/null +++ b/testsuites/support/src/locked_print.c @@ -0,0 +1,87 @@ +/* + * COPYRIGHT (c) 1989-2011. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#include "tmacros.h" + +static rtems_id locked_print_semaphore; /* synchronisation semaphore */ + +void locked_print_initialize(void) +{ + rtems_status_code sc; + static bool initted = false; + + if ( initted ) + return; + + initted = true; + + /* Create/verify synchronisation semaphore */ + sc = rtems_semaphore_create( + rtems_build_name ('S', 'E', 'M', '1'), + 1, + RTEMS_LOCAL | + RTEMS_SIMPLE_BINARY_SEMAPHORE | + RTEMS_PRIORITY, + 1, + &locked_print_semaphore + ); + directive_failed( sc, "rtems_semaphore_create" ); +} + +void locked_printf(const char *fmt, ...) { + va_list ap; /* points to each unnamed argument in turn */ + rtems_status_code sc; + + locked_print_initialize(); + + /* Lock semaphore without releasing the cpu */ + do { + sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 ); + } while (sc != RTEMS_SUCCESSFUL ); + + + va_start(ap, fmt); /* make ap point to 1st unnamed arg */ + vprintf(fmt, ap); + va_end(ap); /* clean up when done */ + + /* Release the semaphore */ + sc = rtems_semaphore_release( locked_print_semaphore ); +} + +void locked_printk(const char *fmt, ...) { + va_list ap; /* points to each unnamed argument in turn */ + rtems_status_code sc; + + + locked_print_initialize(); + + /* Lock semaphore without releasing the cpu */ + do { + sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 ); + } while (sc != RTEMS_SUCCESSFUL ); + + va_start(ap, fmt); /* make ap point to 1st unnamed arg */ + vprintk(fmt, ap); + va_end(ap); /* clean up when done */ + + /* Release the semaphore */ + sc = rtems_semaphore_release( locked_print_semaphore ); +} -- cgit v1.2.3