On Wed, 19 Oct 2022, Ani Sinha wrote:
> On Wed, Oct 19, 2022 at 3:05 PM Philippe Mathieu-Daudé > <phi...@linaro.org> wrote: > > > > >>> + List, > > >>> + Optional, > > >>> + Sequence, > > >>> +) > > >>> +from qemu.machine import QEMUMachine > > >>> +from avocado import skipIf > > >>> +from avocado_qemu import QemuBaseTest > > > > >>> +@skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') > > >>> +class AcpiBitsTest(QemuBaseTest): #pylint: > > >>> disable=too-many-instance-attributes > > >>> + """ > > >>> + ACPI and SMBIOS tests using biosbits. > > > > > > <snip> > > > > > >>> + > > >>> + def setUp(self): # pylint: disable=arguments-differ > > >>> + super().setUp('qemu-system-') > > >>> + > > >>> + if shutil.which('xorriso') is None: > > >>> + logging.error('xorriso is required to run this test.') > > >>> + self.skipTest("xorriso is not installed. Please install > > >>> it.") > > >> > > >> This would result in output like this when xorriso is not found: > > >> > > >> $ which xorriso > > >> /usr/bin/which: no xorriso in > > >> (/home/anisinha/.local/bin:/home/anisinha/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin) > > >> [anisinha@centos8 build]$ ./tests/venv/bin/avocado run -t acpi > > >> tests/avocado > > >> Fetching asset from > > >> tests/avocado/acpi-bits.py:AcpiBitsTest.test_acpi_smbios_bits > > >> JOB ID : 95aba043201755ed888ef7d1598402c555118df4 > > >> JOB LOG : > > >> /home/anisinha/avocado/job-results/job-2022-10-19T02.27-95aba04/job.log > > >> (1/1) tests/avocado/acpi-bits.py:AcpiBitsTest.test_acpi_smbios_bits: > > >> ERROR: xorriso is not installed. Please install it. (0.00 s) > > > > If an optional tool is missing, the test should be SKIPped, this is not > > an ERROR. > > Yes will fix in v6. > These are the changes I have made in v6 in this test that are worth taking into account when reviewing v5. I want to make v6 as close to the final version as possible. --- tests/avocado/acpi-bits.py 2022-10-19 19:11:21.506830448 +0530 +++ /home/anisinha/temp/acpi-bits.py.v6 2022-10-19 19:11:12.530782674 +0530 @@ -33,6 +33,7 @@ import logging import os +import platform import re import shutil import subprocess @@ -49,12 +50,39 @@ from avocado import skipIf from avocado_qemu import QemuBaseTest +deps = ["xorriso"] # dependent tools needed in the test setup/box. +supported_platforms = ['x86_64'] # supported test platforms. + def _print_log(log): print('\nlogs from biosbits follows:') print('==========================================\n') print(log) print('==========================================\n') +def which(tool): + """ looks up the full path for @tool, returns None if not found + or if @tool does not have executable permissions. + """ + paths=os.getenv('PATH') + for p in paths.split(os.path.pathsep): + p = os.path.join(p, tool) + if os.path.exists(p) and os.access(p, os.X_OK): + return p + return None + +def missing_deps(): + """ returns True if any of the test dependent tools are absent. + """ + for dep in deps: + if which(dep) is None: + return True + return False + +def supported_platform(): + """ checks if the test is running on a supported platform. + """ + return platform.machine() in supported_platforms + class QEMUBitsMachine(QEMUMachine): # pylint: disable=too-few-public-methods """ A QEMU VM, with isa-debugcon enabled and bits iso passed @@ -100,7 +128,9 @@ """return the base argument to QEMU binary""" return self._base_args -@skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') +@skipIf(not supported_platform() or missing_deps() or os.getenv('GITLAB_CI'), + 'incorrect platform or dependencies (%s) not installed ' \ + 'or running on GitLab' % ','.join(deps)) class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes """ ACPI and SMBIOS tests using biosbits. @@ -247,10 +277,6 @@ def setUp(self): # pylint: disable=arguments-differ super().setUp('qemu-system-') - if shutil.which('xorriso') is None: - logging.error('xorriso is required to run this test.') - self.skipTest("xorriso is not installed. Please install it.") - self._baseDir = os.getenv('AVOCADO_TEST_BASEDIR') # workdir could also be avocado's own workdir in self.workdir.