Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 02d71198 authored by Lee Shombert's avatar Lee Shombert
Browse files

Initial drop of the memory test app

This is a bare-bones application that is used to measure the baseline
memory used by an application when it starts.  The baseline memory is
memory that is not under control of the application.

The test is run via atest and one of the test artefacts is a perfetto
trace that contains a heap profile.

Flag: EXEMPT test-only
Bug: 429215212
Test: atest
 * AppMemoryTestCases

Change-Id: I8ef0435e818ced380b5bb763285520a587a12056
parent e45b09dc
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
// Copyright (C) 2025 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 {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_base_license"],
}

android_test {
    name: "AppMemoryTestCases",
    team: "trendy_team_system_performance",
    srcs: ["src/**/*.java"],
    static_libs: [
        "androidx.test.rules",
        "androidx.test.core",
        "platform-test-annotations",
        "flag-junit",
        "androidx.test.uiautomator_uiautomator",
    ],
    device_common_data: [
        ":AppMemoryTest_Helper",
    ],
    platform_apis: true,
    test_suites: ["general-tests"],
    certificate: "platform",
}

android_test_helper_app {
    name: "AppMemoryTest_Helper",
    manifest: "app/AndroidManifest.xml",
    srcs: ["app/src/**/*.java"],
    resource_dirs: ["app/res"],
    static_libs: ["com.google.android.material_material"],

    platform_apis: true,
    test_suites: ["general-tests"],
    certificate: "platform",
    dex_preopt: {
        enabled: false,
    },
}
+35 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2025 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.
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="android.app.memory.tests">

    <!-- This app is allowed to query for the heap profile in /data/local/tmp. -->
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>

    <queries>
        <package android:name="android.app.memory.testhelper" />
    </queries>

    <!--  self-instrumenting test package. -->
    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:label="App Memory Test"
        android:targetPackage="android.app.memory.tests">
    </instrumentation>

</manifest>
+61 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2025 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="Config for App Memory Tests">
    <option name="test-suite-tag" value="apct"/>

    <option name="config-descriptor:metadata" key="component" value="systems"/>
    <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
    <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
    <option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
    <option name="config-descriptor:metadata" key="parameter" value="no_foldable_states" />

    <option name="install-arg" value="-t -g" />

    <!-- Expose shared storage for testing purpose. -->
    <target_preparer class="com.android.tradefed.targetprep.DisableSELinuxTargetPreparer" />

    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true"/>
        <option name="test-file-name" value="AppMemoryTestCases.apk"/>
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
      <option name="run-command" value="rm -rf /data/local/tmp/appmemorytest"/>
      <option name="run-command" value="mkdir -p /data/local/tmp/appmemorytest"/>
      <option name="run-command" value="chmod a+rw /data/local/tmp/appmemorytest"/>
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
      <option name="push"
              value="AppMemoryTest_Helper.apk->/data/local/tmp/appmemorytest/"/>
    </target_preparer>

    <test class="com.android.tradefed.testtype.AndroidJUnitTest">
        <option name="package" value="android.app.memory.tests"/>
        <option name="runner" value="androidx.test.runner.AndroidJUnitRunner"/>
    </test>

    <!-- Retrieve the heap profile.  It will be named "jheap_<n>.hprof". -->
    <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
        <option name="directory-keys" value="/data/local/tmp/appmemorytest" />
        <option name="pull-pattern-keys" value="jheap-*.hprof" />
        <option name="pull-pattern-keys" value="jheap-*.stats" />
        <option name="collect-on-run-ended-only" value="true" />
        <option name="clean-up" value="true" />
    </metrics_collector>

</configuration>
+1 −0
Original line number Diff line number Diff line
include /PERFORMANCE_OWNERS
+40 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2025 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.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="android.app.memory.testhelper"
          >
    <!-- This app is allowed to generate a heap profile in /data/local/tmp. -->
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application android:debuggable="true"
               >
        <activity android:name=".EmptyActivity"
                  android:label="_EmptyActivity"
                  android:enabled="true"
                  android:exported="true"
                  >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>
Loading