public void testInstallTime() throws Exception { HostReportLog report = new HostReportLog(mDevice.getSerialNumber(), ReportLog.getClassMethodNames()); final int NUMBER_REPEAT = 10; final CtsBuildHelper build = mBuild; final ITestDevice device = mDevice; double[] result = MeasureTime.measure( NUMBER_REPEAT, new MeasureRun() { @Override public void prepare(int i) throws Exception { device.uninstallPackage(PACKAGE); } @Override public void run(int i) throws Exception { File app = build.getTestApp(APK); device.installPackage(app, false); } }); report.printArray("install time", result, ResultType.LOWER_BETTER, ResultUnit.MS); Stat.StatResult stat = Stat.getStatWithOutlierRejection(result, OUTLIER_THRESHOLD); if (stat.mDataCount != result.length) { Log.w(TAG, "rejecting " + (result.length - stat.mDataCount) + " outliers"); } report.printSummary("install time", stat.mAverage, ResultType.LOWER_BETTER, ResultUnit.MS); report.deliverReportToHost(); }
/** {@inheritDoc} */ @Override protected void setUp() throws Exception { super.setUp(); mMockFlasher = EasyMock.createMock(IDeviceFlasher.class); mMockDevice = EasyMock.createMock(ITestDevice.class); EasyMock.expect(mMockDevice.getSerialNumber()).andReturn("foo").anyTimes(); mMockBuildInfo = new DeviceBuildInfo("0", "", ""); mMockBuildInfo.setBuildFlavor("flavor"); mDeviceFlashPreparer = new DeviceFlashPreparer() { @Override protected IDeviceFlasher createFlasher(ITestDevice device) { return mMockFlasher; } @Override int getDeviceBootPollTimeMs() { return 100; } }; mDeviceFlashPreparer.setDeviceBootTime(100); // expect this call mMockFlasher.setUserDataFlashOption(UserDataFlashOption.FLASH); mTmpDir = FileUtil.createTempDir("tmp"); }
/** {@inheritDoc} */ @Override public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e) throws DeviceNotAvailableException { for (String cmd : mTeardownCommands) { // If the command had any output, the executeShellCommand method will log it at the // VERBOSE level; so no need to do any logging from here. CLog.d("About to run tearDown command on device %s: %s", device.getSerialNumber(), cmd); device.executeShellCommand(cmd); } }
@Override protected void setUp() throws Exception { super.setUp(); // Get the device, this gives a handle to run commands and install APKs. mDevice = getDevice(); // Remove any previously installed versions of this APK. mDevice.uninstallPackage(PACKAGE); // Get the APK from the build. File app = mBuild.getTestApp(APK); // Get the ABI flag. String[] options = {AbiUtils.createAbiFlag(mAbi.getName())}; // Install the APK on the device. mDevice.installPackage(app, false, options); final String densityProp; if (mDevice.getSerialNumber().startsWith("emulator-")) { densityProp = DENSITY_PROP_EMULATOR; } else { densityProp = DENSITY_PROP_DEVICE; } final String zip = String.format( "/%s.zip", getDensityBucket(Integer.parseInt(mDevice.getProperty(densityProp)))); Log.logAndDisplay(LogLevel.INFO, TAG, "Loading resources from " + zip); final InputStream zipStream = this.getClass().getResourceAsStream(zip); if (zipStream != null) { final ZipInputStream in = new ZipInputStream(zipStream); try { ZipEntry ze; final byte[] buffer = new byte[1024]; while ((ze = in.getNextEntry()) != null) { final String name = ze.getName(); final File tmp = File.createTempFile("ref_" + name, ".png"); final FileOutputStream out = new FileOutputStream(tmp); int count; while ((count = in.read(buffer)) != -1) { out.write(buffer, 0, count); } out.flush(); out.close(); mReferences.put(name, tmp); } } finally { in.close(); } } mExecutionService = Executors.newFixedThreadPool(2); // 2 worker threads mCompletionService = new ExecutorCompletionService<Boolean>(mExecutionService); }