aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaggie White <maggiewhite@google.com>2019-07-25 23:59:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-07-25 23:59:08 +0000
commit58cf4c1bf8a9c779b7cbf0c6a58055f5fe51f4cf (patch)
treea411ba5d3c25a54e46d0090a5656a08d5cb8e2c1
parent947b30170277c75feee5c5a76bfacad0af037057 (diff)
parent63e301d7050f8e92d0051dad07f7c3162f62a6d8 (diff)
downloadtradefederation-58cf4c1bf8a9c779b7cbf0c6a58055f5fe51f4cf.tar.gz
Merge changes from topic "bits-collector-qt-r1-dev" into qt-r1-dev
* changes: Add onTestEnd with test description Add .7z and .7z.bits as supported tradefed file types
-rw-r--r--src/com/android/tradefed/device/metric/BaseDeviceMetricCollector.java11
-rw-r--r--src/com/android/tradefed/device/metric/IMetricCollector.java14
-rw-r--r--src/com/android/tradefed/result/LogDataType.java2
-rw-r--r--tests/src/com/android/tradefed/device/metric/BaseDeviceMetricCollectorTest.java45
4 files changed, 71 insertions, 1 deletions
diff --git a/src/com/android/tradefed/device/metric/BaseDeviceMetricCollector.java b/src/com/android/tradefed/device/metric/BaseDeviceMetricCollector.java
index 1e4d16ca0..10885cf2f 100644
--- a/src/com/android/tradefed/device/metric/BaseDeviceMetricCollector.java
+++ b/src/com/android/tradefed/device/metric/BaseDeviceMetricCollector.java
@@ -130,6 +130,15 @@ public class BaseDeviceMetricCollector implements IMetricCollector {
// Does nothing
}
+ @Override
+ public void onTestEnd(
+ DeviceMetricData testData,
+ final Map<String, Metric> currentTestCaseMetrics,
+ TestDescription test) {
+ // Call the default implementation of onTestEnd if not overridden
+ onTestEnd(testData, currentTestCaseMetrics);
+ }
+
/** =================================== */
/** Invocation Listeners for forwarding */
@Override
@@ -233,7 +242,7 @@ public class BaseDeviceMetricCollector implements IMetricCollector {
TestDescription test, long endTime, HashMap<String, Metric> testMetrics) {
if (!mSkipTestCase) {
try {
- onTestEnd(mTestData, testMetrics);
+ onTestEnd(mTestData, testMetrics, test);
mTestData.addToMetrics(testMetrics);
} catch (Throwable t) {
// Prevent exception from messing up the status reporting.
diff --git a/src/com/android/tradefed/device/metric/IMetricCollector.java b/src/com/android/tradefed/device/metric/IMetricCollector.java
index 387e53678..1c8b84fad 100644
--- a/src/com/android/tradefed/device/metric/IMetricCollector.java
+++ b/src/com/android/tradefed/device/metric/IMetricCollector.java
@@ -113,4 +113,18 @@ public interface IMetricCollector extends ITestInvocationListener, IDisableable
*/
public void onTestEnd(
DeviceMetricData testData, final Map<String, Metric> currentTestCaseMetrics);
+
+ /**
+ * Callback when a test case is ended. This should be the time for clean up.
+ *
+ * @param testData the {@link DeviceMetricData} holding the data for the test case. Will be the
+ * same object as during {@link #onTestStart(DeviceMetricData)}.
+ * @param currentTestCaseMetrics the current map of metrics passed to {@link
+ * #testEnded(TestDescription, Map)}.
+ * @param test the {@link TestDescription} of the test case in progress.
+ */
+ public void onTestEnd(
+ DeviceMetricData testData,
+ final Map<String, Metric> currentTestCaseMetrics,
+ TestDescription test);
}
diff --git a/src/com/android/tradefed/result/LogDataType.java b/src/com/android/tradefed/result/LogDataType.java
index 9589c907d..2024bf17b 100644
--- a/src/com/android/tradefed/result/LogDataType.java
+++ b/src/com/android/tradefed/result/LogDataType.java
@@ -27,6 +27,8 @@ public enum LogDataType {
MP4("mp4", "video/mp4", true, false),
EAR("ear", "application/octet-stream", true, false),
ZIP("zip", "application/zip", true, false),
+ SEVEN_Z("7z", "application/x-7z-compressed", true, false),
+ BITS("bits", "application/octet-stream", true, false),
JPEG("jpeg", "image/jpeg", true, false),
TAR_GZ("tar.gz", "application/gzip", true, false),
GZIP("gz", "application/gzip", true, false),
diff --git a/tests/src/com/android/tradefed/device/metric/BaseDeviceMetricCollectorTest.java b/tests/src/com/android/tradefed/device/metric/BaseDeviceMetricCollectorTest.java
index dd6bde56a..70bc6b7f2 100644
--- a/tests/src/com/android/tradefed/device/metric/BaseDeviceMetricCollectorTest.java
+++ b/tests/src/com/android/tradefed/device/metric/BaseDeviceMetricCollectorTest.java
@@ -485,4 +485,49 @@ public class BaseDeviceMetricCollectorTest {
assertTrue(allValues.get(2).containsKey("onteststart"));
assertTrue(allValues.get(2).containsKey("ontestend"));
}
+
+ /**
+ * Test that onTestEnd with TestDescription formal supercedes the method signature without a
+ * TestDescription.
+ */
+ @Test
+ public void testOnTestEndWithTestDescription() throws Exception {
+ mBase =
+ new TwoMetricsBaseCollector() {
+ @Override
+ public void onTestEnd(
+ DeviceMetricData testData,
+ final Map<String, Metric> currentTestCaseMetrics,
+ TestDescription test) {
+ testData.addMetric(
+ test.getTestName(),
+ Metric.newBuilder()
+ .setMeasurements(
+ Measurements.newBuilder()
+ .setSingleString("value1")));
+ }
+ };
+ mBase.init(mContext, mMockListener);
+ mBase.invocationStarted(mContext);
+ mBase.testRunStarted("testRun", 1);
+ TestDescription test = new TestDescription("class", "method");
+ mBase.testStarted(test);
+ mBase.testEnded(test, new HashMap<String, Metric>());
+ mBase.testRunEnded(0L, new HashMap<String, Metric>());
+ mBase.invocationEnded(0L);
+
+ Mockito.verify(mMockListener, times(1)).invocationStarted(Mockito.any());
+ Mockito.verify(mMockListener, times(1)).testRunStarted("testRun", 1);
+ Mockito.verify(mMockListener, times(1)).testStarted(Mockito.eq(test), Mockito.anyLong());
+ Mockito.verify(mMockListener, times(1))
+ .testEnded(Mockito.eq(test), Mockito.anyLong(), mCapturedMetrics.capture());
+
+ Mockito.verify(mMockListener, times(1))
+ .testRunEnded(Mockito.anyLong(), (HashMap<String, Metric>) Mockito.any());
+
+ List<HashMap<String, Metric>> allValues = mCapturedMetrics.getAllValues();
+ assertTrue(allValues.get(0).containsKey("onteststart"));
+ assertTrue(allValues.get(0).containsKey("method"));
+ assertTrue(!allValues.get(0).containsKey("ontestend"));
+ }
}