summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-08-13 07:33:17 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-08-18 07:08:51 +0200
commite67eff2b53d4178a66f48de6d496e6272898761a (patch)
tree5f98a9d51ecbffa919b42ff50fa576a83aacbea7
parentlibtest: Change fixture scope method (diff)
downloadrtems-e67eff2b53d4178a66f48de6d496e6272898761a.tar.bz2
libtest: Add output buffer drain and fill
Update #3199.
-rw-r--r--cpukit/libtest/t-test.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/cpukit/libtest/t-test.c b/cpukit/libtest/t-test.c
index b1b5253bb5..e8d0542c31 100644
--- a/cpukit/libtest/t-test.c
+++ b/cpukit/libtest/t-test.c
@@ -143,15 +143,12 @@ T_snprintf(char *s, size_t n, char const *fmt, ...)
return len;
}
-static int
-T_vprintf_direct(char const *fmt, va_list ap)
+static void
+T_output_buffer_drain(T_context *ctx)
{
- T_context *ctx;
unsigned int head;
unsigned int tail;
- ctx = &T_instance;
-
head = atomic_load_explicit(&ctx->buf_head, memory_order_acquire);
tail = atomic_load_explicit(&ctx->buf_tail, memory_order_relaxed);
@@ -161,32 +158,16 @@ T_vprintf_direct(char const *fmt, va_list ap)
}
atomic_store_explicit(&ctx->buf_tail, tail, memory_order_relaxed);
-
- return _IO_Vprintf(ctx->putchar, ctx->putchar_arg, fmt, ap);
}
-static int
-T_vprintf_buffered(char const *fmt, va_list ap)
+static unsigned int
+T_output_buffer_fill(T_context *ctx, const char *buf, unsigned int len)
{
- unsigned int len;
- T_context *ctx;
- char buf[T_LINE_SIZE];
- T_putchar_string_context sctx = {
- .s = buf,
- .n = sizeof(buf)
- };
unsigned int head;
unsigned int tail;
unsigned int mask;
unsigned int capacity;
- len = (unsigned int)_IO_Vprintf(T_putchar_string, &sctx, fmt, ap);
-
- if (len >= sizeof(buf)) {
- len = sizeof(buf) - 1;
- }
-
- ctx = &T_instance;
pthread_spin_lock(&ctx->lock);
head = atomic_load_explicit(&ctx->buf_head, memory_order_relaxed);
tail = atomic_load_explicit(&ctx->buf_tail, memory_order_relaxed);
@@ -195,7 +176,7 @@ T_vprintf_buffered(char const *fmt, va_list ap)
if (len <= capacity) {
unsigned int todo;
- char *c;
+ const char *c;
todo = len;
c = buf;
@@ -215,7 +196,36 @@ T_vprintf_buffered(char const *fmt, va_list ap)
}
pthread_spin_unlock(&ctx->lock);
- return (int)len;
+ return len;
+}
+
+static int
+T_vprintf_direct(char const *fmt, va_list ap)
+{
+ T_context *ctx;
+
+ ctx = &T_instance;
+ T_output_buffer_drain(ctx);
+ return _IO_Vprintf(ctx->putchar, ctx->putchar_arg, fmt, ap);
+}
+
+static int
+T_vprintf_buffered(char const *fmt, va_list ap)
+{
+ char buf[T_LINE_SIZE];
+ T_putchar_string_context sctx = {
+ .s = buf,
+ .n = sizeof(buf)
+ };
+ unsigned int len;
+
+ len = (unsigned int)_IO_Vprintf(T_putchar_string, &sctx, fmt, ap);
+
+ if (len >= sizeof(buf)) {
+ len = sizeof(buf) - 1;
+ }
+
+ return (int)T_output_buffer_fill(&T_instance, buf, len);
}
int