"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/test-utils.c" between
dbus-1.13.12.tar.xz and dbus-1.13.14.tar.xz

About: D-Bus is an inter-process communication (IPC) system, allowing multiple, concurrently-running applications to communicate with one another. D-Bus supplies both a system daemon and a per-user-login-session daemon. Development version.

test-utils.c  (dbus-1.13.12.tar.xz):test-utils.c  (dbus-1.13.14.tar.xz)
/* /*
* Copyright 2002-2008 Red Hat Inc. * Copyright 2002-2009 Red Hat Inc.
* Copyright 2011-2017 Collabora Ltd. * Copyright 2011-2017 Collabora Ltd.
* Copyright 2017 Endless Mobile, Inc.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
* Permission is hereby granted, free of charge, to any person * Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files * obtaining a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, * (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, * including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, * publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, * and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions: * subject to the following conditions:
skipping to change at line 49 skipping to change at line 50
#ifdef DBUS_UNIX #ifdef DBUS_UNIX
# include <sys/types.h> # include <sys/types.h>
# include <unistd.h> # include <unistd.h>
# include <dbus/dbus-sysdeps-unix.h> # include <dbus/dbus-sysdeps-unix.h>
#else #else
# include <dbus/dbus-sysdeps-win.h> # include <dbus/dbus-sysdeps-win.h>
#endif #endif
#ifdef __linux__
/* Necessary for the Linux-specific fd leak checking code only */
#include <dirent.h>
#include <errno.h>
#endif
#include "dbus/dbus-message-internal.h" #include "dbus/dbus-message-internal.h"
#include "dbus/dbus-test-tap.h"
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/* /*
* Like strdup(), but crash on out-of-memory, and pass through NULL * Like strdup(), but crash on out-of-memory, and pass through NULL
* unchanged (the "0" in the name is meant to be a mnemonic for this, * unchanged (the "0" in the name is meant to be a mnemonic for this,
* similar to g_strcmp0()). * similar to g_strcmp0()).
*/ */
static char * static char *
strdup0_or_die (const char *str) strdup0_or_die (const char *str)
{ {
char *ret; char *ret;
if (str == NULL) if (str == NULL)
return NULL; /* not an error */ return NULL; /* not an error */
ret = strdup (str); ret = strdup (str);
if (ret == NULL) if (ret == NULL)
_dbus_test_fatal ("Out of memory"); _dbus_test_fatal ("Out of memory");
return ret; return ret;
} }
#endif
typedef struct typedef struct
{ {
DBusLoop *loop; DBusLoop *loop;
DBusConnection *connection; DBusConnection *connection;
} CData; } CData;
static dbus_bool_t static dbus_bool_t
add_watch (DBusWatch *watch, add_watch (DBusWatch *watch,
skipping to change at line 463 skipping to change at line 467
void void
test_pending_call_store_reply (DBusPendingCall *pc, test_pending_call_store_reply (DBusPendingCall *pc,
void *data) void *data)
{ {
DBusMessage **message_p = data; DBusMessage **message_p = data;
*message_p = dbus_pending_call_steal_reply (pc); *message_p = dbus_pending_call_steal_reply (pc);
_dbus_assert (*message_p != NULL); _dbus_assert (*message_p != NULL);
} }
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#ifdef DBUS_UNIX #ifdef DBUS_UNIX
/* /*
* Set uid to a machine-readable authentication identity (numeric Unix * Set uid to a machine-readable authentication identity (numeric Unix
* uid or ConvertSidToStringSid-style Windows SID) that is likely to exist, * uid or ConvertSidToStringSid-style Windows SID) that is likely to exist,
* and differs from the identity of the current process. * and differs from the identity of the current process.
* *
* @param uid Populated with a machine-readable authentication identity * @param uid Populated with a machine-readable authentication identity
* on success * on success
* @returns #FALSE if no memory * @returns #FALSE if no memory
skipping to change at line 528 skipping to change at line 530
ret = _dbus_string_append (uid, LOCAL_SYSTEM_SID); ret = _dbus_string_append (uid, LOCAL_SYSTEM_SID);
else else
ret = _dbus_string_append (uid, ANONYMOUS_SID); ret = _dbus_string_append (uid, ANONYMOUS_SID);
LocalFree (sid); LocalFree (sid);
return ret; return ret;
} }
#endif /* !defined(DBUS_UNIX) */ #endif /* !defined(DBUS_UNIX) */
#ifdef __linux__
struct DBusInitialFDs {
fd_set set;
};
#endif
DBusInitialFDs *
_dbus_check_fdleaks_enter (void)
{
#ifdef __linux__
DIR *d;
DBusInitialFDs *fds;
/* this is plain malloc so it won't interfere with leak checking */
fds = malloc (sizeof (DBusInitialFDs));
_dbus_assert (fds != NULL);
/* This works on Linux only */
if ((d = opendir ("/proc/self/fd")))
{
struct dirent *de;
while ((de = readdir(d)))
{
long l;
char *e = NULL;
int fd;
if (de->d_name[0] == '.')
continue;
errno = 0;
l = strtol (de->d_name, &e, 10);
_dbus_assert (errno == 0 && e && !*e);
fd = (int) l;
if (fd < 3)
continue;
if (fd == dirfd (d))
continue;
if (fd >= FD_SETSIZE)
{
_dbus_verbose ("FD %d unexpectedly large; cannot track whether "
"it is leaked\n", fd);
continue;
}
FD_SET (fd, &fds->set);
}
closedir (d);
}
return fds;
#else
return NULL;
#endif
}
void
_dbus_check_fdleaks_leave (DBusInitialFDs *fds,
const char *context)
{
#ifdef __linux__
DIR *d;
/* This works on Linux only */
if ((d = opendir ("/proc/self/fd")))
{
struct dirent *de;
while ((de = readdir(d)))
{
long l;
char *e = NULL;
int fd;
if (de->d_name[0] == '.')
continue;
errno = 0;
l = strtol (de->d_name, &e, 10);
_dbus_assert (errno == 0 && e && !*e);
fd = (int) l;
if (fd < 3)
continue;
if (fd == dirfd (d))
continue;
if (fd >= FD_SETSIZE)
{
_dbus_verbose ("FD %d unexpectedly large; cannot track whether "
"it is leaked\n", fd);
continue;
}
if (FD_ISSET (fd, &fds->set))
continue;
_dbus_test_fatal ("file descriptor %i leaked in %s.", fd, context);
}
closedir (d);
}
free (fds);
#else
_dbus_assert (fds == NULL);
#endif
}
/* /*
* _dbus_test_main: * _dbus_test_main:
* @argc: number of command-line arguments * @argc: number of command-line arguments
* @argv: array of @argc arguments * @argv: array of @argc arguments
* @n_tests: length of @tests * @n_tests: length of @tests
* @tests: array of @n_tests tests * @tests: array of @n_tests tests
* @flags: flags affecting all tests * @flags: flags affecting all tests
* @test_pre_hook: if not %NULL, called before each test * @test_pre_hook: if not %NULL, called before each test
* @test_post_hook: if not %NULL, called after each test * @test_post_hook: if not %NULL, called after each test
* *
skipping to change at line 652 skipping to change at line 773
_dbus_test_diag ("%s test took %ld seconds", _dbus_test_diag ("%s test took %ld seconds",
tests[i].name, after - before); tests[i].name, after - before);
if (test_post_hook) if (test_post_hook)
test_post_hook (); test_post_hook ();
if (flags & DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS) if (flags & DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS)
_dbus_test_check_memleaks (tests[i].name); _dbus_test_check_memleaks (tests[i].name);
if (flags & DBUS_TEST_FLAGS_CHECK_FD_LEAKS) 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); free (test_data_dir);
free (specific_test); free (specific_test);
return _dbus_test_done_testing (); return _dbus_test_done_testing ();
} }
/* If embedded tests are enabled, the TAP helpers have to be in the
* shared library because some of the embedded tests call them. If not,
* implement them here. We #include the file here instead of adding it
* to SOURCES because Automake versions older than 1.16 can't cope with
* expanding directory variables in SOURCES when using subdir-objects. */
#ifndef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus/dbus-test-tap.c"
#endif #endif
 End of changes. 10 change blocks. 
7 lines changed or deleted 135 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)