diff options
author | 2017-06-15 14:50:08 +0100 | |
---|---|---|
committer | 2017-06-20 10:26:29 +0100 | |
commit | 5361c48199edb15a4de2e74cd6ae4df28f598b68 (patch) | |
tree | 3546b7b961a5c48d458fef100582d2580bdf5978 | |
parent | dcfaccd3cc65b48eeb1c3730f2be09670550658f (diff) |
Remove android.test dependencies on a.o.PerformanceCollector
The a.t.TimedTest annotation was removed because it was not in the API
and was only used by the code that has been removed.
The a.t.PerformanceCollectorTestCase was removed because it was not in
the API and its only purpose was to allow the AndroidTestRunner to
supply a PerformanceCollector.PerformanceResultsWriter to a test.
Bug: 62652137
Test: make checkbuild
Change-Id: Ie90a7004ade1448cb6bc7e029f6ba5620db29bfd
4 files changed, 3 insertions, 176 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 9bd4c966496d..97bf9203e7a8 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(); } @@ -476,7 +472,7 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu /** * Returns the test predicate object, corresponding to the annotation class value provided via - * the {@link ARGUMENT_ANNOTATION} argument. + * the {@link #ARGUMENT_ANNOTATION} argument. * * @return the predicate or <code>null</code> */ @@ -490,7 +486,7 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu /** * Returns the negative test predicate object, corresponding to the annotation class value - * provided via the {@link ARGUMENT_NOT_ANNOTATION} argument. + * provided via the {@link #ARGUMENT_NOT_ANNOTATION} argument. * * @return the predicate or <code>null</code> */ @@ -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; -} |