base-manager: allow forcing the testing without udev

Even if udev support is really built and available.

This is extremely useful to test the udev-less setup without fully
recompiling the whole daemon.

  E.g.: the daemon can be run like this:
    $ sudo /usr/sbin/ModemManager --debug --test-no-udev

  And then, the kernel events may be reported using mmcli like this:
    $ sudo mmcli --report-kernel-event-auto-scan
This commit is contained in:
Aleksander Morgado
2020-11-09 00:36:13 +01:00
parent 6e642418bb
commit e112896994
3 changed files with 52 additions and 24 deletions

View File

@@ -388,10 +388,11 @@ handle_kernel_event (MMBaseManager *self,
mm_obj_dbg (self, " uid: %s", uid ? uid : "n/a"); mm_obj_dbg (self, " uid: %s", uid ? uid : "n/a");
#if defined WITH_UDEV #if defined WITH_UDEV
kernel_device = mm_kernel_device_udev_new_from_properties (properties, error); if (!mm_context_get_test_no_udev ())
#else kernel_device = mm_kernel_device_udev_new_from_properties (properties, error);
kernel_device = mm_kernel_device_generic_new (properties, error); else
#endif #endif
kernel_device = mm_kernel_device_generic_new (properties, error);
if (!kernel_device) if (!kernel_device)
return FALSE; return FALSE;
@@ -541,12 +542,13 @@ mm_base_manager_start (MMBaseManager *self,
} }
#if defined WITH_UDEV #if defined WITH_UDEV
mm_obj_dbg (self, "starting %s device scan...", manual_scan ? "manual" : "automatic"); if (!mm_context_get_test_no_udev ()) {
process_scan (self, manual_scan); mm_obj_dbg (self, "starting %s device scan...", manual_scan ? "manual" : "automatic");
mm_obj_dbg (self, "finished device scan..."); process_scan (self, manual_scan);
#else mm_obj_dbg (self, "finished device scan...");
mm_obj_dbg (self, "unsupported %s device scan...", manual_scan ? "manual" : "automatic"); } else
#endif #endif
mm_obj_dbg (self, "unsupported %s device scan...", manual_scan ? "manual" : "automatic");
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -725,16 +727,17 @@ scan_devices_auth_ready (MMAuthProvider *authp,
g_dbus_method_invocation_take_error (ctx->invocation, error); g_dbus_method_invocation_take_error (ctx->invocation, error);
else { else {
#if defined WITH_UDEV #if defined WITH_UDEV
/* Otherwise relaunch device scan */ if (!mm_context_get_test_no_udev ()) {
mm_base_manager_start (MM_BASE_MANAGER (ctx->self), TRUE); /* Otherwise relaunch device scan */
mm_gdbus_org_freedesktop_modem_manager1_complete_scan_devices ( mm_base_manager_start (MM_BASE_MANAGER (ctx->self), TRUE);
MM_GDBUS_ORG_FREEDESKTOP_MODEM_MANAGER1 (ctx->self), mm_gdbus_org_freedesktop_modem_manager1_complete_scan_devices (
ctx->invocation); MM_GDBUS_ORG_FREEDESKTOP_MODEM_MANAGER1 (ctx->self),
#else ctx->invocation);
g_dbus_method_invocation_return_error_literal ( } else
ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
"Cannot request manual scan of devices: unsupported");
#endif #endif
g_dbus_method_invocation_return_error_literal (
ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
"Cannot request manual scan of devices: unsupported");
} }
scan_devices_context_free (ctx); scan_devices_context_free (ctx);
@@ -788,7 +791,7 @@ report_kernel_event_auth_ready (MMAuthProvider *authp,
goto out; goto out;
#if defined WITH_UDEV #if defined WITH_UDEV
if (ctx->self->priv->auto_scan) { if (!mm_context_get_test_no_udev () && ctx->self->priv->auto_scan) {
error = g_error_new_literal (MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, error = g_error_new_literal (MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
"Cannot report kernel event: " "Cannot report kernel event: "
"udev monitoring already in place"); "udev monitoring already in place");
@@ -1397,12 +1400,13 @@ initable_init (GInitable *initable,
return FALSE; return FALSE;
#if defined WITH_UDEV #if defined WITH_UDEV
/* Create udev client based on the subsystems requested by the plugins */ if (!mm_context_get_test_no_udev ()) {
self->priv->udev = g_udev_client_new (mm_plugin_manager_get_subsystems (self->priv->plugin_manager)); /* Create udev client based on the subsystems requested by the plugins */
self->priv->udev = g_udev_client_new (mm_plugin_manager_get_subsystems (self->priv->plugin_manager));
/* If autoscan enabled, list for udev events */ /* If autoscan enabled, list for udev events */
if (self->priv->auto_scan) if (self->priv->auto_scan)
g_signal_connect_swapped (self->priv->udev, "uevent", G_CALLBACK (handle_uevent), initable); g_signal_connect_swapped (self->priv->udev, "uevent", G_CALLBACK (handle_uevent), initable);
}
#endif #endif
/* Export the manager interface */ /* Export the manager interface */

View File

@@ -222,6 +222,9 @@ mm_context_get_log_relative_timestamps (void)
static gboolean test_session; static gboolean test_session;
static gboolean test_enable; static gboolean test_enable;
static gchar *test_plugin_dir; static gchar *test_plugin_dir;
#if defined WITH_UDEV
static gboolean test_no_udev;
#endif
static const GOptionEntry test_entries[] = { static const GOptionEntry test_entries[] = {
{ {
@@ -239,6 +242,13 @@ static const GOptionEntry test_entries[] = {
"Path to look for plugins", "Path to look for plugins",
"[PATH]" "[PATH]"
}, },
#if defined WITH_UDEV
{
"test-no-udev", 0, 0, G_OPTION_ARG_NONE, &test_no_udev,
"Run without udev support even if available",
NULL
},
#endif
{ NULL } { NULL }
}; };
@@ -274,6 +284,14 @@ mm_context_get_test_plugin_dir (void)
return test_plugin_dir ? test_plugin_dir : PLUGINDIR; return test_plugin_dir ? test_plugin_dir : PLUGINDIR;
} }
#if defined WITH_UDEV
gboolean
mm_context_get_test_no_udev (void)
{
return test_no_udev;
}
#endif
/*****************************************************************************/ /*****************************************************************************/
static void static void
@@ -345,5 +363,8 @@ mm_context_init (gint argc,
g_warning ("error: --initial-kernel-events must be used only if --no-auto-scan is also used"); g_warning ("error: --initial-kernel-events must be used only if --no-auto-scan is also used");
exit (1); exit (1);
} }
/* Force skipping autoscan if running test without udev */
if (test_no_udev)
no_auto_scan = TRUE;
#endif #endif
} }

View File

@@ -46,5 +46,8 @@ gboolean mm_context_get_log_relative_timestamps (void);
gboolean mm_context_get_test_session (void); gboolean mm_context_get_test_session (void);
gboolean mm_context_get_test_enable (void); gboolean mm_context_get_test_enable (void);
const gchar *mm_context_get_test_plugin_dir (void); const gchar *mm_context_get_test_plugin_dir (void);
#if defined WITH_UDEV
gboolean mm_context_get_test_no_udev (void);
#endif
#endif /* MM_CONTEXT_H */ #endif /* MM_CONTEXT_H */