support package scope prepare/teardown

* introduced concept of module test config as AndroidTest.xml;
  for now target preparers can be defined in it to complete tasks
  before and after (CTS) package scope test execution
* modified CtsTest to invoke the preparers around package scope
  test execution
* modified related makefiles to "install" the module test config
  into CTS repository/testcases
* default common test config that included the commonly useful
  preparers
* modified accessibility tests to adopt module test config

Bug: 19442125

Change-Id: I1c694997c96c37150399395de2fbc464264c2aba
diff --git a/build/config.mk b/build/config.mk
index 20f6001..ffc71ba 100644
--- a/build/config.mk
+++ b/build/config.mk
@@ -34,6 +34,9 @@
 # Holds the target architecture to build for.
 CTS_TARGET_ARCH := $(TARGET_ARCH)
 
+# default module config filename
+CTS_MODULE_TEST_CONFIG := AndroidTest.xml
+
 # CTS build rules
 BUILD_CTS_EXECUTABLE := cts/build/test_executable.mk
 BUILD_CTS_PACKAGE := cts/build/test_package.mk
@@ -43,3 +46,4 @@
 BUILD_CTS_UI_JAVA_LIBRARY := cts/build/test_uiautomator.mk
 BUILD_CTS_DEQP_PACKAGE := cts/build/test_deqp_package.mk
 BUILD_CTS_SUPPORT_PACKAGE := cts/build/support_package.mk
+BUILD_CTS_MODULE_TEST_CONFIG := cts/build/module_test_config.mk
diff --git a/build/module_test_config.mk b/build/module_test_config.mk
new file mode 100644
index 0000000..5cbaf0d
--- /dev/null
+++ b/build/module_test_config.mk
@@ -0,0 +1,21 @@
+# 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.
+
+cts_module_test_config := $(if $(wildcard \
+	$(LOCAL_PATH)/$(CTS_MODULE_TEST_CONFIG)), \
+	$(CTS_TESTCASES_OUT)/$(LOCAL_PACKAGE_NAME).config)
+ifneq ($(cts_module_test_config),)
+$(cts_module_test_config): $(LOCAL_PATH)/$(CTS_MODULE_TEST_CONFIG)
+	$(call copy-file-to-target)
+endif
diff --git a/build/test_package.mk b/build/test_package.mk
index b2bf2c6..0e8d37b 100644
--- a/build/test_package.mk
+++ b/build/test_package.mk
@@ -24,6 +24,7 @@
 LOCAL_PROGUARD_ENABLED := disabled
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
+include $(BUILD_CTS_MODULE_TEST_CONFIG)
 
 cts_src_dirs := $(LOCAL_PATH)
 cts_src_dirs += $(sort $(dir $(LOCAL_GENERATED_SOURCES)))
@@ -41,6 +42,7 @@
 $(cts_package_xml): PRIVATE_TEST_PACKAGE := $(PRIVATE_CTS_TEST_PACKAGE_NAME_)
 $(cts_package_xml): PRIVATE_MANIFEST := $(LOCAL_PATH)/AndroidManifest.xml
 $(cts_package_xml): PRIVATE_TEST_TYPE := $(if $(LOCAL_CTS_TEST_RUNNER),$(LOCAL_CTS_TEST_RUNNER),'')
+$(cts_package_xml): $(cts_module_test_config)
 $(cts_package_xml): $(CTS_EXPECTATIONS) $(CTS_UNSUPPORTED_ABIS) $(CTS_JAVA_TEST_SCANNER_DOCLET) $(CTS_JAVA_TEST_SCANNER) $(CTS_XML_GENERATOR)
 	$(hide) echo Generating test description for java package $(PRIVATE_PACKAGE)
 	$(hide) mkdir -p $(CTS_TESTCASES_OUT)
@@ -57,6 +59,5 @@
 						-b $(CTS_UNSUPPORTED_ABIS) \
 						-a $(CTS_TARGET_ARCH) \
 						-o $@
-
 # Have the module name depend on the cts files; so the cts files get generated when you run mm/mmm/mma/mmma.
-$(my_register_name) : $(cts_package_xml)
+$(my_register_name) : $(cts_package_xml) $(cts_module_test_config)