summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-11-14 14:01:56 +0000
committerSimon McVittie <smcv@collabora.com>2017-11-15 12:11:21 +0000
commit5ffb709b42783b0d13a49b8c9a84c75f556c88a2 (patch)
tree62c21a30307a05fd9d5db6856df0654982ed0984
parentfb9e8e4e0ce24b1fa65e157739826773b5d3f05d (diff)
Add utility functions to emit TAP diagnostics and fatal errors
Reviewed-by: Philip Withnall <withnall@endlessm.com> [smcv: Add an explanatory comment as suggested] Signed-off-by: Simon McVittie <smcv@collabora.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
-rw-r--r--cmake/dbus/CMakeLists.txt2
-rw-r--r--dbus/Makefile.am2
-rw-r--r--dbus/dbus-test-tap.c77
-rw-r--r--dbus/dbus-test-tap.h44
4 files changed, 125 insertions, 0 deletions
diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt
index 8a01d918b..2fdd11282 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 b2913ef0e..d4fe09f89 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 000000000..a6f99b547
--- /dev/null
+++ b/dbus/dbus-test-tap.c
@@ -0,0 +1,77 @@
+/* -*- 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 <config.h>
+#include "dbus/dbus-test-tap.h"
+
+/*
+ * TAP, the Test Anything Protocol, is a text-based syntax for test-cases
+ * to report results to test harnesses.
+ *
+ * See <http://testanything.org/> for details of the syntax, which
+ * will not be explained here.
+ */
+
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+ * 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 000000000..706475bdd
--- /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 <dbus/dbus-internals.h>
+
+#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