Initial change to add cts tests to runtest.

Adds cts test definitions to the testrunner/test_defs.xml.
Adds support for runtest --cts arg, which will run all cts tests.
This temporarily relies on the addition of a 'cts' attribute to the test
definition - a new xml format may be defined later that changes how cts tests
are identified.

This change is based on previous unsubmitted CL
https://android-git.corp.google.com/g/Gerrit#change,1702. The only delta wrt
to that change is the use of InstrumentationCtsTestRunner.

Update: rebased to latest donut.
diff --git a/testrunner/errors.py b/testrunner/errors.py
index e240899..c04fd01 100755
--- a/testrunner/errors.py
+++ b/testrunner/errors.py
@@ -34,7 +34,7 @@
   """Generic exception that indicates a fatal error has occurred and program
   execution should be aborted."""
 
-  def __init__(self, msg="AbortError"):
+  def __init__(self, msg=""):
     self.msg = msg
 
 
diff --git a/testrunner/runtest.py b/testrunner/runtest.py
index 046eb7c..e66b8de 100755
--- a/testrunner/runtest.py
+++ b/testrunner/runtest.py
@@ -115,7 +115,10 @@
     parser.add_option("--timeout", dest="timeout",
                       default=300, help="Set a timeout limit (in sec) for "
                       "running native tests on a device (default: 300 secs)")
-
+    parser.add_option("--cts", dest="cts_tests",
+                      default=False, action="store_true",
+                      help="Run all tests defined as part of the "
+                      "compatibility test suite")
     group = optparse.OptionGroup(
         parser, "Targets", "Use these options to direct tests to a specific "
         "Android target")
@@ -129,8 +132,11 @@
 
     self._options, self._test_args = parser.parse_args()
 
-    if (not self._options.only_list_tests and not self._options.all_tests
-        and not self._options.continuous_tests and len(self._test_args) < 1):
+    if (not self._options.only_list_tests
+        and not self._options.all_tests
+        and not self._options.continuous_tests
+        and not self._options.cts_tests
+        and len(self._test_args) < 1):
       parser.print_help()
       logger.SilentLog("at least one test name must be specified")
       raise errors.AbortError
@@ -229,8 +235,10 @@
     """Get a list of TestSuite objects to run, based on command line args."""
     if self._options.all_tests:
       return self._known_tests.GetTests()
-    if self._options.continuous_tests:
+    elif self._options.continuous_tests:
       return self._known_tests.GetContinuousTests()
+    elif self._options.cts_tests:
+      return self._known_tests.GetCtsTests()
     tests = []
     for name in self._test_args:
       test = self._known_tests.GetTest(name)
diff --git a/testrunner/test_defs.py b/testrunner/test_defs.py
index 2cdcfa8..0542a05 100644
--- a/testrunner/test_defs.py
+++ b/testrunner/test_defs.py
@@ -144,6 +144,14 @@
         con_tests.append(test)
     return con_tests
 
+  def GetCtsTests(self):
+    """Return list of cts tests."""
+    cts_tests = []
+    for test in self.GetTests():
+      if test.IsCts():
+        cts_tests.append(test)
+    return cts_tests
+
   def GetTest(self, name):
     return self._testname_map.get(name, None)
   
@@ -157,6 +165,7 @@
   _TARGET_ATTR = "coverage_target"
   _BUILD_ATTR = "build_path"
   _CONTINUOUS_ATTR = "continuous"
+  _CTS_ATTR = "cts"
   _DESCRIPTION_ATTR = "description"
   _EXTRA_MAKE_ARGS_ATTR = "extra_make_args"
 
@@ -199,6 +208,11 @@
       self._continuous = suite_element.getAttribute(self._CONTINUOUS_ATTR)
     else:
       self._continuous = False
+    if suite_element.hasAttribute(self._CTS_ATTR):
+      self._cts = suite_element.getAttribute(self._CTS_ATTR)
+    else:
+      self._cts = False
+
     if suite_element.hasAttribute(self._DESCRIPTION_ATTR):
       self._description = suite_element.getAttribute(self._DESCRIPTION_ATTR)
     else:
@@ -236,6 +250,10 @@
     """Returns true if test is flagged as being part of the continuous tests"""  
     return self._continuous
 
+  def IsCts(self):
+    """Returns true if test is part of the compatibility test suite"""
+    return self._cts
+
   def IsNative(self):
     """Returns true if test is a native one."""
     return self._native
