From 24d0ee57a4d95f99be6e7e60bd162a30daf0638d Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Fri, 20 May 2016 18:39:50 +1000 Subject: cpukit, testsuite: Add rtems_printf and rtems_printer support. This change adds rtems_printf and related functions and wraps the RTEMS print plugin support into a user API. All references to the plugin are removed and replaced with the rtems_printer interface. Printk and related functions are made to return a valid number of characters formatted and output. The function attribute to check printf functions has been added to rtems_printf and printk. No changes to remove warrnings are part of this patch set. The testsuite has been moved over to the rtems_printer. The testsuite has a mix of rtems_printer access and direct print control via the tmacros.h header file. The support for begink/endk has been removed as it served no purpose and only confused the code base. The testsuite has not been refactored to use rtems_printf. This is future work. --- cpukit/libmisc/cpuuse/cpuusagereport.c | 28 +++--- cpukit/libmisc/cpuuse/cpuusagetop.c | 147 ++++++++++++----------------- cpukit/libmisc/cpuuse/cpuuse.h | 14 +-- cpukit/libmisc/fb/mw_print.c | 23 ++--- cpukit/libmisc/fb/mw_uid.h | 9 +- cpukit/libmisc/shell/main_blkstats.c | 7 +- cpukit/libmisc/shell/main_cpuuse.c | 4 +- cpukit/libmisc/shell/main_perioduse.c | 5 +- cpukit/libmisc/shell/main_profreport.c | 5 +- cpukit/libmisc/shell/main_stackuse.c | 7 +- cpukit/libmisc/shell/main_top.c | 4 +- cpukit/libmisc/stackchk/check.c | 36 ++++--- cpukit/libmisc/stackchk/stackchk.h | 5 +- cpukit/libmisc/testsupport/test.h | 60 +++--------- cpukit/libmisc/testsupport/testbeginend.c | 39 +++++--- cpukit/libmisc/testsupport/testextension.c | 6 +- 16 files changed, 172 insertions(+), 227 deletions(-) (limited to 'cpukit/libmisc') diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c index 95d06480d6..5200352f96 100644 --- a/cpukit/libmisc/cpuuse/cpuusagereport.c +++ b/cpukit/libmisc/cpuuse/cpuusagereport.c @@ -34,8 +34,7 @@ * rtems_cpu_usage_report */ void rtems_cpu_usage_report_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer *printer ) { uint32_t i; @@ -44,11 +43,8 @@ void rtems_cpu_usage_report_with_plugin( Objects_Information *information; char name[13]; uint32_t ival, fval; - Timestamp_Control uptime, total, used, uptime_at_last_reset; - uint32_t seconds, nanoseconds; - - if ( !print ) - return; + Timestamp_Control uptime, total, used, uptime_at_last_reset; + uint32_t seconds, nanoseconds; /* * When not using nanosecond CPU usage resolution, we have to count @@ -58,8 +54,8 @@ void rtems_cpu_usage_report_with_plugin( _Timestamp_Set_to_zero( &total ); uptime_at_last_reset = CPU_usage_Uptime_at_last_reset; - (*print)( - context, + rtems_printf( + printer, "-------------------------------------------------------------------------------\n" " CPU USAGE BY THREAD\n" "------------+----------------------------------------+---------------+---------\n" @@ -83,8 +79,8 @@ void rtems_cpu_usage_report_with_plugin( rtems_object_get_name( the_thread->Object.id, sizeof(name), name ); - (*print)( - context, + rtems_printf( + printer, " 0x%08" PRIx32 " | %-38s |", the_thread->Object.id, name @@ -102,7 +98,7 @@ void rtems_cpu_usage_report_with_plugin( seconds = _Timestamp_Get_seconds( &used ); nanoseconds = _Timestamp_Get_nanoseconds( &used ) / TOD_NANOSECONDS_PER_MICROSECOND; - (*print)( context, + rtems_printf( printer, "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n", seconds, nanoseconds, ival, fval @@ -114,8 +110,8 @@ void rtems_cpu_usage_report_with_plugin( seconds = _Timestamp_Get_seconds( &total ); nanoseconds = _Timestamp_Get_nanoseconds( &total ) / TOD_NANOSECONDS_PER_MICROSECOND; - (*print)( - context, + rtems_printf( + printer, "------------+----------------------------------------+---------------+---------\n" " TIME SINCE LAST CPU USAGE RESET IN SECONDS: %7" PRIu32 ".%06" PRIu32 "\n" "-------------------------------------------------------------------------------\n", @@ -125,5 +121,7 @@ void rtems_cpu_usage_report_with_plugin( void rtems_cpu_usage_report( void ) { - rtems_cpu_usage_report_with_plugin( NULL, printk_plugin ); + rtems_printer printer; + rtems_print_printer_printk( &printer ); + rtems_cpu_usage_report_with_plugin( &printer ); } diff --git a/cpukit/libmisc/cpuuse/cpuusagetop.c b/cpukit/libmisc/cpuuse/cpuusagetop.c index cf896e3782..2f48eb8f63 100644 --- a/cpukit/libmisc/cpuuse/cpuusagetop.c +++ b/cpukit/libmisc/cpuuse/cpuusagetop.c @@ -40,15 +40,6 @@ #include #include -/* - * Common variable to sync the load monitor task. - */ -typedef struct -{ - void* context; - rtems_printk_plugin_t print; -} rtems_cpu_usage_plugin; - /* * Use a struct for all data to allow more than one top and to support the * thread iterator. @@ -61,7 +52,7 @@ typedef struct volatile uint32_t sort_order; volatile uint32_t poll_rate_usecs; volatile uint32_t show; - rtems_cpu_usage_plugin plugin; + const rtems_printer* printer; Timestamp_Control zero; Timestamp_Control uptime; Timestamp_Control last_uptime; @@ -144,27 +135,19 @@ static inline bool less_than_uint32_t( uint32_t * lhs, uint32_t * rhs ) return false; } -#define CPU_usage_Equal_to( _lhs, _rhs ) \ - _Timestamp_Equal_to( _lhs, _rhs ) - -#define CPU_usage_Set_to_zero( _time ) \ - _Timestamp_Set_to_zero( _time ) - -#define CPU_usage_Less_than( _lhs, _rhs ) \ - _Timestamp_Less_than( _lhs, _rhs ) +#define CPU_usage_Equal_to( _lhs, _rhs ) _Timestamp_Equal_to( _lhs, _rhs ) +#define CPU_usage_Set_to_zero( _time ) _Timestamp_Set_to_zero( _time ) +#define CPU_usage_Less_than( _lhs, _rhs ) _Timestamp_Less_than( _lhs, _rhs ) static void print_memsize(rtems_cpu_usage_data* data, const uint32_t size, const char* label) { if (size > (1024 * 1024)) - (*data->plugin.print)(data->plugin.context, "%4" PRIu32 "M %s", - size / (1024 * 1024), label); + rtems_printf(data->printer, "%4" PRIu32 "M %s", size / (1024 * 1024), label); else if (size > 1024) - (*data->plugin.print)(data->plugin.context, "%4" PRIu32 "K %s", - size / 1024, label); + rtems_printf(data->printer, "%4" PRIu32 "K %s", size / 1024, label); else - (*data->plugin.print)(data->plugin.context, "%4" PRIu32 " %s", - size, label); + rtems_printf(data->printer, "%4" PRIu32 " %s", size, label); } static int @@ -184,19 +167,19 @@ print_time(rtems_cpu_usage_data* data, uint32_t hours = mins / 60; if (hours > 24) { - len += (*data->plugin.print)(data->plugin.context, "%" PRIu32 "d", hours / 24); + len += rtems_printf(data->printer, "%" PRIu32 "d", hours / 24); hours %= 24; } - len += (*data->plugin.print)(data->plugin.context, "%" PRIu32 "hr", hours); + len += rtems_printf(data->printer, "%" PRIu32 "hr", hours); mins %= 60; } - len += (*data->plugin.print)(data->plugin.context, "%" PRIu32 "m", mins); + len += rtems_printf(data->printer, "%" PRIu32 "m", mins); secs %= 60; } - len += (*data->plugin.print)(data->plugin.context, "%" PRIu32 ".%06" PRIu32, secs, usecs); + len += rtems_printf(data->printer, "%" PRIu32 ".%06" PRIu32, secs, usecs); if (len < length) - (*data->plugin.print)(data->plugin.context, "%*c", length - len, ' '); + rtems_printf(data->printer, "%*c", length - len, ' '); return len; } @@ -344,7 +327,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) data->current_usage = realloc(data->current_usage, usage_size); if ((data->tasks == NULL) || (data->usage == NULL) || (data->current_usage == NULL)) { - (*data->plugin.print)(data->plugin.context, "top worker: error: no memory\n"); + rtems_printf(data->printer, "top worker: error: no memory\n"); data->thread_run = false; break; } @@ -371,7 +354,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) data->last_usage = realloc(data->last_usage, usage_size); if ((data->last_tasks == NULL) || (data->last_usage == NULL)) { - (*data->plugin.print)(data->plugin.context, "top worker: error: no memory\n"); + rtems_printf(data->printer, "top worker: error: no memory\n"); data->thread_run = false; break; } @@ -396,43 +379,43 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) _Protected_heap_Get_information(&_Workspace_Area, &wksp); if (data->single_page) - (*data->plugin.print)(data->plugin.context, - "\x1b[H\x1b[J" - " ENTER:Exit SPACE:Refresh" - " S:Scroll A:All <>:Order +/-:Lines\n"); - (*data->plugin.print)(data->plugin.context,"\n"); + rtems_printf(data->printer, + "\x1b[H\x1b[J" + " ENTER:Exit SPACE:Refresh" + " S:Scroll A:All <>:Order +/-:Lines\n"); + rtems_printf(data->printer, "\n"); /* * Uptime and period of this sample. */ - (*data->plugin.print)(data->plugin.context, "Uptime: "); + rtems_printf(data->printer, "Uptime: "); print_time(data, &data->uptime, 20); - (*data->plugin.print)(data->plugin.context, " Period: "); + rtems_printf(data->printer, " Period: "); print_time(data, &data->period, 20); /* * Task count, load and idle levels. */ - (*data->plugin.print)(data->plugin.context, "\nTasks: %4i ", data->task_count); + rtems_printf(data->printer, "\nTasks: %4i ", data->task_count); _Timestamp_Subtract(&data->idle, &data->total, &load); _Timestamp_Divide(&load, &data->uptime, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - "Load Average: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); + rtems_printf(data->printer, + "Load Average: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); _Timestamp_Subtract(&data->current_idle, &data->current, &load); _Timestamp_Divide(&load, &data->period, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - " Load: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); + rtems_printf(data->printer, + " Load: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); _Timestamp_Divide(&data->current_idle, &data->period, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - " Idle: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); + rtems_printf(data->printer, + " Idle: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); /* * Memory usage. */ if (rtems_configuration_get_unified_work_area()) { - (*data->plugin.print)(data->plugin.context, "\nMem: "); + rtems_printf(data->printer, "\nMem: "); print_memsize(data, wksp.Free.total, "free"); print_memsize(data, wksp.Used.total, "used"); } @@ -440,7 +423,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) { region_information_block libc_heap; malloc_info(&libc_heap); - (*data->plugin.print)(data->plugin.context, "\nMem: Wksp: "); + rtems_printf(data->printer, "\nMem: Wksp: "); print_memsize(data, wksp.Free.total, "free"); print_memsize(data, wksp.Used.total, "used Heap: "); print_memsize(data, libc_heap.Free.total, "free"); @@ -449,7 +432,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) print_memsize(data, data->stack_size, "stack\n"); - (*data->plugin.print)(data->plugin.context, + rtems_printf(data->printer, "\n" " ID | NAME | RPRI | CPRI | TIME | TOTAL | CURRENT\n" "-%s---------+---------------------+-%s-----%s-----+---------------------+-%s------+--%s----\n", @@ -487,12 +470,12 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) if (name[0] == '\0') snprintf(name, sizeof(name) - 1, "(%p)", thread->Start.Entry.Kinds.Numeric.entry); - (*data->plugin.print)(data->plugin.context, - " 0x%08" PRIx32 " | %-19s | %3" PRId32 " | %3" PRId32 " | ", - thread->Object.id, - name, - thread->real_priority, - thread->current_priority); + rtems_printf(data->printer, + " 0x%08" PRIx32 " | %-19s | %3" PRId32 " | %3" PRId32 " | ", + thread->Object.id, + name, + thread->real_priority, + thread->current_priority); usage = data->usage[i]; current_usage = data->current_usage[i]; @@ -502,11 +485,11 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) */ print_time(data, &usage, 19); _Timestamp_Divide(&usage, &data->total, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - " |%4" PRIu32 ".%03" PRIu32, ival, fval); + rtems_printf(data->printer, + " |%4" PRIu32 ".%03" PRIu32, ival, fval); _Timestamp_Divide(¤t_usage, &data->period, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - " |%4" PRIu32 ".%03" PRIu32 "\n", ival, fval); + rtems_printf(data->printer, + " |%4" PRIu32 ".%03" PRIu32 "\n", ival, fval); } if (data->single_page && (data->show != 0) && (task_count < data->show)) @@ -514,7 +497,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) i = data->show - task_count; while (i > 0) { - (*data->plugin.print)(data->plugin.context, "\x1b[K\n"); + rtems_printf(data->printer, "\x1b[K\n"); i--; } } @@ -525,8 +508,8 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) &out); if ((sc != RTEMS_SUCCESSFUL) && (sc != RTEMS_TIMEOUT)) { - (*data->plugin.print)(data->plugin.context, - "error: event receive: %s\n", rtems_status_text(sc)); + rtems_printf(data->printer, + "error: event receive: %s\n", rtems_status_text(sc)); break; } } @@ -542,8 +525,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) } void rtems_cpu_usage_top_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer *printer ) { rtems_status_code sc; @@ -553,9 +535,6 @@ void rtems_cpu_usage_top_with_plugin( rtems_cpu_usage_data data; int show_lines = 25; - if ( !print ) - return; - memset(&data, 0, sizeof(data)); data.thread_run = true; @@ -563,18 +542,14 @@ void rtems_cpu_usage_top_with_plugin( data.sort_order = RTEMS_TOP_SORT_CURRENT; data.poll_rate_usecs = 3000; data.show = show_lines; - data.plugin.context = context; - data.plugin.print = print; + data.printer = printer; sc = rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority); if (sc != RTEMS_SUCCESSFUL) { - (*print)( - context, - "error: cannot obtain the current priority: %s\n", - rtems_status_text (sc) - ); + rtems_printf (printer, + "error: cannot obtain the current priority: %s\n", rtems_status_text (sc)); return; } @@ -587,24 +562,16 @@ void rtems_cpu_usage_top_with_plugin( if (sc != RTEMS_SUCCESSFUL) { - (*print)( - context, - "error: cannot create helper thread: %s\n", - rtems_status_text (sc) - ); + rtems_printf (printer, + "error: cannot create helper thread: %s\n", rtems_status_text (sc)); return; } - sc = rtems_task_start ( - id, rtems_cpuusage_top_thread, (rtems_task_argument) &data - ); + sc = rtems_task_start (id, rtems_cpuusage_top_thread, (rtems_task_argument) &data); if (sc != RTEMS_SUCCESSFUL) { - (*print)( - context, - "error: cannot start helper thread: %s\n", - rtems_status_text (sc) - ); + rtems_printf (printer, + "error: cannot start helper thread: %s\n", rtems_status_text (sc)); rtems_task_delete (id); return; } @@ -624,7 +591,7 @@ void rtems_cpu_usage_top_with_plugin( while (loops && data.thread_active) rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (100000)); - (*print)(context, "load monitoring stopped.\n"); + rtems_printf (printer, "load monitoring stopped.\n"); return; } else if (c == '<') @@ -676,7 +643,9 @@ void rtems_cpu_usage_top_with_plugin( } } -void rtems_cpu_usage_top( void ) +void rtems_cpu_usage_top (void) { - rtems_cpu_usage_top_with_plugin( NULL, printk_plugin ); + rtems_printer printer; + rtems_print_printer_printk (&printer); + rtems_cpu_usage_top_with_plugin (&printer); } diff --git a/cpukit/libmisc/cpuuse/cpuuse.h b/cpukit/libmisc/cpuuse/cpuuse.h index 1e26019cd6..1a3d2a7f3e 100644 --- a/cpukit/libmisc/cpuuse/cpuuse.h +++ b/cpukit/libmisc/cpuuse/cpuuse.h @@ -1,6 +1,6 @@ /** * @file rtems/cpuuse.h - * + * * @defgroup libmisc_cpuuse CPU Usage * * @ingroup libmisc @@ -23,7 +23,7 @@ #define __RTEMS_CPUUSE_h #include -#include +#include #include @@ -43,10 +43,7 @@ extern Timestamp_Control CPU_usage_Uptime_at_last_reset; * rtems_cpu_usage_report_with_handler */ -void rtems_cpu_usage_report_with_plugin( - void *context, - rtems_printk_plugin_t handler -); +void rtems_cpu_usage_report_with_plugin( const rtems_printer *printer ); /** * @brief Report CPU usage. @@ -62,10 +59,7 @@ void rtems_cpu_usage_report( void ); * Report CPU Usage in top format to * to a print plugin. */ -void rtems_cpu_usage_top_with_plugin( - void *context, - rtems_printk_plugin_t print -); +void rtems_cpu_usage_top_with_plugin( const rtems_printer *printer ); /** * @brief CPU usage top. diff --git a/cpukit/libmisc/fb/mw_print.c b/cpukit/libmisc/fb/mw_print.c index 8f4e465da2..25a3456c80 100644 --- a/cpukit/libmisc/fb/mw_print.c +++ b/cpukit/libmisc/fb/mw_print.c @@ -43,12 +43,13 @@ void uid_print_message( struct MW_UID_MESSAGE *uid ) { - uid_print_message_with_plugin( NULL, printk_plugin, uid ); + rtems_printer printer; + rtems_print_printer_printk(&printer); + uid_print_message_with_plugin( &printer, uid ); } void uid_print_message_with_plugin( - void *context, - rtems_printk_plugin_t handler, + const rtems_printer *printer, struct MW_UID_MESSAGE *uid ) { @@ -56,11 +57,11 @@ void uid_print_message_with_plugin( switch (uid->type) { case MV_UID_INVALID: - (*handler)( context, "MV_UID_INVALID\n" ); + rtems_printf( printer, "MV_UID_INVALID\n" ); break; case MV_UID_REL_POS: - (*handler)( - context, + rtems_printf( + printer, "MV_UID_REL_POS - %s x=%d y=%d z=%d\n", uid_buttons( uid->m.pos.btns, buttons, sizeof(buttons)), uid->m.pos.x, /* x location */ @@ -69,8 +70,8 @@ void uid_print_message_with_plugin( ); break; case MV_UID_ABS_POS: - (*handler)( - context, + rtems_printf( + printer, "MV_UID_ABS_POS - %s x=%d y=%d z=%d\n", uid_buttons( uid->m.pos.btns, buttons, sizeof(buttons)), uid->m.pos.x, /* x location */ @@ -79,7 +80,7 @@ void uid_print_message_with_plugin( ); break; case MV_UID_KBD: - (*handler)( context, + rtems_printf( printer, "MV_UID_KBD - code=0x%04x modifiers=0x%02x mode=0x%02x\n", uid->m.kbd.code, /* keycode or scancode */ uid->m.kbd.modifiers, /* key modifiers */ @@ -87,10 +88,10 @@ void uid_print_message_with_plugin( ); break; case MV_UID_TIMER: - (*handler)( context, "MV_UID_TIMER\n" ); + rtems_printf( printer, "MV_UID_TIMER\n" ); break; default: - (*handler)( context, "Invalid device type\n" ); + rtems_printf( printer, "Invalid device type\n" ); break; } diff --git a/cpukit/libmisc/fb/mw_uid.h b/cpukit/libmisc/fb/mw_uid.h index 8a10a8f38c..aa88392d26 100644 --- a/cpukit/libmisc/fb/mw_uid.h +++ b/cpukit/libmisc/fb/mw_uid.h @@ -18,7 +18,7 @@ #define _MW_UID_H #include -#include +#include /** * @defgroup libmisc_fb_mw Input Devices for MicroWindows @@ -179,14 +179,11 @@ void uid_print_message( * This methods prints the specified UID message using your fprintf * style method of choice. * - * @param[in] context is a pointer to a data area which may be - * used by some print handlers - * @param[in] handler is the fprintf style method to invoke + * @param[in] RTEMS printer * @param[in] uid points to the message to print */ void uid_print_message_with_plugin( - void *context, - rtems_printk_plugin_t handler, + const rtems_printer *printer, struct MW_UID_MESSAGE *uid ); diff --git a/cpukit/libmisc/shell/main_blkstats.c b/cpukit/libmisc/shell/main_blkstats.c index 50d783d76c..d814df673c 100644 --- a/cpukit/libmisc/shell/main_blkstats.c +++ b/cpukit/libmisc/shell/main_blkstats.c @@ -31,6 +31,7 @@ static int rtems_shell_main_blkstats(int argc, char **argv) bool ok = false; bool reset = false; const char *device; + rtems_printer printer; if (argc == 2) { ok = true; @@ -41,10 +42,12 @@ static int rtems_shell_main_blkstats(int argc, char **argv) device = argv [2]; } + rtems_print_printer_printf(&printer); + if (ok) { - rtems_blkstats(stdout, device, reset); + rtems_blkstats(&printer, device, reset); } else { - fprintf(stdout, "usage: %s\n", rtems_shell_BLKSTATS_Command.usage); + rtems_printf(&printer, "usage: %s\n", rtems_shell_BLKSTATS_Command.usage); } return 0; diff --git a/cpukit/libmisc/shell/main_cpuuse.c b/cpukit/libmisc/shell/main_cpuuse.c index c1f991a390..190fd039ff 100644 --- a/cpukit/libmisc/shell/main_cpuuse.c +++ b/cpukit/libmisc/shell/main_cpuuse.c @@ -30,7 +30,9 @@ static int rtems_shell_main_cpuuse( * When invoked with no arguments, print the report. */ if ( argc == 1 ) { - rtems_cpu_usage_report_with_plugin(stdout, (rtems_printk_plugin_t)fprintf); + rtems_printer printer; + rtems_print_printer_fprintf(&printer, stdout); + rtems_cpu_usage_report_with_plugin(&printer); return 0; } diff --git a/cpukit/libmisc/shell/main_perioduse.c b/cpukit/libmisc/shell/main_perioduse.c index 9b33a75446..023e154cbc 100644 --- a/cpukit/libmisc/shell/main_perioduse.c +++ b/cpukit/libmisc/shell/main_perioduse.c @@ -29,9 +29,10 @@ static int rtems_shell_main_perioduse( * When invoked with no arguments, print the report. */ if ( argc == 1 ) { + rtems_printer printer; + rtems_print_printer_printf(&printer); rtems_rate_monotonic_report_statistics_with_plugin( - stdout, - (rtems_printk_plugin_t)fprintf + &printer ); return 0; } diff --git a/cpukit/libmisc/shell/main_profreport.c b/cpukit/libmisc/shell/main_profreport.c index d6e4c5a843..a98b8ba9aa 100644 --- a/cpukit/libmisc/shell/main_profreport.c +++ b/cpukit/libmisc/shell/main_profreport.c @@ -24,10 +24,11 @@ static int rtems_shell_main_profreport(int argc, char **argv) { + rtems_printer printer; + rtems_print_printer_printf(&printer); rtems_profiling_report_xml( "Shell", - (rtems_profiling_printf) fprintf, - stdout, + &printer, 0, " " ); diff --git a/cpukit/libmisc/shell/main_stackuse.c b/cpukit/libmisc/shell/main_stackuse.c index 74d47e16b0..40fc711f49 100644 --- a/cpukit/libmisc/shell/main_stackuse.c +++ b/cpukit/libmisc/shell/main_stackuse.c @@ -25,10 +25,9 @@ static int rtems_shell_main_stackuse( char *argv[] RTEMS_UNUSED ) { - rtems_stack_checker_report_usage_with_plugin( - stdout, - (rtems_printk_plugin_t)fprintf - ); + rtems_printer printer; + rtems_print_printer_printf(&printer); + rtems_stack_checker_report_usage_with_plugin( &printer ); return 0; } diff --git a/cpukit/libmisc/shell/main_top.c b/cpukit/libmisc/shell/main_top.c index ad6223a560..aea50d80fb 100644 --- a/cpukit/libmisc/shell/main_top.c +++ b/cpukit/libmisc/shell/main_top.c @@ -30,7 +30,9 @@ static int rtems_shell_main_top( * When invoked with no arguments, print the report. */ if ( argc == 1 ) { - rtems_cpu_usage_top_with_plugin(stdout, (rtems_printk_plugin_t)fprintf); + rtems_printer printer; + rtems_print_printer_fprintf(&printer, stdout); + rtems_cpu_usage_top_with_plugin(&printer); return 0; } diff --git a/cpukit/libmisc/stackchk/check.c b/cpukit/libmisc/stackchk/check.c index 9c6932e290..93d45de77c 100644 --- a/cpukit/libmisc/stackchk/check.c +++ b/cpukit/libmisc/stackchk/check.c @@ -387,8 +387,7 @@ static inline void *Stack_check_find_high_water_mark( * * Try to print out how much stack was actually used by the task. */ -static void *print_context; -static rtems_printk_plugin_t print_handler; +static const rtems_printer* printer; static void Stack_check_Dump_threads_usage( Thread_Control *the_thread @@ -438,8 +437,8 @@ static void Stack_check_Dump_threads_usage( if ( the_thread ) #endif { - (*print_handler)( - print_context, + rtems_printf( + printer, "0x%08" PRIx32 " %4s", the_thread->Object.id, rtems_object_get_name( the_thread->Object.id, sizeof(name), name ) @@ -447,12 +446,12 @@ static void Stack_check_Dump_threads_usage( } #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) else { - (*print_handler)( print_context, "0x%08" PRIx32 " INTR", ~0 ); + rtems_printf( printer, "0x%08" PRIx32 " INTR", ~0 ); } #endif - (*print_handler)( - print_context, + rtems_printf( + printer, " %010p - %010p %010p %8" PRId32 " ", stack->area, stack->area + stack->size - 1, @@ -461,9 +460,9 @@ static void Stack_check_Dump_threads_usage( ); if (Stack_check_Initialized == 0) { - (*print_handler)( print_context, "Unavailable\n" ); + rtems_printf( printer, "Unavailable\n" ); } else { - (*print_handler)( print_context, "%8" PRId32 "\n", used ); + rtems_printf( printer, "%8" PRId32 "\n", used ); } @@ -489,18 +488,16 @@ static void Stack_check_Dump_threads_usage( */ void rtems_stack_checker_report_usage_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer* printer_ ) { - if ( !print ) + if ( printer != NULL || ! rtems_print_printer_valid ( printer_ ) ) return; - print_context = context; - print_handler = print; + printer = printer_; - (*print)( context, "Stack usage by thread\n"); - (*print)( context, + rtems_printf( printer, "Stack usage by thread\n"); + rtems_printf( printer, " ID NAME LOW HIGH CURRENT AVAILABLE USED\n" ); @@ -512,11 +509,12 @@ void rtems_stack_checker_report_usage_with_plugin( Stack_check_Dump_threads_usage((Thread_Control *) -1); #endif - print_context = NULL; - print_handler = NULL; + printer = NULL; } void rtems_stack_checker_report_usage( void ) { - rtems_stack_checker_report_usage_with_plugin( NULL, printk_plugin ); + rtems_printer printer; + rtems_print_printer_printk(&printer); + rtems_stack_checker_report_usage_with_plugin( &printer ); } diff --git a/cpukit/libmisc/stackchk/stackchk.h b/cpukit/libmisc/stackchk/stackchk.h index b824057f59..f7f75b63e2 100644 --- a/cpukit/libmisc/stackchk/stackchk.h +++ b/cpukit/libmisc/stackchk/stackchk.h @@ -25,7 +25,7 @@ #include /* bool */ #include /* Thread_Control */ -#include +#include /** * @defgroup libmisc_stackchk Stack Checker Mechanism @@ -71,8 +71,7 @@ void rtems_stack_checker_report_usage( void ); * @note It uses the caller's routine to print the report. */ void rtems_stack_checker_report_usage_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer *printer ); /************************************************************* diff --git a/cpukit/libmisc/testsupport/test.h b/cpukit/libmisc/testsupport/test.h index 497c4b679b..980ab666a6 100644 --- a/cpukit/libmisc/testsupport/test.h +++ b/cpukit/libmisc/testsupport/test.h @@ -16,7 +16,7 @@ #define _RTEMS_TEST_H #include -#include +#include #include #include @@ -37,6 +37,11 @@ extern "C" { */ extern const char rtems_test_name[]; +/** + * @brief Each test must define a printer. + */ +extern rtems_printer rtems_test_printer; + /** * @brief Fatal extension for tests. */ @@ -53,70 +58,35 @@ void rtems_test_fatal_extension( { NULL, NULL, NULL, NULL, NULL, NULL, NULL, rtems_test_fatal_extension } /** - * @brief Prints a begin of test message. - * - * @param[in] printf_func The formatted output function. - * @param[in, out] printf_arg The formatted output function argument. - * - * @returns As specified by printf(). - */ -int rtems_test_begin_with_plugin( - rtems_printk_plugin_t printf_func, - void *printf_arg -); - -/** - * @brief Prints a begin of test message using printf(). - * - * @returns As specified by printf(). + * @brief Begin of test message format string. */ -static inline int rtems_test_begin(void) -{ - return rtems_test_begin_with_plugin(rtems_printf_plugin, NULL); -} +#define TEST_BEGIN_STRING "\n\n*** BEGIN OF TEST %s ***\n", rtems_test_name /** - * @brief Prints a begin of test message using printk(). - * - * @returns As specified by printf(). + * @brief End of test message format string. */ -static inline int rtems_test_begink(void) -{ - return rtems_test_begin_with_plugin(printk_plugin, NULL); -} +#define TEST_END_STRING "*** END OF TEST %s ***\n", rtems_test_name /** - * @brief Prints an end of test message. - * - * @param[in] printf_func The formatted output function. - * @param[in, out] printf_arg The formatted output function argument. + * @brief Prints a begin of test message using printf(). * * @returns As specified by printf(). */ -int rtems_test_end_with_plugin( - rtems_printk_plugin_t printf_func, - void *printf_arg -); +int rtems_test_begin(void); /** * @brief Prints an end of test message using printf(). * * @returns As specified by printf(). */ -static inline int rtems_test_end(void) -{ - return rtems_test_end_with_plugin(rtems_printf_plugin, NULL); -} +int rtems_test_end(void); /** - * @brief Prints an end of test message using printk(). + * @brief Prints via the RTEMS printer. * * @returns As specified by printf(). */ -static inline int rtems_test_endk(void) -{ - return rtems_test_end_with_plugin(printk_plugin, NULL); -} +int rtems_test_print(const char* format, ...) RTEMS_PRINTF_ATTRIBUTE(1, 2); /** * @brief Internal context for parallel job execution. diff --git a/cpukit/libmisc/testsupport/testbeginend.c b/cpukit/libmisc/testsupport/testbeginend.c index 6383b33a78..6bfc400e1e 100644 --- a/cpukit/libmisc/testsupport/testbeginend.c +++ b/cpukit/libmisc/testsupport/testbeginend.c @@ -18,26 +18,35 @@ #include -int rtems_test_begin_with_plugin( - rtems_printk_plugin_t printf_func, - void *printf_arg -) +int rtems_test_begin(void) +{ + return rtems_printf( + &rtems_test_printer, + TEST_BEGIN_STRING + ); +} + +int rtems_test_end(void) { - return (*printf_func)( - printf_arg, - "\n\n*** BEGIN OF TEST %s ***\n", - rtems_test_name + return rtems_printf( + &rtems_test_printer, + TEST_END_STRING ); } -int rtems_test_end_with_plugin( - rtems_printk_plugin_t printf_func, - void *printf_arg +int rtems_test_print( + const char* format, + ... ) { - return (*printf_func)( - printf_arg, - "*** END OF TEST %s ***\n", - rtems_test_name + va_list ap; + int len; + va_start(ap, format); + len = rtems_vprintf( + &rtems_test_printer, + format, + ap ); + va_end(ap); + return len; } diff --git a/cpukit/libmisc/testsupport/testextension.c b/cpukit/libmisc/testsupport/testextension.c index a689e66792..43f79bc114 100644 --- a/cpukit/libmisc/testsupport/testextension.c +++ b/cpukit/libmisc/testsupport/testextension.c @@ -33,6 +33,9 @@ void rtems_test_fatal_extension( { #if defined(RTEMS_PROFILING) rtems_interrupt_lock_context lock_context; + rtems_printer printer; + + rtems_print_printer_printk( &printer ); /* * Ensures to report only once on SMP machines and ensures that the report is @@ -50,8 +53,7 @@ void rtems_test_fatal_extension( rtems_profiling_report_xml( rtems_test_name, - printk_plugin, - NULL, + &printer, 1, " " ); -- cgit v1.2.3