Revert "Add log data capability in JUnit style tests"
Needs rebase
This reverts commit 5c18475d534641b162a3f6e4b9b375ad2d76900c.
Change-Id: I5e225f02cc437cc228de9d28e49bd6fc35be2aad
diff --git a/src/com/android/tradefed/result/JUnit4ResultForwarder.java b/src/com/android/tradefed/result/JUnit4ResultForwarder.java
index 07086e4..d52cc35 100644
--- a/src/com/android/tradefed/result/JUnit4ResultForwarder.java
+++ b/src/com/android/tradefed/result/JUnit4ResultForwarder.java
@@ -16,10 +16,7 @@
package com.android.tradefed.result;
import com.android.ddmlib.testrunner.TestIdentifier;
-import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.LogAnnotation;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.MetricAnnotation;
-import com.android.tradefed.testtype.MetricTestCase.LogHolder;
-import com.android.tradefed.util.StreamUtil;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
@@ -75,14 +72,6 @@
if (a instanceof MetricAnnotation) {
metrics.putAll(((MetricAnnotation) a).mMetrics);
}
- if (a instanceof LogAnnotation) {
- // Log all the logs found.
- for (LogHolder log : ((LogAnnotation) a).mLogs) {
- mListener.testLog(log.mDataName, log.mDataType, log.mDataStream);
- StreamUtil.cancel(log.mDataStream);
- }
- ((LogAnnotation) a).mLogs.clear();
- }
}
}
//description.
diff --git a/src/com/android/tradefed/result/JUnitToInvocationResultForwarder.java b/src/com/android/tradefed/result/JUnitToInvocationResultForwarder.java
index 57d6f5c..b2357d3 100644
--- a/src/com/android/tradefed/result/JUnitToInvocationResultForwarder.java
+++ b/src/com/android/tradefed/result/JUnitToInvocationResultForwarder.java
@@ -92,24 +92,6 @@
}
}
- /**
- * Callback from JUnit3 forwarder in order to get the logs from a test.
- *
- * @param dataName a String descriptive name of the data. e.g. "device_logcat". Note dataName
- * may not be unique per invocation. ie implementers must be able to handle multiple calls
- * with same dataName
- * @param dataType the LogDataType of the data
- * @param dataStream the InputStreamSource of the data. Implementers should call
- * createInputStream to start reading the data, and ensure to close the resulting
- * InputStream when complete. Callers should ensure the source of the data remains present
- * and accessible until the testLog method completes.
- */
- public void testLog(String dataName, LogDataType dataType, InputStreamSource dataStream) {
- for (ITestInvocationListener listener : mInvocationListeners) {
- listener.testLog(dataName, dataType, dataStream);
- }
- }
-
/** {@inheritDoc} */
@Override
public void startTest(Test test) {
diff --git a/src/com/android/tradefed/testtype/DeviceJUnit4ClassRunner.java b/src/com/android/tradefed/testtype/DeviceJUnit4ClassRunner.java
index 8ae3036..eb6601b 100644
--- a/src/com/android/tradefed/testtype/DeviceJUnit4ClassRunner.java
+++ b/src/com/android/tradefed/testtype/DeviceJUnit4ClassRunner.java
@@ -18,9 +18,6 @@
import com.android.tradefed.build.IBuildInfo;
import com.android.tradefed.config.Option;
import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.result.InputStreamSource;
-import com.android.tradefed.result.LogDataType;
-import com.android.tradefed.testtype.MetricTestCase.LogHolder;
import org.junit.rules.ExternalResource;
import org.junit.rules.TestRule;
@@ -115,18 +112,19 @@
*
* @Test
* public void testFoo() {
- * metrics.addTestMetric("key", "value");
- * metrics.addTestMetric("key2", "value2");
+ * metrics.put("key", "value");
+ * metrics.put("key2", "value2");
* }
*
* @Test
* public void testFoo2() {
- * metrics.addTestMetric("key3", "value3");
+ * metrics.put("key3", "value3");
* }
* </pre>
*/
public static class TestMetrics extends ExternalResource {
- private Description mDescription;
+
+ Description mDescription;
private Map<String, String> mMetrics = new HashMap<>();
@Override
@@ -176,64 +174,4 @@
return null;
}
}
-
- /**
- * Implementation of {@link ExternalResource} and {@link TestRule}. This rule allows to log logs
- * during a test case (inside @Test). It guarantees that the log list is cleaned between tests,
- * so the same rule object can be re-used.
- *
- * <pre>Example:
- * @Rule
- * public TestLogData logs = new TestLogData();
- *
- * @Test
- * public void testFoo() {
- * logs.addTestLog("logcat", LogDataType.LOGCAT, new FileInputStreamSource(logcatFile));
- * }
- *
- * @Test
- * public void testFoo2() {
- * logs.addTestLog("logcat2", LogDataType.LOGCAT, new FileInputStreamSource(logcatFile2));
- * }
- * </pre>
- */
- public static class TestLogData extends ExternalResource {
- private Description mDescription;
- private List<LogHolder> mLogs = new ArrayList<>();
-
- @Override
- public Statement apply(Statement base, Description description) {
- mDescription = description;
- return super.apply(base, description);
- }
-
- public final void addTestLog(
- String dataName, LogDataType dataType, InputStreamSource dataStream) {
- mLogs.add(new LogHolder(dataName, dataType, dataStream));
- }
-
- @Override
- protected void after() {
- // we inject a Description with an annotation carrying metrics.
- // We have to go around, since Description cannot be extended and RunNotifier
- // does not give us a lot of flexibility to find our metrics back.
- mDescription.addChild(
- Description.createTestDescription("LOGS", "LOGS", new LogAnnotation(mLogs)));
- }
- }
-
- /** Fake annotation meant to carry logs to the reporters. */
- public static class LogAnnotation implements Annotation {
-
- public List<LogHolder> mLogs = new ArrayList<>();
-
- public LogAnnotation(List<LogHolder> logs) {
- mLogs.addAll(logs);
- }
-
- @Override
- public Class<? extends Annotation> annotationType() {
- return null;
- }
- }
}
diff --git a/src/com/android/tradefed/testtype/DeviceTestResult.java b/src/com/android/tradefed/testtype/DeviceTestResult.java
index 7f57210..48840ac 100644
--- a/src/com/android/tradefed/testtype/DeviceTestResult.java
+++ b/src/com/android/tradefed/testtype/DeviceTestResult.java
@@ -17,8 +17,6 @@
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.result.JUnitToInvocationResultForwarder;
-import com.android.tradefed.testtype.MetricTestCase.LogHolder;
-import com.android.tradefed.util.StreamUtil;
import junit.framework.AssertionFailedError;
import junit.framework.Protectable;
@@ -102,24 +100,10 @@
public void endTest(Test test) {
Map<String, String> metrics = new HashMap<>();
if (test instanceof MetricTestCase) {
- MetricTestCase metricTest = (MetricTestCase) test;
- metrics.putAll(metricTest.mMetrics);
+ metrics.putAll(((MetricTestCase) test).mMetrics);
// reset the metric for next test.
- metricTest.mMetrics = new HashMap<String, String>();
-
- // testLog the log files
- for (TestListener each : cloneListeners()) {
- for (LogHolder log : metricTest.mLogs) {
- if (each instanceof JUnitToInvocationResultForwarder) {
- ((JUnitToInvocationResultForwarder) each)
- .testLog(log.mDataName, log.mDataType, log.mDataStream);
- }
- StreamUtil.cancel(log.mDataStream);
- }
- }
- metricTest.mLogs.clear();
+ ((MetricTestCase) test).mMetrics = new HashMap<String, String>();
}
-
for (TestListener each : cloneListeners()) {
// when possible pass the metrics collected from the tests to our reporters.
if (!metrics.isEmpty() && each instanceof JUnitToInvocationResultForwarder) {
diff --git a/src/com/android/tradefed/testtype/MetricTestCase.java b/src/com/android/tradefed/testtype/MetricTestCase.java
index 0fdfbb6..92a9ade 100644
--- a/src/com/android/tradefed/testtype/MetricTestCase.java
+++ b/src/com/android/tradefed/testtype/MetricTestCase.java
@@ -15,15 +15,9 @@
*/
package com.android.tradefed.testtype;
-import com.android.tradefed.result.InputStreamSource;
-import com.android.tradefed.result.LogDataType;
-import com.android.tradefed.result.SnapshotInputStreamSource;
-
import junit.framework.TestCase;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -34,7 +28,6 @@
public class MetricTestCase extends TestCase {
public Map<String, String> mMetrics = new HashMap<>();
- public List<LogHolder> mLogs = new ArrayList<>();
public MetricTestCase() {
super();
@@ -54,35 +47,4 @@
public final void addTestMetric(String key, String value) {
mMetrics.put(key, value);
}
-
- /**
- * Callback from JUnit3 forwarder in order to get the logs from a test.
- *
- * @param dataName a String descriptive name of the data. e.g. "device_logcat". Note dataName
- * may not be unique per invocation. ie implementers must be able to handle multiple calls
- * with same dataName
- * @param dataType the LogDataType of the data
- * @param dataStream the InputStreamSource of the data. Implementers should call
- * createInputStream to start reading the data, and ensure to close the resulting
- * InputStream when complete. Callers should ensure the source of the data remains present
- * and accessible until the testLog method completes.
- */
- public final void addTestLog(
- String dataName, LogDataType dataType, InputStreamSource dataStream) {
- mLogs.add(new LogHolder(dataName, dataType, dataStream));
- }
-
- /** Structure to hold a log file to be reported. */
- public static class LogHolder {
- public final String mDataName;
- public final LogDataType mDataType;
- public final InputStreamSource mDataStream;
-
- public LogHolder(String dataName, LogDataType dataType, InputStreamSource dataStream) {
- mDataName = dataName;
- mDataType = dataType;
- // We hold a copy because the caller will most likely cancel the stream after.
- mDataStream = new SnapshotInputStreamSource(dataStream.createInputStream());
- }
- }
}
diff --git a/tests/src/com/android/tradefed/testtype/HostTestTest.java b/tests/src/com/android/tradefed/testtype/HostTestTest.java
index 403ce6c..230821f 100644
--- a/tests/src/com/android/tradefed/testtype/HostTestTest.java
+++ b/tests/src/com/android/tradefed/testtype/HostTestTest.java
@@ -21,13 +21,8 @@
import com.android.tradefed.config.OptionSetter;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.result.ByteArrayInputStreamSource;
import com.android.tradefed.result.ITestInvocationListener;
-import com.android.tradefed.result.InputStreamSource;
-import com.android.tradefed.result.LogDataType;
-import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestLogData;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestMetrics;
-import com.android.tradefed.util.StreamUtil;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -112,19 +107,6 @@
}
}
- public static class LogMetricTestCase extends MetricTestCase {
-
- public void testPass() {}
-
- public void testPass2() {
- addTestLog(
- "test2_log",
- LogDataType.TEXT,
- new ByteArrayInputStreamSource("test_log".getBytes()));
- addTestMetric("key2", "metric2");
- }
- }
-
@MyAnnotation
public static class AnotherTestCase extends TestCase {
public AnotherTestCase() {
@@ -177,33 +159,6 @@
/**
* Test class, we have to annotate with full org.junit.Test to avoid name collision in import.
- */
- @RunWith(DeviceJUnit4ClassRunner.class)
- public static class Junit4TestLogClass {
-
- public Junit4TestLogClass() {}
-
- @Rule public TestLogData logs = new TestLogData();
-
- @org.junit.Test
- public void testPass1() {
- ByteArrayInputStreamSource source = new ByteArrayInputStreamSource("test".getBytes());
- logs.addTestLog("TEST", LogDataType.TEXT, source);
- // Always cancel streams.
- StreamUtil.cancel(source);
- }
-
- @org.junit.Test
- public void testPass2() {
- ByteArrayInputStreamSource source = new ByteArrayInputStreamSource("test2".getBytes());
- logs.addTestLog("TEST2", LogDataType.TEXT, source);
- // Always cancel streams.
- StreamUtil.cancel(source);
- }
- }
-
- /**
- * Test class, we have to annotate with full org.junit.Test to avoid name collision in import.
* And with one test marked as Ignored
*/
@RunWith(DeviceJUnit4ClassRunner.class)
@@ -442,31 +397,6 @@
}
/**
- * Test a case where a test use {@link MetricTestCase#addTestLog(String, LogDataType,
- * InputStreamSource)} in order to log data for all the reporters to know about.
- */
- public void testRun_LogMetricTestCase() throws Exception {
- mHostTest.setClassName(LogMetricTestCase.class.getName());
- TestIdentifier test1 = new TestIdentifier(LogMetricTestCase.class.getName(), "testPass");
- TestIdentifier test2 = new TestIdentifier(LogMetricTestCase.class.getName(), "testPass2");
- mListener.testRunStarted((String) EasyMock.anyObject(), EasyMock.eq(2));
- mListener.testStarted(EasyMock.eq(test1));
- // test1 should only have its metrics
- mListener.testEnded(test1, Collections.emptyMap());
- // test2 should only have its metrics
- mListener.testStarted(EasyMock.eq(test2));
- Map<String, String> metric2 = new HashMap<>();
- metric2.put("key2", "metric2");
- mListener.testLog(
- EasyMock.eq("test2_log"), EasyMock.eq(LogDataType.TEXT), EasyMock.anyObject());
- mListener.testEnded(test2, metric2);
- mListener.testRunEnded(EasyMock.anyLong(), (Map<String, String>) EasyMock.anyObject());
- EasyMock.replay(mListener);
- mHostTest.run(mListener);
- EasyMock.verify(mListener);
- }
-
- /**
* Test success case for {@link HostTest#run(ITestInvocationListener)}, where test to run is a
* {@link MetricTestCase} and where an option is set to get extra metrics.
*/
@@ -1622,27 +1552,4 @@
}
EasyMock.verify(mListener);
}
-
- /**
- * Test for {@link HostTest#run(ITestInvocationListener)}, for test with Junit4 style that log
- * some data.
- */
- public void testRun_junit4style_log() throws Exception {
- mHostTest.setClassName(Junit4TestLogClass.class.getName());
- TestIdentifier test1 = new TestIdentifier(Junit4TestLogClass.class.getName(), "testPass1");
- TestIdentifier test2 = new TestIdentifier(Junit4TestLogClass.class.getName(), "testPass2");
- mListener.testRunStarted((String) EasyMock.anyObject(), EasyMock.eq(2));
- mListener.testStarted(EasyMock.eq(test1));
- mListener.testLog(EasyMock.eq("TEST"), EasyMock.eq(LogDataType.TEXT), EasyMock.anyObject());
- mListener.testEnded(test1, Collections.emptyMap());
- mListener.testStarted(EasyMock.eq(test2));
- // test cases do not share logs, only the second test logs are seen.
- mListener.testLog(
- EasyMock.eq("TEST2"), EasyMock.eq(LogDataType.TEXT), EasyMock.anyObject());
- mListener.testEnded(test2, Collections.emptyMap());
- mListener.testRunEnded(EasyMock.anyLong(), EasyMock.anyObject());
- EasyMock.replay(mListener);
- mHostTest.run(mListener);
- EasyMock.verify(mListener);
- }
}