[Qemu-devel] [RFC 00/24] Avocado-based functional tests

Eduardo Habkost posted 24 patches 5 years, 12 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180420181951.7252-1-ehabkost@redhat.com
Test checkpatch failed
Test docker-build@min-glib passed
Test docker-mingw@fedora passed
Test s390x passed
scripts/qemu.py                                    |  59 ++-
tests/avocado/README.rst                           | 132 +++++++
tests/avocado/avocado_qemu/__init__.py             |   0
tests/avocado/avocado_qemu/test.py                 | 418 +++++++++++++++++++++
tests/avocado/parameters.yaml                      |  19 +
tests/avocado/test_info_memdev_host_nodes.py       |  66 ++++
tests/avocado/test_nec-usb-xhci.py                 |  63 ++++
.../test_nec-usb-xhci.py.data/parameters.yaml      |   4 +
tests/avocado/test_numa_hotplug.py                 | 120 ++++++
tests/avocado/test_ovmf_with_240_vcpus.py          |  70 ++++
.../parameters.yaml                                |   2 +
tests/avocado/test_vnc.py                          |  58 +++
tests/avocado/variants.yaml                        |  62 +++
tests/qemu-iotests/iotests.py                      |  28 +-
14 files changed, 1077 insertions(+), 24 deletions(-)
create mode 100644 tests/avocado/README.rst
create mode 100644 tests/avocado/avocado_qemu/__init__.py
create mode 100644 tests/avocado/avocado_qemu/test.py
create mode 100644 tests/avocado/parameters.yaml
create mode 100644 tests/avocado/test_info_memdev_host_nodes.py
create mode 100644 tests/avocado/test_nec-usb-xhci.py
create mode 100644 tests/avocado/test_nec-usb-xhci.py.data/parameters.yaml
create mode 100644 tests/avocado/test_numa_hotplug.py
create mode 100644 tests/avocado/test_ovmf_with_240_vcpus.py
create mode 100644 tests/avocado/test_ovmf_with_240_vcpus.py.data/parameters.yaml
create mode 100644 tests/avocado/test_vnc.py
create mode 100644 tests/avocado/variants.yaml
[Qemu-devel] [RFC 00/24] Avocado-based functional tests
Posted by Eduardo Habkost 5 years, 12 months ago
Background
==========

A few months ago, Cleber started a thread[1] about the system for
Avocado-based tests.  He invited people to take a look at it, we
got some interesting feedback.

However, I saw no feedback on the actual code itself, and I don't
know what needs to be done to get this merged.

To make sure we're having a discussion about the implementation
of avocado_qemu and to figure out what's still necessary to get
it included, I am sending all the commits from Amador's
avocado_qemu branch[2] as a RFC.

Note that I didn't review most of this code yet, and I will
probably send comments and questions as replies to this RFC
later.

Also, many of the patches in this series probably can be squashed
together, but I decided to not do that before getting some
feedback on the changes.

[1] https://www.mail-archive.com/qemu-devel@nongnu.org/msg506859.html
[2] https://github.com/apahim/qemu/commits/avocado_qemu

README
======

Below, I'm copying the raw contents of tests/avocado/README.rst,
for reference:

----------------------------------------------------------------------

========================================
 QEMU tests using the Avocado Framework
========================================

This directory [tests/avocado] hosts functional tests written
using Avocado Testing Framework.

Installation
============

To install Avocado and the dependencies needed for these tests, run::

    pip install --user avocado-framework avocado-framework-plugin-varianter-yaml-to-mux aexpect

Alternatively, follow the instructions on this link::

    http://avocado-framework.readthedocs.io/en/latest/GetStartedGuide.html#installing-avocado

Overview
========

In this directory [tests/avocado], an ``avocado_qemu`` package is
provided, containing the ``test`` module, which inherits from
``avocado.Test`` and provides a builtin and easy-to-use Qemu
virtual machine. Here's a template that can be used as reference
to start writing your own tests::

    from avocado_qemu import test

    class MyTest(test.QemuTest):
        """
        :avocado: enable
        """

        def setUp(self):
            self.vm.args.extend(['-m', '512'])
            self.vm.launch()

        def test_01(self):
            res = self.vm.qmp('human-monitor-command',
                              command_line='info version')
            self.assertIn('v2.9.0', res['return'])

        def tearDown(self):
            self.vm.shutdown()

