From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6940636076695355392 X-Received: by 2002:a19:ca54:: with SMTP id h20mr2655932lfj.292.1615992791339; Wed, 17 Mar 2021 07:53:11 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a2e:3c10:: with SMTP id j16ls5002304lja.2.gmail; Wed, 17 Mar 2021 07:53:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGXDikZ0dnFn03lK3qludFprbtdLrKHOCQHpXDt7koH+rlHDqZyMFSgM9fancdQABk2FqU X-Received: by 2002:a2e:535a:: with SMTP id t26mr2588209ljd.503.1615992790361; Wed, 17 Mar 2021 07:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615992790; cv=none; d=google.com; s=arc-20160816; b=wp18CEtnme7TzXcLxGMoErGUYVmXe+VywVYpZavTcCFeZOjiYlBAJm9JLf5Y8m+Zyf YQycoO7Wze7+4m+oKJ1WUhl1zSUbJcLk8HPNNiUWIg2J4PIAVkF6oV8134AsJq2NkzeJ vVKW5IfS25TkLh/LgyK2a2Exu1Cptf3lcfGmFZ2w841mi3KVMSug3igsYeK9siMpPs2j Cjt/2nef8P7XEFykm4Q3X+eQbKGjl8XTG4nAB2Y7BZtB9yDoxMFQoRKbAqD90A9BjnAJ Gv4+9cmvAxPDK+iVyLAUjZdVN1dz952v33TnqYZQF33w+2d+JvNYHRpcgBP8MfFj1SGV ChtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=LXRRmcqEnJdbRNYQLvtzOJfpgkerR/2bma68XPh5iPc=; b=cBsJs8S02F5vSFRix7SUrgp1ZqSjX0I3sJga/ZRnwB+SOxruvfoH0rJzW4GkGAUJMd I9q02mBY9VgARP5KUhl4UvpWFQq61k+qGzWXDgdYNwzHUbZqN0z3fQ4tLY9v77yIYzkp USWX1EHTMyr1/Fuq7xoQMtmT+/snAiOVGY1UfhD7Hc92qOs93xYErnIJ+H3E+GpjoGEe USnMUfbksvAw1KbPoRkDGwGHmTCnMLHRrBdUQx+jIMVBYzaW8QyrrysQkwkbBTq38fJS r6hrMtGm63I+jTgGAm+AEHYDBWpKUa3i8xvLMOIODgBz9VQMHlar9re4MmS3Oby37cjQ Lstw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of amikan@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=amikan@ilbers.de Return-Path: Received: from shymkent.ilbers.de (shymkent.ilbers.de. [85.214.156.166]) by gmr-mx.google.com with ESMTPS id a10si929428lfs.11.2021.03.17.07.53.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Mar 2021 07:53:10 -0700 (PDT) Received-SPF: pass (google.com: domain of amikan@ilbers.de designates 85.214.156.166 as permitted sender) client-ip=85.214.156.166; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of amikan@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=amikan@ilbers.de Received: from localhost.localdomain (mm-117-75-121-178.mgts.dynamic.pppoe.byfly.by [178.121.75.117] (may be forged)) (authenticated bits=0) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8) with ESMTPSA id 12HEqhaF032071 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Mar 2021 15:53:09 +0100 From: Anton Mikanovich To: isar-users@googlegroups.com Cc: Anton Mikanovich Subject: [PATCH v3 06/11] vm_boot_test: Improve QEMU images checking Date: Wed, 17 Mar 2021 17:52:20 +0300 Message-Id: <20210317145225.88050-7-amikan@ilbers.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210317145225.88050-1-amikan@ilbers.de> References: <20210317145225.88050-1-amikan@ilbers.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-TUID: 1TtTtUSHNpDt 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 --- testsuite/vm_boot_test/vm_boot_test.py | 59 ++++++++++++++++++++------ 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/testsuite/vm_boot_test/vm_boot_test.py b/testsuite/vm_boot_test/vm_boot_test.py index 73fee3e..4c1b6fe 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'): @@ -31,23 +35,54 @@ class VmBase(Test): cmdline = start_vm.format_qemu_cmdline(arch, build_dir, distro, None, None) cmdline.insert(1, '-nographic') + cmdline.append('-chardev') + cmdline.append('stdio,id=ch0,logfile=' + output_file) cmdline.append('-serial') - cmdline.append('file:' + output_file) + cmdline.append('chardev:ch0') + cmdline.append('-monitor') + cmdline.append('none') 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