Python queue, 2019-05-02

* configure: automatically pick python3 is available
   (Daniel P. Berrangé)
 
 * tests/acceptance (Cleber Rosa, Philippe Mathieu-Daudé):
   * Multi-architecture test support
   * Multiple arch-specific boot_linux_console test cases
   * Increase verbosity of avocado by default
   * docstring improvements
 -----BEGIN PGP SIGNATURE-----
 
 iQIcBAABCAAGBQJcy43mAAoJECgHk2+YTcWm7DEQAIWbC47Ux4Mbww+RFFHGiqR0
 Add+gvRp+PiAwHFqvE/tmWXlXFefMT6igeMfUmh6Z9SX+aWclX4IHP7NBQ5XeaWp
 YPoPzh0aPft40EfI/ncN6YCSRB89knAVbJZzsBjIduVOgRhty0HLo7TcNxGOISMo
 bUFGZEq8dFJW2twDBbYOD3ho4BSSw99RcfUcqp7SrIAvOi9b6AxN30MKomqwzZlq
 gOjGqhbbOvGllNclnB1VKJOp+3e4G6TuJu//OWgroKTAZMYx0+qmcjnCH9b9noDN
 JBhnoJbYGOS53FXNiPmhgz99hjQHSwovyepfwbnqHZgdFhMWceKkV2WbtsgixOba
 NKX3DPvQgLybXOWVYGBFpPAc5WwzAgfGuXWcN3Qe6H9YdZruJJVS6ZDy4P41hqrL
 1DAsMWVInwojwYT3Q5Xuy2FwUoEFXe1aFLzMc3KB7wDq1VOs9WfvXrECxWY3bo7z
 7Ygx721vJzfheRrvLQSlK6o3TgVc9MjWdLInbXpHHZtjyfp65MahjOMUvFz/NXPk
 DObg8xn35B955QSH08QsLl/t6uHx2YoEIJyXvHNr330U4+py0Akx3bPYwupKc6ft
 6j7KNFB3w15jDE4+WRoWbwCbWfwJ3JmeZAp54rp4tT69b2+gFnCXVp4iS9ARMewo
 gO4yr84+4dmHNt/tJp3b
 =GuGy
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/ehabkost/tags/python-next-pull-request' into staging

Python queue, 2019-05-02

* configure: automatically pick python3 is available
  (Daniel P. Berrangé)

* tests/acceptance (Cleber Rosa, Philippe Mathieu-Daudé):
  * Multi-architecture test support
  * Multiple arch-specific boot_linux_console test cases
  * Increase verbosity of avocado by default
  * docstring improvements

# gpg: Signature made Fri 03 May 2019 01:40:06 BST
# gpg:                using RSA key 2807936F984DC5A6
# gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>" [full]
# Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF  D1AA 2807 936F 984D C5A6

* remotes/ehabkost/tags/python-next-pull-request:
  configure: automatically pick python3 is available
  tests/boot_linux_console: add a test for alpha + clipper
  tests/boot_linux_console: add a test for s390x + s390-ccw-virtio
  tests/boot_linux_console: add a test for arm + virt
  tests/boot_linux_console: add a test for aarch64 + virt
  tests/boot_linux_console: add a test for mips64el + malta
  tests/boot_linux_console: add a test for mips + malta
  scripts/qemu.py: support adding a console with the default serial device
  tests/boot_linux_console: refactor the console watcher into utility method
  tests/boot_linux_console: increase timeout
  tests/boot_linux_console: add common kernel command line options
  tests/boot_linux_console: update the x86_64 kernel
  tests/boot_linux_console: rename the x86_64 after the arch and machine
  tests/acceptance: look for target architecture in test tags first
  tests/acceptance: use "arch:" tag to filter target specific tests
  tests/acceptance: introduce arch parameter and attribute
  tests/acceptance: fix doc reference to avocado_qemu directory
  tests/acceptance: improve docstring on pick_default_qemu_bin()
  tests/acceptance: show avocado test execution by default

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