To execute your test, run::

    avocado run test_my_test.py

To execute all tests, run::

    avocado run .

If you don't specify the Qemu binary to use, the ``avocado_qemu``
package will automatically probe it. The probe will try to use the Qemu
binary from the git tree build directory, using the same architecture as
the local system (if the architecture is not specified). If the Qemu
binary is not available in the git tree build directory, the next try is
to use the system installed Qemu binary.

You can define a number of optional parameters, providing them via YAML
file using the Avocado parameters system:

- ``qemu_bin``: Use a given Qemu binary, skipping the automatic
  probe. Example: ``qemu_bin: /usr/libexec/qemu-kvm``.
- ``qemu_dst_bin``: Use a given Qemu binary to create the destination VM
  when the migration process takes place. If it's not provided, the same
  binary used in the source VM will be used for the destination VM.
  Example: ``qemu_dst_bin: /usr/libexec/qemu-kvm-binary2``.
- ``arch``: Probe the Qemu binary from a given architecture. It has no
  effect if ``qemu_bin`` is specified. If not provided, the binary probe
  will use the system architecture. Example: ``arch: x86_64``
- ``image_path``: When a test requires (usually a bootable) image, this
  parameter is used to define where the image is located. When undefined
  it uses ``$QEMU_ROOT/bootable_image_$arch.qcow2``. The image is added
  to the qemu command __only__ when the test requires an image. By
  default ``,snapshot=on`` is used, but it can be altered by
  ``image_snapshot`` parameter.
- ``image_user`` and ``image_pass``: When using a ``image_path``, if you
  want to get the console from the Guest OS you have to define the Guest
  OS credentials. Example: ``image_user: avocado`` and
  ``image_pass: p4ssw0rd``. Both parameters have defaults to ``avocado``.
- ``machine_type``: Use this option to define a machine type for the VM.
  Example: ``machine_type: pc``
- ``machine_accel``: Use this option to define a machine acceleration
  for the VM. Example: ``machine_accel: kvm``.
- ``machine_kvm_type``: Use this option to select the KVM type when the
  ``accel`` is ``kvm`` and there are more than one KVM types available.
  Example: ``machine_kvm_type: PR``

Run the test with::

    $ avocado run test_my_test.py -m parameters.yaml

Additionally, you can use a variants file to to set different values
for each parameter. Using the YAML tag ``!mux`` Avocado will execute the
tests once per combination of parameters. Example::

    $ cat variants.yaml
    architecture: !mux
        x86_64:
            arch: x86_64
        i386:
            arch: i386

Run it the with::

    $ avocado run test_my_test.py -m variants.yaml

You can use both the parameters file and the variants file in the same
command line::

    $ avocado run test_my_test.py -m parameters.yaml variants.yaml

Avocado will then merge the parameters from both files and create the
proper variants.

See ``avocado run --help`` and ``man avocado`` for several other
options, such as ``--filter-by-tags``, ``--show-job-log``,
``--failfast``, etc.

Uninstallation
==============

If you've followed the installation instructions above, you can easily
uninstall Avocado.  Start by listing the packages you have installed::

    pip list --user

And remove any package you want with::

    pip uninstall <package_name>

Amador Pahim (12):
  qemu.py: Introduce _create_console() method
  Introduce the basic framework to run Avocado tests
  avocado_qemu: Fix exception name in caller
  avocado_qemu: Improve migration error message
  avocado_qemu: Functional test for RHBZ#1431939
  avocado_qemu: Functional test for RHBZ#1447027
  avocado_qemu: Functional test for RHBZ#1436616
  avocado_qemu: Clean unneeded 'pass'
  avocado_qemu: Set QMP log level to INFO
  avocado_qemu: Introduce the add_image() VM API
  avocado_qemu: Tests fixes
  avocado_qemu: Force vmimage distro

Cleber Rosa (3):
  avocado_qemu: Remove duplicate PortTracker implementation
  avocado_qemu: Simplify the installation instructions
  avocado_qemu: Add a few VNC related tests

