From patchwork Mon Aug 18 20:02:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maria Kustova X-Patchwork-Id: 381117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9FC1B14008F for ; Tue, 19 Aug 2014 06:03:52 +1000 (EST) Received: from localhost ([::1]:45465 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJT9i-0008Mx-Iu for incoming@patchwork.ozlabs.org; Mon, 18 Aug 2014 16:03:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJT8s-0006w7-5Z for qemu-devel@nongnu.org; Mon, 18 Aug 2014 16:03:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJT8h-00040V-Si for qemu-devel@nongnu.org; Mon, 18 Aug 2014 16:02:58 -0400 Received: from mail-la0-f50.google.com ([209.85.215.50]:46214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJT8h-0003zX-MI for qemu-devel@nongnu.org; Mon, 18 Aug 2014 16:02:47 -0400 Received: by mail-la0-f50.google.com with SMTP id pi18so5015013lab.23 for ; Mon, 18 Aug 2014 13:02:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=vs2PrLc+pyi6nFjmhMY7lwP/oh3L3buqhgFGDJt+Wvw=; b=IFnjl2m4KHicmZL1g6vHfA5egteipVfREWoqaCaJLpbXX2cJuXQoaDhnvFLqP/BZjm BGf+G3eG6iiOcUh+RzSFmXKDNgvYrrSJKMeW5vBMxwfNCS2mLRoebWEqXqebI8Ogm1QE Oj50wG3sS1cjSbp9+vnvJlQAXkaQTEBeBzBEDfj1Ncf2Xyvgm2Ozaudxb/dJcfDRNWrb Te7Jv9ui9auYqrYSpMxmOPHND/SzamshebNXyJXIVbPoac0eNLXmN9U54YlqgdzYrWMu 48BeI+NCh2aGwVJQGc+E4KylvKbNALXMQKxSK6hxiUg+C2rE9yBJfB+GdkOW2ogpn04M AYug== X-Gm-Message-State: ALoCoQmyz3r/gf4YGUq/w1/Vk+c4ezY2CXTeED3ITh2dEfjufjug+lLJUqDCM5YPzxxU0YEBt2/0 X-Received: by 10.152.8.82 with SMTP id p18mr8475521laa.83.1408392166812; Mon, 18 Aug 2014 13:02:46 -0700 (PDT) Received: from localhost.localdomain ([31.134.130.233]) by mx.google.com with ESMTPSA id as3sm28591610lbc.7.2014.08.18.13.02.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Aug 2014 13:02:46 -0700 (PDT) From: Maria Kustova X-Google-Original-From: Maria Kustova To: qemu-devel@nongnu.org Date: Tue, 19 Aug 2014 00:02:35 +0400 Message-Id: X-Mailer: git-send-email 1.9.3 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.215.50 Cc: kwolf@redhat.com, famz@redhat.com, Maria Kustova , stefanha@redhat.com Subject: [Qemu-devel] [PATCH V2 2/2] runner: Kill a program under test by time-out X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If a program under test get frozen, the test should finish and report about its failure. In such cases the runner waits for 10 minutes until the program ends its execution. After this time-out the program will be terminated and the test will be marked as failed. For current limitation of test image size to 10 MB as a maximum an execution of each command takes about several seconds in general, so 10 minutes is enough to discriminate freeze, but not drastically increase an overall test duration. Signed-off-by: Maria Kustova --- tests/image-fuzzer/runner.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py index ea9916b..2e1bd51 100755 --- a/tests/image-fuzzer/runner.py +++ b/tests/image-fuzzer/runner.py @@ -65,14 +65,35 @@ def run_app(fd, q_args): """Start an application with specified arguments and return its exit code or kill signal depending on the result of execution. """ + + class Alarm(Exception): + """Exception for signal.alarm events.""" + pass + + def handler(*arg): + """Notify that an alarm event occurred.""" + raise Alarm + + signal.signal(signal.SIGALRM, handler) + signal.alarm(600) + term_signal = signal.SIGKILL devnull = open('/dev/null', 'r+') process = subprocess.Popen(q_args, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = process.communicate() - fd.write(out) - fd.write(err) - return process.returncode + try: + out, err = process.communicate() + signal.alarm(0) + fd.write(out) + fd.write(err) + fd.flush() + return process.returncode + + except Alarm: + os.kill(process.pid, term_signal) + fd.write('The command was terminated by timeout.\n') + fd.flush() + return -term_signal class TestException(Exception):