Merge \"CTS: Replace deviceSerial with startTime as MetricsStore key.\" into nyc-dev
am: 6a2a6975fe
Change-Id: I93ce754df192136790ef098309dc9826890bbb46
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
index 4de108a..1335fc6 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
@@ -284,8 +284,8 @@
}
} else {
// host test should be checked into MetricsStore.
- report = MetricsStore.removeResult(
- mDeviceSerial, mCurrentModuleResult.getAbi(), test.toString());
+ report = MetricsStore.removeResult(mBuildHelper.getBuildInfo(),
+ mCurrentModuleResult.getAbi(), test.toString());
}
if (mCurrentResult.getResultStatus() == null) {
// Only claim that we passed when we're certain our result was
diff --git a/common/host-side/util/src/com/android/compatibility/common/util/MetricsReportLog.java b/common/host-side/util/src/com/android/compatibility/common/util/MetricsReportLog.java
index ad7d098..19524ce 100644
--- a/common/host-side/util/src/com/android/compatibility/common/util/MetricsReportLog.java
+++ b/common/host-side/util/src/com/android/compatibility/common/util/MetricsReportLog.java
@@ -16,6 +16,7 @@
package com.android.compatibility.common.util;
+import com.android.tradefed.build.IBuildInfo;
import com.android.tradefed.util.FileUtil;
import java.io.File;
@@ -26,9 +27,9 @@
* A {@link ReportLog} that can be used with the in memory metrics store used for host side metrics.
*/
public final class MetricsReportLog extends ReportLog {
- private final String mDeviceSerial;
private final String mAbi;
private final String mClassMethodName;
+ private final IBuildInfo mBuildInfo;
// TODO(mishragaurav): Remove default names and constructor after fixing b/27950009.
private static final String DEFAULT_REPORT_LOG_NAME = "DefaultHostTestMetrics";
@@ -39,39 +40,39 @@
private ReportLogHostInfoStore store;
/**
- * @param deviceSerial serial number of the device
- * @param abi abi the test was run on
+ * @param buildInfo the test build info.
+ * @param abi abi the test was run on.
* @param classMethodName class name and method name of the test in class#method format.
* Note that ReportLog.getClassMethodNames() provide this.
*/
- public MetricsReportLog(String deviceSerial, String abi, String classMethodName) {
- this(deviceSerial, abi, classMethodName, DEFAULT_REPORT_LOG_NAME, DEFAULT_STREAM_NAME);
+ public MetricsReportLog(IBuildInfo buildInfo, String abi, String classMethodName) {
+ this(buildInfo, abi, classMethodName, DEFAULT_REPORT_LOG_NAME, DEFAULT_STREAM_NAME);
}
/**
- * @param deviceSerial serial number of the device
- * @param abi abi the test was run on
+ * @param buildInfo the test build info.
+ * @param abi abi the test was run on.
* @param classMethodName class name and method name of the test in class#method format.
* Note that ReportLog.getClassMethodNames() provide this.
* @param reportLogName the name of the report log file. Metrics will be written out to this.
*/
- public MetricsReportLog(String deviceSerial, String abi, String classMethodName,
+ public MetricsReportLog(IBuildInfo buildInfo, String abi, String classMethodName,
String reportLogName) {
- this(deviceSerial, abi, classMethodName, reportLogName, DEFAULT_STREAM_NAME);
+ this(buildInfo, abi, classMethodName, reportLogName, DEFAULT_STREAM_NAME);
}
/**
- * @param deviceSerial serial number of the device
- * @param abi abi the test was run on
+ * @param buildInfo the test build info.
+ * @param abi abi the test was run on.
* @param classMethodName class name and method name of the test in class#method format.
* Note that ReportLog.getClassMethodNames() provide this.
* @param reportLogName the name of the report log file. Metrics will be written out to this.
* @param streamName the key for the JSON object of the set of metrics to be logged.
*/
- public MetricsReportLog(String deviceSerial, String abi, String classMethodName,
+ public MetricsReportLog(IBuildInfo buildInfo, String abi, String classMethodName,
String reportLogName, String streamName) {
super(reportLogName, streamName);
- mDeviceSerial = deviceSerial;
+ mBuildInfo = buildInfo;
mAbi = abi;
mClassMethodName = classMethodName;
try {
@@ -283,6 +284,6 @@
} catch (IOException e) {
e.printStackTrace();
}
- MetricsStore.storeResult(mDeviceSerial, mAbi, mClassMethodName, this);
+ MetricsStore.storeResult(mBuildInfo, mAbi, mClassMethodName, this);
}
}
diff --git a/common/host-side/util/src/com/android/compatibility/common/util/MetricsStore.java b/common/host-side/util/src/com/android/compatibility/common/util/MetricsStore.java
index efe7182..5f70727 100644
--- a/common/host-side/util/src/com/android/compatibility/common/util/MetricsStore.java
+++ b/common/host-side/util/src/com/android/compatibility/common/util/MetricsStore.java
@@ -16,6 +16,8 @@
package com.android.compatibility.common.util;
+import com.android.tradefed.build.IBuildInfo;
+
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -28,34 +30,38 @@
private static final ConcurrentHashMap<String, ReportLog> mMap =
new ConcurrentHashMap<String, ReportLog>();
+ private static final String START_TIME_TAG = "START_TIME_MS";
+
private MetricsStore() {}
/**
* Stores a result. Existing result with the same key will be replaced.
- * Note that key is generated in the form of device_serial#class#method name.
+ * Note that key is generated in the form of start_time#class#method name.
* So there should be no concurrent test for the same (serial, class, method).
- * @param deviceSerial
+ * @param buildInfo
* @param abi
* @param classMethodName
* @param reportLog Contains the result to be stored
*/
- public static void storeResult(
- String deviceSerial, String abi, String classMethodName, ReportLog reportLog) {
- mMap.put(generateTestKey(deviceSerial, abi, classMethodName), reportLog);
+ public static void storeResult(IBuildInfo buildInfo, String abi, String classMethodName,
+ ReportLog reportLog) {
+ String startTime = buildInfo.getBuildAttributes().get(START_TIME_TAG);
+ mMap.put(generateTestKey(startTime, abi, classMethodName), reportLog);
}
/**
* retrieves a metric result for the given condition and remove it from the internal
* storage. If there is no result for the given condition, it will return null.
*/
- public static ReportLog removeResult(String deviceSerial, String abi, String classMethodName) {
- return mMap.remove(generateTestKey(deviceSerial, abi, classMethodName));
+ public static ReportLog removeResult(IBuildInfo buildInfo, String abi, String classMethodName) {
+ String startTime = buildInfo.getBuildAttributes().get(START_TIME_TAG);
+ return mMap.remove(generateTestKey(startTime, abi, classMethodName));
}
/**
- * @return test key in the form of device_serial#abi#class_name#method_name
+ * @return test key in the form of start_time#abi#class_name#method_name
*/
- private static String generateTestKey(String deviceSerial, String abi, String classMethodName) {
- return String.format("%s#%s#%s", deviceSerial, abi, classMethodName);
+ private static String generateTestKey(String startTime, String abi, String classMethodName) {
+ return String.format("%s#%s#%s", startTime, abi, classMethodName);
}
}
diff --git a/common/host-side/util/tests/src/com/android/compatibility/common/util/HostUnitTests.java b/common/host-side/util/tests/src/com/android/compatibility/common/util/HostUnitTests.java
index 8cf1e3f..4b47bf3 100644
--- a/common/host-side/util/tests/src/com/android/compatibility/common/util/HostUnitTests.java
+++ b/common/host-side/util/tests/src/com/android/compatibility/common/util/HostUnitTests.java
@@ -28,7 +28,6 @@
public HostUnitTests() {
super();
addTestSuite(DynamicConfigHandlerTest.class);
- addTestSuite(MetricsStoreTest.class);
}
public static Test suite() {
diff --git a/common/host-side/util/tests/src/com/android/compatibility/common/util/MetricsStoreTest.java b/common/host-side/util/tests/src/com/android/compatibility/common/util/MetricsStoreTest.java
deleted file mode 100644
index 944cc43..0000000
--- a/common/host-side/util/tests/src/com/android/compatibility/common/util/MetricsStoreTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2015 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 com.android.compatibility.common.util;
-
-import junit.framework.TestCase;
-
-/**
- * Unit tests for {@link MetricsStore}
- */
-public class MetricsStoreTest extends TestCase {
-
- private static final String DEVICE_SERIAL = "DEVICE_SERIAL";
- private static final String ABI = "ABI";
- private static final String CLASSMETHOD_NAME = "CLASSMETHOD_NAME";
-
- private static final double[] VALUES = new double[] {1, 11, 21, 1211, 111221};
-
- private ReportLog mReportLog;
-
- @Override
- protected void setUp() throws Exception {
- this.mReportLog = new ReportLog();
- }
-
- public void testStoreAndRemove() {
- mReportLog.setSummary("Sample Summary", 1.0, ResultType.HIGHER_BETTER, ResultUnit.BYTE);
- mReportLog.addValues("Details", VALUES, ResultType.NEUTRAL, ResultUnit.FPS);
- MetricsStore.storeResult(DEVICE_SERIAL, ABI, CLASSMETHOD_NAME, mReportLog);
-
- ReportLog reportLog = MetricsStore.removeResult(DEVICE_SERIAL, ABI, CLASSMETHOD_NAME);
- assertSame(mReportLog, reportLog);
- assertNull(MetricsStore.removeResult("blah", ABI, CLASSMETHOD_NAME));
- }
-
-}
diff --git a/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java b/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java
index 5730ee0..7cc8b20 100644
--- a/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java
+++ b/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java
@@ -138,7 +138,8 @@
Stat.StatResult stat = Stat.getStat(result);
// Get the report for this test and add the results to record.
String streamName = "test_transfer_time_metrics";
- MetricsReportLog report = new MetricsReportLog(mDevice.getSerialNumber(), mAbi.getName(),
+ MetricsReportLog report = new MetricsReportLog(
+ mBuildHelper.getBuildInfo(), mAbi.getName(),
String.format("%s#testTransferTime", getClass().getCanonicalName()),
REPORT_LOG_NAME, streamName);
report.addValues("times", result, ResultType.LOWER_BETTER, ResultUnit.MS);
diff --git a/hostsidetests/ui/src/android/ui/cts/InstallTimeTest.java b/hostsidetests/ui/src/android/ui/cts/InstallTimeTest.java
index 5acb17e..ee9e7c6 100644
--- a/hostsidetests/ui/src/android/ui/cts/InstallTimeTest.java
+++ b/hostsidetests/ui/src/android/ui/cts/InstallTimeTest.java
@@ -74,7 +74,7 @@
public void testInstallTime() throws Exception {
String streamName = "test_install_time";
- MetricsReportLog report = new MetricsReportLog(mDevice.getSerialNumber(), mAbi.getName(),
+ MetricsReportLog report = new MetricsReportLog(mBuild, mAbi.getName(),
String.format("%s#%s", getClass().getName(), "testInstallTime"), REPORT_LOG_NAME,
streamName);
final int NUMBER_REPEAT = 10;
diff --git a/hostsidetests/ui/src/android/ui/cts/TaskSwitchingTest.java b/hostsidetests/ui/src/android/ui/cts/TaskSwitchingTest.java
index 4af40a2..409264e 100644
--- a/hostsidetests/ui/src/android/ui/cts/TaskSwitchingTest.java
+++ b/hostsidetests/ui/src/android/ui/cts/TaskSwitchingTest.java
@@ -103,7 +103,7 @@
fail(result.getRunFailureMessage());
}
assertNotNull("no performance data", mReport);
- MetricsStore.storeResult(mDevice.getSerialNumber(), mAbi.getName(),
+ MetricsStore.storeResult(mBuild, mAbi.getName(),
String.format("%s#%s", getClass().getName(), "testTaskSwitching"), mReport);
}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/TestPackageResult.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/TestPackageResult.java
index 2229671..60d8408 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/TestPackageResult.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/TestPackageResult.java
@@ -254,9 +254,6 @@
} catch (XmlPullParserException | IOException e) {
e.printStackTrace();
}
- } else {
- // host test should be checked into MetricsStore.
- report = MetricsStore.removeResult(mDeviceSerial, getAbi(), test.toString());
}
Test result = findTest(test);
if (report != null && !result.getResult().equals(CtsTestStatus.FAIL)) {
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/util/HostReportLog.java b/tools/tradefed-host/src/com/android/cts/tradefed/util/HostReportLog.java
index f72b097..7de3c10 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/util/HostReportLog.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/util/HostReportLog.java
@@ -18,6 +18,7 @@
import com.android.compatibility.common.util.MetricsReportLog;
import com.android.cts.util.ReportLog;
+import com.android.tradefed.build.IBuildInfo;
/**
* ReportLog for host tests
@@ -28,13 +29,13 @@
@Deprecated
public class HostReportLog extends ReportLog {
/**
- * @param deviceSerial serial number of the device
- * @param abiName the name of the ABI on which the test was run
+ * @param buildInfo the test build info.
+ * @param abiName the name of the ABI on which the test was run.
* @param classMethodName class name and method name of the test in class#method format.
* Note that ReportLog.getClassMethodNames() provide this.
*/
- public HostReportLog(String deviceSerial, String abiName, String classMethodName) {
- super(new MetricsReportLog(deviceSerial, abiName, classMethodName));
+ public HostReportLog(IBuildInfo buildInfo, String abiName, String classMethodName) {
+ super(new MetricsReportLog(buildInfo, abiName, classMethodName));
}
public void deliverReportToHost() {