Add 'device serials' to output of 'list results'

Bug 5924016

Change-Id: I54dc0612f96fb156461b3eb2bccacead9f7d188c
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/command/CtsConsole.java b/tools/tradefed-host/src/com/android/cts/tradefed/command/CtsConsole.java
index 82fa0d7..bd7a983 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/command/CtsConsole.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/command/CtsConsole.java
@@ -203,7 +203,8 @@
     private void listResults(CtsBuildHelper ctsBuild) {
         TableFormatter tableFormatter = new TableFormatter();
         List<List<String>> table = new ArrayList<List<String>>();
-        table.add(Arrays.asList("Session","Pass", "Fail","Not Executed","Start time","Plan name"));
+        table.add(Arrays.asList("Session","Pass", "Fail","Not Executed","Start time","Plan name",
+                "Device serial(s)"));
         ITestResultRepo testResultRepo = new TestResultRepo(ctsBuild.getResultsDir());
         for (ITestSummary result : testResultRepo.getSummaries()) {
             table.add(Arrays.asList(Integer.toString(result.getId()),
@@ -211,7 +212,8 @@
                     Integer.toString(result.getNumFailed()),
                     Integer.toString(result.getNumIncomplete()),
                     result.getTimestamp(),
-                    result.getTestPlan()));
+                    result.getTestPlan(),
+                    result.getDeviceSerials()));
         }
         tableFormatter.displayTable(table, new PrintWriter(System.out, true));
     }
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/DeviceInfoResult.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/DeviceInfoResult.java
index d5f4530..17b62ca 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/DeviceInfoResult.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/DeviceInfoResult.java
@@ -39,7 +39,7 @@
 class DeviceInfoResult extends AbstractXmlPullParser {
     static final String TAG = "DeviceInfo";
     private static final String ns = CtsXmlResultReporter.ns;
-    private static final String BUILD_TAG = "BuildInfo";
+    static final String BUILD_TAG = "BuildInfo";
     private static final String PHONE_TAG = "PhoneSubInfo";
     private static final String SCREEN_TAG = "Screen";
     private static final String FEATURE_INFO_TAG = "FeatureInfo";
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/ITestSummary.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/ITestSummary.java
index 509e564..98494ee 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/ITestSummary.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/ITestSummary.java
@@ -57,4 +57,9 @@
      */
     String getStartTime();
 
+    /**
+     * @return a comma separated list of device serials associated with result
+     */
+    String getDeviceSerials();
+
 }
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/TestSummaryXml.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/TestSummaryXml.java
index af37184..36f3297 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/TestSummaryXml.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/TestSummaryXml.java
@@ -20,6 +20,8 @@
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
+import android.tests.getinfo.DeviceInfoConstants;
+
 import java.io.FileNotFoundException;
 import java.io.IOException;
 
@@ -35,6 +37,7 @@
     private int mNumPassed = 0;
     private String mPlan = "NA";
     private String mStartTime = "unknown";
+    private String mDeviceSerials = "unknown";
 
     /**
      * @param id
@@ -105,13 +108,17 @@
                 mPlan = getAttribute(parser, CtsXmlResultReporter.PLAN_ATTR);
                 mStartTime = getAttribute(parser, CtsXmlResultReporter.STARTTIME_ATTR);
             } else if (eventType == XmlPullParser.START_TAG && parser.getName().equals(
+                    DeviceInfoResult.BUILD_TAG)) {
+                mDeviceSerials = getAttribute(parser, DeviceInfoConstants.SERIAL_NUMBER);
+            } else if (eventType == XmlPullParser.START_TAG && parser.getName().equals(
                     TestResults.SUMMARY_TAG)) {
                 mNumFailed = parseIntAttr(parser, TestResults.FAILED_ATTR) +
                     parseIntAttr(parser, TestResults.TIMEOUT_ATTR);
                 mNumNotExecuted = parseIntAttr(parser, TestResults.NOT_EXECUTED_ATTR);
                 mNumPassed = parseIntAttr(parser, TestResults.PASS_ATTR);
+                // abort after parsing Summary, which should be the last tag
                 return;
-              }
+             }
             eventType = parser.next();
         }
         throw new XmlPullParserException("Could not find Summary tag");
@@ -124,5 +131,12 @@
     public String getStartTime() {
         return mStartTime;
     }
-}
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getDeviceSerials() {
+        return mDeviceSerials;
+    }
+}