Merge "CTS Test Metrics: Remove Details from result xml." into nyc-dev
am: 79ca18845a
* commit '79ca18845a900db79abea5c301d67c65edf02e95':
CTS Test Metrics: Remove Details from result xml.
Change-Id: I9fbb65f9a19b1840523da56f7196acc9a94faab3
diff --git a/common/util/src/com/android/compatibility/common/util/MetricsXmlSerializer.java b/common/util/src/com/android/compatibility/common/util/MetricsXmlSerializer.java
index 0f4b597..a7b1153 100644
--- a/common/util/src/com/android/compatibility/common/util/MetricsXmlSerializer.java
+++ b/common/util/src/com/android/compatibility/common/util/MetricsXmlSerializer.java
@@ -38,7 +38,6 @@
return;
}
ReportLog.Metric summary = reportLog.getSummary();
- List<ReportLog.Metric> detailedMetrics = reportLog.getDetailedMetrics();
// <Summary message="Average" scoreType="lower_better" unit="ms">195.2</Summary>
if (summary != null) {
mXmlSerializer.startTag(null, "Summary");
@@ -48,24 +47,5 @@
mXmlSerializer.text(Double.toString(summary.getValues()[0]));
mXmlSerializer.endTag(null, "Summary");
}
-
- if (!detailedMetrics.isEmpty()) {
- mXmlSerializer.startTag(null, "Details");
- for (ReportLog.Metric result : detailedMetrics) {
- mXmlSerializer.startTag(null, "ValueArray");
- mXmlSerializer.attribute(null, "source", result.getSource());
- mXmlSerializer.attribute(null, "message", result.getMessage());
- mXmlSerializer.attribute(null, "scoreType", result.getType().toReportString());
- mXmlSerializer.attribute(null, "unit", result.getUnit().toReportString());
-
- for (double value : result.getValues()) {
- mXmlSerializer.startTag(null, "Value");
- mXmlSerializer.text(Double.toString(value));
- mXmlSerializer.endTag(null, "Value");
- }
- mXmlSerializer.endTag(null, "ValueArray");
- }
- mXmlSerializer.endTag(null, "Details");
- }
}
}
\ No newline at end of file
diff --git a/common/util/src/com/android/compatibility/common/util/ReportLog.java b/common/util/src/com/android/compatibility/common/util/ReportLog.java
index 76ff1cd..08b1d76 100644
--- a/common/util/src/com/android/compatibility/common/util/ReportLog.java
+++ b/common/util/src/com/android/compatibility/common/util/ReportLog.java
@@ -38,7 +38,6 @@
private static final String TYPE = "org.kxml2.io.KXmlParser,org.kxml2.io.KXmlSerializer";
// XML constants
- private static final String DETAIL_TAG = "Detail";
private static final String METRIC_TAG = "Metric";
private static final String MESSAGE_ATTR = "message";
private static final String SCORETYPE_ATTR = "score_type";
@@ -51,9 +50,7 @@
protected Metric mSummary;
protected String mReportLogName;
protected String mStreamName;
- protected final List<Metric> mDetails = new ArrayList<>();
- // TODO(mishragaurav): Remove Metric class after removing details from result report.
public static class Metric implements Serializable {
private static final int MAX_SOURCE_LENGTH = 200;
private static final int MAX_MESSAGE_LENGTH = 200;
@@ -174,18 +171,11 @@
mStreamName = streamName;
}
- /* package */ void addMetric(Metric elem) {
- mDetails.add(elem);
- }
-
- // TODO(mishragaurav): Make addValue functions no-op after removing details from report.
-
/**
* Adds a double array of metrics to the report.
*/
public void addValues(String message, double[] values, ResultType type, ResultUnit unit) {
- addMetric(new Metric(Stacktrace.getTestCallerClassMethodNameLineNumber(),
- message, values, type, unit));
+ // Do nothing. Subclasses may implement using InfoStore to write metrics to files.
}
/**
@@ -193,15 +183,14 @@
*/
public void addValues(String source, String message, double[] values, ResultType type,
ResultUnit unit) {
- addMetric(new Metric(source, message, values, type, unit));
+ // Do nothing. Subclasses may implement using InfoStore to write metrics to files.
}
/**
* Adds a double metric to the report.
*/
public void addValue(String message, double value, ResultType type, ResultUnit unit) {
- addMetric(new Metric(Stacktrace.getTestCallerClassMethodNameLineNumber(), message,
- value, type, unit));
+ // Do nothing. Subclasses may implement using InfoStore to write metrics to files.
}
/**
@@ -209,7 +198,7 @@
*/
public void addValue(String source, String message, double value, ResultType type,
ResultUnit unit) {
- addMetric(new Metric(source, message, value, type, unit));
+ // Do nothing. Subclasses may implement using InfoStore to write metrics to files.
}
/**
@@ -303,10 +292,6 @@
return mSummary;
}
- public List<Metric> getDetailedMetrics() {
- return new ArrayList<Metric>(mDetails);
- }
-
/**
* Serializes a given {@link ReportLog} to a String.
* @throws XmlPullParserException
@@ -338,20 +323,11 @@
throw new IllegalArgumentException("Metrics reports was null");
}
Metric summary = reportLog.getSummary();
- List<Metric> detailedMetrics = reportLog.getDetailedMetrics();
- if (summary == null) {
- throw new IllegalArgumentException("Metrics reports must have a summary");
- }
- serializer.startTag(null, SUMMARY_TAG);
- summary.serialize(serializer);
- serializer.endTag(null, SUMMARY_TAG);
-
- if (!detailedMetrics.isEmpty()) {
- serializer.startTag(null, DETAIL_TAG);
- for (Metric elem : detailedMetrics) {
- elem.serialize(serializer);
- }
- serializer.endTag(null, DETAIL_TAG);
+ // Summary is optional. Details are not included in result report.
+ if (summary != null) {
+ serializer.startTag(null, SUMMARY_TAG);
+ summary.serialize(serializer);
+ serializer.endTag(null, SUMMARY_TAG);
}
}
@@ -361,13 +337,22 @@
* @throws IOException
*/
public static ReportLog parse(String result) throws XmlPullParserException, IOException {
- if (result == null || result.trim().isEmpty()) {
- throw new IllegalArgumentException("Metrics string was empty");
+ if (result == null){
+ throw new IllegalArgumentException("Metrics string was null");
+ }
+ if (result.trim().isEmpty()) {
+ // Empty report.
+ return new ReportLog();
}
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(new ByteArrayInputStream(result.getBytes(ENCODING)), ENCODING);
- parser.nextTag();
+ try {
+ parser.nextTag();
+ } catch (XmlPullParserException e) {
+ // Empty Report.
+ return new ReportLog();
+ }
return parse(parser);
}
@@ -384,18 +369,6 @@
report.setSummary(Metric.parse(parser));
parser.nextTag();
parser.require(XmlPullParser.END_TAG, null, SUMMARY_TAG);
- try {
- parser.nextTag();
- } catch (XmlPullParserException e) {
- // Report doesn't have any details, it's ok
- return report;
- }
- if (parser.getName().equals(DETAIL_TAG)) {
- while (parser.nextTag() == XmlPullParser.START_TAG) {
- report.addMetric(Metric.parse(parser));
- }
- parser.require(XmlPullParser.END_TAG, null, DETAIL_TAG);
- }
return report;
}
}
diff --git a/common/util/src/com/android/compatibility/common/util/ResultHandler.java b/common/util/src/com/android/compatibility/common/util/ResultHandler.java
index 655add8..8e435d8 100644
--- a/common/util/src/com/android/compatibility/common/util/ResultHandler.java
+++ b/common/util/src/com/android/compatibility/common/util/ResultHandler.java
@@ -53,7 +53,6 @@
private static final String BUILD_PRODUCT = "build_product";
private static final String BUILD_TAG = "Build";
private static final String CASE_TAG = "TestCase";
- private static final String DETAIL_TAG = "Detail";
private static final String DEVICES_ATTR = "devices";
private static final String END_DISPLAY_TIME_ATTR = "end_display";
private static final String END_TIME_ATTR = "end";
@@ -172,11 +171,7 @@
parser.nextTag();
} else {
test.setReportLog(ReportLog.parse(parser));
- // Details are optional; parser is at next tag if report log
- // does not have details.
- if (parser.getName().equals(DETAIL_TAG)) {
- parser.nextTag();
- }
+ parser.nextTag();
}
}
parser.require(XmlPullParser.END_TAG, NS, TEST_TAG);
diff --git a/common/util/tests/src/com/android/compatibility/common/util/MetricsXmlSerializerTest.java b/common/util/tests/src/com/android/compatibility/common/util/MetricsXmlSerializerTest.java
index c6f3ec1..dbbb479 100644
--- a/common/util/tests/src/com/android/compatibility/common/util/MetricsXmlSerializerTest.java
+++ b/common/util/tests/src/com/android/compatibility/common/util/MetricsXmlSerializerTest.java
@@ -34,18 +34,7 @@
private static final double[] VALUES = new double[] {1, 11, 21, 1211, 111221};
private static final String HEADER = "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>";
private static final String EXPECTED_XML = HEADER
- + "<Summary message=\"Sample\" scoreType=\"higher_better\" unit=\"byte\">1.0</Summary>"
- + "<Details>"
- + "<ValueArray source=\"com.android.compatibility.common.util."
- + "MetricsXmlSerializerTest#testSerialize:84\""
- + " message=\"Details\" scoreType=\"neutral\" unit=\"fps\">"
- + "<Value>1.0</Value>"
- + "<Value>11.0</Value>"
- + "<Value>21.0</Value>"
- + "<Value>1211.0</Value>"
- + "<Value>111221.0</Value>"
- + "</ValueArray>"
- + "</Details>";
+ + "<Summary message=\"Sample\" scoreType=\"higher_better\" unit=\"byte\">1.0</Summary>";
private LocalReportLog mLocalReportLog;
private MetricsXmlSerializer mMetricsXmlSerializer;
diff --git a/common/util/tests/src/com/android/compatibility/common/util/ReportLogTest.java b/common/util/tests/src/com/android/compatibility/common/util/ReportLogTest.java
index 0b4a639..c8d4682 100644
--- a/common/util/tests/src/com/android/compatibility/common/util/ReportLogTest.java
+++ b/common/util/tests/src/com/android/compatibility/common/util/ReportLogTest.java
@@ -42,18 +42,7 @@
" <Value>1.0</Value>\r\n" +
" </Metric>\r\n" +
"</Summary>";
- private static final String DETAIL_XML =
- "<Detail>\r\n" +
- " <Metric source=\"com.android.compatibility.common.util.ReportLogTest#%s\" message=\"Details\" score_type=\"neutral\" score_unit=\"fps\">\r\n" +
- " <Value>0.1</Value>\r\n" +
- " <Value>124.0</Value>\r\n" +
- " <Value>4736.0</Value>\r\n" +
- " <Value>835.683</Value>\r\n" +
- " <Value>98.0</Value>\r\n" +
- " <Value>395.0</Value>\r\n" +
- " </Metric>\r\n" +
- "</Detail>";
- private static final String FULL_XML = SUMMARY_XML + "\r\n" + DETAIL_XML;
+ private static final String FULL_XML = SUMMARY_XML;
private ReportLog mReportLog;
@@ -72,34 +61,24 @@
}
public void testSerialize_noData() throws Exception {
- try {
- ReportLog.serialize(mReportLog);
- fail("Expected IllegalArgumentException when serializing an empty report");
- } catch (IllegalArgumentException e) {
- // Expected
- }
+ ReportLog.serialize(mReportLog);
}
public void testSerialize_summaryOnly() throws Exception {
mReportLog.setSummary("Sample", 1.0, ResultType.HIGHER_BETTER, ResultUnit.BYTE);
- assertEquals(String.format(SUMMARY_XML, "testSerialize_summaryOnly:84"),
+ assertEquals(String.format(SUMMARY_XML, "testSerialize_summaryOnly:68"),
ReportLog.serialize(mReportLog));
}
public void testSerialize_detailOnly() throws Exception {
mReportLog.addValues("Details", VALUES, ResultType.NEUTRAL, ResultUnit.FPS);
- try {
- ReportLog.serialize(mReportLog);
- fail("Expected IllegalArgumentException when serializing report without summary");
- } catch(IllegalArgumentException e) {
- // Expected
- }
+ assertEquals(HEADER_XML, ReportLog.serialize(mReportLog));
}
public void testSerialize_full() throws Exception {
mReportLog.setSummary("Sample", 1.0, ResultType.HIGHER_BETTER, ResultUnit.BYTE);
mReportLog.addValues("Details", VALUES, ResultType.NEUTRAL, ResultUnit.FPS);
- assertEquals(String.format(FULL_XML, "testSerialize_full:100", "testSerialize_full:101"),
+ assertEquals(String.format(FULL_XML, "testSerialize_full:79"),
ReportLog.serialize(mReportLog));
}
@@ -113,12 +92,8 @@
}
public void testParse_noData() throws Exception {
- try {
- ReportLog.parse(HEADER_XML);
- fail("Expected XmlPullParserException when passing a report with no content");
- } catch(XmlPullParserException e) {
- // Expected
- }
+ ReportLog report = ReportLog.parse(HEADER_XML);
+ assertNull(report.getSummary());
}
public void testParse_summaryOnly() throws Exception {
@@ -127,23 +102,10 @@
assertEquals("Sample", report.getSummary().getMessage());
}
- public void testParse_detailOnly() throws Exception {
- try {
- ReportLog.parse(String.format(DETAIL_XML, "testParse_detailOnly:132"));
- fail("Expected XmlPullParserException when serializing report without summary");
- } catch (XmlPullParserException e) {
- // Expected
- }
- }
-
public void testParse_full() throws Exception {
- ReportLog report = ReportLog.parse(String.format(FULL_XML, "testParse_full:140",
- "testParse_full:138"));
+ ReportLog report = ReportLog.parse(String.format(FULL_XML, "testParse_full:140"));
assertNotNull(report);
assertEquals("Sample", report.getSummary().getMessage());
- List<Metric> details = report.getDetailedMetrics();
- assertEquals(1, details.size());
- assertEquals("Details", details.get(0).getMessage());
}
public void testLimits_source() throws Exception {
diff --git a/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java b/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java
index c88fe8e..3009ec4 100644
--- a/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java
+++ b/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java
@@ -122,13 +122,6 @@
" <Value>%s</Value>\n" +
" </Metric>\n" +
" </Summary>\n" +
- " <Detail>\n" +
- " <Metric source=\"%s\" message=\"%s\" score_type=\"%s\" score_unit=\"%s\">\n" +
- " <Value>%s</Value>\n" +
- " <Value>%s</Value>\n" +
- " <Value>%s</Value>\n" +
- " </Metric>\n" +
- " </Detail>\n" +
" </Test>\n";
private File resultsDir = null;
private File resultDir = null;
@@ -173,10 +166,6 @@
ReportLog.Metric summary = new ReportLog.Metric(SUMMARY_SOURCE, SUMMARY_MESSAGE,
SUMMARY_VALUE, ResultType.HIGHER_BETTER, ResultUnit.SCORE);
report.setSummary(summary);
- ReportLog.Metric details = new ReportLog.Metric(DETAILS_SOURCE, DETAILS_MESSAGE,
- new double[] {DETAILS_VALUE_1, DETAILS_VALUE_2, DETAILS_VALUE_3},
- ResultType.LOWER_BETTER, ResultUnit.MS);
- report.addMetric(details);
moduleBTest4.setReportLog(report);
// Serialize to file
@@ -332,14 +321,5 @@
assertEquals("Incorrect unit", ResultUnit.SCORE, summary.getUnit());
assertTrue("Incorrect values", Arrays.equals(new double[] { SUMMARY_VALUE },
summary.getValues()));
- List<ReportLog.Metric> details = report.getDetailedMetrics();
- assertEquals("Expected 1 report detail", 1, details.size());
- ReportLog.Metric detail = details.get(0);
- assertEquals("Incorrect source", DETAILS_SOURCE, detail.getSource());
- assertEquals("Incorrect message", DETAILS_MESSAGE, detail.getMessage());
- assertEquals("Incorrect type", ResultType.LOWER_BETTER, detail.getType());
- assertEquals("Incorrect unit", ResultUnit.MS, detail.getUnit());
- assertTrue("Incorrect values", Arrays.equals(new double[] { DETAILS_VALUE_1,
- DETAILS_VALUE_2, DETAILS_VALUE_3 }, detail.getValues()));
}
}