OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.base.test.util; | 5 package org.chromium.base.test.util; |
6 | 6 |
7 /** | 7 /** |
8 * Utility class for scaling various timeouts by a common factor. | 8 * Utility class for scaling various timeouts by a common factor. |
9 * For example, to run tests under Valgrind, you might want the following: | 9 * For example, to run tests under Valgrind, you might want the following: |
10 * adb shell "echo 20.0 > /data/local/tmp/chrome_timeout_scale" | 10 * adb shell "echo 20.0 > /data/local/tmp/chrome_timeout_scale" |
11 */ | 11 */ |
12 public class ScalableTimeout { | 12 public class ScalableTimeout { |
13 private static Double sTimeoutScale = null; | 13 private static Double sTimeoutScale = null; |
14 private static final String PROPERTY_FILE = "/data/local/tmp/chrome_timeout_
scale"; | 14 private static final String PROPERTY_FILE = "/data/local/tmp/chrome_timeout_
scale"; |
15 | 15 |
16 public static long scaleTimeout(long timeout) { | 16 public static long scaleTimeout(long timeout) { |
17 if (sTimeoutScale == null) { | 17 if (sTimeoutScale == null) { |
18 try { | 18 try { |
19 char[] data = TestFileUtil.readUtf8File(PROPERTY_FILE, 32); | 19 char[] data = TestFileUtil.readUtf8File(PROPERTY_FILE, 32); |
20 sTimeoutScale = Double.parseDouble(new String(data)); | 20 sTimeoutScale = Double.parseDouble(new String(data)); |
21 } catch (Exception e) { | 21 } catch (Exception e) { |
22 // NumberFormatException, FileNotFoundException, IOException | 22 // NumberFormatException, FileNotFoundException, IOException |
23 sTimeoutScale = 1.0; | 23 sTimeoutScale = 1.0; |
24 } | 24 } |
25 } | 25 } |
26 return (long)(timeout * sTimeoutScale); | 26 return (long) (timeout * sTimeoutScale); |
27 } | 27 } |
28 } | 28 } |
OLD | NEW |