Received: from eggs.gnu.org ([2001:4830:134:3::10]:47648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKqCN-0000wK-9R for qemu-devel@nongnu.org; Fri, 22 Aug 2014 10:52:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKqCF-0005cA-Qu for qemu-devel@nongnu.org; Fri, 22 Aug 2014 10:52:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59681) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKqCF-0005c5-Hl for qemu-devel@nongnu.org; Fri, 22 Aug 2014 10:52:07 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7MEq61G010693 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 22 Aug 2014 10:52:07 -0400 From: Kevin Wolf Date: Fri, 22 Aug 2014 16:51:30 +0200 Message-Id: <1408719113-5316-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1408719113-5316-1-git-send-email-kwolf@redhat.com> References: <1408719113-5316-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 06/29] runner: Kill a program under test by time-out List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Maria Kustova 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 Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- 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 1e38b95..c903c8a 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): -- 1.8.3.1