qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 22/25] iotests: Add _timeout function


From: Max Reitz
Subject: [Qemu-devel] [PATCH 22/25] iotests: Add _timeout function
Date: Wed, 25 Feb 2015 13:08:35 -0500

Add a function for executing a command with a timeout.

Signed-off-by: Max Reitz <address@hidden>
---
 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
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]