# Conflicts:
#	configure
This commit is contained in:
Peter Maydell 2019-05-03 15:26:09 +01:00
commit a6ae23831b
9 changed files with 284 additions and 64 deletions

View File

@ -223,8 +223,8 @@ matrix:
# Acceptance (Functional) tests
- env:
- CONFIG="--python=/usr/bin/python3 --target-list=x86_64-softmmu"
- TEST_CMD="make AVOCADO_SHOW=app check-acceptance"
- CONFIG="--python=/usr/bin/python3 --target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu,alpha-softmmu"
- TEST_CMD="make check-acceptance"
addons:
apt:
packages:

18
configure vendored
View File

@ -899,7 +899,18 @@ fi
: ${make=${MAKE-make}}
: ${install=${INSTALL-install}}
: ${python=${PYTHON-python}}
# We prefer python 3.x. A bare 'python' is traditionally
# python 2.x, but some distros have it as python 3.x, so
# we check that before python2
python=
for binary in "${PYTHON-python3}" python python2
do
if has "$binary"
then
python="$binary"
break
fi
done
: ${smbd=${SMBD-/usr/sbin/smbd}}
# Default objcc to clang if available, otherwise use CC
@ -1823,8 +1834,9 @@ fi
# Remove old dependency files to make sure that they get properly regenerated
rm -f *-config-devices.mak.d
if ! has $python; then
error_exit "Python not found. Use --python=/path/to/python"
if test -z "$python"
then
error_exit "Python not found. Use --python=/path/to/python"
fi
# Note that if the Python conditional here evaluates True we will exit

View File

@ -590,8 +590,9 @@ Alternatively, follow the instructions on this link:
Overview
--------
This directory provides the ``avocado_qemu`` Python module, containing
the ``avocado_qemu.Test`` class. Here's a simple usage example:
The ``tests/acceptance/avocado_qemu`` directory provides the
``avocado_qemu`` Python module, containing the ``avocado_qemu.Test``
class. Here's a simple usage example:
.. code::
@ -726,6 +727,23 @@ vm
A QEMUMachine instance, initially configured according to the given
``qemu_bin`` parameter.
arch
~~~~
The architecture can be used on different levels of the stack, e.g. by
the framework or by the test itself. At the framework level, it will
currently influence the selection of a QEMU binary (when one is not
explicitly given).
Tests are also free to use this attribute value, for their own needs.
A test may, for instance, use the same value when selecting the
architecture of a kernel or disk image to boot a VM with.
The ``arch`` attribute will be set to the test parameter of the same
name. If one is not given explicitly, it will either be set to
``None``, or, if the test is tagged with one (and only one)
``:avocado: tags=arch:VALUE`` tag, it will be set to ``VALUE``.
qemu_bin
~~~~~~~~
@ -748,6 +766,19 @@ like the following:
PARAMS (key=qemu_bin, path=*, default=x86_64-softmmu/qemu-system-x86_64) => 'x86_64-softmmu/qemu-system-x86_64
arch
~~~~
The architecture that will influence the selection of a QEMU binary
(when one is not explicitly given).
Tests are also free to use this parameter value, for their own needs.
A test may, for instance, use the same value when selecting the
architecture of a kernel or disk image to boot a VM with.
This parameter has a direct relation with the ``arch`` attribute. If
not given, it will default to None.
qemu_bin
~~~~~~~~

View File

