Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2240)

Unified Diff: base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java

Issue 1519523002: [Android] Support conditional test disabling based on android.os.Build values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java
diff --git a/base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java b/base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java
index 58e5b1c4252e80d798a87494e07241df0a523057..dce04cf899396d63b32ff17127fbb23e49e892e2 100644
--- a/base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java
+++ b/base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java
@@ -21,11 +21,13 @@ import org.chromium.base.SysUtils;
import org.chromium.base.multidex.ChromiumMultiDex;
import org.chromium.base.test.BaseTestResult.SkipCheck;
import org.chromium.base.test.util.CommandLineFlags;
+import org.chromium.base.test.util.DisableIf;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.Restriction;
import org.chromium.test.reporter.TestStatusListener;
import java.lang.reflect.Method;
+import java.util.Arrays;
// TODO(jbudorick): Add support for on-device handling of timeouts.
/**
@@ -64,24 +66,30 @@ public class BaseInstrumentationTestRunner extends InstrumentationTestRunner {
protected void addTestHooks(BaseTestResult result) {
result.addSkipCheck(new MinAndroidSdkLevelSkipCheck());
result.addSkipCheck(new RestrictionSkipCheck());
+ result.addSkipCheck(new DisableSkipCheck());
result.addPreTestHook(CommandLineFlags.getRegistrationHook());
}
+ private static Method getTestMethod(TestCase testCase) {
+ try {
+ return testCase.getClass().getMethod(testCase.getName(), (Class[]) null);
+ } catch (NoSuchMethodException e) {
+ Log.e(TAG, "Unable to find %s in %s", testCase.getName(),
+ testCase.getClass().getName(), e);
+ return null;
+ }
+ }
+
/**
* Checks if any restrictions exist and skip the test if it meets those restrictions.
*/
public class RestrictionSkipCheck implements SkipCheck {
@Override
public boolean shouldSkip(TestCase testCase) {
- Method method;
- try {
- method = testCase.getClass().getMethod(testCase.getName(), (Class[]) null);
- } catch (NoSuchMethodException e) {
- Log.e(TAG, "Unable to find %s in %s", testCase.getName(),
- testCase.getClass().getName(), e);
- return true;
- }
+ Method method = getTestMethod(testCase);
+ if (method == null) return true;
+
Restriction restrictions = method.getAnnotation(Restriction.class);
if (restrictions != null) {
for (String restriction : restrictions.value()) {
@@ -118,6 +126,52 @@ public class BaseInstrumentationTestRunner extends InstrumentationTestRunner {
}
/**
+ * Checks for conditional disables.
+ *
+ * Currently, this only includes checks against a few {@link android.os.Build} values.
+ */
+ public static class DisableIfSkipCheck implements SkipCheck {
+
+ @Override
+ public boolean shouldSkip(TestCase testCase) {
+ Method method = getTestMethod(testCase);
+ if (method == null) return true;
+
+ if (method.isAnnotationPresent(DisableIf.Build.class)) {
+ DisableIf.Build v = method.getAnnotation(
+ DisableIf.Build.class);
+ return sdk(v) && abi(v) && hardware(v);
+ }
+
+ return false;
+ }
+
+ private boolean sdk(DisableIf.Build v) {
+ return Build.VERSION.SDK_INT < v.sdk_is_less_than()
Yaron 2015/12/11 02:22:16 *sigh* I guess I'll eventually lose this battle o
jbudorick 2015/12/17 02:08:13 I'm fine with leaving this out until someone needs
+ && Build.VERSION.SDK_INT > v.sdk_is_greater_than();
+ }
+
+ private boolean abi(DisableIf.Build v) {
+ if (v.supported_abis_includes().isEmpty()) return true;
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ for (String s : Build.SUPPORTED_ABIS) {
+ Log.i(TAG, " %s", s);
Yaron 2015/12/11 02:22:16 ?
jbudorick 2015/12/17 02:08:13 leftover, removed.
+ }
+ return Arrays.asList(Build.SUPPORTED_ABIS).contains(
+ v.supported_abis_includes());
Yaron 2015/12/11 02:22:16 would you need to strip this on spaces or can you
jbudorick 2015/12/17 02:08:13 at the moment, only one.
+ } else {
+ return Build.CPU_ABI.equals(v.supported_abis_includes())
+ || Build.CPU_ABI2.equals(v.supported_abis_includes());
+ }
+ }
+
+ private boolean hardware(DisableIf.Build v) {
+ return v.hardware_is().isEmpty() || Build.HARDWARE.equals(v.hardware_is());
+ }
+ }
+
+ /**
* Checks the device's SDK level against any specified minimum requirement.
*/
public static class MinAndroidSdkLevelSkipCheck implements SkipCheck {

Powered by Google App Engine
This is Rietveld 408576698