aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIoannis Ilkos <ilkos@google.com>2023-01-16 19:32:42 +0000
committerMartin Stjernholm <mast@google.com>2023-03-06 18:40:39 +0000
commitf7ac0db2eea9005687ade87f9d5aca632641163a (patch)
treeff88900f4f33f9e140ff70be24df1d215efbd2ed
parent25e6b1119dbc40cc79d5ed6260a50a51e3317a04 (diff)
downloadperfetto-f7ac0db2eea9005687ade87f9d5aca632641163a.tar.gz
Add CTS tests for heap dump on OOME
First pass at a test verifying operation on non-user builds (as they are the only ones currently supported). The next changes will widen the coverage of both impl and test. Test: atest HeapprofdJavaCtsTest#DebuggableAppOom Bug: 260850768 Bug: 261018462 Change-Id: I077bd464e6c6a692d91371a43c1ed73ac33a4670 Merged-In: I077bd464e6c6a692d91371a43c1ed73ac33a4670
-rw-r--r--test/cts/heapprofd_java_test_cts.cc53
-rwxr-xr-xtest/cts/test_apps/AndroidManifest_debuggable.xml13
-rw-r--r--test/cts/test_apps/src/android/perfetto/cts/app/JavaOomActivity.java54
3 files changed, 120 insertions, 0 deletions
diff --git a/test/cts/heapprofd_java_test_cts.cc b/test/cts/heapprofd_java_test_cts.cc
index 7d8112819..10bc98550 100644
--- a/test/cts/heapprofd_java_test_cts.cc
+++ b/test/cts/heapprofd_java_test_cts.cc
@@ -89,6 +89,51 @@ std::vector<protos::gen::TracePacket> ProfileRuntime(std::string app_name) {
return helper.trace();
}
+std::vector<protos::gen::TracePacket> TriggerOomHeapDump(std::string app_name) {
+ base::TestTaskRunner task_runner;
+
+ // (re)start the target app's main activity
+ if (IsAppRunning(app_name)) {
+ StopApp(app_name, "old.app.stopped", &task_runner);
+ task_runner.RunUntilCheckpoint("old.app.stopped", 10000 /*ms*/);
+ }
+
+ // set up tracing
+ TestHelper helper(&task_runner);
+ helper.ConnectConsumer();
+ helper.WaitForConsumerConnect();
+
+ TraceConfig trace_config;
+ trace_config.add_buffers()->set_size_kb(40 * 1024);
+ trace_config.set_unique_session_name(RandomSessionName().c_str());
+ trace_config.set_data_source_stop_timeout_ms(60000);
+
+ auto* trigger_config = trace_config.mutable_trigger_config();
+ trigger_config->set_trigger_mode(perfetto::protos::gen::TraceConfig::TriggerConfig::START_TRACING);
+ trigger_config->set_trigger_timeout_ms(60000);
+ auto* oom_trigger = trigger_config->add_triggers();
+ oom_trigger->set_name("com.android.telemetry.art-outofmemory");
+ oom_trigger->set_stop_delay_ms(10000);
+
+ auto* ds_config = trace_config.add_data_sources()->mutable_config();
+ ds_config->set_name("android.java_hprof.oom");
+ ds_config->set_target_buffer(0);
+
+ // start tracing
+ helper.StartTracing(trace_config);
+ StartAppActivity(app_name, "JavaOomActivity", "target.app.running", &task_runner,
+ /*delay_ms=*/100);
+
+ helper.WaitForTracingDisabled();
+ helper.ReadData();
+ helper.WaitForReadData();
+
+ PERFETTO_CHECK(IsAppRunning(app_name));
+ StopApp(app_name, "new.app.stopped", &task_runner);
+ task_runner.RunUntilCheckpoint("new.app.stopped", 10000 /*ms*/);
+ return helper.trace();
+}
+
void AssertGraphPresent(std::vector<protos::gen::TracePacket> packets) {
ASSERT_GT(packets.size(), 0u);
@@ -184,5 +229,13 @@ TEST(HeapprofdJavaCtsTest, DebuggableAppRuntimeByPid) {
AssertGraphPresent(packets);
}
+TEST(HeapprofdJavaCtsTest, DebuggableAppOom) {
+ if (IsUserBuild()) return;
+
+ std::string app_name = "android.perfetto.cts.app.debuggable";
+ const auto& packets = TriggerOomHeapDump(app_name);
+ AssertGraphPresent(packets);
+}
+
} // namespace
} // namespace perfetto
diff --git a/test/cts/test_apps/AndroidManifest_debuggable.xml b/test/cts/test_apps/AndroidManifest_debuggable.xml
index cb746c17e..291469e5a 100755
--- a/test/cts/test_apps/AndroidManifest_debuggable.xml
+++ b/test/cts/test_apps/AndroidManifest_debuggable.xml
@@ -58,5 +58,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
+ <activity
+ android:name="android.perfetto.cts.app.JavaOomActivity"
+ android:exported="true">
+ </activity>
+ <activity-alias
+ android:name="android.perfetto.cts.app.debuggable.JavaOomActivity"
+ android:targetActivity="android.perfetto.cts.app.JavaOomActivity"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity-alias>
</application>
</manifest>
diff --git a/test/cts/test_apps/src/android/perfetto/cts/app/JavaOomActivity.java b/test/cts/test_apps/src/android/perfetto/cts/app/JavaOomActivity.java
new file mode 100644
index 000000000..4165a928d
--- /dev/null
+++ b/test/cts/test_apps/src/android/perfetto/cts/app/JavaOomActivity.java
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+package android.perfetto.cts.app;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import java.util.ArrayList;
+
+public class JavaOomActivity extends Activity {
+ @Override
+ public void onCreate(Bundle state) {
+ super.onCreate(state);
+
+ new Thread(new Runnable() {
+ public void run() {
+ try {
+ runAllocationLoop();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }).start();
+ }
+
+ private static void runAllocationLoop() {
+ ArrayList<byte[]> leaky = new ArrayList<>();
+ try {
+ for (;;) {
+ leaky.add(new byte[1024 * 1024]);
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException ignored) {
+ }
+ }
+ } catch (OutOfMemoryError e) {
+ leaky.clear();
+ }
+ }
+}