@ -41,17 +41,6 @@ def kvm_available(target_arch=None):
return os.access("/dev/kvm", os.R_OK | os.W_OK)
#: Maps machine types to the preferred console device types
CONSOLE_DEV_TYPES = {
r'^clipper$': 'isa-serial',
r'^malta': 'isa-serial',
r'^(pc.*|q35.*|isapc)$': 'isa-serial',
r'^(40p|powernv|prep)$': 'isa-serial',
r'^pseries.*': 'spapr-vty',
r'^s390-ccw-virtio.*': 'sclpconsole',
}
class QEMUMachineError(Exception):
"""
Exception called when an error in QEMUMachine happens.
@ -130,6 +119,7 @@ class QEMUMachine(object):
self._temp_dir = None
self._launched = False
self._machine = None
self._console_set = False
self._console_device_type = None
self._console_address = None
self._console_socket = None
@ -248,13 +238,17 @@ class QEMUMachine(object):
'-display', 'none', '-vga', 'none']
if self._machine is not None:
args.extend(['-machine', self._machine])
if self._console_device_type is not None:
if self._console_set:
self._console_address = os.path.join(self._temp_dir,
self._name + "-console.sock")
chardev = ('socket,id=console,path=%s,server,nowait' %
self._console_address)
device = '%s,chardev=console' % self._console_device_type
args.extend(['-chardev', chardev, '-device', device])
args.extend(['-chardev', chardev])
if self._console_device_type is None:
args.extend(['-serial', 'chardev:console'])
else:
device = '%s,chardev=console' % self._console_device_type
args.extend(['-device', device])
return args
def _pre_launch(self):
@ -480,30 +474,20 @@ class QEMUMachine(object):
line.
This is a convenience method that will either use the provided
device type, of if not given, it will used the device type set
on CONSOLE_DEV_TYPES.
device type, or default to a "-serial chardev:console" command
line argument.
The actual setting of command line arguments will be be done at
machine launch time, as it depends on the temporary directory
to be created.
@param device_type: the device type, such as "isa-serial"
@raises: QEMUMachineAddDeviceError if the device type is not given
and can not be determined.
@param device_type: the device type, such as "isa-serial". If
None is given (the default value) a "-serial
chardev:console" command line argument will
be used instead, resorting to the machine's
default device type.
"""
if device_type is None:
if self._machine is None:
raise QEMUMachineAddDeviceError("Can not add a console device:"
" QEMU instance without a "
"defined machine type")
for regex, device in CONSOLE_DEV_TYPES.items():
if re.match(regex, self._machine):
device_type = device
break
if device_type is None:
raise QEMUMachineAddDeviceError("Can not add a console device:"
" no matching console device "
"type definition")
self._console_set = True
self._console_device_type = device_type
@property

View File

@ -1133,7 +1133,8 @@ TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/results
# Controls the output generated by Avocado when running tests.
# Any number of command separated loggers are accepted. For more
# information please refer to "avocado --help".
AVOCADO_SHOW=none
AVOCADO_SHOW=app
AVOCADO_TAGS=$(patsubst %-softmmu,-t arch:%, $(filter %-softmmu,$(TARGET_DIRS)))
ifneq ($(findstring v2,"v$(PYTHON_VERSION)"),v2)
$(TESTS_VENV_DIR): $(TESTS_VENV_REQ)
@ -1159,6 +1160,8 @@ check-acceptance: check-venv $(TESTS_RESULTS_DIR)
$(call quiet-command, \
$(TESTS_VENV_DIR)/bin/python -m avocado \
--show=$(AVOCADO_SHOW) run --job-results-dir=$(TESTS_RESULTS_DIR) \
--filter-by-tags-include-empty --filter-by-tags-include-empty-key \
$(AVOCADO_TAGS) \
--failfast=on $(SRC_PATH)/tests/acceptance, \
"AVOCADO", "tests/acceptance")

View File

