summaryrefslogtreecommitdiff
path: root/ravenwood/junit-src
diff options
context:
space:
mode:
author Makoto Onuki <omakoto@google.com> 2024-02-01 15:34:37 -0800
committer Makoto Onuki <omakoto@google.com> 2024-02-12 12:59:52 -0800
commit8e4eb7ed4d16c7ea847d5e21717389db8dd021de (patch)
tree2e12ef480f6e80361726539ec3c15d1a32f34167 /ravenwood/junit-src
parenta60c144b83026e6a95f94aa712ba089eec91d456 (diff)
Add @OnlyOnRavenwood
Also add a bivalent test. Test: atest RavenwoodBivalentTest && atest RavenwoodBivalentTest_device Bug: 292141694 Change-Id: I10f258e62e8a7f6a85fad5b39eda27c397e08f55
Diffstat (limited to 'ravenwood/junit-src')
-rw-r--r--ravenwood/junit-src/android/platform/test/annotations/DisabledOnNonRavenwood.java47
-rw-r--r--ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodClassRule.java2
-rw-r--r--ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java11
3 files changed, 60 insertions, 0 deletions
diff --git a/ravenwood/junit-src/android/platform/test/annotations/DisabledOnNonRavenwood.java b/ravenwood/junit-src/android/platform/test/annotations/DisabledOnNonRavenwood.java
new file mode 100644
index 000000000000..8ca34bafc2c6
--- /dev/null
+++ b/ravenwood/junit-src/android/platform/test/annotations/DisabledOnNonRavenwood.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.platform.test.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Tests marked with this annotation are only executed when running on Ravenwood, but not
+ * on a device.
+ *
+ * This is basically equivalent to the opposite of {@link DisabledOnRavenwood}, but in order to
+ * avoid complex structure, and there's no equivalent to the opposite {@link EnabledOnRavenwood},
+ * which means if a test class has this annotation, you can't negate it in subclasses or
+ * on a per-method basis.
+ *
+ * The {@code RAVENWOOD_RUN_DISABLED_TESTS} environmental variable won't work because it won't be
+ * propagated to the device. (We may support it in the future, possibly using a debug. sysprop.)
+ *
+ * @hide
+ */
+@Inherited
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DisabledOnNonRavenwood {
+ /**
+ * General free-form description of why this test is being ignored.
+ */
+ String reason() default "";
+}
diff --git a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodClassRule.java b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodClassRule.java
index 8d76970f9ad4..9a4d4886d6f0 100644
--- a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodClassRule.java
+++ b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodClassRule.java
@@ -18,6 +18,7 @@ package android.platform.test.ravenwood;
import static android.platform.test.ravenwood.RavenwoodRule.ENABLE_PROBE_IGNORED;
import static android.platform.test.ravenwood.RavenwoodRule.IS_ON_RAVENWOOD;
+import static android.platform.test.ravenwood.RavenwoodRule.shouldEnableOnDevice;
import static android.platform.test.ravenwood.RavenwoodRule.shouldEnableOnRavenwood;
import static android.platform.test.ravenwood.RavenwoodRule.shouldStillIgnoreInProbeIgnoreMode;
@@ -42,6 +43,7 @@ public class RavenwoodClassRule implements TestRule {
public Statement apply(Statement base, Description description) {
// No special treatment when running outside Ravenwood; run tests as-is
if (!IS_ON_RAVENWOOD) {
+ Assume.assumeTrue(shouldEnableOnDevice(description));
return base;
}
diff --git a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
index 764573defd7a..b90f112c1655 100644
--- a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
+++ b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
@@ -22,6 +22,7 @@ import static android.os.UserHandle.USER_SYSTEM;
import static org.junit.Assert.fail;
+import android.platform.test.annotations.DisabledOnNonRavenwood;
import android.platform.test.annotations.DisabledOnRavenwood;
import android.platform.test.annotations.EnabledOnRavenwood;
import android.platform.test.annotations.IgnoreUnderRavenwood;
@@ -211,6 +212,15 @@ public class RavenwoodRule implements TestRule {
return IS_ON_RAVENWOOD;
}
+ static boolean shouldEnableOnDevice(Description description) {
+ if (description.isTest()) {
+ if (description.getAnnotation(DisabledOnNonRavenwood.class) != null) {
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* Determine if the given {@link Description} should be enabled when running on the
* Ravenwood test environment.
@@ -271,6 +281,7 @@ public class RavenwoodRule implements TestRule {
public Statement apply(Statement base, Description description) {
// No special treatment when running outside Ravenwood; run tests as-is
if (!IS_ON_RAVENWOOD) {
+ Assume.assumeTrue(shouldEnableOnDevice(description));
return base;
}