* [PATCH 0/3] Fix some crashes when using -object @ 2020-10-08 20:27 Eduardo Habkost 2020-10-08 20:27 ` [PATCH 1/3] authz-list-file: Fix crash when filename is not set Eduardo Habkost ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Eduardo Habkost @ 2020-10-08 20:27 UTC (permalink / raw) To: qemu-devel Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, Wainer dos Santos Moschetta, Cleber Rosa, Philippe Mathieu-Daudé, Pavel Pisa Fix two crashes when using `-object` with no extra arguments, and add a acceptance test case to detect similar crashes in the future. Eduardo Habkost (3): authz-list-file: Fix crash when filename is not set can-host-socketcan: Fix crash when 'if' option is not set tests/acceptance: Test case for detecting -object crashes authz/listfile.c | 5 ++++ net/can/can_socketcan.c | 5 ++++ tests/acceptance/object_option.py | 49 +++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 tests/acceptance/object_option.py -- 2.26.2 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/3] authz-list-file: Fix crash when filename is not set 2020-10-08 20:27 [PATCH 0/3] Fix some crashes when using -object Eduardo Habkost @ 2020-10-08 20:27 ` Eduardo Habkost 2020-10-08 21:17 ` Cleber Rosa ` (3 more replies) 2020-10-08 20:27 ` [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option " Eduardo Habkost 2020-10-08 20:27 ` [PATCH 3/3] tests/acceptance: Test case for detecting -object crashes Eduardo Habkost 2 siblings, 4 replies; 12+ messages in thread From: Eduardo Habkost @ 2020-10-08 20:27 UTC (permalink / raw) To: qemu-devel Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, Wainer dos Santos Moschetta, Cleber Rosa, Philippe Mathieu-Daudé, Pavel Pisa Fix the following crash: $ qemu-system-x86_64 -object authz-list-file,id=obj0 qemu-system-x86_64: -object authz-list-file,id=obj0: GLib: g_file_get_contents: assertion 'filename != NULL' failed Segmentation fault (core dumped) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- Cc: "Daniel P. Berrangé" <berrange@redhat.com> Cc: qemu-devel@nongnu.org --- authz/listfile.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/authz/listfile.c b/authz/listfile.c index cd6163aa40..aaf930453d 100644 --- a/authz/listfile.c +++ b/authz/listfile.c @@ -122,6 +122,11 @@ qauthz_list_file_complete(UserCreatable *uc, Error **errp) QAuthZListFile *fauthz = QAUTHZ_LIST_FILE(uc); gchar *dir = NULL, *file = NULL; + if (!fauthz->filename) { + error_setg(errp, "filename not provided"); + return; + } + fauthz->list = qauthz_list_file_load(fauthz, errp); if (!fauthz->refresh) { -- 2.26.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/3] authz-list-file: Fix crash when filename is not set 2020-10-08 20:27 ` [PATCH 1/3] authz-list-file: Fix crash when filename is not set Eduardo Habkost @ 2020-10-08 21:17 ` Cleber Rosa 2020-10-09 8:37 ` Daniel P. Berrangé ` (2 subsequent siblings) 3 siblings, 0 replies; 12+ messages in thread From: Cleber Rosa @ 2020-10-08 21:17 UTC (permalink / raw) To: Eduardo Habkost Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, qemu-devel, Wainer dos Santos Moschetta, Philippe Mathieu-Daudé, Pavel Pisa [-- Attachment #1: Type: text/plain, Size: 1143 bytes --] On Thu, Oct 08, 2020 at 04:27:11PM -0400, Eduardo Habkost wrote: > Fix the following crash: > > $ qemu-system-x86_64 -object authz-list-file,id=obj0 > qemu-system-x86_64: -object authz-list-file,id=obj0: GLib: g_file_get_contents: assertion 'filename != NULL' failed > Segmentation fault (core dumped) > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > Cc: "Daniel P. Berrangé" <berrange@redhat.com> > Cc: qemu-devel@nongnu.org Out of curiosity, are those notes intended for git-publish? (If so, I didn't realize it would read them). > --- > authz/listfile.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/authz/listfile.c b/authz/listfile.c > index cd6163aa40..aaf930453d 100644 > --- a/authz/listfile.c > +++ b/authz/listfile.c > @@ -122,6 +122,11 @@ qauthz_list_file_complete(UserCreatable *uc, Error **errp) > QAuthZListFile *fauthz = QAUTHZ_LIST_FILE(uc); > gchar *dir = NULL, *file = NULL; > > + if (!fauthz->filename) { > + error_setg(errp, "filename not provided"); Nitpick: all other similar error messages start capitalized. - Cleber. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/3] authz-list-file: Fix crash when filename is not set 2020-10-08 20:27 ` [PATCH 1/3] authz-list-file: Fix crash when filename is not set Eduardo Habkost 2020-10-08 21:17 ` Cleber Rosa @ 2020-10-09 8:37 ` Daniel P. Berrangé 2020-10-09 10:31 ` Philippe Mathieu-Daudé 2020-10-09 15:06 ` Li Qiang 3 siblings, 0 replies; 12+ messages in thread From: Daniel P. Berrangé @ 2020-10-09 8:37 UTC (permalink / raw) To: Eduardo Habkost Cc: Vikram Garhwal, Jason Wang, qemu-devel, Wainer dos Santos Moschetta, Cleber Rosa, Philippe Mathieu-Daudé, Pavel Pisa On Thu, Oct 08, 2020 at 04:27:11PM -0400, Eduardo Habkost wrote: > Fix the following crash: > > $ qemu-system-x86_64 -object authz-list-file,id=obj0 > qemu-system-x86_64: -object authz-list-file,id=obj0: GLib: g_file_get_contents: assertion 'filename != NULL' failed > Segmentation fault (core dumped) > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > Cc: "Daniel P. Berrangé" <berrange@redhat.com> > Cc: qemu-devel@nongnu.org > --- > authz/listfile.c | 5 +++++ > 1 file changed, 5 insertions(+) Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> 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] 12+ messages in thread
* Re: [PATCH 1/3] authz-list-file: Fix crash when filename is not set 2020-10-08 20:27 ` [PATCH 1/3] authz-list-file: Fix crash when filename is not set Eduardo Habkost 2020-10-08 21:17 ` Cleber Rosa 2020-10-09 8:37 ` Daniel P. Berrangé @ 2020-10-09 10:31 ` Philippe Mathieu-Daudé 2020-10-09 15:06 ` Li Qiang 3 siblings, 0 replies; 12+ messages in thread From: Philippe Mathieu-Daudé @ 2020-10-09 10:31 UTC (permalink / raw) To: Eduardo Habkost, qemu-devel Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, Wainer dos Santos Moschetta, Cleber Rosa, Pavel Pisa On 10/8/20 10:27 PM, Eduardo Habkost wrote: > Fix the following crash: > > $ qemu-system-x86_64 -object authz-list-file,id=obj0 > qemu-system-x86_64: -object authz-list-file,id=obj0: GLib: g_file_get_contents: assertion 'filename != NULL' failed > Segmentation fault (core dumped) > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > Cc: "Daniel P. Berrangé" <berrange@redhat.com> > Cc: qemu-devel@nongnu.org > --- > authz/listfile.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/authz/listfile.c b/authz/listfile.c > index cd6163aa40..aaf930453d 100644 > --- a/authz/listfile.c > +++ b/authz/listfile.c > @@ -122,6 +122,11 @@ qauthz_list_file_complete(UserCreatable *uc, Error **errp) > QAuthZListFile *fauthz = QAUTHZ_LIST_FILE(uc); > gchar *dir = NULL, *file = NULL; > > + if (!fauthz->filename) { > + error_setg(errp, "filename not provided"); > + return; > + } > + > fauthz->list = qauthz_list_file_load(fauthz, errp); > > if (!fauthz->refresh) { > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/3] authz-list-file: Fix crash when filename is not set 2020-10-08 20:27 ` [PATCH 1/3] authz-list-file: Fix crash when filename is not set Eduardo Habkost ` (2 preceding siblings ...) 2020-10-09 10:31 ` Philippe Mathieu-Daudé @ 2020-10-09 15:06 ` Li Qiang 3 siblings, 0 replies; 12+ messages in thread From: Li Qiang @ 2020-10-09 15:06 UTC (permalink / raw) To: Eduardo Habkost Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, Qemu Developers, Wainer dos Santos Moschetta, Cleber Rosa, Philippe Mathieu-Daudé, Pavel Pisa Eduardo Habkost <ehabkost@redhat.com> 于2020年10月9日周五 上午4:28写道: > > Fix the following crash: > > $ qemu-system-x86_64 -object authz-list-file,id=obj0 > qemu-system-x86_64: -object authz-list-file,id=obj0: GLib: g_file_get_contents: assertion 'filename != NULL' failed > Segmentation fault (core dumped) > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Li Qiang <liq3ea@gmail.com> > --- > Cc: "Daniel P. Berrangé" <berrange@redhat.com> > Cc: qemu-devel@nongnu.org > --- > authz/listfile.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/authz/listfile.c b/authz/listfile.c > index cd6163aa40..aaf930453d 100644 > --- a/authz/listfile.c > +++ b/authz/listfile.c > @@ -122,6 +122,11 @@ qauthz_list_file_complete(UserCreatable *uc, Error **errp) > QAuthZListFile *fauthz = QAUTHZ_LIST_FILE(uc); > gchar *dir = NULL, *file = NULL; > > + if (!fauthz->filename) { > + error_setg(errp, "filename not provided"); > + return; > + } > + > fauthz->list = qauthz_list_file_load(fauthz, errp); > > if (!fauthz->refresh) { > -- > 2.26.2 > > ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option is not set 2020-10-08 20:27 [PATCH 0/3] Fix some crashes when using -object Eduardo Habkost 2020-10-08 20:27 ` [PATCH 1/3] authz-list-file: Fix crash when filename is not set Eduardo Habkost @ 2020-10-08 20:27 ` Eduardo Habkost 2020-10-08 22:18 ` Pavel Pisa ` (2 more replies) 2020-10-08 20:27 ` [PATCH 3/3] tests/acceptance: Test case for detecting -object crashes Eduardo Habkost 2 siblings, 3 replies; 12+ messages in thread From: Eduardo Habkost @ 2020-10-08 20:27 UTC (permalink / raw) To: qemu-devel Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, Wainer dos Santos Moschetta, Cleber Rosa, Philippe Mathieu-Daudé, Pavel Pisa Fix the following crash: $ qemu-system-x86_64 -object can-host-socketcan,id=obj0 Segmentation fault (core dumped) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- Cc: Pavel Pisa <pisa@cmp.felk.cvut.cz> Cc: Vikram Garhwal <fnu.vikram@xilinx.com> Cc: Jason Wang <jasowang@redhat.com> Cc: qemu-devel@nongnu.org --- net/can/can_socketcan.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c index 92b1f79385..4b68f60c6b 100644 --- a/net/can/can_socketcan.c +++ b/net/can/can_socketcan.c @@ -194,6 +194,11 @@ static void can_host_socketcan_connect(CanHostState *ch, Error **errp) struct sockaddr_can addr; struct ifreq ifr; + if (!c->ifname) { + error_setg(errp, "'if' property not set"); + return; + } + /* open socket */ s = qemu_socket(PF_CAN, SOCK_RAW, CAN_RAW); if (s < 0) { -- 2.26.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option is not set 2020-10-08 20:27 ` [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option " Eduardo Habkost @ 2020-10-08 22:18 ` Pavel Pisa 2020-10-09 15:17 ` Li Qiang 2020-10-12 16:23 ` Vikram Garhwal 2 siblings, 0 replies; 12+ messages in thread From: Pavel Pisa @ 2020-10-08 22:18 UTC (permalink / raw) To: Eduardo Habkost Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, qemu-devel, Wainer dos Santos Moschetta, Cleber Rosa, Philippe Mathieu-Daudé Thanks for catching missing test On Thursday 08 of October 2020 22:27:12 Eduardo Habkost wrote: > Fix the following crash: > > $ qemu-system-x86_64 -object can-host-socketcan,id=obj0 > Segmentation fault (core dumped) > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > Cc: Pavel Pisa <pisa@cmp.felk.cvut.cz> > Cc: Vikram Garhwal <fnu.vikram@xilinx.com> > Cc: Jason Wang <jasowang@redhat.com> > Cc: qemu-devel@nongnu.org > --- > net/can/can_socketcan.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c > index 92b1f79385..4b68f60c6b 100644 > --- a/net/can/can_socketcan.c > +++ b/net/can/can_socketcan.c > @@ -194,6 +194,11 @@ static void can_host_socketcan_connect(CanHostState > *ch, Error **errp) struct sockaddr_can addr; > struct ifreq ifr; > > + if (!c->ifname) { > + error_setg(errp, "'if' property not set"); > + return; > + } > + > /* open socket */ > s = qemu_socket(PF_CAN, SOCK_RAW, CAN_RAW); > if (s < 0) { Acked-by: Pavel Pisa <pisa@cmp.felk.cvut.cz> -- Pavel Pisa e-mail: pisa@cmp.felk.cvut.cz Department of Control Engineering FEE CVUT Karlovo namesti 13, 121 35, Prague 2 university: http://dce.fel.cvut.cz/ personal: http://cmp.felk.cvut.cz/~pisa projects: https://www.openhub.net/accounts/ppisa CAN related:http://canbus.pages.fel.cvut.cz/ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option is not set 2020-10-08 20:27 ` [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option " Eduardo Habkost 2020-10-08 22:18 ` Pavel Pisa @ 2020-10-09 15:17 ` Li Qiang 2020-10-12 16:23 ` Vikram Garhwal 2 siblings, 0 replies; 12+ messages in thread From: Li Qiang @ 2020-10-09 15:17 UTC (permalink / raw) To: Eduardo Habkost Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, Qemu Developers, Wainer dos Santos Moschetta, Cleber Rosa, Philippe Mathieu-Daudé, Pavel Pisa Eduardo Habkost <ehabkost@redhat.com> 于2020年10月9日周五 上午4:31写道: > > Fix the following crash: > > $ qemu-system-x86_64 -object can-host-socketcan,id=obj0 > Segmentation fault (core dumped) > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Li Qiang <liq3ea@gmail.com> > --- > Cc: Pavel Pisa <pisa@cmp.felk.cvut.cz> > Cc: Vikram Garhwal <fnu.vikram@xilinx.com> > Cc: Jason Wang <jasowang@redhat.com> > Cc: qemu-devel@nongnu.org > --- > net/can/can_socketcan.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c > index 92b1f79385..4b68f60c6b 100644 > --- a/net/can/can_socketcan.c > +++ b/net/can/can_socketcan.c > @@ -194,6 +194,11 @@ static void can_host_socketcan_connect(CanHostState *ch, Error **errp) > struct sockaddr_can addr; > struct ifreq ifr; > > + if (!c->ifname) { > + error_setg(errp, "'if' property not set"); > + return; > + } > + > /* open socket */ > s = qemu_socket(PF_CAN, SOCK_RAW, CAN_RAW); > if (s < 0) { > -- > 2.26.2 > > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option is not set 2020-10-08 20:27 ` [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option " Eduardo Habkost 2020-10-08 22:18 ` Pavel Pisa 2020-10-09 15:17 ` Li Qiang @ 2020-10-12 16:23 ` Vikram Garhwal 2 siblings, 0 replies; 12+ messages in thread From: Vikram Garhwal @ 2020-10-12 16:23 UTC (permalink / raw) To: Eduardo Habkost Cc: Daniel P. Berrangé, Jason Wang, qemu-devel, Wainer dos Santos Moschetta, Cleber Rosa, Philippe Mathieu-Daudé, Pavel Pisa On Thu, Oct 08, 2020 at 04:27:12PM -0400, Eduardo Habkost wrote: > Fix the following crash: > > $ qemu-system-x86_64 -object can-host-socketcan,id=obj0 > Segmentation fault (core dumped) > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Vikram Garhwal <fnu.vikram@xilinx.com> > --- > Cc: Pavel Pisa <pisa@cmp.felk.cvut.cz> > Cc: Vikram Garhwal <fnu.vikram@xilinx.com> > Cc: Jason Wang <jasowang@redhat.com> > Cc: qemu-devel@nongnu.org > --- > net/can/can_socketcan.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c > index 92b1f79385..4b68f60c6b 100644 > --- a/net/can/can_socketcan.c > +++ b/net/can/can_socketcan.c > @@ -194,6 +194,11 @@ static void can_host_socketcan_connect(CanHostState *ch, Error **errp) > struct sockaddr_can addr; > struct ifreq ifr; > > + if (!c->ifname) { > + error_setg(errp, "'if' property not set"); > + return; > + } > + > /* open socket */ > s = qemu_socket(PF_CAN, SOCK_RAW, CAN_RAW); > if (s < 0) { > -- > 2.26.2 > ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/3] tests/acceptance: Test case for detecting -object crashes 2020-10-08 20:27 [PATCH 0/3] Fix some crashes when using -object Eduardo Habkost 2020-10-08 20:27 ` [PATCH 1/3] authz-list-file: Fix crash when filename is not set Eduardo Habkost 2020-10-08 20:27 ` [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option " Eduardo Habkost @ 2020-10-08 20:27 ` Eduardo Habkost 2020-10-09 0:48 ` Cleber Rosa 2 siblings, 1 reply; 12+ messages in thread From: Eduardo Habkost @ 2020-10-08 20:27 UTC (permalink / raw) To: qemu-devel Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, Wainer dos Santos Moschetta, Cleber Rosa, Philippe Mathieu-Daudé, Pavel Pisa Add a simple test case that will run QEMU directly (without QMP) just to check for crashes when using `-object`. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- Cc: Cleber Rosa <crosa@redhat.com> Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com> Cc: Wainer dos Santos Moschetta <wainersm@redhat.com> Cc: qemu-devel@nongnu.org --- tests/acceptance/object_option.py | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/acceptance/object_option.py diff --git a/tests/acceptance/object_option.py b/tests/acceptance/object_option.py new file mode 100644 index 0000000000..2b8bd00db1 --- /dev/null +++ b/tests/acceptance/object_option.py @@ -0,0 +1,49 @@ +# Copyright (c) 2020 Red Hat, Inc. +# +# Author: +# Eduardo Habkost <ehabkost@redhat.com> +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import avocado_qemu +import subprocess +import shlex + +class ObjectOption(avocado_qemu.Test): + """Check if ``-object`` option behaves as expected""" + + def run(self, cmd, *args, **kwargs): + cmdstr = ' '.join(shlex.quote(c) for c in cmd) + self.log.info("Command: %s", cmdstr) + return subprocess.run(cmd, encoding='utf-8', *args, **kwargs) + + def devices(self): + out = self.run([self.qemu_bin, '-object', 'help'], + check=True, stdout=subprocess.PIPE).stdout + lines = out.split('\n') + return [l.strip() for l in lines[1:] if l.strip()] + + def test_help(self): + """Check if ``-object ...,help`` behaves as expected""" + for device in self.devices(): + self.run([self.qemu_bin, '-object', '%s,help' % (device)], + check=True, + stdout=subprocess.DEVNULL) + + def test_crash(self): + """Check for crashes when using ``-object ...``""" + for device in self.devices(): + r = self.run([self.qemu_bin, '-object', + '%s,id=obj0' % (device), + '-monitor', 'stdio'], + input='quit\n', + stdout=subprocess.DEVNULL, + stderr=subprocess.PIPE) + if r.returncode not in (0, 1): + self.log.warn("QEMU stderr: %s", r.stderr) + self.log.warn("QEMU exit code: %d", r.returncode) + if r.returncode < 0: + self.fail("QEMU crashed") + else: + self.fail("Unexpected exit code") -- 2.26.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] tests/acceptance: Test case for detecting -object crashes 2020-10-08 20:27 ` [PATCH 3/3] tests/acceptance: Test case for detecting -object crashes Eduardo Habkost @ 2020-10-09 0:48 ` Cleber Rosa 0 siblings, 0 replies; 12+ messages in thread From: Cleber Rosa @ 2020-10-09 0:48 UTC (permalink / raw) To: Eduardo Habkost Cc: Vikram Garhwal, Daniel P. Berrangé, Jason Wang, qemu-devel, Wainer dos Santos Moschetta, Philippe Mathieu-Daudé, Pavel Pisa [-- Attachment #1: Type: text/plain, Size: 5209 bytes --] On Thu, Oct 08, 2020 at 04:27:13PM -0400, Eduardo Habkost wrote: > Add a simple test case that will run QEMU directly (without QMP) > just to check for crashes when using `-object`. > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > Cc: Cleber Rosa <crosa@redhat.com> > Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com> > Cc: Wainer dos Santos Moschetta <wainersm@redhat.com> > Cc: qemu-devel@nongnu.org > --- > tests/acceptance/object_option.py | 49 +++++++++++++++++++++++++++++++ > 1 file changed, 49 insertions(+) > create mode 100644 tests/acceptance/object_option.py > > diff --git a/tests/acceptance/object_option.py b/tests/acceptance/object_option.py > new file mode 100644 > index 0000000000..2b8bd00db1 > --- /dev/null > +++ b/tests/acceptance/object_option.py > @@ -0,0 +1,49 @@ > +# Copyright (c) 2020 Red Hat, Inc. > +# > +# Author: > +# Eduardo Habkost <ehabkost@redhat.com> > +# > +# This work is licensed under the terms of the GNU GPL, version 2 or > +# later. See the COPYING file in the top-level directory. > + > +import avocado_qemu > +import subprocess > +import shlex > + > +class ObjectOption(avocado_qemu.Test): > + """Check if ``-object`` option behaves as expected""" > + > + def run(self, cmd, *args, **kwargs): > + cmdstr = ' '.join(shlex.quote(c) for c in cmd) > + self.log.info("Command: %s", cmdstr) Maybe "Running command: %s" is clearer? > + return subprocess.run(cmd, encoding='utf-8', *args, **kwargs) I'd just use `universal_newlines=True` (equivalent to `text`, but that's Python 3.7+ only), so the current encoding will be respected. I understand "utf-8" is a safe choice, but IMO, if someone sets a different default, it should be respected, unless there's a clear reason not to do so. > + > + def devices(self): Maybe call it `get_devices()` or make it a property? > + out = self.run([self.qemu_bin, '-object', 'help'], > + check=True, stdout=subprocess.PIPE).stdout > + lines = out.split('\n') > + return [l.strip() for l in lines[1:] if l.strip()] > + In case the `CalledProcessError` is raised on subprocess.run(), the following test status will be ERROR, which is a condition you were not testing for, something unexpected. Given that you're using `check=True`, I'd decorate this test with: @avocado.fail_on(subprocess.CalledProcessError) > + def test_help(self): > + """Check if ``-object ...,help`` behaves as expected""" > + for device in self.devices(): > + self.run([self.qemu_bin, '-object', '%s,help' % (device)], > + check=True, > + stdout=subprocess.DEVNULL) > + > + def test_crash(self): > + """Check for crashes when using ``-object ...``""" Maybe change the wording here, given that this is really checking that QEMU doesn't crash, right? So something like "Checks that QEMU doesn't crash ..." seems clearer to me. > + for device in self.devices(): > + r = self.run([self.qemu_bin, '-object', > + '%s,id=obj0' % (device), > + '-monitor', 'stdio'], > + input='quit\n', > + stdout=subprocess.DEVNULL, > + stderr=subprocess.PIPE) I know adding command line options to QEMU (specially at this stage) is, at the very least, frowned upon, but I can't help to think that an option similar to Python's "-c" would be very helpful in testing scenarios. > + if r.returncode not in (0, 1): > + self.log.warn("QEMU stderr: %s", r.stderr) > + self.log.warn("QEMU exit code: %d", r.returncode) > + if r.returncode < 0: > + self.fail("QEMU crashed") > + else: > + self.fail("Unexpected exit code") > -- > 2.26.2 > This looks fine, but this test is clearly provocative (at least to me), given at it's a bit more barebones than the approached used in "empty_cpu_model.py". It seems to show the need for: 1) a custom test class (similar to avocado_qemu.Test) that can be more suitable to more barebones tests like this 2) a custom QEMU "varianter" implementation we've talked about in the past, with which the test code could be simplified. For instance, setting hypothetical configuration "qemu-varianter=objects" could produce: [ {"object": "authz-list"}, {"object": "authz-list-file"}, ... {"object": "tls-creds-x509"} ] I had not attempted this before, because Avocado was limited to applying variants globally to a job. Starting with version 81.0 (released a month or so ago), this is no longer a limitation. A simple PoC is here: https://gitlab.com/cleber.gnu/qemu/-/commit/30f26b662326502c2d82aabca225009ccdebe6aa Can be run with: ./tests/venv/bin/python job_object_option.py And the tests themselves would look like this: https://paste.centos.org/view/4c5f413d Let me know if any of this makes sense. Thanks, - Cleber. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2020-10-12 16:39 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-10-08 20:27 [PATCH 0/3] Fix some crashes when using -object Eduardo Habkost 2020-10-08 20:27 ` [PATCH 1/3] authz-list-file: Fix crash when filename is not set Eduardo Habkost 2020-10-08 21:17 ` Cleber Rosa 2020-10-09 8:37 ` Daniel P. Berrangé 2020-10-09 10:31 ` Philippe Mathieu-Daudé 2020-10-09 15:06 ` Li Qiang 2020-10-08 20:27 ` [PATCH 2/3] can-host-socketcan: Fix crash when 'if' option " Eduardo Habkost 2020-10-08 22:18 ` Pavel Pisa 2020-10-09 15:17 ` Li Qiang 2020-10-12 16:23 ` Vikram Garhwal 2020-10-08 20:27 ` [PATCH 3/3] tests/acceptance: Test case for detecting -object crashes Eduardo Habkost 2020-10-09 0:48 ` Cleber Rosa
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).