summaryrefslogtreecommitdiff
path: root/ravenwood/junit-src
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@google.com> 2023-11-16 16:10:54 -0700
committer Jeff Sharkey <jsharkey@google.com> 2023-11-21 09:36:02 -0700
commit1c7db6b9a1562404b870daa19d353d159e9608a9 (patch)
tree8f57aa4b4e62972c57549ca5fe950dab8ac53c45 /ravenwood/junit-src
parentc914beed5fe5055d4aea2a227b064c45fdbd96ce (diff)
Support Handler/Looper for Ravenwood, with CTS.
Now that we have a solid foundation of classes available, one of the tricker pieces is supporting Handler/Looper under Ravenwood. At its core, the native implementation of MessageQueue can be emulated using core JVM primitives, which is enough to reliably pass CTS. Advanced features like FileDescriptor events will need to wait until we eventually have real JNI support. Fix obscure bug with SystemClock; must be positive number. Always start our "fake" pointers from 1 to prevent `nullptr` oddness. Bug: 292141694 Test: atest-dev CtsOsTestCasesRavenwood CtsOsTestCases Change-Id: I0f82b659973443968ef2609a7e3151f381abff29
Diffstat (limited to 'ravenwood/junit-src')
-rw-r--r--ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java23
1 files changed, 17 insertions, 6 deletions
diff --git a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
index 79f9e58aaa1a..9db5b9895749 100644
--- a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
+++ b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
@@ -34,6 +34,8 @@ import java.util.concurrent.atomic.AtomicInteger;
public class RavenwoodRule implements TestRule {
private static AtomicInteger sNextPid = new AtomicInteger(100);
+ private static final boolean IS_UNDER_RAVENWOOD = RavenwoodRuleImpl.isUnderRavenwood();
+
private static final int SYSTEM_UID = 1000;
private static final int NOBODY_UID = 9999;
private static final int FIRST_APPLICATION_UID = 10000;
@@ -45,6 +47,8 @@ public class RavenwoodRule implements TestRule {
int mUid = NOBODY_UID;
int mPid = sNextPid.getAndIncrement();
+ boolean mProvideMainThread = false;
+
public RavenwoodRule() {
}
@@ -72,6 +76,15 @@ public class RavenwoodRule implements TestRule {
return this;
}
+ /**
+ * Configure a "main" thread to be available for the duration of the test, as defined
+ * by {@code Looper.getMainLooper()}. Has no effect under non-Ravenwood environments.
+ */
+ public Builder setProvideMainThread(boolean provideMainThread) {
+ mRule.mProvideMainThread = provideMainThread;
+ return this;
+ }
+
public RavenwoodRule build() {
return mRule;
}
@@ -81,8 +94,7 @@ public class RavenwoodRule implements TestRule {
* Return if the current process is running under a Ravenwood test environment.
*/
public boolean isUnderRavenwood() {
- // TODO: give ourselves a better environment signal
- return System.getProperty("java.class.path").contains("ravenwood");
+ return IS_UNDER_RAVENWOOD;
}
@Override
@@ -90,17 +102,16 @@ public class RavenwoodRule implements TestRule {
return new Statement() {
@Override
public void evaluate() throws Throwable {
- final boolean isUnderRavenwood = isUnderRavenwood();
if (description.getAnnotation(IgnoreUnderRavenwood.class) != null) {
- Assume.assumeFalse(isUnderRavenwood);
+ Assume.assumeFalse(IS_UNDER_RAVENWOOD);
}
- if (isUnderRavenwood) {
+ if (IS_UNDER_RAVENWOOD) {
RavenwoodRuleImpl.init(RavenwoodRule.this);
}
try {
base.evaluate();
} finally {
- if (isUnderRavenwood) {
+ if (IS_UNDER_RAVENWOOD) {
RavenwoodRuleImpl.reset(RavenwoodRule.this);
}
}