diff options
author | Richard Hughes <richard@hughsie.com> | 2022-09-05 20:50:06 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2022-09-08 09:06:56 +0100 |
commit | 1c778b7013582bab13a66467e12c7573f615cc8c (patch) | |
tree | 953159ce969761acb608166d0a5c02bde618882d /tools | |
parent | 4eca7b72db7f5c921927ca5b7a16a8d05b093861 (diff) | |
download | gusb-1c778b7013582bab13a66467e12c7573f615cc8c.tar.gz |
Save device events when required
This allows us to simulate an entire context of devices, simulating responses
as if the hardware is connected. This allows building rich device-specific
unit tests in programs like fwupd, without having to have the hardware attached.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gusb-main.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/gusb-main.c b/tools/gusb-main.c index ab8e4ad..1f0826d 100644 --- a/tools/gusb-main.c +++ b/tools/gusb-main.c @@ -461,7 +461,9 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUsbCmdPrivate, gusb_cmd_private_free) int main(int argc, char *argv[]) { + GUsbContextFlags context_flags = G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES; gboolean verbose = FALSE; + gboolean save_events = FALSE; g_autofree gchar *cmd_descriptions = NULL; g_autofree gchar *options_help = NULL; g_autoptr(GError) error = NULL; @@ -474,6 +476,13 @@ main(int argc, char *argv[]) &verbose, "Show extra debugging information", NULL}, + {"events", + '\0', + 0, + G_OPTION_ARG_NONE, + &save_events, + "Save USB events", + NULL}, {NULL}}; setlocale(LC_ALL, ""); @@ -503,7 +512,9 @@ main(int argc, char *argv[]) /* GUsbContext */ priv->usb_ctx = g_usb_context_new(NULL); - g_usb_context_set_flags(priv->usb_ctx, G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES); + if (save_events) + context_flags |= G_USB_CONTEXT_FLAGS_SAVE_EVENTS; + g_usb_context_set_flags(priv->usb_ctx, context_flags); /* add commands */ priv->cmd_array = g_ptr_array_new_with_free_func((GDestroyNotify)gusb_cmd_item_free); |