Lukáš Doktor (9):
  avocado_qemu: Improve handle_prompts to allow login after booted vm
  avocado_qemu: Be lenient towards poluted serial console
  avocado_qemu: Increase the login timeout to 60s
  avocado_qemu: Add " " after the default prompt regexp
  avocado_qemu: Store "arch" in VM
  avocado_qemu: Provide defaults for user and pass
  avocado_qemu: Ignore kernel messages on get_console
  avocado_qemu: Add support to request image for testing
  avocado_qemu: Functional test for RHBZ1473203

 scripts/qemu.py                                    |  59 ++-
 tests/avocado/README.rst                           | 132 +++++++
 tests/avocado/avocado_qemu/__init__.py             |   0
 tests/avocado/avocado_qemu/test.py                 | 418 +++++++++++++++++++++
 tests/avocado/parameters.yaml                      |  19 +
 tests/avocado/test_info_memdev_host_nodes.py       |  66 ++++
 tests/avocado/test_nec-usb-xhci.py                 |  63 ++++
 .../test_nec-usb-xhci.py.data/parameters.yaml      |   4 +
 tests/avocado/test_numa_hotplug.py                 | 120 ++++++
 tests/avocado/test_ovmf_with_240_vcpus.py          |  70 ++++
 .../parameters.yaml                                |   2 +
 tests/avocado/test_vnc.py                          |  58 +++
 tests/avocado/variants.yaml                        |  62 +++
 tests/qemu-iotests/iotests.py                      |  28 +-
 14 files changed, 1077 insertions(+), 24 deletions(-)
 create mode 100644 tests/avocado/README.rst
 create mode 100644 tests/avocado/avocado_qemu/__init__.py
 create mode 100644 tests/avocado/avocado_qemu/test.py
 create mode 100644 tests/avocado/parameters.yaml
 create mode 100644 tests/avocado/test_info_memdev_host_nodes.py
 create mode 100644 tests/avocado/test_nec-usb-xhci.py
 create mode 100644 tests/avocado/test_nec-usb-xhci.py.data/parameters.yaml
 create mode 100644 tests/avocado/test_numa_hotplug.py
 create mode 100644 tests/avocado/test_ovmf_with_240_vcpus.py
 create mode 100644 tests/avocado/test_ovmf_with_240_vcpus.py.data/parameters.yaml
 create mode 100644 tests/avocado/test_vnc.py
 create mode 100644 tests/avocado/variants.yaml

-- 
2.14.3


Re: [Qemu-devel] [RFC 00/24] Avocado-based functional tests
Posted by no-reply@patchew.org 5 years, 12 months ago
Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20180420181951.7252-1-ehabkost@redhat.com
Subject: [Qemu-devel] [RFC 00/24] Avocado-based functional tests

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]               patchew/20180420181951.7252-1-ehabkost@redhat.com -> patchew/20180420181951.7252-1-ehabkost@redhat.com
Switched to a new branch 'test'
ec49778cf4 avocado_qemu: Add a few VNC related tests
1f46f502ab avocado_qemu: Force vmimage distro
3c652684e4 avocado_qemu: Tests fixes
c4e2d71898 avocado_qemu: Introduce the add_image() VM API
35b9856b7d avocado_qemu: Set QMP log level to INFO
3d81ee79d0 avocado_qemu: Clean unneeded 'pass'
3fea592db2 avocado_qemu: Simplify the installation instructions
d1b9960835 avocado_qemu: Remove duplicate PortTracker implementation
030c3444fa avocado_qemu: Functional test for RHBZ1473203
4452f51949 avocado_qemu: Functional test for RHBZ#1436616
a791819b84 avocado_qemu: Functional test for RHBZ#1447027
1b525617c2 avocado_qemu: Functional test for RHBZ#1431939
8cb3174c7d avocado_qemu: Improve migration error message
800fdc0407 avocado_qemu: Fix exception name in caller
487b76eeea avocado_qemu: Add support to request image for testing
2349952ea0 avocado_qemu: Ignore kernel messages on get_console
ee1ba766ab avocado_qemu: Provide defaults for user and pass
2151fc0647 avocado_qemu: Store "arch" in VM
27d897fc64 avocado_qemu: Add " " after the default prompt regexp
1b31385780 avocado_qemu: Increase the login timeout to 60s
f964227931 avocado_qemu: Be lenient towards poluted serial console
903c5ccd71 avocado_qemu: Improve handle_prompts to allow login after booted vm
46e5bdc04f Introduce the basic framework to run Avocado tests
9a629a9861 qemu.py: Introduce _create_console() method

