From 44d9a1d8dd8cee6197ad01ccbb663b966cbee62a Mon Sep 17 00:00:00 2001 From: Roland Levillain Date: Fri, 15 Nov 2019 19:26:45 +0000 Subject: 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 Change-Id: Ie05e05d305bc23ac94d19a6565bd37512a6e34c4 --- tests/PlatformCompatGating/Android.bp | 33 ------- tests/PlatformCompatGating/AndroidManifest.xml | 11 --- tests/PlatformCompatGating/AndroidTest.xml | 30 ------ .../src/com/android/compat/testing/DummyApi.java | 87 ----------------- .../tests/gating/PlatformCompatGatingTest.java | 94 ------------------ tests/PlatformCompatGating/test-rules/Android.bp | 26 ----- .../compat/testing/PlatformCompatChangeRule.java | 107 --------------------- 7 files changed, 388 deletions(-) delete mode 100644 tests/PlatformCompatGating/Android.bp delete mode 100644 tests/PlatformCompatGating/AndroidManifest.xml delete mode 100644 tests/PlatformCompatGating/AndroidTest.xml delete mode 100644 tests/PlatformCompatGating/src/com/android/compat/testing/DummyApi.java delete mode 100644 tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatGatingTest.java delete mode 100644 tests/PlatformCompatGating/test-rules/Android.bp delete mode 100644 tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java diff --git a/tests/PlatformCompatGating/Android.bp b/tests/PlatformCompatGating/Android.bp deleted file mode 100644 index 5e9ef8efc402..000000000000 --- a/tests/PlatformCompatGating/Android.bp +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright (C) 2019 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. -// - -android_test { - name: "PlatformCompatGating", - // Only compile source java files in this apk. - srcs: ["src/**/*.java"], - certificate: "platform", - libs: [ - "android.test.runner", - "android.test.base", - ], - static_libs: [ - "junit", - "android-support-test", - "mockito-target-minus-junit4", - "truth-prebuilt", - "platform-compat-test-rules" - ], -} diff --git a/tests/PlatformCompatGating/AndroidManifest.xml b/tests/PlatformCompatGating/AndroidManifest.xml deleted file mode 100644 index 7f14b83fbc75..000000000000 --- a/tests/PlatformCompatGating/AndroidManifest.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - diff --git a/tests/PlatformCompatGating/AndroidTest.xml b/tests/PlatformCompatGating/AndroidTest.xml deleted file mode 100644 index c62684837332..000000000000 --- a/tests/PlatformCompatGating/AndroidTest.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - diff --git a/tests/PlatformCompatGating/src/com/android/compat/testing/DummyApi.java b/tests/PlatformCompatGating/src/com/android/compat/testing/DummyApi.java deleted file mode 100644 index 731be8e3d9f0..000000000000 --- a/tests/PlatformCompatGating/src/com/android/compat/testing/DummyApi.java +++ /dev/null @@ -1,87 +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 com.android.compat.testing; - -import android.compat.Compatibility; -import android.content.Context; -import android.os.RemoteException; -import android.os.ServiceManager; - -import com.android.internal.compat.IPlatformCompat; - -/** - * 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; - public static final long CHANGE_SYSTEM_SERVER = 666016; - - /** - * 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"; - } - - /** - * Dummy api using system server API. - */ - public static boolean dummySystemServer(Context context) { - IPlatformCompat platformCompat = IPlatformCompat.Stub - .asInterface(ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); - if (platformCompat == null) { - throw new RuntimeException("Could not obtain IPlatformCompat instance!"); - } - String packageName = context.getPackageName(); - try { - return platformCompat.isChangeEnabledByPackageName(CHANGE_SYSTEM_SERVER, packageName, - context.getUserId()); - } catch (RemoteException e) { - throw new RuntimeException("Could not get change value!", e); - } - } -} diff --git a/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatGatingTest.java b/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatGatingTest.java deleted file mode 100644 index dc317f1941c7..000000000000 --- a/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatGatingTest.java +++ /dev/null @@ -1,94 +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 com.android.tests.gating; - -import static com.google.common.truth.Truth.assertThat; - -import android.compat.testing.PlatformCompatChangeRule; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import com.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; - -/** - * Tests for platform compatibility change gating. - */ -@RunWith(AndroidJUnit4.class) -public class PlatformCompatGatingTest { - - @Rule - public TestRule compatChangeRule = new PlatformCompatChangeRule(); - - @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"); - } - - @Test - @EnableCompatChanges({DummyApi.CHANGE_SYSTEM_SERVER}) - public void testDummyGatingPositiveSystemServer() { - assertThat( - DummyApi.dummySystemServer(InstrumentationRegistry.getTargetContext())).isTrue(); - } - - @Test - @DisableCompatChanges({DummyApi.CHANGE_SYSTEM_SERVER}) - public void testDummyGatingNegativeSystemServer() { - assertThat( - DummyApi.dummySystemServer(InstrumentationRegistry.getTargetContext())).isFalse(); - } -} diff --git a/tests/PlatformCompatGating/test-rules/Android.bp b/tests/PlatformCompatGating/test-rules/Android.bp deleted file mode 100644 index 8211ef523ee7..000000000000 --- a/tests/PlatformCompatGating/test-rules/Android.bp +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (C) 2019 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. -// - -java_library { - name: "platform-compat-test-rules", - srcs: ["src/**/*.java"], - static_libs: [ - "junit", - "android-support-test", - "truth-prebuilt", - "core-compat-test-rules" - ], -} \ No newline at end of file diff --git a/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java b/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java deleted file mode 100644 index 4e61862a0083..000000000000 --- a/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2019 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.app.Instrumentation; -import android.compat.Compatibility; -import android.compat.Compatibility.ChangeConfig; -import android.content.Context; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.support.test.InstrumentationRegistry; - -import com.android.internal.compat.CompatibilityChangeConfig; -import com.android.internal.compat.IPlatformCompat; - -import libcore.junit.util.compat.CoreCompatChangeRule; - -import org.junit.runners.model.Statement; - -/** - * Allows tests to specify the which change to disable. - * - *

