From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH v5 07/15] vm_boot_test: Improve QEMU images checking
Date: Thu, 29 Apr 2021 16:52:38 +0300 [thread overview]
Message-ID: <20210429135246.78792-8-amikan@ilbers.de> (raw)
In-Reply-To: <20210429135246.78792-1-amikan@ilbers.de>
Makes QEMU start test to analyze boot log in real-time. It helps test
cases to finish as soon as booting succeeds and do not wasting time on
waiting.
Get rid of python-subprocess32 backport package.
Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
testsuite/vm_boot_test/vm_boot_test.py | 53 ++++++++++++++++++++------
1 file changed, 42 insertions(+), 11 deletions(-)
diff --git a/testsuite/vm_boot_test/vm_boot_test.py b/testsuite/vm_boot_test/vm_boot_test.py
index eee14b2..6e580d0 100644
--- a/testsuite/vm_boot_test/vm_boot_test.py
+++ b/testsuite/vm_boot_test/vm_boot_test.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
import os
-import subprocess32
+import select
+import subprocess
import sys
import time
import tempfile
@@ -13,6 +14,9 @@ import start_vm
from avocado import Test
+class CanBeFinished(Exception):
+ pass
+
class VmBase(Test):
def vm_start(self, arch='amd64', distro='buster'):
@@ -34,18 +38,45 @@ class VmBase(Test):
self.log.info('QEMU boot line: ' + str(cmdline))
- devnull = open(os.devnull, 'w')
-
- p1 = subprocess32.Popen(cmdline, stdout=devnull, stderr=devnull)
- time.sleep(int(time_to_wait))
- p1.kill()
- p1.wait()
+ 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):
- if 'isar login:' in open(output_file).read():
- return
-
- self.fail('Test failed')
+ 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):
--
2.25.1
next prev parent reply other threads:[~2021-04-29 13:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-29 13:52 [PATCH v5 00/15] Update Avocado testsuite Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 01/15] start_vm.py: Fix target name handling Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 02/15] start_vm.py: Add output and PID file vm_start.py options Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 03/15] start_vm.py: Add MIPS support Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 04/15] start_vm.py: Fix ubuntu image name Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 05/15] vm_boot_test: Fix log file path in vm_boot_test Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 06/15] vm_boot_test: Remove external varianter Anton Mikanovich
2021-04-29 13:52 ` Anton Mikanovich [this message]
2021-04-29 13:52 ` [PATCH v5 08/15] build_test: Refactoring build tests cases Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 09/15] testsuite: Add Python generations for testsuite in gitignore Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 10/15] testsuite: Fix test suite prepare guide Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 11/15] gitlab-ci: Add Avocado build artifacts Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 12/15] vm_boot_test: Add automatic bitbake init Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 13/15] ci_build: Migrate to Avocado Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 14/15] vm_smoke_test: " Anton Mikanovich
2021-04-29 13:52 ` [PATCH v5 15/15] ci_build: Install Avocado if needed 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=20210429135246.78792-8-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