diff options
author | Roland Levillain <rpl@google.com> | 2019-11-15 19:27:02 +0000 |
---|---|---|
committer | Roland Levillain <rpl@google.com> | 2019-11-15 19:50:50 +0000 |
commit | d38b50d216334359b9969606cc611b8be217887f (patch) | |
tree | ac80f025bd021950081702a2ffe7b7955c9a4b4b | |
parent | c5d7d083c5848ddd9bf33b13dc2084088806f8ce (diff) |
Revert submission from topic "separate-testing".
Reason for revert: Breaks master-art builds with this error:
FAILED: out/soong/.intermediates/development/build/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar
echo "module android_stubs_current missing dependencies: api-stubs-docs, framework-res" && false
module android_stubs_current missing dependencies: api-stubs-docs, framework-res
Test: art/tools/buildbot-build.sh --host
Bug: 140367850
Exempt-From-Owner-Approval: Reverting change breaking ART builds
Change-Id: I48f9505342cf035822b445df0fb8b2b778ef36d4
-rw-r--r-- | JavaLibrary.bp | 12 | ||||
-rw-r--r-- | luni/src/main/java/android/compat/Compatibility.java | 5 | ||||
-rw-r--r-- | test-rules/src/platform_compat/java/android/compat/CompatChangeRule.java (renamed from test-rules/src/platform_compat/java/libcore/junit/util/CoreCompatChangeRule.java) | 43 | ||||
-rw-r--r-- | test-rules/src/test/java/android/compat/testing/DummyApi.java | 64 | ||||
-rw-r--r-- | test-rules/src/test/java/libcore/junit/util/compat/CoreCompatChangeRuleTest.java | 77 |
5 files changed, 37 insertions, 164 deletions
diff --git a/JavaLibrary.bp b/JavaLibrary.bp index ec47b5aa8b..c0777ffd07 100644 --- a/JavaLibrary.bp +++ b/JavaLibrary.bp @@ -492,10 +492,8 @@ java_library_static { // Builds platform_compat test rules java_library_static { - name: "core-compat-test-rules", - visibility: [ - "//frameworks/base/tests/PlatformCompatGating/test-rules", - ], + name: "platform_compat-test-rules", + visibility: ["//visibility:public"], srcs: [ "luni/src/main/java/android/compat/**/*.java", "test-rules/src/platform_compat/**/*.java", @@ -505,13 +503,12 @@ java_library_static { static_libs: [ "junit", "guava", + "android-support-test", "app-compat-annotations", ], - sdk_version: "none", - system_modules: "core-all-system-modules", + platform_apis: true, // This builds classes that are in the java.base Java module: patch_module: "java.base", - hostdex: true, } // Builds the core-tests-support library used by various tests. @@ -609,7 +606,6 @@ java_test { static_libs: [ "archive-patcher", - "core-compat-test-rules", "core-java-9-language-tests", "core-test-rules", "core-tests-support", diff --git a/luni/src/main/java/android/compat/Compatibility.java b/luni/src/main/java/android/compat/Compatibility.java index e5d7cbb8d8..1fbdf76a68 100644 --- a/luni/src/main/java/android/compat/Compatibility.java +++ b/luni/src/main/java/android/compat/Compatibility.java @@ -121,14 +121,13 @@ public final class Compatibility { } @CorePlatformApi protected void reportChange(long changeId) { - System.logW(String.format( + throw new IllegalStateException(String.format( "No Compatibility callbacks set! Reporting change %d", changeId)); } @CorePlatformApi protected boolean isChangeEnabled(long changeId) { - System.logW(String.format( + throw new IllegalStateException(String.format( "No Compatibility callbacks set! Querying change %d", changeId)); - return true; } } diff --git a/test-rules/src/platform_compat/java/libcore/junit/util/CoreCompatChangeRule.java b/test-rules/src/platform_compat/java/android/compat/CompatChangeRule.java index 59842c2306..1bae1a2c31 100644 --- a/test-rules/src/platform_compat/java/libcore/junit/util/CoreCompatChangeRule.java +++ b/test-rules/src/platform_compat/java/android/compat/CompatChangeRule.java @@ -14,11 +14,19 @@ * limitations under the License. */ -package libcore.junit.util.compat; +package android.compat; -import android.compat.Compatibility; +import android.app.Instrumentation; import android.compat.Compatibility.Callbacks; import android.compat.Compatibility.ChangeConfig; +import android.content.Context; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.support.test.InstrumentationRegistry; +import android.util.ArraySet; + +import com.android.internal.compat.CompatibilityChangeConfig; +import com.android.internal.compat.IPlatformCompat; import org.junit.rules.TestRule; import org.junit.runner.Description; @@ -29,9 +37,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.HashSet; +import java.util.Map; import java.util.Set; import com.google.common.primitives.Longs; + /** * Allows tests to specify the which change to disable. * @@ -40,7 +50,7 @@ import com.google.common.primitives.Longs; * * <pre> * @Rule - * public TestRule compatChangeRule = new CoreCompatChangeRule(); + * public TestRule compatChangeRule = new CompatChangeRule(); * </pre> * * <p>Each test method that needs to disable a specific change needs to be annotated @@ -61,8 +71,7 @@ import com.google.common.primitives.Longs; * * </pre> */ -public class CoreCompatChangeRule implements TestRule { - +public class CompatChangeRule implements TestRule { @Override public Statement apply(final Statement statement, Description description) { Set<Long> enabled = new HashSet<>(); @@ -80,13 +89,9 @@ public class CoreCompatChangeRule implements TestRule { ChangeConfig config = new ChangeConfig(enabled, disabled); if (config.isEmpty()) { throw new IllegalArgumentException("Added a CompatChangeRule without specifying any " - + "@EnableCompatChanges or @DisableCompatChanges !"); + + "@EnableCompatChanges or @DisableCompatChanges !"); } - return createStatementForConfig(statement, config); - } - - protected Statement createStatementForConfig(final Statement statement, ChangeConfig config) { - return new CompatChangeStatement(statement, config); + return new CompatChangeStatement(statement, config); } private static class CompatChangeStatement extends Statement { @@ -100,9 +105,23 @@ public class CoreCompatChangeRule implements TestRule { @Override public void evaluate() throws Throwable { + Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); + String packageName = instrumentation.getTargetContext().getPackageName(); + IPlatformCompat platformCompat = IPlatformCompat.Stub + .asInterface(ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); + if (platformCompat == null) { + throw new IllegalStateException("Could not get IPlatformCompat service!"); + } Compatibility.setOverrides(config); try { - testStatement.evaluate(); + platformCompat.setOverrides(new CompatibilityChangeConfig(config), packageName); + try { + testStatement.evaluate(); + } finally { + platformCompat.clearOverrides(packageName); + } + } catch(RemoteException e) { + throw new RuntimeException("Could not call IPlatformCompat binder method!", e); } finally { Compatibility.clearOverrides(); } diff --git a/test-rules/src/test/java/android/compat/testing/DummyApi.java b/test-rules/src/test/java/android/compat/testing/DummyApi.java deleted file mode 100644 index dfe40cc022..0000000000 --- a/test-rules/src/test/java/android/compat/testing/DummyApi.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2016 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.compat.testing; - -import android.compat.Compatibility; - -/** - * This is a dummy API to test gating - * - * @hide - */ -public class DummyApi { - - public static final long CHANGE_ID = 666013; - public static final long CHANGE_ID_1 = 666014; - public static final long CHANGE_ID_2 = 666015; - - /** - * Dummy method - * @return "A" if change is enabled, "B" otherwise. - */ - public static String dummyFunc() { - if (Compatibility.isChangeEnabled(CHANGE_ID)) { - return "A"; - } - return "B"; - } - - /** - * Dummy combined method - * @return "0" if {@link CHANGE_ID_1} is disabled and {@link CHANGE_ID_2} is disabled, - "1" if {@link CHANGE_ID_1} is disabled and {@link CHANGE_ID_2} is enabled, - "2" if {@link CHANGE_ID_1} is enabled and {@link CHANGE_ID_2} is disabled, - "3" if {@link CHANGE_ID_1} is enabled and {@link CHANGE_ID_2} is enabled. - */ - public static String dummyCombinedFunc() { - if (!Compatibility.isChangeEnabled(CHANGE_ID_1) - && !Compatibility.isChangeEnabled(CHANGE_ID_2)) { - return "0"; - } else if (!Compatibility.isChangeEnabled(CHANGE_ID_1) - && Compatibility.isChangeEnabled(CHANGE_ID_2)) { - return "1"; - } else if (Compatibility.isChangeEnabled(CHANGE_ID_1) - && !Compatibility.isChangeEnabled(CHANGE_ID_2)) { - return "2"; - } - return "3"; - } - -}
\ No newline at end of file diff --git a/test-rules/src/test/java/libcore/junit/util/compat/CoreCompatChangeRuleTest.java b/test-rules/src/test/java/libcore/junit/util/compat/CoreCompatChangeRuleTest.java deleted file mode 100644 index 87b9446eac..0000000000 --- a/test-rules/src/test/java/libcore/junit/util/compat/CoreCompatChangeRuleTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2018 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 libcore.junit.util.compat; - -import static com.google.common.truth.Truth.assertThat; - -import android.compat.testing.DummyApi; - -import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges; -import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Tests for compatibility change gating. - */ -@RunWith(JUnit4.class) -public class CoreCompatChangeRuleTest { - - @Rule - public TestRule compatChangeRule = new CoreCompatChangeRule(); - - @Test - @EnableCompatChanges({DummyApi.CHANGE_ID}) - public void testDummyGatingPositive() { - assertThat(DummyApi.dummyFunc()).isEqualTo("A"); - } - - @Test - @DisableCompatChanges({DummyApi.CHANGE_ID}) - public void testDummyGatingNegative() { - assertThat(DummyApi.dummyFunc()).isEqualTo("B"); - } - - @Test - @DisableCompatChanges({DummyApi.CHANGE_ID_1, DummyApi.CHANGE_ID_2}) - public void testDummyGatingCombined0() { - assertThat(DummyApi.dummyCombinedFunc()).isEqualTo("0"); - } - - @Test - @DisableCompatChanges({DummyApi.CHANGE_ID_1}) - @EnableCompatChanges({DummyApi.CHANGE_ID_2}) - public void testDummyGatingCombined1() { - assertThat(DummyApi.dummyCombinedFunc()).isEqualTo("1"); - } - - @Test - @EnableCompatChanges({DummyApi.CHANGE_ID_1}) - @DisableCompatChanges({DummyApi.CHANGE_ID_2}) - public void testDummyGatingCombined2() { - assertThat(DummyApi.dummyCombinedFunc()).isEqualTo("2"); - } - - @Test - @EnableCompatChanges({DummyApi.CHANGE_ID_1, DummyApi.CHANGE_ID_2}) - public void testDummyGatingCombined3() { - assertThat(DummyApi.dummyCombinedFunc()).isEqualTo("3"); - } -}
\ No newline at end of file |