=== OUTPUT BEGIN ===
Checking PATCH 1/24: qemu.py: Introduce _create_console() method...
Checking PATCH 2/24: Introduce the basic framework to run Avocado tests...
WARNING: line over 80 characters
#311: FILE: tests/avocado/avocado_qemu/test.py:118:
+    :raise QEMULoginProcessTerminatedError: If the client terminates during login

WARNING: line over 80 characters
#399: FILE: tests/avocado/avocado_qemu/test.py:206:
+            raise QEMULoginProcessTerminatedError(details.status, details.output)

total: 0 errors, 2 warnings, 661 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 3/24: avocado_qemu: Improve handle_prompts to allow login after booted vm...
Checking PATCH 4/24: avocado_qemu: Be lenient towards poluted serial console...
Checking PATCH 5/24: avocado_qemu: Increase the login timeout to 60s...
Checking PATCH 6/24: avocado_qemu: Add " " after the default prompt regexp...
Checking PATCH 7/24: avocado_qemu: Store "arch" in VM...
Checking PATCH 8/24: avocado_qemu: Provide defaults for user and pass...
Checking PATCH 9/24: avocado_qemu: Ignore kernel messages on get_console...
Checking PATCH 10/24: avocado_qemu: Add support to request image for testing...
Checking PATCH 11/24: avocado_qemu: Fix exception name in caller...
Checking PATCH 12/24: avocado_qemu: Improve migration error message...
Checking PATCH 13/24: avocado_qemu: Functional test for RHBZ#1431939...
WARNING: line over 80 characters
#73: FILE: tests/avocado/test_info_memdev_host_nodes.py:49:
+        cmd = 'object_add memory-backend-ram,id=mem1,host-nodes=0,size=2G,policy=bind'

total: 0 errors, 1 warnings, 66 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 14/24: avocado_qemu: Functional test for RHBZ#1447027...
ERROR: line over 90 characters
#51: FILE: tests/avocado/test_ovmf_with_240_vcpus.py:22:
+                                         default='/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd')

WARNING: line over 80 characters
#53: FILE: tests/avocado/test_ovmf_with_240_vcpus.py:24:
+                                         default='/usr/share/edk2/ovmf/OVMF_VARS.fd')

total: 1 errors, 1 warnings, 72 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 15/24: avocado_qemu: Functional test for RHBZ#1436616...
WARNING: line over 80 characters
#53: FILE: tests/avocado/test_nec-usb-xhci.py:24:
+        self.vm.args.extend(['-device', 'nec-usb-xhci,id=xhci1,bus=bridge1,addr=0x3'])

ERROR: line over 90 characters
#54: FILE: tests/avocado/test_nec-usb-xhci.py:25:
+        self.vm.args.extend(['-drive', 'file=%s,format=raw,id=drive_usb,if=none' % usbdevice])

ERROR: line over 90 characters
#55: FILE: tests/avocado/test_nec-usb-xhci.py:26:
+        self.vm.args.extend(['-device', 'usb-storage,drive=drive_usb,id=device_usb,bus=xhci1.0'])

total: 2 errors, 1 warnings, 59 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 16/24: avocado_qemu: Functional test for RHBZ1473203...
Checking PATCH 17/24: avocado_qemu: Remove duplicate PortTracker implementation...
Checking PATCH 18/24: avocado_qemu: Simplify the installation instructions...
Checking PATCH 19/24: avocado_qemu: Clean unneeded 'pass'...
Checking PATCH 20/24: avocado_qemu: Set QMP log level to INFO...
Checking PATCH 21/24: avocado_qemu: Introduce the add_image() VM API...
Checking PATCH 22/24: avocado_qemu: Tests fixes...
Checking PATCH 23/24: avocado_qemu: Force vmimage distro...
Checking PATCH 24/24: avocado_qemu: Add a few VNC related tests...
=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com