From 6aa0cd7860531e1a52195f2657fd368038bd1fc4 Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Fri, 5 Jul 2019 17:41:29 +0200 Subject: Fix aktualizr-native run in oe-selftest It did not work when using an empty build dir with sstate-cache, the proper working way is to bitbake build_sysroots. Also change the way we fetches some of the akautalizr package files which was broken too. Signed-off-by: Laurent Bonnans --- lib/oeqa/selftest/cases/testutils.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lib/oeqa/selftest/cases/testutils.py') diff --git a/lib/oeqa/selftest/cases/testutils.py b/lib/oeqa/selftest/cases/testutils.py index f8b1904..900d15c 100644 --- a/lib/oeqa/selftest/cases/testutils.py +++ b/lib/oeqa/selftest/cases/testutils.py @@ -1,4 +1,5 @@ import os +import oe.path import logging import re import subprocess @@ -72,20 +73,16 @@ def akt_native_run(testInst, cmd, **kwargs): # run a command supplied by aktualizr-native and checks that: # - the executable exists # - the command runs without error - # NOTE: the base test class must have built aktualizr-native (in - # setUpClass, for example) - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], - 'aktualizr-native') - sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] - sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] - libdir = bb_vars['libdir'] - - program, *_ = cmd.split(' ') - p = '{}/{}'.format(sysrootbin, program) - testInst.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) - env = dict(os.environ) - env['LD_LIBRARY_PATH'] = libdir - result = runCmd(cmd, env=env, native_sysroot=sysroot, ignore_status=True, **kwargs) + # + # Requirements in base test class (setUpClass for example): + # bitbake aktualizr-native + # bitbake build-sysroots -c build_native_sysroot + # + # (technique found in poky/meta/lib/oeqa/selftest/cases/package.py) + bb_vars = get_bb_vars(['STAGING_DIR', 'BUILD_ARCH']) + sysroot = oe.path.join(bb_vars['STAGING_DIR'], bb_vars['BUILD_ARCH']) + + result = runCmd(cmd, native_sysroot=sysroot, ignore_status=True, **kwargs) testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) -- cgit v1.2.3-54-g00ecf From 08e60a5085e6e6da95d7c85fed16147ce9e834af Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Mon, 8 Jul 2019 11:28:34 +0200 Subject: Factor out ugly function in oe-selftests Signed-off-by: Laurent Bonnans --- lib/oeqa/selftest/cases/testutils.py | 10 +++++ lib/oeqa/selftest/cases/updater_minnowboard.py | 12 ++---- lib/oeqa/selftest/cases/updater_qemux86_64.py | 47 ++++------------------ .../selftest/cases/updater_qemux86_64_ptest.py | 9 +---- lib/oeqa/selftest/cases/updater_raspberrypi.py | 13 +++--- 5 files changed, 28 insertions(+), 63 deletions(-) (limited to 'lib/oeqa/selftest/cases/testutils.py') diff --git a/lib/oeqa/selftest/cases/testutils.py b/lib/oeqa/selftest/cases/testutils.py index 900d15c..e67f30c 100644 --- a/lib/oeqa/selftest/cases/testutils.py +++ b/lib/oeqa/selftest/cases/testutils.py @@ -69,6 +69,16 @@ def qemu_send_command(port, command, timeout=60): return stdout, stderr, s2.returncode +def metadir(): + # Assume the directory layout for finding other layers. We could also + # make assumptions by using 'show-layers', but either way, if the + # layers we need aren't where we expect them, we are out of luck. + path = os.path.abspath(os.path.dirname(__file__)) + metadir = path + "/../../../../../" + + return metadir + + def akt_native_run(testInst, cmd, **kwargs): # run a command supplied by aktualizr-native and checks that: # - the executable exists diff --git a/lib/oeqa/selftest/cases/updater_minnowboard.py b/lib/oeqa/selftest/cases/updater_minnowboard.py index 267445b..855bd20 100644 --- a/lib/oeqa/selftest/cases/updater_minnowboard.py +++ b/lib/oeqa/selftest/cases/updater_minnowboard.py @@ -1,9 +1,8 @@ -import os import re from oeqa.selftest.case import OESelftestTestCase from oeqa.utils.commands import runCmd, get_bb_var -from testutils import qemu_launch, qemu_send_command, qemu_terminate, verifyProvisioned +from testutils import metadir, qemu_launch, qemu_send_command, qemu_terminate, verifyProvisioned class MinnowTests(OESelftestTestCase): @@ -12,18 +11,13 @@ class MinnowTests(OESelftestTestCase): layer_intel = "meta-intel" layer_minnow = "meta-updater-minnowboard" result = runCmd('bitbake-layers show-layers') - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of luck. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" if re.search(layer_intel, result.output) is None: - self.meta_intel = metadir + layer_intel + self.meta_intel = metadir() + layer_intel runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) else: self.meta_intel = None if re.search(layer_minnow, result.output) is None: - self.meta_minnow = metadir + layer_minnow + self.meta_minnow = metadir() + layer_minnow runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow) else: self.meta_minnow = None diff --git a/lib/oeqa/selftest/cases/updater_qemux86_64.py b/lib/oeqa/selftest/cases/updater_qemux86_64.py index c61c9b2..7228529 100644 --- a/lib/oeqa/selftest/cases/updater_qemux86_64.py +++ b/lib/oeqa/selftest/cases/updater_qemux86_64.py @@ -9,7 +9,8 @@ from uuid import uuid4 from oeqa.selftest.case import OESelftestTestCase from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars from testutils import qemu_launch, qemu_send_command, qemu_terminate, \ - akt_native_run, verifyNotProvisioned, verifyProvisioned, qemu_bake_image, qemu_boot_image + metadir, akt_native_run, verifyNotProvisioned, verifyProvisioned, \ + qemu_bake_image, qemu_boot_image class GeneralTests(OESelftestTestCase): @@ -46,8 +47,6 @@ class AktualizrToolsTests(OESelftestTestCase): akt_native_run(self, 'aktualizr-cert-provider --help') def test_cert_provider_local_output(self): - logger = logging.getLogger("selftest") - logger.info('Running bitbake to build aktualizr-device-prov') bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native') creds = bb_vars['SOTA_PACKED_CREDENTIALS'] temp_dir = bb_vars['T'] @@ -75,12 +74,7 @@ class SharedCredProvTests(OESelftestTestCase): layer = "meta-updater-qemux86-64" result = runCmd('bitbake-layers show-layers') if re.search(layer, result.output) is None: - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of luck. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" - self.meta_qemu = metadir + layer + self.meta_qemu = metadir() + layer runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) else: self.meta_qemu = None @@ -117,12 +111,7 @@ class ManualControlTests(OESelftestTestCase): layer = "meta-updater-qemux86-64" result = runCmd('bitbake-layers show-layers') if re.search(layer, result.output) is None: - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of like. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" - self.meta_qemu = metadir + layer + self.meta_qemu = metadir() + layer runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) else: self.meta_qemu = None @@ -161,12 +150,7 @@ class DeviceCredProvTests(OESelftestTestCase): layer = "meta-updater-qemux86-64" result = runCmd('bitbake-layers show-layers') if re.search(layer, result.output) is None: - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of luck. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" - self.meta_qemu = metadir + layer + self.meta_qemu = metadir() + layer runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) else: self.meta_qemu = None @@ -217,12 +201,7 @@ class DeviceCredProvHsmTests(OESelftestTestCase): layer = "meta-updater-qemux86-64" result = runCmd('bitbake-layers show-layers') if re.search(layer, result.output) is None: - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of luck. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" - self.meta_qemu = metadir + layer + self.meta_qemu = metadir() + layer runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) else: self.meta_qemu = None @@ -399,12 +378,7 @@ class IpSecondaryTests(OESelftestTestCase): layer = "meta-updater-qemux86-64" result = runCmd('bitbake-layers show-layers') if re.search(layer, result.output) is None: - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of luck. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" - self.meta_qemu = metadir + layer + self.meta_qemu = metadir() + layer runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) else: self.meta_qemu = None @@ -446,12 +420,7 @@ class ResourceControlTests(OESelftestTestCase): layer = "meta-updater-qemux86-64" result = runCmd('bitbake-layers show-layers') if re.search(layer, result.output) is None: - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of luck. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" - self.meta_qemu = metadir + layer + self.meta_qemu = metadir() + layer runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) else: self.meta_qemu = None diff --git a/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py b/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py index 0f0f491..88e773b 100644 --- a/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py +++ b/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py @@ -4,7 +4,7 @@ import re from oeqa.selftest.case import OESelftestTestCase from oeqa.utils.commands import runCmd -from testutils import qemu_launch, qemu_send_command, qemu_terminate +from testutils import metadir, qemu_launch, qemu_send_command, qemu_terminate class PtestTests(OESelftestTestCase): @@ -13,12 +13,7 @@ class PtestTests(OESelftestTestCase): layer = "meta-updater-qemux86-64" result = runCmd('bitbake-layers show-layers') if re.search(layer, result.output) is None: - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of like. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" - self.meta_qemu = metadir + layer + self.meta_qemu = metadir() + layer runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) else: self.meta_qemu = None diff --git a/lib/oeqa/selftest/cases/updater_raspberrypi.py b/lib/oeqa/selftest/cases/updater_raspberrypi.py index 6b71a03..b1375bb 100644 --- a/lib/oeqa/selftest/cases/updater_raspberrypi.py +++ b/lib/oeqa/selftest/cases/updater_raspberrypi.py @@ -7,6 +7,8 @@ import unittest from oeqa.selftest.case import OESelftestTestCase from oeqa.utils.commands import runCmd, bitbake, get_bb_var +from testutils import metadir + class RpiTests(OESelftestTestCase): @@ -17,23 +19,18 @@ class RpiTests(OESelftestTestCase): layer_rpi = "meta-raspberrypi" layer_upd_rpi = "meta-updater-raspberrypi" result = runCmd('bitbake-layers show-layers') - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of luck. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" if re.search(layer_python, result.output) is None: - self.meta_python = metadir + layer_python + self.meta_python = metadir() + layer_python runCmd('bitbake-layers add-layer "%s"' % self.meta_python) else: self.meta_python = None if re.search(layer_rpi, result.output) is None: - self.meta_rpi = metadir + layer_rpi + self.meta_rpi = metadir() + layer_rpi runCmd('bitbake-layers add-layer "%s"' % self.meta_rpi) else: self.meta_rpi = None if re.search(layer_upd_rpi, result.output) is None: - self.meta_upd_rpi = metadir + layer_upd_rpi + self.meta_upd_rpi = metadir() + layer_upd_rpi runCmd('bitbake-layers add-layer "%s"' % self.meta_upd_rpi) else: self.meta_upd_rpi = None -- cgit v1.2.3-54-g00ecf From 3d83977e4d3f7a75ad80c4a5ba190b4d48ec2ec8 Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Tue, 9 Jul 2019 12:06:22 +0200 Subject: Fix some oe-selftest timeouts issues Was causing problems on CI Signed-off-by: Laurent Bonnans --- lib/oeqa/selftest/cases/testutils.py | 2 +- lib/oeqa/selftest/cases/updater_qemux86_64.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'lib/oeqa/selftest/cases/testutils.py') diff --git a/lib/oeqa/selftest/cases/testutils.py b/lib/oeqa/selftest/cases/testutils.py index e67f30c..208f822 100644 --- a/lib/oeqa/selftest/cases/testutils.py +++ b/lib/oeqa/selftest/cases/testutils.py @@ -61,7 +61,7 @@ def qemu_bake_image(imagename): bitbake(imagename) -def qemu_send_command(port, command, timeout=60): +def qemu_send_command(port, command, timeout=120): command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + str(port) + ' "' + command + '"'] s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/lib/oeqa/selftest/cases/updater_qemux86_64.py b/lib/oeqa/selftest/cases/updater_qemux86_64.py index 7228529..033b224 100644 --- a/lib/oeqa/selftest/cases/updater_qemux86_64.py +++ b/lib/oeqa/selftest/cases/updater_qemux86_64.py @@ -2,6 +2,7 @@ import os import logging import re +import subprocess import unittest from time import sleep from uuid import uuid4 @@ -307,8 +308,8 @@ class IpSecondaryTests(OESelftestTestCase): self.configure() qemu_bake_image(self.imagename) - def send_command(self, cmd): - stdout, stderr, retcode = qemu_send_command(self.qemu.ssh_port, cmd, timeout=60) + def send_command(self, cmd, timeout=60): + stdout, stderr, retcode = qemu_send_command(self.qemu.ssh_port, cmd, timeout=timeout) return str(stdout), str(stderr), retcode def __enter__(self): @@ -323,7 +324,7 @@ class IpSecondaryTests(OESelftestTestCase): def wait_till_sshable(self): # qemu_send_command tries to ssh into the qemu VM and blocks until it gets there or timeout happens # so it helps us to block q control flow until the VM is booted and a target binary/daemon is running there - self.stdout, self.stderr, self.retcode = self.send_command(self.binaryname + ' --help') + self.stdout, self.stderr, self.retcode = self.send_command(self.binaryname + ' --help', timeout=300) def was_successfully_booted(self): return self.retcode == 0 @@ -445,10 +446,13 @@ class ResourceControlTests(OESelftestTestCase): ran_ok = False for delay in [5, 5, 5, 5]: sleep(delay) - stdout, stderr, retcode = self.qemu_command('systemctl --no-pager show aktualizr') - if retcode == 0 and b'ExecMainStatus=9' in stdout: - ran_ok = True - break + try: + stdout, stderr, retcode = self.qemu_command('systemctl --no-pager show aktualizr') + if retcode == 0 and b'ExecMainStatus=9' in stdout: + ran_ok = True + break + except subprocess.TimeoutExpired: + pass self.assertTrue(ran_ok, 'Aktualizr was not killed') self.assertIn(b'CPUWeight=1000', stdout, 'CPUWeight was not set correctly') -- cgit v1.2.3-54-g00ecf From b471c16dd39327e8ce5b6174666c28cfbf34dbd4 Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Mon, 15 Jul 2019 15:37:43 +0200 Subject: Use 128M by default for qemu in oe-selftests Signed-off-by: Laurent Bonnans --- lib/oeqa/selftest/cases/testutils.py | 1 + lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py | 3 +-- scripts/qemucommand.py | 9 ++++++--- scripts/run-qemu-ota | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/oeqa/selftest/cases/testutils.py') diff --git a/lib/oeqa/selftest/cases/testutils.py b/lib/oeqa/selftest/cases/testutils.py index 208f822..8d618a6 100644 --- a/lib/oeqa/selftest/cases/testutils.py +++ b/lib/oeqa/selftest/cases/testutils.py @@ -34,6 +34,7 @@ def qemu_boot_image(imagename, **kwargs): args.dir = 'tmp/deploy/images' args.efi = kwargs.get('efi', False) args.machine = kwargs.get('machine', None) + args.mem = kwargs.get('mem', '128M') qemu_use_kvm = get_bb_var("QEMU_USE_KVM") if qemu_use_kvm and \ (qemu_use_kvm == 'True' and 'x86' in args.machine or diff --git a/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py b/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py index 83f5841..fe09371 100644 --- a/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py +++ b/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py @@ -1,5 +1,4 @@ # pylint: disable=C0111,C0325 -import os import re from oeqa.selftest.case import OESelftestTestCase @@ -22,7 +21,7 @@ class PtestTests(OESelftestTestCase): self.append_config('PTEST_ENABLED_pn-aktualizr = "1"') self.append_config('IMAGE_INSTALL_append += "aktualizr-ptest ptest-runner "') self.append_config('IMAGE_FSTYPES_remove = "ostreepush garagesign garagecheck"') - self.qemu, self.s = qemu_launch(machine='qemux86-64') + self.qemu, self.s = qemu_launch(machine='qemux86-64', mem="768M") def tearDownLocal(self): qemu_terminate(self.s) diff --git a/scripts/qemucommand.py b/scripts/qemucommand.py index 532e331..8b7da2b 100644 --- a/scripts/qemucommand.py +++ b/scripts/qemucommand.py @@ -2,7 +2,7 @@ from os.path import exists, join, realpath, abspath from os import listdir import random import socket -from subprocess import check_output, CalledProcessError +from subprocess import check_output EXTENSIONS = { 'intel-corei7-64': 'wic', @@ -68,6 +68,10 @@ class QemuCommand(object): self.mac_address = random_mac() self.serial_port = find_local_port(8990) self.ssh_port = find_local_port(2222) + if args.mem: + self.mem = args.mem + else: + self.mem = "1G" if args.kvm is None: # Autodetect KVM using 'kvm-ok' try: @@ -95,7 +99,7 @@ class QemuCommand(object): cmdline += ["-drive", "file=%s,if=ide,format=raw,snapshot=on" % self.image] cmdline += [ "-serial", "tcp:127.0.0.1:%d,server,nowait" % self.serial_port, - "-m", "1G", + "-m", self.mem, "-usb", "-object", "rng-random,id=rng0,filename=/dev/urandom", "-device", "virtio-rng-pci,rng=rng0", @@ -131,4 +135,3 @@ class QemuCommand(object): "-f", "qcow2", self.overlay] return cmdline - diff --git a/scripts/run-qemu-ota b/scripts/run-qemu-ota index b2f55e9..de63297 100755 --- a/scripts/run-qemu-ota +++ b/scripts/run-qemu-ota @@ -26,6 +26,7 @@ def main(): dest='kvm', action='store_true', default=None) kvm_group.add_argument('--no-kvm', help='Disable KVM in QEMU', dest='kvm', action='store_false') + parser.add_argument('--mem', default=None, help="Amount of memory the machine boots with") parser.add_argument('--no-gui', help='Disable GUI', action='store_true') parser.add_argument('--gdb', help='Export gdbserver port 2159 from the image', action='store_true') parser.add_argument('--pcap', default=None, help='Dump all network traffic') -- cgit v1.2.3-54-g00ecf