diff options
author | Jed Estep <jestep@google.com> | 2016-04-12 22:19:29 -0700 |
---|---|---|
committer | Jed Estep <jestep@google.com> | 2016-04-20 12:14:16 -0700 |
commit | 71832c71d1fe049a1f898c231f9b0405028fe12d (patch) | |
tree | 6e53f4c967ed45b35db05781233d721f2cd2f6dc | |
parent | 7e7837877bc1a57a8228bfc7bcd93c1229707947 (diff) | |
download | tradefederation-71832c71d1fe049a1f898c231f9b0405028fe12d.tar.gz |
Enable OtaFaultInjectionPreparer to sign packages
OTA packages need to be re-signed after any modification This requires
the following changes to tradefed:
* OtaDeviceBuildInfo must be accessible to google_tradefed
* A BuildInfo must exist that contains otatools.zip files (signapk.jar)
Bug: 28193112
Change-Id: I9ed42ea34634fc20768fbe0d99ebcbf8c07b94d8
-rw-r--r-- | prod-tests/src/com/android/ota/tests/SideloadOtaStabilityTest.java | 21 | ||||
-rw-r--r-- | src/com/android/tradefed/build/OtaDeviceBuildInfo.java (renamed from prod-tests/src/com/android/ota/tests/OtaDeviceBuildInfo.java) | 10 | ||||
-rw-r--r-- | src/com/android/tradefed/build/OtaToolsDeviceBuildInfo.java | 75 | ||||
-rw-r--r-- | src/com/android/tradefed/targetprep/OtaFaultInjectionPreparer.java | 105 | ||||
-rw-r--r-- | tests/src/com/android/tradefed/UnitTests.java | 2 | ||||
-rw-r--r-- | tests/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparerTest.java | 76 |
6 files changed, 87 insertions, 202 deletions
diff --git a/prod-tests/src/com/android/ota/tests/SideloadOtaStabilityTest.java b/prod-tests/src/com/android/ota/tests/SideloadOtaStabilityTest.java index ab64a3723..a6a51db11 100644 --- a/prod-tests/src/com/android/ota/tests/SideloadOtaStabilityTest.java +++ b/prod-tests/src/com/android/ota/tests/SideloadOtaStabilityTest.java @@ -18,6 +18,7 @@ package com.android.ota.tests; import com.android.tradefed.build.IBuildInfo; import com.android.tradefed.build.IDeviceBuildInfo; +import com.android.tradefed.build.OtaDeviceBuildInfo; import com.android.tradefed.config.ConfigurationException; import com.android.tradefed.config.IConfiguration; import com.android.tradefed.config.IConfigurationReceiver; @@ -308,15 +309,17 @@ public class SideloadOtaStabilityTest implements IDeviceTest, IBuildReceiver, doUncrypt(SocketFactory.getInstance()); String installOtaCmd = String.format("--update_package=%s\n", BLOCK_MAP_PATH); mDevice.pushString(installOtaCmd, RECOVERY_COMMAND_PATH); + CLog.i("Rebooting to install OTA"); try { mDevice.rebootIntoRecovery(); } catch (DeviceNotAvailableException e) { - CLog.w("Device %s did reach state 'recovery', instead in state %s", - mDevice.getSerialNumber(), mDevice.getDeviceState()); - // TODO: with a new ddmlib, this should be SIDELOAD, but for now it will be null - if (mDevice.getDeviceState() != null) { - throw e; - } + // The device will only enter the RECOVERY state if it hits the recovery menu. + // Since we added a command to /cache/recovery/command, recovery mode executes the + // command rather than booting into the menu. While applying the update as a result + // of the installed command, the device reports its state as NOT_AVAILABLE. If the + // device *actually* becomes unavailable, we will catch the resulting DNAE in the + // next call to waitForDeviceOnline. + CLog.i("Didn't go to recovery, went straigh to update"); } try { @@ -334,12 +337,6 @@ public class SideloadOtaStabilityTest implements IDeviceTest, IBuildReceiver, mDevice.getSerialNumber()); throw e; } - Assert.assertEquals("build id does not equal expected value after OTA", - mDevice.getBuildId(), otaBuild.getOtaPackageVersion()); - Assert.assertEquals("bootloader version does not equal expected value after OTA", - mDevice.getBootloaderVersion(), mExpectedBootloaderVersion); - Assert.assertEquals("baseband version does not equal expected value after OTA", - mDevice.getBasebandVersion(), mExpectedBasebandVersion); } diff --git a/prod-tests/src/com/android/ota/tests/OtaDeviceBuildInfo.java b/src/com/android/tradefed/build/OtaDeviceBuildInfo.java index d4708a9ee..437e84cbc 100644 --- a/prod-tests/src/com/android/ota/tests/OtaDeviceBuildInfo.java +++ b/src/com/android/tradefed/build/OtaDeviceBuildInfo.java @@ -14,11 +14,7 @@ * limitations under the License. */ -package com.android.ota.tests; - -import com.android.tradefed.build.IBuildInfo; -import com.android.tradefed.build.IDeviceBuildInfo; -import com.android.tradefed.build.VersionedFile; +package com.android.tradefed.build; import java.io.File; import java.util.Collection; @@ -38,8 +34,8 @@ import java.util.Map; */ public class OtaDeviceBuildInfo implements IDeviceBuildInfo { - private IDeviceBuildInfo mOtaBuild; - private IDeviceBuildInfo mBaselineBuild; + protected IDeviceBuildInfo mOtaBuild; + protected IDeviceBuildInfo mBaselineBuild; public void setOtaBuild(IDeviceBuildInfo otaBuild) { mOtaBuild = otaBuild; diff --git a/src/com/android/tradefed/build/OtaToolsDeviceBuildInfo.java b/src/com/android/tradefed/build/OtaToolsDeviceBuildInfo.java new file mode 100644 index 000000000..905621076 --- /dev/null +++ b/src/com/android/tradefed/build/OtaToolsDeviceBuildInfo.java @@ -0,0 +1,75 @@ +/* + * 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.tradefed.build; + +import com.android.tradefed.util.FileUtil; + +import java.io.File; +import java.io.IOException; + +/** + * An {@link OtaDeviceBuildInfo} that also contains an otatools directory. + */ +public class OtaToolsDeviceBuildInfo extends OtaDeviceBuildInfo { + private File mOtaToolsDir; + + /** + * Construct based on an {@link OtaDeviceBuildInfo}. + * @param parent + */ + public OtaToolsDeviceBuildInfo(OtaDeviceBuildInfo parent) { + setBaselineBuild(parent.mBaselineBuild); + setOtaBuild(parent.mOtaBuild); + } + + public void setOtaTools(File otaTools) { + mOtaToolsDir = otaTools; + } + + public File getOtaTools() { + return mOtaToolsDir; + } + + // Allow the OTA package to be overwritten + @Override + public void setOtaPackageFile(File file, String version) { + ((DeviceBuildInfo)mBaselineBuild) + .getVersionedFileMap().put("ota", new VersionedFile(file, version)); + ((DeviceBuildInfo)mOtaBuild) + .getVersionedFileMap().put("ota", new VersionedFile(file, version)); + } + + @Override + public void cleanUp() { + if (mOtaToolsDir != null) mOtaToolsDir.delete(); + super.cleanUp(); + } + + @Override + public IBuildInfo clone() { + try { + OtaToolsDeviceBuildInfo clone = new OtaToolsDeviceBuildInfo( + (OtaDeviceBuildInfo)super.clone()); + File toolsCopy = FileUtil.createTempDir("otatools"); + FileUtil.recursiveHardlink(mOtaToolsDir, toolsCopy); + clone.setOtaTools(toolsCopy); + return clone; + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} + diff --git a/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparer.java b/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparer.java deleted file mode 100644 index 3a6f6fa7a..000000000 --- a/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparer.java +++ /dev/null @@ -1,105 +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.tradefed.targetprep; - -import com.android.tradefed.build.IBuildInfo; -import com.android.tradefed.build.IDeviceBuildInfo; -import com.android.tradefed.config.Option; -import com.android.tradefed.device.DeviceNotAvailableException; -import com.android.tradefed.device.ITestDevice; -import com.android.tradefed.util.ArrayUtil; -import com.android.tradefed.util.ZipUtil; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.util.zip.ZipOutputStream; - -/** - * An {@link ITargetPreparer} that adds fault injection configuration to an OTA package ZIP. - */ -public class OtaFaultInjectionPreparer implements ITargetPreparer { - - protected static final String CFG_BASE = ".libotafault"; - - @Option(name = "read-fault-file", description = "the filename to trigger a read fault") - protected String mReadFaultFile = null; - - @Option(name = "write-fault-file", description = "the filename to trigger a write fault") - protected String mWriteFaultFile = null; - - @Option(name = "fsync-fault-file", description = "the filename to trigger a fsync fault") - protected String mFsyncFaultFile = null; - - @Option(name = "hit-cache", description = "whether or not to hit /cache/saved.file instead of " - + "the targeted file") - protected boolean mShouldHitCache = false; - - /** - * {@inheritDoc} - */ - @Override - public void setUp(ITestDevice device, IBuildInfo buildInfo) - throws TargetSetupError, BuildError, DeviceNotAvailableException { - if (!(buildInfo instanceof IDeviceBuildInfo)) { - throw new TargetSetupError( - "OtaFaultInjectionPreparer must receive an IDeviceBuildInfo"); - } - IDeviceBuildInfo deviceBuild = (IDeviceBuildInfo) buildInfo; - ZipOutputStream otaPackageStream = null; - try { - otaPackageStream = new ZipOutputStream( - new FileOutputStream(deviceBuild.getOtaPackageFile())); - if (mReadFaultFile != null) { - addToConfig(otaPackageStream, "READ", mReadFaultFile); - } - if (mWriteFaultFile != null) { - addToConfig(otaPackageStream, "WRITE", mWriteFaultFile); - } - if (mFsyncFaultFile != null) { - addToConfig(otaPackageStream, "FSYNC", mFsyncFaultFile); - } - if (mShouldHitCache) { - addToConfig(otaPackageStream, "CACHE", ""); - } - } catch (IOException e) { - throw new TargetSetupError("Could not add config files to OTA zip", e); - } finally { - try { - if (otaPackageStream != null) { - otaPackageStream.close(); - } - } catch (IOException e) { - throw new TargetSetupError("Could not close OTA zip file", e); - } - } - } - - private void addToConfig(ZipOutputStream packageStream, String ioType, String targetFile) - throws IOException { - File cfgFile = new File(ioType); - try { - FileWriter cfgWriter = new FileWriter(cfgFile); - cfgWriter.write(targetFile, 0, targetFile.length()); - cfgWriter.close(); - ZipUtil.addToZip(packageStream, cfgFile, - ArrayUtil.list(CFG_BASE, File.separator)); - } finally { - cfgFile.delete(); - } - } -}
\ No newline at end of file diff --git a/tests/src/com/android/tradefed/UnitTests.java b/tests/src/com/android/tradefed/UnitTests.java index 3d2950e26..48e36ddd9 100644 --- a/tests/src/com/android/tradefed/UnitTests.java +++ b/tests/src/com/android/tradefed/UnitTests.java @@ -78,7 +78,6 @@ import com.android.tradefed.targetprep.FastbootDeviceFlasherTest; import com.android.tradefed.targetprep.FlashingResourcesParserTest; import com.android.tradefed.targetprep.InstrumentationPreparerTest; import com.android.tradefed.targetprep.KernelFlashPreparerTest; -import com.android.tradefed.targetprep.OtaFaultInjectionPreparerTest; import com.android.tradefed.targetprep.SdkAvdPreparerTest; import com.android.tradefed.targetprep.StopServicesSetupTest; import com.android.tradefed.targetprep.SystemUpdaterDeviceFlasherTest; @@ -217,7 +216,6 @@ public class UnitTests extends DeviceTestSuite { addTestSuite(StopServicesSetupTest.class); addTestSuite(SystemUpdaterDeviceFlasherTest.class); addTestSuite(InstrumentationPreparerTest.class); - addTestSuite(OtaFaultInjectionPreparerTest.class); // testtype addTestSuite(AndroidJUnitTestTest.class); diff --git a/tests/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparerTest.java b/tests/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparerTest.java deleted file mode 100644 index 882b7a134..000000000 --- a/tests/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparerTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.android.tradefed.targetprep; - -import com.android.tradefed.build.IDeviceBuildInfo; -import com.android.tradefed.device.ITestDevice; -import com.android.tradefed.util.FileUtil; -import com.android.tradefed.util.ZipUtil; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; - -import java.io.File; -import java.io.InputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public class OtaFaultInjectionPreparerTest extends TestCase { - - private IDeviceBuildInfo mMockDeviceBuildInfo; - private ITestDevice mMockDevice; - private OtaFaultInjectionPreparer mFaultInjectionPreparer; - private File mOtaPackage = null; - private File mStubZipBaseDir = null; - private ZipFile mZipFile = null; - - /** - * {@inheritDoc} - */ - @Override - public void setUp() throws Exception { - super.setUp(); - mStubZipBaseDir = FileUtil.createTempDir("libotafault"); - File stubChildDir = new File(mStubZipBaseDir, "somedir"); - assertTrue(stubChildDir.mkdir()); - File subFile = new File(stubChildDir, "foo.txt"); - FileUtil.writeToFile("contents", subFile); - mOtaPackage = ZipUtil.createZip(mStubZipBaseDir); - - mMockDevice = EasyMock.createMock(ITestDevice.class); - mMockDeviceBuildInfo = EasyMock.createMock(IDeviceBuildInfo.class); - EasyMock.expect(mMockDeviceBuildInfo.getOtaPackageFile()).andReturn(mOtaPackage); - - mFaultInjectionPreparer = new OtaFaultInjectionPreparer(); - } - - /** - * {@inheritDoc} - */ - @Override - public void tearDown() throws Exception { - super.tearDown(); - mZipFile.close(); - mOtaPackage.delete(); - FileUtil.recursiveDelete(mStubZipBaseDir); - } - - public void testAddSingleFault_read() throws Exception { - mFaultInjectionPreparer.mReadFaultFile = "/foo/bar"; - EasyMock.replay(mMockDevice, mMockDeviceBuildInfo); - mFaultInjectionPreparer.setUp(mMockDevice, mMockDeviceBuildInfo); - EasyMock.verify(mMockDevice, mMockDeviceBuildInfo); - mZipFile = new ZipFile(mOtaPackage); - ZipEntry ze = mZipFile.getEntry(OtaFaultInjectionPreparer.CFG_BASE + "/READ"); - - assertTrue(ZipUtil.isZipFileValid(mOtaPackage, true)); - assertNotNull(ze); - - InputStream entryReader = mZipFile.getInputStream(ze); - byte buf[] = new byte[8]; - int numBytesRead = entryReader.read(buf); - - assertEquals(numBytesRead, 8); - assertEquals(new String(buf), "/foo/bar"); - } -} - |