To use add the following to the test class. It will only change the behavior of a test method - * if it is annotated with - * {@link libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges} and/or - * {@link libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges}. - *

- *
- * @Rule
- * public TestRule compatChangeRule = new PlatformCompatChangeRule();
- * 
- * - *

Each test method that needs to disable a specific change needs to be annotated - * with {@link libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges} and/or - * {@link libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges} specifying the change - * id. e.g.: - *

- *
- *   @Test
- *   @DisableCompatChanges({42})
- *   public void testAsIfChange42Disabled() {
- *     // check behavior
- *   }
- *
- *   @Test
- *   @EnableCompatChanges({42})
- *   public void testAsIfChange42Enabled() {
- *     // check behavior
- *
- * 
- */ -public class PlatformCompatChangeRule extends CoreCompatChangeRule { - - @Override - protected Statement createStatementForConfig(final Statement statement, ChangeConfig config) { - return new CompatChangeStatement(statement, config); - } - - - private static class CompatChangeStatement extends Statement { - private final Statement mTestStatement; - private final ChangeConfig mConfig; - - private CompatChangeStatement(Statement testStatement, ChangeConfig config) { - this.mTestStatement = testStatement; - this.mConfig = config; - } - - @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(mConfig); - try { - platformCompat.setOverrides(new CompatibilityChangeConfig(mConfig), packageName); - try { - mTestStatement.evaluate(); - } finally { - platformCompat.clearOverrides(packageName); - } - } catch (RemoteException e) { - throw new RuntimeException("Could not call IPlatformCompat binder method!", e); - } finally { - Compatibility.clearOverrides(); - } - } - } -} -- cgit v1.2.3-59-g8ed1b