mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-24 18:10:09 +01:00
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
This commit is contained in:
parent
fb9e8e4e0c
commit
5ffb709b42
4 changed files with 125 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
77
dbus/dbus-test-tap.c
Normal file
77
dbus/dbus-test-tap.c
Normal file
|
|
@ -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
|
||||
44
dbus/dbus-test-tap.h
Normal file
44
dbus/dbus-test-tap.h
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue