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 3 // found in the LICENSE file. 4 5 package org.chromium.base.test.util; 6 7 /** 8 * Utility class for scaling various timeouts by a common factor. 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" 11 */ 12 public class ScalableTimeout { 13 private static Double sTimeoutScale = null; 14 private static final String PROPERTY_FILE = "/data/local/tmp/chrome_timeout_scale"; 15 ScaleTimeout(long timeout)16 public static long ScaleTimeout(long timeout) { 17 if (sTimeoutScale == null) { 18 try { 19 char[] data = TestFileUtil.readUtf8File(PROPERTY_FILE, 32); 20 sTimeoutScale = Double.parseDouble(new String(data)); 21 } catch (Exception e) { 22 // NumberFormatException, FileNotFoundException, IOException 23 sTimeoutScale = 1.0; 24 } 25 } 26 return (long)(timeout * sTimeoutScale); 27 } 28 } 29