mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 10:52:22 +00:00
Switch systemd test to use generic dbus mock
Remove the virsystemdmock.la library and instead make use of the shared virmockdbus.la library Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
2c3ce1de94
commit
4607168e77
@ -365,7 +365,7 @@ test_libraries += bhyvexml2argvmock.la
|
||||
endif WITH_BHYVE
|
||||
|
||||
if WITH_DBUS
|
||||
test_libraries += virsystemdmock.la \
|
||||
test_libraries += \
|
||||
virmockdbus.la
|
||||
endif WITH_DBUS
|
||||
|
||||
@ -913,17 +913,12 @@ virmockdbus_la_LDFLAGS = -module -avoid-version \
|
||||
|
||||
virsystemdtest_SOURCES = \
|
||||
virsystemdtest.c testutils.h testutils.c
|
||||
virsystemdtest_CFLAGS = $(AM_CFLAGS)
|
||||
virsystemdtest_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
|
||||
virsystemdtest_LDADD = $(LDADDS)
|
||||
|
||||
virsystemdmock_la_SOURCES = \
|
||||
virsystemdmock.c
|
||||
virsystemdmock_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
|
||||
virsystemdmock_la_LDFLAGS = -module -avoid-version \
|
||||
-rpath /evil/libtool/hack/to/force/shared/lib/creation
|
||||
virsystemdtest_LDFLAGS = $(DRIVER_MODULE_LDFLAGS)
|
||||
|
||||
else ! WITH_DBUS
|
||||
EXTRA_DIST += virdbustest.c virmockdbus.c virsystemdtest.c virsystemdmock.c
|
||||
EXTRA_DIST += virdbustest.c virmockdbus.c virsystemdtest.c
|
||||
endif ! WITH_DBUS
|
||||
|
||||
viruritest_SOURCES = \
|
||||
|
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Daniel P. Berrange <berrange@redhat.com>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef __linux__
|
||||
# include "internal.h"
|
||||
|
||||
# include <stdlib.h>
|
||||
|
||||
# include <dbus/dbus.h>
|
||||
|
||||
void dbus_connection_set_change_sigpipe(dbus_bool_t will_modify_sigpipe ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
DBusConnection *dbus_bus_get(DBusBusType type ATTRIBUTE_UNUSED,
|
||||
DBusError *error ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (DBusConnection *)0x1;
|
||||
}
|
||||
|
||||
void dbus_connection_set_exit_on_disconnect(DBusConnection *connection ATTRIBUTE_UNUSED,
|
||||
dbus_bool_t exit_on_disconnect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
dbus_bool_t dbus_connection_set_watch_functions(DBusConnection *connection ATTRIBUTE_UNUSED,
|
||||
DBusAddWatchFunction add_function ATTRIBUTE_UNUSED,
|
||||
DBusRemoveWatchFunction remove_function ATTRIBUTE_UNUSED,
|
||||
DBusWatchToggledFunction toggled_function ATTRIBUTE_UNUSED,
|
||||
void *data ATTRIBUTE_UNUSED,
|
||||
DBusFreeFunction free_data_function ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
dbus_bool_t dbus_message_set_reply_serial(DBusMessage *message ATTRIBUTE_UNUSED,
|
||||
dbus_uint32_t serial ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
DBusMessage *dbus_connection_send_with_reply_and_block(DBusConnection *connection ATTRIBUTE_UNUSED,
|
||||
DBusMessage *message,
|
||||
int timeout_milliseconds ATTRIBUTE_UNUSED,
|
||||
DBusError *error ATTRIBUTE_UNUSED)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
const char *service = dbus_message_get_destination(message);
|
||||
const char *member = dbus_message_get_member(message);
|
||||
|
||||
if (STREQ(service, "org.freedesktop.machine1")) {
|
||||
if (getenv("FAIL_BAD_SERVICE")) {
|
||||
dbus_set_error_const(error,
|
||||
"org.freedesktop.systemd.badthing",
|
||||
"Something went wrong creating the machine");
|
||||
} else {
|
||||
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
}
|
||||
} else if (STREQ(service, "org.freedesktop.DBus") &&
|
||||
STREQ(member, "ListActivatableNames")) {
|
||||
const char *svc1 = "org.foo.bar.wizz";
|
||||
const char *svc2 = "org.freedesktop.machine1";
|
||||
DBusMessageIter iter, sub;
|
||||
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
||||
"s", &sub);
|
||||
|
||||
if (!dbus_message_iter_append_basic(&sub,
|
||||
DBUS_TYPE_STRING,
|
||||
&svc1))
|
||||
goto error;
|
||||
if (!getenv("FAIL_NO_SERVICE") &&
|
||||
!dbus_message_iter_append_basic(&sub,
|
||||
DBUS_TYPE_STRING,
|
||||
&svc2))
|
||||
goto error;
|
||||
dbus_message_iter_close_container(&iter, &sub);
|
||||
} else if (STREQ(service, "org.freedesktop.DBus") &&
|
||||
STREQ(member, "ListNames")) {
|
||||
const char *svc1 = "org.foo.bar.wizz";
|
||||
const char *svc2 = "org.freedesktop.systemd1";
|
||||
DBusMessageIter iter, sub;
|
||||
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
||||
"s", &sub);
|
||||
|
||||
if (!dbus_message_iter_append_basic(&sub,
|
||||
DBUS_TYPE_STRING,
|
||||
&svc1))
|
||||
goto error;
|
||||
if ((!getenv("FAIL_NO_SERVICE") && !getenv("FAIL_NOT_REGISTERED")) &&
|
||||
!dbus_message_iter_append_basic(&sub,
|
||||
DBUS_TYPE_STRING,
|
||||
&svc2))
|
||||
goto error;
|
||||
dbus_message_iter_close_container(&iter, &sub);
|
||||
} else {
|
||||
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
}
|
||||
|
||||
return reply;
|
||||
|
||||
error:
|
||||
dbus_message_unref(reply);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
/* Nothing to override on non-__linux__ platforms */
|
||||
#endif
|
@ -22,17 +22,93 @@
|
||||
|
||||
#include "testutils.h"
|
||||
|
||||
#ifdef __linux__
|
||||
#ifdef WITH_DBUS
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <dbus/dbus.h>
|
||||
|
||||
# include "virsystemd.h"
|
||||
# include "virlog.h"
|
||||
|
||||
# include "virmock.h"
|
||||
# define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
VIR_LOG_INIT("tests.systemdtest");
|
||||
|
||||
VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
|
||||
DBusMessage *,
|
||||
DBusConnection *, connection,
|
||||
DBusMessage *, message,
|
||||
int, timeout_milliseconds,
|
||||
DBusError *, error)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
const char *service = dbus_message_get_destination(message);
|
||||
const char *member = dbus_message_get_member(message);
|
||||
|
||||
VIR_MOCK_IMPL_INIT_REAL(dbus_connection_send_with_reply_and_block);
|
||||
|
||||
if (STREQ(service, "org.freedesktop.machine1")) {
|
||||
if (getenv("FAIL_BAD_SERVICE")) {
|
||||
dbus_set_error_const(error,
|
||||
"org.freedesktop.systemd.badthing",
|
||||
"Something went wrong creating the machine");
|
||||
} else {
|
||||
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
}
|
||||
} else if (STREQ(service, "org.freedesktop.DBus") &&
|
||||
STREQ(member, "ListActivatableNames")) {
|
||||
const char *svc1 = "org.foo.bar.wizz";
|
||||
const char *svc2 = "org.freedesktop.machine1";
|
||||
DBusMessageIter iter;
|
||||
DBusMessageIter sub;
|
||||
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
||||
"s", &sub);
|
||||
|
||||
if (!dbus_message_iter_append_basic(&sub,
|
||||
DBUS_TYPE_STRING,
|
||||
&svc1))
|
||||
goto error;
|
||||
if (!getenv("FAIL_NO_SERVICE") &&
|
||||
!dbus_message_iter_append_basic(&sub,
|
||||
DBUS_TYPE_STRING,
|
||||
&svc2))
|
||||
goto error;
|
||||
dbus_message_iter_close_container(&iter, &sub);
|
||||
} else if (STREQ(service, "org.freedesktop.DBus") &&
|
||||
STREQ(member, "ListNames")) {
|
||||
const char *svc1 = "org.foo.bar.wizz";
|
||||
const char *svc2 = "org.freedesktop.systemd1";
|
||||
DBusMessageIter iter;
|
||||
DBusMessageIter sub;
|
||||
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
||||
"s", &sub);
|
||||
|
||||
if (!dbus_message_iter_append_basic(&sub,
|
||||
DBUS_TYPE_STRING,
|
||||
&svc1))
|
||||
goto error;
|
||||
if ((!getenv("FAIL_NO_SERVICE") && !getenv("FAIL_NOT_REGISTERED")) &&
|
||||
!dbus_message_iter_append_basic(&sub,
|
||||
DBUS_TYPE_STRING,
|
||||
&svc2))
|
||||
goto error;
|
||||
dbus_message_iter_close_container(&iter, &sub);
|
||||
} else {
|
||||
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
}
|
||||
|
||||
return reply;
|
||||
|
||||
error:
|
||||
dbus_message_unref(reply);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static int testCreateContainer(const void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
unsigned char uuid[VIR_UUID_BUFLEN] = {
|
||||
@ -278,12 +354,12 @@ mymain(void)
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virsystemdmock.so")
|
||||
VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virmockdbus.so")
|
||||
|
||||
#else
|
||||
#else /* ! WITH_DBUS */
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
return EXIT_AM_SKIP;
|
||||
}
|
||||
#endif
|
||||
#endif /* ! WITH_DBUS */
|
||||
|
Loading…
x
Reference in New Issue
Block a user