Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 00d4d01c authored by Paul Duffin's avatar Paul Duffin Committed by Android (Google) Code Review
Browse files

Merge "Remove android.test dependencies on a.o.PerformanceCollector"

parents 915ede0f 5361c481
Loading
Loading
Loading
Loading
+0 −17
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ package android.test;


import android.app.Instrumentation;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Context;
import android.os.PerformanceCollector.PerformanceResultsWriter;


import java.util.ArrayList;
import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.Test;
@@ -49,7 +48,6 @@ public class AndroidTestRunner extends BaseTestRunner {


    private List<TestListener> mTestListeners = new ArrayList<>();
    private List<TestListener> mTestListeners = new ArrayList<>();
    private Instrumentation mInstrumentation;
    private Instrumentation mInstrumentation;
    private PerformanceResultsWriter mPerfWriter;


    @SuppressWarnings("unchecked")
    @SuppressWarnings("unchecked")
    public void setTestClassName(String testClassName, String testMethodName) {
    public void setTestClassName(String testClassName, String testMethodName) {
@@ -194,7 +192,6 @@ public class AndroidTestRunner extends BaseTestRunner {
        for (TestCase testCase : mTestCases) {
        for (TestCase testCase : mTestCases) {
            setContextIfAndroidTestCase(testCase, mContext, testContext);
            setContextIfAndroidTestCase(testCase, mContext, testContext);
            setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation);
            setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation);
            setPerformanceWriterIfPerformanceCollectorTestCase(testCase, mPerfWriter);
            testCase.run(mTestResult);
            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) {
    public void setInstrumentation(Instrumentation instrumentation) {
        mInstrumentation = instrumentation;
        mInstrumentation = instrumentation;
    }
    }
@@ -237,13 +227,6 @@ public class AndroidTestRunner extends BaseTestRunner {
        setInstrumentation(instrumentation);
        setInstrumentation(instrumentation);
    }
    }


    /**
     * {@hide} Pending approval for public API.
     */
    public void setPerformanceResultsWriter(PerformanceResultsWriter writer) {
        mPerfWriter = writer;
    }

    @Override
    @Override
    protected Class loadSuiteClass(String suiteClassName) throws ClassNotFoundException {
    protected Class loadSuiteClass(String suiteClassName) throws ClassNotFoundException {
        return mContext.getClassLoader().loadClass(suiteClassName);
        return mContext.getClassLoader().loadClass(suiteClassName);
+1 −82
Original line number Original line Diff line number Diff line
@@ -24,9 +24,6 @@ import android.app.Instrumentation;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Debug;
import android.os.Debug;
import android.os.Looper;
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.TestMethod;
import android.test.suitebuilder.TestPredicates;
import android.test.suitebuilder.TestPredicates;
import android.test.suitebuilder.TestSuiteBuilder;
import android.test.suitebuilder.TestSuiteBuilder;
@@ -390,7 +387,6 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu
            WatcherResultPrinter resultPrinter = new WatcherResultPrinter(mTestCount);
            WatcherResultPrinter resultPrinter = new WatcherResultPrinter(mTestCount);
            mTestRunner.addTestListener(new TestPrinter("TestRunner", false));
            mTestRunner.addTestListener(new TestPrinter("TestRunner", false));
            mTestRunner.addTestListener(resultPrinter);
            mTestRunner.addTestListener(resultPrinter);
            mTestRunner.setPerformanceResultsWriter(resultPrinter);
        }
        }
        start();
        start();
    }
    }
@@ -743,15 +739,12 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu
    /**
    /**
     * This class sends status reports back to the IInstrumentationWatcher
     * This class sends status reports back to the IInstrumentationWatcher
     */
     */
    private class WatcherResultPrinter implements TestListener, PerformanceResultsWriter {
    private class WatcherResultPrinter implements TestListener {
        private final Bundle mResultTemplate;
        private final Bundle mResultTemplate;
        Bundle mTestResult;
        Bundle mTestResult;
        int mTestNum = 0;
        int mTestNum = 0;
        int mTestResultCode = 0;
        int mTestResultCode = 0;
        String mTestClass = null;
        String mTestClass = null;
        PerformanceCollector mPerfCollector = new PerformanceCollector();
        boolean mIsTimedTest = false;
        boolean mIncludeDetailedStats = false;


        public WatcherResultPrinter(int numTests) {
        public WatcherResultPrinter(int numTests) {
            mResultTemplate = new Bundle();
            mResultTemplate = new Bundle();
@@ -806,30 +799,6 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu


            sendStatus(REPORT_VALUE_RESULT_START, mTestResult);
            sendStatus(REPORT_VALUE_RESULT_START, mTestResult);
            mTestResultCode = 0;
            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)
         * @see junit.framework.TestListener#endTest(Test)
         */
         */
        public void endTest(Test test) {
        public void endTest(Test test) {
            if (mIsTimedTest && mIncludeDetailedStats) {
                mTestResult.putAll(mPerfCollector.endSnapshot());
            } else if (mIsTimedTest) {
                writeStopTiming(mPerfCollector.stopTiming(""));
            }

            if (mTestResultCode == 0) {
            if (mTestResultCode == 0) {
                mTestResult.putString(Instrumentation.REPORT_KEY_STREAMRESULT, ".");
                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
        // TODO report the end of the cycle
    }
    }
}
}
+0 −38
Original line number Original line Diff line number Diff line
/*
 * 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);
}
+0 −37
Original line number Original line Diff line number Diff line
/*
 * 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;
}