• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.fastboot;
18 
19 import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
20 import com.android.tradefed.device.ITestDevice;
21 import com.android.tradefed.device.TestDeviceState;
22 import com.android.tradefed.invoker.TestInformation;
23 import com.android.tradefed.log.LogUtil.CLog;
24 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
25 import com.android.tradefed.testtype.junit4.AfterClassWithInfo;
26 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
27 import com.android.tradefed.util.AbiFormatter;
28 import com.android.tradefed.util.CommandResult;
29 import com.android.tradefed.util.CommandStatus;
30 import com.android.tradefed.util.IRunUtil;
31 import com.android.tradefed.util.RunUtil;
32 import java.io.File;
33 import java.lang.Thread;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.HashSet;
37 import java.util.regex.Matcher;
38 import java.util.regex.Pattern;
39 import org.junit.Assert;
40 import org.junit.Assume;
41 import org.junit.Before;
42 import org.junit.Ignore;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.junit.runners.JUnit4;
46 
47 /* VTS test to verify userspace fastboot implementation. */
48 @RunWith(DeviceJUnit4ClassRunner.class)
49 public class FastbootVerifyUserspaceTest extends BaseHostJUnit4Test {
50     // Default maximum command run time is set to 1 minute.
51     private static final long MAX_CMD_RUN_TIME = 60000L;
52 
53     private ITestDevice mDevice;
54     private IRunUtil mRunUtil = RunUtil.getDefault();
55     private String mFuzzyFastbootPath;
56 
57     @Before
setUp()58     public void setUp() throws Exception {
59         mDevice = getDevice();
60 
61         ArrayList<String> supportedAbis = new ArrayList<>(Arrays.asList(AbiFormatter.getSupportedAbis(mDevice, "")));
62         if (supportedAbis.contains("arm64-v8a")) {
63             String output = mDevice.executeShellCommand("uname -r");
64             Pattern p = Pattern.compile("^(\\d+)\\.(\\d+)");
65             Matcher m1 = p.matcher(output);
66             Assert.assertTrue(m1.find());
67             Assume.assumeTrue("Skipping test for fastbootd on GKI",
68                               Integer.parseInt(m1.group(1)) < 5 ||
69                               (Integer.parseInt(m1.group(1)) == 5 &&
70                                Integer.parseInt(m1.group(2)) < 4));
71         }
72 
73         CompatibilityBuildHelper buildHelper = new CompatibilityBuildHelper(getBuild());
74         File file = buildHelper.getTestFile("fuzzy_fastboot", getAbi());
75         Assert.assertNotNull(file);
76         mFuzzyFastbootPath = file.getAbsolutePath();
77         CLog.d("Locate `fuzzy_fastboot` at %s", mFuzzyFastbootPath);
78 
79         // Make sure the device is in fastbootd mode.
80         if (!TestDeviceState.FASTBOOT.equals(mDevice.getDeviceState())) {
81             mDevice.rebootIntoFastbootd();
82         }
83     }
84 
85     @AfterClassWithInfo
tearDownClass(TestInformation testInfo)86     public static void tearDownClass(TestInformation testInfo) throws Exception {
87         testInfo.getDevice().reboot();
88     }
89 
90     /* Runs fuzzy_fastboot gtest to verify slot operations in fastbootd implementation. */
91     @Ignore("b/146589281")
92     @Test
testFastbootdSlotOperations()93     public void testFastbootdSlotOperations() throws Exception {
94         CommandResult result = mRunUtil.runTimedCmd(MAX_CMD_RUN_TIME, mFuzzyFastbootPath,
95                 String.format("--serial=%s", mDevice.getFastbootSerialNumber()),
96                 "--gtest_filter=Conformance.Slots:Conformance.SetActive");
97         Assert.assertEquals(CommandStatus.SUCCESS, result.getStatus());
98     }
99 
100     /* Runs fuzzy_fastboot to verify getvar commands related to logical partitions. */
101     @Test
testLogicalPartitionCommands()102     public void testLogicalPartitionCommands() throws Exception {
103         CommandResult result = mRunUtil.runTimedCmd(MAX_CMD_RUN_TIME, mFuzzyFastbootPath,
104                 String.format("--serial=%s", mDevice.getFastbootSerialNumber()),
105                 "--gtest_filter=LogicalPartitionCompliance.GetVarIsLogical:LogicalPartitionCompliance.SuperPartition");
106         Assert.assertEquals(CommandStatus.SUCCESS, result.getStatus());
107     }
108 
109     /* Devices launching with DAP must have a super partition named "super". */
110     @Test
testSuperPartitionName()111     public void testSuperPartitionName() throws Exception {
112         String superPartitionName = mDevice.getFastbootVariable("super-partition-name");
113         Assert.assertEquals("super", superPartitionName);
114     }
115 
116     /* Runs fuzzy_fastboot to verify the commands to reboot into fastbootd and bootloader. */
117     @Test
testFastbootReboot()118     public void testFastbootReboot() throws Exception {
119         CommandResult result = mRunUtil.runTimedCmd(MAX_CMD_RUN_TIME, mFuzzyFastbootPath,
120                 String.format("--serial=%s", mDevice.getFastbootSerialNumber()),
121                 "--gtest_filter=LogicalPartitionCompliance.FastbootRebootTest");
122         Assert.assertEquals(CommandStatus.SUCCESS, result.getStatus());
123     }
124 
125     /* Runs fuzzy_fastboot to verify the commands to reboot into fastbootd and bootloader. */
126     @Test
testLogicalPartitionFlashing()127     public void testLogicalPartitionFlashing() throws Exception {
128         CommandResult result = mRunUtil.runTimedCmd(MAX_CMD_RUN_TIME, mFuzzyFastbootPath,
129                 String.format("--serial=%s", mDevice.getFastbootSerialNumber()),
130                 "--gtest_filter=LogicalPartitionCompliance.CreateResizeDeleteLP");
131         Assert.assertEquals(CommandStatus.SUCCESS, result.getStatus());
132     }
133 }
134