diff --git a/testrunner/test_defs.xml b/testrunner/test_defs.xml
index 4121f7b..e1d9cc5 100644
--- a/testrunner/test_defs.xml
+++ b/testrunner/test_defs.xml
@@ -42,6 +42,8 @@
   continuous: Optional boolean. Default is false. Set to true if tests are known
     to be reliable, and should be included in a continuous test system. false if
     they are under development.
+  cts: Optional boolean. Default is false. Set to true if test is included in
+    compatibility test suite.
 
   description: Optional string. Default is empty. Short description (typically
      less than 60 characters) about this test.
@@ -166,6 +168,162 @@
     coverage_target="framework"
     continuous="true" />
 
+<!--  cts tests -->
+
+<test name="cts-permission"
+    build_path="cts/tests"
+    package="com.android.cts.permission"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    continuous="true"
+    cts="true" />
+
+<test name="cts-process"
+    build_path="cts/tests"
+    package="com.android.cts.process"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-api-signature"
+    build_path="cts/tests"
+    package="android.tests.sigtest"
+    runner=".InstrumentationRunner"
+    cts="true" />
+
+<test name="cts-api-signature-func"
+    build_path="cts/tests"
+    package="android.tests.sigtest.tests"
+    cts="true" />
+
+<test name="cts-apidemos"
+    build_path="cts/tests"
+    package="android.apidemos.cts"
+    coverage_target="ApiDemos"
+    cts="true" />
+
+<test name="cts-app"
+    build_path="cts/tests"
+    package="com.android.cts.app"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-content"
+    build_path="cts/tests"
+    package="com.android.cts.content"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-database"
+    build_path="cts/tests"
+    package="com.android.cts.database"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-graphics"
+    build_path="cts/tests"
+    package="com.android.cts.graphics"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-hardware"
+    build_path="cts/tests"
+    package="com.android.cts.hardware"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-location"
+    build_path="cts/tests"
+    package="com.android.cts.location"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-net"
+    build_path="cts/tests"
+    package="com.android.cts.net"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-os"
+    build_path="cts/tests"
+    package="com.android.cts.os"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-perf1"
+    build_path="cts/tests"
+    package="com.android.cts.performance"
+    runner="android.test.InstrumentationCtsTestRunner"
+    cts="true" />
+
+<test name="cts-perf2"
+    build_path="cts/tests"
+    package="com.android.cts.performance2"
+    runner="android.test.InstrumentationCtsTestRunner"
+    cts="true" />
+
+<test name="cts-perf3"
+    build_path="cts/tests"
+    package="com.android.cts.performance3"
+    runner="android.test.InstrumentationCtsTestRunner"
+    cts="true" />
+
+<test name="cts-perf4"
+    build_path="cts/tests"
+    package="com.android.cts.performance4"
+    runner="android.test.InstrumentationCtsTestRunner"
+    cts="true" />
+
+<test name="cts-perf5"
+    build_path="cts/tests"
+    package="com.android.cts.performance5"
+    runner="android.test.InstrumentationCtsTestRunner"
+    cts="true" />
+
+<test name="cts-provider"
+    build_path="cts/tests"
+    package="com.android.cts.provider"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-text"
+    build_path="cts/tests"
+    package="com.android.cts.text"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-util"
+    build_path="cts/tests"
+    package="com.android.cts.util"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-view"
+    build_path="cts/tests"
+    package="com.android.cts.view"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<test name="cts-widget"
+    build_path="cts/tests"
+    package="com.android.cts.widget"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
+<!--  end of cts tests -->
+
 <!--  selected app tests -->
 <test name="browser"
     build_path="packages/apps/Browser"
diff --git a/testrunner/test_defs.xsd b/testrunner/test_defs.xsd
index 5387a28..f964779 100644
--- a/testrunner/test_defs.xsd
+++ b/testrunner/test_defs.xsd
@@ -24,6 +24,7 @@
                       default="android.test.InstrumentationTestRunner"/>
         <xs:attribute name="coverage_target" type="xs:string" use="optional"/>
         <xs:attribute name="continuous" type="xs:boolean" use="optional" default="false"/>
+        <xs:attribute name="cts" type="xs:boolean" use="optional" default="false"/>
     </xs:complexType>
 
     <xs:complexType name="nativeTestType">