Propagate timeout to run-test-jar.

Bug: 141485154
Test: art/test/run-test --chroot /data/local/art-test-chroot --jit --64 --timeout 5 151-OpenFileLimit (timeout failure)
Test: art/test/run-test --chroot /data/local/art-test-chroot --jit --64 151-OpenFileLimit (success)
Change-Id: I741e2ae485e4f5769d6e0dfa44f4986d901d7d3b
diff --git a/test/run-test b/test/run-test
index 2214d6c..eeeefbb 100755
--- a/test/run-test
+++ b/test/run-test
@@ -160,6 +160,7 @@
 have_image="yes"
 android_root="/system"
 bisection_search="no"
+timeout=""
 suspend_timeout="500000"
 image_suffix=""
 run_optimizing="false"
@@ -321,7 +322,8 @@
         shift
     elif [ "x$1" = "x--strace" ]; then
         strace="yes"
-        run_args+=(--timeout 1800 --invoke-with strace --invoke-with -o --invoke-with "$tmp_dir/$strace_output")
+        run_args+=(--invoke-with strace --invoke-with -o --invoke-with "$tmp_dir/$strace_output")
+        timeout="${timeout:-1800}"
         shift
     elif [ "x$1" = "x--zygote" ]; then
         run_args+=(--zygote)
@@ -456,6 +458,15 @@
         # extract it. 512mb should be good enough.
         file_ulimit=512000
         shift
+    elif [ "x$1" = "x--timeout" ]; then
+        shift
+        if [ "x$1" = "x" ]; then
+            echo "$0 missing argument to --timeout" 1>&2
+            usage="yes"
+            break
+        fi
+        timeout="$1"
+        shift
     elif [ "x$1" = "x--trace" ]; then
         trace="true"
         shift
@@ -592,6 +603,9 @@
     err_echo "Cannot use --stream without --trace."
     exit 1
 fi
+if [ -n "$timeout" ]; then
+    run_args+=(--timeout "$timeout")
+fi
 
 # Most interesting target architecture variables are Makefile variables, not environment variables.
 # Try to map the suffix64 flag and what we find in ${ANDROID_PRODUCT_OUT}/data/art-test to an architecture name.
@@ -797,6 +811,7 @@
         echo "    --runtime-extracted-zipapex [dir]"
         echo "                          Use the given extracted zipapex directory to provide"
         echo "                          runtime binaries"
+        echo "    --timeout n           Test timeout in seconds"
         echo "    --trace               Run with method tracing"
         echo "    --strace              Run with syscall tracing from strace."
         echo "    --stream              Run method tracing in streaming mode (requires --trace)"
@@ -1092,7 +1107,7 @@
         --check-script="$cwd/check" \
         --expected-output="$cwd/expected.txt" \
         --logfile="$cwd/bisection_log.txt" \
-        --timeout=300
+        --timeout=${timeout:-300}
     fi
 fi