[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2] tests/acceptance: Test case for detecting -object crashes
From: |
Eduardo Habkost |
Subject: |
Re: [PATCH v2] tests/acceptance: Test case for detecting -object crashes |
Date: |
Mon, 26 Oct 2020 08:07:49 -0400 |
On Mon, Oct 26, 2020 at 09:17:57AM +0100, Philippe Mathieu-Daudé wrote:
> Hi Eduardo, Thomas,
>
> On 10/9/20 10:29 PM, 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>
> > ---
> > Changes v1 -> v2:
> > * "Running command:" log message instead of "Command:" (Cleber)
> > * Use universal_newlines=True instead of encoding='utf-8' (Cleber)
> > * Rename devices() to get_devices() (Cleber)
> > * Use @avocado.fail_on(subprocess.CalledProcessError) (Cleber)
> > * Reword test_crash() docstring (Cleber)
> > * Reorder imports
> > ---
> > tests/acceptance/object_option.py | 53 +++++++++++++++++++++++++++++++
> > 1 file changed, 53 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..511c03a36f
> > --- /dev/null
> > +++ b/tests/acceptance/object_option.py
> > @@ -0,0 +1,53 @@
> > +# 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 shlex
> > +import subprocess
> > +
> > +import avocado
> > +import avocado_qemu
> > +
> > +
> > +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("Running command: %s", cmdstr)
> > + return subprocess.run(cmd, universal_newlines=True, *args,
> > **kwargs)
> > +
> > + def get_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()]
> > +
> > + @avocado.fail_on(subprocess.CalledProcessError)
> > + def test_help(self):
> > + """Check if ``-object ...,help`` behaves as expected"""
> > + for device in self.get_devices():
> > + self.run([self.qemu_bin, '-object', '%s,help' % (device)],
> > + check=True,
> > + stdout=subprocess.DEVNULL)
> > +
> > + @avocado.fail_on(subprocess.CalledProcessError)
> > + def test_crash(self):
> > + """Check that QEMU doesn't crash when using ``-object ...``"""
> > + for device in self.get_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")
> >
>
> Eduardo, what is the "acceptance" (functional) part of this test?
It is testing an external interface (the command line), and I'm
pretty sure "not crashing when using -object with valid types" is
a functional requirement.
>
> Thomas, could this be written using the QTest framework instead?
I'm sure it can, but why would we?
I don't think rewriting test cases in C is a good use of our
time.
--
Eduardo
Re: [PATCH v2] tests/acceptance: Test case for detecting -object crashes, Philippe Mathieu-Daudé, 2020/10/26
- Re: [PATCH v2] tests/acceptance: Test case for detecting -object crashes,
Eduardo Habkost <=