@ -23,12 +23,22 @@ def is_readable_executable_file(path):
return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
def pick_default_qemu_bin():
def pick_default_qemu_bin(arch=None):
"""
Picks the path of a QEMU binary, starting either in the current working
directory or in the source tree root directory.
:param arch: the arch to use when looking for a QEMU binary (the target
will match the arch given). If None (the default), arch
will be the current host system arch (as given by
:func:`os.uname`).
:type arch: str
:returns: the path to the default QEMU binary or None if one could not
be found
:rtype: str or None
"""
arch = os.uname()[4]
if arch is None:
arch = os.uname()[4]
qemu_bin_relative_path = os.path.join("%s-softmmu" % arch,
"qemu-system-%s" % arch)
if is_readable_executable_file(qemu_bin_relative_path):
@ -43,8 +53,15 @@ def pick_default_qemu_bin():
class Test(avocado.Test):
def setUp(self):
self._vms = {}
arches = self.tags.get('arch', [])
if len(arches) == 1:
arch = arches.pop()
else:
arch = None
self.arch = self.params.get('arch', default=arch)
default_qemu_bin = pick_default_qemu_bin(arch=self.arch)
self.qemu_bin = self.params.get('qemu_bin',
default=pick_default_qemu_bin())
default=default_qemu_bin)
if self.qemu_bin is None:
self.cancel("No QEMU binary defined or found in the source tree")

View File

