diff options
5 files changed, 91 insertions, 20 deletions
diff --git a/Ravenwood.bp b/Ravenwood.bp index b497871aee85..03a23ba15273 100644 --- a/Ravenwood.bp +++ b/Ravenwood.bp @@ -81,7 +81,7 @@ android_ravenwood_libgroup { "hoststubgen-helper-framework-runtime.ravenwood", "junit", "truth", - "ravenwood-junit", + "ravenwood-junit-impl", "android.test.mock", ], } diff --git a/ravenwood/Android.bp b/ravenwood/Android.bp index b9e34ee97f21..3f46ab859bf9 100644 --- a/ravenwood/Android.bp +++ b/ravenwood/Android.bp @@ -25,12 +25,32 @@ java_library { } java_library { - name: "ravenwood-junit", - srcs: ["junit-src/**/*.java"], + name: "ravenwood-junit-impl", + srcs: [ + "junit-src/**/*.java", + "junit-impl-src/**/*.java", + ], libs: [ "framework-minus-apex.ravenwood", "junit", ], + visibility: ["//frameworks/base"], +} + +// Carefully compiles against only test_current to support tests that +// want to verify they're unbundled. The "impl" library above is what +// ships inside the Ravenwood environment to actually drive any API +// access to implementation details. +java_library { + name: "ravenwood-junit", + srcs: [ + "junit-src/**/*.java", + "junit-stub-src/**/*.java", + ], + sdk_version: "test_current", + libs: [ + "junit", + ], visibility: ["//visibility:public"], } diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java new file mode 100644 index 000000000000..1caef26d50eb --- /dev/null +++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2023 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.ravenwood; + +public class RavenwoodRuleImpl { + public static void init(RavenwoodRule rule) { + android.os.Process.init$ravenwood(rule.mUid, rule.mPid); + android.os.Binder.init$ravenwood(); + } + + public static void reset(RavenwoodRule rule) { + android.os.Process.reset$ravenwood(); + android.os.Binder.reset$ravenwood(); + } +} diff --git a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java index bffd0cdc9412..79f9e58aaa1a 100644 --- a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java +++ b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java @@ -16,7 +16,6 @@ package android.platform.test.ravenwood; -import android.os.Process; import android.platform.test.annotations.IgnoreUnderRavenwood; import org.junit.Assume; @@ -35,12 +34,16 @@ import java.util.concurrent.atomic.AtomicInteger; public class RavenwoodRule implements TestRule { private static AtomicInteger sNextPid = new AtomicInteger(100); + private static final int SYSTEM_UID = 1000; + private static final int NOBODY_UID = 9999; + private static final int FIRST_APPLICATION_UID = 10000; + /** * Unless the test author requests differently, run as "nobody", and give each collection of * tests its own unique PID. */ - private int mUid = android.os.Process.NOBODY_UID; - private int mPid = sNextPid.getAndIncrement(); + int mUid = NOBODY_UID; + int mPid = sNextPid.getAndIncrement(); public RavenwoodRule() { } @@ -56,7 +59,7 @@ public class RavenwoodRule implements TestRule { * test. Has no effect under non-Ravenwood environments. */ public Builder setProcessSystem() { - mRule.mUid = android.os.Process.SYSTEM_UID; + mRule.mUid = SYSTEM_UID; return this; } @@ -65,7 +68,7 @@ public class RavenwoodRule implements TestRule { * test. Has no effect under non-Ravenwood environments. */ public Builder setProcessApp() { - mRule.mUid = android.os.Process.FIRST_APPLICATION_UID; + mRule.mUid = FIRST_APPLICATION_UID; return this; } @@ -82,16 +85,6 @@ public class RavenwoodRule implements TestRule { return System.getProperty("java.class.path").contains("ravenwood"); } - private void init() { - android.os.Process.init$ravenwood(mUid, mPid); - android.os.Binder.init$ravenwood(); - } - - private void reset() { - android.os.Process.reset$ravenwood(); - android.os.Binder.reset$ravenwood(); - } - @Override public Statement apply(Statement base, Description description) { return new Statement() { @@ -102,13 +95,13 @@ public class RavenwoodRule implements TestRule { Assume.assumeFalse(isUnderRavenwood); } if (isUnderRavenwood) { - init(); + RavenwoodRuleImpl.init(RavenwoodRule.this); } try { base.evaluate(); } finally { if (isUnderRavenwood) { - reset(); + RavenwoodRuleImpl.reset(RavenwoodRule.this); } } } diff --git a/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java new file mode 100644 index 000000000000..ecaff8084888 --- /dev/null +++ b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2023 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.ravenwood; + +public class RavenwoodRuleImpl { + public static void init(RavenwoodRule rule) { + // Must be provided by impl to reference runtime internals + throw new UnsupportedOperationException(); + } + + public static void reset(RavenwoodRule rule) { + // Must be provided by impl to reference runtime internals + throw new UnsupportedOperationException(); + } +} |