• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tests.odsign;
18 
19 import static org.junit.Assert.assertTrue;
20 
21 import com.android.tests.odsign.annotation.CtsTestCase;
22 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
23 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
24 import com.android.tradefed.testtype.junit4.DeviceTestRunOptions;
25 
26 import org.junit.Before;
27 import org.junit.Ignore;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 
31 import java.util.Optional;
32 import java.util.Set;
33 
34 /**
35  * Test to check if odrefresh, odsign, fs-verity, and ART runtime work together properly.
36  */
37 @Ignore("See derived classes, each produces the file for running the following verification")
38 abstract class ActivationTest extends BaseHostJUnit4Test {
39     private static final String TEST_APP_PACKAGE_NAME = "com.android.tests.odsign";
40     private static final String TEST_APP_APK = "odsign_e2e_test_app.apk";
41 
42     private OdsignTestUtils mTestUtils;
43 
44     @Before
setUp()45     public void setUp() throws Exception {
46         mTestUtils = new OdsignTestUtils(getTestInformation());
47     }
48 
49     @Test
50     @CtsTestCase
verifyArtUpgradeSignsFiles()51     public void verifyArtUpgradeSignsFiles() throws Exception {
52         installPackage(TEST_APP_APK);
53         DeviceTestRunOptions options = new DeviceTestRunOptions(TEST_APP_PACKAGE_NAME);
54         options.setTestClassName(TEST_APP_PACKAGE_NAME + ".ArtifactsSignedTest");
55         options.setTestMethodName("testArtArtifactsHaveFsverity");
56         runDeviceTests(options);
57     }
58 
59     @Test
60     @CtsTestCase
verifyArtUpgradeGeneratesAnyArtifacts()61     public void verifyArtUpgradeGeneratesAnyArtifacts() throws Exception {
62         installPackage(TEST_APP_APK);
63         DeviceTestRunOptions options = new DeviceTestRunOptions(TEST_APP_PACKAGE_NAME);
64         options.setTestClassName(TEST_APP_PACKAGE_NAME + ".ArtifactsSignedTest");
65         options.setTestMethodName("testGeneratesAnyArtArtifacts");
66         runDeviceTests(options);
67     }
68 
69     @Test
verifyArtUpgradeGeneratesRequiredArtifacts()70     public void verifyArtUpgradeGeneratesRequiredArtifacts() throws Exception {
71         installPackage(TEST_APP_APK);
72         DeviceTestRunOptions options = new DeviceTestRunOptions(TEST_APP_PACKAGE_NAME);
73         options.setTestClassName(TEST_APP_PACKAGE_NAME + ".ArtifactsSignedTest");
74         options.setTestMethodName("testGeneratesRequiredArtArtifacts");
75         runDeviceTests(options);
76     }
77 
78     @Test
verifyGeneratedArtifactsLoaded()79     public void verifyGeneratedArtifactsLoaded() throws Exception {
80         // Check both zygote and system_server processes to see that they have loaded the
81         // artifacts compiled and signed by odrefresh and odsign. We check both here rather than
82         // having a separate test because the device reboots between each @Test method and
83         // that is an expensive use of time.
84         mTestUtils.verifyZygotesLoadedPrimaryBootImage();
85         mTestUtils.verifyZygotesLoadedBootImageMainlineExtension();
86         mTestUtils.verifySystemServerLoadedArtifacts();
87     }
88 
89     @Test
verifyGeneratedArtifactsLoadedAfterReboot()90     public void verifyGeneratedArtifactsLoadedAfterReboot() throws Exception {
91         mTestUtils.reboot();
92         verifyGeneratedArtifactsLoaded();
93     }
94 
95     @Test
verifyGeneratedArtifactsLoadedAfterPartialCompilation()96     public void verifyGeneratedArtifactsLoadedAfterPartialCompilation() throws Exception {
97         Set<String> mappedArtifacts = mTestUtils.getSystemServerLoadedArtifacts();
98         // Delete an arbitrary artifact.
99         getDevice().deleteFile(mappedArtifacts.iterator().next());
100         mTestUtils.removeCompilationLogToAvoidBackoff();
101         mTestUtils.reboot();
102         verifyGeneratedArtifactsLoaded();
103     }
104 }
105