From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH 2/6] CI: Migrate all tests to one location
Date: Tue, 22 Feb 2022 10:12:55 +0300 [thread overview]
Message-ID: <20220222071259.157349-3-amikan@ilbers.de> (raw)
In-Reply-To: <20220222071259.157349-1-amikan@ilbers.de>
Move QEMU start tests to the same class as build tests to be able to
run everything from the single avocado command.
Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
scripts/vm_smoke_test | 2 +-
testsuite/build_test.py | 46 +++++++++++++
testsuite/cibuilder.py | 68 ++++++++++++++++++++
testsuite/vm_boot_test.py | 132 --------------------------------------
4 files changed, 115 insertions(+), 133 deletions(-)
delete mode 100755 testsuite/vm_boot_test.py
diff --git a/scripts/vm_smoke_test b/scripts/vm_smoke_test
index 50051a7..28c959a 100755
--- a/scripts/vm_smoke_test
+++ b/scripts/vm_smoke_test
@@ -95,7 +95,7 @@ logs_dir = $BUILD_DIR/job-results
EOF
export VIRTUAL_ENV="./"
-if avocado $VERBOSE run "$TESTSUITE_DIR/vm_boot_test.py" -t $TAGS \
+if avocado $VERBOSE run "$TESTSUITE_DIR/build_test.py" -t $TAGS,startvm \
--test-runner=runner --disable-sysinfo \
-p build_dir="$BUILD_DIR" -p time_to_wait=$TIMEOUT; then
RET=$ES_OK
diff --git a/testsuite/build_test.py b/testsuite/build_test.py
index 988ae2f..2818a2d 100755
--- a/testsuite/build_test.py
+++ b/testsuite/build_test.py
@@ -244,3 +244,49 @@ class SstateTest(CIBaseTest):
self.init('build-sstate')
self.perform_sstate_test(image_target, package_target)
+
+class VmBootTestFast(CIBaseTest):
+
+ """
+ Test QEMU image start (fast)
+
+ :avocado: tags=startvm,fast,full
+ """
+ def test_arm_bullseye(self):
+ self.init()
+ self.vm_start('arm','bullseye')
+
+ def test_arm_buster(self):
+ self.init()
+ self.vm_start('arm','buster')
+
+ def test_arm64_bullseye(self):
+ self.init()
+ self.vm_start('arm64','bullseye')
+
+ def test_amd64_bullseye(self):
+ self.init()
+ self.vm_start('amd64','bullseye')
+
+class VmBootTestFull(CIBaseTest):
+
+ """
+ Test QEMU image start (full)
+
+ :avocado: tags=startvm,full
+ """
+ def test_i386_stretch(self):
+ self.init()
+ self.vm_start('i386','stretch')
+
+ def test_i386_buster(self):
+ self.init()
+ self.vm_start('i386','buster')
+
+ def test_amd64_buster(self):
+ self.init()
+ self.vm_start('amd64','buster')
+
+ def test_amd64_focal(self):
+ self.init()
+ self.vm_start('amd64','focal')
diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py
index f0c4bc3..2170ea6 100755
--- a/testsuite/cibuilder.py
+++ b/testsuite/cibuilder.py
@@ -5,6 +5,10 @@ import os
import select
import shutil
import subprocess
+import time
+import tempfile
+
+import start_vm
from avocado import Test
from avocado.utils import path
@@ -15,6 +19,9 @@ backup_prefix = '.ci-backup'
app_log = logging.getLogger("avocado.app")
+class CanBeFinished(Exception):
+ pass
+
class CIBuilder(Test):
def setUp(self):
super(CIBuilder, self).setUp()
@@ -181,3 +188,64 @@ class CIBuilder(Test):
for x in output.splitlines() if x != ''))
return env['LAYERDIR_' + layer].strip('"')
+
+ def vm_start(self, arch='amd64', distro='buster'):
+ time_to_wait = self.params.get('time_to_wait', default=60)
+
+ self.log.info('===================================================')
+ self.log.info('Running Isar VM boot test for (' + distro + '-' + arch + ')')
+ self.log.info('Isar build folder is: ' + self.build_dir)
+ self.log.info('===================================================')
+
+ self.check_init()
+
+ fd, output_file = tempfile.mkstemp(suffix='_log.txt',
+ prefix='vm_start_' + distro + '_' +
+ arch + '_', dir=self.build_dir, text=True)
+ os.chmod(output_file, 0o644)
+
+ cmdline = start_vm.format_qemu_cmdline(arch, self.build_dir, distro,
+ output_file, None)
+ cmdline.insert(1, '-nographic')
+
+ self.log.info('QEMU boot line: ' + str(cmdline))
+
+ login_prompt = b'isar login:'
+ service_prompt = b'Just an example'
+
+ timeout = time.time() + int(time_to_wait)
+
+ p1 = subprocess.Popen(cmdline, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ try:
+ poller = select.poll()
+ poller.register(p1.stdout, select.POLLIN)
+ poller.register(p1.stderr, select.POLLIN)
+ while time.time() < timeout and p1.poll() is None:
+ events = poller.poll(1000 * (timeout - time.time()))
+ for fd, event in events:
+ if fd == p1.stdout.fileno():
+ # Wait for the complete string if it is read in chunks
+ # like "i", "sar", " login:"
+ time.sleep(0.01)
+ data = os.read(fd, 1024)
+ if login_prompt in data:
+ raise CanBeFinished
+ if fd == p1.stderr.fileno():
+ self.log.error(p1.stderr.readline())
+ except CanBeFinished:
+ self.log.debug('Got login prompt')
+ finally:
+ if p1.poll() is None:
+ p1.kill()
+ p1.wait()
+
+ if os.path.exists(output_file):
+ with open(output_file, "rb") as f1:
+ data = f1.read()
+ if service_prompt in data and login_prompt in data:
+ return
+ else:
+ self.log.error(data)
+
+ self.fail('Log ' + output_file)
diff --git a/testsuite/vm_boot_test.py b/testsuite/vm_boot_test.py
deleted file mode 100755
index 6c4e979..0000000
--- a/testsuite/vm_boot_test.py
+++ /dev/null
@@ -1,132 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import select
-import subprocess
-import sys
-import time
-import tempfile
-
-from os.path import dirname
-
-import start_vm
-
-from avocado import Test
-from avocado.utils import process
-from avocado.utils import path
-
-class CanBeFinished(Exception):
- pass
-
-class VmBase(Test):
-
- def check_bitbake(self, build_dir):
- try:
- path.find_command('bitbake')
- except path.CmdNotFoundError:
- out = process.getoutput('/bin/bash -c "cd ../.. && \
- source isar-init-build-env \
- %s 2>&1 >/dev/null; env"' % build_dir)
- env = dict(((x.split('=', 1) + [''])[:2] \
- for x in output.splitlines() if x != ''))
- os.environ.update(env)
-
- def vm_start(self, arch='amd64', distro='buster'):
- build_dir = self.params.get('build_dir', default='.')
- time_to_wait = self.params.get('time_to_wait', default=60)
-
- self.log.info('===================================================')
- self.log.info('Running Isar VM boot test for (' + distro + '-' + arch + ')')
- self.log.info('Isar build folder is: ' + build_dir)
- self.log.info('===================================================')
-
- self.check_bitbake(build_dir)
-
- fd, output_file = tempfile.mkstemp(suffix='_log.txt',
- prefix='vm_start_' + distro + '_' +
- arch + '_', dir=build_dir, text=True)
- os.chmod(output_file, 0o644)
-
- cmdline = start_vm.format_qemu_cmdline(arch, build_dir, distro,
- output_file, None)
- cmdline.insert(1, '-nographic')
-
- self.log.info('QEMU boot line: ' + str(cmdline))
-
- login_prompt = b'isar login:'
- service_prompt = b'Just an example'
-
- timeout = time.time() + int(time_to_wait)
-
- p1 = subprocess.Popen(cmdline, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- try:
- poller = select.poll()
- poller.register(p1.stdout, select.POLLIN)
- poller.register(p1.stderr, select.POLLIN)
- while time.time() < timeout and p1.poll() is None:
- events = poller.poll(1000 * (timeout - time.time()))
- for fd, event in events:
- if fd == p1.stdout.fileno():
- # Wait for the complete string if it is read in chunks
- # like "i", "sar", " login:"
- time.sleep(0.01)
- data = os.read(fd, 1024)
- if login_prompt in data:
- raise CanBeFinished
- if fd == p1.stderr.fileno():
- self.log.error(p1.stderr.readline())
- except CanBeFinished:
- self.log.debug('Got login prompt')
- finally:
- if p1.poll() is None:
- p1.kill()
- p1.wait()
-
- if os.path.exists(output_file):
- with open(output_file, "rb") as f1:
- data = f1.read()
- if service_prompt in data and login_prompt in data:
- return
- else:
- self.log.error(data)
-
- self.fail('Log ' + output_file)
-
-class VmBootTestFast(VmBase):
-
- """
- Test QEMU image start (fast)
-
- :avocado: tags=fast,full
- """
- def test_arm_bullseye(self):
- self.vm_start('arm','bullseye')
-
- def test_arm_buster(self):
- self.vm_start('arm','buster')
-
- def test_arm64_bullseye(self):
- self.vm_start('arm64','bullseye')
-
- def test_amd64_bullseye(self):
- self.vm_start('amd64','bullseye')
-
-class VmBootTestFull(VmBase):
-
- """
- Test QEMU image start (full)
-
- :avocado: tags=full
- """
- def test_i386_stretch(self):
- self.vm_start('i386','stretch')
-
- def test_i386_buster(self):
- self.vm_start('i386','buster')
-
- def test_amd64_buster(self):
- self.vm_start('amd64','buster')
-
- def test_amd64_focal(self):
- self.vm_start('amd64','focal')
--
2.25.1
next prev parent reply other threads:[~2022-02-22 7:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 7:12 [PATCH 0/6] Unify build and run test cases Anton Mikanovich
2022-02-22 7:12 ` [PATCH 1/6] CI: Reorganize testsuite folders Anton Mikanovich
2022-02-22 7:12 ` Anton Mikanovich [this message]
2022-02-22 7:12 ` [PATCH 3/6] CI: Adopt vm_start test logging Anton Mikanovich
2022-02-22 7:12 ` [PATCH 4/6] CI: Do not run QEMU start tests from Gitlab Anton Mikanovich
2022-02-22 7:12 ` [PATCH 5/6] CI: Rename build_test.py to citest.py Anton Mikanovich
2022-02-22 7:12 ` [PATCH 6/6] CI: Change QEMU boot logs format Anton Mikanovich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220222071259.157349-3-amikan@ilbers.de \
--to=amikan@ilbers.de \
--cc=isar-users@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox