Merge "Make the target_files zip reflect the recent partition change" into main
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 957da92..4a7e957 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -773,6 +773,9 @@
# Don't use SOONG_HOST_OUT, it is now an alias for HOST_OUT.
$(call add-clean-step, rm -rf $(OUT_DIR)/soong/host)
+# Clear out tools/metalava Bazel output dir
+$(call add-clean-step, rm -rf $(OUT_DIR)/bazel/output/execroot/__main__/bazel-out/mixed_builds_product-*/bin/tools/metalava)
+
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
diff --git a/core/Makefile b/core/Makefile
index a5432ef..099df47 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -5137,40 +5137,48 @@
my_board_extracted_kernel :=
-# BOARD_KERNEL_CONFIG_FILE and BOARD_KERNEL_VERSION can be used to override the values extracted
-# from INSTALLED_KERNEL_TARGET.
-ifdef BOARD_KERNEL_CONFIG_FILE
-ifdef BOARD_KERNEL_VERSION
-$(BUILT_KERNEL_CONFIGS_FILE): $(BOARD_KERNEL_CONFIG_FILE)
- cp $< $@
-$(BUILT_KERNEL_VERSION_FILE):
- echo $(BOARD_KERNEL_VERSION) > $@
-
-$(call declare-license-metadata,$(BUILT_KERNEL_CONFIGS_FILE),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
-$(call declare-license-metadata,$(BUILT_KERNEL_VERSION_FILE),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
-
-my_board_extracted_kernel := true
-endif # BOARD_KERNEL_VERSION
-endif # BOARD_KERNEL_CONFIG_FILE
-
-ifneq ($(my_board_extracted_kernel),true)
# Tools for decompression that is not in PATH.
# Check $(EXTRACT_KERNEL) for decompression algorithms supported by the script.
# Algorithms that are in the script but not in this list will be found in PATH.
my_decompress_tools := \
lz4:$(HOST_OUT_EXECUTABLES)/lz4 \
-endif # my_board_extracted_kernel
+
+# BOARD_KERNEL_CONFIG_FILE and BOARD_KERNEL_VERSION can be used to override the values extracted
+# from INSTALLED_KERNEL_TARGET.
+ifdef BOARD_KERNEL_VERSION
+$(BUILT_KERNEL_VERSION_FILE): PRIVATE_DECOMPRESS_TOOLS := $(my_decompress_tools)
+$(BUILT_KERNEL_VERSION_FILE): $(foreach pair,$(my_decompress_tools),$(call word-colon,2,$(pair)))
+$(BUILT_KERNEL_VERSION_FILE): $(EXTRACT_KERNEL) $(firstword $(INSTALLED_KERNEL_TARGET))
+ KERNEL_RELEASE=`$(EXTRACT_KERNEL) --tools $(PRIVATE_DECOMPRESS_TOOLS) --input $(firstword $(INSTALLED_KERNEL_TARGET)) \
+ --output-release` ;\
+ if [ "$$KERNEL_RELEASE" != '$(BOARD_KERNEL_VERSION)' ]; then \
+ echo "Specified kernel version '$(BOARD_KERNEL_VERSION)' does not match actual kernel version '$$KERNEL_RELEASE' " ; exit 1; fi;
+ echo '$(BOARD_KERNEL_VERSION)' > $@
+
+ifdef BOARD_KERNEL_CONFIG_FILE
+$(BUILT_KERNEL_CONFIGS_FILE): $(BOARD_KERNEL_CONFIG_FILE)
+ cp $< $@
+
+$(call declare-license-metadata,$(BUILT_KERNEL_CONFIGS_FILE),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
+$(call declare-license-metadata,$(BUILT_KERNEL_VERSION_FILE),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
+
+my_board_extracted_kernel := true
+endif # BOARD_KERNEL_CONFIG_FILE
+endif # BOARD_KERNEL_VERSION
+
ifneq ($(my_board_extracted_kernel),true)
ifdef INSTALLED_KERNEL_TARGET
+ifndef BOARD_KERNEL_VERSION
$(BUILT_KERNEL_CONFIGS_FILE): .KATI_IMPLICIT_OUTPUTS := $(BUILT_KERNEL_VERSION_FILE)
+endif
$(BUILT_KERNEL_CONFIGS_FILE): PRIVATE_DECOMPRESS_TOOLS := $(my_decompress_tools)
$(BUILT_KERNEL_CONFIGS_FILE): $(foreach pair,$(my_decompress_tools),$(call word-colon,2,$(pair)))
$(BUILT_KERNEL_CONFIGS_FILE): $(EXTRACT_KERNEL) $(firstword $(INSTALLED_KERNEL_TARGET))
$< --tools $(PRIVATE_DECOMPRESS_TOOLS) --input $(firstword $(INSTALLED_KERNEL_TARGET)) \
--output-configs $@ \
- --output-release $(BUILT_KERNEL_VERSION_FILE)
+ $(if $(BOARD_KERNEL_VERSION),,--output-release $(BUILT_KERNEL_VERSION_FILE))
$(call declare-license-metadata,$(BUILT_KERNEL_CONFIGS_FILE),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
diff --git a/core/android_soong_config_vars.mk b/core/android_soong_config_vars.mk
index 4dd66c9..e2a3492 100644
--- a/core/android_soong_config_vars.mk
+++ b/core/android_soong_config_vars.mk
@@ -154,11 +154,11 @@
$(call add_soong_config_var_value,ANDROID,avf_kernel_modules_enabled,$(PRODUCT_AVF_KERNEL_MODULES_ENABLED))
endif
-$(call add_soong_config_var_value,ANDROID,release_avf_enable_dice_changes,$(RELEASE_AVF_ENABLE_LLPVM_CHANGES))
-$(call add_soong_config_var_value,ANDROID,release_avf_enable_remote_attestation,$(RELEASE_AVF_ENABLE_REMOTE_ATTESTATION))
-$(call add_soong_config_var_value,ANDROID,release_avf_enable_multi_tenant_microdroid_vm,$(RELEASE_AVF_ENABLE_MULTI_TENANT_MICRODROID_VM))
$(call add_soong_config_var_value,ANDROID,release_avf_enable_device_assignment,$(RELEASE_AVF_ENABLE_DEVICE_ASSIGNMENT))
$(call add_soong_config_var_value,ANDROID,release_avf_enable_dice_changes,$(RELEASE_AVF_ENABLE_DICE_CHANGES))
+$(call add_soong_config_var_value,ANDROID,release_avf_enable_llpvm_changes,$(RELEASE_AVF_ENABLE_LLPVM_CHANGES))
+$(call add_soong_config_var_value,ANDROID,release_avf_enable_multi_tenant_microdroid_vm,$(RELEASE_AVF_ENABLE_MULTI_TENANT_MICRODROID_VM))
+$(call add_soong_config_var_value,ANDROID,release_avf_enable_remote_attestation,$(RELEASE_AVF_ENABLE_REMOTE_ATTESTATION))
$(call add_soong_config_var_value,ANDROID,release_avf_enable_vendor_modules,$(RELEASE_AVF_ENABLE_VENDOR_MODULES))
# Enable system_server optimizations by default unless explicitly set or if
diff --git a/core/dex_preopt.mk b/core/dex_preopt.mk
index 6ac169b..6791125 100644
--- a/core/dex_preopt.mk
+++ b/core/dex_preopt.mk
@@ -90,8 +90,8 @@
# The input variables are written by build/soong/java/dexpreopt_bootjars.go. Examples can be found
# at the bottom of build/soong/java/dexpreopt_config_testing.go.
dexpreopt_root_dir := $(dir $(patsubst %/,%,$(dir $(firstword $(bootclasspath_jars)))))
-booclasspath_arg := $(subst $(space),:,$(patsubst $(dexpreopt_root_dir)%,%,$(DEXPREOPT_BOOTCLASSPATH_DEX_FILES)))
-booclasspath_locations_arg := $(subst $(space),:,$(DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS))
+bootclasspath_arg := $(subst $(space),:,$(patsubst $(dexpreopt_root_dir)%,%,$(DEXPREOPT_BOOTCLASSPATH_DEX_FILES)))
+bootclasspath_locations_arg := $(subst $(space),:,$(DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS))
boot_images := $(subst :,$(space),$(DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICE$(DEXPREOPT_INFIX)))
boot_image_arg := $(subst $(space),:,$(patsubst /%,%,$(boot_images)))
dex2oat_extra_args := $(if $(filter true,$(ENABLE_UFFD_GC)),--runtime-arg -Xgc:CMC)
@@ -99,8 +99,8 @@
boot_zip_metadata_txt := $(dir $(boot_zip))boot_zip/METADATA.txt
$(boot_zip_metadata_txt):
rm -f $@
- echo "booclasspath = $(booclasspath_arg)" >> $@
- echo "booclasspath-locations = $(booclasspath_locations_arg)" >> $@
+ echo "bootclasspath = $(bootclasspath_arg)" >> $@
+ echo "bootclasspath-locations = $(bootclasspath_locations_arg)" >> $@
echo "boot-image = $(boot_image_arg)" >> $@
echo "extra-args = $(dex2oat_extra_args)" >> $@
diff --git a/core/release_config.mk b/core/release_config.mk
index 4f9daaf..b72ee89 100644
--- a/core/release_config.mk
+++ b/core/release_config.mk
@@ -76,12 +76,6 @@
ifeq ($(filter $(_all_release_configs), $(TARGET_RELEASE)),)
$(error No release config found for TARGET_RELEASE: $(TARGET_RELEASE). Available releases are: $(_all_release_configs))
else
-# TODO(b/294161396): Remove this logic
-ifeq ($(TARGET_RELEASE),next)
-ifndef TESTING_TARGET_RELEASE_NEXT
- $(error "next" releases are not supported yet. b/294161396)
-endif
-endif
# Choose flag files
# Don't sort this, use it in the order they gave us.
flag_value_files := $(_all_release_configs.$(TARGET_RELEASE).FILES)
diff --git a/core/soong_config.mk b/core/soong_config.mk
index e00447a..5bcdfce 100644
--- a/core/soong_config.mk
+++ b/core/soong_config.mk
@@ -319,6 +319,10 @@
$(call add_json_bool, CheckVendorSeappViolations, $(filter true,$(CHECK_VENDOR_SEAPP_VIOLATIONS)))
+$(call add_json_map, PartitionVars)
+ $(call add_json_str, ProductDirectory, $(dir $(INTERNAL_PRODUCT)))
+$(call end_json_map)
+
$(call json_end)
$(file >$(SOONG_VARIABLES).tmp,$(json_contents))
diff --git a/target/board/Android.mk b/target/board/Android.mk
index 21c0c10..decc345 100644
--- a/target/board/Android.mk
+++ b/target/board/Android.mk
@@ -10,15 +10,29 @@
# device we're building for. This file is typically packaged up
# with everything else.
#
-# If TARGET_BOARD_INFO_FILE (which can be set in BoardConfig.mk) is
-# defined, it is used, otherwise board-info.txt is looked for in
-# $(TARGET_DEVICE_DIR).
+# The following logic is used to find the contents of the info file:
+# 1. TARGET_BOARD_INFO_FILES (can be set in BoardConfig.mk) will be combined.
+# 2. TARGET_BOARD_INFO_FILE (can be set in BoardConfig.mk) will be used.
+# 3. $(TARGET_DEVICE_DIR)/board-info.txt will be used if present.
+#
+# Specifying both TARGET_BOARD_INFO_FILES and TARGET_BOARD_INFO_FILE is an
+# error.
#
INSTALLED_ANDROID_INFO_TXT_TARGET := $(PRODUCT_OUT)/android-info.txt
-board_info_txt := $(TARGET_BOARD_INFO_FILE)
-ifndef board_info_txt
-board_info_txt := $(wildcard $(TARGET_DEVICE_DIR)/board-info.txt)
+ifdef TARGET_BOARD_INFO_FILES
+ ifdef TARGET_BOARD_INFO_FILE
+ $(warning Both TARGET_BOARD_INFO_FILES and TARGET_BOARD_INFO_FILE are defined.)
+ $(warning Using $(TARGET_BOARD_INFO_FILES) rather than $(TARGET_BOARD_INFO_FILE) for android-info.txt)
+ endif
+ board_info_txt := $(call intermediates-dir-for,PACKAGING,board-info)/board-info.txt
+$(board_info_txt): $(TARGET_BOARD_INFO_FILES)
+ $(hide) cat $(TARGET_BOARD_INFO_FILES) > $@
+else ifdef TARGET_BOARD_INFO_FILE
+ board_info_txt := $(TARGET_BOARD_INFO_FILE)
+else
+ board_info_txt := $(wildcard $(TARGET_DEVICE_DIR)/board-info.txt)
endif
+
CHECK_RADIO_VERSIONS := $(HOST_OUT_EXECUTABLES)/check_radio_versions$(HOST_EXECUTABLE_SUFFIX)
$(INSTALLED_ANDROID_INFO_TXT_TARGET): $(board_info_txt) $(CHECK_RADIO_VERSIONS)
$(hide) $(CHECK_RADIO_VERSIONS) \
diff --git a/target/product/base_vendor.mk b/target/product/base_vendor.mk
index 3c4d62e..d22f71f 100644
--- a/target/product/base_vendor.mk
+++ b/target/product/base_vendor.mk
@@ -46,7 +46,7 @@
# Base modules and settings for the vendor partition.
PRODUCT_PACKAGES += \
- android.hardware.cas-service.example \
+ com.android.hardware.cas \
boringssl_self_test_vendor \
dumpsys_vendor \
fs_config_files_nonsystem \
diff --git a/tools/Android.bp b/tools/Android.bp
index bea0602..b8ab162 100644
--- a/tools/Android.bp
+++ b/tools/Android.bp
@@ -82,3 +82,17 @@
}
}
}
+
+python_test_host {
+ name: "auto_gen_test_config_test",
+ main: "auto_gen_test_config_test.py",
+ srcs: [
+ "auto_gen_test_config.py",
+ "auto_gen_test_config_test.py",
+ ],
+ auto_gen_config: true,
+ test_suites: ["general-tests"],
+ test_options: {
+ unit_test: true,
+ },
+}
diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel
index 2dbb585..9ec0dce 100644
--- a/tools/BUILD.bazel
+++ b/tools/BUILD.bazel
@@ -26,3 +26,10 @@
python_version = "PY3",
visibility = ["//visibility:public"],
)
+
+py_binary(
+ name = "auto_gen_test_config",
+ srcs = ["auto_gen_test_config.py"],
+ python_version = "PY3",
+ visibility = ["//visibility:public"],
+)
diff --git a/tools/auto_gen_test_config.py b/tools/auto_gen_test_config.py
index ce64160..8ee599a 100755
--- a/tools/auto_gen_test_config.py
+++ b/tools/auto_gen_test_config.py
@@ -17,6 +17,8 @@
"""A tool to generate TradeFed test config file.
"""
+import argparse
+import re
import os
import shutil
import sys
@@ -42,42 +44,85 @@
Returns:
0 if no error, otherwise 1.
"""
- if len(argv) != 4 and len(argv) != 6:
- sys.stderr.write(
- 'Invalid arguments. The script requires 4 arguments for file paths: '
- 'target_config android_manifest empty_config '
- 'instrumentation_test_config_template '
- 'and 2 optional arguments for extra configs: '
- '--extra-configs \'EXTRA_CONFIGS\'.\n')
- return 1
- target_config = argv[0]
- android_manifest = argv[1]
- empty_config = argv[2]
- instrumentation_test_config_template = argv[3]
- extra_configs = '\n'.join(argv[5].split('\\n')) if len(argv) == 6 else ''
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "target_config",
+ help="Path to the generated output config.")
+ parser.add_argument(
+ "android_manifest",
+ help="Path to AndroidManifest.xml or output of 'aapt2 dump xmltree' with .xmltree extension.")
+ parser.add_argument(
+ "empty_config",
+ help="Path to the empty config template.")
+ parser.add_argument(
+ "instrumentation_test_config_template",
+ help="Path to the instrumentation test config template.")
+ parser.add_argument("--extra-configs", default="")
+ args = parser.parse_args(argv)
- manifest = parse(android_manifest)
- instrumentation_elements = manifest.getElementsByTagName('instrumentation')
- manifest_elements = manifest.getElementsByTagName('manifest')
- if len(instrumentation_elements) != 1 or len(manifest_elements) != 1:
- # Failed to locate instrumentation or manifest element in AndroidManifest.
- # file. Empty test config file will be created.
- shutil.copyfile(empty_config, target_config)
- return 0
+ target_config = args.target_config
+ android_manifest = args.android_manifest
+ empty_config = args.empty_config
+ instrumentation_test_config_template = args.instrumentation_test_config_template
+ extra_configs = '\n'.join(args.extra_configs.split('\\n'))
module = os.path.splitext(os.path.basename(target_config))[0]
- instrumentation = instrumentation_elements[0]
- manifest = manifest_elements[0]
- if ATTRIBUTE_LABEL in instrumentation.attributes:
- label = instrumentation.attributes[ATTRIBUTE_LABEL].value
- else:
+
+ # If the AndroidManifest.xml is not available, but the APK is, this tool also
+ # accepts the output of `aapt2 dump xmltree <apk> AndroidManifest.xml` written
+ # into a file. This is a custom structured aapt2 output - not raw XML!
+ if android_manifest.endswith(".xmltree"):
label = module
- runner = instrumentation.attributes[ATTRIBUTE_RUNNER].value
- package = manifest.attributes[ATTRIBUTE_PACKAGE].value
+ with open(android_manifest, encoding="utf-8") as manifest:
+ # e.g. A: package="android.test.example.helloworld" (Raw: "android.test.example.helloworld")
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ pattern = re.compile(r"\(Raw:\s\"(.*)\"\)$")
+ curr_element = None
+ for line in manifest:
+ curr_line = line.strip()
+ if curr_line.startswith("E:"):
+ # e.g. "E: instrumentation (line=9)"
+ # ^^^^^^^^^^^^^^^
+ curr_element = curr_line.split(" ")[1]
+ if curr_element == "instrumentation":
+ if ATTRIBUTE_RUNNER in curr_line:
+ runner = re.findall(pattern, curr_line)[0]
+ if ATTRIBUTE_LABEL in curr_line:
+ label = re.findall(pattern, curr_line)[0]
+ if curr_element == "manifest":
+ if ATTRIBUTE_PACKAGE in curr_line:
+ package = re.findall(pattern, curr_line)[0]
+
+ if not (runner and label and package):
+ # Failed to locate instrumentation or manifest element in AndroidManifest.
+ # file. Empty test config file will be created.
+ shutil.copyfile(empty_config, target_config)
+ return 0
+
+ else:
+ # If the AndroidManifest.xml file is directly available, read it as an XML file.
+ manifest = parse(android_manifest)
+ instrumentation_elements = manifest.getElementsByTagName('instrumentation')
+ manifest_elements = manifest.getElementsByTagName('manifest')
+ if len(instrumentation_elements) != 1 or len(manifest_elements) != 1:
+ # Failed to locate instrumentation or manifest element in AndroidManifest.
+ # file. Empty test config file will be created.
+ shutil.copyfile(empty_config, target_config)
+ return 0
+
+ instrumentation = instrumentation_elements[0]
+ manifest = manifest_elements[0]
+ if ATTRIBUTE_LABEL in instrumentation.attributes:
+ label = instrumentation.attributes[ATTRIBUTE_LABEL].value
+ else:
+ label = module
+ runner = instrumentation.attributes[ATTRIBUTE_RUNNER].value
+ package = manifest.attributes[ATTRIBUTE_PACKAGE].value
+
test_type = ('InstrumentationTest'
- if runner.endswith('.InstrumentationTestRunner')
- else 'AndroidJUnitTest')
+ if runner.endswith('.InstrumentationTestRunner')
+ else 'AndroidJUnitTest')
with open(instrumentation_test_config_template) as template:
config = template.read()
diff --git a/tools/auto_gen_test_config_test.py b/tools/auto_gen_test_config_test.py
index 51a8583..ce97723 100644
--- a/tools/auto_gen_test_config_test.py
+++ b/tools/auto_gen_test_config_test.py
@@ -30,6 +30,24 @@
</manifest>
"""
+XMLTREE_JUNIT_TEST = """N: android=http://schemas.android.com/apk/res/android (line=2)
+ E: manifest (line=2)
+ A: package="com.android.my.tests.x" (Raw: "com.android.my.tests.x")
+ E: instrumentation (line=9)
+ A: http://schemas.android.com/apk/res/android:label(0x01010001)="TestModule" (Raw: "TestModule")
+ A: http://schemas.android.com/apk/res/android:name(0x01010003)="androidx.test.runner.AndroidJUnitRunner" (Raw: "androidx.test.runner.AndroidJUnitRunner")
+ A: http://schemas.android.com/apk/res/android:targetPackage(0x01010021)="com.android.my.tests" (Raw: "com.android.my.tests")
+"""
+
+XMLTREE_INSTRUMENTATION_TEST = """N: android=http://schemas.android.com/apk/res/android (line=2)
+ E: manifest (line=2)
+ A: package="com.android.my.tests.x" (Raw: "com.android.my.tests.x")
+ E: instrumentation (line=9)
+ A: http://schemas.android.com/apk/res/android:label(0x01010001)="TestModule" (Raw: "TestModule")
+ A: http://schemas.android.com/apk/res/android:name(0x01010003)="android.test.InstrumentationTestRunner" (Raw: "android.test.InstrumentationTestRunner")
+ A: http://schemas.android.com/apk/res/android:targetPackage(0x01010021)="com.android.my.tests" (Raw: "com.android.my.tests")
+"""
+
MANIFEST_JUNIT_TEST = """<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.my.tests.x">
@@ -45,12 +63,12 @@
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.android.my.tests"
- android:label="My Tests" />
+ android:label="TestModule" />
</manifest>
"""
EXPECTED_JUNIT_TEST_CONFIG = """<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2017 The Android Open Source Project
+<!-- Copyright (C) 2023 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.
@@ -66,19 +84,23 @@
-->
<!-- This test config file is auto-generated. -->
<configuration description="Runs TestModule.">
+ <option name="test-suite-tag" value="apct" />
+ <option name="test-suite-tag" value="apct-instrumentation" />
+
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true" />
<option name="test-file-name" value="TestModule.apk" />
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
- <option name="package" value="com.android.my.tests.x" />
+ {EXTRA_TEST_RUNNER_CONFIGS}<option name="package" value="com.android.my.tests.x" />
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
</test>
</configuration>
"""
EXPECTED_INSTRUMENTATION_TEST_CONFIG = """<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2017 The Android Open Source Project
+<!-- Copyright (C) 2023 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.
@@ -93,23 +115,74 @@
limitations under the License.
-->
<!-- This test config file is auto-generated. -->
-<configuration description="Runs My Tests.">
+<configuration description="Runs TestModule.">
+ <option name="test-suite-tag" value="apct" />
+ <option name="test-suite-tag" value="apct-instrumentation" />
+
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true" />
<option name="test-file-name" value="TestModule.apk" />
</target_preparer>
<test class="com.android.tradefed.testtype.InstrumentationTest" >
- <option name="package" value="com.android.my.tests.x" />
+ {EXTRA_TEST_RUNNER_CONFIGS}<option name="package" value="com.android.my.tests.x" />
<option name="runner" value="android.test.InstrumentationTestRunner" />
</test>
</configuration>
"""
-TOOLS_DIR = os.path.dirname(os.path.dirname(__file__))
-EMPTY_TEST_CONFIG = os.path.join(
- TOOLS_DIR, '..', 'core', 'empty_test_config.xml')
-INSTRUMENTATION_TEST_CONFIG_TEMPLATE = os.path.join(
- TOOLS_DIR, '..', 'core', 'instrumentation_test_config_template.xml')
+EMPTY_TEST_CONFIG_CONTENT = """<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 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.
+-->
+<!-- No AndroidTest.xml was provided and the manifest does not include
+ instrumentation, hence this apk is not instrumentable.
+-->
+<configuration description="Empty Configuration" />
+"""
+
+INSTRUMENTATION_TEST_CONFIG_TEMPLATE_CONTENT = """<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2023 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.
+-->
+<!-- This test config file is auto-generated. -->
+<configuration description="Runs {LABEL}.">
+ <option name="test-suite-tag" value="apct" />
+ <option name="test-suite-tag" value="apct-instrumentation" />
+{EXTRA_CONFIGS}
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true" />
+ <option name="test-file-name" value="{MODULE}.apk" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.{TEST_TYPE}" >
+ {EXTRA_TEST_RUNNER_CONFIGS}<option name="package" value="{PACKAGE}" />
+ <option name="runner" value="{RUNNER}" />
+ </test>
+</configuration>
+"""
class AutoGenTestConfigUnittests(unittest.TestCase):
@@ -120,6 +193,16 @@
self.test_dir = tempfile.mkdtemp()
self.config_file = os.path.join(self.test_dir, TEST_MODULE + '.config')
self.manifest_file = os.path.join(self.test_dir, 'AndroidManifest.xml')
+ self.xmltree_file = os.path.join(self.test_dir, TEST_MODULE + '.xmltree')
+ self.empty_test_config_file = os.path.join(self.test_dir, 'empty.config')
+ self.instrumentation_test_config_template_file = os.path.join(
+ self.test_dir, 'instrumentation.config')
+
+ with open(self.empty_test_config_file, 'w') as f:
+ f.write(EMPTY_TEST_CONFIG_CONTENT)
+
+ with open(self.instrumentation_test_config_template_file, 'w') as f:
+ f.write(INSTRUMENTATION_TEST_CONFIG_TEMPLATE_CONTENT)
def tearDown(self):
"""Cleanup the test directory."""
@@ -133,11 +216,11 @@
argv = [self.config_file,
self.manifest_file,
- EMPTY_TEST_CONFIG,
- INSTRUMENTATION_TEST_CONFIG_TEMPLATE]
+ self.empty_test_config_file,
+ self.instrumentation_test_config_template_file]
auto_gen_test_config.main(argv)
with open(self.config_file) as config_file:
- with open(EMPTY_TEST_CONFIG) as empty_config:
+ with open(self.empty_test_config_file) as empty_config:
self.assertEqual(config_file.read(), empty_config.read())
def testCreateJUnitTestConfig(self):
@@ -148,8 +231,8 @@
argv = [self.config_file,
self.manifest_file,
- EMPTY_TEST_CONFIG,
- INSTRUMENTATION_TEST_CONFIG_TEMPLATE]
+ self.empty_test_config_file,
+ self.instrumentation_test_config_template_file]
auto_gen_test_config.main(argv)
with open(self.config_file) as config_file:
self.assertEqual(config_file.read(), EXPECTED_JUNIT_TEST_CONFIG)
@@ -162,8 +245,37 @@
argv = [self.config_file,
self.manifest_file,
- EMPTY_TEST_CONFIG,
- INSTRUMENTATION_TEST_CONFIG_TEMPLATE]
+ self.empty_test_config_file,
+ self.instrumentation_test_config_template_file]
+ auto_gen_test_config.main(argv)
+ with open(self.config_file) as config_file:
+ self.assertEqual(
+ config_file.read(), EXPECTED_INSTRUMENTATION_TEST_CONFIG)
+
+ def testCreateJUnitTestConfigWithXMLTree(self):
+ """Test creating test config for AndroidJUnitTest.
+ """
+ with open(self.xmltree_file, 'w') as f:
+ f.write(XMLTREE_JUNIT_TEST)
+
+ argv = [self.config_file,
+ self.xmltree_file,
+ self.empty_test_config_file,
+ self.instrumentation_test_config_template_file]
+ auto_gen_test_config.main(argv)
+ with open(self.config_file) as config_file:
+ self.assertEqual(config_file.read(), EXPECTED_JUNIT_TEST_CONFIG)
+
+ def testCreateInstrumentationTestConfigWithXMLTree(self):
+ """Test creating test config for InstrumentationTest.
+ """
+ with open(self.xmltree_file, 'w') as f:
+ f.write(XMLTREE_INSTRUMENTATION_TEST)
+
+ argv = [self.config_file,
+ self.xmltree_file,
+ self.empty_test_config_file,
+ self.instrumentation_test_config_template_file]
auto_gen_test_config.main(argv)
with open(self.config_file) as config_file:
self.assertEqual(