Commit e4e904a8 authored by Simon McVittie's avatar Simon McVittie

tests: Improve messages when fd leaks are diagnosed

Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent 491a2da3
......@@ -453,6 +453,9 @@ dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str,
typedef struct { char _assertion[(expr) ? 1 : -1]; } \
_DBUS_PASTE (_DBUS_STATIC_ASSERT_, __LINE__) _DBUS_GNUC_UNUSED
#define _DBUS_STRINGIFY(x) #x
#define _DBUS_FILE_LINE __FILE__ ":" _DBUS_STRINGIFY(__LINE__)
DBUS_END_DECLS
#endif /* DBUS_INTERNALS_H */
......@@ -884,7 +884,8 @@ verify_test_message (DBusMessage *message)
}
static void
verify_test_message_args_ignored (DBusMessage *message)
verify_test_message_args_ignored (DBusMessage *message,
const char *context)
{
DBusMessageIter iter;
DBusError error = DBUS_ERROR_INIT;
......@@ -922,11 +923,12 @@ verify_test_message_args_ignored (DBusMessage *message)
_dbus_verbose ("arguments ignored.\n");
}
_dbus_check_fdleaks_leave (initial_fds);
_dbus_check_fdleaks_leave (initial_fds, context);
}
static void
verify_test_message_memleak (DBusMessage *message)
verify_test_message_memleak (DBusMessage *message,
const char *context)
{
DBusMessageIter iter;
DBusError error = DBUS_ERROR_INIT;
......@@ -1036,7 +1038,7 @@ verify_test_message_memleak (DBusMessage *message)
_dbus_close (our_unix_fd2, &error);
#endif
}
_dbus_check_fdleaks_leave (initial_fds);
_dbus_check_fdleaks_leave (initial_fds, context);
}
/**
......@@ -1501,7 +1503,7 @@ _dbus_message_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
_dbus_message_loader_unref (loader);
check_memleaks ();
_dbus_check_fdleaks_leave (initial_fds);
_dbus_check_fdleaks_leave (initial_fds, _DBUS_FILE_LINE);
initial_fds = _dbus_check_fdleaks_enter ();
/* Test enumeration of array elements */
......@@ -1623,8 +1625,8 @@ _dbus_message_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
_dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
verify_test_message_args_ignored (message);
verify_test_message_memleak (message);
verify_test_message_args_ignored (message, _DBUS_FILE_LINE);
verify_test_message_memleak (message, _DBUS_FILE_LINE);
dbus_message_unref (message);
......@@ -1660,7 +1662,7 @@ _dbus_message_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
}
check_memleaks ();
_dbus_check_fdleaks_leave (initial_fds);
_dbus_check_fdleaks_leave (initial_fds, _DBUS_FILE_LINE);
/* Now load every message in test_data_dir if we have one */
if (test_data_dir == NULL)
......@@ -1671,7 +1673,7 @@ _dbus_message_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
if (!foreach_message_file (test_data_dir, try_message_file, NULL))
_dbus_test_fatal ("foreach_message_file test failed");
_dbus_check_fdleaks_leave (initial_fds);
_dbus_check_fdleaks_leave (initial_fds, _DBUS_FILE_LINE);
return TRUE;
}
......
......@@ -597,7 +597,8 @@ _dbus_check_fdleaks_enter (void)
}
void
_dbus_check_fdleaks_leave (DBusInitialFDs *fds)
_dbus_check_fdleaks_leave (DBusInitialFDs *fds,
const char *context)
{
#ifdef __linux__
DIR *d;
......@@ -639,7 +640,7 @@ _dbus_check_fdleaks_leave (DBusInitialFDs *fds)
if (FD_ISSET (fd, &fds->set))
continue;
_dbus_test_fatal ("file descriptor %i leaked in %s.", fd, __FILE__);
_dbus_test_fatal ("file descriptor %i leaked in %s.", fd, context);
}
closedir (d);
......@@ -775,7 +776,7 @@ _dbus_test_main (int argc,
_dbus_test_check_memleaks (tests[i].name);
if (flags & DBUS_TEST_FLAGS_CHECK_FD_LEAKS)
_dbus_check_fdleaks_leave (initial_fds);
_dbus_check_fdleaks_leave (initial_fds, tests[i].name);
}
free (test_data_dir);
......
......@@ -99,6 +99,7 @@ dbus_bool_t _dbus_test_append_different_username (DBusString *username);
typedef struct DBusInitialFDs DBusInitialFDs;
DBusInitialFDs *_dbus_check_fdleaks_enter (void);
void _dbus_check_fdleaks_leave (DBusInitialFDs *fds);
void _dbus_check_fdleaks_leave (DBusInitialFDs *fds,
const char *context);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment