aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-04 22:16:12 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-04 22:16:12 +0000
commitc5952599a22be6bbe44f9426452b34c60edd89b5 (patch)
tree9e9d9d7ddc5336c94be6b96fba669cefb7986237
parent4c5efa79ce533c7290cb646bdbe4c68f15c8bbe5 (diff)
parent467f1ec58dc1574f14a536b78d0ee38a1e6928cd (diff)
downloadcsuite-simpleperf-release.tar.gz
Snap for 11526323 from 467f1ec58dc1574f14a536b78d0ee38a1e6928cd to simpleperf-releasesimpleperf-release
Change-Id: Ia428a258b2446fcfa403bad80f7b1db62400d198
-rw-r--r--test_scripts/src/main/java/com/android/art/targetprep/AggregateImgdiagOutput.java93
-rw-r--r--test_scripts/src/main/java/com/android/art/tests/AppLaunchImgdiagTest.java72
-rw-r--r--test_scripts/src/main/java/com/android/csuite/tests/AppLaunchTest.java2
-rw-r--r--test_targets/imgdiag-app-launch/Android.bp24
-rw-r--r--test_targets/imgdiag-app-launch/default-launch.xml31
-rw-r--r--test_targets/imgdiag-app-launch/plan.xml24
-rw-r--r--test_targets/imgdiag-app-launch/pre-installed-launch.xml29
7 files changed, 274 insertions, 1 deletions
diff --git a/test_scripts/src/main/java/com/android/art/targetprep/AggregateImgdiagOutput.java b/test_scripts/src/main/java/com/android/art/targetprep/AggregateImgdiagOutput.java
new file mode 100644
index 0000000..aed9ebb
--- /dev/null
+++ b/test_scripts/src/main/java/com/android/art/targetprep/AggregateImgdiagOutput.java
@@ -0,0 +1,93 @@
+/*
+ * 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.tradefed.config.Option;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.IFileEntry;
+import com.android.tradefed.invoker.TestInformation;
+import com.android.tradefed.log.ITestLogger;
+import com.android.tradefed.result.ByteArrayInputStreamSource;
+import com.android.tradefed.result.ITestLoggerReceiver;
+import com.android.tradefed.result.LogDataType;
+import com.android.tradefed.targetprep.ITargetPreparer;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.Assert;
+
+import java.util.Collection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/** Collect all imgdiag dirty objects into one file. */
+public class AggregateImgdiagOutput 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));
+
+ Pattern imgdiagOutRegex = Pattern.compile("imgdiag_(\\S+_\\d+)\\.txt");
+ String dirtyObjPrefix = "dirty_obj:";
+
+ JSONObject combinedData = new JSONObject();
+ IFileEntry deviceImgdiagOutDir = testInformation.getDevice().getFileEntry(mImgdiagOutPath);
+ for (IFileEntry child : deviceImgdiagOutDir.getChildren(false)) {
+ Matcher m = imgdiagOutRegex.matcher(child.getName());
+ if (!m.matches()) {
+ continue;
+ }
+
+ String key = m.group(1);
+
+ String fileContents = testInformation.getDevice().pullFileContents(child.getFullPath());
+ Collection<String> dirty_objects =
+ fileContents
+ .lines()
+ .filter(line -> line.startsWith(dirtyObjPrefix))
+ .map(line -> line.substring(dirtyObjPrefix.length()).strip())
+ .toList();
+
+ try {
+ combinedData.put(key, new JSONArray(dirty_objects));
+ } catch (JSONException exception) {
+ Assert.fail(exception.toString());
+ }
+ }
+
+ mTestLogger.testLog(
+ "combined_imgdiag_data",
+ LogDataType.JSON,
+ new ByteArrayInputStreamSource(combinedData.toString().getBytes()));
+ }
+}
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
new file mode 100644
index 0000000..853bf1e
--- /dev/null
+++ b/test_scripts/src/main/java/com/android/art/tests/AppLaunchImgdiagTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.tests;
+
+import com.android.csuite.core.ApkInstaller.ApkInstallerException;
+import com.android.csuite.core.TestUtils;
+import com.android.csuite.tests.AppLaunchTest;
+import com.android.tradefed.config.Option;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.result.LogDataType;
+import com.android.tradefed.util.CommandResult;
+import com.android.tradefed.util.CommandStatus;
+
+import org.junit.After;
+import org.junit.Assert;
+
+import java.io.File;
+
+/** A test that gets imgdiag data after launching an app. */
+public class AppLaunchImgdiagTest extends AppLaunchTest {
+ @Option(
+ name = "imgdiag-out-path",
+ description = "Path to directory containing imgdiag output files.")
+ private String mImgdiagOutPath;
+
+ @After
+ public void tearDown() throws DeviceNotAvailableException, ApkInstallerException {
+ String[] packagePids =
+ getDevice().executeShellCommand("pidof " + mPackageName).strip().split(" ");
+ Assert.assertEquals(1, packagePids.length);
+ String targetPid = packagePids[0].strip();
+ Assert.assertFalse(targetPid.isEmpty());
+
+ 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);
+ CommandResult res = getDevice().executeShellV2Command(imgdiagCmd);
+ Assert.assertEquals(
+ "Failed to run imgdiag. " + res.toString(), CommandStatus.SUCCESS, res.getStatus());
+
+ File imgdiagFile = getDevice().pullFile(outFilePath);
+ TestUtils testUtils = TestUtils.getInstance(getTestInformation(), mLogData);
+ testUtils
+ .getTestArtifactReceiver()
+ .addTestArtifact(outFileName, LogDataType.HOST_LOG, imgdiagFile);
+
+ super.tearDown();
+ }
+}
diff --git a/test_scripts/src/main/java/com/android/csuite/tests/AppLaunchTest.java b/test_scripts/src/main/java/com/android/csuite/tests/AppLaunchTest.java
index 1f06e87..a8017ac 100644
--- a/test_scripts/src/main/java/com/android/csuite/tests/AppLaunchTest.java
+++ b/test_scripts/src/main/java/com/android/csuite/tests/AppLaunchTest.java
@@ -107,7 +107,7 @@ public class AppLaunchTest extends BaseHostJUnit4Test {
private TestUtils.TakeEffectWhen mSaveApkWhen = TestUtils.TakeEffectWhen.NEVER;
@Option(name = "package-name", description = "Package name of testing app.")
- private String mPackageName;
+ protected String mPackageName;
@Option(
name = "app-launch-timeout-ms",
diff --git a/test_targets/imgdiag-app-launch/Android.bp b/test_targets/imgdiag-app-launch/Android.bp
new file mode 100644
index 0000000..4e11267
--- /dev/null
+++ b/test_targets/imgdiag-app-launch/Android.bp
@@ -0,0 +1,24 @@
+// 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 {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+csuite_test {
+ name: "imgdiag-app-launch",
+ test_plan_include: "plan.xml",
+ test_config_template: "default-launch.xml",
+ extra_test_config_templates: ["pre-installed-launch.xml"],
+}
diff --git a/test_targets/imgdiag-app-launch/default-launch.xml b/test_targets/imgdiag-app-launch/default-launch.xml
new file mode 100644
index 0000000..8427041
--- /dev/null
+++ b/test_targets/imgdiag-app-launch/default-launch.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<configuration description="Launch an app and collect imgdiag data">
+ <target_preparer class="com.android.compatibility.targetprep.CheckGmsPreparer"/>
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller" />
+ <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+ <option name="run-command" value="input keyevent KEYCODE_WAKEUP"/>
+ <option name="run-command" value="input keyevent KEYCODE_MENU"/>
+ <option name="run-command" value="input keyevent KEYCODE_HOME"/>
+ </target_preparer>
+ <test class="com.android.tradefed.testtype.HostTest" >
+ <option name="set-option" value="package-name:{package}"/>
+ <option name="set-option" value="install-apk:app\://{package}"/>
+ <option name="set-option" value="install-arg:-g"/>
+ <option name="set-option" value="imgdiag-out-path:/data/local/tmp/imgdiag_out/"/>
+ <option name="class" value="com.android.art.tests.AppLaunchImgdiagTest" />
+ </test>
+</configuration>
diff --git a/test_targets/imgdiag-app-launch/plan.xml b/test_targets/imgdiag-app-launch/plan.xml
new file mode 100644
index 0000000..9f7158b
--- /dev/null
+++ b/test_targets/imgdiag-app-launch/plan.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<configuration description="Imgdiag Applaunch Test Plan">
+ <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+ <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.AggregateImgdiagOutput">
+ <option name="imgdiag-out-path" value="/data/local/tmp/imgdiag_out/"/>
+ </target_preparer>
+</configuration>
diff --git a/test_targets/imgdiag-app-launch/pre-installed-launch.xml b/test_targets/imgdiag-app-launch/pre-installed-launch.xml
new file mode 100644
index 0000000..bc80f46
--- /dev/null
+++ b/test_targets/imgdiag-app-launch/pre-installed-launch.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<configuration description="Launch an app that exists on the device and collect imgdiag data">
+ <target_preparer class="com.android.compatibility.targetprep.CheckGmsPreparer"/>
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller" />
+ <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+ <option name="run-command" value="input keyevent KEYCODE_WAKEUP"/>
+ <option name="run-command" value="input keyevent KEYCODE_MENU"/>
+ <option name="run-command" value="input keyevent KEYCODE_HOME"/>
+ </target_preparer>
+ <test class="com.android.tradefed.testtype.HostTest" >
+ <option name="set-option" value="package-name:{package}"/>
+ <option name="set-option" value="imgdiag-out-path:/data/local/tmp/imgdiag_out/"/>
+ <option name="class" value="com.android.art.tests.AppLaunchImgdiagTest" />
+ </test>
+</configuration>