diff options
author | Paul Duffin <paulduffin@google.com> | 2017-06-21 11:26:53 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-06-21 11:27:01 +0000 |
commit | 00d4d01c3ae855690b8770090b10c80ca12088e0 (patch) | |
tree | d4143ed10e2718fedbc277ccd3eb129b452357a6 | |
parent | 915ede0fc3abc0b7ccb76c35084020602e2a1b4c (diff) | |
parent | 5361c48199edb15a4de2e74cd6ae4df28f598b68 (diff) |
Merge "Remove android.test dependencies on a.o.PerformanceCollector"
4 files changed, 1 insertions, 174 deletions
diff --git a/test-runner/src/android/test/AndroidTestRunner.java b/test-runner/src/android/test/AndroidTestRunner.java index 7313a2880ea2..f898516a001b 100644 --- a/test-runner/src/android/test/AndroidTestRunner.java +++ b/test-runner/src/android/test/AndroidTestRunner.java @@ -18,7 +18,6 @@ package android.test; import android.app.Instrumentation; import android.content.Context; -import android.os.PerformanceCollector.PerformanceResultsWriter; import java.util.ArrayList; import junit.framework.Test; @@ -49,7 +48,6 @@ public class AndroidTestRunner extends BaseTestRunner { private List<TestListener> mTestListeners = new ArrayList<>(); private Instrumentation mInstrumentation; - private PerformanceResultsWriter mPerfWriter; @SuppressWarnings("unchecked") public void setTestClassName(String testClassName, String testMethodName) { @@ -194,7 +192,6 @@ public class AndroidTestRunner extends BaseTestRunner { for (TestCase testCase : mTestCases) { setContextIfAndroidTestCase(testCase, mContext, testContext); setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation); - setPerformanceWriterIfPerformanceCollectorTestCase(testCase, mPerfWriter); testCase.run(mTestResult); } } @@ -217,13 +214,6 @@ public class AndroidTestRunner extends BaseTestRunner { } } - private void setPerformanceWriterIfPerformanceCollectorTestCase( - Test test, PerformanceResultsWriter writer) { - if (PerformanceCollectorTestCase.class.isAssignableFrom(test.getClass())) { - ((PerformanceCollectorTestCase) test).setPerformanceResultsWriter(writer); - } - } - public void setInstrumentation(Instrumentation instrumentation) { mInstrumentation = instrumentation; } @@ -237,13 +227,6 @@ public class AndroidTestRunner extends BaseTestRunner { setInstrumentation(instrumentation); } - /** - * {@hide} Pending approval for public API. - */ - public void setPerformanceResultsWriter(PerformanceResultsWriter writer) { - mPerfWriter = writer; - } - @Override protected Class loadSuiteClass(String suiteClassName) throws ClassNotFoundException { return mContext.getClassLoader().loadClass(suiteClassName); diff --git a/test-runner/src/android/test/InstrumentationTestRunner.java b/test-runner/src/android/test/InstrumentationTestRunner.java index 6e5492bd751c..29e21a757f10 100644 --- a/test-runner/src/android/test/InstrumentationTestRunner.java +++ b/test-runner/src/android/test/InstrumentationTestRunner.java @@ -24,9 +24,6 @@ import android.app.Instrumentation; import android.os.Bundle; import android.os.Debug; import android.os.Looper; -import android.os.Parcelable; -import android.os.PerformanceCollector; -import android.os.PerformanceCollector.PerformanceResultsWriter; import android.test.suitebuilder.TestMethod; import android.test.suitebuilder.TestPredicates; import android.test.suitebuilder.TestSuiteBuilder; @@ -390,7 +387,6 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu WatcherResultPrinter resultPrinter = new WatcherResultPrinter(mTestCount); mTestRunner.addTestListener(new TestPrinter("TestRunner", false)); mTestRunner.addTestListener(resultPrinter); - mTestRunner.setPerformanceResultsWriter(resultPrinter); } start(); } @@ -743,15 +739,12 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu /** * This class sends status reports back to the IInstrumentationWatcher */ - private class WatcherResultPrinter implements TestListener, PerformanceResultsWriter { + private class WatcherResultPrinter implements TestListener { private final Bundle mResultTemplate; Bundle mTestResult; int mTestNum = 0; int mTestResultCode = 0; String mTestClass = null; - PerformanceCollector mPerfCollector = new PerformanceCollector(); - boolean mIsTimedTest = false; - boolean mIncludeDetailedStats = false; public WatcherResultPrinter(int numTests) { mResultTemplate = new Bundle(); @@ -806,30 +799,6 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu sendStatus(REPORT_VALUE_RESULT_START, mTestResult); mTestResultCode = 0; - - mIsTimedTest = false; - mIncludeDetailedStats = false; - try { - // Look for TimedTest annotation on both test class and test method - if (testMethod != null && testMethod.isAnnotationPresent(TimedTest.class)) { - mIsTimedTest = true; - mIncludeDetailedStats = testMethod.getAnnotation( - TimedTest.class).includeDetailedStats(); - } else if (test.getClass().isAnnotationPresent(TimedTest.class)) { - mIsTimedTest = true; - mIncludeDetailedStats = test.getClass().getAnnotation( - TimedTest.class).includeDetailedStats(); - } - } catch (SecurityException e) { - // ignore - the test with given name cannot be accessed. Will be handled during - // test execution - } - - if (mIsTimedTest && mIncludeDetailedStats) { - mPerfCollector.beginSnapshot(""); - } else if (mIsTimedTest) { - mPerfCollector.startTiming(""); - } } /** @@ -860,12 +829,6 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu * @see junit.framework.TestListener#endTest(Test) */ public void endTest(Test test) { - if (mIsTimedTest && mIncludeDetailedStats) { - mTestResult.putAll(mPerfCollector.endSnapshot()); - } else if (mIsTimedTest) { - writeStopTiming(mPerfCollector.stopTiming("")); - } - if (mTestResultCode == 0) { mTestResult.putString(Instrumentation.REPORT_KEY_STREAMRESULT, "."); } @@ -878,50 +841,6 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu } } - public void writeBeginSnapshot(String label) { - // Do nothing - } - - public void writeEndSnapshot(Bundle results) { - // Copy all snapshot data fields into mResults, which is outputted - // via Instrumentation.finish - mResults.putAll(results); - } - - public void writeStartTiming(String label) { - // Do nothing - } - - public void writeStopTiming(Bundle results) { - // Copy results into mTestResult by flattening list of iterations, - // which is outputted via WatcherResultPrinter.endTest - int i = 0; - for (Parcelable p : - results.getParcelableArrayList(PerformanceCollector.METRIC_KEY_ITERATIONS)) { - Bundle iteration = (Bundle)p; - String index = "iteration" + i + "."; - mTestResult.putString(index + PerformanceCollector.METRIC_KEY_LABEL, - iteration.getString(PerformanceCollector.METRIC_KEY_LABEL)); - mTestResult.putLong(index + PerformanceCollector.METRIC_KEY_CPU_TIME, - iteration.getLong(PerformanceCollector.METRIC_KEY_CPU_TIME)); - mTestResult.putLong(index + PerformanceCollector.METRIC_KEY_EXECUTION_TIME, - iteration.getLong(PerformanceCollector.METRIC_KEY_EXECUTION_TIME)); - i++; - } - } - - public void writeMeasurement(String label, long value) { - mTestResult.putLong(label, value); - } - - public void writeMeasurement(String label, float value) { - mTestResult.putFloat(label, value); - } - - public void writeMeasurement(String label, String value) { - mTestResult.putString(label, value); - } - // TODO report the end of the cycle } } diff --git a/test-runner/src/android/test/PerformanceCollectorTestCase.java b/test-runner/src/android/test/PerformanceCollectorTestCase.java deleted file mode 100644 index 3a5dafc0db75..000000000000 --- a/test-runner/src/android/test/PerformanceCollectorTestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2009 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 android.test; - -import android.os.PerformanceCollector; -import android.os.PerformanceCollector.PerformanceResultsWriter; - -/** - * A simple interface for passing in a PerformanceResultsWriter instance to be used with - * PerformanceCollector. - * <p/> - * A one line implementation of {@link #setPerformanceResultsWriter(PerformanceResultsWriter)} - * is sufficient in most cases: - * <p/> - * <code>mPerfCollector.setPerformanceResultsWriter(writer);</code> - * - * {@hide} Not needed for SDK. - */ -@Deprecated -public interface PerformanceCollectorTestCase { - public PerformanceCollector mPerfCollector = new PerformanceCollector(); - - public void setPerformanceResultsWriter(PerformanceResultsWriter writer); -} diff --git a/test-runner/src/android/test/TimedTest.java b/test-runner/src/android/test/TimedTest.java deleted file mode 100644 index cb15ef907050..000000000000 --- a/test-runner/src/android/test/TimedTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2009 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 android.test; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * This annotation can be used on an {@link junit.framework.TestCase}'s test methods. When the - * annotation is present, the test method is timed and the results written through instrumentation - * output. It can also be used on the class itself, which is equivalent to tagging all test methods - * with this annotation. - * <p/> - * Setting {@link #includeDetailedStats()} to true causes additional metrics such as memory usage - * and binder transactions to be gathered and written through instrumentation output. - * - * {@hide} Pending approval for public API. - */ -@Deprecated -@Retention(RetentionPolicy.RUNTIME) -public @interface TimedTest { - boolean includeDetailedStats() default false; -} |