cts-tradefed: cleanup signature test and option reporting.

Bug 5264339

Change-Id: I3fee64b7f5e6855e7457389522dac4e68a230143
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
index 4770e92..ffa861c 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
@@ -63,9 +63,9 @@
     private static final String TEST_RESULT_FILE_NAME = "testResult.xml";
     private static final String CTS_RESULT_FILE_VERSION = "1.11";
     private static final String CTS_VERSION = "ICS_tradefed";
-
     private static final String[] CTS_RESULT_RESOURCES = {"cts_result.xsl", "cts_result.css",
         "logo.gif", "newrule-green.png"};
+    private static final String SIGNATURE_TEST_PKG = "android.tests.sigtest";
 
     /** the XML namespace */
     static final String ns = null;
@@ -189,7 +189,6 @@
                     "href=\"cts_result.xsl\"");
             serializeResultsDoc(serializer, startTimestamp, endTime);
             serializer.endDocument();
-            // TODO: output not executed timeout omitted counts
             String msg = String.format("XML test result file generated at %s. Passed %d, " +
                     "Failed %d, Not Executed %d", getReportPath(), getNumPassedTests(),
                     getNumFailedTests() + getNumErrorTests(), getNumIncompleteTests());
@@ -395,7 +394,13 @@
 
         serializer.startTag(ns, "Cts");
         serializer.attribute(ns, "version", CTS_VERSION);
-        // TODO: consider outputting tradefed options here
+        // TODO: consider outputting other tradefed options here
+        serializer.startTag(ns, "IntValue");
+        serializer.attribute(ns, "name", "testStatusTimeoutMs");
+        // TODO: create a constant variable for testStatusTimeoutMs value. Currently it cannot be
+        // changed
+        serializer.attribute(ns, "value", "600000");
+        serializer.endTag(ns, "IntValue");
         serializer.endTag(ns, "Cts");
 
         serializer.endTag(ns, "HostInfo");
@@ -448,6 +453,9 @@
         serializer.attribute(ns, "name", getMetric(runResult, CtsTest.PACKAGE_NAME_METRIC));
         serializer.attribute(ns, "appPackageName", runResult.getName());
         serializer.attribute(ns, "digest", getMetric(runResult, CtsTest.PACKAGE_DIGEST_METRIC));
+        if (runResult.getName().equals(SIGNATURE_TEST_PKG)) {
+            serializer.attribute(ns, "signatureCheck", "true");
+        }
 
         // Dump the results.
 
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
index 2b91053..8f0ed2d 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
@@ -13,9 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package com.android.cts.tradefed.testtype;
 
-import com.android.ddmlib.Log;
 import com.android.ddmlib.testrunner.TestIdentifier;
 import com.android.tradefed.log.LogUtil.CLog;
 import com.android.tradefed.testtype.IRemoteTest;