@ -8,39 +8,212 @@
# 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 os
import logging
from avocado_qemu import Test
from avocado.utils import process
from avocado.utils import archive
class BootLinuxConsole(Test):
"""
Boots a x86_64 Linux kernel and checks that the console is operational
and the kernel command line is properly passed from QEMU to the kernel
:avocado: tags=x86_64
Boots a Linux kernel and checks that the console is operational and the
kernel command line is properly passed from QEMU to the kernel
"""
timeout = 60
timeout = 90
def test(self):
kernel_url = ('https://mirrors.kernel.org/fedora/releases/28/'
'Everything/x86_64/os/images/pxeboot/vmlinuz')
kernel_hash = '238e083e114c48200f80d889f7e32eeb2793e02a'
kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
self.vm.set_machine('pc')
self.vm.set_console()
kernel_command_line = 'console=ttyS0'
self.vm.add_args('-kernel', kernel_path,
'-append', kernel_command_line)
self.vm.launch()
def wait_for_console_pattern(self, success_message,
failure_message='Kernel panic - not syncing'):
"""
Waits for messages to appear on the console, while logging the content
:param success_message: if this message appears, test succeeds
:param failure_message: if this message appears, test fails
"""
console = self.vm.console_socket.makefile()
console_logger = logging.getLogger('console')
while True:
msg = console.readline()
console_logger.debug(msg.strip())
if 'Kernel command line: %s' % kernel_command_line in msg:
if success_message in msg:
break
if 'Kernel panic - not syncing' in msg:
self.fail("Kernel panic reached")
if failure_message in msg:
fail = 'Failure message found in console: %s' % failure_message
self.fail(fail)
def extract_from_deb(self, deb, path):
"""
Extracts a file from a deb package into the test workdir
:param deb: path to the deb archive
:param file: path within the deb archive of the file to be extracted
:returns: path of the extracted file
"""
cwd = os.getcwd()
os.chdir(self.workdir)
process.run("ar x %s data.tar.gz" % deb)
archive.extract("data.tar.gz", self.workdir)
os.chdir(cwd)
return self.workdir + path
def test_x86_64_pc(self):
"""
:avocado: tags=arch:x86_64
:avocado: tags=machine:pc
"""
kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
'releases/29/Everything/x86_64/os/images/pxeboot/vmlinuz')
kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
self.vm.set_machine('pc')
self.vm.set_console()
kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
self.vm.add_args('-kernel', kernel_path,
'-append', kernel_command_line)
self.vm.launch()
console_pattern = 'Kernel command line: %s' % kernel_command_line
self.wait_for_console_pattern(console_pattern)
def test_mips_malta(self):
"""
:avocado: tags=arch:mips
:avocado: tags=machine:malta
:avocado: tags=endian:big
"""
deb_url = ('http://snapshot.debian.org/archive/debian/'
'20130217T032700Z/pool/main/l/linux-2.6/'
'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
kernel_path = self.extract_from_deb(deb_path,
'/boot/vmlinux-2.6.32-5-4kc-malta')
self.vm.set_machine('malta')
self.vm.set_console()
kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
self.vm.add_args('-kernel', kernel_path,
'-append', kernel_command_line)
self.vm.launch()
console_pattern = 'Kernel command line: %s' % kernel_command_line
self.wait_for_console_pattern(console_pattern)
def test_mips64el_malta(self):
"""
This test requires the ar tool to extract "data.tar.gz" from
the Debian package.
The kernel can be rebuilt using this Debian kernel source [1] and
following the instructions on [2].
[1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
#linux-source-2.6.32_2.6.32-48
[2] https://kernel-team.pages.debian.net/kernel-handbook/
ch-common-tasks.html#s-common-official
:avocado: tags=arch:mips64el
:avocado: tags=machine:malta
"""
deb_url = ('http://snapshot.debian.org/archive/debian/'
'20130217T032700Z/pool/main/l/linux-2.6/'
'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
kernel_path = self.extract_from_deb(deb_path,
'/boot/vmlinux-2.6.32-5-5kc-malta')
self.vm.set_machine('malta')
self.vm.set_console()
kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
self.vm.add_args('-kernel', kernel_path,
'-append', kernel_command_line)
self.vm.launch()
console_pattern = 'Kernel command line: %s' % kernel_command_line
self.wait_for_console_pattern(console_pattern)
def test_aarch64_virt(self):
"""
:avocado: tags=arch:aarch64
:avocado: tags=machine:virt
"""
kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
'releases/29/Everything/aarch64/os/images/pxeboot/vmlinuz')
kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
self.vm.set_machine('virt')
self.vm.set_console()
kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
'console=ttyAMA0')
self.vm.add_args('-cpu', 'cortex-a53',
'-kernel', kernel_path,
'-append', kernel_command_line)
self.vm.launch()
console_pattern = 'Kernel command line: %s' % kernel_command_line
self.wait_for_console_pattern(console_pattern)
def test_arm_virt(self):
"""
:avocado: tags=arch:arm
:avocado: tags=machine:virt
"""
kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
'releases/29/Everything/armhfp/os/images/pxeboot/vmlinuz')
kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
self.vm.set_machine('virt')
self.vm.set_console()
kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
'console=ttyAMA0')
self.vm.add_args('-kernel', kernel_path,
'-append', kernel_command_line)
self.vm.launch()
console_pattern = 'Kernel command line: %s' % kernel_command_line
self.wait_for_console_pattern(console_pattern)
def test_s390x_s390_ccw_virtio(self):
"""
:avocado: tags=arch:s390x
:avocado: tags=machine:s390_ccw_virtio
"""
kernel_url = ('https://download.fedoraproject.org/pub/fedora-secondary/'
'releases/29/Everything/s390x/os/images/kernel.img')
kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
self.vm.set_machine('s390-ccw-virtio')
self.vm.set_console()
kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
self.vm.add_args('-nodefaults',
'-kernel', kernel_path,
'-append', kernel_command_line)
self.vm.launch()
console_pattern = 'Kernel command line: %s' % kernel_command_line
self.wait_for_console_pattern(console_pattern)
def test_alpha_clipper(self):
"""
:avocado: tags=arch:alpha
:avocado: tags=machine:clipper
"""
kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
'installer-alpha/current/images/cdrom/vmlinuz')
kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
self.vm.set_machine('clipper')
self.vm.set_console()
kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
self.vm.add_args('-vga', 'std',
'-kernel', uncompressed_kernel,
'-append', kernel_command_line)
self.vm.launch()
console_pattern = 'Kernel command line: %s' % kernel_command_line
self.wait_for_console_pattern(console_pattern)

View File

@ -19,7 +19,7 @@ class LinuxInitrd(Test):
"""
Checks QEMU evaluates correctly the initrd file passed as -initrd option.
:avocado: tags=x86_64
:avocado: tags=arch:x86_64
"""
timeout = 300

View File

@ -61,7 +61,7 @@ class VirtioVersionCheck(Test):
same device tree created by `disable-modern` and
`disable-legacy`.
:avocado: tags=x86_64
:avocado: tags=arch:x86_64
"""
# just in case there are failures, show larger diff: