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 import org.chromium.base.annotations.SuppressFBWarnings; | 7 import org.chromium.base.annotations.SuppressFBWarnings; |
8 | 8 |
9 /** | 9 /** |
10 * Utility class for scaling various timeouts by a common factor. | 10 * Utility class for scaling various timeouts by a common factor. |
11 * For example, to run tests under Valgrind, you might want the following: | 11 * For example, to run tests under Valgrind, you might want the following: |
12 * adb shell "echo 20.0 > /data/local/tmp/chrome_timeout_scale" | 12 * adb shell "echo 20.0 > /data/local/tmp/chrome_timeout_scale" |
13 */ | 13 */ |
14 public class ScalableTimeout { | 14 public class ScalableTimeout { |
15 private static Double sTimeoutScale = null; | 15 private static Double sTimeoutScale; |
16 public static final String PROPERTY_FILE = "/data/local/tmp/chrome_timeout_s
cale"; | 16 public static final String PROPERTY_FILE = "/data/local/tmp/chrome_timeout_s
cale"; |
17 | 17 |
18 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") | 18 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") |
19 public static long scaleTimeout(long timeout) { | 19 public static long scaleTimeout(long timeout) { |
20 if (sTimeoutScale == null) { | 20 if (sTimeoutScale == null) { |
21 try { | 21 try { |
22 char[] data = TestFileUtil.readUtf8File(PROPERTY_FILE, 32); | 22 char[] data = TestFileUtil.readUtf8File(PROPERTY_FILE, 32); |
23 sTimeoutScale = Double.parseDouble(new String(data)); | 23 sTimeoutScale = Double.parseDouble(new String(data)); |
24 } catch (Exception e) { | 24 } catch (Exception e) { |
25 // NumberFormatException, FileNotFoundException, IOException | 25 // NumberFormatException, FileNotFoundException, IOException |
26 sTimeoutScale = 1.0; | 26 sTimeoutScale = 1.0; |
27 } | 27 } |
28 } | 28 } |
29 return (long) (timeout * sTimeoutScale); | 29 return (long) (timeout * sTimeoutScale); |
30 } | 30 } |
31 } | 31 } |
OLD | NEW |