@@ -41,7 +41,6 @@
  */
 class TestPackageDef implements ITestPackageDef {
 
-    private static final String LOG_TAG = "TestPackageDef";
     private static final String SIGNATURE_TEST_METHOD = "testSignature";
     private static final String SIGNATURE_TEST_CLASS = "android.tests.sigtest.SimpleSignatureTest";
 
@@ -59,7 +58,8 @@
     private String mTestPackageName = null;
     private String mDigest = null;
 
-    // use a LinkedHashSet for predictable iteration insertion-order, and fast lookups
+    // use a LinkedHashSet for predictable iteration insertion-order, and fast
+    // lookups
     private Collection<TestIdentifier> mTests = new LinkedHashSet<TestIdentifier>();
     // also maintain an index of known test classes
     private Collection<String> mTestClasses = new LinkedHashSet<String>();
@@ -125,6 +125,7 @@
     boolean isVMHostTest() {
         return mIsVMHostTest;
     }
+
     void setJarPath(String jarPath) {
         mJarPath = jarPath;
     }
@@ -187,7 +188,7 @@
         mTests = filterTests();
 
         if (mIsHostSideTest) {
-            Log.d(LOG_TAG, String.format("Creating host test for %s", mName));
+            CLog.d("Creating host test for %s", mName);
             JarHostTest hostTest = new JarHostTest();
             hostTest.setRunName(getUri());
             hostTest.setJarFileName(mJarPath);
@@ -195,7 +196,7 @@
             mDigest = generateDigest(testCaseDir, mJarPath);
             return hostTest;
         } else if (mIsVMHostTest) {
-            Log.d(LOG_TAG, String.format("Creating vm host test for %s", mName));
+            CLog.d("Creating vm host test for %s", mName);
             VMHostTest vmHostTest = new VMHostTest();
             vmHostTest.setRunName(getUri());
             vmHostTest.setJarFileName(mJarPath);
@@ -203,17 +204,19 @@
             mDigest = generateDigest(testCaseDir, mJarPath);
             return vmHostTest;
         } else if (mIsSignatureTest) {
-            // TODO: hardcode the runner/class/method for now, since current package xml
-            // points to specialized instrumentation. Eventually this special case for signatureTest
-            // can be removed, and it can be treated just like a normal InstrumentationTest
-            Log.d(LOG_TAG, String.format("Creating signature test %s", mName));
+            // TODO: hardcode the runner/class/method for now, since current package xml points to
+            // specialized instrumentation. Eventually this special case for signatureTest can be
+            // removed, and it can be treated just like a normal InstrumentationTest
+            CLog.d("Creating signature test %s", mName);
             InstrumentationApkTest instrTest = new InstrumentationApkTest();
             instrTest.setPackageName(mAppNameSpace);
             instrTest.setRunnerName("android.test.InstrumentationTestRunner");
             instrTest.setClassName(SIGNATURE_TEST_CLASS);
             instrTest.setMethodName(SIGNATURE_TEST_METHOD);
-            // add signature test to list of known tests
-            addTest(new TestIdentifier(SIGNATURE_TEST_CLASS, SIGNATURE_TEST_METHOD));
+            // set expected tests to the single signature test
+            TestIdentifier t = new TestIdentifier(SIGNATURE_TEST_CLASS, SIGNATURE_TEST_METHOD);
+            mTests.clear();
+            mTests.add(t);
             // mName means 'apk file name' for instrumentation tests
             instrTest.addInstallApk(String.format("%s.apk", mName), mAppNameSpace);
             mDigest = generateDigest(testCaseDir, String.format("%s.apk", mName));
@@ -224,14 +227,14 @@
             instrTest.addInstallApk(String.format("%s.apk", mApkToTestName), mPackageToTest);
             return setInstrumentationTest(instrTest, testCaseDir);
         } else {
-            Log.d(LOG_TAG, String.format("Creating instrumentation test for %s", mName));
+            CLog.d("Creating instrumentation test for %s", mName);
             InstrumentationApkTest instrTest = new InstrumentationApkTest();
             return setInstrumentationTest(instrTest, testCaseDir);
         }
     }
 
     /**
-     * Populates given {@link InstrumentationApkTest} with data from the package xml
+     * Populates given {@link InstrumentationApkTest} with data from the package xml.
      *
      * @param testCaseDir
      * @param className
@@ -255,13 +258,13 @@
         mDigest = generateDigest(testCaseDir, String.format("%s.apk", mName));
         if (mTests.size() > 1000) {
             // TODO: hack, large test suites can take longer to collect tests, increase timeout
-            instrTest.setCollectsTestsShellTimeout(10*60*1000);
+            instrTest.setCollectsTestsShellTimeout(10 * 60 * 1000);
         }
         return instrTest;
     }
 
     /**
-     * Filter the tests to run based on list of excluded tests, class and method name
+     * Filter the tests to run based on list of excluded tests, class and method name.
      *
      * @return the filtered collection of tests
      */
@@ -319,10 +322,10 @@
      * @param fileName the name of the file
      * @return a hex {@link String} of the digest
      */
-     String generateDigest(File fileDir, String fileName) {
+    String generateDigest(File fileDir, String fileName) {
         final String algorithm = "SHA-1";
         InputStream fileStream = null;
-        DigestInputStream d  = null;
+        DigestInputStream d = null;
         try {
             fileStream = getFileStream(fileDir, fileName);
             MessageDigest md = MessageDigest.getInstance(algorithm);