Loading TEST_MAPPING +13 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,19 @@ } ], "presubmit": [ { "file_patterns": [ "ApexManager\\.java", "SystemServer\\.java", "services/tests/apexsystemservices/.*" ], "name": "ApexSystemServicesTestCases", "options": [ { "exclude-annotation": "androidx.test.filters.FlakyTest" } ] }, { "name": "FrameworksUiServicesTests", "options": [ Loading services/tests/apexsystemservices/Android.bp 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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 { // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "frameworks_base_license" // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["frameworks_base_license"], } java_test_host { name: "ApexSystemServicesTestCases", srcs: ["src/**/*.java"], libs: ["tradefed"], java_resources: [ ":test_com.android.server", ], static_libs: [ "compatibility-host-util", "cts-install-lib-host", "frameworks-base-hostutils", "truth-prebuilt", "modules-utils-build-testing", ], test_suites: ["device-tests"], } services/tests/apexsystemservices/AndroidTest.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <!-- ~ Copyright (C) 2021 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. --> <configuration description="Tests for apex-system-service support"> <option name="config-descriptor:metadata" key="component" value="misc" /> <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" /> <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" /> <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" > <option name="jar" value="ApexSystemServicesTestCases.jar" /> </test> </configuration> services/tests/apexsystemservices/src/com/android/server/ApexSystemServicesTestCases.java 0 → 100644 +94 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.server; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assume.assumeTrue; import android.cts.install.lib.host.InstallUtilsHost; import com.android.internal.util.test.SystemPreparer; import com.android.modules.utils.build.testing.DeviceSdkLevel; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; @RunWith(DeviceJUnit4ClassRunner.class) public class ApexSystemServicesTestCases extends BaseHostJUnit4Test { private final InstallUtilsHost mHostUtils = new InstallUtilsHost(this); private final TemporaryFolder mTemporaryFolder = new TemporaryFolder(); private final SystemPreparer mPreparer = new SystemPreparer(mTemporaryFolder, this::getDevice); @Rule public final RuleChain ruleChain = RuleChain.outerRule(mTemporaryFolder).around(mPreparer); private DeviceSdkLevel mDeviceSdkLevel; private ITestDevice mDevice; @Before public void setup() throws Exception { mDevice = getDevice(); mDeviceSdkLevel = new DeviceSdkLevel(getDevice()); assumeTrue(mDeviceSdkLevel.isDeviceAtLeastT()); assertThat(mDevice.enableAdbRoot()).isTrue(); assertThat(mHostUtils.isApexUpdateSupported()).isTrue(); } @After public void tearDown() throws Exception { mDevice.disableAdbRoot(); } @Test public void noApexSystemServerStartsWithoutApex() throws Exception { mPreparer.reboot(); assertThat(getFakeApexSystemServiceLogcat()) .doesNotContain("FakeApexSystemService onStart"); } @Test public void apexSystemServerStarts() throws Exception { // Pre-install the apex String apex = "test_com.android.server.apex"; mPreparer.pushResourceFile(apex, "/system/apex/" + apex); // Reboot activates the apex mPreparer.reboot(); assertThat(getFakeApexSystemServiceLogcat()) .contains("FakeApexSystemService onStart"); } private String getFakeApexSystemServiceLogcat() throws DeviceNotAvailableException { return mDevice.executeAdbCommand("logcat", "-v", "brief", "-d", "FakeApexSystemService:D", "*:S"); } } Loading
TEST_MAPPING +13 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,19 @@ } ], "presubmit": [ { "file_patterns": [ "ApexManager\\.java", "SystemServer\\.java", "services/tests/apexsystemservices/.*" ], "name": "ApexSystemServicesTestCases", "options": [ { "exclude-annotation": "androidx.test.filters.FlakyTest" } ] }, { "name": "FrameworksUiServicesTests", "options": [ Loading
services/tests/apexsystemservices/Android.bp 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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 { // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "frameworks_base_license" // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["frameworks_base_license"], } java_test_host { name: "ApexSystemServicesTestCases", srcs: ["src/**/*.java"], libs: ["tradefed"], java_resources: [ ":test_com.android.server", ], static_libs: [ "compatibility-host-util", "cts-install-lib-host", "frameworks-base-hostutils", "truth-prebuilt", "modules-utils-build-testing", ], test_suites: ["device-tests"], }
services/tests/apexsystemservices/AndroidTest.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <!-- ~ Copyright (C) 2021 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. --> <configuration description="Tests for apex-system-service support"> <option name="config-descriptor:metadata" key="component" value="misc" /> <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" /> <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" /> <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" > <option name="jar" value="ApexSystemServicesTestCases.jar" /> </test> </configuration>
services/tests/apexsystemservices/src/com/android/server/ApexSystemServicesTestCases.java 0 → 100644 +94 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.server; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assume.assumeTrue; import android.cts.install.lib.host.InstallUtilsHost; import com.android.internal.util.test.SystemPreparer; import com.android.modules.utils.build.testing.DeviceSdkLevel; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; @RunWith(DeviceJUnit4ClassRunner.class) public class ApexSystemServicesTestCases extends BaseHostJUnit4Test { private final InstallUtilsHost mHostUtils = new InstallUtilsHost(this); private final TemporaryFolder mTemporaryFolder = new TemporaryFolder(); private final SystemPreparer mPreparer = new SystemPreparer(mTemporaryFolder, this::getDevice); @Rule public final RuleChain ruleChain = RuleChain.outerRule(mTemporaryFolder).around(mPreparer); private DeviceSdkLevel mDeviceSdkLevel; private ITestDevice mDevice; @Before public void setup() throws Exception { mDevice = getDevice(); mDeviceSdkLevel = new DeviceSdkLevel(getDevice()); assumeTrue(mDeviceSdkLevel.isDeviceAtLeastT()); assertThat(mDevice.enableAdbRoot()).isTrue(); assertThat(mHostUtils.isApexUpdateSupported()).isTrue(); } @After public void tearDown() throws Exception { mDevice.disableAdbRoot(); } @Test public void noApexSystemServerStartsWithoutApex() throws Exception { mPreparer.reboot(); assertThat(getFakeApexSystemServiceLogcat()) .doesNotContain("FakeApexSystemService onStart"); } @Test public void apexSystemServerStarts() throws Exception { // Pre-install the apex String apex = "test_com.android.server.apex"; mPreparer.pushResourceFile(apex, "/system/apex/" + apex); // Reboot activates the apex mPreparer.reboot(); assertThat(getFakeApexSystemServiceLogcat()) .contains("FakeApexSystemService onStart"); } private String getFakeApexSystemServiceLogcat() throws DeviceNotAvailableException { return mDevice.executeAdbCommand("logcat", "-v", "brief", "-d", "FakeApexSystemService:D", "*:S"); } }