diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-30 21:46:24 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-30 21:46:24 +0000 |
commit | b219aa78842e947d79ca02c66f6273af48276459 (patch) | |
tree | 60ae943a51ca0545fb4af8efe7eed1ecd4691369 | |
parent | ce49385cd3d05ea362e1aa9f781fd7a4e0f79595 (diff) | |
parent | b6f8c9cfb4bd7017e7ff876e6c37eb752e43b469 (diff) | |
download | csuite-build-tools-release.tar.gz |
Snap for 11784721 from b6f8c9cfb4bd7017e7ff876e6c37eb752e43b469 to build-tools-releasebuild-tools-release
Change-Id: I60e09a414e3e9559b5da1c78eb38518893d1b308
24 files changed, 183 insertions, 67 deletions
diff --git a/harness/Android.bp b/harness/Android.bp index 257dfe5..00b30c2 100644 --- a/harness/Android.bp +++ b/harness/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } diff --git a/integration_tests/Android.bp b/integration_tests/Android.bp index 6fc242f..cdb2b44 100644 --- a/integration_tests/Android.bp +++ b/integration_tests/Android.bp @@ -23,6 +23,7 @@ // artifact location instead of using the Soong 'location' feature. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } @@ -45,7 +46,7 @@ java_genrule_host { "touch $${CSUITE_TOOLS}/csuite-tradefed-tests.jar && " + "chmod a+x $${CSUITE_TOOLS}/csuite-tradefed && " + "$(location soong_zip) -o $(out) -d -C $(genDir) -D $${ANDROID_CSUITE}", - out: ["csuite-standalone.zip"], + out: ["testdata/csuite-standalone.zip"], srcs: [ ":tradefed", ":compatibility-host-util", @@ -83,6 +84,11 @@ python_test_host { libs: [ "csuite_test_utils", ], + version: { + py3: { + embedded_launcher: true, + }, + }, } python_test_host { @@ -96,12 +102,26 @@ python_test_host { ], libs: [ "csuite_test_utils", + "csuite_crash_detection_test_data", ], + test_options: { + unit_test: false, + }, + version: { + py3: { + embedded_launcher: true, + }, + }, +} + +// importlib.resources cannot load resources from the root package, so move the test apps +// into a "testdata" subpackage +python_library_host { + name: "csuite_crash_detection_test_data", + pkg_path: "testdata", data: [ ":csuite_crash_on_launch_test_app", ":csuite_no_crash_test_app", ], - test_options: { - unit_test: false, - }, + visibility: ["//visibility:private"], } diff --git a/integration_tests/csuite_crash_detection_test.py b/integration_tests/csuite_crash_detection_test.py index 2cec583..29497f5 100644 --- a/integration_tests/csuite_crash_detection_test.py +++ b/integration_tests/csuite_crash_detection_test.py @@ -69,8 +69,7 @@ class CrashDetectionTest(csuite_test_utils.TestCase): self.adb.uninstall(test_app_package, check=False) self.assert_package_not_installed(test_app_package) - self.repo.add_package_apks( - test_app_package, csuite_test_utils.get_test_app_apks(test_app_module)) + self.repo.add_package_apks(test_app_package, [test_app_module]) file_resolver_class = 'com.android.csuite.config.AppRemoteFileResolver' diff --git a/integration_tests/csuite_test_utils.py b/integration_tests/csuite_test_utils.py index 39d5ba4..fd76e34 100644 --- a/integration_tests/csuite_test_utils.py +++ b/integration_tests/csuite_test_utils.py @@ -26,8 +26,10 @@ import stat import subprocess import sys import tempfile -from typing import Sequence, Text import zipfile +from importlib import resources +from typing import Sequence + import csuite_test # Export symbols to reduce the number of imports tests have to list. @@ -52,8 +54,10 @@ class CSuiteHarness(contextlib.AbstractContextManager): self._suite_dir = pathlib.Path(tempfile.mkdtemp(prefix='csuite')) logging.debug('Created harness directory: %s', self._suite_dir) - with zipfile.ZipFile(_get_standalone_zip_path(), 'r') as f: - f.extractall(self._suite_dir) + with resources.files('testdata').joinpath( + 'csuite-standalone.zip').open('rb') as data: + with zipfile.ZipFile(data, 'r') as f: + f.extractall(self._suite_dir) # Add owner-execute permission on scripts since zip does not preserve them. self._launcher_binary = self._suite_dir.joinpath( @@ -71,7 +75,7 @@ class CSuiteHarness(contextlib.AbstractContextManager): shutil.rmtree(self._suite_dir, ignore_errors=True) - def run_and_wait(self, flags: Sequence[Text]) -> subprocess.CompletedProcess: + def run_and_wait(self, flags: Sequence[str]) -> subprocess.CompletedProcess: """Starts the Tradefed launcher and waits for it to complete.""" env = os.environ.copy() @@ -130,15 +134,19 @@ class PackageRepository(contextlib.AbstractContextManager): """Returns the path to the repository's root directory.""" return self._root_dir - def add_package_apks(self, package_name: Text, - apk_paths: Sequence[pathlib.Path]): + def add_package_apks(self, package_name: str, apks: Sequence[str]): """Adds the provided package APKs to the repository.""" apk_dir = self._root_dir.joinpath(package_name) # Raises if the directory already exists. apk_dir.mkdir() - for f in apk_paths: - shutil.copy(f, apk_dir) + for apk in apks: + apk = apk + '.apk' + with ( + resources.files('testdata').joinpath(apk).open('rb') as data, + open(os.path.join(apk_dir, apk), 'wb') as file, + ): + shutil.copyfileobj(data, file) class Adb: @@ -150,7 +158,7 @@ class Adb: def __init__(self, adb_binary_path: pathlib.Path = None, - device_serial: Text = None): + device_serial: str = None): self._args = [adb_binary_path or 'adb'] device_serial = device_serial or get_device_serial() @@ -158,7 +166,7 @@ class Adb: self._args.extend(['-s', device_serial]) def shell(self, - args: Sequence[Text], + args: Sequence[str], check: bool = None) -> subprocess.CompletedProcess: """Runs an adb shell command and waits for it to complete. @@ -177,16 +185,16 @@ class Adb: return self.run(['shell'] + args, check) def run(self, - args: Sequence[Text], + args: Sequence[str], check: bool = None) -> subprocess.CompletedProcess: """Runs an adb command and waits for it to complete.""" return _run_command(self._args + args, check=check) - def uninstall(self, package_name: Text, check: bool = None): + def uninstall(self, package_name: str, check: bool = None): """Uninstalls the specified package.""" self.run(['uninstall', package_name], check=check) - def list_packages(self) -> Sequence[Text]: + def list_packages(self) -> Sequence[str]: """Lists packages installed on the device.""" p = self.shell(['pm', 'list', 'packages']) return [l.split(':')[1] for l in p.stdout.splitlines()] @@ -216,39 +224,13 @@ def _add_owner_exec_permission(path: pathlib.Path): path.chmod(path.stat().st_mode | stat.S_IEXEC) -def get_test_app_apks(app_module_name: Text) -> Sequence[pathlib.Path]: - """Returns a test app's apk file paths.""" - return [_get_test_file(app_module_name + '.apk')] - - -def _get_standalone_zip_path(): - """Returns the suite standalone zip file's path.""" - return _get_test_file('csuite-standalone.zip') - - -def _get_test_file(name: Text) -> pathlib.Path: - test_dir = _get_test_dir() - test_file = test_dir.joinpath(name) - - if not test_file.exists(): - raise RuntimeError(f'Unable to find the file `{name}` in the test ' - 'execution dir `{test_dir}`; are you missing a data ' - 'dependency in the build module?') - - return test_file - - -def _shlex_join(split_command: Sequence[Text]) -> Text: +def _shlex_join(split_command: Sequence[str]) -> str: """Concatenate tokens and return a shell-escaped string.""" # This is an alternative to shlex.join that doesn't exist in Python versions # < 3.8. return ' '.join(shlex.quote(t) for t in split_command) -def _get_test_dir() -> pathlib.Path: - return pathlib.Path(__file__).parent - - def main(): global _KEEP_TEMP_DIRS diff --git a/test_scripts/src/main/java/com/android/art/OWNERS b/test_scripts/src/main/java/com/android/art/OWNERS new file mode 100644 index 0000000..3414a74 --- /dev/null +++ b/test_scripts/src/main/java/com/android/art/OWNERS @@ -0,0 +1 @@ +include platform/art:/OWNERS diff --git a/test_scripts/src/main/java/com/android/art/targetprep/AllProcessesImgdiag.java b/test_scripts/src/main/java/com/android/art/targetprep/AllProcessesImgdiag.java new file mode 100644 index 0000000..d0a9b29 --- /dev/null +++ b/test_scripts/src/main/java/com/android/art/targetprep/AllProcessesImgdiag.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2024 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. + */ + +package com.android.art.targetprep; + +import com.android.art.tests.AppLaunchImgdiagTest; +import com.android.tradefed.config.Option; +import com.android.tradefed.device.DeviceNotAvailableException; +import com.android.tradefed.invoker.TestInformation; +import com.android.tradefed.log.ITestLogger; +import com.android.tradefed.result.FileInputStreamSource; +import com.android.tradefed.result.ITestLoggerReceiver; +import com.android.tradefed.result.LogDataType; +import com.android.tradefed.targetprep.ITargetPreparer; + +import org.junit.Assert; + +import java.io.File; + +/** Collect imgdiag data from all zygote children at the end of the run. */ +public class AllProcessesImgdiag implements ITestLoggerReceiver, ITargetPreparer { + @Option( + name = "imgdiag-out-path", + description = "Path to directory containing imgdiag output files.") + private String mImgdiagOutPath; + + private ITestLogger mTestLogger; + + @Override + public void setTestLogger(ITestLogger testLogger) { + mTestLogger = testLogger; + } + + @Override + public void setUp(TestInformation testInformation) {} + + @Override + public void tearDown(TestInformation testInformation, Throwable e) + throws DeviceNotAvailableException { + Assert.assertTrue(testInformation.getDevice().doesFileExist(mImgdiagOutPath)); + + String zygoteChildren = + testInformation + .getDevice() + .executeShellCommand("ps --ppid `pidof zygote64` -o pid,args"); + + // Skip "PID ARGS" header. + for (String line : zygoteChildren.lines().skip(1).toList()) { + String[] vals = line.strip().split("\\s+"); + Assert.assertEquals(2, vals.length); + + String targetPid = vals[0]; + String targetName = vals[1]; + + String outFileName = String.format("imgdiag_%s_%s.txt", targetName, targetPid); + String outFilePath = new File(mImgdiagOutPath, outFileName).getAbsolutePath(); + + String imgdiagCmd = AppLaunchImgdiagTest.getImgdiagRunCmd(targetPid, outFilePath); + testInformation.getDevice().executeShellCommand(imgdiagCmd); + + File imgdiagFile = testInformation.getDevice().pullFile(outFilePath); + mTestLogger.testLog( + outFileName, LogDataType.HOST_LOG, new FileInputStreamSource(imgdiagFile)); + } + } +} diff --git a/test_scripts/src/main/java/com/android/art/tests/AppLaunchImgdiagTest.java b/test_scripts/src/main/java/com/android/art/tests/AppLaunchImgdiagTest.java index 853bf1e..08b9344 100644 --- a/test_scripts/src/main/java/com/android/art/tests/AppLaunchImgdiagTest.java +++ b/test_scripts/src/main/java/com/android/art/tests/AppLaunchImgdiagTest.java @@ -48,18 +48,13 @@ public class AppLaunchImgdiagTest extends AppLaunchTest { String outFileName = String.format("imgdiag_%s_%s.txt", mPackageName, targetPid); String outFilePath = new File(mImgdiagOutPath, outFileName).getAbsolutePath(); - String imgdiagCmd = - String.format( - "imgdiag --zygote-diff-pid=`pidof zygote64` --image-diff-pid=%2$s" - + " --output=" - + outFilePath - + " --dump-dirty-objects --boot-image=" - + "/data/misc/apexdata/com.android.art/dalvik-cache/boot.art", - mPackageName, - targetPid); + String imgdiagCmd = getImgdiagRunCmd(targetPid, outFilePath); CommandResult res = getDevice().executeShellV2Command(imgdiagCmd); Assert.assertEquals( - "Failed to run imgdiag. " + res.toString(), CommandStatus.SUCCESS, res.getStatus()); + String.format( + "Failed to run imgdiag:\n%s\nResult:\n%s", imgdiagCmd, res.toString()), + CommandStatus.SUCCESS, + res.getStatus()); File imgdiagFile = getDevice().pullFile(outFilePath); TestUtils testUtils = TestUtils.getInstance(getTestInformation(), mLogData); @@ -69,4 +64,21 @@ public class AppLaunchImgdiagTest extends AppLaunchTest { super.tearDown(); } + + /** + * Constructs the command line string to run the `imgdiag` tool for gathering dirty image + * objects. + * + * @param targetPid The process ID of the target process to analyze. + * @param outFilePath The absolute file path on the device where the imgdiag data will be saved. + * @return The complete `imgdiag` command that can be run with `adb shell`. + */ + public static String getImgdiagRunCmd(String targetPid, String outFilePath) { + return String.format( + "imgdiag --zygote-diff-pid=`pidof zygote64` --image-diff-pid=%s" + + " --output=%s" + + " --dump-dirty-objects --boot-image=" + + "/data/misc/apexdata/com.android.art/dalvik-cache/boot.art", + targetPid, outFilePath); + } } diff --git a/test_scripts/src/main/java/com/android/webview/Android.bp b/test_scripts/src/main/java/com/android/webview/Android.bp index 62aed62..7957944 100644 --- a/test_scripts/src/main/java/com/android/webview/Android.bp +++ b/test_scripts/src/main/java/com/android/webview/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_chromium_webview", default_applicable_licenses: ["Android-Apache-2.0"], } diff --git a/test_targets/csuite-app-crawl/Android.bp b/test_targets/csuite-app-crawl/Android.bp index 131e45d..c7bfc7f 100644 --- a/test_targets/csuite-app-crawl/Android.bp +++ b/test_targets/csuite-app-crawl/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } @@ -20,5 +21,8 @@ csuite_test { name: "csuite-app-crawl", test_plan_include: "plan.xml", test_config_template: "ui-automator-crawl.xml", - extra_test_config_templates: ["espresso-crawl.xml", "pre-installed-crawl.xml"] + extra_test_config_templates: [ + "espresso-crawl.xml", + "pre-installed-crawl.xml", + ], } diff --git a/test_targets/csuite-app-launch/Android.bp b/test_targets/csuite-app-launch/Android.bp index 9bf1194..ef396f0 100644 --- a/test_targets/csuite-app-launch/Android.bp +++ b/test_targets/csuite-app-launch/Android.bp @@ -13,11 +13,12 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } csuite_test { - name: "csuite-app-launch", - test_config_template: "default-launch.xml", - extra_test_config_templates: ["pre-installed-launch.xml"] + name: "csuite-app-launch", + test_config_template: "default-launch.xml", + extra_test_config_templates: ["pre-installed-launch.xml"], } diff --git a/test_targets/csuite-pre-installed-app-launch/Android.bp b/test_targets/csuite-pre-installed-app-launch/Android.bp index 539306a..1087a32 100644 --- a/test_targets/csuite-pre-installed-app-launch/Android.bp +++ b/test_targets/csuite-pre-installed-app-launch/Android.bp @@ -13,10 +13,11 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } csuite_test { name: "csuite-pre-installed-app-launch", - test_config_template: "template.xml" + test_config_template: "template.xml", } diff --git a/test_targets/csuite-system-app-launch/Android.bp b/test_targets/csuite-system-app-launch/Android.bp index 2514740..da3b438 100644 --- a/test_targets/csuite-system-app-launch/Android.bp +++ b/test_targets/csuite-system-app-launch/Android.bp @@ -13,10 +13,11 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } csuite_test { - name: "csuite-system-app-launch", - test_config_template: "template.xml" + name: "csuite-system-app-launch", + test_config_template: "template.xml", } diff --git a/test_targets/csuite-test-package-launch/Android.bp b/test_targets/csuite-test-package-launch/Android.bp index 6cdd899..9cc96ee 100644 --- a/test_targets/csuite-test-package-launch/Android.bp +++ b/test_targets/csuite-test-package-launch/Android.bp @@ -13,10 +13,11 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } csuite_test { - name: "csuite-test-package-launch", - test_config_template: "template.xml" + name: "csuite-test-package-launch", + test_config_template: "template.xml", } diff --git a/test_targets/drm-app-launch/Android.bp b/test_targets/drm-app-launch/Android.bp index 08d241b..fb20c98 100644 --- a/test_targets/drm-app-launch/Android.bp +++ b/test_targets/drm-app-launch/Android.bp @@ -13,11 +13,12 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } csuite_test { name: "drm-app-launch", test_plan_include: "plan.xml", - test_config_template: "template.xml" -}
\ No newline at end of file + test_config_template: "template.xml", +} diff --git a/test_targets/imgdiag-app-launch/OWNERS b/test_targets/imgdiag-app-launch/OWNERS new file mode 100644 index 0000000..3414a74 --- /dev/null +++ b/test_targets/imgdiag-app-launch/OWNERS @@ -0,0 +1 @@ +include platform/art:/OWNERS diff --git a/test_targets/imgdiag-app-launch/plan.xml b/test_targets/imgdiag-app-launch/plan.xml index 9f7158b..163c79a 100644 --- a/test_targets/imgdiag-app-launch/plan.xml +++ b/test_targets/imgdiag-app-launch/plan.xml @@ -18,6 +18,9 @@ <option name="run-command" value="mkdir /data/local/tmp/imgdiag_out/"/> <option name="teardown-command" value="rm -r /data/local/tmp/imgdiag_out/"/> </target_preparer> + <target_preparer class="com.android.art.targetprep.AllProcessesImgdiag"> + <option name="imgdiag-out-path" value="/data/local/tmp/imgdiag_out/"/> + </target_preparer> <target_preparer class="com.android.art.targetprep.AggregateImgdiagOutput"> <option name="imgdiag-out-path" value="/data/local/tmp/imgdiag_out/"/> </target_preparer> diff --git a/test_targets/pixel-app-launch-lock-recentapp/Android.bp b/test_targets/pixel-app-launch-lock-recentapp/Android.bp index 720c249..b139aa7 100644 --- a/test_targets/pixel-app-launch-lock-recentapp/Android.bp +++ b/test_targets/pixel-app-launch-lock-recentapp/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_test_eng_comms_power", default_applicable_licenses: ["Android-Apache-2.0"], } diff --git a/test_targets/pixel-app-launch-lock/Android.bp b/test_targets/pixel-app-launch-lock/Android.bp index 8261309..f28dc14 100644 --- a/test_targets/pixel-app-launch-lock/Android.bp +++ b/test_targets/pixel-app-launch-lock/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } diff --git a/test_targets/pixel-app-launch-recentapp/Android.bp b/test_targets/pixel-app-launch-recentapp/Android.bp index 4458cf3..30a86a0 100644 --- a/test_targets/pixel-app-launch-recentapp/Android.bp +++ b/test_targets/pixel-app-launch-recentapp/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_test_eng_comms_power", default_applicable_licenses: ["Android-Apache-2.0"], } diff --git a/test_targets/pixel-app-launch-rotate/Android.bp b/test_targets/pixel-app-launch-rotate/Android.bp index 89419ae..efb00a5 100644 --- a/test_targets/pixel-app-launch-rotate/Android.bp +++ b/test_targets/pixel-app-launch-rotate/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_qmc_script_automation", default_applicable_licenses: ["Android-Apache-2.0"], } diff --git a/test_targets/webview-app-crawl/Android.bp b/test_targets/webview-app-crawl/Android.bp index 57d4192..baa627a 100644 --- a/test_targets/webview-app-crawl/Android.bp +++ b/test_targets/webview-app-crawl/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_embedded_web_on_android", default_applicable_licenses: ["Android-Apache-2.0"], } diff --git a/test_targets/webview-app-launch/Android.bp b/test_targets/webview-app-launch/Android.bp index 8d54421..ddfb639 100644 --- a/test_targets/webview-app-launch/Android.bp +++ b/test_targets/webview-app-launch/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_embedded_web_on_android", default_applicable_licenses: ["Android-Apache-2.0"], } diff --git a/tools/csuite-tradefed/Android.bp b/tools/csuite-tradefed/Android.bp index f65410a..a6eed91 100644 --- a/tools/csuite-tradefed/Android.bp +++ b/tools/csuite-tradefed/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } diff --git a/tools/script/Android.bp b/tools/script/Android.bp index a9832f9..a1a31d2 100644 --- a/tools/script/Android.bp +++ b/tools/script/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_app_compat", default_applicable_licenses: ["Android-Apache-2.0"], } |