* [PATCH] qtest: start a VNC test @ 2022-10-06 13:05 marcandre.lureau 2022-10-06 13:42 ` Daniel P. Berrangé 0 siblings, 1 reply; 3+ messages in thread From: marcandre.lureau @ 2022-10-06 13:05 UTC (permalink / raw) To: qemu-devel Cc: berrange, Marc-André Lureau, Thomas Huth, Laurent Vivier, Paolo Bonzini From: Marc-André Lureau <marcandre.lureau@redhat.com> This is some of the simplest test we could perform, it simply connects to the VNC server via passed-in socket FDs and checks the connection can be established. Another series will make this test work on Windows as well. As always, more tests can be added later! :) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- tests/qtest/vnc-display-test.c | 103 +++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 8 ++- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/vnc-display-test.c diff --git a/tests/qtest/vnc-display-test.c b/tests/qtest/vnc-display-test.c new file mode 100644 index 0000000000..e2a9d682bb --- /dev/null +++ b/tests/qtest/vnc-display-test.c @@ -0,0 +1,103 @@ +/* + * VNC display tests + * + * Copyright (c) 2022 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/sockets.h" +#include "libqtest.h" +#include <gio/gio.h> +#include <gvnc.h> + +typedef struct Test { + QTestState *qts; + VncConnection *conn; + GMainLoop *loop; +} Test; + +static void on_vnc_error(VncConnection* self, + const char* msg) +{ + g_error("vnc-error: %s", msg); +} + +static void on_vnc_auth_failure(VncConnection *self, + const char *msg) +{ + g_error("vnc-auth-failure: %s", msg); +} + +static bool +test_setup(Test *test) +{ +#ifdef WIN32 + g_test_skip("Not supported on Windows yet"); + return false; +#else + int pair[2]; + + test->qts = qtest_init("-vnc none -name vnc-test"); + + g_assert_cmpint(qemu_socketpair(AF_UNIX, SOCK_STREAM, 0, pair), ==, 0); + + qtest_qmp_add_client(test->qts, "vnc", pair[1]); + + test->conn = vnc_connection_new(); + g_signal_connect(test->conn, "vnc-error", + G_CALLBACK(on_vnc_error), NULL); + g_signal_connect(test->conn, "vnc-auth-failure", + G_CALLBACK(on_vnc_auth_failure), NULL); + vnc_connection_set_auth_type(test->conn, VNC_CONNECTION_AUTH_NONE); + vnc_connection_open_fd(test->conn, pair[0]); + + test->loop = g_main_loop_new(NULL, FALSE); + return true; +#endif +} + +static void +test_vnc_basic_on_vnc_initialized(VncConnection *self, + Test *test) +{ + const char *name = vnc_connection_get_name(test->conn); + + g_assert_cmpstr(name, ==, "QEMU (vnc-test)"); + g_main_loop_quit(test->loop); +} + +static void +test_vnc_basic(void) +{ + Test test; + + if (!test_setup(&test)) { + return; + } + + g_signal_connect(test.conn, "vnc-initialized", + G_CALLBACK(test_vnc_basic_on_vnc_initialized), &test); + + g_main_loop_run(test.loop); + + qtest_quit(test.qts); + g_object_unref(test.conn); + g_main_loop_unref(test.loop); +} + +int +main(int argc, char **argv) +{ + if (getenv("GTK_VNC_DEBUG")) { + vnc_util_set_debug(true); + } + + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/vnc-display/basic", test_vnc_basic); + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 455f1bbb7e..c07a5b1a5f 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -306,8 +306,14 @@ qtests = { 'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'), } +gvnc = dependency('gvnc-1.0', required: false) +if gvnc.found() + qtests += {'vnc-display-test': [gvnc]} + qtests_generic += [ 'vnc-display-test' ] +endif + if dbus_display -qtests += {'dbus-display-test': [dbus_display1, gio]} + qtests += {'dbus-display-test': [dbus_display1, gio]} endif qtest_executables = {} -- 2.37.3 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] qtest: start a VNC test 2022-10-06 13:05 [PATCH] qtest: start a VNC test marcandre.lureau @ 2022-10-06 13:42 ` Daniel P. Berrangé 2022-10-06 13:50 ` Marc-André Lureau 0 siblings, 1 reply; 3+ messages in thread From: Daniel P. Berrangé @ 2022-10-06 13:42 UTC (permalink / raw) To: marcandre.lureau; +Cc: qemu-devel, Thomas Huth, Laurent Vivier, Paolo Bonzini On Thu, Oct 06, 2022 at 05:05:13PM +0400, marcandre.lureau@redhat.com wrote: > From: Marc-André Lureau <marcandre.lureau@redhat.com> > > This is some of the simplest test we could perform, it simply connects > to the VNC server via passed-in socket FDs and checks the connection can > be established. > > Another series will make this test work on Windows as well. > > As always, more tests can be added later! :) This test program uses GTK-VNC's VncConnection class, which makes sense for testing the expected behaviour, not least because GTK-VNC is what alot of QEMU clients will use. IOW, its good to ensure we don't regress with GTK-VNC. Looking at testing from a robustness POV though, it is desirable to be able to try various bad things in an attempt to trip up QEMU's VNC server and potentially exploit it. This will be pretty much impossible todo using VncConnection, and would require being able to speak the raw VNC protocol on the sockets, and take unsual actions like sending requests but not processing the results. Any thoughts on the "bad" testing ? > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> > --- > tests/qtest/vnc-display-test.c | 103 +++++++++++++++++++++++++++++++++ > tests/qtest/meson.build | 8 ++- > 2 files changed, 110 insertions(+), 1 deletion(-) > create mode 100644 tests/qtest/vnc-display-test.c > > diff --git a/tests/qtest/vnc-display-test.c b/tests/qtest/vnc-display-test.c > new file mode 100644 > index 0000000000..e2a9d682bb > --- /dev/null > +++ b/tests/qtest/vnc-display-test.c > @@ -0,0 +1,103 @@ > +/* > + * VNC display tests > + * > + * Copyright (c) 2022 Red Hat, Inc. > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + */ > + > +#include "qemu/osdep.h" > +#include "qemu/sockets.h" > +#include "libqtest.h" > +#include <gio/gio.h> > +#include <gvnc.h> > + > +typedef struct Test { > + QTestState *qts; > + VncConnection *conn; > + GMainLoop *loop; > +} Test; > + > +static void on_vnc_error(VncConnection* self, > + const char* msg) > +{ > + g_error("vnc-error: %s", msg); > +} > + > +static void on_vnc_auth_failure(VncConnection *self, > + const char *msg) > +{ > + g_error("vnc-auth-failure: %s", msg); > +} > + > +static bool > +test_setup(Test *test) > +{ > +#ifdef WIN32 > + g_test_skip("Not supported on Windows yet"); > + return false; > +#else > + int pair[2]; > + > + test->qts = qtest_init("-vnc none -name vnc-test"); > + > + g_assert_cmpint(qemu_socketpair(AF_UNIX, SOCK_STREAM, 0, pair), ==, 0); > + > + qtest_qmp_add_client(test->qts, "vnc", pair[1]); > + > + test->conn = vnc_connection_new(); > + g_signal_connect(test->conn, "vnc-error", > + G_CALLBACK(on_vnc_error), NULL); > + g_signal_connect(test->conn, "vnc-auth-failure", > + G_CALLBACK(on_vnc_auth_failure), NULL); > + vnc_connection_set_auth_type(test->conn, VNC_CONNECTION_AUTH_NONE); > + vnc_connection_open_fd(test->conn, pair[0]); > + > + test->loop = g_main_loop_new(NULL, FALSE); > + return true; > +#endif > +} > + > +static void > +test_vnc_basic_on_vnc_initialized(VncConnection *self, > + Test *test) > +{ > + const char *name = vnc_connection_get_name(test->conn); > + > + g_assert_cmpstr(name, ==, "QEMU (vnc-test)"); > + g_main_loop_quit(test->loop); > +} > + > +static void > +test_vnc_basic(void) > +{ > + Test test; > + > + if (!test_setup(&test)) { > + return; > + } > + > + g_signal_connect(test.conn, "vnc-initialized", > + G_CALLBACK(test_vnc_basic_on_vnc_initialized), &test); > + > + g_main_loop_run(test.loop); > + > + qtest_quit(test.qts); > + g_object_unref(test.conn); > + g_main_loop_unref(test.loop); > +} > + > +int > +main(int argc, char **argv) > +{ > + if (getenv("GTK_VNC_DEBUG")) { > + vnc_util_set_debug(true); > + } > + > + g_test_init(&argc, &argv, NULL); > + > + qtest_add_func("/vnc-display/basic", test_vnc_basic); > + > + return g_test_run(); > +} > diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build > index 455f1bbb7e..c07a5b1a5f 100644 > --- a/tests/qtest/meson.build > +++ b/tests/qtest/meson.build > @@ -306,8 +306,14 @@ qtests = { > 'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'), > } > > +gvnc = dependency('gvnc-1.0', required: false) > +if gvnc.found() > + qtests += {'vnc-display-test': [gvnc]} > + qtests_generic += [ 'vnc-display-test' ] > +endif > + > if dbus_display > -qtests += {'dbus-display-test': [dbus_display1, gio]} > + qtests += {'dbus-display-test': [dbus_display1, gio]} > endif > > qtest_executables = {} > -- > 2.37.3 > With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :| ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] qtest: start a VNC test 2022-10-06 13:42 ` Daniel P. Berrangé @ 2022-10-06 13:50 ` Marc-André Lureau 0 siblings, 0 replies; 3+ messages in thread From: Marc-André Lureau @ 2022-10-06 13:50 UTC (permalink / raw) To: Daniel P. Berrangé Cc: qemu-devel, Thomas Huth, Laurent Vivier, Paolo Bonzini [-- Attachment #1: Type: text/plain, Size: 5848 bytes --] Hi On Thu, Oct 6, 2022 at 5:43 PM Daniel P. Berrangé <berrange@redhat.com> wrote: > On Thu, Oct 06, 2022 at 05:05:13PM +0400, marcandre.lureau@redhat.com > wrote: > > From: Marc-André Lureau <marcandre.lureau@redhat.com> > > > > This is some of the simplest test we could perform, it simply connects > > to the VNC server via passed-in socket FDs and checks the connection can > > be established. > > > > Another series will make this test work on Windows as well. > > > > As always, more tests can be added later! :) > > This test program uses GTK-VNC's VncConnection class, which makes sense > for testing the expected behaviour, not least because GTK-VNC is what > alot of QEMU clients will use. IOW, its good to ensure we don't regress > with GTK-VNC. > > Looking at testing from a robustness POV though, it is desirable to be > able to try various bad things in an attempt to trip up QEMU's VNC server > and potentially exploit it. This will be pretty much impossible todo using > VncConnection, and would require being able to speak the raw VNC protocol > on the sockets, and take unsual actions like sending requests but not > processing the results. > > Any thoughts on the "bad" testing ? > Well, that requires some exploration I guess, using fuzzing. That's another story imho :) thanks > > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> > > --- > > tests/qtest/vnc-display-test.c | 103 +++++++++++++++++++++++++++++++++ > > tests/qtest/meson.build | 8 ++- > > 2 files changed, 110 insertions(+), 1 deletion(-) > > create mode 100644 tests/qtest/vnc-display-test.c > > > > diff --git a/tests/qtest/vnc-display-test.c > b/tests/qtest/vnc-display-test.c > > new file mode 100644 > > index 0000000000..e2a9d682bb > > --- /dev/null > > +++ b/tests/qtest/vnc-display-test.c > > @@ -0,0 +1,103 @@ > > +/* > > + * VNC display tests > > + * > > + * Copyright (c) 2022 Red Hat, Inc. > > + * > > + * This work is licensed under the terms of the GNU GPL, version 2 or > later. > > + * See the COPYING file in the top-level directory. > > + */ > > + > > +#include "qemu/osdep.h" > > +#include "qemu/sockets.h" > > +#include "libqtest.h" > > +#include <gio/gio.h> > > +#include <gvnc.h> > > + > > +typedef struct Test { > > + QTestState *qts; > > + VncConnection *conn; > > + GMainLoop *loop; > > +} Test; > > + > > +static void on_vnc_error(VncConnection* self, > > + const char* msg) > > +{ > > + g_error("vnc-error: %s", msg); > > +} > > + > > +static void on_vnc_auth_failure(VncConnection *self, > > + const char *msg) > > +{ > > + g_error("vnc-auth-failure: %s", msg); > > +} > > + > > +static bool > > +test_setup(Test *test) > > +{ > > +#ifdef WIN32 > > + g_test_skip("Not supported on Windows yet"); > > + return false; > > +#else > > + int pair[2]; > > + > > + test->qts = qtest_init("-vnc none -name vnc-test"); > > + > > + g_assert_cmpint(qemu_socketpair(AF_UNIX, SOCK_STREAM, 0, pair), ==, > 0); > > + > > + qtest_qmp_add_client(test->qts, "vnc", pair[1]); > > + > > + test->conn = vnc_connection_new(); > > + g_signal_connect(test->conn, "vnc-error", > > + G_CALLBACK(on_vnc_error), NULL); > > + g_signal_connect(test->conn, "vnc-auth-failure", > > + G_CALLBACK(on_vnc_auth_failure), NULL); > > + vnc_connection_set_auth_type(test->conn, VNC_CONNECTION_AUTH_NONE); > > + vnc_connection_open_fd(test->conn, pair[0]); > > + > > + test->loop = g_main_loop_new(NULL, FALSE); > > + return true; > > +#endif > > +} > > + > > +static void > > +test_vnc_basic_on_vnc_initialized(VncConnection *self, > > + Test *test) > > +{ > > + const char *name = vnc_connection_get_name(test->conn); > > + > > + g_assert_cmpstr(name, ==, "QEMU (vnc-test)"); > > + g_main_loop_quit(test->loop); > > +} > > + > > +static void > > +test_vnc_basic(void) > > +{ > > + Test test; > > + > > + if (!test_setup(&test)) { > > + return; > > + } > > + > > + g_signal_connect(test.conn, "vnc-initialized", > > + G_CALLBACK(test_vnc_basic_on_vnc_initialized), > &test); > > + > > + g_main_loop_run(test.loop); > > + > > + qtest_quit(test.qts); > > + g_object_unref(test.conn); > > + g_main_loop_unref(test.loop); > > +} > > + > > +int > > +main(int argc, char **argv) > > +{ > > + if (getenv("GTK_VNC_DEBUG")) { > > + vnc_util_set_debug(true); > > + } > > + > > + g_test_init(&argc, &argv, NULL); > > + > > + qtest_add_func("/vnc-display/basic", test_vnc_basic); > > + > > + return g_test_run(); > > +} > > diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build > > index 455f1bbb7e..c07a5b1a5f 100644 > > --- a/tests/qtest/meson.build > > +++ b/tests/qtest/meson.build > > @@ -306,8 +306,14 @@ qtests = { > > 'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'), > > } > > > > +gvnc = dependency('gvnc-1.0', required: false) > > +if gvnc.found() > > + qtests += {'vnc-display-test': [gvnc]} > > + qtests_generic += [ 'vnc-display-test' ] > > +endif > > + > > if dbus_display > > -qtests += {'dbus-display-test': [dbus_display1, gio]} > > + qtests += {'dbus-display-test': [dbus_display1, gio]} > > endif > > > > qtest_executables = {} > > -- > > 2.37.3 > > > > With regards, > Daniel > -- > |: https://berrange.com -o- > https://www.flickr.com/photos/dberrange :| > |: https://libvirt.org -o- > https://fstop138.berrange.com :| > |: https://entangle-photo.org -o- > https://www.instagram.com/dberrange :| > > > -- Marc-André Lureau [-- Attachment #2: Type: text/html, Size: 8338 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-06 13:58 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-10-06 13:05 [PATCH] qtest: start a VNC test marcandre.lureau 2022-10-06 13:42 ` Daniel P. Berrangé 2022-10-06 13:50 ` Marc-André Lureau
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).