From patchwork Wed Feb 25 18:08:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 443592 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 7405B140083 for ; Thu, 26 Feb 2015 05:19:24 +1100 (AEDT) Received: from localhost ([::1]:55796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQgYM-0006Bi-Ic for incoming@patchwork.ozlabs.org; Wed, 25 Feb 2015 13:19:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQgOV-00031U-5G for qemu-devel@nongnu.org; Wed, 25 Feb 2015 13:09:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQgOQ-0001lY-49 for qemu-devel@nongnu.org; Wed, 25 Feb 2015 13:09:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42226) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQgOO-0001kA-00; Wed, 25 Feb 2015 13:09:04 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1PI92q5021553 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 25 Feb 2015 13:09:03 -0500 Received: from localhost (dhcp-17-71.bos.redhat.com [10.18.17.71]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1PI91xc025970 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Wed, 25 Feb 2015 13:09:02 -0500 From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 25 Feb 2015 13:08:35 -0500 Message-Id: <1424887718-10800-23-git-send-email-mreitz@redhat.com> In-Reply-To: <1424887718-10800-1-git-send-email-mreitz@redhat.com> References: <1424887718-10800-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Paolo Bonzini , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH 22/25] iotests: Add _timeout function 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 Add a function for executing a command with a timeout. Signed-off-by: Max Reitz --- tests/qemu-iotests/common.rc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 22d3514..bd8453a 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -489,5 +489,21 @@ _die() exit 1 } +_timeout() +{ + local timeout=1 + local pid + + if [ "$1" = "-t" ]; then + shift + timeout=$1 + shift + fi + "$@" & + pid=$! + (sleep $timeout; kill -9 $pid &> /dev/null) & + wait -n $pid $! +} + # make sure this script returns success true