From 269d74f214f87bed0f6fd58f1c848240d31e0b9f Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 26 Mar 2003 07:16:03 +0000 Subject: [PATCH] 2003-03-26 Havoc Pennington * bus/test-main.c, dbus/dbus-test.c (main): check memleaks after every test so it's quick and easy to see which leaked, and so we test multiple dbus_shutdown() calls * configure.in: change configure.in XML stuff to also support expat * config-loader-libxml.c: some hacking * config-loader-expat.c: some hacking * config-parser.c: some hacking, plus tests --- ChangeLog | 15 ++ bus/Makefile.am | 3 + bus/config-loader-expat.c | 280 ++++++++++++++++++++++++++++++++ bus/config-loader-libxml.c | 74 ++++++++- bus/config-parser.c | 224 +++++++++++++++++++++++++ bus/test-main.c | 30 ++-- configure.in | 76 ++++++--- dbus/dbus-test.c | 49 +++++- test/data/valid-config-files/basic.conf | 7 + 9 files changed, 711 insertions(+), 47 deletions(-) create mode 100644 bus/config-loader-expat.c create mode 100644 test/data/valid-config-files/basic.conf diff --git a/ChangeLog b/ChangeLog index a789b2f..cb0f041 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2003-03-26 Havoc Pennington + + * bus/test-main.c, dbus/dbus-test.c (main): check memleaks + after every test so it's quick and easy to see which leaked, and + so we test multiple dbus_shutdown() calls + + * configure.in: change configure.in XML stuff to also support + expat + + * config-loader-libxml.c: some hacking + + * config-loader-expat.c: some hacking + + * config-parser.c: some hacking, plus tests + 2003-03-25 Havoc Pennington * throughout - add more _DBUS_ASSERT_ERROR_IS_CLEAR diff --git a/bus/Makefile.am b/bus/Makefile.am index 37d3de0..904e0c5 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -9,6 +9,9 @@ bin_PROGRAMS=dbus-daemon-1 if DBUS_USE_LIBXML XML_SOURCES=config-loader-libxml.c endif +if DBUS_USE_EXPAT +XML_SOURCES=config-loader-expat.c +endif BUS_SOURCES= \ activation.c \ diff --git a/bus/config-loader-expat.c b/bus/config-loader-expat.c new file mode 100644 index 0000000..5e8d28c --- /dev/null +++ b/bus/config-loader-expat.c @@ -0,0 +1,280 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* config-loader-expat.c expat XML loader + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 1.2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "config-parser.h" +#include +#include + +static void* +expat_malloc (size_t size) +{ + return dbus_malloc (size); +} + +static void* +expat_realloc (void *ptr, size_t size) +{ + return dbus_realloc (ptr, size); +} + +static void +expat_free (void *ptr) +{ + dbus_free (ptr); +} + +static XML_Memory_Handling_Suite memsuite = +{ + expat_malloc, + expat_realloc, + expat_free +}; + +typedef struct +{ + BusConfigParser *parser; + const char *filename; + DBusString content; + DBusError *error; + dbus_bool_t failed; +} ExpatParseContext; + +static void +expat_StartElementHandler (void *userData, + const XML_Char *name, + const XML_Char **atts) +{ + ExpatParseContext *context = userData; + int i; + char **names; + char **values; + + /* Expat seems to suck and can't abort the parse if we + * throw an error. Expat 2.0 is supposed to fix this. + */ + if (context->failed) + return; + + /* "atts" is key, value, key, value, NULL */ + for (i = 0; atts[i] != NULL; ++i) + ; /* nothing */ + + _dbus_assert (i % 2 == 0); + names = dbus_new0 (char *, i / 2 + 1); + values = dbus_new0 (char *, i / 2 + 1); + + if (names == NULL || values == NULL) + { + dbus_set_error (context->error, DBUS_ERROR_NO_MEMORY, NULL); + context->failed = TRUE; + dbus_free (names); + dbus_free (values); + return; + } + + i = 0; + while (atts[i] != NULL) + { + _dbus_assert (i % 2 == 0); + names [i / 2] = (char*) atts[i]; + values[i / 2 + 1] = (char*) atts[i+1]; + + i += 2; + } + + if (!bus_config_parser_start_element (context->parser, + name, + (const char **) names, + (const char **) values, + context->error)) + { + dbus_free (names); + dbus_free (values); + context->failed = TRUE; + return; + } + + dbus_free (names); + dbus_free (values); +} + +static void +expat_EndElementHandler (void *userData, + const XML_Char *name) +{ + ExpatParseContext *context = userData; + if (context->failed) + return; + + if (_dbus_string_get_length (&context->content) > 0) + { + if (!bus_config_parser_content (context->parser, + &context->content, + context->error)) + { + context->failed = TRUE; + return; + } + _dbus_string_set_length (&context->content, 0); + } + + if (!bus_config_parser_end_element (context->parser, + name, + context->error)) + { + context->failed = TRUE; + return; + } +} + +/* s is not 0 terminated. */ +static void +expat_CharacterDataHandler (void *userData, + const XML_Char *s, + int len) +{ + ExpatParseContext *context = userData; + if (context->failed) + return; + + if (!_dbus_string_append_len (&context->content, + s, len)) + { + dbus_set_error (context->error, DBUS_ERROR_NO_MEMORY, NULL); + context->failed = TRUE; + return; + } +} + + +BusConfigParser* +bus_config_load (const DBusString *file, + DBusError *error) +{ + XML_Parser *expat; + const char *filename; + BusConfigParser *parser; + ExpatParseContext context; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + parser = NULL; + expat = NULL; + context.error = error; + context.failed = FALSE; + + _dbus_string_get_const_data (file, &filename); + + if (!_dbus_string_init (&context.content, _DBUS_INT_MAX)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } + + expat = XML_ParserCreate_MM ("UTF-8", &memsuite, NULL); + if (expat == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed; + } + + parser = bus_config_parser_new (); + if (parser == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed; + } + + XML_SetUserData (expat, &context); + XML_SetElementHandler (expat, + expat_StartElementHandler, + expat_EndElementHandler); + XML_SetCharacterDataHandler (expat, + expat_CharacterDataHandler); + + { + DBusString data; + const char *data_str; + + if (!_dbus_string_init (&data, _DBUS_INT_MAX)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed; + } + + if (!_dbus_file_get_contents (&data, file, error)) + { + _dbus_string_free (&data); + goto failed; + } + + _dbus_string_get_const_data (&data, &data_str); + + if (!XML_Parse (expat, data_str, _dbus_string_get_length (&data), TRUE)) + { + if (context.error != NULL && + !dbus_error_is_set (context.error)) + { + enum XML_Error e; + + e = XML_GetErrorCode (expat); + if (e == XML_ERROR_NO_MEMORY) + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + else + dbus_set_error (error, DBUS_ERROR_FAILED, + "Error in file %s, line %d, column %d: %s\n", + filename, + XML_GetCurrentLineNumber (expat), + XML_GetCurrentColumnNumber (expat), + XML_ErrorString (e)); + } + + _dbus_string_free (&data); + goto failed; + } + + _dbus_string_free (&data); + + if (context.failed) + goto failed; + } + + if (!bus_config_parser_finished (parser, error)) + goto failed; + + _dbus_string_free (&context.content); + XML_ParserFree (expat); + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return parser; + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + + _dbus_string_free (&context.content); + if (expat) + XML_ParserFree (expat); + if (parser) + bus_config_parser_unref (parser); + return NULL; +} diff --git a/bus/config-loader-libxml.c b/bus/config-loader-libxml.c index 3bfc97f..74cfd7d 100644 --- a/bus/config-loader-libxml.c +++ b/bus/config-loader-libxml.c @@ -26,9 +26,34 @@ #include #include #include +#include #include #include +static void* +libxml_malloc (size_t size) +{ + return dbus_malloc (size); +} + +static void* +libxml_realloc (void *ptr, size_t size) +{ + return dbus_realloc (ptr, size); +} + +static void +libxml_free (void *ptr) +{ + dbus_free (ptr); +} + +static char* +libxml_strdup (const char *str) +{ + return _dbus_strdup (str); +} + static void xml_text_reader_error (void *arg, const char *msg, @@ -57,6 +82,30 @@ bus_config_load (const DBusString *file, _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_string_get_const_data (file, &filename); + parser = NULL; + reader = NULL; + dbus_error_init (&tmp_error); + + if (xmlMemSetup (libxml_free, + libxml_malloc, + libxml_realloc, + libxml_strdup) != 0) + { + /* Current libxml can't possibly fail here, but just being + * paranoid; don't really know why xmlMemSetup() returns an + * error code, assuming some version of libxml had a reason. + */ + dbus_set_error (error, DBUS_ERROR_FAILED, + "xmlMemSetup() didn't work for some reason\n"); + return NULL; + } + + parser = bus_config_parser_new (); + if (parser == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } errno = 0; reader = xmlNewTextReaderFilename (filename); @@ -68,24 +117,35 @@ bus_config_load (const DBusString *file, filename, errno != 0 ? strerror (errno) : "Unknown error"); - return NULL; + goto failed; } - dbus_error_init (&tmp_error); xmlTextReaderSetErrorHandler (reader, xml_text_reader_error, &tmp_error); - while (xmlTextReaderRead(reader) == 1) + while (xmlTextReaderRead (reader) == 1) { + int type; + if (dbus_error_is_set (&tmp_error)) goto reader_out; - + /* "enum" anyone? http://dotgnu.org/pnetlib-doc/System/Xml/XmlNodeType.html for + * the magic numbers + */ + type = xmlTextReaderNodeType (reader); + if (dbus_error_is_set (&tmp_error)) + goto reader_out; - + /* FIXME I don't really know exactly what I need to do to + * resolve all entities and so on to get the full content of a + * node or attribute value. I'm worried about whether I need to + * manually handle stuff like < + */ } reader_out: xmlFreeTextReader (reader); + reader = NULL; if (dbus_error_is_set (&tmp_error)) { dbus_move_error (&tmp_error, error); @@ -100,6 +160,8 @@ bus_config_load (const DBusString *file, failed: _DBUS_ASSERT_ERROR_IS_SET (error); - bus_config_parser_unref (parser); + if (parser) + bus_config_parser_unref (parser); + _dbus_assert (reader == NULL); /* must go to reader_out first */ return NULL; } diff --git a/bus/config-parser.c b/bus/config-parser.c index 0d33d2b..8fb3b29 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -183,6 +183,7 @@ bus_config_parser_start_element (BusConfigParser *parser, { _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return TRUE; } dbus_bool_t @@ -192,6 +193,7 @@ bus_config_parser_end_element (BusConfigParser *parser, { _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return TRUE; } dbus_bool_t @@ -201,6 +203,7 @@ bus_config_parser_content (BusConfigParser *parser, { _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return TRUE; } dbus_bool_t @@ -209,6 +212,7 @@ bus_config_parser_finished (BusConfigParser *parser, { _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return TRUE; } const char* @@ -216,13 +220,233 @@ bus_config_parser_get_user (BusConfigParser *parser) { + return NULL; } #ifdef DBUS_BUILD_TESTS +#include + +typedef enum +{ + VALID, + INVALID, + UNKNOWN +} Validity; + +static dbus_bool_t +do_load (const DBusString *full_path, + Validity validity, + dbus_bool_t oom_possible) +{ + BusConfigParser *parser; + DBusError error; + + dbus_error_init (&error); + + parser = bus_config_load (full_path, &error); + if (parser == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + + if (oom_possible && + dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_verbose ("Failed to load valid file due to OOM\n"); + dbus_error_free (&error); + return TRUE; + } + else if (validity == VALID) + { + _dbus_warn ("Failed to load valid file but still had memory: %s\n", + error.message); + + dbus_error_free (&error); + return FALSE; + } + else + { + dbus_error_free (&error); + return TRUE; + } + } + else + { + _DBUS_ASSERT_ERROR_IS_CLEAR (&error); + + bus_config_parser_unref (parser); + + if (validity == INVALID) + { + _dbus_warn ("Accepted invalid file\n"); + return FALSE; + } + + return TRUE; + } +} + +static dbus_bool_t +check_oom_loading (const DBusString *full_path, + Validity validity) +{ + int approx_mallocs; + + /* Run once to see about how many mallocs are involved */ + + _dbus_set_fail_alloc_counter (_DBUS_INT_MAX); + + if (!do_load (full_path, validity, FALSE)) + return FALSE; + + approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter (); + + _dbus_verbose ("=================\nabout %d mallocs total\n=================\n", + approx_mallocs); + + approx_mallocs += 10; /* fudge factor */ + + /* Now run failing each malloc */ + + while (approx_mallocs >= 0) + { + + _dbus_set_fail_alloc_counter (approx_mallocs); + + _dbus_verbose ("\n===\n(will fail malloc %d)\n===\n", + approx_mallocs); + + if (!do_load (full_path, validity, TRUE)) + return FALSE; + + approx_mallocs -= 1; + } + + _dbus_set_fail_alloc_counter (_DBUS_INT_MAX); + + _dbus_verbose ("=================\n all iterations passed\n=================\n"); + + return TRUE; +} + +static dbus_bool_t +process_test_subdir (const DBusString *test_base_dir, + const char *subdir, + Validity validity) +{ + DBusString test_directory; + DBusString filename; + DBusDirIter *dir; + dbus_bool_t retval; + DBusError error; + + retval = FALSE; + dir = NULL; + + if (!_dbus_string_init (&test_directory, _DBUS_INT_MAX)) + _dbus_assert_not_reached ("didn't allocate test_directory\n"); + + _dbus_string_init_const (&filename, subdir); + + if (!_dbus_string_copy (test_base_dir, 0, + &test_directory, 0)) + _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory"); + + if (!_dbus_concat_dir_and_file (&test_directory, &filename)) + _dbus_assert_not_reached ("couldn't allocate full path"); + + _dbus_string_free (&filename); + if (!_dbus_string_init (&filename, _DBUS_INT_MAX)) + _dbus_assert_not_reached ("didn't allocate filename string\n"); + + dbus_error_init (&error); + dir = _dbus_directory_open (&test_directory, &error); + if (dir == NULL) + { + const char *s; + _dbus_string_get_const_data (&test_directory, &s); + _dbus_warn ("Could not open %s: %s\n", s, + error.message); + dbus_error_free (&error); + goto failed; + } + + printf ("Testing:\n"); + + next: + while (_dbus_directory_get_next_file (dir, &filename, &error)) + { + DBusString full_path; + + if (!_dbus_string_init (&full_path, _DBUS_INT_MAX)) + _dbus_assert_not_reached ("couldn't init string"); + + if (!_dbus_string_copy (&test_directory, 0, &full_path, 0)) + _dbus_assert_not_reached ("couldn't copy dir to full_path"); + + if (!_dbus_concat_dir_and_file (&full_path, &filename)) + _dbus_assert_not_reached ("couldn't concat file to dir"); + + if (!_dbus_string_ends_with_c_str (&full_path, ".conf")) + { + const char *filename_c; + _dbus_string_get_const_data (&filename, &filename_c); + _dbus_verbose ("Skipping non-.conf file %s\n", + filename_c); + _dbus_string_free (&full_path); + goto next; + } + + { + const char *s; + _dbus_string_get_const_data (&filename, &s); + printf (" %s\n", s); + } + + _dbus_verbose (" expecting %s\n", + validity == VALID ? "valid" : + (validity == INVALID ? "invalid" : + (validity == UNKNOWN ? "unknown" : "???"))); + + if (!check_oom_loading (&full_path, validity)) + _dbus_assert_not_reached ("test failed"); + + _dbus_string_free (&full_path); + } + + if (dbus_error_is_set (&error)) + { + const char *s; + _dbus_string_get_const_data (&test_directory, &s); + _dbus_warn ("Could not get next file in %s: %s\n", + s, error.message); + dbus_error_free (&error); + goto failed; + } + + retval = TRUE; + + failed: + + if (dir) + _dbus_directory_close (dir); + _dbus_string_free (&test_directory); + _dbus_string_free (&filename); + + return retval; +} dbus_bool_t bus_config_parser_test (const DBusString *test_data_dir) { + if (test_data_dir == NULL || + _dbus_string_get_length (test_data_dir) == 0) + { + printf ("No test data\n"); + return TRUE; + } + + if (!process_test_subdir (test_data_dir, "valid-config-files", VALID)) + return FALSE; return TRUE; } diff --git a/bus/test-main.c b/bus/test-main.c index c7f9f7b..3768de5 100644 --- a/bus/test-main.c +++ b/bus/test-main.c @@ -35,6 +35,20 @@ die (const char *failure) exit (1); } +static void +check_memleaks (const char *name) +{ + dbus_shutdown (); + + printf ("%s: checking for memleaks\n", name); + if (_dbus_get_malloc_blocks_outstanding () != 0) + { + _dbus_warn ("%d dbus_malloc blocks were not freed\n", + _dbus_get_malloc_blocks_outstanding ()); + die ("memleaks"); + } +} + int main (int argc, char **argv) { @@ -56,23 +70,19 @@ main (int argc, char **argv) if (!bus_config_parser_test (&test_data_dir)) die ("parser"); + check_memleaks (argv[0]); + printf ("%s: Running policy test\n", argv[0]); if (!bus_policy_test (&test_data_dir)) die ("policy"); + + check_memleaks (argv[0]); printf ("%s: Running message dispatch test\n", argv[0]); if (!bus_dispatch_test (&test_data_dir)) die ("dispatch"); - - dbus_shutdown (); - - printf ("%s: checking for memleaks\n", argv[0]); - if (_dbus_get_malloc_blocks_outstanding () != 0) - { - _dbus_warn ("%d dbus_malloc blocks were not freed\n", - _dbus_get_malloc_blocks_outstanding ()); - die ("memleaks"); - } + + check_memleaks (argv[0]); printf ("%s: Success\n", argv[0]); diff --git a/configure.in b/configure.in index 552a7cf..7212f3b 100644 --- a/configure.in +++ b/configure.in @@ -31,7 +31,7 @@ AC_ARG_ENABLE(verbose-mode, [ --enable-verbose-mode support verbose debug mode] AC_ARG_ENABLE(asserts, [ --enable-asserts include assertion checks],enable_asserts=$enableval,enable_asserts=yes) AC_ARG_ENABLE(gcov, [ --enable-gcov compile with coverage profiling instrumentation (gcc only)],enable_gcov=$enableval,enable_gcov=no) -AC_ARG_WITH(xml, [ --with-xml=[libxml] XML library to use]) +AC_ARG_WITH(xml, [ --with-xml=[libxml/expat] XML library to use]) dnl DBUS_BUILD_TESTS controls unit tests built in to .c files dnl and also some stuff in the test/ subdir @@ -47,23 +47,6 @@ if test x$enable_asserts = xno; then AC_DEFINE(DBUS_DISABLE_ASSERT,1,[Disable assertion checking]) fi -dbus_use_libxml=false -dbus_use_fooxml=false -if test x$with_xml = xfooxml; then - dbus_use_fooxml=true -elif test x$with_xml = xlibxml; then - dbus_use_libxml=true -else - with_xml=libxml - dbus_use_libxml=true -fi - -AM_CONDITIONAL(DBUS_USE_LIBXML, $dbus_use_libxml) -if $dbus_use_libxml; then - PKG_CHECK_MODULES(LIBXML, libxml-2.0) -fi -AM_CONDITIONAL(DBUS_USE_FOOXML, $dbus_use_fooxml) - if test "x$GCC" = "xyes"; then changequote(,)dnl case " $CFLAGS " in @@ -137,8 +120,6 @@ else fi fi - - AC_CHECK_SIZEOF(char) AC_CHECK_SIZEOF(short) AC_CHECK_SIZEOF(long) @@ -238,13 +219,64 @@ if test x$dbus_have_struct_cmsgcred = xyes; then AC_DEFINE(HAVE_CMSGCRED,1,[Have cmsgcred structure]) fi + +#### Sort out XML library + +# see what we have +AC_CHECK_LIB(expat, XML_ParserCreate_MM, + [ AC_CHECK_HEADERS(expat.h, have_expat=true, have_expat=false) ], + have_expat=false) + +PKG_CHECK_MODULES(LIBXML, libxml-2.0, have_libxml=true, have_libxml=false) + +# see what we want to use +dbus_use_libxml=false +dbus_use_expat=false +if test x$with_xml = xexpat; then + dbus_use_expat=true + if ! $have_expat ; then + AC_MSG_ERROR([Explicitly requested expat but expat not found]) + fi +elif test x$with_xml = xlibxml; then + dbus_use_libxml=true + if ! $have_libxml ; then + AC_MSG_ERROR([Explicitly requested libxml but libxml not found]) + fi +else + ### expat is the default because libxml can't currently survive + ### our brutal OOM-handling unit test setup. Need to find the + ### bugs and submit to DV + if $have_expat ; then + with_xml=expat + dbus_use_expat=true + elif $have_libxml ; then + with_xml=libxml + dbus_use_libxml=true + else + AC_MSG_ERROR([No XML library found, check config.log for failed attempts]) + fi +fi + +AM_CONDITIONAL(DBUS_USE_EXPAT, $dbus_use_expat) +AM_CONDITIONAL(DBUS_USE_LIBXML, $dbus_use_libxml) + +if $dbus_use_expat; then + XML_LIBS=-lexpat + XML_CFLAGS= +fi +if $dbus_use_libxml; then + XML_LIBS=$LIBXML_LIBS + XML_CFLAGS=$LIBXML_CFLAGS +fi + +#### Set up final flags DBUS_CLIENT_CFLAGS= DBUS_CLIENT_LIBS= AC_SUBST(DBUS_CLIENT_CFLAGS) AC_SUBST(DBUS_CLIENT_LIBS) -DBUS_BUS_CFLAGS=$LIBXML_CFLAGS -DBUS_BUS_LIBS=$LIBXML_LIBS +DBUS_BUS_CFLAGS=$XML_CFLAGS +DBUS_BUS_LIBS=$XML_LIBS AC_SUBST(DBUS_BUS_CFLAGS) AC_SUBST(DBUS_BUS_LIBS) diff --git a/dbus/dbus-test.c b/dbus/dbus-test.c index 3416011..b9cf64c 100644 --- a/dbus/dbus-test.c +++ b/dbus/dbus-test.c @@ -35,6 +35,21 @@ die (const char *failure) fprintf (stderr, "Unit test failed: %s\n", failure); exit (1); } + +static void +check_memleaks (void) +{ + dbus_shutdown (); + + printf ("%s: checking for memleaks\n", "dbus-test"); + if (_dbus_get_malloc_blocks_outstanding () != 0) + { + _dbus_warn ("%d dbus_malloc blocks were not freed\n", + _dbus_get_malloc_blocks_outstanding ()); + die ("memleaks"); + } +} + #endif /* DBUS_BUILD_TESTS */ /** @@ -61,66 +76,82 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir) printf ("%s: running string tests\n", "dbus-test"); if (!_dbus_string_test ()) die ("strings"); + + check_memleaks (); printf ("%s: running data slot tests\n", "dbus-test"); if (!_dbus_data_slot_test ()) die ("dataslot"); + + check_memleaks (); printf ("%s: running keyring tests\n", "dbus-test"); if (!_dbus_keyring_test ()) die ("keyring"); + + check_memleaks (); #if 0 printf ("%s: running md5 tests\n", "dbus-test"); if (!_dbus_md5_test ()) die ("md5"); + + check_memleaks (); #endif printf ("%s: running SHA-1 tests\n", "dbus-test"); if (!_dbus_sha_test (test_data_dir)) die ("SHA-1"); + + check_memleaks (); printf ("%s: running auth tests\n", "dbus-test"); if (!_dbus_auth_test (test_data_dir)) die ("auth"); + + check_memleaks (); printf ("%s: running address parse tests\n", "dbus-test"); if (!_dbus_address_test ()) die ("address parsing"); + + check_memleaks (); printf ("%s: running marshalling tests\n", "dbus-test"); if (!_dbus_marshal_test ()) die ("marshalling"); + check_memleaks (); + printf ("%s: running message tests\n", "dbus-test"); if (!_dbus_message_test (test_data_dir)) die ("messages"); + check_memleaks (); + printf ("%s: running memory pool tests\n", "dbus-test"); if (!_dbus_mem_pool_test ()) die ("memory pools"); + + check_memleaks (); printf ("%s: running linked list tests\n", "dbus-test"); if (!_dbus_list_test ()) die ("lists"); + check_memleaks (); + printf ("%s: running hash table tests\n", "dbus-test"); if (!_dbus_hash_test ()) die ("hash tables"); + + check_memleaks (); printf ("%s: running dict tests\n", "dbus-test"); if (!_dbus_dict_test ()) die ("dicts"); - dbus_shutdown (); - - printf ("%s: checking for memleaks\n", "dbus-test"); - if (_dbus_get_malloc_blocks_outstanding () != 0) - { - _dbus_warn ("%d dbus_malloc blocks were not freed\n", - _dbus_get_malloc_blocks_outstanding ()); - die ("memleaks"); - } + check_memleaks (); printf ("%s: completed successfully\n", "dbus-test"); #else diff --git a/test/data/valid-config-files/basic.conf b/test/data/valid-config-files/basic.conf new file mode 100644 index 0000000..4b09ef7 --- /dev/null +++ b/test/data/valid-config-files/basic.conf @@ -0,0 +1,7 @@ + + + + + + -- 2.7.4