[Spice-devel] [PATCH spice-gtk v4 26/29] test-cd-emu: Test attach/detach emulated device

Frediano Ziglio fziglio at redhat.com
Tue Aug 27 10:18:15 UTC 2019


> 
> Frediano Ziglio writes:
> 
> > Mock some usb-backend functions to be able to simulate device
> > attachment and detachment.
> > +
> > +    // this it's the correct sequence to free session!
> > +    // g_object_unref is not enough, causing wrong reference countings
> > +    spice_session_disconnect(session);
> > +    g_object_unref(session);
> > +    while (g_main_context_iteration(NULL, FALSE)) {
> > +        continue;
> > +    }
> 
> This looks so peculiar that it might be worth putting in its
> own function, in order to facilitate reuse.
> 

I was thinking about a DoEvents function in memory of the good old VB!
(well, do_events in C).
Getting these lines right was not really easy! Calling g_object_unref
directly causes multiple crashes. The deallocations are queued in GLib.

> > +
> > +    g_assert_cmpint(gobjects_allocated, ==, 0);
> > +}
> > +
> >  static void
> >  write_test_iso(void)
> >  {
> > @@ -87,6 +234,8 @@ int main(int argc, char* argv[])
> >
> >      g_test_add_data_func("/cd-emu/simple", GUINT_TO_POINTER(1), multiple);
> >      g_test_add_data_func("/cd-emu/multiple", GUINT_TO_POINTER(128),
> >      multiple);
> > +    g_test_add_data_func("/cd-emu/attach_no_auto", GUINT_TO_POINTER(0),
> > attach);
> > +    g_test_add_data_func("/cd-emu/attach_auto", GUINT_TO_POINTER(1),
> > attach);
> >
> >      return g_test_run();
> >  }
> 

Frediano


More information about the Spice-devel mailing list