From 6e6f1e90e5c8ac1b05495686847af35c1b85a83a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 14 Nov 2017 14:01:56 +0000 Subject: [PATCH 04/13] Add utility functions to emit TAP diagnostics and fatal errors Signed-off-by: Simon McVittie --- cmake/dbus/CMakeLists.txt | 2 ++ dbus/Makefile.am | 2 ++ dbus/dbus-test-tap.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ dbus/dbus-test-tap.h | 44 ++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 dbus/dbus-test-tap.c create mode 100644 dbus/dbus-test-tap.h diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt index 8a01d918..2fdd1128 100644 --- a/cmake/dbus/CMakeLists.txt +++ b/cmake/dbus/CMakeLists.txt @@ -127,6 +127,7 @@ set (DBUS_SHARED_SOURCES ${DBUS_DIR}/dbus-string.c ${DBUS_DIR}/dbus-sysdeps.c ${DBUS_DIR}/dbus-pipe.c + ${DBUS_DIR}/dbus-test-tap.c ) set (DBUS_SHARED_HEADERS @@ -141,6 +142,7 @@ set (DBUS_SHARED_HEADERS ${DBUS_DIR}/dbus-string-private.h ${DBUS_DIR}/dbus-pipe.h ${DBUS_DIR}/dbus-sysdeps.h + ${DBUS_DIR}/dbus-test-tap.h ) ### source code that is generic utility functionality used diff --git a/dbus/Makefile.am b/dbus/Makefile.am index b2913ef0..d4fe09f8 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -231,6 +231,8 @@ DBUS_SHARED_SOURCES= \ $(DBUS_SHARED_arch_sources) \ dbus-sysdeps.c \ dbus-sysdeps.h \ + dbus-test-tap.c \ + dbus-test-tap.h \ dbus-valgrind-internal.h ### source code that is generic utility functionality used diff --git a/dbus/dbus-test-tap.c b/dbus/dbus-test-tap.c new file mode 100644 index 00000000..88be1c4b --- /dev/null +++ b/dbus/dbus-test-tap.c @@ -0,0 +1,69 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-test-tap — TAP helpers for "embedded tests" + * + * Copyright © 2017 Collabora Ltd. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "dbus/dbus-test-tap.h" + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + +#include +#include + +/* + * Output TAP indicating a fatal error, and exit unsuccessfully. + */ +void +_dbus_test_fatal (const char *format, + ...) +{ + va_list ap; + + printf ("Bail out! "); + va_start (ap, format); + vprintf (format, ap); + va_end (ap); + printf ("\n"); + fflush (stdout); + exit (1); +} + +/* + * Output TAP indicating a diagnostic (informational message). + */ +void +_dbus_test_diag (const char *format, + ...) +{ + va_list ap; + + printf ("# "); + va_start (ap, format); + vprintf (format, ap); + va_end (ap); + printf ("\n"); +} + +#endif diff --git a/dbus/dbus-test-tap.h b/dbus/dbus-test-tap.h new file mode 100644 index 00000000..706475bd --- /dev/null +++ b/dbus/dbus-test-tap.h @@ -0,0 +1,44 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-test-tap — TAP helpers for "embedded tests" + * + * Copyright © 2017 Collabora Ltd. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef DBUS_TEST_TAP_H +#define DBUS_TEST_TAP_H + +#include + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + +DBUS_PRIVATE_EXPORT +void _dbus_test_fatal (const char *format, + ...) _DBUS_GNUC_NORETURN _DBUS_GNUC_PRINTF (1, 2); + +DBUS_PRIVATE_EXPORT +void _dbus_test_diag (const char *format, + ...) _DBUS_GNUC_PRINTF (1, 2); + +#endif + +#endif -- 2.15.0