summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 23:27:06 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 23:27:06 +0000
commit9fbef9205e7e9b9daf4cfbd90b8da1906af1ebcb (patch)
tree00a4cc82e79cd3e285b0e5e07845aff304ecd10a
parentf8f5593b34f0cf7563186381124172a336eebf99 (diff)
downloadchromium_src-9fbef9205e7e9b9daf4cfbd90b8da1906af1ebcb.zip
chromium_src-9fbef9205e7e9b9daf4cfbd90b8da1906af1ebcb.tar.gz
chromium_src-9fbef9205e7e9b9daf4cfbd90b8da1906af1ebcb.tar.bz2
Android: upstream instrumentation test components.
In preparation for upstreaming the instrumentation tests, we need these components first. BUG=136687 TEST= Review URL: https://chromiumcodereview.appspot.com/10796031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147989 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/android/javatests/src/org/chromium/base/test/Feature.java29
-rw-r--r--base/android/javatests/src/org/chromium/base/test/ScalableTimeout.java28
-rw-r--r--base/android/javatests/src/org/chromium/base/test/TestFileUtil.java46
3 files changed, 103 insertions, 0 deletions
diff --git a/base/android/javatests/src/org/chromium/base/test/Feature.java b/base/android/javatests/src/org/chromium/base/test/Feature.java
new file mode 100644
index 0000000..76fba41
--- /dev/null
+++ b/base/android/javatests/src/org/chromium/base/test/Feature.java
@@ -0,0 +1,29 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.base.test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The java instrumentation tests are normally fairly large (in terms of
+ * dependencies), and the test suite ends up containing a large amount of
+ * tests that are not trivial to filter / group just by their names.
+ * Instead, we use this annotation: each test should be annotated as:
+ * @Feature({"Foo", "Bar"})
+ * in order for the test runner scripts to be able to filter and group
+ * them accordingly (for instance, this enable us to run all tests that exercise
+ * feature Foo).
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Feature {
+ /**
+ * @return A list of feature names.
+ */
+ public String[] value();
+}
diff --git a/base/android/javatests/src/org/chromium/base/test/ScalableTimeout.java b/base/android/javatests/src/org/chromium/base/test/ScalableTimeout.java
new file mode 100644
index 0000000..d502aaa
--- /dev/null
+++ b/base/android/javatests/src/org/chromium/base/test/ScalableTimeout.java
@@ -0,0 +1,28 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.base.test;
+
+/**
+ * Utility class for scaling various timeouts by a common factor.
+ * For example, to run tests under Valgrind, you might want the following:
+ * adb shell "echo 20.0 > /data/local/tmp/chrome_timeout_scale"
+ */
+public class ScalableTimeout {
+ private static Double sTimeoutScale = null;
+ private static final String PROPERTY_FILE = "/data/local/tmp/chrome_timeout_scale";
+
+ public static long ScaleTimeout(long timeout) {
+ if (sTimeoutScale == null) {
+ try {
+ char[] data = TestFileUtil.readUtf8File(PROPERTY_FILE, 32);
+ sTimeoutScale = Double.parseDouble(new String(data));
+ } catch (Exception e) {
+ // NumberFormatException, FileNotFoundException, IOException
+ sTimeoutScale = 1.0;
+ }
+ }
+ return (long)(timeout * sTimeoutScale);
+ }
+}
diff --git a/base/android/javatests/src/org/chromium/base/test/TestFileUtil.java b/base/android/javatests/src/org/chromium/base/test/TestFileUtil.java
new file mode 100644
index 0000000..66ff085
--- /dev/null
+++ b/base/android/javatests/src/org/chromium/base/test/TestFileUtil.java
@@ -0,0 +1,46 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.base.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Arrays;
+
+/**
+ * Utility class for dealing with files for test.
+ */
+public class TestFileUtil {
+ /**
+ * @param fileName the file to read in.
+ * @param sizeLimit cap on the file size: will throw an exception if exceeded
+ * @return Array of chars read from the file
+ * @throws FileNotFoundException file does not exceed
+ * @throws IOException error encountered accessing the file
+ */
+ public static char[] readUtf8File(String fileName, int sizeLimit) throws
+ FileNotFoundException, IOException {
+ Reader reader = null;
+ try {
+ File f = new File(fileName);
+ if (f.length() > sizeLimit) {
+ throw new IOException("File " + fileName + " length " + f.length() +
+ " exceeds limit " + sizeLimit);
+ }
+ char[] buffer = new char[(int) f.length()];
+ reader = new InputStreamReader(new FileInputStream(f), "UTF-8");
+ int charsRead = reader.read(buffer);
+ // Debug check that we've exhausted the input stream (will fail e.g. if the
+ // file grew after we inspected its length).
+ assert !reader.ready();
+ return charsRead < buffer.length ? Arrays.copyOfRange(buffer, 0, charsRead) : buffer;
+ } finally {
+ if (reader != null) reader.close();
+ }
+ }
+}