build: disable Test interface in base manager if building without tests

There is no real need for this interface if tests are not being built.
This commit is contained in:
Aleksander Morgado
2022-10-27 22:08:37 +00:00
parent 7ea2452b1e
commit 634f6cbcbc
6 changed files with 65 additions and 20 deletions

View File

@@ -90,6 +90,7 @@ cc_args = cc.get_supported_arguments([
# tests are enabled by default
enable_tests = get_option('tests')
config_h.set('WITH_TESTS', enable_tests)
# strict flags to use in debug builds
if get_option('buildtype').contains('debug')

View File

@@ -97,7 +97,9 @@ bus_acquired_cb (GDBusConnection *connection,
!mm_context_get_no_auto_scan (),
mm_context_get_filter_policy (),
mm_context_get_initial_kernel_events (),
#if defined WITH_TESTS
mm_context_get_test_enable (),
#endif
&error);
if (!manager) {
mm_warn ("could not create manager: %s", error->message);

View File

@@ -41,7 +41,9 @@
#include <mm-errors-types.h>
#include <mm-gdbus-manager.h>
#include <mm-gdbus-test.h>
#if defined WITH_TESTS
# include <mm-gdbus-test.h>
#endif
#include "mm-context.h"
#include "mm-base-manager.h"
@@ -66,9 +68,11 @@ enum {
PROP_CONNECTION,
PROP_AUTO_SCAN,
PROP_FILTER_POLICY,
PROP_ENABLE_TEST,
PROP_PLUGIN_DIR,
PROP_INITIAL_KERNEL_EVENTS,
#if defined WITH_TESTS
PROP_ENABLE_TEST,
#endif
LAST_PROP
};
@@ -79,8 +83,6 @@ struct _MMBaseManagerPrivate {
gboolean auto_scan;
/* Filter policy (mask of enabled rules) */
MMFilterRule filter_policy;
/* Whether the test interface is enabled */
gboolean enable_test;
/* Path to look for plugins */
gchar *plugin_dir;
/* Path to the list of initial kernel events */
@@ -99,8 +101,12 @@ struct _MMBaseManagerPrivate {
/* The map of inhibited devices */
GHashTable *inhibited_devices;
#if defined WITH_TESTS
/* Whether the test interface is enabled */
gboolean enable_test;
/* The Test interface support */
MmGdbusTest *test_skeleton;
#endif
#if defined WITH_UDEV
/* The UDev client */
@@ -1297,6 +1303,8 @@ handle_inhibit_device (MmGdbusOrgFreedesktopModemManager1 *manager,
/*****************************************************************************/
/* Test profile setup */
#if defined WITH_TESTS
static gboolean
handle_set_profile (MmGdbusTest *skeleton,
GDBusMethodInvocation *invocation,
@@ -1358,6 +1366,8 @@ out:
return TRUE;
}
#endif
/*****************************************************************************/
static gchar *
@@ -1374,7 +1384,9 @@ mm_base_manager_new (GDBusConnection *connection,
gboolean auto_scan,
MMFilterRule filter_policy,
const gchar *initial_kernel_events,
#if defined WITH_TESTS
gboolean enable_test,
#endif
GError **error)
{
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
@@ -1387,8 +1399,10 @@ mm_base_manager_new (GDBusConnection *connection,
MM_BASE_MANAGER_AUTO_SCAN, auto_scan,
MM_BASE_MANAGER_FILTER_POLICY, filter_policy,
MM_BASE_MANAGER_INITIAL_KERNEL_EVENTS, initial_kernel_events,
MM_BASE_MANAGER_ENABLE_TEST, enable_test,
"version", MM_DIST_VERSION,
#if defined WITH_TESTS
MM_BASE_MANAGER_ENABLE_TEST, enable_test,
#endif
NULL);
}
@@ -1415,11 +1429,13 @@ set_property (GObject *object,
mm_obj_dbg (self, "stopping connection in object manager server");
g_dbus_object_manager_server_set_connection (self->priv->object_manager, NULL);
}
#if defined WITH_TESTS
if (self->priv->test_skeleton &&
g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (self->priv->test_skeleton))) {
mm_obj_dbg (self, "stopping connection in test skeleton");
g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->priv->test_skeleton));
}
#endif
}
break;
}
@@ -1429,9 +1445,6 @@ set_property (GObject *object,
case PROP_FILTER_POLICY:
self->priv->filter_policy = g_value_get_flags (value);
break;
case PROP_ENABLE_TEST:
self->priv->enable_test = g_value_get_boolean (value);
break;
case PROP_PLUGIN_DIR:
g_free (self->priv->plugin_dir);
self->priv->plugin_dir = g_value_dup_string (value);
@@ -1440,6 +1453,11 @@ set_property (GObject *object,
g_free (self->priv->initial_kernel_events);
self->priv->initial_kernel_events = g_value_dup_string (value);
break;
#if defined WITH_TESTS
case PROP_ENABLE_TEST:
self->priv->enable_test = g_value_get_boolean (value);
break;
#endif
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1464,15 +1482,17 @@ get_property (GObject *object,
case PROP_FILTER_POLICY:
g_value_set_flags (value, self->priv->filter_policy);
break;
case PROP_ENABLE_TEST:
g_value_set_boolean (value, self->priv->enable_test);
break;
case PROP_PLUGIN_DIR:
g_value_set_string (value, self->priv->plugin_dir);
break;
case PROP_INITIAL_KERNEL_EVENTS:
g_value_set_string (value, self->priv->initial_kernel_events);
break;
#if defined WITH_TESTS
case PROP_ENABLE_TEST:
g_value_set_boolean (value, self->priv->enable_test);
break;
#endif
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1498,8 +1518,10 @@ mm_base_manager_init (MMBaseManager *self)
/* By default, enable autoscan */
self->priv->auto_scan = TRUE;
#if defined WITH_TESTS
/* By default, no test interface */
self->priv->enable_test = FALSE;
#endif
/* Setup Object Manager Server */
self->priv->object_manager = g_dbus_object_manager_server_new (MM_DBUS_PATH);
@@ -1565,6 +1587,7 @@ initable_init (GInitable *initable,
g_dbus_object_manager_server_set_connection (self->priv->object_manager,
self->priv->connection);
#if defined WITH_TESTS
/* Setup the Test skeleton and export the interface */
if (self->priv->enable_test) {
self->priv->test_skeleton = mm_gdbus_test_skeleton_new ();
@@ -1578,6 +1601,7 @@ initable_init (GInitable *initable,
error))
return FALSE;
}
#endif
/* All good */
return TRUE;
@@ -1613,8 +1637,10 @@ finalize (GObject *object)
if (self->priv->object_manager)
g_object_unref (self->priv->object_manager);
#if defined WITH_TESTS
if (self->priv->test_skeleton)
g_object_unref (self->priv->test_skeleton);
#endif
if (self->priv->connection)
g_object_unref (self->priv->connection);
@@ -1678,14 +1704,6 @@ mm_base_manager_class_init (MMBaseManagerClass *manager_class)
MM_FILTER_RULE_NONE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_ENABLE_TEST,
g_param_spec_boolean (MM_BASE_MANAGER_ENABLE_TEST,
"Enable tests",
"Enable the Test interface",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_PLUGIN_DIR,
g_param_spec_string (MM_BASE_MANAGER_PLUGIN_DIR,
@@ -1701,4 +1719,14 @@ mm_base_manager_class_init (MMBaseManagerClass *manager_class)
"Path to a file with the list of initial kernel events",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
#if defined WITH_TESTS
g_object_class_install_property
(object_class, PROP_ENABLE_TEST,
g_param_spec_boolean (MM_BASE_MANAGER_ENABLE_TEST,
"Enable tests",
"Enable the Test interface",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
#endif
}

View File

@@ -18,6 +18,8 @@
#ifndef MM_BASE_MANAGER_H
#define MM_BASE_MANAGER_H
#include <config.h>
#include <glib-object.h>
#include <gio/gio.h>
@@ -34,9 +36,11 @@
#define MM_BASE_MANAGER_CONNECTION "connection" /* Construct-only */
#define MM_BASE_MANAGER_AUTO_SCAN "auto-scan" /* Construct-only */
#define MM_BASE_MANAGER_FILTER_POLICY "filter-policy" /* Construct-only */
#define MM_BASE_MANAGER_ENABLE_TEST "enable-test" /* Construct-only */
#define MM_BASE_MANAGER_PLUGIN_DIR "plugin-dir" /* Construct-only */
#define MM_BASE_MANAGER_INITIAL_KERNEL_EVENTS "initial-kernel-events" /* Construct-only */
#if defined WITH_TESTS
#define MM_BASE_MANAGER_ENABLE_TEST "enable-test" /* Construct-only */
#endif
typedef struct _MMBaseManagerPrivate MMBaseManagerPrivate;
@@ -57,7 +61,9 @@ MMBaseManager *mm_base_manager_new (GDBusConnection *bus,
gboolean auto_scan,
MMFilterRule filter_policy,
const gchar *initial_kernel_events,
#if defined WITH_TESTS
gboolean enable_test,
#endif
GError **error);
void mm_base_manager_start (MMBaseManager *manager,

View File

@@ -226,7 +226,9 @@ mm_context_get_log_personal_info (void)
/* Test context */
static gboolean test_session;
#if defined WITH_TESTS
static gboolean test_enable;
#endif
static gchar *test_plugin_dir;
#if defined WITH_UDEV
static gboolean test_no_udev;
@@ -249,11 +251,13 @@ static const GOptionEntry test_entries[] = {
"Run in session DBus",
NULL
},
#if defined WITH_TESTS
{
"test-enable", 0, 0, G_OPTION_ARG_NONE, &test_enable,
"Enable the Test interface in the daemon",
NULL
},
#endif
{
"test-plugin-dir", 0, 0, G_OPTION_ARG_FILENAME, &test_plugin_dir,
"Path to look for plugins",
@@ -320,11 +324,13 @@ mm_context_get_test_session (void)
return test_session;
}
#if defined WITH_TESTS
gboolean
mm_context_get_test_enable (void)
{
return test_enable;
}
#endif
const gchar *
mm_context_get_test_plugin_dir (void)

View File

@@ -45,7 +45,9 @@ gboolean mm_context_get_log_personal_info (void);
/* Testing support */
gboolean mm_context_get_test_session (void);
#if defined WITH_TESTS
gboolean mm_context_get_test_enable (void);
#endif
const gchar *mm_context_get_test_plugin_dir (void);
#if defined WITH_UDEV
gboolean mm_context_get_test_no_udev (void);